DataController.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. package com.bootdo.datas.controller;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.bootdo.common.annotation.Log;
  4. import com.bootdo.common.utils.*;
  5. import com.bootdo.datas.domain.GbDataExcelDO;
  6. import com.bootdo.datas.domain.GyDataExcelDO;
  7. import com.bootdo.datas.dto.GyDataImportDTO;
  8. import com.bootdo.datas.service.DataService;
  9. import com.bootdo.datas.service.GyDataService;
  10. import com.bootdo.datas.tools.ExcelUtils;
  11. import com.google.common.collect.Lists;
  12. import org.apache.shiro.authz.annotation.RequiresPermissions;
  13. import org.slf4j.Logger;
  14. import org.slf4j.LoggerFactory;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Controller;
  17. import org.springframework.ui.Model;
  18. import org.springframework.util.ObjectUtils;
  19. import org.springframework.web.bind.annotation.*;
  20. import org.springframework.web.multipart.MultipartFile;
  21. import javax.servlet.http.HttpServletResponse;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. import java.util.Map;
  25. /**
  26. * 重要数据表
  27. *
  28. * @author admin
  29. * @email admin@163.com
  30. * @date 2022-03-06 10:37:54
  31. */
  32. @Controller
  33. @RequestMapping("/datas/data")
  34. public class DataController {
  35. private static Logger log = LoggerFactory.getLogger(DataController.class);
  36. @Autowired
  37. private GyDataService gyDataService;
  38. @GetMapping()
  39. @Log("访问数据目录")
  40. @RequiresPermissions("datas:data:data")
  41. String Data() {
  42. return "datas/data/data";
  43. }
  44. @GetMapping("dataInfo")
  45. @RequiresPermissions("datas:data:data")
  46. String dataInfo(String type, String status, String cityName, Model model) {
  47. log.info("dataLevel:" + type);
  48. log.info("dataStatus:" + status);
  49. log.info("cityName:" + cityName);
  50. model.addAttribute("dataLevel", type);
  51. model.addAttribute("dataStatus", status);
  52. model.addAttribute("cityName", cityName);
  53. return "datas/data/dataInfo";
  54. }
  55. @ResponseBody
  56. @GetMapping("/list")
  57. @RequiresPermissions("datas:data:data")
  58. public PageUtils list(@RequestParam Map<String, Object> params) {
  59. // 查询列表数据
  60. Query query = new Query(params);
  61. query.put("dataStatusArrs", Lists.newArrayList(3));
  62. query.put("auditStageMenu", "2");
  63. query.put("neqDataStatus", "4");
  64. List<GyDataImportDTO> dataList = gyDataService.list(query);
  65. int total = gyDataService.countTotal(query);
  66. PageUtils pageUtils = new PageUtils(dataList, total);
  67. return pageUtils;
  68. }
  69. @GetMapping("/add")
  70. @RequiresPermissions("datas:data:add")
  71. String add() {
  72. return "datas/data/add";
  73. }
  74. /**
  75. * @Description: 跳转批量导入页面
  76. * @Author: wangp
  77. * @Date: 2022/3/21 10:06
  78. * @param
  79. * @Return: String
  80. */
  81. @GetMapping("/batchAdd")
  82. @RequiresPermissions("datas:data:data")
  83. String batchAdd() {
  84. return "datas/data/batchAdd";
  85. }
  86. @GetMapping("/edit/{id}")
  87. @RequiresPermissions("datas:data:edit")
  88. String edit(@PathVariable("id") Long id, Model model) {
  89. GyDataImportDTO data = gyDataService.get(id);
  90. model.addAttribute("data", data);
  91. return "datas/data/edit";
  92. }
  93. /**
  94. * 密文导入
  95. */
  96. @ResponseBody
  97. @PostMapping("/save")
  98. @RequiresPermissions("datas:data:add")
  99. public R save(@RequestParam("data_file") MultipartFile file) {
  100. try {
  101. String fileName = file.getOriginalFilename();
  102. log.info("fileName:" + fileName);
  103. String type = fileName.substring(fileName.lastIndexOf(".") + 1);
  104. // 根据excel类型取数据
  105. if ("xlsx".equals(type) || "xlsx".equals(type)) {
  106. // dataService.save(file);
  107. // 文件解密
  108. String decFlg = gyDataService.dec(file);
  109. log.info("decFlg:" + decFlg);
  110. if (StringUtils.isNotBlank(decFlg)) {
  111. String reault = gyDataService.cipherTextImport(decFlg, 2);
  112. if (!ObjectUtils.isEmpty(reault)) {
  113. return R.ok(fileName + ":" + reault);
  114. }
  115. } else {
  116. return R.error("文件解密异常!");
  117. }
  118. } else {
  119. return R.error("请使用excel导入!");
  120. }
  121. return R.ok("0");
  122. } catch (BDException e){
  123. return R.error(e.getMessage());
  124. } catch (Exception e) {
  125. e.printStackTrace();
  126. return R.error("导入失败");
  127. }
  128. }
  129. /**
  130. * 删除
  131. */
  132. @PostMapping("/remove")
  133. @ResponseBody
  134. @RequiresPermissions("datas:data:remove")
  135. public R remove(Long id) {
  136. //判断一下该条数据是否被风评系统使用
  137. int cnt = gyDataService.countAaAssData(id);
  138. if(cnt > 0){
  139. return R.error("该条数据已经被风评系统使用,不能删除!");
  140. }
  141. Long[] longArray = new Long[]{id};
  142. gyDataService.batchRemove(longArray);
  143. return R.ok();
  144. }
  145. /**
  146. * 删除
  147. */
  148. @PostMapping("/batchRemove")
  149. @ResponseBody
  150. @RequiresPermissions("datas:data:batchRemove")
  151. public R remove(@RequestParam("ids[]") Long[] ids) {
  152. gyDataService.batchRemove(ids);
  153. return R.ok();
  154. }
  155. /**
  156. * @Description: 列表页面 审核通过
  157. * @Author: wangp
  158. * @Date: 2022/3/6 16:35
  159. * @param id
  160. * @Return: R
  161. */
  162. @PostMapping("/verify")
  163. @ResponseBody
  164. @RequiresPermissions("datas:data:verify")
  165. public R verify(Long id) {
  166. log.info("审核通过 id:" + id);
  167. GyDataImportDTO data = new GyDataImportDTO();
  168. // 0:待审核 1:删除 2:已上报 3:通过审核 4:驳回
  169. data.setId(id);
  170. data.setDataStatus("3");
  171. gyDataService.updateStatus(data);
  172. return R.ok();
  173. }
  174. /**
  175. * @Description: 批量审核
  176. * @Author: wangp
  177. * @Date: 2022/3/6 16:35
  178. * @param ids
  179. * @Return: R
  180. */
  181. @PostMapping("/batchVerify")
  182. @ResponseBody
  183. @RequiresPermissions("datas:data:verify")
  184. public R batchVerify(@RequestParam("ids[]") Long[] ids) {
  185. log.info("批量审核通过 ids:" + ids.toString());
  186. List<String> failedDataNames = new ArrayList<>();
  187. List<GyDataImportDTO> dataImportDTOList = new ArrayList<>();
  188. for (Long id : ids) {
  189. log.info("审核通过 id:" + id);
  190. GyDataImportDTO data = new GyDataImportDTO();
  191. // 判断是否已审核过
  192. data = gyDataService.get(id);
  193. log.info("status:" + data.getDataStatus());
  194. if ("2".equals(data.getDataStatus()) || "5".equals(data.getDataStatus())
  195. || "6".equals(data.getDataStatus())) {
  196. // 0:待审核 1:删除 2:已上报 3:通过审核 4:驳回 5:联合审批 6:终审
  197. data.setId(id);
  198. data.setDataStatus("3");
  199. dataImportDTOList.add(data);
  200. } else {
  201. failedDataNames.add(data.getDataName());
  202. }
  203. }
  204. if (failedDataNames.size() > 0) {
  205. return R.error(String.join(",", failedDataNames) + ",审核失败");
  206. } else {
  207. if(dataImportDTOList.size() > 0){
  208. for(GyDataImportDTO importDTO : dataImportDTOList){
  209. gyDataService.updateStatus(importDTO);
  210. }
  211. }
  212. }
  213. return R.ok();
  214. }
  215. /**
  216. * @Description: 列表页面 驳回
  217. * @Author: wangp
  218. * @Date: 2022/3/6 16:35
  219. * @param id
  220. * @Return: R
  221. */
  222. @PostMapping("/rebut")
  223. @ResponseBody
  224. @RequiresPermissions("datas:data:rebut")
  225. public R rebut(Long id) {
  226. log.info("驳回 id:" + id);
  227. GyDataImportDTO data = new GyDataImportDTO();
  228. // 0:正常 1:删除 2:已上报 3:通过审核 4:驳回
  229. data.setId(id);
  230. data.setDataStatus("4");
  231. gyDataService.updateStatus(data);
  232. return R.ok();
  233. }
  234. /**
  235. * @Description: 批量审核
  236. * @Author: wangp
  237. * @Date: 2022/3/3 14:10
  238. * @param ids
  239. * @Return: R
  240. */
  241. @PostMapping("/batchRebut")
  242. @ResponseBody
  243. @RequiresPermissions("datas:data:rebut")
  244. public R batchRebut(@RequestParam("ids[]") Long[] ids) {
  245. log.info("审核通过 备案主键 ids:" + ids);
  246. List<String> failedDataNames = new ArrayList<>();
  247. List<GyDataImportDTO> dataImportDTOList = new ArrayList<>();
  248. for (Long id : ids) {
  249. log.info("审核通过 id:" + id);
  250. GyDataImportDTO data = new GyDataImportDTO();
  251. // 判断是否已审核过
  252. data = gyDataService.get(id);
  253. log.info("status:" + data.getDataStatus());
  254. if ("2".equals(data.getDataStatus()) || "5".equals(data.getDataStatus())
  255. || "6".equals(data.getDataStatus())) {
  256. // 0:待审核 1:删除 2:已上报 3:通过审核 4:驳回 5:联合审批 6:终审
  257. data.setId(id);
  258. data.setDataStatus("4");
  259. dataImportDTOList.add(data);
  260. } else {
  261. failedDataNames.add(data.getDataName());
  262. }
  263. }
  264. if (failedDataNames.size() > 0) {
  265. return R.error(String.join(",", failedDataNames) + ",驳回失败");
  266. } else {
  267. if(dataImportDTOList.size() > 0){
  268. for(GyDataImportDTO importDTO : dataImportDTOList){
  269. gyDataService.updateStatus(importDTO);
  270. }
  271. }
  272. }
  273. return R.ok();
  274. }
  275. /**
  276. * @Description: 批量导出
  277. * @Author: wangp
  278. * @Date: 2022/3/16 10:46
  279. * @param idValue
  280. * @Return: R
  281. */
  282. @GetMapping("/batchExports")
  283. public void batchExports(HttpServletResponse responses, String idValue) {
  284. log.info("批量导出 备案主键 idvalue:" + idValue);
  285. List<GyDataExcelDO> list = new ArrayList<>();
  286. JSONArray json = (JSONArray)JSONArray.parse(idValue);
  287. for (int i = 0; i < json.size(); i++) {
  288. String id = String.valueOf(json.get(i));
  289. log.info("批量导出 id:" + json.get(i));
  290. GyDataExcelDO data = new GyDataExcelDO();
  291. data = gyDataService.getDataExcel(Long.parseLong(id));
  292. data.setNo(i + 1); //序号
  293. list.add(data);
  294. }
  295. log.info("list size:" + list.size());
  296. // 导出xlsx操作
  297. try {
  298. ExcelUtils.export(responses, GyDataExcelDO.class, list, "数据备案导出信息");
  299. } catch (Exception e) {
  300. log.error("export error", e);
  301. }
  302. }
  303. /**
  304. * @Description: 国办导出
  305. */
  306. @GetMapping("/gbExports")
  307. @RequiresPermissions("datas:data:gbExport")
  308. public void gbExports(HttpServletResponse responses, String idValue) {
  309. log.info("批量导出 备案主键 idvalue:" + idValue);
  310. List<GbDataExcelDO> list = new ArrayList<>();
  311. JSONArray json = (JSONArray)JSONArray.parse(idValue);
  312. for (int i = 0; i < json.size(); i++) {
  313. String id = String.valueOf(json.get(i));
  314. log.info("批量导出 id:" + json.get(i));
  315. GbDataExcelDO data = new GbDataExcelDO();
  316. data = gyDataService.getGbDataExcel(Long.parseLong(id));
  317. data.setNo(i + 1); //序号
  318. list.add(data);
  319. }
  320. log.info("list size:" + list.size());
  321. // 导出xlsx操作
  322. try {
  323. ExcelUtils.export(responses, GbDataExcelDO.class, list, "国办导出信息");
  324. } catch (Exception e) {
  325. log.error("export error", e);
  326. }
  327. }
  328. /**
  329. * @Description: 加密导出
  330. */
  331. @GetMapping("/encryptExports")
  332. @RequiresPermissions("datas:data:encryptExports")
  333. public void encryptExports(HttpServletResponse responses, String idValue) throws Exception {
  334. log.info("批量导出 备案主键 idvalue:" + idValue);
  335. // 导出xlsx操作
  336. try {
  337. gyDataService.encryptExports(responses,idValue);
  338. } catch (Exception e) {
  339. log.error("export error", e);
  340. }
  341. }
  342. /**
  343. * @Description: 联合审批
  344. * @Author: wangp
  345. * @Date: 2022/3/6 16:35
  346. * @param ids
  347. * @Return: R
  348. */
  349. @PostMapping("/nextVerify/{deptId}")
  350. @ResponseBody
  351. @RequiresPermissions("datas:data:nextVerify")
  352. public R nextVerify(@RequestParam("ids[]") Long[] ids, @PathVariable("deptId") Long deptId) {
  353. log.info("联合审批通过 ids:" + ids.toString());
  354. log.info("联合审批通过 deptId:" + deptId);
  355. for (Long id : ids) {
  356. log.info("联合审批通过 id:" + id);
  357. GyDataImportDTO data = new GyDataImportDTO();
  358. // 判断是否已审核过
  359. data = gyDataService.get(id);
  360. log.info("status:" + data.getDataStatus());
  361. if ("2".equals(data.getDataStatus())) {
  362. // 0:待审核 1:删除 2:已上报 3:通过审核 4:驳回
  363. data.setId(id);
  364. data.setSendVerify("3");
  365. data.setNextVerifyDept(deptId);
  366. gyDataService.updateStatus(data);
  367. }
  368. }
  369. return R.ok();
  370. }
  371. /**
  372. * @Description: 跳转批量导入页面
  373. * @Author: wangp
  374. * @Date: 2022/3/21 10:06
  375. * @param
  376. * @Return: String
  377. */
  378. @GetMapping("/dataImport")
  379. @RequiresPermissions("datas:data:plainTextImport")
  380. String dataImport() {
  381. return "datas/data/dataImport";
  382. }
  383. /**
  384. * @Description: 明文导入
  385. * @Author: wangp
  386. * @Date: 2022/6/10 15:01
  387. * @param file
  388. * @Return: R
  389. */
  390. @ResponseBody
  391. @PostMapping("/plainTextImport")
  392. @RequiresPermissions("datas:data:plainTextImport")
  393. public R plainTextImport(@RequestParam("data_file") MultipartFile file) {
  394. try {
  395. String fileName = file.getOriginalFilename();
  396. log.info("fileName:" + fileName);
  397. String type = fileName.substring(fileName.lastIndexOf(".") + 1);
  398. // 根据excel类型取数据
  399. if ("xlsx".equals(type) || "xlsx".equals(type)) {
  400. String reault = gyDataService.plainTextImport(file, 2);
  401. if (!ObjectUtils.isEmpty(reault)) {
  402. return R.ok(fileName + ":" + reault);
  403. }
  404. } else {
  405. return R.error("请使用excel导入!");
  406. }
  407. return R.ok("0");
  408. } catch (BDException e){
  409. return R.error(e.getMessage());
  410. } catch (Exception e) {
  411. e.printStackTrace();
  412. return R.error("导入失败");
  413. }
  414. }
  415. }