DataController.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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();
  122. } catch (BDException e){
  123. return R.error(e.getMessage());
  124. }
  125. }
  126. /**
  127. * 删除
  128. */
  129. @PostMapping("/remove")
  130. @ResponseBody
  131. @RequiresPermissions("datas:data:remove")
  132. public R remove(Long id) {
  133. Long[] longArray = new Long[]{id};
  134. gyDataService.batchRemove(longArray);
  135. return R.ok();
  136. }
  137. /**
  138. * 删除
  139. */
  140. @PostMapping("/batchRemove")
  141. @ResponseBody
  142. @RequiresPermissions("datas:data:batchRemove")
  143. public R remove(@RequestParam("ids[]") Long[] ids) {
  144. gyDataService.batchRemove(ids);
  145. return R.ok();
  146. }
  147. /**
  148. * @Description: 列表页面 审核通过
  149. * @Author: wangp
  150. * @Date: 2022/3/6 16:35
  151. * @param id
  152. * @Return: R
  153. */
  154. @PostMapping("/verify")
  155. @ResponseBody
  156. @RequiresPermissions("datas:data:verify")
  157. public R verify(Long id) {
  158. log.info("审核通过 id:" + id);
  159. GyDataImportDTO data = new GyDataImportDTO();
  160. // 0:待审核 1:删除 2:已上报 3:通过审核 4:驳回
  161. data.setId(id);
  162. data.setDataStatus("3");
  163. gyDataService.updateStatus(data);
  164. return R.ok();
  165. }
  166. /**
  167. * @Description: 批量审核
  168. * @Author: wangp
  169. * @Date: 2022/3/6 16:35
  170. * @param ids
  171. * @Return: R
  172. */
  173. @PostMapping("/batchVerify")
  174. @ResponseBody
  175. @RequiresPermissions("datas:data:verify")
  176. public R batchVerify(@RequestParam("ids[]") Long[] ids) {
  177. log.info("批量审核通过 ids:" + ids.toString());
  178. List<String> failedDataNames = new ArrayList<>();
  179. for (Long id : ids) {
  180. log.info("审核通过 id:" + id);
  181. GyDataImportDTO data = new GyDataImportDTO();
  182. // 判断是否已审核过
  183. data = gyDataService.get(id);
  184. log.info("status:" + data.getDataStatus());
  185. if ("2".equals(data.getDataStatus()) || "5".equals(data.getDataStatus())
  186. || "6".equals(data.getDataStatus())) {
  187. // 0:待审核 1:删除 2:已上报 3:通过审核 4:驳回 5:联合审批 6:终审
  188. data.setId(id);
  189. data.setDataStatus("3");
  190. gyDataService.updateStatus(data);
  191. } else {
  192. failedDataNames.add(data.getDataName());
  193. }
  194. }
  195. if (failedDataNames.size() > 0) {
  196. return R.error(String.join(",", failedDataNames) + ",审核失败");
  197. }
  198. return R.ok();
  199. }
  200. /**
  201. * @Description: 列表页面 驳回
  202. * @Author: wangp
  203. * @Date: 2022/3/6 16:35
  204. * @param id
  205. * @Return: R
  206. */
  207. @PostMapping("/rebut")
  208. @ResponseBody
  209. @RequiresPermissions("datas:data:rebut")
  210. public R rebut(Long id) {
  211. log.info("驳回 id:" + id);
  212. GyDataImportDTO data = new GyDataImportDTO();
  213. // 0:正常 1:删除 2:已上报 3:通过审核 4:驳回
  214. data.setId(id);
  215. data.setDataStatus("4");
  216. gyDataService.updateStatus(data);
  217. return R.ok();
  218. }
  219. /**
  220. * @Description: 批量审核
  221. * @Author: wangp
  222. * @Date: 2022/3/3 14:10
  223. * @param ids
  224. * @Return: R
  225. */
  226. @PostMapping("/batchRebut")
  227. @ResponseBody
  228. @RequiresPermissions("datas:data:rebut")
  229. public R batchRebut(@RequestParam("ids[]") Long[] ids) {
  230. log.info("审核通过 备案主键 ids:" + ids);
  231. for (Long id : ids) {
  232. log.info("审核通过 id:" + id);
  233. GyDataImportDTO data = new GyDataImportDTO();
  234. // 判断是否已审核过
  235. data = gyDataService.get(id);
  236. log.info("status:" + data.getDataStatus());
  237. if ("2".equals(data.getDataStatus()) || "5".equals(data.getDataStatus())
  238. || "6".equals(data.getDataStatus())) {
  239. // 0:待审核 1:删除 2:已上报 3:通过审核 4:驳回 5:联合审批 6:终审
  240. data.setId(id);
  241. data.setDataStatus("4");
  242. gyDataService.updateStatus(data);
  243. }
  244. }
  245. return R.ok();
  246. }
  247. /**
  248. * @Description: 批量导出
  249. * @Author: wangp
  250. * @Date: 2022/3/16 10:46
  251. * @param idValue
  252. * @Return: R
  253. */
  254. @GetMapping("/batchExports")
  255. public void batchExports(HttpServletResponse responses, String idValue) {
  256. log.info("批量导出 备案主键 idvalue:" + idValue);
  257. List<GyDataExcelDO> list = new ArrayList<>();
  258. JSONArray json = (JSONArray)JSONArray.parse(idValue);
  259. for (int i = 0; i < json.size(); i++) {
  260. String id = String.valueOf(json.get(i));
  261. log.info("批量导出 id:" + json.get(i));
  262. GyDataExcelDO data = new GyDataExcelDO();
  263. data = gyDataService.getDataExcel(Long.parseLong(id));
  264. data.setNo(i + 1); //序号
  265. list.add(data);
  266. }
  267. log.info("list size:" + list.size());
  268. // 导出xlsx操作
  269. try {
  270. ExcelUtils.export(responses, GyDataExcelDO.class, list, "数据备案导出信息");
  271. } catch (Exception e) {
  272. log.error("export error", e);
  273. }
  274. }
  275. /**
  276. * @Description: 国办导出
  277. */
  278. @GetMapping("/gbExports")
  279. @RequiresPermissions("datas:data:gbExport")
  280. public void gbExports(HttpServletResponse responses, String idValue) {
  281. log.info("批量导出 备案主键 idvalue:" + idValue);
  282. List<GbDataExcelDO> list = new ArrayList<>();
  283. JSONArray json = (JSONArray)JSONArray.parse(idValue);
  284. for (int i = 0; i < json.size(); i++) {
  285. String id = String.valueOf(json.get(i));
  286. log.info("批量导出 id:" + json.get(i));
  287. GbDataExcelDO data = new GbDataExcelDO();
  288. data = gyDataService.getGbDataExcel(Long.parseLong(id));
  289. data.setNo(i + 1); //序号
  290. list.add(data);
  291. }
  292. log.info("list size:" + list.size());
  293. // 导出xlsx操作
  294. try {
  295. ExcelUtils.export(responses, GbDataExcelDO.class, list, "国办导出信息");
  296. } catch (Exception e) {
  297. log.error("export error", e);
  298. }
  299. }
  300. /**
  301. * @Description: 加密导出
  302. */
  303. @GetMapping("/encryptExports")
  304. @RequiresPermissions("datas:data:encryptExports")
  305. public void encryptExports(HttpServletResponse responses, String idValue) throws Exception {
  306. log.info("批量导出 备案主键 idvalue:" + idValue);
  307. // 导出xlsx操作
  308. try {
  309. gyDataService.encryptExports(responses,idValue);
  310. } catch (Exception e) {
  311. log.error("export error", e);
  312. }
  313. }
  314. /**
  315. * @Description: 联合审批
  316. * @Author: wangp
  317. * @Date: 2022/3/6 16:35
  318. * @param ids
  319. * @Return: R
  320. */
  321. @PostMapping("/nextVerify/{deptId}")
  322. @ResponseBody
  323. @RequiresPermissions("datas:data:nextVerify")
  324. public R nextVerify(@RequestParam("ids[]") Long[] ids, @PathVariable("deptId") Long deptId) {
  325. log.info("联合审批通过 ids:" + ids.toString());
  326. log.info("联合审批通过 deptId:" + deptId);
  327. for (Long id : ids) {
  328. log.info("联合审批通过 id:" + id);
  329. GyDataImportDTO data = new GyDataImportDTO();
  330. // 判断是否已审核过
  331. data = gyDataService.get(id);
  332. log.info("status:" + data.getDataStatus());
  333. if ("2".equals(data.getDataStatus())) {
  334. // 0:待审核 1:删除 2:已上报 3:通过审核 4:驳回
  335. data.setId(id);
  336. data.setSendVerify("3");
  337. data.setNextVerifyDept(deptId);
  338. gyDataService.updateStatus(data);
  339. }
  340. }
  341. return R.ok();
  342. }
  343. /**
  344. * @Description: 跳转批量导入页面
  345. * @Author: wangp
  346. * @Date: 2022/3/21 10:06
  347. * @param
  348. * @Return: String
  349. */
  350. @GetMapping("/dataImport")
  351. @RequiresPermissions("datas:data:plainTextImport")
  352. String dataImport() {
  353. return "datas/data/dataImport";
  354. }
  355. /**
  356. * @Description: 明文导入
  357. * @Author: wangp
  358. * @Date: 2022/6/10 15:01
  359. * @param file
  360. * @Return: R
  361. */
  362. @ResponseBody
  363. @PostMapping("/plainTextImport")
  364. @RequiresPermissions("datas:data:plainTextImport")
  365. public R plainTextImport(@RequestParam("data_file") MultipartFile file) {
  366. try {
  367. String fileName = file.getOriginalFilename();
  368. log.info("fileName:" + fileName);
  369. String type = fileName.substring(fileName.lastIndexOf(".") + 1);
  370. // 根据excel类型取数据
  371. if ("xlsx".equals(type) || "xlsx".equals(type)) {
  372. String reault = gyDataService.plainTextImport(file, 2);
  373. if (!ObjectUtils.isEmpty(reault)) {
  374. return R.ok(fileName + ":" + reault);
  375. }
  376. } else {
  377. return R.error("请使用excel导入!");
  378. }
  379. return R.ok();
  380. } catch (BDException e){
  381. return R.error(e.getMessage());
  382. }
  383. }
  384. }