TUInterfaceinfoServiceImpl.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. package com.sooka.system.service.impl;
  2. import java.util.Date;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.Map;
  6. import com.business.domain.ImputationData;
  7. import com.business.mapper.ImputationDataMapper;
  8. import com.sooka.apply.domain.IntDetailed;
  9. import com.sooka.apply.mapper.IntRecordMapper;
  10. import com.sooka.common.core.text.Convert;
  11. import com.sooka.common.utils.DateUtils;
  12. import com.sooka.common.utils.uuid.UUID;
  13. import com.sooka.framework.util.ShiroUtils;
  14. import com.util.NumberUtils;
  15. import com.util.SecretKeyUtil;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.stereotype.Service;
  18. import com.sooka.system.mapper.TUInterfaceinfoMapper;
  19. import com.sooka.system.domain.TUInterfaceinfo;
  20. import com.sooka.system.service.ITUInterfaceinfoService;
  21. import javax.annotation.Resource;
  22. /**
  23. * 【接口应用审批管理】Service业务层处理
  24. *
  25. * @author lei
  26. * @date 2021-07-01
  27. */
  28. @Service
  29. public class TUInterfaceinfoServiceImpl implements ITUInterfaceinfoService
  30. {
  31. @Resource
  32. private TUInterfaceinfoMapper tUInterfaceinfoMapper;
  33. @Resource
  34. private ImputationDataMapper imputationDataMapper;
  35. @Resource
  36. private IntRecordMapper intRecordMapper;
  37. /**
  38. * 查询【接口应用审批管理】
  39. *
  40. * @param id 【接口应用审批管理】ID
  41. * @return 【接口应用审批管理】
  42. */
  43. @Override
  44. public TUInterfaceinfo selectTUInterfaceinfoById(String id)
  45. {
  46. // String str = SecretKeyUtil.AESEncode("3fc674da58", "123/政数局/2022-10-20 - 2022-10-29/b29c94d72ee74c6d94b573d90020ea59");
  47. // System.out.println("解密后的明文是:" + SecretKeyUtil.AESDncode("3fc674da58", str));
  48. Long deptId = ShiroUtils.getSysUser().getDept().getDeptId();
  49. String deptName = ShiroUtils.getSysUser().getDept().getDeptName();
  50. TUInterfaceinfo tuInterfaceinfo = tUInterfaceinfoMapper.selectTUInterfaceinfoById(id);
  51. List<IntDetailed> intDetailedList = intRecordMapper.selectIntDetailedByIntId(id);
  52. if(intDetailedList.size() == 0){
  53. IntDetailed detailed = new IntDetailed();
  54. String purpose = "";
  55. String shrareType = tuInterfaceinfo.getShareType();
  56. String interfaceName = tuInterfaceinfo.getInterfaceName();
  57. switch (shrareType){
  58. case "share_type_2":
  59. purpose = "市归集接口申请密钥:" + interfaceName;
  60. break;
  61. case "share_type_3":
  62. purpose = "省上报接口申请密钥:" + interfaceName;
  63. }
  64. String secretKey = SecretKeyUtil.AESEncode("3fc674da58", deptId + "/" + deptName + "/2022-12-02 - 2099-12-31/" + id);
  65. detailed.setIntId(id);
  66. detailed.setPurpose(purpose);
  67. detailed.setSecretKey(secretKey);
  68. detailed.setCode(tuInterfaceinfo.getCode());
  69. if(!purpose.equals("")){
  70. intRecordMapper.insertIntDetailed(detailed);
  71. tuInterfaceinfo.setSecretKey(secretKey);
  72. }
  73. }else {
  74. tuInterfaceinfo.setSecretKey(intDetailedList.get(0).getSecretKey());
  75. }
  76. return tuInterfaceinfo;
  77. }
  78. /**
  79. * 查询【接口应用审批管理】列表
  80. *
  81. * @param tUInterfaceinfo 【接口应用审批管理】
  82. * @return 【接口应用审批管理】
  83. */
  84. @Override
  85. public List<TUInterfaceinfo> selectTUInterfaceinfoList(TUInterfaceinfo tUInterfaceinfo)
  86. {
  87. List<TUInterfaceinfo> list = tUInterfaceinfoMapper.selectTUInterfaceinfoList(tUInterfaceinfo);
  88. list.forEach((i) -> i.setCount(sum(i.getCallsuccnum(),i.getCallfailnum())));
  89. return list;
  90. }
  91. private String sum(Long a, Long b){
  92. Long count = a + b;
  93. return NumberUtils.amountConversion(Integer.parseInt(count.toString()));
  94. }
  95. /**
  96. * 根据接口IDS获取接口LIST
  97. * */
  98. @Override
  99. public List<TUInterfaceinfo> selectTUInterfaceinfoList(String[] ids){
  100. return tUInterfaceinfoMapper.selectTUInterfaceinfoListByIds(ids);
  101. }
  102. /**
  103. * 根据数据应用IDS获取数据应用LIST
  104. * */
  105. @Override
  106. public List<TUInterfaceinfo> selectTUInterfaceDataList(String[] ids){
  107. return tUInterfaceinfoMapper.selectTUInterfaceDataListByIds(ids);
  108. }
  109. /**
  110. * 新增【接口应用审批管理】
  111. *
  112. * @param tUInterfaceinfo 【接口应用审批管理】
  113. * @return 结果
  114. */
  115. @Override
  116. public int insertTUInterfaceinfo(TUInterfaceinfo tUInterfaceinfo)
  117. {
  118. tUInterfaceinfo.setId(UUID.fastUUID().toString());
  119. tUInterfaceinfo.setCreateTime(DateUtils.getNowDate());
  120. //计算code 5位
  121. Integer integer = tUInterfaceinfoMapper.getMaxCode();
  122. if(integer == null){
  123. tUInterfaceinfo.setCode("00001");
  124. }else{
  125. Integer i = integer+1;
  126. int w =getW(i);
  127. String r = String.valueOf(i);
  128. for(int k=0;k<5-w;k++){
  129. r = "0"+r;
  130. }
  131. tUInterfaceinfo.setCode(r);
  132. }
  133. return tUInterfaceinfoMapper.insertTUInterfaceinfo(tUInterfaceinfo);
  134. }
  135. public static int getW(Integer i){
  136. for(int k=1;k<=5;k++){
  137. if(i/ (int)Math.pow(10,k) == 0){
  138. return k;
  139. }
  140. }
  141. return 0;
  142. }
  143. /**
  144. * 修改【接口应用审批管理】
  145. *
  146. * @param tUInterfaceinfo 【接口应用审批管理】
  147. * @return 结果
  148. */
  149. @Override
  150. public int updateTUInterfaceinfo(TUInterfaceinfo tUInterfaceinfo)
  151. {
  152. tUInterfaceinfo.setUpdateTime(DateUtils.getNowDate());
  153. return tUInterfaceinfoMapper.updateTUInterfaceinfo(tUInterfaceinfo);
  154. }
  155. /**
  156. * 删除【接口应用审批管理】对象
  157. *
  158. * @param ids 需要删除的数据ID
  159. * @return 结果
  160. */
  161. @Override
  162. public int deleteTUInterfaceinfoByIds(String ids)
  163. {
  164. return tUInterfaceinfoMapper.deleteTUInterfaceinfoByIds(Convert.toStrArray(ids));
  165. }
  166. /**
  167. * 删除【接口应用审批管理】信息
  168. *
  169. * @param id 【接口应用审批管理】ID
  170. * @return 结果
  171. */
  172. @Override
  173. public int deleteTUInterfaceinfoById(String id)
  174. {
  175. return tUInterfaceinfoMapper.deleteTUInterfaceinfoById(id);
  176. }
  177. /**
  178. * 刷新数据
  179. */
  180. @Override
  181. public void refreshData(){
  182. //(164-57) t_guiji_gas_zenner_gas_purchase_center_infor - 归集-市燃气(真兰收费系统)-中心计费购气信息 - 467184 ms total:[12746163]
  183. //(123-29) t_guiji_gas_zenner_meter_reading_infor - 归集-市燃气(真兰收费系统)-抄表信息 - 324043 ms total:[12703733]
  184. //t_guiji_naturalresources_bdcdjxx - 归集-市自然资源(不动产)-个人基本信息 - updating database... id = 672238a3-3687-433c-888e-5db0c81eb8a8
  185. TUInterfaceinfo param = new TUInterfaceinfo();
  186. param.setNeedRefresh("1");
  187. List<TUInterfaceinfo> tuInterfaceinfoList = tUInterfaceinfoMapper.selectTUInterfaceinfoList(param);
  188. for (int i = 0; i < tuInterfaceinfoList.size(); i++) {
  189. TUInterfaceinfo tuInterfaceinfo = tuInterfaceinfoList.get(i);
  190. String tableName = tuInterfaceinfo.getTableName();
  191. if(tableName == null || tableName.equals("")){
  192. System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + 0 + " ms");
  193. continue;
  194. }
  195. System.out.println(tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + "updating database... id = " + tuInterfaceinfo.getId());
  196. //select count(id) callsuccnum from ${tableName}
  197. Date dateBegin = new Date();
  198. TUInterfaceinfo result = tUInterfaceinfoMapper.selectCountByTableName(tuInterfaceinfo);
  199. Long interval = new Date().getTime() - dateBegin.getTime();//接口查询总数所用时间
  200. System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + interval + " ms total:[" + result.getCallsuccnum() + "]");
  201. tuInterfaceinfo.setCallsuccnum(result.getCallsuccnum());
  202. tuInterfaceinfo.setRefreshTime(new Date());
  203. tuInterfaceinfo.setNeedRefresh("2");
  204. tUInterfaceinfoMapper.updateInterfaceCallsuccnum(tuInterfaceinfo);
  205. //update t_u_interfaceinfo set callsuccnum = #{callsuccnum} where id = #{id}
  206. }
  207. }
  208. /**
  209. * 刷新归集数据分析
  210. */
  211. @Override
  212. public void imputationData(){
  213. Long[] calendar = new Long[13];
  214. calendar[1] = 0L;
  215. calendar[2] = 0L;
  216. calendar[3] = 0L;
  217. calendar[4] = 0L;
  218. calendar[5] = 0L;
  219. calendar[6] = 0L;
  220. calendar[7] = 0L;
  221. calendar[8] = 0L;
  222. calendar[9] = 0L;
  223. calendar[10] = 0L;
  224. calendar[11] = 0L;
  225. calendar[12] = 0L;
  226. TUInterfaceinfo param = new TUInterfaceinfo();
  227. // param.setNeedRefresh("1");
  228. List<TUInterfaceinfo> tuInterfaceinfoList = tUInterfaceinfoMapper.selectTUInterfaceinfoList(param);
  229. for (int i = 0; i < tuInterfaceinfoList.size(); i++) {
  230. TUInterfaceinfo tuInterfaceinfo = tuInterfaceinfoList.get(i);
  231. String tableName = tuInterfaceinfo.getTableName();
  232. if (tableName == null || tableName.equals("")) {
  233. System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + 0 + " ms");
  234. continue;
  235. }
  236. Map map = new HashMap();
  237. map.put("year", "2020");
  238. map.put("tableName", tableName);
  239. System.out.println(tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + "updating database... id = " + tuInterfaceinfo.getId());
  240. Date dateBegin = new Date();
  241. ImputationData imputationData = tUInterfaceinfoMapper.imputationData(map);
  242. Long interval = new Date().getTime() - dateBegin.getTime();//接口查询总数所用时间
  243. calendar[1] += Long.valueOf(imputationData.getJan());
  244. calendar[2] += Long.valueOf(imputationData.getFeb());
  245. calendar[3] += Long.valueOf(imputationData.getMar());
  246. calendar[4] += Long.valueOf(imputationData.getApr());
  247. calendar[5] += Long.valueOf(imputationData.getMay());
  248. calendar[6] += Long.valueOf(imputationData.getJun());
  249. calendar[7] += Long.valueOf(imputationData.getJul());
  250. calendar[8] += Long.valueOf(imputationData.getAug());
  251. calendar[9] += Long.valueOf(imputationData.getSep());
  252. calendar[10] += Long.valueOf(imputationData.getOct());
  253. calendar[11] += Long.valueOf(imputationData.getNov());
  254. calendar[12] += Long.valueOf(imputationData.getDecb());
  255. System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + interval + " ms");
  256. tuInterfaceinfo.setRefreshTime(new Date());
  257. // tuInterfaceinfo.setNeedRefresh("2");
  258. // tUInterfaceinfoMapper.updateInterfaceCallsuccnum(tuInterfaceinfo);
  259. //update t_u_interfaceinfo set callsuccnum = #{callsuccnum} where id = #{id}
  260. }
  261. ImputationData imputationData = new ImputationData();
  262. imputationData.setYear("2020");
  263. imputationData.setJan(calendar[1].toString());
  264. imputationData.setFeb(calendar[2].toString());
  265. imputationData.setMar(calendar[3].toString());
  266. imputationData.setApr(calendar[4].toString());
  267. imputationData.setMay(calendar[5].toString());
  268. imputationData.setJun(calendar[6].toString());
  269. imputationData.setJul(calendar[7].toString());
  270. imputationData.setAug(calendar[8].toString());
  271. imputationData.setSep(calendar[9].toString());
  272. imputationData.setOct(calendar[10].toString());
  273. imputationData.setNov(calendar[11].toString());
  274. imputationData.setDecb(calendar[12].toString());
  275. imputationDataMapper.updateImputationData(imputationData);
  276. }
  277. /**
  278. * 查询接口数量
  279. * @return 结果
  280. */
  281. @Override
  282. public List<TUInterfaceinfo> getCount(){
  283. return tUInterfaceinfoMapper.getCount();
  284. }
  285. /**
  286. * 查询接口占比
  287. * @return 结果
  288. */
  289. @Override
  290. public List<TUInterfaceinfo> getPercent(String year){
  291. return tUInterfaceinfoMapper.getPercent(year);
  292. }
  293. /**
  294. * 查询接口占比
  295. * @return 结果
  296. */
  297. @Override
  298. public List<TUInterfaceinfo> getSubPercent(String deptId, String year){
  299. return tUInterfaceinfoMapper.getSubPercent(deptId,year);
  300. }
  301. /**
  302. * 接口审批分析
  303. * @return 结果
  304. */
  305. @Override
  306. public TUInterfaceinfo getSubJkspfx(String deptId, String year){
  307. return tUInterfaceinfoMapper.getSubJkspfx(deptId, year);
  308. }
  309. /**
  310. * 审批分析
  311. * @return 结果
  312. */
  313. @Override
  314. public TUInterfaceinfo getSubSpfx(String deptId, String year){
  315. return tUInterfaceinfoMapper.getSubSpfx(deptId, year);
  316. }
  317. /**
  318. * 查询省接口调用频次TOP5
  319. * @return 结果
  320. */
  321. @Override
  322. public List<TUInterfaceinfo> getProvinceTop5Frequency(){
  323. return tUInterfaceinfoMapper.getProvinceTop5Frequency();
  324. }
  325. /**
  326. * 查询市接口调用频次TOP5
  327. * @return 结果
  328. */
  329. @Override
  330. public List<TUInterfaceinfo> getCityTop5Frequency(){
  331. return tUInterfaceinfoMapper.getCityTop5Frequency();
  332. }
  333. /**
  334. * 查询省接口调用频次TOP20
  335. * @return 结果
  336. */
  337. @Override
  338. public List<TUInterfaceinfo> getProvinceTop20Frequency(){
  339. return tUInterfaceinfoMapper.getProvinceTop20Frequency();
  340. }
  341. /**
  342. * 查询市接口调用频次TOP20
  343. * @return 结果
  344. */
  345. @Override
  346. public List<TUInterfaceinfo> getCityTop20Frequency(){
  347. return tUInterfaceinfoMapper.getCityTop20Frequency();
  348. }
  349. /**
  350. * 查询归集接口排名
  351. */
  352. @Override
  353. public List<TUInterfaceinfo> getImputationInterfaceRanking(){
  354. return tUInterfaceinfoMapper.getImputationInterfaceRanking();
  355. }
  356. /**
  357. * 查询归集数据排名
  358. */
  359. @Override
  360. public List<TUInterfaceinfo> getImputationDataRanking(){
  361. return tUInterfaceinfoMapper.getImputationDataRanking();
  362. }
  363. /**
  364. * 查询故障接口数量
  365. * @return 结果
  366. * */
  367. @Override
  368. public Integer getInterfaceCount(String status){
  369. return tUInterfaceinfoMapper.getInterfaceCount(status);
  370. }
  371. /**
  372. * 根据部门ID查询分类数量
  373. * @return 结果
  374. * */
  375. @Override
  376. public TUInterfaceinfo getShareCountByDeptId(String deptId){
  377. return tUInterfaceinfoMapper.getShareCountByDeptId(deptId);
  378. }
  379. @Override
  380. public Long getGuijiCountByDeptId(String deptId){
  381. new Thread() {
  382. public void run() {
  383. try{
  384. TUInterfaceinfo tuInterfaceinfo = new TUInterfaceinfo();
  385. tuInterfaceinfo.setDeptId(deptId);
  386. tuInterfaceinfo.setStatus("0");//状态(0可用,2禁用)
  387. /*
  388. t_guiji_gas_zenner_gas_purchase_center_infor 真兰中心计费信息
  389. */
  390. List<TUInterfaceinfo> tuInterfaceinfoList = tUInterfaceinfoMapper.selectTUInterfaceinfoDataNumList(tuInterfaceinfo);
  391. for (int i = 0; i < tuInterfaceinfoList.size(); i ++) {
  392. TUInterfaceinfo interfaceinfo = tuInterfaceinfoList.get(i);
  393. boolean uninitialized = interfaceinfo.getUpdateTime() == null;//未初始化
  394. boolean oldData = interfaceinfo.getUpdateTime() != null && new Date().getTime() - interfaceinfo.getUpdateTime().getTime() > 10 * 60 * 1000;//最多10分钟刷新一次最新数据
  395. boolean isValid = interfaceinfo.getStatus().equals("0");//有效数据
  396. if(uninitialized || (oldData && isValid)){
  397. interfaceinfo.setUpdateTime(new Date());
  398. Date dateBegin = new Date();
  399. tUInterfaceinfoMapper.updateTUInterfaceinfoDataNum(interfaceinfo);//更新更新时间 防止多次操作
  400. System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + interfaceinfo.getInterfaceName() + "更新更新时间 防止多次操作");
  401. tUInterfaceinfoMapper.updateDataNum(interfaceinfo);//更新更新时间为最新的以及数据条数
  402. Long interval = new Date().getTime() - dateBegin.getTime();//接口查询总数所用时间
  403. System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + interfaceinfo.getTableName() + " - " + interfaceinfo.getInterfaceName() + " - " + interval + " ms");
  404. // update t_u_interfaceinfo_datanum set datanum = 0, update_time = null 重置数据总数重新查询 使用updateTime控制min分钟内只能查询一次
  405. // select count(*) from t_guiji_gas_zenner_gas_purchase_center_infor - 归集-真兰收费系统-中心计费购气信息 12452820
  406. // (17-4) t_guiji_gas_zenner_gas_purchase_center_infor - 归集-真兰收费系统-中心计费购气信息 - 32424 ms
  407. // (17-5) t_guiji_gas_zenner_meter_reading_infor - 归集-真兰收费系统-抄表信息 - 222659 ms
  408. /*
  409. update t_u_interfaceinfo_datanum set datanum = 0, update_time = null;
  410. update t_u_interfaceinfo_datanum set status = 2 where table_name = 't_guiji_gas_zenner_gas_purchase_center_infor'; -- 12489514 17ms
  411. update t_u_interfaceinfo_datanum set status = 2 where table_name = 't_guiji_gas_zenner_meter_reading_infor'; -- 12389252 23ms
  412. */
  413. // 燃气 25010409 26114283
  414. }
  415. }
  416. System.out.println((tuInterfaceinfoList.size()>0?tuInterfaceinfoList.get(0).getDeptName():deptId)+": 查询接口数据结束,共" + tuInterfaceinfoList.size() + "个接口");
  417. }catch (Exception e){
  418. e.printStackTrace();
  419. }
  420. }
  421. }.start();
  422. Map<String, Object> param = new HashMap<>();
  423. param.put("deptId", deptId);
  424. tUInterfaceinfoMapper.getGuijiCountByDeptId(param);
  425. return Long.valueOf(String.valueOf(param.get("count"))).longValue();
  426. }
  427. /**
  428. * 接口调用频次
  429. * @return 结果
  430. * */
  431. @Override
  432. public int callFrequency(){
  433. return tUInterfaceinfoMapper.callFrequency();
  434. }
  435. /**
  436. * 接口归集频次
  437. * @return 结果
  438. * */
  439. @Override
  440. public int pushFrequency(){
  441. return tUInterfaceinfoMapper.pushFrequency();
  442. }
  443. /**
  444. * 接口共享频次
  445. * @return 结果
  446. * */
  447. @Override
  448. public int pullFrequency(){
  449. return tUInterfaceinfoMapper.pullFrequency();
  450. }
  451. /**
  452. * 查询接口日志台账
  453. * @return 结果
  454. */
  455. @Override
  456. public List<TUInterfaceinfo> interfaceLogList(TUInterfaceinfo interfaceinfo){
  457. return tUInterfaceinfoMapper.interfaceLogList(interfaceinfo);
  458. }
  459. /**
  460. * 查询共享应用分析
  461. * @return 结果
  462. */
  463. @Override
  464. public List<TUInterfaceinfo> getCallNumByDept(Long deptId){
  465. return tUInterfaceinfoMapper.getCallNumByDept(deptId);
  466. }
  467. }