|
|
@@ -16,6 +16,9 @@
|
|
|
*/
|
|
|
package org.springblade.bank.autodata.controller;
|
|
|
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
import io.swagger.annotations.Api;
|
|
|
@@ -37,13 +40,18 @@ import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.utils.BeanUtil;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
+import org.springblade.modules.system.entity.Dept;
|
|
|
import org.springblade.modules.system.entity.User;
|
|
|
+import org.springblade.modules.system.service.IDeptService;
|
|
|
+import org.springblade.modules.system.service.IUserService;
|
|
|
import org.springframework.util.Assert;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 控制器
|
|
|
@@ -59,6 +67,8 @@ public class AutoDataController extends BladeController {
|
|
|
|
|
|
private final IAutoDataService autoDataService;
|
|
|
private final IAutoStructService autoStructService;
|
|
|
+ private final IDeptService deptService;
|
|
|
+ private final IUserService userService;
|
|
|
|
|
|
/**
|
|
|
* 详情
|
|
|
@@ -92,7 +102,21 @@ public class AutoDataController extends BladeController {
|
|
|
public R<IPage<AutoDataVO>> page(AutoDataVO autoData, Query query) {
|
|
|
BladeUser user = AuthUtil.getUser();
|
|
|
//當前部門id
|
|
|
- autoData.setCurrentDeptId(AuthUtil.getDeptId());
|
|
|
+ Dept dept = deptService.getById(AuthUtil.getDeptId());
|
|
|
+ if (dept.getOrgNo().startsWith("999")){
|
|
|
+ List<Long> deptChildIds = deptService.getDeptChildIds(dept.getId());
|
|
|
+ String[] deptArr = new String[deptChildIds.size()];
|
|
|
+ for (int i = 0; i < deptChildIds.size(); i++) {
|
|
|
+ deptArr[i] = deptChildIds.get(i) + "";
|
|
|
+ }
|
|
|
+ autoData.setUserDeptList(deptArr);
|
|
|
+ }else{
|
|
|
+ String[] deptArr = new String[1];
|
|
|
+ deptArr[0] = AuthUtil.getDeptId();
|
|
|
+ autoData.setUserDeptList(deptArr);
|
|
|
+ }
|
|
|
+// autoData.setCurrentDeptId(AuthUtil.getDeptId());
|
|
|
+ autoData.setCurrentuserId(AuthUtil.getUserId());
|
|
|
|
|
|
Assert.isTrue(autoData.getTableId() != null, "表ID不能為空!");
|
|
|
AutoStruct autoStruct = autoStructService.getById(autoData.getTableId());
|
|
|
@@ -153,6 +177,104 @@ public class AutoDataController extends BladeController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 審批通過
|
|
|
+ */
|
|
|
+ @PostMapping("/approveYes")
|
|
|
+ @ApiOperationSupport(order = 6)
|
|
|
+ @ApiOperation(value = "審批通過", notes = "传入autoData")
|
|
|
+ public R approveYes(@Valid @RequestBody AutoData autoData) {
|
|
|
+ Long tableId = autoData.getTableId();
|
|
|
+ AutoStruct struct = autoStructService.getById(tableId);
|
|
|
+
|
|
|
+ // 並行-直接把審批人信息追加到已審批人字段
|
|
|
+ AutoData oldData = autoDataService.getById(autoData.getId());
|
|
|
+ if (struct.getApproveType().equals(2)){
|
|
|
+ User user = userService.getById(AuthUtil.getUserId());
|
|
|
+ if (oldData.getProcess().equals(1)){
|
|
|
+ autoData.setApproveId(user.getId()+"");
|
|
|
+ autoData.setApproveName(user.getName());
|
|
|
+ autoData.setApproveNo(user.getEhr());
|
|
|
+ }else{
|
|
|
+ autoData.setApproveId(oldData.getApproveId() + "," + user.getId());
|
|
|
+ autoData.setApproveName(oldData.getApproveName() + "," + user.getName());
|
|
|
+ autoData.setApproveNo(oldData.getApproveNo() + "," + user.getEhr());
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ // 串行-統一設置-從設置中拿出相應位置的人員,填充到下一個審批人字段,process+1
|
|
|
+ String settingStr = struct.getSetting();
|
|
|
+ if (struct.getSettingType().equals(1)){
|
|
|
+ JSONArray jsonArray = JSONUtil.parseArray(settingStr);
|
|
|
+ // 取出下一個審批人
|
|
|
+ Map<String, String > tobePerson = (Map<String, String>) jsonArray.get(autoData.getProcess());
|
|
|
+ autoData.setReceiverId(tobePerson.get("id"));
|
|
|
+ autoData.setReceiverName(tobePerson.get("name"));
|
|
|
+ autoData.setReceiverNo(tobePerson.get("ehr"));
|
|
|
+ jsonArray.toJSONString(0);
|
|
|
+ }else{
|
|
|
+ // 串行-逐級設置-把前端傳過來的審批人,保存到待審批人字段,保存,process+1
|
|
|
+ JSONArray jsonArray;
|
|
|
+ if (settingStr == null){
|
|
|
+ jsonArray = new JSONArray(1);
|
|
|
+ }else{
|
|
|
+ jsonArray = JSONUtil.parseArray(settingStr);
|
|
|
+ }
|
|
|
+ Map<String, String > tobePerson = new HashMap<>();
|
|
|
+ tobePerson.put("id", oldData.getReceiverId());
|
|
|
+ tobePerson.put("name", oldData.getReceiverName());
|
|
|
+ tobePerson.put("ehr", oldData.getReceiverNo());
|
|
|
+ jsonArray.set(tobePerson);
|
|
|
+ String newSettingStr = jsonArray.toJSONString(0);
|
|
|
+ struct.setSetting(newSettingStr);
|
|
|
+ autoStructService.updateById(struct);
|
|
|
+ }
|
|
|
+ autoData.setProcess(oldData.getProcess()+1);
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.status(autoDataService.saveOrUpdate(autoData));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 審批駁回
|
|
|
+ */
|
|
|
+ @PostMapping("/approveNo")
|
|
|
+ @ApiOperationSupport(order = 6)
|
|
|
+ @ApiOperation(value = "審批駁回", notes = "传入autoData")
|
|
|
+ public R approveNo(@Valid @RequestBody AutoData autoData) {
|
|
|
+ AutoData oldData = autoDataService.getById(autoData.getId());
|
|
|
+ Assert.isTrue(!oldData.getProcess().equals(1), "無法駁回!因為已無路可退!");
|
|
|
+ Long tableId = autoData.getTableId();
|
|
|
+ AutoStruct struct = autoStructService.getById(tableId);
|
|
|
+
|
|
|
+ //串行(並行無駁回)
|
|
|
+ if (struct.getApproveType().equals(1)){
|
|
|
+ // 串行-統一設置-從設置中拿出相應位置的人員,填充到下一個審批人字段,process-1
|
|
|
+ String settingStr = struct.getSetting();
|
|
|
+ JSONArray jsonArray = JSONUtil.parseArray(settingStr);
|
|
|
+ // 取出上一個審批人
|
|
|
+ Map<String, String > tobePerson = (Map<String, String>) jsonArray.get(oldData.getProcess() - 2);
|
|
|
+ autoData.setReceiverId(tobePerson.get("id"));
|
|
|
+ autoData.setReceiverName(tobePerson.get("name"));
|
|
|
+ autoData.setReceiverNo(tobePerson.get("ehr"));
|
|
|
+ if (struct.getSettingType().equals(2)){
|
|
|
+ // 逐級審批-需刪除前審批人信息
|
|
|
+ Object remove = jsonArray.remove(oldData.getProcess() - 2);
|
|
|
+ if (jsonArray.size() == 0){
|
|
|
+ struct.setSetting(null);
|
|
|
+ }else {
|
|
|
+ String newSettingStr = jsonArray.toJSONString(0);
|
|
|
+ struct.setSetting(newSettingStr);
|
|
|
+ }
|
|
|
+ autoStructService.updateById(struct);
|
|
|
+ }
|
|
|
+ autoData.setProcess(oldData.getProcess()-1);
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.status(autoDataService.saveOrUpdate(autoData));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 删除
|
|
|
*/
|
|
|
@@ -163,5 +285,23 @@ public class AutoDataController extends BladeController {
|
|
|
return R.status(autoDataService.deleteLogic(Func.toLongList(ids)));
|
|
|
}
|
|
|
|
|
|
+ /*public static void main(String[] args) {
|
|
|
+ *//*String str = "[{\"id\":\"1432588697624535042\",\"name\":\"林嘉莉\",\"ehr\":\"0150800\"},{\"id\":\"1432588735327133698\",\"name\":\"陳麗華\",\"ehr\":\"0146072\"},{\"id\":\"1432588753018707969\",\"name\":\"盧思雅2\",\"ehr\":\"2064717\"}]";
|
|
|
+ JSONArray jsonArray = JSONUtil.parseArray(str);
|
|
|
+ String s = jsonArray.toJSONString(0);
|
|
|
+ System.out.println(s);*//*
|
|
|
+
|
|
|
+
|
|
|
+ JSONArray arr = new JSONArray();
|
|
|
+ Map<String, String > tobePerson = new HashMap<>();
|
|
|
+ tobePerson.put("id", "123123");
|
|
|
+ tobePerson.put("name", "看监控的方式");
|
|
|
+ tobePerson.put("ehr", "fgh1232");
|
|
|
+ arr.set(tobePerson);
|
|
|
+ arr.add(tobePerson);
|
|
|
+ System.out.println(arr.toJSONString(0));
|
|
|
+ arr.remove(1);
|
|
|
+ System.out.println(arr.toJSONString(0));
|
|
|
+ }*/
|
|
|
|
|
|
}
|