SealHandoverController.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. /*
  2. * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * Neither the name of the dreamlu.net developer nor the names of its
  13. * contributors may be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. * Author: Chill 庄骞 (smallchill@163.com)
  16. */
  17. package org.springblade.bank.sealhandover.controller;
  18. import cn.hutool.json.JSONUtil;
  19. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  20. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  21. import com.baomidou.mybatisplus.core.metadata.IPage;
  22. import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
  23. import io.swagger.annotations.Api;
  24. import io.swagger.annotations.ApiOperation;
  25. import io.swagger.annotations.ApiParam;
  26. import lombok.AllArgsConstructor;
  27. import org.apache.commons.lang.StringUtils;
  28. import org.springblade.bank.sealhandover.entity.SealHandover;
  29. import org.springblade.bank.sealhandover.service.ISealHandoverService;
  30. import org.springblade.bank.sealhandover.vo.SealHandoverVO;
  31. import org.springblade.bank.sealhandover.wrapper.SealHandoverWrapper;
  32. import org.springblade.bank.userlog.entity.UserLog;
  33. import org.springblade.bank.userlog.service.IUserLogService;
  34. import org.springblade.core.boot.ctrl.BladeController;
  35. import org.springblade.core.mp.support.Condition;
  36. import org.springblade.core.mp.support.Query;
  37. import org.springblade.core.secure.BladeUser;
  38. import org.springblade.core.secure.utils.AuthUtil;
  39. import org.springblade.core.tool.api.R;
  40. import org.springblade.core.tool.utils.DateUtil;
  41. import org.springblade.core.tool.utils.Func;
  42. import org.springblade.modules.desk.service.INoticeService;
  43. import org.springblade.modules.system.entity.Dept;
  44. import org.springblade.modules.system.entity.Dict;
  45. import org.springblade.modules.system.entity.User;
  46. import org.springblade.modules.system.service.IDeptService;
  47. import org.springblade.modules.system.service.IDictService;
  48. import org.springblade.modules.system.service.IUserService;
  49. import org.springframework.util.Assert;
  50. import org.springframework.web.bind.annotation.*;
  51. import javax.validation.Valid;
  52. import java.util.*;
  53. /**
  54. * 業務印章交接登記表 控制器
  55. *
  56. * @author BladeX
  57. * @since 2021-08-13
  58. */
  59. @RestController
  60. @AllArgsConstructor
  61. @RequestMapping("bank/sealhandover")
  62. @Api(value = "業務印章交接登記表", tags = "業務印章交接登記表接口")
  63. public class SealHandoverController extends BladeController {
  64. private final ISealHandoverService sealHandoverService;
  65. private final IUserLogService userLogService;
  66. private final IUserService userService;
  67. private final IDeptService deptService;
  68. private final IDictService dictService;
  69. private final INoticeService noticeService;
  70. /**
  71. * 详情
  72. */
  73. @GetMapping("/detail")
  74. @ApiOperationSupport(order = 1)
  75. @ApiOperation(value = "详情", notes = "传入sealHandover")
  76. public R<SealHandoverVO> detail(SealHandover sealHandover) {
  77. SealHandover detail = sealHandoverService.getOne(Condition.getQueryWrapper(sealHandover));
  78. return R.data(SealHandoverWrapper.build().entityVO(detail));
  79. }
  80. /**
  81. * 分页 業務印章交接登記表
  82. */
  83. @GetMapping("/list")
  84. @ApiOperationSupport(order = 2)
  85. @ApiOperation(value = "分页", notes = "传入sealHandover")
  86. public R<IPage<SealHandoverVO>> list(SealHandover sealHandover, Query query) {
  87. IPage<SealHandover> pages = sealHandoverService.page(Condition.getPage(query), Condition.getQueryWrapper(sealHandover));
  88. return R.data(SealHandoverWrapper.build().pageVO(pages));
  89. }
  90. /**
  91. * 自定义分页 業務印章交接登記表
  92. */
  93. @GetMapping("/page")
  94. @ApiOperationSupport(order = 3)
  95. @ApiOperation(value = "分页", notes = "传入sealHandover")
  96. public R<IPage<SealHandoverVO>> page(SealHandoverVO sealHandover, Query query) {
  97. Long deptId = Long.valueOf(AuthUtil.getDeptId());
  98. List<Long> deptChildIds = deptService.getDeptChildIds(deptId);
  99. deptChildIds.add(deptId);
  100. sealHandover.setDeptIdList(deptChildIds);
  101. sealHandover.setCurrentuserId(AuthUtil.getUserId());
  102. if (StringUtils.isNotBlank(sealHandover.getSealType())){
  103. List<String> sealTypes = Func.toStrList(sealHandover.getSealType());
  104. sealHandover.setSealTypes(sealTypes);
  105. }
  106. if (StringUtils.isNotBlank(sealHandover.getOrgNostr())){
  107. List<String> orgNos = Func.toStrList(sealHandover.getOrgNostr());
  108. sealHandover.setOrgNos(orgNos);
  109. }
  110. IPage<SealHandoverVO> pages = sealHandoverService.selectSealHandoverPage(Condition.getPage(query), sealHandover);
  111. return R.data(pages);
  112. }
  113. /**
  114. * 自定义分页 業務印章交接登記表
  115. */
  116. @GetMapping("/getKeepList")
  117. @ApiOperationSupport(order = 3)
  118. @ApiOperation(value = "分页", notes = "传入sealHandover")
  119. public R<List<SealHandoverVO>> getKeepList(SealHandoverVO sealHandover) {
  120. if (StringUtils.isNotBlank(sealHandover.getSealType())){
  121. List<String> sealTypes = Func.toStrList(sealHandover.getSealType());
  122. sealHandover.setSealTypes(sealTypes);
  123. }
  124. if (StringUtils.isNotBlank(sealHandover.getOrgNostr())){
  125. List<String> orgNos = Func.toStrList(sealHandover.getOrgNostr());
  126. sealHandover.setOrgNos(orgNos);
  127. }
  128. List<SealHandoverVO> list = sealHandoverService.getList(sealHandover);
  129. List<SealHandover> turnInList = sealHandoverService.getTurnInList();
  130. HashSet<Map> set = new HashSet<>();
  131. for (int i = 0; i < list.size(); i++) {
  132. SealHandover item = list.get(i);
  133. boolean flag = false;
  134. for (int j = 0; j < turnInList.size(); j++) {
  135. SealHandover turnIn = turnInList.get(j);
  136. if (item.getSealType().equals(turnIn.getSealType()) && item.getSealNo().equals(turnIn.getSealNo())){
  137. list.remove(i);
  138. i--;
  139. flag = true;
  140. break;
  141. }
  142. }
  143. if (!flag){
  144. HashMap<String, Object> map = new HashMap<>();
  145. map.put("bankNo", item.getBankNo());
  146. map.put("orgNo", item.getOrgNo());
  147. map.put("sealType", item.getSealType());
  148. map.put("sealNo", item.getSealNo());
  149. int size1 = set.size();
  150. set.add(map);
  151. if (set.size() == size1){
  152. list.remove(i);
  153. i--;
  154. }
  155. }
  156. }
  157. return R.data(list);
  158. }
  159. /**
  160. *
  161. * @param sealHandover
  162. * @return
  163. */
  164. @GetMapping("/getList")
  165. @ApiOperationSupport(order = 3)
  166. @ApiOperation(value = "分页", notes = "传入sealHandover")
  167. public R getList(SealHandoverVO sealHandover) {
  168. if (StringUtils.isNotBlank(sealHandover.getSealType())){
  169. List<String> sealTypes = Func.toStrList(sealHandover.getSealType());
  170. sealHandover.setSealTypes(sealTypes);
  171. }
  172. if (StringUtils.isNotBlank(sealHandover.getOrgNostr())){
  173. List<String> orgNos = Func.toStrList(sealHandover.getOrgNostr());
  174. sealHandover.setOrgNos(orgNos);
  175. }
  176. List<SealHandoverVO> list = sealHandoverService.getList(sealHandover);
  177. for (int i = 0; i < list.size(); i++) {
  178. SealHandover seal = list.get(i);
  179. String sealType = seal.getSealType();
  180. String value = dictService.getValue("seal_type", sealType);
  181. seal.setSealType(value);
  182. }
  183. /*list.forEach(seal -> {
  184. String sealType = seal.getSealType();
  185. String value = dictService.getValue("seal_type", sealType);
  186. seal.setSealType(value);
  187. });*/
  188. return R.data(list);
  189. }
  190. /**
  191. * 確認 業務印章交接登記表
  192. */
  193. @PostMapping("/sure")
  194. @ApiOperationSupport(order = 4)
  195. @ApiOperation(value = "確認", notes = "传入sealHandover")
  196. public R sure(@Valid @RequestBody SealHandover sealHandover) {
  197. sealHandover.setProcess(3);
  198. sealHandover.setSureTime(DateUtil.now());
  199. if (sealHandoverService.updateById(sealHandover)){
  200. User user = userService.getById(AuthUtil.getUserId());
  201. Dept dept = deptService.getById(user.getDeptId());
  202. UserLog userLog = new UserLog();
  203. userLog.setTableName("sealhandover");
  204. userLog.setBankNo(dept.getBankNo());
  205. userLog.setOrgNo(dept.getOrgNo());
  206. userLog.setOrgName(dept.getDeptName());
  207. userLog.setNewData(JSONUtil.toJsonStr(sealHandover));
  208. userLog.setPersonNo(user.getEhr());
  209. userLog.setPersonName(user.getName());
  210. userLog.setOperationType("sure");
  211. userLogService.save(userLog);
  212. //發送通知
  213. noticeService.sendSealNotice(sealHandover, false, true);
  214. }
  215. return R.status(true);
  216. }
  217. /**
  218. * 修改 業務印章交接登記表
  219. */
  220. @PostMapping("/update")
  221. @ApiOperationSupport(order = 5)
  222. @ApiOperation(value = "修改", notes = "传入sealHandover")
  223. public R update(@Valid @RequestBody SealHandover sealHandover) {
  224. return R.status(sealHandoverService.updateById(sealHandover));
  225. }
  226. /**
  227. * 新增或修改 業務印章交接登記表
  228. */
  229. @PostMapping("/submit")
  230. @ApiOperationSupport(order = 6)
  231. @ApiOperation(value = "新增或修改", notes = "传入sealHandover")
  232. public R submit(@Valid @RequestBody SealHandover sealHandover) {
  233. boolean isAdd = sealHandover.getId() == null;
  234. BladeUser currentUser = AuthUtil.getUser();
  235. User user = userService.getById(currentUser.getUserId());
  236. Dept dept = deptService.getById(user.getDeptId());
  237. UserLog userLog = new UserLog();
  238. if (StringUtils.isNotBlank(sealHandover.getReceiverNo())){
  239. Assert.isTrue(!sealHandover.getReceiverNo().equals(sealHandover.getHandoverPersonNo()), "交出人不可為接收人!請重新選擇!");
  240. }
  241. SealHandover old = null;
  242. if (isAdd){
  243. sealHandover.setProcess(2);
  244. sealHandover.setFillingPerson(currentUser.getUserName());
  245. sealHandover.setFillingDate(DateUtil.now());
  246. }else{
  247. old = sealHandoverService.getById(sealHandover.getId());
  248. }
  249. if (sealHandoverService.saveOrUpdate(sealHandover)){
  250. userLog.setTableName("sealhandover");
  251. userLog.setBankNo(dept.getBankNo());
  252. userLog.setOrgNo(dept.getOrgNo());
  253. userLog.setOrgName(dept.getDeptName());
  254. userLog.setNewData(JSONUtil.toJsonStr(sealHandover));
  255. userLog.setPersonNo(user.getEhr());
  256. userLog.setPersonName(user.getName());
  257. if (isAdd){
  258. userLog.setOperationType("add");
  259. //發送通知
  260. noticeService.sendSealNotice(sealHandover, false, false);
  261. }else{
  262. userLog.setOperationType("edit");
  263. userLog.setOldData(JSONUtil.toJsonStr(old));
  264. //發送通知
  265. noticeService.sendSealNotice(sealHandover, true, false);
  266. }
  267. userLogService.save(userLog);
  268. }
  269. return R.status(true);
  270. }
  271. /**
  272. * 删除 業務印章交接登記表
  273. */
  274. @PostMapping("/remove")
  275. @ApiOperationSupport(order = 7)
  276. @ApiOperation(value = "逻辑删除", notes = "传入ids")
  277. public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
  278. List<Long> idList = Func.toLongList(ids);
  279. List<UserLog> userLogList = new ArrayList<>();
  280. // 日誌記錄
  281. BladeUser currentUser = AuthUtil.getUser();
  282. User user = userService.getById(currentUser.getUserId());
  283. Dept dept = deptService.getById(user.getDeptId());
  284. idList.forEach(id -> {
  285. UserLog userLog = new UserLog();
  286. SealHandover sealHandover = sealHandoverService.getById(id);
  287. userLog.setTableName("sealhandover");
  288. userLog.setOperationType("del");
  289. userLog.setBankNo(dept.getBankNo());
  290. userLog.setOrgNo(dept.getOrgNo());
  291. userLog.setOrgName(dept.getDeptName());
  292. userLog.setOldData(JSONUtil.toJsonStr(sealHandover));
  293. userLog.setPersonNo(user.getEhr());
  294. userLog.setPersonName(user.getName());
  295. userLogList.add(userLog);
  296. });
  297. return R.status(sealHandoverService.deleteLogic(idList) && userLogService.saveBatch(userLogList));
  298. }
  299. /**
  300. * 根據交接日期來排序,判斷最新一條記錄
  301. * @param sealNo
  302. * @param sealType
  303. * @param orgNo
  304. * @return
  305. */
  306. @GetMapping("/getByNoAndType")
  307. @ApiOperationSupport(order = 8)
  308. @ApiOperation(value = "获取最新一条记录", notes = "传入category,type")
  309. public R getByNoAndType(@ApiParam(required = true) @RequestParam String sealNo, @ApiParam(required = true) @RequestParam String sealType, @ApiParam(required = true) @RequestParam String orgNo){
  310. LambdaQueryWrapper<SealHandover> eq = new QueryWrapper<>(new SealHandover()).lambda().eq(SealHandover::getSealNo, sealNo)
  311. .eq(SealHandover::getSealType, sealType).eq(SealHandover::getOrgNo, orgNo).orderByDesc(SealHandover::getFillingDate);
  312. List<SealHandover> list = sealHandoverService.list(eq);
  313. if (list != null && list.size() > 0){
  314. return R.data(list.get(0));
  315. }
  316. return R.data(null);
  317. }
  318. /**
  319. * 業務印章持有量匯總表
  320. * @return
  321. */
  322. @GetMapping("/getOrgsSealhandoverCount")
  323. public R getOrgsSealhandoverCount(){
  324. Map data = new HashMap();
  325. Dept currDept = deptService.getById(AuthUtil.getDeptId());
  326. List<Long> deptChildIds = deptService.getDeptChildIds(currDept.getId());
  327. List<Dict> sealList = dictService.getList("seal_type");
  328. List sealData = new ArrayList();
  329. deptChildIds.forEach(deptId -> {
  330. Dept dept = deptService.getById(deptId);
  331. if (!dept.getOrgNo().startsWith("999")){
  332. Map map = this.getKeepCountByDept(dept);
  333. if (map != null){
  334. sealData.add(map);
  335. }
  336. }
  337. });
  338. data.put("sealTypeList", sealList);
  339. data.put("sealData", sealData);
  340. return R.data(data);
  341. }
  342. /**
  343. * 業務印章持有量匯總表-支行
  344. * @param dept
  345. * @return
  346. */
  347. private Map getKeepCountByDept(Dept dept){
  348. Map map = new HashMap();
  349. map.put("orgName", dept.getDeptName());
  350. SealHandoverVO sealHandoverVO = new SealHandoverVO();
  351. sealHandoverVO.setOrgNostr(dept.getOrgNo());
  352. R<List<SealHandoverVO>> keepListR = this.getKeepList(sealHandoverVO);
  353. List<SealHandoverVO> keepList = keepListR.getData();
  354. if (keepList.size() > 0){
  355. for (int i = 0; i < keepList.size(); i++) {
  356. SealHandover item = keepList.get(i);
  357. String key = "seal_type" + item.getSealType();
  358. if (map.containsKey(key)){
  359. map.put(key, Integer.valueOf(map.get(key).toString()) + 1);
  360. }else{
  361. map.put(key, 1);
  362. }
  363. }
  364. }
  365. return map;
  366. }
  367. }