GyDataServiceImpl.java 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. package com.bootdo.datas.service.impl;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.bootdo.common.config.BootdoConfig;
  4. import com.bootdo.common.utils.*;
  5. import com.bootdo.datas.domain.ExpertOpinionDO;
  6. import com.bootdo.datas.dao.GyDataDao;
  7. import com.bootdo.datas.dao.GyUnitDao;
  8. import com.bootdo.datas.domain.*;
  9. import com.bootdo.datas.dto.ExamineLogDTO;
  10. import com.bootdo.datas.dto.GyDataImportDTO;
  11. import com.bootdo.datas.service.*;
  12. import com.bootdo.datas.tools.ExcelUtils;
  13. import com.bootdo.datas.tools.gm.FileCryptTool;
  14. import com.bootdo.system.domain.RoleDO;
  15. import com.bootdo.system.domain.UserDO;
  16. import com.bootdo.system.service.RoleService;
  17. import org.apache.poi.ss.usermodel.Cell;
  18. import org.apache.poi.ss.usermodel.CellType;
  19. import org.apache.poi.ss.usermodel.Row;
  20. import org.apache.poi.xssf.usermodel.XSSFSheet;
  21. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  22. import org.slf4j.Logger;
  23. import org.slf4j.LoggerFactory;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.beans.factory.annotation.Value;
  26. import org.springframework.stereotype.Service;
  27. import org.springframework.transaction.annotation.Transactional;
  28. import org.springframework.util.CollectionUtils;
  29. import org.springframework.util.ObjectUtils;
  30. import org.springframework.web.multipart.MultipartFile;
  31. import javax.servlet.http.HttpServletResponse;
  32. import java.io.*;
  33. import java.util.*;
  34. import java.util.function.Function;
  35. import java.util.stream.Collectors;
  36. @Service
  37. @Transactional
  38. public class GyDataServiceImpl implements GyDataService {
  39. @Autowired
  40. private BootdoConfig bootdoConfig;
  41. @Autowired
  42. private GyUnitDao gyUnitDao;
  43. @Autowired
  44. private GyDataDao gyDataDao;
  45. @Value("${managerValue}")
  46. public String managerValue;
  47. @Value("${deployType:#{null}}")
  48. public String deployType;
  49. @Value("${sysProvince:#{null}}")
  50. public String sysProvince;
  51. @Value("${sysCity:#{null}}")
  52. public String sysCity;
  53. @Autowired
  54. private ExamineLogService examineLogService;
  55. @Autowired
  56. private RoleService roleService;
  57. @Autowired
  58. private MessageHuNanService messageHuNanService;
  59. @Autowired
  60. private GyDataUnitService gyDataUnitService;
  61. private static Logger log = LoggerFactory.getLogger(GyDataServiceImpl.class);
  62. @Override
  63. public List<GyDataImportDTO> list(Map<String, Object> map) {
  64. UserDO currUser = ShiroUtils.getUser();
  65. log.info("currUser:" + currUser.toString());
  66. if(currUser.getDeptId() == null){
  67. throw new BDException("当前用户的部门id为空");
  68. }
  69. if (!managerValue.contains(currUser.getDeptId().toString())) {
  70. String province = currUser.getProvince();
  71. if(StringUtils.isEmpty(province)){
  72. province = sysProvince;
  73. }
  74. if(!ObjectUtils.isEmpty(province)) {
  75. map.put("unitProvince", province);
  76. }
  77. String city = currUser.getCity();
  78. if(StringUtils.isEmpty(city)){
  79. city = sysCity;
  80. }
  81. String gyUnitId = currUser.getGyUnitId();
  82. map.put("unitId", gyUnitId);
  83. if (!ObjectUtils.isEmpty(city)) {
  84. map.put("unitCity", city);
  85. if(!map.containsKey("auditStage")){
  86. map.put("auditStage", "1");
  87. }else{
  88. // 包含auditStage时检查值
  89. String value = (String) map.get("auditStage");
  90. if (value == null || value.trim().isEmpty()) {
  91. map.put("auditStage", "1");
  92. }
  93. }
  94. } else {
  95. if(!map.containsKey("auditStage")){
  96. map.put("auditStage", "2");
  97. }else{
  98. // 包含auditStage时检查值
  99. String value = (String) map.get("auditStage");
  100. if (value == null || value.trim().isEmpty()) {
  101. map.put("auditStage", "2");
  102. }
  103. }
  104. }
  105. }
  106. return this.dealDataWithCompany(gyDataDao.list(map));
  107. }
  108. /***
  109. * 处理查询出来的数据绑定企业信息
  110. * @param list
  111. * @return
  112. */
  113. List<GyDataImportDTO> dealDataWithCompany(List<GyDataImportDTO> list){
  114. // 使用Stream提取所有dataId
  115. List<Long> dataIds = list.stream()
  116. .map(GyDataImportDTO::getId)
  117. .collect(Collectors.toList());
  118. if (CollectionUtils.isEmpty(dataIds)){
  119. return list;
  120. }
  121. // 一次性获取所有关联的单位信息并转换为Map以提高查询效率
  122. Map<Long, GyDataUnitDO> unitMap = gyDataUnitService.getByDataIds(dataIds).stream()
  123. .collect(Collectors.toMap(GyDataUnitDO::getDataId, Function.identity()));
  124. // 遍历DTO列表,设置单位信息
  125. list.forEach(dto -> {
  126. GyDataUnitDO unitDO = unitMap.get(dto.getId());
  127. if (unitDO != null) {
  128. dto.setReporterUnit(unitDO.getReporterUnit());
  129. dto.setCreditCode(unitDO.getCreditCode());
  130. dto.setSupervisoryOrg(unitDO.getSupervisoryOrg());
  131. dto.setUnitCharacter(unitDO.getUnitCharacter());
  132. dto.setIndustryTypeOne(unitDO.getIndustryTypeOne());
  133. dto.setIndustryTypeTwo(unitDO.getIndustryTypeTwo());
  134. dto.setUnitProvince(unitDO.getUnitProvince());
  135. dto.setUnitCity(unitDO.getUnitCity());
  136. dto.setUnitMan(unitDO.getUnitMan());
  137. dto.setUnitOffice(unitDO.getUnitOffice());
  138. dto.setDataSecurityMan(unitDO.getDataSecurityMan());
  139. dto.setDataSecurityOffice(unitDO.getDataSecurityOffice());
  140. dto.setDataSecurityWay(unitDO.getDataSecurityWay());
  141. dto.setUpdateTime(unitDO.getUpdateTime());
  142. }
  143. });
  144. return list;
  145. }
  146. @Override
  147. public int countTotal(Map<String, Object> map) {
  148. UserDO currUser = ShiroUtils.getUser();
  149. log.info("currUser:" + currUser.toString());
  150. if (!managerValue.contains(currUser.getDeptId().toString())) {
  151. String province = currUser.getProvince();
  152. if(StringUtils.isEmpty(province)){
  153. province = sysProvince;
  154. }
  155. if(!ObjectUtils.isEmpty(province)) {
  156. map.put("unitProvince", province);
  157. }
  158. String city = currUser.getCity();
  159. if(StringUtils.isEmpty(city)){
  160. city = sysCity;
  161. }
  162. String gyUnitId = currUser.getGyUnitId();
  163. map.put("unitId", gyUnitId);
  164. if (!ObjectUtils.isEmpty(city)) {
  165. map.put("unitCity", city);
  166. map.put("auditStage", "1");
  167. } else {
  168. map.put("auditStage", "2");
  169. }
  170. }
  171. return gyDataDao.countTotal(map);
  172. }
  173. /**
  174. * @param file
  175. * @Description: 文件解密
  176. * @Author: wangp
  177. * @Date: 2022/3/9 15:07
  178. * @Return: boolean
  179. */
  180. @Override
  181. public String dec(MultipartFile file) {
  182. String decFile = "";
  183. FileInputStream srcStream = null;
  184. try {
  185. String fileName = file.getOriginalFilename();
  186. // 生成临时文件
  187. String fileNames = FileUtil.renameToUUID(fileName);
  188. String temFile = bootdoConfig.getUploadPath() + fileNames;
  189. MultipartFileToFile(file, temFile);
  190. // FileUtil.uploadFile(file.getBytes(), bootdoConfig.getUploadPath(), fileName);
  191. // 解密文件路径
  192. decFile = bootdoConfig.getUploadPath() + fileName;
  193. log.info("temFile:" + temFile + ",decFile:" + decFile);
  194. srcStream = new FileInputStream(temFile);
  195. log.info("srcStream:" + srcStream.toString());
  196. log.info("EncPrival:" + bootdoConfig.getEncPrival());
  197. FileCryptTool.decryptFile(bootdoConfig.getEncPrival(), temFile, decFile);
  198. // 清除数据
  199. srcStream.close();
  200. FileUtil.deleteFile(temFile);// 临时文件
  201. } catch (Exception e) {
  202. log.error("文件解密异常", e);
  203. return "";
  204. }
  205. return decFile;
  206. }
  207. /**
  208. * @description: 密文导入
  209. * @param:
  210. * @return: int
  211. * @author xhl
  212. * @date: 2022/9/7 14:28
  213. */
  214. @Override
  215. public String cipherTextImport(String decFlg,int type) throws Exception {
  216. File file = new File(decFlg);
  217. String result = null;
  218. InputStream is = null;
  219. try {
  220. is = new FileInputStream(file);
  221. result = imp(is,type);
  222. // 清除临时数据
  223. FileUtil.deleteFile(decFlg);
  224. } finally {
  225. try {
  226. if (is != null) {
  227. is.close();
  228. }
  229. // xssfWorkbook.close();
  230. } catch (IOException e) {
  231. e.printStackTrace();
  232. }
  233. return result;
  234. }
  235. }
  236. /**
  237. * @description: 明文导入
  238. * @param: file
  239. * @return: java.lang.String
  240. * @author xhl
  241. * @date: 2022/9/7 14:23
  242. */
  243. @Override
  244. public String plainTextImport(MultipartFile file,int type) throws Exception {
  245. String result = null;
  246. InputStream is = null;
  247. try {
  248. is = file.getInputStream();
  249. result = imp(is,type);
  250. } finally {
  251. try {
  252. is.close();
  253. // xssfWorkbook.close();
  254. } catch (IOException e) {
  255. e.printStackTrace();
  256. }
  257. }
  258. return result;
  259. }
  260. private String imp(InputStream is,int type) throws Exception {
  261. int otherProvince = 0;
  262. int otherCity = 0;
  263. int auditPass = 0;
  264. int unitNoAudit = 0;
  265. int nonData = 0;
  266. XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is);
  267. XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
  268. // 企业信息
  269. List<GyUnitDO> gyUnitList = new ArrayList();
  270. // 数据目录
  271. List<GyDataDO> dataList = new ArrayList();
  272. // 用户信息
  273. UserDO currUser = ShiroUtils.getUser();
  274. log.info("currUser:" + currUser.toString());
  275. if(null == currUser){
  276. throw new BDException("当前用户没登录");
  277. }
  278. String userProvince = null;
  279. String userCity= null;
  280. if (managerValue.contains(currUser.getDeptId().toString())) {
  281. userProvince = sysProvince;
  282. userCity = sysCity;
  283. } else {
  284. userProvince = currUser.getProvince();
  285. if(StringUtils.isEmpty(userProvince)){
  286. userProvince = sysProvince;
  287. }
  288. userCity = currUser.getCity();
  289. if(StringUtils.isEmpty(userCity)){
  290. userCity = sysCity;
  291. }
  292. }
  293. log.info("===========1=============");
  294. //判断是哪种格式的
  295. Row firstRow = xssfSheet.getRow(0);
  296. Cell firstRowCell = firstRow.getCell(0);
  297. int beginDataRowIndex = 0;
  298. if("序号".equals(firstRowCell.getStringCellValue())){
  299. beginDataRowIndex = 1;
  300. } else {
  301. beginDataRowIndex = 4;
  302. }
  303. log.info("===========2=============");
  304. if(xssfSheet.getLastRowNum() < beginDataRowIndex){ //getLastRowNum返回最后一行的索引,即 比行总数小1
  305. throw new BDException("excel文件无数据");
  306. }
  307. log.info("===========3=============");
  308. log.info("===========3=============");
  309. // 遍历
  310. for (int i = beginDataRowIndex; i <= xssfSheet.getLastRowNum(); i++) {
  311. log.info("userProvince: {}, i: {}", userProvince, i);
  312. Row row = xssfSheet.getRow(i);
  313. if (row.getCell(1) == null) {
  314. break;
  315. }
  316. if(row.getLastCellNum()<52){ //getLastCellNum返回的是最后一列的列数,即 等于总列数
  317. throw new BDException("excel文件列数不正确");
  318. }
  319. log.info("===========4============="+i);
  320. //所属省份
  321. String dataProvince = this.getCellValue_String(row,18);
  322. String dataCity = this.getCellValue_String(row,19);
  323. // 当非管理员导入的数据为非本省的数据的时候 跳过当前数据 并记录
  324. if (StringUtils.isEmpty(dataProvince) || (!StringUtils.isEmpty(userProvince)) && !dataProvince.equals(userProvince)) {
  325. log.info("当前用户省份: {}, 当前数据省份: {}, 数据名称: {}", userProvince, dataProvince, this.getCellValue_String(row,1));
  326. otherProvince++;
  327. continue;
  328. }
  329. log.info("===========5============="+i);
  330. if (StringUtils.isEmpty(dataCity) || (!StringUtils.isEmpty(userCity)) && !dataCity.equals(userCity)) {
  331. log.info("当前用户地市: {}, 当前数据地市: {}, 数据名称: {}", userCity, dataCity, this.getCellValue_String(row,1));
  332. otherCity++;
  333. continue;
  334. }
  335. log.info("===========6============="+i);
  336. // 企业单位
  337. GyUnitDO gyUnitDO = new GyUnitDO();
  338. // 数据信息
  339. GyDataDO gyDataDO = new GyDataDO();
  340. //代码报错:java.lang.IllegalStateException: Cannot get a STRING value from a NUMERIC cell
  341. //GyUnitDO tmpGyUnitDO = gyUnitDao.getGyUnitByCreditCode(row.getCell(17).getStringCellValue());
  342. //获取单元格的字符出信息
  343. String creditCode = this.getCellValue_String(row,17);
  344. log.info("===========6.5============creditCode="+creditCode);
  345. // 使用获取到的信用代码
  346. GyUnitDO tmpGyUnitDO = gyUnitDao.getGyUnitByCreditCode(creditCode);
  347. //判断是否已经在gu_unit表中添加企业信息
  348. if (ObjectUtils.isEmpty(tmpGyUnitDO) ) {
  349. //没有添加企业信息, 需要进行企业信息的添加,审核状态为【未审核】
  350. log.info("===========7============="+i);
  351. try {
  352. this.createGyUnitDO(gyUnitDO, row);
  353. gyUnitDO.setCreateTime(new Date());
  354. gyUnitDO.setAuditStatus("0");
  355. gyUnitDao.save(gyUnitDO);
  356. log.info("========first_load_data======create_gy_unit======sucess:"+gyUnitDO.toString());
  357. } catch (Exception e) {
  358. log.error("error enterprise-only : {}", e.getMessage());
  359. }
  360. unitNoAudit++;
  361. break;
  362. } else {
  363. log.info("===========8============="+i);
  364. if ( !"1".equals(tmpGyUnitDO.getAuditStatus()) ){
  365. unitNoAudit++;
  366. break;
  367. }
  368. }
  369. log.info("===========9============="+i);
  370. //无数据导出
  371. if ("/".equals(this.getCellValue_String(row,1)) && this.getCellValue_String(row,16) !=null && !"/".equals(this.getCellValue_String(row,16))) {
  372. log.info("===========10============="+i);
  373. int count = gyUnitDao.getGyUnit(this.createGyUnitDO(gyUnitDO,row));
  374. if (count == 0) {
  375. try {
  376. gyUnitDO.setCreateTime(new Date());
  377. gyUnitDO.setAuditStatus("0");
  378. gyUnitDao.save(gyUnitDO);
  379. } catch (Exception e) {
  380. log.error("error enterprise-only : {}", e.getMessage());
  381. }
  382. }
  383. nonData++;
  384. break;
  385. }
  386. gyDataDO.setDataName(this.getCellValue_String(row,1));//数据名称
  387. gyDataDO.setDataTypeBase(this.getCellValue_String(row,2));//数据分类分级规范
  388. gyDataDO.setDataTypeOne(this.getCellValue_String(row,3));//数据一级类别
  389. gyDataDO.setDataTypeTwo(this.getCellValue_String(row,4));//数据二级类别
  390. gyDataDO.setDataTypeThree(row.getCell(5)==null?null:this.getCellValue_String(row,5));//数据三级类别
  391. gyDataDO.setDataTypeFour(row.getCell(6)==null?null:this.getCellValue_String(row,6));//数据四级类别
  392. gyDataDO.setDataLevel(this.getCellValue_String(row,7));//数据级别
  393. gyDataDO.setDataCarrier(this.getCellValue_String(row,8));//数据载体
  394. gyDataDO.setDataSource(this.getCellValue_String(row,9));//数据来源
  395. gyDataDO.setDataNumGb(row.getCell(10).getNumericCellValue());//数据数量(非电子数据)
  396. gyDataDO.setDataNum((int) row.getCell(11).getNumericCellValue());//数据数量(电子数据)
  397. gyDataDO.setDataScope(this.getCellValue_String(row,12));//覆盖类型
  398. gyDataDO.setDataProportion(this.getCellValue_String(row,13));//覆盖占比
  399. gyDataDO.setDataPrecision(this.getCellValue_String(row,14));//数据精度
  400. gyDataDO.setDataPrecisionDes(this.getCellValue_String(row,15));//数据精度描述
  401. log.info("===========11============="+i);
  402. //添加企业信息
  403. gyUnitList.add(this.createGyUnitDO(gyUnitDO,row));
  404. gyDataDO.setDataHandleType(this.getCellValue_String(row,26));//数据处理方式
  405. gyDataDO.setDataResult(this.getCellValue_String(row,27));//数据目的
  406. gyDataDO.setIsAlgorithmHandle(this.getCellValue_String(row,28));//是否涉及算法处理
  407. gyDataDO.setIsCross(this.getCellValue_String(row,29));//是否出境
  408. gyDataDO.setCrossAcceptName(this.getCellValue_String(row,30));//跨境接收方名称
  409. gyDataDO.setDataCrossType(this.getCellValue_String(row,31));//出境方式
  410. gyDataDO.setIsSecurityAss(this.getCellValue_String(row,32));//是否安全评估
  411. gyDataDO.setAssessResult(this.getCellValue_String(row,33));//评估结果
  412. gyDataDO.setIsCrossMain(this.getCellValue_String(row,34));//是否对外共享
  413. gyDataDO.setCrossmainAcceptName(this.getCellValue_String(row,35));//数据对外共享接收方
  414. gyDataDO.setDataCrossmainType(this.getCellValue_String(row,36));//数据对外共享方式
  415. gyDataDO.setIsForeignData(this.getCellValue_String(row,37));//是否为涉外数据
  416. gyDataDO.setIsCrossmainFlow(this.getCellValue_String(row,38));//是否涉及跨主体流动
  417. gyDataDO.setInfoSystemName(this.getCellValue_String(row,39));//信息系统名称
  418. gyDataDO.setInfoSystemIpAddress(this.getCellValue_String(row,40));//信息系统ip地址
  419. gyDataDO.setInfoSystemDomainName(this.getCellValue_String(row,41));//信息系统域名
  420. gyDataDO.setInfoSystemType(this.getCellValue_String(row,42));//信息系统类型
  421. gyDataDO.setSecurityCognizance(this.getCellValue_String(row,43));//网络安全等级保护认定情况
  422. gyDataDO.setComSecurityCognizance(this.getCellValue_String(row,44));//通信网络安全防护定级备案情况
  423. gyDataDO.setIsKetSystem(this.getCellValue_String(row,45));//是否为关键信息基础设施
  424. gyDataDO.setIsKeydataAss(this.getCellValue_String(row,46));//是否开展重要数据安全风险评估
  425. gyDataDO.setAssessOrg(this.getCellValue_String(row,47));//评估机构
  426. gyDataDO.setAssessBase(this.getCellValue_String(row,48));//评估依据的规范
  427. gyDataDO.setAssessTime(this.getCellValue_String(row,49));//评估时间
  428. gyDataDO.setDataAssessResult(this.getCellValue_String(row,50));//重要数据安全风险评估结论
  429. gyDataDO.setDataDesc(this.getCellValue_String(row,51));//备注
  430. log.info("===========12============="+i);
  431. gyDataDO.setGyUnitId(gyUnitDO.getCreditCode());//关联填报企业
  432. log.info("===========12.1============="+i+"===type=="+type);
  433. if (type == 1) { //导入列表导入
  434. log.info("===========13============="+i);
  435. gyDataDO.setSendVerify("0");// 送审状态 0:未送审 1:已送审
  436. gyDataDO.setDataStatus("0"); // 状态 0:待审核 1:删除 2:已上报 3:通过审核 4:驳回
  437. gyDataDO.setDeleteStatus("0"); // 状态 0:正常 1:删除
  438. log.info("===========14============="+i+"===deployType===="+deployType);
  439. if("1".equals(deployType)){ //市级单独部署
  440. gyDataDO.setAuditStage("1");
  441. } else if("2".equals(deployType)){ //省级单独部署
  442. gyDataDO.setAuditStage("2");
  443. } else if("3".equals(deployType)){ //省市一体部署
  444. if(StringUtils.isNotEmpty(currUser.getCity())){ //市级人员操作
  445. gyDataDO.setAuditStage("1");
  446. } else { //省级人员
  447. if (managerValue.contains(currUser.getDeptId().toString())) { //机构是管理员
  448. gyDataDO.setAuditStage("1");
  449. } else { //一般省级人员
  450. gyDataDO.setAuditStage("2");
  451. }
  452. }
  453. }
  454. } else if(type == 2){ //数据目录导入
  455. gyDataDO.setSendVerify("1");// 送审状态 0:未送审 1:已送审
  456. gyDataDO.setDataStatus("3"); // 状态 0:待审核 1:删除 2:已上报 3:通过审核 4:驳回
  457. gyDataDO.setDeleteStatus("0"); // 状态 0:正常 1:删除
  458. if("1".equals(deployType)){ //市级单独部署
  459. throw new BDException("不支持该操作,请到“报送到省级”列表操作");
  460. } else if("2".equals(deployType)){ //省级单独部署
  461. gyDataDO.setAuditStage("2");
  462. } else if("3".equals(deployType)){ //省市一体部署
  463. if(StringUtils.isNotEmpty(currUser.getCity())){ //市级人员操作
  464. throw new BDException("市级人员无权操作");
  465. } else {
  466. gyDataDO.setAuditStage("2");
  467. }
  468. }
  469. } else { //上报到省级导入
  470. log.info("===========15============="+i);
  471. gyDataDO.setSendVerify("1");// 送审状态 0:未送审 1:已送审
  472. gyDataDO.setDataStatus("3"); // 状态 0:待审核 1:删除 2:已上报 3:通过审核 4:驳回
  473. gyDataDO.setDeleteStatus("0"); // 状态 0:正常 1:删除
  474. if("1".equals(deployType)){ //市级单独部署
  475. gyDataDO.setAuditStage("1");
  476. } else if("2".equals(deployType)){ //省级单独部署
  477. throw new BDException("不支持该操作,请到“数据目录”列表操作");
  478. } else if("3".equals(deployType)){ //省市一体部署
  479. if(StringUtils.isNotEmpty(currUser.getCity())){ //市级人员操作
  480. gyDataDO.setAuditStage("1");
  481. } else {
  482. if (managerValue.contains(currUser.getDeptId().toString())) { //机构是管理员
  483. gyDataDO.setAuditStage("1");
  484. } else { //一般省级人员
  485. throw new BDException("省级人员无权操作");
  486. }
  487. }
  488. }
  489. }
  490. gyDataDO.setUploadTime(new Date());
  491. gyDataDO.setUpdateTime(gyDataDO.getUploadTime());
  492. log.info("dataDO:" + gyDataDO.toString());
  493. Map<String, Object> params = new HashMap<>();
  494. params.put("dataName", gyDataDO.getDataName());// 数据名称
  495. params.put("gyUnitId", gyDataDO.getGyUnitId());// 单位
  496. //判断数据是否已经上传过
  497. List<GyDataImportDTO> listInfo = gyDataDao.listId(params);
  498. log.info("============16=======listInfo======"+listInfo);
  499. if (listInfo !=null && listInfo.size()>0) {
  500. GyDataImportDTO gyDataImportDTO = listInfo.get(0);
  501. if("3".equals(gyDataImportDTO.getDataStatus())){ //审核通过数据不导入
  502. log.info("审核通过数据id:" + gyDataImportDTO.getId());
  503. auditPass++;
  504. continue;
  505. } else{
  506. // 删除数据
  507. log.info("删除数据id:" + gyDataImportDTO.getId());
  508. gyDataDao.remove(gyDataImportDTO.getId());
  509. }
  510. }
  511. dataList.add(gyDataDO);
  512. }
  513. // 企业单位批量导入
  514. log.info("unitList size:" + gyUnitList.size());
  515. if (gyUnitList != null && gyUnitList.size() > 0) {
  516. for (GyUnitDO gyUnitDO : gyUnitList) {
  517. log.info("unitList size:" + gyUnitList.size());
  518. int count = gyUnitDao.getGyUnit(gyUnitDO);
  519. if (count == 0) {
  520. try {
  521. gyUnitDO.setCreateTime(new Date());
  522. gyUnitDO.setAuditStatus("0");
  523. gyUnitDao.save(gyUnitDO);
  524. } catch (Exception e) {
  525. log.error("error enterprise-only : {}", e.getMessage());
  526. }
  527. }
  528. }
  529. }
  530. // 数据批量导入
  531. if (dataList != null && dataList.size() > 0) {
  532. gyDataDao.batchSave(dataList);
  533. }
  534. String result = null;
  535. if ((otherProvince + otherCity + auditPass + unitNoAudit + nonData) > 0) {
  536. StringBuilder sb = new StringBuilder();
  537. if (otherProvince > 0) {
  538. sb.append(otherProvince).append("条非本省数据(已忽略导入)! <br/>");
  539. }
  540. if (otherCity > 0) {
  541. sb.append(otherCity).append("条非本市数据(已忽略导入)! <br/>");
  542. }
  543. if (auditPass > 0) {
  544. sb.append(auditPass).append("条已经审核通过数据(已忽略导入)! <br/>");
  545. }
  546. if (unitNoAudit > 0) {
  547. sb.append(unitNoAudit).append("条所属企业未注册或还没通过审核(已忽略导入)! <br/>");
  548. }
  549. if (nonData > 0) {
  550. sb.append(nonData).append("条仅导入企业(无数据导入)! <br/>");
  551. }
  552. result = sb.toString();
  553. }
  554. return result;
  555. }
  556. //获取单元格的字符出信息
  557. private String getCellValue_String(Row row,int i) {
  558. // 获取单元格
  559. Cell cell = row.getCell(i);
  560. String result = null;
  561. if (cell != null) {
  562. // 根据 POI 3.17 版本的单元格类型常量处理
  563. switch (cell.getCellType()) {
  564. case Cell.CELL_TYPE_STRING:
  565. result = cell.getStringCellValue();
  566. break;
  567. case Cell.CELL_TYPE_NUMERIC:
  568. // 数值类型转换为字符串
  569. result = String.valueOf(cell.getNumericCellValue());
  570. // 处理小数点后为0的情况(如12345.0 -> 12345)
  571. if (result.endsWith(".0")) {
  572. result = result.substring(0, result.length() - 2);
  573. }
  574. break;
  575. case Cell.CELL_TYPE_BLANK:
  576. result = "";
  577. break;
  578. default:
  579. // 处理公式、布尔等其他类型
  580. result = String.valueOf(cell);
  581. }
  582. }
  583. return result;
  584. }
  585. private GyUnitDO createGyUnitDO(GyUnitDO gyUnitDO, Row row){
  586. gyUnitDO.setReporterUnit(this.getCellValue_String(row,16));// 数据处理者名称
  587. gyUnitDO.setCreditCode(this.getCellValue_String(row,17));// 统一社会信用代码(机构代码 )
  588. gyUnitDO.setUnitProvince(this.getCellValue_String(row,18));//所在地区(省)
  589. gyUnitDO.setUnitCity(this.getCellValue_String(row,19));//所在地区(市)
  590. gyUnitDO.setUnitCharacter(this.getCellValue_String(row,20));//数据处理者性质
  591. gyUnitDO.setIndustryTypeOne(this.getCellValue_String(row,21));//所属行业
  592. gyUnitDO.setIndustryTypeTwo(this.getCellValue_String(row,22));//主营业务范围
  593. gyUnitDO.setDataSecurityMan(this.getCellValue_String(row,23));//数据安全负责人姓名
  594. gyUnitDO.setDataSecurityOffice(this.getCellValue_String(row,24));//数据安全负责人职务
  595. gyUnitDO.setDataSecurityWay(this.getCellValue_String(row,25));//数据安全负责人联系方式
  596. return gyUnitDO;
  597. }
  598. @Override
  599. public GyDataImportDTO get(Long id) {
  600. return gyDataDao.get(id);
  601. }
  602. @Override
  603. public GyDataExcelDO getDataExcel(Long id) {
  604. return gyDataDao.getDataExcel(id);
  605. }
  606. @Override
  607. public GbDataExcelDO getGbDataExcel(Long id) {
  608. return gyDataDao.getGbDataExcel(id);
  609. }
  610. @Override
  611. public void updateStatus(GyDataImportDTO data,String opinion) {
  612. int effect = gyDataDao.updateStatus(data);
  613. if ("2".equalsIgnoreCase(data.getDataStatus()) && effect > 0) {
  614. GyDataImportDTO gyDataImportDTO = get(data.getId());
  615. RoleDO roleDO = roleService.get(gyDataImportDTO.getRoleId());
  616. if (roleDO != null) {
  617. ExamineLogDTO dto = new ExamineLogDTO();
  618. dto.setUniqueKey(String.valueOf(data.getId()));
  619. dto.setDataType("DI_OPER");
  620. dto.setMessage("数据已送审至: " + roleDO.getRoleName());
  621. examineLogService.save(dto);
  622. }
  623. } else if ("3".equalsIgnoreCase(data.getDataStatus()) && effect > 0) {
  624. GyDataImportDTO gyDataImportDTO = get(data.getId());
  625. RoleDO roleDO = roleService.get(gyDataImportDTO.getRoleId());
  626. if (roleDO != null) {
  627. ExamineLogDTO dto = new ExamineLogDTO();
  628. dto.setUniqueKey(String.valueOf(data.getId()));
  629. dto.setDataType("DI_OPER");
  630. dto.setMessage("数据已被(" + roleDO.getRoleName() + ")审核通过");
  631. examineLogService.save(dto);
  632. }
  633. } else if ("4".equalsIgnoreCase(data.getDataStatus()) && effect > 0) {
  634. GyDataImportDTO gyDataImportDTO = get(data.getId());
  635. RoleDO roleDO = roleService.get(gyDataImportDTO.getRoleId());
  636. if (roleDO != null) {
  637. ExamineLogDTO dto = new ExamineLogDTO();
  638. dto.setUniqueKey(String.valueOf(data.getId()));
  639. dto.setDataType("DI_OPER");
  640. dto.setMessage("数据已被(" + roleDO.getRoleName() + ")审核驳回, 请核对");
  641. dto.setOpinion(opinion);
  642. examineLogService.save(dto);
  643. }
  644. if("湖南".equals(this.sysProvince)){
  645. //通过数据id,查询数据信息
  646. GyDataImportDTO importDTO = gyDataDao.get(data.getId());
  647. if(Objects.nonNull(importDTO)){
  648. //发送短息
  649. if("2".equals(importDTO.getAuditStage())){
  650. log.info("=====================发送短信了===数据信息查询==="+importDTO.toString());
  651. //审核阶段: 1:市级,2:省级
  652. GyUnitDO gyUnitDO = gyUnitDao.getGyUnitByCreditCode(importDTO.getGyUnitId());
  653. log.info("=====================发送短信了===企业信息查询==="+gyUnitDO.toString());
  654. if(Objects.nonNull(gyUnitDO)){
  655. try {
  656. log.info("=====================发送短信了===start==="+gyUnitDO.toString());
  657. messageHuNanService.sendMessage(gyUnitDO.getDataSecurityWay()+","+gyUnitDO.getMobilePhone(),
  658. importDTO.getDataName());
  659. log.info("=====================发送短信了===end==="+gyUnitDO.toString());
  660. } catch (Exception e) {
  661. log.error("=============messageHuNanService.sendMessage=======error======="+e.getMessage());
  662. e.printStackTrace();
  663. }
  664. }else {
  665. log.info("=========企业的组织机构代码:"+importDTO.getGyUnitId()+",查询不到对应的企业信息===========");
  666. }
  667. }
  668. }else {
  669. log.error("=========数据id:"+data.getId()+",查询不到对应的数据信息===========");
  670. }
  671. }
  672. }
  673. }
  674. @Override
  675. public void addExpertOpinion(ExpertOpinionDO expertOpinionDO){
  676. GyDataImportDTO gyDataImportDTO = get(expertOpinionDO.getId());
  677. RoleDO roleDO = roleService.get(gyDataImportDTO.getRoleId());
  678. if (roleDO != null) {
  679. ExamineLogDTO dto = new ExamineLogDTO();
  680. dto.setUniqueKey(String.valueOf(expertOpinionDO.getId()));
  681. dto.setDataType("DI_OPER");
  682. dto.setMessage(roleDO.getRoleName() + "的专家意见为: " + expertOpinionDO.getOpinion());
  683. examineLogService.save(dto);
  684. }
  685. }
  686. @Override
  687. public void addUnionOpinion(UnionOpinionDO unionOpinionDO) {
  688. GyDataImportDTO gyDataImportDTO = get(unionOpinionDO.getId());
  689. RoleDO roleDO = roleService.get(gyDataImportDTO.getRoleId());
  690. if (roleDO != null) {
  691. ExamineLogDTO dto = new ExamineLogDTO();
  692. dto.setUniqueKey(String.valueOf(unionOpinionDO.getId()));
  693. dto.setDataType("DI_OPER");
  694. dto.setMessage(roleDO.getRoleName() + "的联合审核意见为: " + unionOpinionDO.getOpinion());
  695. examineLogService.save(dto);
  696. }
  697. }
  698. @Override
  699. public void batchRemove(Long[] ids) {
  700. gyDataDao.batchRemove(ids);
  701. }
  702. @Override
  703. public int countTotal4Del(Map<String, Object> map) {
  704. return gyDataDao.countTotal4Del(map);
  705. }
  706. @Override
  707. public List<GyDataImportDTO> listRecover(Map<String, Object> map) {
  708. UserDO currUser = ShiroUtils.getUser();
  709. log.info("currUser:" + currUser.toString());
  710. if (!managerValue.contains(currUser.getDeptId().toString())) {
  711. String province = currUser.getProvince();
  712. if(StringUtils.isEmpty(province)){
  713. province = sysProvince;
  714. }
  715. if(!ObjectUtils.isEmpty(province)) {
  716. map.put("unitProvince", province);
  717. }
  718. String city = currUser.getCity();
  719. if(StringUtils.isEmpty(city)){
  720. city = sysCity;
  721. }
  722. String gyUnitId = currUser.getGyUnitId();
  723. map.put("unitId", gyUnitId);
  724. if (!ObjectUtils.isEmpty(city)) {
  725. map.put("unitCity", city);
  726. map.put("auditStage", "1");
  727. } else {
  728. map.put("auditStage", "2");
  729. }
  730. }
  731. return gyDataDao.listRecover(map);
  732. }
  733. @Override
  734. public int countRecover(Map<String, Object> map) {
  735. UserDO currUser = ShiroUtils.getUser();
  736. log.info("currUser:" + currUser.toString());
  737. if (!managerValue.contains(currUser.getDeptId().toString())) {
  738. String province = currUser.getProvince();
  739. if(StringUtils.isEmpty(province)){
  740. province = sysProvince;
  741. }
  742. if(!ObjectUtils.isEmpty(province)) {
  743. map.put("unitProvince", province);
  744. }
  745. String city = currUser.getCity();
  746. if(StringUtils.isEmpty(city)){
  747. city = sysCity;
  748. }
  749. String gyUnitId = currUser.getGyUnitId();
  750. map.put("unitId", gyUnitId);
  751. if (!ObjectUtils.isEmpty(city)) {
  752. map.put("unitCity", city);
  753. map.put("auditStage", "1");
  754. } else {
  755. map.put("auditStage", "2");
  756. }
  757. }
  758. return gyDataDao.countRecover(map);
  759. }
  760. @Transactional
  761. @Override
  762. public int recover(Long id) {
  763. GyDataImportDTO gyDataImportDTO = gyDataDao.getRecoverData(id);
  764. if("1".equals(gyDataImportDTO.getDeleteStatus())){ //属于删除数据
  765. Map<String, Object> params = new HashMap<>();
  766. params.put("dataName", gyDataImportDTO.getDataName());// 数据名称
  767. params.put("gyUnitId", gyDataImportDTO.getGyUnitId());// 单位
  768. int countTotal = gyDataDao.countTotal(params);
  769. if (countTotal > 0) {
  770. // //未删除的数据存在企业机构编码和数据名一样的,不允许恢复
  771. return 0;
  772. }
  773. }
  774. UserDO currUser = ShiroUtils.getUser();
  775. String auditStage =null;
  776. if("1".equals(deployType)){ //市级单独部署
  777. auditStage = "1";
  778. } else if("2".equals(deployType)){ //省级单独部署
  779. auditStage = "2";
  780. } else if("3".equals(deployType)){ //省市一体部署
  781. if (managerValue.contains(currUser.getDeptId().toString())) { //机构是管理员
  782. auditStage = "1";
  783. } else {
  784. String city = currUser.getCity();
  785. if(StringUtils.isEmpty(city)){ //一般省级人员
  786. auditStage = "2";
  787. } else { //一般市级人员
  788. auditStage = "1";
  789. }
  790. }
  791. }
  792. int result = gyDataDao.recover(id, auditStage);
  793. gyDataUnitService.deleteByDataId(id);
  794. return result;
  795. }
  796. @Override
  797. public int batchPhysicalDeletion(Long id) {
  798. Long[] longArray = new Long[]{id};
  799. return gyDataDao.batchPhysicalDeletion(longArray);
  800. }
  801. @Override
  802. public void encryptExports(HttpServletResponse responses, String idValue) throws Exception {
  803. List<GyDataExcelDO> list = new ArrayList<>();
  804. JSONArray json = (JSONArray)JSONArray.parse(idValue);
  805. for (int i = 0; i < json.size(); i++) {
  806. String id = String.valueOf(json.get(i));
  807. log.info("批量导出 id:" + json.get(i));
  808. GyDataExcelDO data = new GyDataExcelDO();
  809. data = gyDataDao.getDataExcel(Long.parseLong(id));
  810. data.setNo(i + 1); //序号
  811. list.add(data);
  812. }
  813. log.info("list size:" + list.size());
  814. String decFile = bootdoConfig.getUploadPath() + "数据备案导出信息.xlsx";
  815. String encFile = bootdoConfig.getUploadPath() + "数据备案加密导出信息.xlsx";
  816. ExcelUtils.encryptExport(responses, EncryptExcelDO.class,list,bootdoConfig.getCrtPrival(),decFile,encFile);
  817. }
  818. @Override
  819. public int countAaAssData(Long id){
  820. return gyDataDao.countAaAssData(id);
  821. }
  822. @Override
  823. public List<GyDataImportDTO> dataEntryList(Map<String, Object> map) {
  824. UserDO currUser = ShiroUtils.getUser();
  825. log.info("currUser:" + currUser.toString());
  826. if (!managerValue.contains(currUser.getDeptId().toString())) {
  827. String province = currUser.getProvince();
  828. if (StringUtils.isEmpty(province)) {
  829. province = sysProvince;
  830. }
  831. if (!ObjectUtils.isEmpty(province)) {
  832. map.put("unitProvince", province);
  833. }
  834. String city = currUser.getCity();
  835. if (StringUtils.isEmpty(city)) {
  836. city = sysCity;
  837. }
  838. String gyUnitId = currUser.getGyUnitId();
  839. map.put("unitId", gyUnitId);
  840. if (!ObjectUtils.isEmpty(city)) {
  841. map.put("unitCity", city);
  842. }
  843. }
  844. return this.dealDataWithCompany(gyDataDao.list(map));
  845. }
  846. @Override
  847. public int dataEntryCountTotal(Map<String, Object> map) {
  848. UserDO currUser = ShiroUtils.getUser();
  849. log.info("currUser:" + currUser.toString());
  850. if (!managerValue.contains(currUser.getDeptId().toString())) {
  851. String province = currUser.getProvince();
  852. if (StringUtils.isEmpty(province)) {
  853. province = sysProvince;
  854. }
  855. if (!ObjectUtils.isEmpty(province)) {
  856. map.put("unitProvince", province);
  857. }
  858. String city = currUser.getCity();
  859. if (StringUtils.isEmpty(city)) {
  860. city = sysCity;
  861. }
  862. String gyUnitId = currUser.getGyUnitId();
  863. map.put("unitId", gyUnitId);
  864. if (!ObjectUtils.isEmpty(city)) {
  865. map.put("unitCity", city);
  866. map.put("auditStage", "1");
  867. } else {
  868. map.put("auditStage", "2");
  869. }
  870. }
  871. return gyDataDao.countTotal(map);
  872. }
  873. /**
  874. * @Description: MultipartFile转file
  875. * @Author: wangp
  876. * @Date: 2022/2/25 9:15
  877. * @param multiFile
  878. * @param fileName
  879. * @Return: File
  880. */
  881. public static File MultipartFileToFile(MultipartFile multiFile, String fileName) {
  882. // 获取文件后缀
  883. String prefix = fileName.substring(fileName.lastIndexOf("."));
  884. log.info("fileName:" + fileName + ",prefix:" + prefix);
  885. // 若须要防止生成的临时文件重复,能够在文件名后添加随机码
  886. try {
  887. File file = new File(fileName);
  888. boolean res = file.createNewFile();
  889. if (!res) {
  890. log.info("创建失败!");
  891. } else {
  892. multiFile.transferTo(file);
  893. file.setExecutable(true);// 设置可执行权限
  894. file.setReadable(true);// 设置可读权限
  895. file.setWritable(true);// 设置可写权限
  896. }
  897. return file;
  898. } catch (Exception e) {
  899. e.printStackTrace();
  900. }
  901. return null;
  902. }
  903. public static void main(String[] args) {
  904. FileCryptTool.encryptFile("F:/dev-dys/sm2/sm2_client_enc_cert.crt", "F:/dev-dys/res/测试导入-河南.xlsx",
  905. "F:/dev-dys/res/enc-测试导入加密文件-河南.xlsx");
  906. FileCryptTool.encryptFile("F:/dev-dys/sm2/sm2_client_enc_cert.crt", "F:/dev-dys/res/测试导入-河北.xlsx",
  907. "F:/dev-dys/res/enc-测试导入加密文件-河北.xlsx");
  908. FileCryptTool.encryptFile("F:/dev-dys/sm2/sm2_client_enc_cert.crt", "F:/dev-dys/res/测试导入-四川.xlsx",
  909. "F:/dev-dys/res/enc-测试导入加密文件-四川.xlsx");
  910. }
  911. }