GyDataServiceImpl.java 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  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.ExamineLogService;
  12. import com.bootdo.datas.service.GyDataService;
  13. import com.bootdo.datas.service.UnitService;
  14. import com.bootdo.datas.tools.ExcelUtils;
  15. import com.bootdo.datas.tools.gm.FileCryptTool;
  16. import com.bootdo.system.domain.RoleDO;
  17. import com.bootdo.system.domain.UserDO;
  18. import com.bootdo.system.service.RoleService;
  19. import com.google.common.collect.Lists;
  20. import org.apache.poi.ss.usermodel.Cell;
  21. import org.apache.poi.ss.usermodel.Row;
  22. import org.apache.poi.xssf.usermodel.XSSFSheet;
  23. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  24. import org.slf4j.Logger;
  25. import org.slf4j.LoggerFactory;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.beans.factory.annotation.Value;
  28. import org.springframework.stereotype.Service;
  29. import org.springframework.transaction.annotation.Transactional;
  30. import org.springframework.util.CollectionUtils;
  31. import org.springframework.util.ObjectUtils;
  32. import org.springframework.web.multipart.MultipartFile;
  33. import javax.servlet.http.HttpServletResponse;
  34. import java.io.*;
  35. import java.util.*;
  36. import java.util.stream.Collectors;
  37. @Service
  38. @Transactional
  39. public class GyDataServiceImpl implements GyDataService {
  40. @Autowired
  41. private BootdoConfig bootdoConfig;
  42. @Autowired
  43. private GyUnitDao gyUnitDao;
  44. @Autowired
  45. private GyDataDao gyDataDao;
  46. @Value("${managerValue}")
  47. public String managerValue;
  48. @Value("${deployType:#{null}}")
  49. public String deployType;
  50. @Value("${sysProvince:#{null}}")
  51. public String sysProvince;
  52. @Value("${sysCity:#{null}}")
  53. public String sysCity;
  54. @Autowired
  55. private UnitService unitService;
  56. @Autowired
  57. private ExamineLogService examineLogService;
  58. @Autowired
  59. private RoleService roleService;
  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 (!managerValue.contains(currUser.getDeptId().toString())) {
  66. String province = currUser.getProvince();
  67. if(StringUtils.isEmpty(province)){
  68. province = sysProvince;
  69. }
  70. map.put("unitProvince", province);
  71. String city = currUser.getCity();
  72. if(StringUtils.isEmpty(city)){
  73. city = sysCity;
  74. }
  75. map.put("unitCity", city);
  76. if(!ObjectUtils.isEmpty(city)){
  77. map.put("auditStage", "1");
  78. } else {
  79. map.put("auditStage", "2");
  80. }
  81. }
  82. return gyDataDao.list(map);
  83. }
  84. @Override
  85. public int countTotal(Map<String, Object> map) {
  86. UserDO currUser = ShiroUtils.getUser();
  87. log.info("currUser:" + currUser.toString());
  88. if (!managerValue.contains(currUser.getDeptId().toString())) {
  89. String province = currUser.getProvince();
  90. if(StringUtils.isEmpty(province)){
  91. province = sysProvince;
  92. }
  93. map.put("unitProvince", province);
  94. String city = currUser.getCity();
  95. if(StringUtils.isEmpty(city)){
  96. city = sysCity;
  97. }
  98. map.put("unitCity", city);
  99. if(!ObjectUtils.isEmpty(city)){
  100. map.put("auditStage", "1");
  101. } else {
  102. map.put("auditStage", "2");
  103. }
  104. }
  105. return gyDataDao.countTotal(map);
  106. }
  107. /**
  108. * @param file
  109. * @Description: 文件解密
  110. * @Author: wangp
  111. * @Date: 2022/3/9 15:07
  112. * @Return: boolean
  113. */
  114. @Override
  115. public String dec(MultipartFile file) {
  116. String decFile = "";
  117. FileInputStream srcStream = null;
  118. try {
  119. String fileName = file.getOriginalFilename();
  120. // 生成临时文件
  121. String fileNames = FileUtil.renameToUUID(fileName);
  122. String temFile = bootdoConfig.getUploadPath() + fileNames;
  123. MultipartFileToFile(file, temFile);
  124. // FileUtil.uploadFile(file.getBytes(), bootdoConfig.getUploadPath(), fileName);
  125. // 解密文件路径
  126. decFile = bootdoConfig.getUploadPath() + fileName;
  127. log.info("temFile:" + temFile + ",decFile:" + decFile);
  128. srcStream = new FileInputStream(temFile);
  129. log.info("srcStream:" + srcStream.toString());
  130. log.info("EncPrival:" + bootdoConfig.getEncPrival());
  131. FileCryptTool.decryptFile(bootdoConfig.getEncPrival(), temFile, decFile);
  132. // 清除数据
  133. srcStream.close();
  134. FileUtil.deleteFile(temFile);// 临时文件
  135. } catch (Exception e) {
  136. log.error("文件解密异常", e);
  137. return "";
  138. }
  139. return decFile;
  140. }
  141. /**
  142. * @description: 密文导入
  143. * @param:
  144. * @return: int
  145. * @author xhl
  146. * @date: 2022/9/7 14:28
  147. */
  148. @Override
  149. public String cipherTextImport(String decFlg,int type) {
  150. File file = new File(decFlg);
  151. String result = null;
  152. InputStream is = null;
  153. try {
  154. is = new FileInputStream(file);
  155. result = imp(is,type);
  156. // 清除临时数据
  157. FileUtil.deleteFile(decFlg);
  158. } catch (Exception e) {
  159. e.printStackTrace();
  160. } finally {
  161. try {
  162. if (is != null) {
  163. is.close();
  164. }
  165. // xssfWorkbook.close();
  166. } catch (IOException e) {
  167. e.printStackTrace();
  168. }
  169. return result;
  170. }
  171. }
  172. /**
  173. * @description: 明文导入
  174. * @param: file
  175. * @return: java.lang.String
  176. * @author xhl
  177. * @date: 2022/9/7 14:23
  178. */
  179. @Override
  180. public String plainTextImport(MultipartFile file,int type) {
  181. String result = null;
  182. InputStream is = null;
  183. try {
  184. is = file.getInputStream();
  185. result = imp(is,type);
  186. } catch (BDException e) {
  187. e.printStackTrace();
  188. throw e;
  189. } catch (Exception e) {
  190. e.printStackTrace();
  191. } finally {
  192. try {
  193. is.close();
  194. // xssfWorkbook.close();
  195. } catch (IOException e) {
  196. e.printStackTrace();
  197. }
  198. }
  199. return result;
  200. }
  201. private String imp(InputStream is,int type) throws Exception {
  202. int otherProvince = 0;
  203. int otherCity = 0;
  204. int auditPass = 0;
  205. int unitNoAudit = 0;
  206. XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is);
  207. XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
  208. // 企业信息
  209. List<GyUnitDO> gyUnitList = new ArrayList();
  210. // 数据目录
  211. List<GyDataDO> dataList = new ArrayList();
  212. // 用户信息
  213. UserDO currUser = ShiroUtils.getUser();
  214. log.info("currUser:" + currUser.toString());
  215. if(null == currUser){
  216. throw new BDException("当前用户没登录");
  217. }
  218. String userProvince = null;
  219. String userCity= null;
  220. if (managerValue.contains(currUser.getDeptId().toString())) {
  221. userProvince = sysProvince;
  222. userCity = sysCity;
  223. } else {
  224. userProvince = currUser.getProvince();
  225. if(StringUtils.isEmpty(userProvince)){
  226. userProvince = sysProvince;
  227. }
  228. userCity = currUser.getCity();
  229. if(StringUtils.isEmpty(userCity)){
  230. userCity = sysCity;
  231. }
  232. }
  233. //判断是哪种格式的
  234. Row firstRow = xssfSheet.getRow(0);
  235. Cell firstRowCell = firstRow.getCell(0);
  236. int beginDataRowIndex = 0;
  237. if("序号".equals(firstRowCell.getStringCellValue())){
  238. beginDataRowIndex = 1;
  239. } else {
  240. beginDataRowIndex = 4;
  241. }
  242. if(xssfSheet.getLastRowNum() < beginDataRowIndex){ //getLastRowNum返回最后一行的索引,即 比行总数小1
  243. throw new BDException("excel文件无数据");
  244. }
  245. // 遍历
  246. for (int i = beginDataRowIndex; i <= xssfSheet.getLastRowNum(); i++) {
  247. log.info("userProvince: {}, i: {}", userProvince, i);
  248. Row row = xssfSheet.getRow(i);
  249. if (row.getCell(1) == null) {
  250. break;
  251. }
  252. if(row.getLastCellNum()<52){ //getLastCellNum返回的是最后一列的列数,即 等于总列数
  253. throw new BDException("excel文件列数不正确");
  254. }
  255. //所属省份
  256. String dataProvince = row.getCell(18).getStringCellValue();
  257. String dataCity = row.getCell(19).getStringCellValue();
  258. // 当非管理员导入的数据为非本省的数据的时候 跳过当前数据 并记录
  259. if (StringUtils.isEmpty(dataProvince) || (!StringUtils.isEmpty(userProvince)) && !dataProvince.equals(userProvince)) {
  260. log.info("当前用户省份: {}, 当前数据省份: {}, 数据名称: {}", userProvince, dataProvince, row.getCell(1).getStringCellValue());
  261. otherProvince++;
  262. continue;
  263. }
  264. if (StringUtils.isEmpty(dataCity) || (!StringUtils.isEmpty(userCity)) && !dataCity.equals(userCity)) {
  265. log.info("当前用户地市: {}, 当前数据地市: {}, 数据名称: {}", userCity, dataCity, row.getCell(1).getStringCellValue());
  266. otherCity++;
  267. continue;
  268. }
  269. GyUnitDO tmpGyUnitDO = gyUnitDao.getGyUnitByCreditCode(row.getCell(17).getStringCellValue());
  270. if (ObjectUtils.isEmpty(tmpGyUnitDO) || !"1".equals(tmpGyUnitDO.getAuditStatus())) {
  271. unitNoAudit++;
  272. continue;
  273. }
  274. // 企业单位
  275. GyUnitDO gyUnitDO = new GyUnitDO();
  276. // 数据信息
  277. GyDataDO gyDataDO = new GyDataDO();
  278. //无数据导出
  279. if ("/".equals(row.getCell(1).getStringCellValue()) && row.getCell(16).getStringCellValue() !=null && !"/".equals(row.getCell(16).getStringCellValue())) {
  280. gyUnitDO.setReporterUnit(row.getCell(16).getStringCellValue());// 数据处理者名称
  281. gyUnitDO.setCreditCode(row.getCell(17).getStringCellValue());// 统一社会信用代码(机构代码 )
  282. gyUnitDO.setUnitProvince(dataProvince);//所在地区(省)
  283. gyUnitDO.setUnitCity(row.getCell(19).getStringCellValue());//所在地区(市)
  284. gyUnitDO.setUnitCharacter(row.getCell(20).getStringCellValue());//数据处理者性质
  285. gyUnitDO.setIndustryTypeOne(row.getCell(21).getStringCellValue());//所属行业
  286. gyUnitDO.setIndustryTypeTwo(row.getCell(22).getStringCellValue());//主营业务范围
  287. gyUnitDO.setDataSecurityMan(row.getCell(23).getStringCellValue());//数据安全负责人姓名
  288. gyUnitDO.setDataSecurityOffice(row.getCell(24).getStringCellValue());//数据安全负责人职务
  289. gyUnitDO.setDataSecurityWay(row.getCell(25).getStringCellValue());//数据安全负责人联系方式
  290. int count = gyUnitDao.getGyUnit(gyUnitDO);
  291. if (count == 0) {
  292. try {
  293. gyUnitDO.setCreateTime(new Date());
  294. gyUnitDO.setStatus("0");
  295. gyUnitDao.save(gyUnitDO);
  296. } catch (Exception e) {
  297. log.error("error enterprise-only : {}", e.getMessage());
  298. }
  299. }
  300. break;
  301. }
  302. gyDataDO.setDataName(row.getCell(1).getStringCellValue());//数据名称
  303. gyDataDO.setDataTypeBase(row.getCell(2).getStringCellValue());//数据分类分级规范
  304. gyDataDO.setDataTypeOne(row.getCell(3).getStringCellValue());//数据一级类别
  305. gyDataDO.setDataTypeTwo(row.getCell(4).getStringCellValue());//数据二级类别
  306. gyDataDO.setDataTypeThree(row.getCell(5)==null?null:row.getCell(5).getStringCellValue());//数据三级类别
  307. gyDataDO.setDataTypeFour(row.getCell(6)==null?null:row.getCell(6).getStringCellValue());//数据四级类别
  308. gyDataDO.setDataLevel(row.getCell(7).getStringCellValue());//数据级别
  309. gyDataDO.setDataCarrier(row.getCell(8).getStringCellValue());//数据载体
  310. gyDataDO.setDataSource(row.getCell(9).getStringCellValue());//数据来源
  311. gyDataDO.setDataNumGb(row.getCell(10).getNumericCellValue());//数据数量(非电子数据)
  312. gyDataDO.setDataNum((int) row.getCell(11).getNumericCellValue());//数据数量(电子数据)
  313. gyDataDO.setDataScope(row.getCell(12).getStringCellValue());//覆盖类型
  314. gyDataDO.setDataProportion(row.getCell(13).getStringCellValue());//覆盖占比
  315. gyDataDO.setDataPrecision(row.getCell(14).getStringCellValue());//数据精度
  316. gyDataDO.setDataPrecisionDes(row.getCell(15).getStringCellValue());//数据精度描述
  317. gyUnitDO.setReporterUnit(row.getCell(16).getStringCellValue());// 数据处理者名称
  318. gyUnitDO.setCreditCode(row.getCell(17).getStringCellValue());// 统一社会信用代码(机构代码 )
  319. gyUnitDO.setUnitProvince(dataProvince);//所在地区(省)
  320. gyUnitDO.setUnitCity(row.getCell(19).getStringCellValue());//所在地区(市)
  321. gyUnitDO.setUnitCharacter(row.getCell(20).getStringCellValue());//数据处理者性质
  322. gyUnitDO.setIndustryTypeOne(row.getCell(21).getStringCellValue());//所属行业
  323. gyUnitDO.setIndustryTypeTwo(row.getCell(22).getStringCellValue());//主营业务范围
  324. gyUnitDO.setDataSecurityMan(row.getCell(23).getStringCellValue());//数据安全负责人姓名
  325. gyUnitDO.setDataSecurityOffice(row.getCell(24).getStringCellValue());//数据安全负责人职务
  326. gyUnitDO.setDataSecurityWay(row.getCell(25).getStringCellValue());//数据安全负责人联系方式
  327. gyUnitList.add(gyUnitDO);
  328. gyDataDO.setDataHandleType(row.getCell(26).getStringCellValue());//数据处理方式
  329. gyDataDO.setDataResult(row.getCell(27).getStringCellValue());//数据目的
  330. gyDataDO.setIsAlgorithmHandle(row.getCell(28).getStringCellValue());//是否涉及算法处理
  331. gyDataDO.setIsCross(row.getCell(29).getStringCellValue());//是否出境
  332. gyDataDO.setCrossAcceptName(row.getCell(30).getStringCellValue());//跨境接收方名称
  333. gyDataDO.setDataCrossType(row.getCell(31).getStringCellValue());//出境方式
  334. gyDataDO.setIsSecurityAss(row.getCell(32).getStringCellValue());//是否安全评估
  335. gyDataDO.setAssessResult(row.getCell(33).getStringCellValue());//评估结果
  336. gyDataDO.setIsCrossMain(row.getCell(34).getStringCellValue());//是否对外共享
  337. gyDataDO.setCrossmainAcceptName(row.getCell(35).getStringCellValue());//数据对外共享接收方
  338. gyDataDO.setDataCrossmainType(row.getCell(36).getStringCellValue());//数据对外共享方式
  339. gyDataDO.setIsForeignData(row.getCell(37).getStringCellValue());//是否为涉外数据
  340. gyDataDO.setIsCrossmainFlow(row.getCell(38).getStringCellValue());//是否涉及跨主体流动
  341. gyDataDO.setInfoSystemName(row.getCell(39).getStringCellValue());//信息系统名称
  342. gyDataDO.setInfoSystemIpAddress(row.getCell(40).getStringCellValue());//信息系统ip地址
  343. gyDataDO.setInfoSystemDomainName(row.getCell(41).getStringCellValue());//信息系统域名
  344. gyDataDO.setInfoSystemType(row.getCell(42).getStringCellValue());//信息系统类型
  345. gyDataDO.setSecurityCognizance(row.getCell(43).getStringCellValue());//网络安全等级保护认定情况
  346. gyDataDO.setComSecurityCognizance(row.getCell(44).getStringCellValue());//通信网络安全防护定级备案情况
  347. gyDataDO.setIsKetSystem(row.getCell(45).getStringCellValue());//是否为关键信息基础设施
  348. gyDataDO.setIsKeydataAss(row.getCell(46).getStringCellValue());//是否开展重要数据安全风险评估
  349. gyDataDO.setAssessOrg(row.getCell(47).getStringCellValue());//评估机构
  350. gyDataDO.setAssessBase(row.getCell(48).getStringCellValue());//评估依据的规范
  351. gyDataDO.setAssessTime(row.getCell(49).getStringCellValue());//评估时间
  352. gyDataDO.setDataAssessResult(row.getCell(50).getStringCellValue());//重要数据安全风险评估结论
  353. gyDataDO.setDataDesc(row.getCell(51).getStringCellValue());//备注
  354. gyDataDO.setGyUnitId(gyUnitDO.getCreditCode());//关联填报企业
  355. if (type == 1) { //导入列表导入
  356. gyDataDO.setSendVerify("0");// 送审状态 0:未送审 1:已送审
  357. gyDataDO.setDataStatus("0"); // 状态 0:待审核 1:删除 2:已上报 3:通过审核 4:驳回
  358. gyDataDO.setDeleteStatus("0"); // 状态 0:正常 1:删除
  359. if("1".equals(deployType)){ //市级单独部署
  360. gyDataDO.setAuditStage("1");
  361. } else if("2".equals(deployType)){ //省级单独部署
  362. gyDataDO.setAuditStage("2");
  363. } else if("3".equals(deployType)){ //省市一体部署
  364. gyDataDO.setAuditStage("1");
  365. }
  366. } else if(type == 2){ //数据目录导入
  367. gyDataDO.setSendVerify("1");// 送审状态 0:未送审 1:已送审
  368. gyDataDO.setDataStatus("3"); // 状态 0:待审核 1:删除 2:已上报 3:通过审核 4:驳回
  369. gyDataDO.setDeleteStatus("0"); // 状态 0:正常 1:删除
  370. if("1".equals(deployType)){ //市级单独部署
  371. throw new BDException("不支持该操作,请到“报送到省级”列表操作");
  372. } else if("2".equals(deployType)){ //省级单独部署
  373. gyDataDO.setAuditStage("2");
  374. } else if("3".equals(deployType)){ //省市一体部署
  375. if(StringUtils.isNotEmpty(currUser.getCity())){ //市级人员操作
  376. throw new BDException("市级人员无权操作");
  377. } else {
  378. gyDataDO.setAuditStage("2");
  379. }
  380. }
  381. } else { //上报到省级导入
  382. gyDataDO.setSendVerify("1");// 送审状态 0:未送审 1:已送审
  383. gyDataDO.setDataStatus("3"); // 状态 0:待审核 1:删除 2:已上报 3:通过审核 4:驳回
  384. gyDataDO.setDeleteStatus("0"); // 状态 0:正常 1:删除
  385. if("1".equals(deployType)){ //市级单独部署
  386. gyDataDO.setAuditStage("1");
  387. } else if("2".equals(deployType)){ //省级单独部署
  388. throw new BDException("不支持该操作,请到“数据目录”列表操作");
  389. } else if("3".equals(deployType)){ //省市一体部署
  390. if(StringUtils.isNotEmpty(currUser.getCity())){ //市级人员操作
  391. gyDataDO.setAuditStage("1");
  392. } else {
  393. if (managerValue.contains(currUser.getDeptId().toString())) { //机构是管理员
  394. gyDataDO.setAuditStage("1");
  395. } else { //一般省级人员
  396. throw new BDException("省级人员无权操作");
  397. }
  398. }
  399. }
  400. }
  401. gyDataDO.setUploadTime(new Date());
  402. gyDataDO.setUpdateTime(gyDataDO.getUploadTime());
  403. log.info("dataDO:" + gyDataDO.toString());
  404. Map<String, Object> params = new HashMap<>();
  405. params.put("dataName", gyDataDO.getDataName());// 数据名称
  406. params.put("gyUnitId", gyDataDO.getGyUnitId());// 单位
  407. //判断数据是否已经上传过
  408. List<GyDataImportDTO> listInfo = gyDataDao.listId(params);
  409. if (listInfo !=null && listInfo.size()>0) {
  410. GyDataImportDTO gyDataImportDTO = listInfo.get(0);
  411. if("3".equals(gyDataImportDTO.getDataStatus())){ //审核通过数据不导入
  412. log.info("审核通过数据id:" + gyDataImportDTO.getId());
  413. auditPass++;
  414. continue;
  415. } else{
  416. // 删除数据
  417. log.info("删除数据id:" + gyDataImportDTO.getId());
  418. gyDataDao.remove(gyDataImportDTO.getId());
  419. }
  420. }
  421. dataList.add(gyDataDO);
  422. }
  423. // 企业单位批量导入
  424. log.info("unitList size:" + gyUnitList.size());
  425. if (gyUnitList != null && gyUnitList.size() > 0) {
  426. for (GyUnitDO gyUnitDO : gyUnitList) {
  427. log.info("unitList size:" + gyUnitList.size());
  428. int count = gyUnitDao.getGyUnit(gyUnitDO);
  429. if (count == 0) {
  430. try {
  431. gyUnitDO.setCreateTime(new Date());
  432. gyUnitDO.setStatus("0");
  433. gyUnitDO.setAuditStatus("0");
  434. gyUnitDao.save(gyUnitDO);
  435. } catch (Exception e) {
  436. log.error("error enterprise-only : {}", e.getMessage());
  437. }
  438. }
  439. }
  440. }
  441. // 数据批量导入
  442. if (dataList != null && dataList.size() > 0) {
  443. gyDataDao.batchSave(dataList);
  444. }
  445. String result = null;
  446. if ((otherProvince + otherCity + auditPass + unitNoAudit) > 0) {
  447. StringBuilder sb = new StringBuilder();
  448. if (otherProvince > 0) {
  449. sb.append(otherProvince).append("条非本省数据(已忽略导入)! <br/>");
  450. }
  451. if (otherCity > 0) {
  452. sb.append(otherCity).append("条非本市数据(已忽略导入)! <br/>");
  453. }
  454. if (auditPass > 0) {
  455. sb.append(auditPass).append("条已经审核通过数据(已忽略导入)! <br/>");
  456. }
  457. if (unitNoAudit > 0) {
  458. sb.append(unitNoAudit).append("条所属企业未注册或还没通过审核(已忽略导入)! <br/>");
  459. }
  460. result = sb.toString();
  461. }
  462. return result;
  463. }
  464. @Override
  465. public GyDataImportDTO get(Long id) {
  466. return gyDataDao.get(id);
  467. }
  468. @Override
  469. public GyDataExcelDO getDataExcel(Long id) {
  470. return gyDataDao.getDataExcel(id);
  471. }
  472. @Override
  473. public GbDataExcelDO getGbDataExcel(Long id) {
  474. return gyDataDao.getGbDataExcel(id);
  475. }
  476. @Override
  477. public void updateStatus(GyDataImportDTO data) {
  478. int effect = gyDataDao.updateStatus(data);
  479. if ("2".equalsIgnoreCase(data.getDataStatus()) && effect > 0) {
  480. GyDataImportDTO gyDataImportDTO = get(data.getId());
  481. RoleDO roleDO = roleService.get(gyDataImportDTO.getRoleId());
  482. if (roleDO != null) {
  483. ExamineLogDTO dto = new ExamineLogDTO();
  484. dto.setUniqueKey(String.valueOf(data.getId()));
  485. dto.setDataType("DI_OPER");
  486. dto.setMessage("数据已送审至: " + roleDO.getRoleName());
  487. examineLogService.save(dto);
  488. }
  489. } else if ("3".equalsIgnoreCase(data.getDataStatus()) && effect > 0) {
  490. GyDataImportDTO gyDataImportDTO = get(data.getId());
  491. RoleDO roleDO = roleService.get(gyDataImportDTO.getRoleId());
  492. if (roleDO != null) {
  493. ExamineLogDTO dto = new ExamineLogDTO();
  494. dto.setUniqueKey(String.valueOf(data.getId()));
  495. dto.setDataType("DI_OPER");
  496. dto.setMessage("数据已被(" + roleDO.getRoleName() + ")审核通过");
  497. examineLogService.save(dto);
  498. }
  499. } else if ("4".equalsIgnoreCase(data.getDataStatus()) && effect > 0) {
  500. GyDataImportDTO gyDataImportDTO = get(data.getId());
  501. RoleDO roleDO = roleService.get(gyDataImportDTO.getRoleId());
  502. if (roleDO != null) {
  503. ExamineLogDTO dto = new ExamineLogDTO();
  504. dto.setUniqueKey(String.valueOf(data.getId()));
  505. dto.setDataType("DI_OPER");
  506. dto.setMessage("数据已被(" + roleDO.getRoleName() + ")审核驳回, 请核对");
  507. examineLogService.save(dto);
  508. }
  509. }
  510. }
  511. @Override
  512. public void addExpertOpinion(ExpertOpinionDO expertOpinionDO){
  513. GyDataImportDTO gyDataImportDTO = get(expertOpinionDO.getId());
  514. RoleDO roleDO = roleService.get(gyDataImportDTO.getRoleId());
  515. if (roleDO != null) {
  516. ExamineLogDTO dto = new ExamineLogDTO();
  517. dto.setUniqueKey(String.valueOf(expertOpinionDO.getId()));
  518. dto.setDataType("DI_OPER");
  519. dto.setMessage(roleDO.getRoleName() + "的专家意见为: " + expertOpinionDO.getOpinion());
  520. examineLogService.save(dto);
  521. }
  522. }
  523. @Override
  524. public void batchRemove(Long[] ids) {
  525. gyDataDao.batchRemove(ids);
  526. }
  527. @Override
  528. public List<GyDataImportDTO> listRecover(Map<String, Object> map) {
  529. UserDO currUser = ShiroUtils.getUser();
  530. log.info("currUser:" + currUser.toString());
  531. if (!managerValue.contains(currUser.getDeptId().toString())) {
  532. String province = currUser.getProvince();
  533. if(StringUtils.isEmpty(province)){
  534. province = sysProvince;
  535. }
  536. map.put("unitProvince", province);
  537. String city = currUser.getCity();
  538. if(StringUtils.isEmpty(city)){
  539. city = sysCity;
  540. }
  541. map.put("unitCity", city);
  542. if(!ObjectUtils.isEmpty(city)){
  543. map.put("auditStage", "1");
  544. } else {
  545. map.put("auditStage", "2");
  546. }
  547. }
  548. return gyDataDao.listRecover(map);
  549. }
  550. @Override
  551. public int countRecover(Map<String, Object> map) {
  552. UserDO currUser = ShiroUtils.getUser();
  553. log.info("currUser:" + currUser.toString());
  554. if (!managerValue.contains(currUser.getDeptId().toString())) {
  555. String province = currUser.getProvince();
  556. if(StringUtils.isEmpty(province)){
  557. province = sysProvince;
  558. }
  559. map.put("unitProvince", province);
  560. String city = currUser.getCity();
  561. if(StringUtils.isEmpty(city)){
  562. city = sysCity;
  563. }
  564. map.put("unitCity", city);
  565. if(!ObjectUtils.isEmpty(city)){
  566. map.put("auditStage", "1");
  567. } else {
  568. map.put("auditStage", "2");
  569. }
  570. }
  571. return gyDataDao.countRecover(map);
  572. }
  573. @Override
  574. public int recover(Long id) {
  575. GyDataImportDTO gyDataImportDTO = gyDataDao.getRecoverUnit(id);
  576. Map<String, Object> params = new HashMap<>();
  577. params.put("dataName", gyDataImportDTO.getDataName());// 数据名称
  578. params.put("gyUnitId", gyDataImportDTO.getGyUnitId());// 单位
  579. params.put("neqDataStatus", "4");
  580. List<GyDataImportDTO> listInfo = gyDataDao.list(params);
  581. if (listInfo !=null && listInfo.size()>0) {
  582. // 存在非驳回数据,不允许恢复
  583. return 0;
  584. }
  585. if ("1".equals(gyDataImportDTO.getStatus())) {
  586. unitService.updateUnitByCreditCode(gyDataImportDTO.getGyUnitId());
  587. }
  588. String auditStage =null;
  589. if("1".equals(deployType)){ //市级单独部署
  590. auditStage = "1";
  591. } else if("2".equals(deployType)){ //省级单独部署
  592. auditStage = "2";
  593. } else if("3".equals(deployType)){ //省市一体部署
  594. auditStage = "1";
  595. }
  596. return gyDataDao.recover(id, auditStage);
  597. }
  598. @Override
  599. public int batchPhysicalDeletion(Long id) {
  600. Long[] longArray = new Long[]{id};
  601. return gyDataDao.batchPhysicalDeletion(longArray);
  602. }
  603. @Override
  604. public void encryptExports(HttpServletResponse responses, String idValue) throws Exception {
  605. List<GyDataExcelDO> list = new ArrayList<>();
  606. JSONArray json = (JSONArray)JSONArray.parse(idValue);
  607. for (int i = 0; i < json.size(); i++) {
  608. String id = String.valueOf(json.get(i));
  609. log.info("批量导出 id:" + json.get(i));
  610. GyDataExcelDO data = new GyDataExcelDO();
  611. data = gyDataDao.getDataExcel(Long.parseLong(id));
  612. data.setNo(i + 1); //序号
  613. list.add(data);
  614. }
  615. log.info("list size:" + list.size());
  616. String decFile = bootdoConfig.getUploadPath() + "数据目录备案导出信息.xlsx";
  617. String encFile = bootdoConfig.getUploadPath() + "数据目录备案加密导出信息.xlsx";
  618. ExcelUtils.encryptExport(responses, EncryptExcelDO.class,list,bootdoConfig.getCrtPrival(),decFile,encFile);
  619. }
  620. /**
  621. * @Description: MultipartFile转file
  622. * @Author: wangp
  623. * @Date: 2022/2/25 9:15
  624. * @param multiFile
  625. * @param fileName
  626. * @Return: File
  627. */
  628. public static File MultipartFileToFile(MultipartFile multiFile, String fileName) {
  629. // 获取文件后缀
  630. String prefix = fileName.substring(fileName.lastIndexOf("."));
  631. log.info("fileName:" + fileName + ",prefix:" + prefix);
  632. // 若须要防止生成的临时文件重复,能够在文件名后添加随机码
  633. try {
  634. File file = new File(fileName);
  635. boolean res = file.createNewFile();
  636. if (!res) {
  637. log.info("创建失败!");
  638. } else {
  639. multiFile.transferTo(file);
  640. file.setExecutable(true);// 设置可执行权限
  641. file.setReadable(true);// 设置可读权限
  642. file.setWritable(true);// 设置可写权限
  643. }
  644. return file;
  645. } catch (Exception e) {
  646. e.printStackTrace();
  647. }
  648. return null;
  649. }
  650. public static void main(String[] args) {
  651. FileCryptTool.encryptFile("F:/dev-dys/sm2/sm2_client_enc_cert.crt", "F:/dev-dys/res/测试导入-河南.xlsx",
  652. "F:/dev-dys/res/enc-测试导入加密文件-河南.xlsx");
  653. FileCryptTool.encryptFile("F:/dev-dys/sm2/sm2_client_enc_cert.crt", "F:/dev-dys/res/测试导入-河北.xlsx",
  654. "F:/dev-dys/res/enc-测试导入加密文件-河北.xlsx");
  655. FileCryptTool.encryptFile("F:/dev-dys/sm2/sm2_client_enc_cert.crt", "F:/dev-dys/res/测试导入-四川.xlsx",
  656. "F:/dev-dys/res/enc-测试导入加密文件-四川.xlsx");
  657. }
  658. }