|
@@ -92,19 +92,33 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
|
|
@Resource
|
|
@Resource
|
|
private ProjectCurrentcostMapper projectCurrentcostMapper;
|
|
private ProjectCurrentcostMapper projectCurrentcostMapper;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private ExpenseAuditSettingMapper expenseAuditSettingMapper;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public HttpRespMsg add(ExpenseSheet sheet, String items, String userId) {
|
|
public HttpRespMsg add(ExpenseSheet sheet, String items, String userId) {
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
User user = userMapper.selectById(userId);
|
|
User user = userMapper.selectById(userId);
|
|
|
|
+ ExpenseAuditSetting auditSetting = expenseAuditSettingMapper.selectById(user.getCompanyId());
|
|
|
|
+
|
|
|
|
+
|
|
List<SysRichFunction> functionDeptList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "费用审核");
|
|
List<SysRichFunction> functionDeptList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "费用审核");
|
|
boolean isAuditor = functionDeptList.size() > 0;
|
|
boolean isAuditor = functionDeptList.size() > 0;
|
|
boolean isNew = false;
|
|
boolean isNew = false;
|
|
if (sheet.getId() == null) {
|
|
if (sheet.getId() == null) {
|
|
- if (isAuditor) {
|
|
|
|
- sheet.setStatus(0);
|
|
|
|
- } else {
|
|
|
|
|
|
+ if (auditSetting == null || auditSetting.getAuditType() == 0) {
|
|
|
|
+ //默认系统中设置的有审核权限的人审核
|
|
|
|
+ if (isAuditor) {
|
|
|
|
+ sheet.setStatus(0);
|
|
|
|
+ } else {
|
|
|
|
+ sheet.setStatus(1);
|
|
|
|
+ }
|
|
|
|
+ } else if (auditSetting.getAuditType() == 1) {
|
|
|
|
+ //项目经理审核,默认为待审核状态
|
|
sheet.setStatus(1);
|
|
sheet.setStatus(1);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
isNew = true;
|
|
isNew = true;
|
|
//检查code不能重复
|
|
//检查code不能重复
|
|
Integer num = expenseSheetMapper.selectCount(new QueryWrapper<ExpenseSheet>().eq("company_id", user.getCompanyId()).eq("code", sheet.getCode()));
|
|
Integer num = expenseSheetMapper.selectCount(new QueryWrapper<ExpenseSheet>().eq("company_id", user.getCompanyId()).eq("code", sheet.getCode()));
|
|
@@ -116,9 +130,15 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
|
|
} else {
|
|
} else {
|
|
//如果是驳回状态,改成待审核,否则不变
|
|
//如果是驳回状态,改成待审核,否则不变
|
|
if (sheet.getStatus() == 2) {
|
|
if (sheet.getStatus() == 2) {
|
|
- if (isAuditor) {
|
|
|
|
- sheet.setStatus(0);
|
|
|
|
- } else {
|
|
|
|
|
|
+ if (auditSetting == null || auditSetting.getAuditType() == 0) {
|
|
|
|
+ //默认系统中设置的有审核权限的人审核
|
|
|
|
+ if (isAuditor) {
|
|
|
|
+ sheet.setStatus(0);
|
|
|
|
+ } else {
|
|
|
|
+ sheet.setStatus(1);
|
|
|
|
+ }
|
|
|
|
+ } else if (auditSetting.getAuditType() == 1) {
|
|
|
|
+ //项目经理审核,默认为待审核状态
|
|
sheet.setStatus(1);
|
|
sheet.setStatus(1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -173,7 +193,8 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
|
|
|
|
|
|
if (isNew) {
|
|
if (isNew) {
|
|
expenseSheetMapper.insert(sheet);
|
|
expenseSheetMapper.insert(sheet);
|
|
- if (!isAuditor) {
|
|
|
|
|
|
+ //常规审核
|
|
|
|
+ if ((auditSetting == null || auditSetting.getAuditType() == 0) && !isAuditor) {
|
|
WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
|
|
WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
|
|
if(wxCorpInfo!=null){
|
|
if(wxCorpInfo!=null){
|
|
//获取具有费用报销审核权限的人员
|
|
//获取具有费用报销审核权限的人员
|
|
@@ -242,10 +263,82 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
|
|
|
|
|
|
//对于修改的情况,要删除之前的
|
|
//对于修改的情况,要删除之前的
|
|
if (!isNew) {
|
|
if (!isNew) {
|
|
- expenseItemService.remove(new QueryWrapper<ExpenseItem>().eq("expense_id", sheet.getId()));
|
|
|
|
|
|
+ if (auditSetting.getAuditType() == null || auditSetting.getAuditType() == 0) {
|
|
|
|
+ expenseItemService.remove(new QueryWrapper<ExpenseItem>().eq("expense_id", sheet.getId()));
|
|
|
|
+ expenseItemService.saveBatch(itemList);
|
|
|
|
+ } else {
|
|
|
|
+ //已通过不能删除
|
|
|
|
+ QueryWrapper<ExpenseItem> queryWrapper = new QueryWrapper<ExpenseItem>().eq("expense_id", sheet.getId());
|
|
|
|
+ queryWrapper.eq("status", 0);
|
|
|
|
+ List<ExpenseItem> passList = expenseItemService.list(queryWrapper);
|
|
|
|
+ //去掉审核通过的
|
|
|
|
+ itemList = itemList.stream().filter(item->!passList.stream().anyMatch(p->p.getId().equals(item.getId()))).collect(Collectors.toList());
|
|
|
|
+ //设置为待审核状态
|
|
|
|
+ System.out.println("设置状态为待审核"+itemList.size());
|
|
|
|
+ itemList.forEach(item->item.setStatus(1));
|
|
|
|
+ expenseItemService.remove(new QueryWrapper<ExpenseItem>().eq("expense_id", sheet.getId()).ne("status", 0));
|
|
|
|
+ expenseItemService.saveOrUpdateBatch(itemList);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //新增时都是待审核
|
|
|
|
+ itemList.forEach(item->item.setStatus(1));
|
|
|
|
+ expenseItemService.saveBatch(itemList);
|
|
}
|
|
}
|
|
- expenseItemService.saveBatch(itemList);
|
|
|
|
|
|
|
|
|
|
+ if (isNew && auditSetting.getAuditType() != null && auditSetting.getAuditType() == 1) {
|
|
|
|
+ //发送给项目经理审核
|
|
|
|
+ List<Integer> collect = itemList.stream().map(ExpenseItem::getProjectId).collect(Collectors.toList());
|
|
|
|
+ if (collect.size() > 0) {
|
|
|
|
+ List<String> inchargerIds = projectMapper.selectList(new QueryWrapper<Project>().select("incharger_id").in("id", collect)).stream().map(Project::getInchargerId).distinct().collect(Collectors.toList());
|
|
|
|
+ List<User> targetUserList = userMapper.selectList(new QueryWrapper<User>().in("id", inchargerIds));
|
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
|
|
|
|
+ if (wxCorpInfo != null) {
|
|
|
|
+ String corpUserString = targetUserList.stream().map(tl -> tl.getCorpwxUserid()).collect(Collectors.joining("|"));
|
|
|
|
+ User targetUser = userMapper.selectById(sheet.getOwnerId());
|
|
|
|
+ ExpenseMainType mainType = expenseMainTypeService.getById(sheet.getType());
|
|
|
|
+ //推送到企业微信
|
|
|
|
+ JSONObject json=new JSONObject();
|
|
|
|
+ JSONArray dataJson=new JSONArray();
|
|
|
|
+ JSONObject jsonObj=new JSONObject();
|
|
|
|
+ jsonObj.put("key", "报销人");
|
|
|
|
+ jsonObj.put("value",("$userName="+targetUser.getCorpwxUserid()+"$"));
|
|
|
|
+ JSONObject jsonObj1=new JSONObject();
|
|
|
|
+ jsonObj1.put("key", "填报日期");
|
|
|
|
+ jsonObj1.put("value",sheet.getCreateDate());
|
|
|
|
+ JSONObject jsonObj2=new JSONObject();
|
|
|
|
+ jsonObj2.put("key", "票据类型");
|
|
|
|
+ jsonObj2.put("value",mainType.getName());
|
|
|
|
+ JSONObject jsonObj3=new JSONObject();
|
|
|
|
+ jsonObj3.put("key", "金额");
|
|
|
|
+ jsonObj3.put("value",sheet.getTotalAmount());
|
|
|
|
+ JSONObject jsonObj4=new JSONObject();
|
|
|
|
+ jsonObj4.put("key", "备注");
|
|
|
|
+ jsonObj4.put("value",sheet.getRemark()==null?"":sheet.getRemark());
|
|
|
|
+ dataJson.add(jsonObj);
|
|
|
|
+ dataJson.add(jsonObj1);
|
|
|
|
+ dataJson.add(jsonObj2);
|
|
|
|
+ dataJson.add(jsonObj3);
|
|
|
|
+ dataJson.add(jsonObj4);
|
|
|
|
+ json.put("template_id","tty9TkCAAALUiWvjdoDg_PZf48gwucZA");
|
|
|
|
+ json.put("url","https://open.weixin.qq.com/connect/oauth2/authorize?appid=ww4e237fd6abb635af&redirect_uri=http://worktime.ttkuaiban.com/api/corpWXAuth&response_type=code&scope=snsapi_base&state=expense#wechat_redirect");
|
|
|
|
+ json.put("content_item",dataJson);
|
|
|
|
+ wxCorpInfoService.sendWXCorpTemplateMsg(wxCorpInfo,corpUserString, json);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<Information> informationList=new ArrayList<>();
|
|
|
|
+ for (User item : targetUserList) {
|
|
|
|
+ Information information=new Information();
|
|
|
|
+ information.setUserId(item.getId());
|
|
|
|
+ information.setTime(LocalDateTime.now());
|
|
|
|
+ information.setMsg("费用报销待审核");
|
|
|
|
+ information.setType(3);
|
|
|
|
+ information.setContent(sheet.getCreateDate()+"");
|
|
|
|
+ informationList.add(information);
|
|
|
|
+ }
|
|
|
|
+ informationService.saveBatch(informationList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
return msg;
|
|
return msg;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -308,7 +401,6 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
|
|
if (list.size() > 0) {
|
|
if (list.size() > 0) {
|
|
String code = list.get(0).getCode();
|
|
String code = list.get(0).getCode();
|
|
code = code.substring(format.length(), code.length());
|
|
code = code.substring(format.length(), code.length());
|
|
- System.out.println("code====="+code);
|
|
|
|
if (code.length() > 0) {
|
|
if (code.length() > 0) {
|
|
start = Integer.parseInt(code) + 1;
|
|
start = Integer.parseInt(code) + 1;
|
|
}
|
|
}
|
|
@@ -402,6 +494,28 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void sendSingleAuditResult(WxCorpInfo wxCorpInfo, User auditor, ExpenseItem item, String ownerId, LocalDate createDate, String denyReason) {
|
|
|
|
+ //推送到企业微信
|
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
+ DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("M月d日");
|
|
|
|
+ stringBuilder.append("$userName="+auditor.getCorpwxUserid()+"$")
|
|
|
|
+ .append(item.getStatus() == 0?"通过":"驳回")
|
|
|
|
+ .append("了您");
|
|
|
|
+ if (createDate != null) {
|
|
|
|
+ stringBuilder.append("于").append(dateTimeFormatter.format(createDate));
|
|
|
|
+ }
|
|
|
|
+ stringBuilder.append("的费用报销申请。");
|
|
|
|
+ if (item.getStatus() == 2 && !StringUtils.isEmpty(denyReason)) {
|
|
|
|
+ //驳回加原因
|
|
|
|
+ stringBuilder.append("原因: ").append(denyReason);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ User owner = userMapper.selectById(ownerId);
|
|
|
|
+ wxCorpInfoService.sendWXCorpMsg(wxCorpInfo,owner.getCorpwxUserid(), stringBuilder.toString(), "expense",
|
|
|
|
+ item.getStatus() == 0?WxCorpInfoServiceImpl.TEXT_CARD_MSG_EXPENSE_AGREE:WxCorpInfoServiceImpl.TEXT_CARD_MSG_EXPENSE_DENY);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
private void saveNotifyToApplier(ExpenseSheet sheet, User auditor) {
|
|
private void saveNotifyToApplier(ExpenseSheet sheet, User auditor) {
|
|
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("M月d日");
|
|
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("M月d日");
|
|
@@ -840,4 +954,59 @@ public class ExpenseSheetServiceImpl extends ServiceImpl<ExpenseSheetMapper, Exp
|
|
// msg.data = resp;
|
|
// msg.data = resp;
|
|
return msg;
|
|
return msg;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg approveSingleProject(Integer itemId) {
|
|
|
|
+ String token = request.getHeader("TOKEN");
|
|
|
|
+ User user = userMapper.selectById(token);
|
|
|
|
+ ExpenseItem item = new ExpenseItem();
|
|
|
|
+ item.setId(itemId);
|
|
|
|
+ item.setStatus(0);
|
|
|
|
+ expenseItemMapper.updateById(item);
|
|
|
|
+ ExpenseItem expenseItem = expenseItemMapper.selectById(itemId);
|
|
|
|
+ //查询单据下的全部费用项目状态
|
|
|
|
+ int count = expenseItemMapper.selectCount(new QueryWrapper<ExpenseItem>().eq("expense_id", item.getExpenseId()).ne("status", 0));
|
|
|
|
+ if (count == 0) {
|
|
|
|
+ ExpenseSheet sheet = new ExpenseSheet();
|
|
|
|
+ sheet.setId(expenseItem.getExpenseId());
|
|
|
|
+ sheet.setStatus(0);
|
|
|
|
+ expenseSheetMapper.updateById(sheet);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ExpenseSheet sheet = expenseSheetMapper.selectById(expenseItem.getExpenseId());
|
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
|
|
|
|
+ if (wxCorpInfo != null) {
|
|
|
|
+ sendSingleAuditResult(wxCorpInfo, user, expenseItem, sheet.getOwnerId(), sheet.getCreateDate(), null);
|
|
|
|
+ }
|
|
|
|
+ saveNotifyToApplier(sheet, user);
|
|
|
|
+
|
|
|
|
+ return new HttpRespMsg();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg denySingleProject(Integer itemId, String denyReason) {
|
|
|
|
+ String token = request.getHeader("TOKEN");
|
|
|
|
+ User user = userMapper.selectById(token);
|
|
|
|
+ ExpenseItem item = new ExpenseItem();
|
|
|
|
+ item.setId(itemId);
|
|
|
|
+ item.setStatus(2);
|
|
|
|
+ expenseItemMapper.updateById(item);
|
|
|
|
+ ExpenseItem expenseItem = expenseItemMapper.selectById(itemId);
|
|
|
|
+ //查询单据下的全部费用项目状态
|
|
|
|
+ int count = expenseItemMapper.selectCount(new QueryWrapper<ExpenseItem>().eq("expense_id", item.getExpenseId()).ne("status", 2));
|
|
|
|
+ if (count == 0) {
|
|
|
|
+ ExpenseSheet sheet = new ExpenseSheet();
|
|
|
|
+ sheet.setId(expenseItem.getExpenseId());
|
|
|
|
+ sheet.setStatus(2);
|
|
|
|
+ expenseSheetMapper.updateById(sheet);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ExpenseSheet sheet = expenseSheetMapper.selectById(expenseItem.getExpenseId());
|
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
|
|
|
|
+ if (wxCorpInfo != null) {
|
|
|
|
+ sendSingleAuditResult(wxCorpInfo, user, expenseItem, sheet.getOwnerId(), sheet.getCreateDate(), denyReason);
|
|
|
|
+ }
|
|
|
|
+ saveNotifyToApplier(sheet, user);
|
|
|
|
+ return new HttpRespMsg();
|
|
|
|
+ }
|
|
}
|
|
}
|