GyDataServiceImpl.java 37 KB

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