123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507 |
- package com.sooka.system.service.impl;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import com.business.domain.ImputationData;
- import com.business.mapper.ImputationDataMapper;
- import com.sooka.apply.domain.IntDetailed;
- import com.sooka.apply.mapper.IntRecordMapper;
- import com.sooka.common.core.text.Convert;
- import com.sooka.common.utils.DateUtils;
- import com.sooka.common.utils.uuid.UUID;
- import com.sooka.framework.util.ShiroUtils;
- import com.util.NumberUtils;
- import com.util.SecretKeyUtil;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import com.sooka.system.mapper.TUInterfaceinfoMapper;
- import com.sooka.system.domain.TUInterfaceinfo;
- import com.sooka.system.service.ITUInterfaceinfoService;
- import javax.annotation.Resource;
- /**
- * 【接口应用审批管理】Service业务层处理
- *
- * @author lei
- * @date 2021-07-01
- */
- @Service
- public class TUInterfaceinfoServiceImpl implements ITUInterfaceinfoService
- {
- @Resource
- private TUInterfaceinfoMapper tUInterfaceinfoMapper;
- @Resource
- private ImputationDataMapper imputationDataMapper;
- @Resource
- private IntRecordMapper intRecordMapper;
- /**
- * 查询【接口应用审批管理】
- *
- * @param id 【接口应用审批管理】ID
- * @return 【接口应用审批管理】
- */
- @Override
- public TUInterfaceinfo selectTUInterfaceinfoById(String id)
- {
- // String str = SecretKeyUtil.AESEncode("3fc674da58", "123/政数局/2022-10-20 - 2022-10-29/b29c94d72ee74c6d94b573d90020ea59");
- // System.out.println("解密后的明文是:" + SecretKeyUtil.AESDncode("3fc674da58", str));
- Long deptId = ShiroUtils.getSysUser().getDept().getDeptId();
- String deptName = ShiroUtils.getSysUser().getDept().getDeptName();
- TUInterfaceinfo tuInterfaceinfo = tUInterfaceinfoMapper.selectTUInterfaceinfoById(id);
- List<IntDetailed> intDetailedList = intRecordMapper.selectIntDetailedByIntId(id);
- if(intDetailedList.size() == 0){
- IntDetailed detailed = new IntDetailed();
- String purpose = "";
- String shrareType = tuInterfaceinfo.getShareType();
- String interfaceName = tuInterfaceinfo.getInterfaceName();
- switch (shrareType){
- case "share_type_2":
- purpose = "市归集接口申请密钥:" + interfaceName;
- break;
- case "share_type_3":
- purpose = "省上报接口申请密钥:" + interfaceName;
- }
- String secretKey = SecretKeyUtil.AESEncode("3fc674da58", deptId + "/" + deptName + "/2022-12-02 - 2099-12-31/" + id);
- detailed.setIntId(id);
- detailed.setPurpose(purpose);
- detailed.setSecretKey(secretKey);
- detailed.setCode(tuInterfaceinfo.getCode());
- if(!purpose.equals("")){
- intRecordMapper.insertIntDetailed(detailed);
- tuInterfaceinfo.setSecretKey(secretKey);
- }
- }else {
- tuInterfaceinfo.setSecretKey(intDetailedList.get(0).getSecretKey());
- }
- return tuInterfaceinfo;
- }
- /**
- * 查询【接口应用审批管理】列表
- *
- * @param tUInterfaceinfo 【接口应用审批管理】
- * @return 【接口应用审批管理】
- */
- @Override
- public List<TUInterfaceinfo> selectTUInterfaceinfoList(TUInterfaceinfo tUInterfaceinfo)
- {
- List<TUInterfaceinfo> list = tUInterfaceinfoMapper.selectTUInterfaceinfoList(tUInterfaceinfo);
- list.forEach((i) -> i.setCount(sum(i.getCallsuccnum(),i.getCallfailnum())));
- return list;
- }
- private String sum(Long a, Long b){
- Long count = a + b;
- return NumberUtils.amountConversion(Integer.parseInt(count.toString()));
- }
- /**
- * 根据接口IDS获取接口LIST
- * */
- @Override
- public List<TUInterfaceinfo> selectTUInterfaceinfoList(String[] ids){
- return tUInterfaceinfoMapper.selectTUInterfaceinfoListByIds(ids);
- }
- /**
- * 根据数据应用IDS获取数据应用LIST
- * */
- @Override
- public List<TUInterfaceinfo> selectTUInterfaceDataList(String[] ids){
- return tUInterfaceinfoMapper.selectTUInterfaceDataListByIds(ids);
- }
- /**
- * 新增【接口应用审批管理】
- *
- * @param tUInterfaceinfo 【接口应用审批管理】
- * @return 结果
- */
- @Override
- public int insertTUInterfaceinfo(TUInterfaceinfo tUInterfaceinfo)
- {
- tUInterfaceinfo.setId(UUID.fastUUID().toString());
- tUInterfaceinfo.setCreateTime(DateUtils.getNowDate());
- //计算code 5位
- Integer integer = tUInterfaceinfoMapper.getMaxCode();
- if(integer == null){
- tUInterfaceinfo.setCode("00001");
- }else{
- Integer i = integer+1;
- int w =getW(i);
- String r = String.valueOf(i);
- for(int k=0;k<5-w;k++){
- r = "0"+r;
- }
- tUInterfaceinfo.setCode(r);
- }
- return tUInterfaceinfoMapper.insertTUInterfaceinfo(tUInterfaceinfo);
- }
- public static int getW(Integer i){
- for(int k=1;k<=5;k++){
- if(i/ (int)Math.pow(10,k) == 0){
- return k;
- }
- }
- return 0;
- }
- /**
- * 修改【接口应用审批管理】
- *
- * @param tUInterfaceinfo 【接口应用审批管理】
- * @return 结果
- */
- @Override
- public int updateTUInterfaceinfo(TUInterfaceinfo tUInterfaceinfo)
- {
- tUInterfaceinfo.setUpdateTime(DateUtils.getNowDate());
- return tUInterfaceinfoMapper.updateTUInterfaceinfo(tUInterfaceinfo);
- }
- /**
- * 删除【接口应用审批管理】对象
- *
- * @param ids 需要删除的数据ID
- * @return 结果
- */
- @Override
- public int deleteTUInterfaceinfoByIds(String ids)
- {
- return tUInterfaceinfoMapper.deleteTUInterfaceinfoByIds(Convert.toStrArray(ids));
- }
- /**
- * 删除【接口应用审批管理】信息
- *
- * @param id 【接口应用审批管理】ID
- * @return 结果
- */
- @Override
- public int deleteTUInterfaceinfoById(String id)
- {
- return tUInterfaceinfoMapper.deleteTUInterfaceinfoById(id);
- }
- /**
- * 刷新数据
- */
- @Override
- public void refreshData(){
- //(164-57) t_guiji_gas_zenner_gas_purchase_center_infor - 归集-市燃气(真兰收费系统)-中心计费购气信息 - 467184 ms total:[12746163]
- //(123-29) t_guiji_gas_zenner_meter_reading_infor - 归集-市燃气(真兰收费系统)-抄表信息 - 324043 ms total:[12703733]
- //t_guiji_naturalresources_bdcdjxx - 归集-市自然资源(不动产)-个人基本信息 - updating database... id = 672238a3-3687-433c-888e-5db0c81eb8a8
- TUInterfaceinfo param = new TUInterfaceinfo();
- param.setNeedRefresh("1");
- List<TUInterfaceinfo> tuInterfaceinfoList = tUInterfaceinfoMapper.selectTUInterfaceinfoList(param);
- for (int i = 0; i < tuInterfaceinfoList.size(); i++) {
- TUInterfaceinfo tuInterfaceinfo = tuInterfaceinfoList.get(i);
- String tableName = tuInterfaceinfo.getTableName();
- if(tableName == null || tableName.equals("")){
- System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + 0 + " ms");
- continue;
- }
- System.out.println(tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + "updating database... id = " + tuInterfaceinfo.getId());
- //select count(id) callsuccnum from ${tableName}
- Date dateBegin = new Date();
- TUInterfaceinfo result = tUInterfaceinfoMapper.selectCountByTableName(tuInterfaceinfo);
- Long interval = new Date().getTime() - dateBegin.getTime();//接口查询总数所用时间
- System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + interval + " ms total:[" + result.getCallsuccnum() + "]");
- tuInterfaceinfo.setCallsuccnum(result.getCallsuccnum());
- tuInterfaceinfo.setRefreshTime(new Date());
- tuInterfaceinfo.setNeedRefresh("2");
- tUInterfaceinfoMapper.updateInterfaceCallsuccnum(tuInterfaceinfo);
- //update t_u_interfaceinfo set callsuccnum = #{callsuccnum} where id = #{id}
- }
- }
- /**
- * 刷新归集数据分析
- */
- @Override
- public void imputationData(){
- Long[] calendar = new Long[13];
- calendar[1] = 0L;
- calendar[2] = 0L;
- calendar[3] = 0L;
- calendar[4] = 0L;
- calendar[5] = 0L;
- calendar[6] = 0L;
- calendar[7] = 0L;
- calendar[8] = 0L;
- calendar[9] = 0L;
- calendar[10] = 0L;
- calendar[11] = 0L;
- calendar[12] = 0L;
- TUInterfaceinfo param = new TUInterfaceinfo();
- // param.setNeedRefresh("1");
- List<TUInterfaceinfo> tuInterfaceinfoList = tUInterfaceinfoMapper.selectTUInterfaceinfoList(param);
- for (int i = 0; i < tuInterfaceinfoList.size(); i++) {
- TUInterfaceinfo tuInterfaceinfo = tuInterfaceinfoList.get(i);
- String tableName = tuInterfaceinfo.getTableName();
- if (tableName == null || tableName.equals("")) {
- System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + 0 + " ms");
- continue;
- }
- Map map = new HashMap();
- map.put("year", "2020");
- map.put("tableName", tableName);
- System.out.println(tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + "updating database... id = " + tuInterfaceinfo.getId());
- Date dateBegin = new Date();
- ImputationData imputationData = tUInterfaceinfoMapper.imputationData(map);
- Long interval = new Date().getTime() - dateBegin.getTime();//接口查询总数所用时间
- calendar[1] += Long.valueOf(imputationData.getJan());
- calendar[2] += Long.valueOf(imputationData.getFeb());
- calendar[3] += Long.valueOf(imputationData.getMar());
- calendar[4] += Long.valueOf(imputationData.getApr());
- calendar[5] += Long.valueOf(imputationData.getMay());
- calendar[6] += Long.valueOf(imputationData.getJun());
- calendar[7] += Long.valueOf(imputationData.getJul());
- calendar[8] += Long.valueOf(imputationData.getAug());
- calendar[9] += Long.valueOf(imputationData.getSep());
- calendar[10] += Long.valueOf(imputationData.getOct());
- calendar[11] += Long.valueOf(imputationData.getNov());
- calendar[12] += Long.valueOf(imputationData.getDecb());
- System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + tuInterfaceinfo.getTableName() + " - " + tuInterfaceinfo.getInterfaceName() + " - " + interval + " ms");
- tuInterfaceinfo.setRefreshTime(new Date());
- // tuInterfaceinfo.setNeedRefresh("2");
- // tUInterfaceinfoMapper.updateInterfaceCallsuccnum(tuInterfaceinfo);
- //update t_u_interfaceinfo set callsuccnum = #{callsuccnum} where id = #{id}
- }
- ImputationData imputationData = new ImputationData();
- imputationData.setYear("2020");
- imputationData.setJan(calendar[1].toString());
- imputationData.setFeb(calendar[2].toString());
- imputationData.setMar(calendar[3].toString());
- imputationData.setApr(calendar[4].toString());
- imputationData.setMay(calendar[5].toString());
- imputationData.setJun(calendar[6].toString());
- imputationData.setJul(calendar[7].toString());
- imputationData.setAug(calendar[8].toString());
- imputationData.setSep(calendar[9].toString());
- imputationData.setOct(calendar[10].toString());
- imputationData.setNov(calendar[11].toString());
- imputationData.setDecb(calendar[12].toString());
- imputationDataMapper.updateImputationData(imputationData);
- }
- /**
- * 查询接口数量
- * @return 结果
- */
- @Override
- public List<TUInterfaceinfo> getCount(){
- return tUInterfaceinfoMapper.getCount();
- }
- /**
- * 查询接口占比
- * @return 结果
- */
- @Override
- public List<TUInterfaceinfo> getPercent(String year){
- return tUInterfaceinfoMapper.getPercent(year);
- }
- /**
- * 查询接口占比
- * @return 结果
- */
- @Override
- public List<TUInterfaceinfo> getSubPercent(String deptId, String year){
- return tUInterfaceinfoMapper.getSubPercent(deptId,year);
- }
- /**
- * 接口审批分析
- * @return 结果
- */
- @Override
- public TUInterfaceinfo getSubJkspfx(String deptId, String year){
- return tUInterfaceinfoMapper.getSubJkspfx(deptId, year);
- }
- /**
- * 审批分析
- * @return 结果
- */
- @Override
- public TUInterfaceinfo getSubSpfx(String deptId, String year){
- return tUInterfaceinfoMapper.getSubSpfx(deptId, year);
- }
- /**
- * 查询省接口调用频次TOP5
- * @return 结果
- */
- @Override
- public List<TUInterfaceinfo> getProvinceTop5Frequency(){
- return tUInterfaceinfoMapper.getProvinceTop5Frequency();
- }
- /**
- * 查询市接口调用频次TOP5
- * @return 结果
- */
- @Override
- public List<TUInterfaceinfo> getCityTop5Frequency(){
- return tUInterfaceinfoMapper.getCityTop5Frequency();
- }
- /**
- * 查询省接口调用频次TOP20
- * @return 结果
- */
- @Override
- public List<TUInterfaceinfo> getProvinceTop20Frequency(){
- return tUInterfaceinfoMapper.getProvinceTop20Frequency();
- }
- /**
- * 查询市接口调用频次TOP20
- * @return 结果
- */
- @Override
- public List<TUInterfaceinfo> getCityTop20Frequency(){
- return tUInterfaceinfoMapper.getCityTop20Frequency();
- }
- /**
- * 查询归集接口排名
- */
- @Override
- public List<TUInterfaceinfo> getImputationInterfaceRanking(){
- return tUInterfaceinfoMapper.getImputationInterfaceRanking();
- }
- /**
- * 查询归集数据排名
- */
- @Override
- public List<TUInterfaceinfo> getImputationDataRanking(){
- return tUInterfaceinfoMapper.getImputationDataRanking();
- }
- /**
- * 查询故障接口数量
- * @return 结果
- * */
- @Override
- public Integer getInterfaceCount(String status){
- return tUInterfaceinfoMapper.getInterfaceCount(status);
- }
- /**
- * 根据部门ID查询分类数量
- * @return 结果
- * */
- @Override
- public TUInterfaceinfo getShareCountByDeptId(String deptId){
- return tUInterfaceinfoMapper.getShareCountByDeptId(deptId);
- }
- @Override
- public Long getGuijiCountByDeptId(String deptId){
- new Thread() {
- public void run() {
- try{
- TUInterfaceinfo tuInterfaceinfo = new TUInterfaceinfo();
- tuInterfaceinfo.setDeptId(deptId);
- tuInterfaceinfo.setStatus("0");//状态(0可用,2禁用)
- /*
- t_guiji_gas_zenner_gas_purchase_center_infor 真兰中心计费信息
- */
- List<TUInterfaceinfo> tuInterfaceinfoList = tUInterfaceinfoMapper.selectTUInterfaceinfoDataNumList(tuInterfaceinfo);
- for (int i = 0; i < tuInterfaceinfoList.size(); i ++) {
- TUInterfaceinfo interfaceinfo = tuInterfaceinfoList.get(i);
- boolean uninitialized = interfaceinfo.getUpdateTime() == null;//未初始化
- boolean oldData = interfaceinfo.getUpdateTime() != null && new Date().getTime() - interfaceinfo.getUpdateTime().getTime() > 10 * 60 * 1000;//最多10分钟刷新一次最新数据
- boolean isValid = interfaceinfo.getStatus().equals("0");//有效数据
- if(uninitialized || (oldData && isValid)){
- interfaceinfo.setUpdateTime(new Date());
- Date dateBegin = new Date();
- tUInterfaceinfoMapper.updateTUInterfaceinfoDataNum(interfaceinfo);//更新更新时间 防止多次操作
- System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + interfaceinfo.getInterfaceName() + "更新更新时间 防止多次操作");
- tUInterfaceinfoMapper.updateDataNum(interfaceinfo);//更新更新时间为最新的以及数据条数
- Long interval = new Date().getTime() - dateBegin.getTime();//接口查询总数所用时间
- System.out.println("(" + tuInterfaceinfoList.size() + "-" + (i + 1) + ") " + interfaceinfo.getTableName() + " - " + interfaceinfo.getInterfaceName() + " - " + interval + " ms");
- // update t_u_interfaceinfo_datanum set datanum = 0, update_time = null 重置数据总数重新查询 使用updateTime控制min分钟内只能查询一次
- // select count(*) from t_guiji_gas_zenner_gas_purchase_center_infor - 归集-真兰收费系统-中心计费购气信息 12452820
- // (17-4) t_guiji_gas_zenner_gas_purchase_center_infor - 归集-真兰收费系统-中心计费购气信息 - 32424 ms
- // (17-5) t_guiji_gas_zenner_meter_reading_infor - 归集-真兰收费系统-抄表信息 - 222659 ms
- /*
- update t_u_interfaceinfo_datanum set datanum = 0, update_time = null;
- update t_u_interfaceinfo_datanum set status = 2 where table_name = 't_guiji_gas_zenner_gas_purchase_center_infor'; -- 12489514 17ms
- update t_u_interfaceinfo_datanum set status = 2 where table_name = 't_guiji_gas_zenner_meter_reading_infor'; -- 12389252 23ms
- */
- // 燃气 25010409 26114283
- }
- }
- System.out.println((tuInterfaceinfoList.size()>0?tuInterfaceinfoList.get(0).getDeptName():deptId)+": 查询接口数据结束,共" + tuInterfaceinfoList.size() + "个接口");
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- }.start();
- Map<String, Object> param = new HashMap<>();
- param.put("deptId", deptId);
- tUInterfaceinfoMapper.getGuijiCountByDeptId(param);
- return Long.valueOf(String.valueOf(param.get("count"))).longValue();
- }
- /**
- * 接口调用频次
- * @return 结果
- * */
- @Override
- public int callFrequency(){
- return tUInterfaceinfoMapper.callFrequency();
- }
- /**
- * 接口归集频次
- * @return 结果
- * */
- @Override
- public int pushFrequency(){
- return tUInterfaceinfoMapper.pushFrequency();
- }
- /**
- * 接口共享频次
- * @return 结果
- * */
- @Override
- public int pullFrequency(){
- return tUInterfaceinfoMapper.pullFrequency();
- }
- /**
- * 查询接口日志台账
- * @return 结果
- */
- @Override
- public List<TUInterfaceinfo> interfaceLogList(TUInterfaceinfo interfaceinfo){
- return tUInterfaceinfoMapper.interfaceLogList(interfaceinfo);
- }
- /**
- * 查询共享应用分析
- * @return 结果
- */
- @Override
- public List<TUInterfaceinfo> getCallNumByDept(Long deptId){
- return tUInterfaceinfoMapper.getCallNumByDept(deptId);
- }
- }
|