GyDataServiceImpl.java 42 KB

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