KeyPwdController.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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.keypwd.controller;
  18. import cn.hutool.json.JSONUtil;
  19. import com.baomidou.mybatisplus.core.conditions.Wrapper;
  20. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  21. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  22. import com.baomidou.mybatisplus.core.metadata.IPage;
  23. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  24. import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
  25. import io.swagger.annotations.Api;
  26. import io.swagger.annotations.ApiOperation;
  27. import io.swagger.annotations.ApiParam;
  28. import lombok.AllArgsConstructor;
  29. import org.apache.commons.lang.StringUtils;
  30. import org.springblade.bank.keypwd.entity.KeyPwd;
  31. import org.springblade.bank.keypwd.service.IKeyPwdService;
  32. import org.springblade.bank.keypwd.vo.KeyPwdVO;
  33. import org.springblade.bank.keypwd.wrapper.KeyPwdWrapper;
  34. import org.springblade.bank.userlog.entity.UserLog;
  35. import org.springblade.bank.userlog.service.IUserLogService;
  36. import org.springblade.core.boot.ctrl.BladeController;
  37. import org.springblade.core.mp.support.Condition;
  38. import org.springblade.core.mp.support.Query;
  39. import org.springblade.core.secure.BladeUser;
  40. import org.springblade.core.secure.utils.AuthUtil;
  41. import org.springblade.core.tool.api.R;
  42. import org.springblade.core.tool.utils.BeanUtil;
  43. import org.springblade.core.tool.utils.DateUtil;
  44. import org.springblade.core.tool.utils.Func;
  45. import org.springblade.core.tool.utils.StringUtil;
  46. import org.springblade.modules.desk.entity.Notice;
  47. import org.springblade.modules.desk.service.INoticeService;
  48. import org.springblade.modules.system.entity.Dept;
  49. import org.springblade.modules.system.entity.User;
  50. import org.springblade.modules.system.service.IDeptService;
  51. import org.springblade.modules.system.service.IDictService;
  52. import org.springblade.modules.system.service.IUserService;
  53. import org.springframework.util.Assert;
  54. import org.springframework.web.bind.annotation.*;
  55. import javax.validation.Valid;
  56. import java.util.*;
  57. import java.util.stream.Collectors;
  58. /**
  59. * 網點鎖匙/密碼登記表 控制器
  60. *
  61. * @author BladeX
  62. * @since 2021-08-13
  63. */
  64. @RestController
  65. @AllArgsConstructor
  66. @RequestMapping("bank/keypwd")
  67. @Api(value = "網點鎖匙/密碼登記表", tags = "網點鎖匙/密碼登記表接口")
  68. public class KeyPwdController extends BladeController {
  69. private final IKeyPwdService keyPwdService;
  70. private final IUserLogService userLogService;
  71. private final IUserService userService;
  72. private final IDeptService deptService;
  73. private final IDictService dictService;
  74. private final INoticeService noticeService;
  75. /**
  76. * 详情
  77. */
  78. @GetMapping("/detail")
  79. @ApiOperationSupport(order = 1)
  80. @ApiOperation(value = "详情", notes = "传入keyPwd")
  81. public R<KeyPwdVO> detail(KeyPwd keyPwd) {
  82. KeyPwd detail = keyPwdService.getOne(Condition.getQueryWrapper(keyPwd));
  83. return R.data(KeyPwdWrapper.build().entityVO(detail));
  84. }
  85. /**
  86. * 分页 網點鎖匙/密碼登記表
  87. */
  88. @GetMapping("/list")
  89. @ApiOperationSupport(order = 2)
  90. @ApiOperation(value = "分页", notes = "传入keyPwd")
  91. public R<IPage<KeyPwdVO>> list(KeyPwd keyPwd, Query query) {
  92. IPage<KeyPwd> pages = keyPwdService.page(Condition.getPage(query), Condition.getQueryWrapper(keyPwd));
  93. return R.data(KeyPwdWrapper.build().pageVO(pages));
  94. }
  95. /**
  96. * 自定义分页 網點鎖匙/密碼登記表
  97. */
  98. @GetMapping("/page")
  99. @ApiOperationSupport(order = 3)
  100. @ApiOperation(value = "分页", notes = "传入keyPwd")
  101. public R<IPage<KeyPwdVO>> page(KeyPwdVO keyPwd, Query query) {
  102. Long deptId = Long.valueOf(AuthUtil.getDeptId());
  103. List<Long> deptChildIds = deptService.getDeptChildIds(deptId);
  104. // deptChildIds.add(deptId);
  105. Dept dept = deptService.getById(deptId);
  106. Dept parentDept = deptService.getById(dept.getParentId());
  107. if (parentDept.getOrgNo().startsWith("999")){
  108. deptChildIds.add(parentDept.getId());
  109. }
  110. keyPwd.setDeptIdList(deptChildIds);
  111. keyPwd.setCurrentuserId(AuthUtil.getUserId());
  112. if (StringUtils.isNotBlank(keyPwd.getCategory())){
  113. List<String> categorys = Func.toStrList(keyPwd.getCategory());
  114. keyPwd.setCategorys(categorys);
  115. }
  116. if (StringUtils.isNotBlank(keyPwd.getOrgNostr())){
  117. List<String> orgNos = Func.toStrList(keyPwd.getOrgNostr());
  118. keyPwd.setOrgNos(orgNos);
  119. }
  120. IPage<KeyPwdVO> pages = keyPwdService.selectKeyPwdPage(Condition.getPage(query), keyPwd);
  121. return R.data(pages);
  122. }
  123. /**
  124. * 自定义分页 網點鎖匙/密碼登記表
  125. */
  126. @GetMapping("/getKeepList")
  127. @ApiOperationSupport(order = 3)
  128. @ApiOperation(value = "分页", notes = "传入keyPwd")
  129. public R<List<KeyPwd>> getKeepList(KeyPwdVO keyPwd) {
  130. Long deptId = Long.valueOf(AuthUtil.getDeptId());
  131. List<Long> deptChildIds = deptService.getDeptChildIds(deptId);
  132. // deptChildIds.add(deptId);
  133. Dept dept = deptService.getById(deptId);
  134. Dept parentDept = deptService.getById(dept.getParentId());
  135. if (parentDept.getOrgNo().startsWith("999")){
  136. deptChildIds.add(parentDept.getId());
  137. }
  138. keyPwd.setDeptIdList(deptChildIds);
  139. keyPwd.setCurrentuserId(AuthUtil.getUserId());
  140. if (StringUtils.isNotBlank(keyPwd.getCategory())){
  141. List<String> categorys = Func.toStrList(keyPwd.getCategory());
  142. keyPwd.setCategorys(categorys);
  143. }
  144. if (StringUtils.isNotBlank(keyPwd.getOrgNostr())){
  145. List<String> orgNos = Func.toStrList(keyPwd.getOrgNostr());
  146. keyPwd.setOrgNos(orgNos);
  147. }
  148. List<KeyPwd> list = keyPwdService.getKeepList(keyPwd);
  149. /*HashSet<Map> set = new HashSet<>();
  150. for (int i = 0; i < list.size(); i++) {
  151. KeyPwd item = list.get(i);
  152. String[] split = item.getCategory().split(",");
  153. //去掉多选的,因为在确认的时候,多选的已经分解了
  154. if (split.length > 1){
  155. list.remove(i);
  156. i--;
  157. continue;
  158. }
  159. HashMap<String, Object> map = new HashMap<>();
  160. map.put("bankNo", item.getBankNo());
  161. map.put("orgNo", item.getOrgNo());
  162. map.put("category", item.getCategory());
  163. int size1 = set.size();
  164. set.add(map);
  165. if (set.size() == size1){
  166. list.remove(i);
  167. i--;
  168. }
  169. }*/
  170. return R.data(list);
  171. }
  172. /**
  173. * 确认 網點鎖匙/密碼登記表
  174. */
  175. @PostMapping("/sure")
  176. @ApiOperationSupport(order = 4)
  177. @ApiOperation(value = "确认", notes = "传入keyPwd")
  178. public R sure(@Valid @RequestBody KeyPwd keyPwd) {
  179. keyPwd.setProcess(3);
  180. keyPwd.setSureTime(DateUtil.now());
  181. if (keyPwdService.updateById(keyPwd)){
  182. String[] split = keyPwd.getCategory().split(",");
  183. //如有多选则分解保存,status=2做持有人标识,pid为记录的原id
  184. if (split.length > 0){
  185. for (int i = 0; i < split.length; i++) {
  186. String category = split[i];
  187. KeyPwd keep = keyPwdService.getKeepOneByOrgNoCategory(keyPwd.getBankNo(), keyPwd.getOrgNo(), category);
  188. if (keep == null){
  189. keep = BeanUtil.clone(keyPwd);
  190. keep.setId(null);
  191. keep.setStatus(2);
  192. keep.setCategory(category);
  193. }else{
  194. keep.setPid(keyPwd.getId());
  195. keep.setReceiverId(keyPwd.getReceiverId());
  196. keep.setReceiverNo(keyPwd.getReceiverNo());
  197. keep.setReceiverName(keyPwd.getReceiverName());
  198. }
  199. keyPwdService.saveOrUpdate(keep);
  200. }
  201. }
  202. User user = userService.getById(AuthUtil.getUserId());
  203. Dept dept = deptService.getById(user.getDeptId());
  204. UserLog userLog = new UserLog();
  205. userLog.setTableName("keypwd");
  206. userLog.setBankNo(dept.getBankNo());
  207. userLog.setOrgNo(dept.getOrgNo());
  208. userLog.setOrgName(dept.getDeptName());
  209. userLog.setNewData(JSONUtil.toJsonStr(keyPwd));
  210. userLog.setPersonNo(user.getEhr());
  211. userLog.setPersonName(user.getName());
  212. userLog.setOperationType("sure");
  213. userLogService.save(userLog);
  214. }
  215. return R.status(true);
  216. }
  217. /**
  218. * 修改 網點鎖匙/密碼登記表
  219. */
  220. @PostMapping("/update")
  221. @ApiOperationSupport(order = 5)
  222. @ApiOperation(value = "修改", notes = "传入keyPwd")
  223. public R update(@Valid @RequestBody KeyPwd keyPwd) {
  224. return R.status(keyPwdService.updateById(keyPwd));
  225. }
  226. /**
  227. * 新增或修改 網點鎖匙/密碼登記表
  228. */
  229. @PostMapping("/submit")
  230. @ApiOperationSupport(order = 6)
  231. @ApiOperation(value = "新增或修改", notes = "传入keyPwd")
  232. public R submit(@Valid @RequestBody KeyPwd keyPwd) {
  233. if (keyPwd.getIsTurnIn() == 1){
  234. keyPwd.setProcess(3); //已确认,直接完结流程
  235. }else {
  236. keyPwd.setProcess(2); //待确认
  237. }
  238. boolean isAdd = keyPwd.getId() == null;
  239. BladeUser currentUser = AuthUtil.getUser();
  240. User user = userService.getById(currentUser.getUserId());
  241. Dept dept = deptService.getById(user.getDeptId());
  242. UserLog userLog = new UserLog();
  243. Assert.isTrue(!keyPwd.getHandoverPersonNo().equals(keyPwd.getReceiverNo()), "交出人不可為接收人!請重新選擇!");
  244. KeyPwd old = null;
  245. if (isAdd){
  246. keyPwd.setFillingPerson(currentUser.getUserName());
  247. keyPwd.setFillingDate(DateUtil.now());
  248. }else{
  249. old = keyPwdService.getById(keyPwd.getId());
  250. }
  251. if (keyPwdService.saveOrUpdate(keyPwd)){
  252. User receiver = userService.getById(keyPwd.getReceiverId());
  253. if (!keyPwd.getCreateDept().equals(Long.valueOf(receiver.getDeptId()))){
  254. keyPwd.setCreateDept(Long.valueOf(receiver.getDeptId()));
  255. keyPwdService.updateById(keyPwd);
  256. }
  257. userLog.setTableName("keypwd");
  258. userLog.setBankNo(dept.getBankNo());
  259. userLog.setOrgNo(dept.getOrgNo());
  260. userLog.setOrgName(dept.getDeptName());
  261. userLog.setNewData(JSONUtil.toJsonStr(keyPwd));
  262. userLog.setPersonNo(user.getEhr());
  263. userLog.setPersonName(user.getName());
  264. if (isAdd){
  265. userLog.setOperationType("add");
  266. //發送通知
  267. noticeService.sendKeyPwdNotice(keyPwd, false, keyPwd.getIsTurnIn().equals(1));
  268. }else{
  269. userLog.setOperationType("edit");
  270. userLog.setOldData(JSONUtil.toJsonStr(old));
  271. //發送通知
  272. noticeService.sendKeyPwdNotice(keyPwd, true, false);
  273. }
  274. userLogService.save(userLog);
  275. }
  276. return R.status(true);
  277. }
  278. /**
  279. * 删除 網點鎖匙/密碼登記表
  280. */
  281. @PostMapping("/remove")
  282. @ApiOperationSupport(order = 7)
  283. @ApiOperation(value = "逻辑删除", notes = "传入ids")
  284. public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
  285. List<Long> idList = Func.toLongList(ids);
  286. List<UserLog> userLogList = new ArrayList<>();
  287. // 日誌記錄
  288. BladeUser currentUser = AuthUtil.getUser();
  289. User user = userService.getById(currentUser.getUserId());
  290. Dept dept = deptService.getById(user.getDeptId());
  291. idList.forEach(id -> {
  292. UserLog userLog = new UserLog();
  293. KeyPwd keyPwd = keyPwdService.getById(id);
  294. userLog.setTableName("keypwd");
  295. userLog.setOperationType("del");
  296. userLog.setBankNo(dept.getBankNo());
  297. userLog.setOrgNo(dept.getOrgNo());
  298. userLog.setOrgName(dept.getDeptName());
  299. userLog.setOldData(JSONUtil.toJsonStr(keyPwd));
  300. userLog.setPersonNo(user.getEhr());
  301. userLog.setPersonName(user.getName());
  302. userLogList.add(userLog);
  303. });
  304. return R.status(keyPwdService.deleteLogic(idList) && userLogService.saveBatch(userLogList));
  305. }
  306. /**
  307. * 根據交接日期來排序,判斷最新一條記錄
  308. * @param category
  309. * @param orgNo
  310. * @return
  311. */
  312. @GetMapping("/getByCategoryAndType")
  313. @ApiOperationSupport(order = 8)
  314. @ApiOperation(value = "获取最新一条记录", notes = "传入category,type")
  315. public R getByCategoryAndType(@ApiParam(required = true) @RequestParam String category, @ApiParam(required = true) @RequestParam String orgNo){
  316. LambdaQueryWrapper<KeyPwd> eq = new QueryWrapper<>(new KeyPwd()).lambda().eq(KeyPwd::getCategory, category)
  317. .eq(KeyPwd::getOrgNo, orgNo).orderByDesc(KeyPwd::getHandoverDate);
  318. List<KeyPwd> list = keyPwdService.list(eq);
  319. if (list != null && list.size() > 0){
  320. return R.data(list.get(0));
  321. }
  322. return R.data(null);
  323. }
  324. /**
  325. * 获取当前用户所持有的分类,逗号拼接返回
  326. * @return
  327. */
  328. @GetMapping("/getCurrentUserKeepCategory")
  329. @ApiOperationSupport(order = 8)
  330. @ApiOperation(value = "获取当前用户所持有的分类", notes = "")
  331. public R getCurrentUserKeepCategory(){
  332. KeyPwdVO keyPwd = new KeyPwdVO();
  333. keyPwd.setReceiverId(AuthUtil.getUserId());
  334. List<KeyPwd> keepList = keyPwdService.getKeepList(keyPwd);
  335. String categorys = keepList.stream().map(item -> item.getCategory()).collect(Collectors.joining(","));
  336. return R.data(categorys);
  337. }
  338. @GetMapping("/getList")
  339. public R getList(KeyPwdVO keyPwd){
  340. if (StringUtils.isNotBlank(keyPwd.getCategory())){
  341. List<String> categorys = Func.toStrList(keyPwd.getCategory());
  342. keyPwd.setCategorys(categorys);
  343. }
  344. if (StringUtils.isNotBlank(keyPwd.getOrgNostr())){
  345. List<String> orgNos = Func.toStrList(keyPwd.getOrgNostr());
  346. keyPwd.setOrgNos(orgNos);
  347. }
  348. List<KeyPwd> list = keyPwdService.getList(keyPwd);
  349. list.forEach(item -> {
  350. List<String> categoryStrList = new ArrayList<>();
  351. String[] categorys = item.getCategory().split(",");
  352. for (int i = 0; i < categorys.length; i++) {
  353. String category = categorys[i];
  354. String value = dictService.getValue("key_type", category);
  355. String[] split = category.split("_");
  356. String key_type = dictService.getValue("key_type", split[0] + "_" + split[1] + "_" + split[2]);
  357. categoryStrList.add(key_type + "-" + value);
  358. }
  359. item.setCategory(StringUtil.join(categoryStrList, " | "));
  360. });
  361. return R.data(list);
  362. }
  363. }