|
|
@@ -1,19 +1,30 @@
|
|
|
package cn.com.ctop.reimburse.mondule.service.impl;
|
|
|
|
|
|
+import cn.com.ctop.common.module.service.ISendMessageService;
|
|
|
+import cn.com.ctop.common.module.service.ISysDepartService;
|
|
|
+import cn.com.ctop.common.module.service.ISysUserService;
|
|
|
+import cn.com.ctop.common.module.service.IUserCompanyService;
|
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
|
import cn.com.ctop.reimburse.mondule.entity.ReimburseApply;
|
|
|
import cn.com.ctop.reimburse.mondule.entity.ReimburseProject;
|
|
|
import cn.com.ctop.reimburse.mondule.mapper.ReimburseApplyMapper;
|
|
|
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.JSONObject;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.system.entity.SysDepart;
|
|
|
+import org.jeecg.common.system.entity.SysUser;
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -23,12 +34,25 @@ import java.util.List;
|
|
|
* 2022-11-21
|
|
|
* @version V1.0
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class ReimburseApplyServiceImpl extends ServiceImpl<ReimburseApplyMapper, ReimburseApply> implements IReimburseApplyService {
|
|
|
|
|
|
@Autowired
|
|
|
private IReimburseProjectService projectService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysDepartService sysDepartService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISendMessageService sendMessageService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ IUserCompanyService userCompanyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService sysUserService;
|
|
|
+
|
|
|
@Override
|
|
|
public Result<Object> queryPageList(ReimburseApply reimburseApply, Integer pageNo, Integer pageSize) {
|
|
|
PageHelper.startPage(pageNo, pageSize);
|
|
|
@@ -37,26 +61,232 @@ public class ReimburseApplyServiceImpl extends ServiceImpl<ReimburseApplyMapper,
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public List<JSONObject> queryList(ReimburseApply reimburseApply) {
|
|
|
+ return baseMapper.queryList(reimburseApply);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public Result<Object> add(JSONObject data) {
|
|
|
ReimburseApply apply = JSONObject.parseObject(data.toJSONString(), ReimburseApply.class);
|
|
|
List<String> ids = JSONObject.parseArray(data.getJSONArray("ids").toJSONString(), String.class);
|
|
|
- List<ReimburseProject> byIds = projectService.getByIds(ids);
|
|
|
- if (Check.isNull(byIds)) {
|
|
|
+ List<ReimburseProject> projects = projectService.getByIds(ids);
|
|
|
+ if (!Check.isNull(projects)) {
|
|
|
Integer invoices = 0;
|
|
|
Double amount = 0.0;
|
|
|
- for (ReimburseProject project : byIds) {
|
|
|
+ for (ReimburseProject project : projects) {
|
|
|
invoices += project.getInvoices();
|
|
|
amount += Double.valueOf(project.getAmount());
|
|
|
}
|
|
|
apply.setInvoices(invoices);
|
|
|
apply.setAmount(amount.toString());
|
|
|
}
|
|
|
+ String leader = getLeader(data.getString("userId"));
|
|
|
+ apply.setLeaderId(leader);
|
|
|
+ String randomNumber = RandomUtil.randomNumbers(6);
|
|
|
+ String today = DateUtils.formatDate(new Date());
|
|
|
+ String todayStr = DateUtils.getDateInteger(today).toString();
|
|
|
+ //20221125123456
|
|
|
+ String id = todayStr + randomNumber;
|
|
|
+ apply.setId(Long.valueOf(id));
|
|
|
this.save(apply);
|
|
|
- for (ReimburseProject project : byIds) {
|
|
|
+ for (ReimburseProject project : projects) {
|
|
|
project.setApplyId(apply.getId());
|
|
|
projectService.updateById(project);
|
|
|
}
|
|
|
+ sendMsg(leader, "1", id, null);
|
|
|
return Result.ok();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Result<Object> edit(JSONObject data) {
|
|
|
+ String sender = null;
|
|
|
+ String msg = null;
|
|
|
+ String type = "1";
|
|
|
+ //是否到财务审核
|
|
|
+ boolean isFinancialReview = false;
|
|
|
+ ReimburseApply apply = JSONObject.parseObject(data.toJSONString(), ReimburseApply.class);
|
|
|
+ Long id = apply.getId();
|
|
|
+ List<String> ids = JSONObject.parseArray(data.getJSONArray("ids").toJSONString(), String.class);
|
|
|
+ List<ReimburseProject> projects = projectService.getByIds(ids);
|
|
|
+ if (!Check.isNull(projects)) {
|
|
|
+ Integer invoices = 0;
|
|
|
+ Double amount = 0.0;
|
|
|
+ for (ReimburseProject project : projects) {
|
|
|
+ invoices += project.getInvoices();
|
|
|
+ amount += Double.valueOf(project.getAmount());
|
|
|
+ }
|
|
|
+ apply.setInvoices(invoices);
|
|
|
+ apply.setAmount(amount.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ //登录人ID
|
|
|
+ String loginId = data.getString("loginId");
|
|
|
+ //创建人操作,直接修改
|
|
|
+ if (loginId.equals(apply.getUserId())) {
|
|
|
+ //获取下次审核人信息
|
|
|
+ sender = getLeader(loginId);
|
|
|
+ apply.setLeaderId(sender);
|
|
|
+ apply.setStatus("1");
|
|
|
+ this.updateById(apply);
|
|
|
+ for (ReimburseProject project : projects) {
|
|
|
+ project.setApplyId(apply.getId());
|
|
|
+ projectService.updateById(project);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //获取下次审核人信息
|
|
|
+ String leader = getLeader(data.getString("leaderId"));
|
|
|
+ //审核人 操作流程:↓↓↓
|
|
|
+ //状态 1待审核、2审核通过、3审核拒绝、4审核中、5部分拒绝
|
|
|
+ String status = data.getString("status");
|
|
|
+ if ("4".equals(status)) {
|
|
|
+ if (loginId.equals(leader)) {
|
|
|
+ //登录人和待审核人一样,则是部门最后审核人
|
|
|
+ apply.setFinalStatus("1");
|
|
|
+ //是否是福利费用,是则发送审核 到指定审核人;否则 发送到财务
|
|
|
+ String welfareUser = checkWelfare(projects);
|
|
|
+ if (!Check.isNull(welfareUser)) {
|
|
|
+ apply.setLeaderId(welfareUser);
|
|
|
+ sender = welfareUser;
|
|
|
+ } else {
|
|
|
+ //发送 财务审核
|
|
|
+ isFinancialReview = true;
|
|
|
+ apply.setLeaderId("");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ sender = leader;
|
|
|
+ apply.setLeaderId(leader);
|
|
|
+ }
|
|
|
+ } else if ("3".equals(status) || "5".equals(status)) {
|
|
|
+ apply.setLeaderId("");
|
|
|
+ sender = apply.getUserId();
|
|
|
+ }
|
|
|
+ this.updateById(apply);
|
|
|
+ }
|
|
|
+ //流程到财务审核
|
|
|
+ if (isFinancialReview) {
|
|
|
+ //财务审核roleId : 32825ea6b43cb61bffa09bf05ad69cf2
|
|
|
+ List<SysUser> users = sysUserService.getUserListByRoleId("32825ea6b43cb61bffa09bf05ad69cf2");
|
|
|
+ for (SysUser user : users) {
|
|
|
+ sendMsg(user.getId(), type, id, msg);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ sendMsg(sender, type, id, msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取审核人ID
|
|
|
+ private String getLeader(String userId) {
|
|
|
+ String leaderId = "";
|
|
|
+ //todo 查询公司
|
|
|
+ JSONObject company = userCompanyService.getCompanyInfoByUserId(userId);
|
|
|
+ String companyId = company.getString("companyId");
|
|
|
+ if ("6608ed13c0dd42de93c790dbdf124234".equals(companyId)) {
|
|
|
+ //广州汇创思拓数字科技有限公司(华南) 直接返回 何田田
|
|
|
+ return "1cd4c769eabb4de98fed306de2a3bbbd";
|
|
|
+ } else if ("4b10089775c040119e139087517aed88".equals(companyId)) {
|
|
|
+ //上海汇创思拓数字科技有限公司 直接返回 吴婵
|
|
|
+ return "183dce577efb49b386369473368cf251";
|
|
|
+ }
|
|
|
+ //查询部门
|
|
|
+ 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 = null;
|
|
|
+ //查询审核人员信息
|
|
|
+ List<JSONObject> list = baseMapper.selectLeaders();
|
|
|
+ for (JSONObject obj : list) {
|
|
|
+ String departName = obj.getString("depart_name");
|
|
|
+ if (map.toJSONString().contains(departName)) {
|
|
|
+ leader = obj;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //第一审核人
|
|
|
+ String firstId = leader.getString("first_id");
|
|
|
+ //第二审核人
|
|
|
+ String secondId = leader.getString("second_id");
|
|
|
+ //终极审核人
|
|
|
+ String finalId = leader.getString("final_id");
|
|
|
+ if (userId.equals(finalId)) {
|
|
|
+ return finalId;
|
|
|
+ } else {
|
|
|
+ if (Check.isNull(firstId)) {
|
|
|
+ //第一审核人为空,则直接取终极审核人
|
|
|
+ leaderId = finalId;
|
|
|
+ } else {
|
|
|
+ if (Check.isNull(secondId)) {
|
|
|
+ //第二审核人为空
|
|
|
+ if (firstId.equals(userId)) {
|
|
|
+ leaderId = finalId;
|
|
|
+ } else {
|
|
|
+ leaderId = firstId;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (firstId.equals(userId)) {
|
|
|
+ leaderId = secondId;
|
|
|
+ } else {
|
|
|
+ if (secondId.equals(userId)) {
|
|
|
+ leaderId = finalId;
|
|
|
+ } else {
|
|
|
+ leaderId = firstId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return leaderId;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送提示到审核人
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ * @throws
|
|
|
+ * @Param type 1:成功;2:失败
|
|
|
+ */
|
|
|
+ private void sendMsg(String userId, String type, Object id, String msg) {
|
|
|
+ try {
|
|
|
+ StringBuilder text = new StringBuilder();
|
|
|
+ if ("1".equals(type)) {
|
|
|
+ text.append("报销提示:").append("<br/>")
|
|
|
+ .append("您好,现在有报销单(编号:").append(id)
|
|
|
+ .append(")待您审批,请您及时查看审批!");
|
|
|
+ } else {
|
|
|
+ text.append("报销提示").append("<br/>")
|
|
|
+ .append("您好,你的报销单(编号:").append(id)
|
|
|
+ .append(")审批未通过,未通过原因:")
|
|
|
+ .append(msg).append(",请及时修改报销内容,以免耽误您的报销!");
|
|
|
+ }
|
|
|
+ sendMessageService.sendMessage(userId, text.toString());
|
|
|
+ log.info("发送报销提醒,userId:{} msg:{}", userId, text.toString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断是否是福利费用,若是则将审核人返回
|
|
|
+ * 考试费-郭艳玲(16eab477cd7a43538c1049d9678753e0)、
|
|
|
+ * 团建费,伯乐奖,结婚礼金,生育礼金-李盼(4afbd7ef38804a558aca1329d4008d37)
|
|
|
+ */
|
|
|
+ private String checkWelfare(List<ReimburseProject> projects) {
|
|
|
+ String type = "KS";
|
|
|
+ String typ = "BL,TJ,JH,SY";
|
|
|
+ for (ReimburseProject project : projects) {
|
|
|
+ if (type.equals(project.getType())) {
|
|
|
+ return "16eab477cd7a43538c1049d9678753e0";
|
|
|
+ } else if (typ.contains(project.getType())) {
|
|
|
+ return "4afbd7ef38804a558aca1329d4008d37";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|