|
@@ -7,11 +7,14 @@ import cn.com.ctop.common.module.service.IUserCompanyService;
|
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
|
import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyAccountMapper;
|
|
|
import cn.com.ctop.reimburse.mondule.entity.ReimburseApply;
|
|
|
+import cn.com.ctop.reimburse.mondule.entity.ReimburseApplyProcess;
|
|
|
import cn.com.ctop.reimburse.mondule.entity.ReimburseProject;
|
|
|
import cn.com.ctop.reimburse.mondule.mapper.ReimburseApplyMapper;
|
|
|
+import cn.com.ctop.reimburse.mondule.service.IReimburseApplyProcessService;
|
|
|
import cn.com.ctop.reimburse.mondule.service.IReimburseApplyService;
|
|
|
import cn.com.ctop.reimburse.mondule.service.IReimburseProjectService;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -26,6 +29,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -44,6 +49,9 @@ public class ReimburseApplyServiceImpl extends ServiceImpl<ReimburseApplyMapper,
|
|
|
private IReimburseProjectService projectService;
|
|
|
|
|
|
@Autowired
|
|
|
+ private IReimburseApplyProcessService processService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private ISysDepartService sysDepartService;
|
|
|
|
|
|
@Autowired
|
|
@@ -111,11 +119,171 @@ public class ReimburseApplyServiceImpl extends ServiceImpl<ReimburseApplyMapper,
|
|
|
projectService.updateById(project);
|
|
|
}
|
|
|
baseMapper.insertRel(leader, apply.getId());
|
|
|
+
|
|
|
+ //是否是福利费用,是则发送非空
|
|
|
+ String welfareUser = checkWelfare(projects);
|
|
|
+ addProcess(apply.getId(), data.getString("userId"), leader, welfareUser);
|
|
|
+
|
|
|
return Result.ok();
|
|
|
}
|
|
|
|
|
|
+ //添加流程
|
|
|
+ private void addProcess(Long applyId, String userId, String leaderId, String welfareUserId) throws Exception {
|
|
|
+ List<ReimburseApplyProcess> list = new ArrayList<>();
|
|
|
+ list.add(new ReimburseApplyProcess(applyId, userId, "0", 1, DateUtils.now()));
|
|
|
+ List<String> leaders = getProcessLeaders(userId, 2);
|
|
|
+ for (int i = 0; i < leaders.size(); i++) {
|
|
|
+ if (leaderId.equals(leaders.get(i))) {
|
|
|
+ list.add(new ReimburseApplyProcess(applyId, leaders.get(i), "3", i + 2, null));
|
|
|
+ } else {
|
|
|
+ list.add(new ReimburseApplyProcess(applyId, leaders.get(i), "4", i + 2, null));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!Check.isNull(welfareUserId) && !leaders.contains(welfareUserId)) {
|
|
|
+ list.add(new ReimburseApplyProcess(applyId, welfareUserId, "4", list.size() + 1, null));
|
|
|
+ }
|
|
|
+ list.add(new ReimburseApplyProcess(applyId, "-", "4", list.size() + 1, null));
|
|
|
+ processService.saveBatch(list);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /*
|
|
|
+ 流程状态 状态 1待审核、2审核通过、3审核拒绝、4审核中、5部分拒绝
|
|
|
+ 更新流程 审核状态:0-创建,1-通过,2-拒绝,3-待审核,4-未审核,5-修改
|
|
|
+ */
|
|
|
+ private void updateProcess(Long applyId, String userId, String leaderId, String state, String welfareUserId) throws Exception {
|
|
|
+ List<ReimburseApplyProcess> editlist = new ArrayList<>();
|
|
|
+ List<ReimburseApplyProcess> list = processService.getListByApplyId(applyId);
|
|
|
+ if ("2".equals(state)) {
|
|
|
+ ReimburseApplyProcess process = list.get(list.size() - 1);
|
|
|
+ process.setState("1");
|
|
|
+ process.setStatTime(DateUtils.now());
|
|
|
+ process.setUserId(userId);
|
|
|
+ processService.updateById(process);
|
|
|
+ } else if ("3".equals(state) || "5".equals(state)) {
|
|
|
+ if (JSONArray.toJSONString(list).contains(userId)) {
|
|
|
+ for (int i = list.size() - 1; i >= 0; i--) {
|
|
|
+ ReimburseApplyProcess process = list.get(i);
|
|
|
+ if (userId.equals(process.getUserId())) {
|
|
|
+ process.setState("2");
|
|
|
+ process.setStatTime(DateUtils.now());
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ list.remove(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ editlist.addAll(list);
|
|
|
+ editlist.add(new ReimburseApplyProcess(applyId, list.get(0).getUserId(), "5", list.size() + 1, null));
|
|
|
+ List<String> leaders = getProcessLeaders(userId, 2);
|
|
|
+ for (int i = 0; i < leaders.size(); i++) {
|
|
|
+ editlist.add(new ReimburseApplyProcess(applyId, leaders.get(i), "4", i + list.size() + 2, null));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(welfareUserId) && !leaders.contains(welfareUserId)) {
|
|
|
+ editlist.add(new ReimburseApplyProcess(applyId, welfareUserId, "4", editlist.size() + 1, null));
|
|
|
+ }
|
|
|
+ editlist.add(new ReimburseApplyProcess(applyId, "-", "4", editlist.size() + 1, null));
|
|
|
+ } else {
|
|
|
+ ReimburseApplyProcess process = list.get(list.size() - 1);
|
|
|
+ process.setUserId(userId);
|
|
|
+ process.setState("2");
|
|
|
+ process.setStatTime(DateUtils.now());
|
|
|
+ editlist.addAll(list);
|
|
|
+ editlist.add(new ReimburseApplyProcess(applyId, list.get(0).getUserId(), "5", list.size() + 1, null));
|
|
|
+ List<String> leaders = getProcessLeaders(list.get(0).getUserId(), list.size() + 2);
|
|
|
+ for (int i = 0; i < leaders.size(); i++) {
|
|
|
+ editlist.add(new ReimburseApplyProcess(applyId, leaders.get(i), "4", i + list.size() + 2, null));
|
|
|
+ }
|
|
|
+ if (!Check.isNull(welfareUserId) && !leaders.contains(welfareUserId)) {
|
|
|
+ editlist.add(new ReimburseApplyProcess(applyId, welfareUserId, "4", editlist.size() + 1, null));
|
|
|
+ }
|
|
|
+ editlist.add(new ReimburseApplyProcess(applyId, "-", "4", editlist.size() + 1, null));
|
|
|
+
|
|
|
+ }
|
|
|
+ processService.deleteByApplyId(applyId);
|
|
|
+ processService.saveBatch(editlist);
|
|
|
+
|
|
|
+ } else if ("4".equals(state)) {
|
|
|
+ for (int i = list.size() - 1; i >= 0; i--) {
|
|
|
+ ReimburseApplyProcess process = list.get(i);
|
|
|
+ if (process.getUserId().equals(leaderId)) {
|
|
|
+ process.setState("3");
|
|
|
+ editlist.add(process);
|
|
|
+ }
|
|
|
+ if (userId.equals(process.getUserId())) {
|
|
|
+ process.setState("1");
|
|
|
+ process.setStatTime(DateUtils.now());
|
|
|
+ editlist.add(process);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (ReimburseApplyProcess applyProcess : editlist) {
|
|
|
+ processService.updateById(applyProcess);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取审核流程全部人员
|
|
|
+ */
|
|
|
+ private List<String> getProcessLeaders(String userId, Integer order) throws Exception {
|
|
|
+ JSONObject company = userCompanyService.getCompanyInfoByUserId(userId);
|
|
|
+ if (Check.isNull(company)) {
|
|
|
+ throw new Exception("用户ID:" + userId + ",未查询到所属公司");
|
|
|
+ }
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ String companyId = company.getString("companyId");
|
|
|
+ if ("6608ed13c0dd42de93c790dbdf124234".equals(companyId)) {
|
|
|
+ //广州汇创思拓数字科技有限公司(华南) 直接返回 何田田
|
|
|
+ list.add("1cd4c769eabb4de98fed306de2a3bbbd");
|
|
|
+ } else if ("4b10089775c040119e139087517aed88".equals(companyId)) {
|
|
|
+ //上海汇创思拓数字科技有限公司 直接返回 吴婵
|
|
|
+ list.add("183dce577efb49b386369473368cf251");
|
|
|
+ } else {
|
|
|
+ String user = baseMapper.selectFinalLeaders(userId, companyId);
|
|
|
+ if (userId.equals(user)) {
|
|
|
+ list.add(userId);
|
|
|
+ } else {
|
|
|
+ //查询部门
|
|
|
+ List<SysDepart> departs = sysDepartService.queryUserDeparts(userId);
|
|
|
+ if (!departs.isEmpty()) {
|
|
|
+ String orgCode = departs.get(0).getOrgCode();
|
|
|
+ JSONObject object = sysDepartService.queryAllParentIdByOrgCode(orgCode);
|
|
|
+ JSONObject map = object.getJSONObject(orgCode).getJSONObject("parentMap");
|
|
|
+ JSONObject leader = new JSONObject();
|
|
|
+ //查询审核人员信息
|
|
|
+ List<JSONObject> leaders = baseMapper.selectLeaders(companyId);
|
|
|
+ for (JSONObject obj : leaders) {
|
|
|
+ String departName = obj.getString("depart_name");
|
|
|
+ if (map.toJSONString().contains(departName)) {
|
|
|
+ leader = obj;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (leader.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ //第一审核人
|
|
|
+ if (!Check.isNull(leader.getString("first_id"))) {
|
|
|
+ list.add(leader.getString("first_id"));
|
|
|
+ }
|
|
|
+ //第二审核人
|
|
|
+ if (!Check.isNull(leader.getString("second_id"))) {
|
|
|
+ list.add(leader.getString("second_id"));
|
|
|
+ }
|
|
|
+ //终极审核人
|
|
|
+ if (!Check.isNull(leader.getString("final_id"))) {
|
|
|
+ list.add(leader.getString("final_id"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Result<Object> edit(JSONObject data) throws Exception {
|
|
|
+
|
|
|
String sender = null;
|
|
|
String msg = null;
|
|
|
String type = "1";
|
|
@@ -143,7 +311,7 @@ public class ReimburseApplyServiceImpl extends ServiceImpl<ReimburseApplyMapper,
|
|
|
apply.setInvoices(invoices);
|
|
|
apply.setAmount(amount.toString());
|
|
|
}
|
|
|
-
|
|
|
+ String welfareUser = welfareUser = checkWelfare(projects);
|
|
|
//登录人ID
|
|
|
String loginId = data.getString("loginId");
|
|
|
//创建人操作,直接修改
|
|
@@ -158,8 +326,10 @@ public class ReimburseApplyServiceImpl extends ServiceImpl<ReimburseApplyMapper,
|
|
|
this.updateById(apply);
|
|
|
for (ReimburseProject project : projects) {
|
|
|
project.setApplyId(apply.getId());
|
|
|
+ project.setAuditDescription("");
|
|
|
projectService.updateById(project);
|
|
|
}
|
|
|
+ updateProcess(id, loginId, sender, "4", welfareUser);
|
|
|
return Result.ok();
|
|
|
} else {
|
|
|
ReimburseApply entity = this.getById(apply.getId());
|
|
@@ -172,6 +342,7 @@ public class ReimburseApplyServiceImpl extends ServiceImpl<ReimburseApplyMapper,
|
|
|
String roleCode = dailyAccountMapper.getRoleCodeByUserId(loginId);
|
|
|
if ("financialReview".equals(roleCode)) {
|
|
|
apply.setStatus("2");
|
|
|
+ status = apply.getStatus();
|
|
|
} else {
|
|
|
//发送 财务审核
|
|
|
isFinancialReview = true;
|
|
@@ -182,7 +353,8 @@ public class ReimburseApplyServiceImpl extends ServiceImpl<ReimburseApplyMapper,
|
|
|
apply.setFinalStatus("0");
|
|
|
sender = apply.getUserId();
|
|
|
}
|
|
|
- } else {
|
|
|
+ updateProcess(id, loginId, sender, status, welfareUser);
|
|
|
+ } else if (loginId.equals(entity.getLeaderId())) {
|
|
|
//获取下次审核人信息
|
|
|
leader = getLeader(entity.getLeaderId());
|
|
|
if (Check.isNull(leader)) {
|
|
@@ -194,8 +366,7 @@ public class ReimburseApplyServiceImpl extends ServiceImpl<ReimburseApplyMapper,
|
|
|
//登录人和待审核人一样,则是部门最后审核人
|
|
|
apply.setFinalStatus("1");
|
|
|
//是否是福利费用,是则发送审核 到指定审核人;否则 发送到财务
|
|
|
- String welfareUser = checkWelfare(projects);
|
|
|
- if (!Check.isNull(welfareUser)) {
|
|
|
+ if (!Check.isNull(welfareUser) && !welfareUser.equals(loginId)) {
|
|
|
apply.setLeaderId(welfareUser);
|
|
|
sender = welfareUser;
|
|
|
} else {
|
|
@@ -212,6 +383,7 @@ public class ReimburseApplyServiceImpl extends ServiceImpl<ReimburseApplyMapper,
|
|
|
apply.setFinalStatus("0");
|
|
|
sender = apply.getUserId();
|
|
|
}
|
|
|
+ updateProcess(id, loginId, sender, status, welfareUser);
|
|
|
}
|
|
|
this.updateById(apply);
|
|
|
if (!Check.isNull(sender)) {
|
|
@@ -230,7 +402,6 @@ public class ReimburseApplyServiceImpl extends ServiceImpl<ReimburseApplyMapper,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
return Result.ok();
|
|
|
}
|
|
|
|
|
@@ -250,6 +421,11 @@ public class ReimburseApplyServiceImpl extends ServiceImpl<ReimburseApplyMapper,
|
|
|
return baseMapper.queryLeaderCompanyList();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<JSONObject> queryProcess(Long applyId) {
|
|
|
+ return processService.queryProcess(applyId);
|
|
|
+ }
|
|
|
+
|
|
|
// 获取审核人ID
|
|
|
private String getLeader(String userId) throws Exception {
|
|
|
JSONObject company = userCompanyService.getCompanyInfoByUserId(userId);
|
|
@@ -263,23 +439,14 @@ public class ReimburseApplyServiceImpl extends ServiceImpl<ReimburseApplyMapper,
|
|
|
} else if ("4b10089775c040119e139087517aed88".equals(companyId)) {
|
|
|
//上海汇创思拓数字科技有限公司 直接返回 吴婵
|
|
|
return "183dce577efb49b386369473368cf251";
|
|
|
- } else if ("4b10089775c040119e139087517aed88".equals(companyId)) {
|
|
|
- //上海汇创思拓数字科技有限公司 直接返回 吴婵
|
|
|
- return "183dce577efb49b386369473368cf251";
|
|
|
- } else if ("d57fecdcf7a94d009736d9c850731582".equals(companyId)) {
|
|
|
- //北京汇创思拓数字科技有限公司
|
|
|
- return getCompanyLeader(userId, companyId);
|
|
|
- } else if ("3f362f527a804e8a9db6552ea12f7574".equals(companyId)) {
|
|
|
- //石家庄汇创思拓数字科技有限公司
|
|
|
+ } else {
|
|
|
return getCompanyLeader(userId, companyId);
|
|
|
}
|
|
|
- return null;
|
|
|
}
|
|
|
|
|
|
// 获取公司审核人ID
|
|
|
private String getCompanyLeader(String userId, String companyId) {
|
|
|
String leaderId = "";
|
|
|
-
|
|
|
String user = baseMapper.selectFinalLeaders(userId, companyId);
|
|
|
if (userId.equals(user)) {
|
|
|
return userId;
|