zxa 3 lat temu
rodzic
commit
cc5dff6794

+ 71 - 12
jeecg-boot-module-system/src/main/java/cn/com/ctop/reimburse/mondule/controller/ReimburseApplyController.java

@@ -1,12 +1,17 @@
 package cn.com.ctop.reimburse.mondule.controller;
 
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.ExportExcelUtils;
+import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.reimburse.mondule.entity.ReimburseApply;
 import cn.com.ctop.reimburse.mondule.service.IReimburseApplyService;
 import com.alibaba.fastjson.JSONObject;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.modules.system.service.ISysRoleService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -15,7 +20,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 
 /**
  * 报销申请提交表
@@ -28,6 +38,9 @@ public class ReimburseApplyController {
     @Autowired
     private IReimburseApplyService reimburseApplyService;
 
+    @Autowired
+    private ISysRoleService sysRoleService;
+
     /**
      * 分页列表查询
      */
@@ -37,6 +50,12 @@ public class ReimburseApplyController {
                                         @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize
     ) {
         try {
+            //查询用户角色
+            String roleCode = sysRoleService.getRoleCodeByUserId(reimburseApply.getUserId());
+            if ("financialReview".equals(roleCode)) {
+                //财务查询
+                reimburseApply.setFinancialReview(1);
+            }
             return reimburseApplyService.queryPageList(reimburseApply, pageNo, pageSize);
         } catch (Exception e) {
             e.printStackTrace();
@@ -44,6 +63,52 @@ public class ReimburseApplyController {
         }
     }
 
+    @GetMapping(value = "/excel")
+    public void queryExcel(HttpServletResponse response, ReimburseApply reimburseApply) {
+        //查询用户角色
+        String roleCode = sysRoleService.getRoleCodeByUserId(reimburseApply.getUserId());
+        if ("financialReview".equals(roleCode)) {
+            //财务查询
+            reimburseApply.setFinancialReview(1);
+        }
+        List<JSONObject> list = reimburseApplyService.queryList(reimburseApply);
+        if (!Check.isNull(list)) {
+            try {
+                List<List<Object>> excelList = new ArrayList<>();
+                if (!list.isEmpty()) {
+                    for (JSONObject info : list) {
+                        List<Object> temp = new ArrayList<>();
+                        temp.add(info.getString("id"));
+                        temp.add(info.getString("userName"));
+                        temp.add(info.getString("departName"));
+                        temp.add(info.getString("companyName"));
+                        temp.add(info.getString("media"));
+                        temp.add(info.getString("type"));
+                        temp.add(info.getString("project"));
+                        temp.add(info.getString("amount"));
+                        temp.add(info.getString("expenseDate"));
+                        temp.add(info.getString("statDate"));
+                        temp.add(info.getString("remarks"));
+                        temp.add(info.getString("status"));
+                        excelList.add(temp);
+                    }
+                }
+                OutputStream os = response.getOutputStream();
+                ExportExcelUtils eeu = new ExportExcelUtils();
+                XSSFWorkbook workbook = new XSSFWorkbook();
+
+                String[] titles = {"编号", "申请人", "部门", "主体", "媒体线", "报销类别", "报销项目", "报销金额", "费用产生日期", "申请时间", "备注", "状态"};
+                eeu.exportExcelForAttendance(workbook, 0, "审核信息", titles, excelList);
+                HttpUtils.setResponseHeader(response, "clockIn.xlsx");
+                workbook.write(os);
+                os.flush();
+                os.close();
+            } catch (IOException e) {
+                log.error(e.getMessage());
+            }
+        }
+    }
+
     /**
      * 添加
      */
@@ -61,19 +126,13 @@ public class ReimburseApplyController {
      * 编辑
      */
     @PostMapping(value = "/edit")
-    public Result<ReimburseApply> edit(@RequestBody ReimburseApply reimburseApply) {
-        Result<ReimburseApply> result = new Result<ReimburseApply>();
-        ReimburseApply reimburseApplyEntity = reimburseApplyService.getById(reimburseApply.getId());
-        if (reimburseApplyEntity == null) {
-            result.error500("未找到对应实体");
-        } else {
-            boolean ok = reimburseApplyService.updateById(reimburseApply);
-            if (ok) {
-                result.success("修改成功!");
-            }
+    public Result<Object> edit(@RequestBody JSONObject data) {
+        try {
+            return reimburseApplyService.edit(data);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return Result.error("修改失败!");
         }
-
-        return result;
     }
 
     /**

+ 9 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/reimburse/mondule/entity/ReimburseApply.java

@@ -112,6 +112,12 @@ public class ReimburseApply {
     @ApiModelProperty(value = "状态  1待审核、2审核通过、3审核拒绝、4审核中、5部分拒绝")
     private String status;
     /**
+     * 最终状态0 无效状态,1 各部门审核人通过审核,2财务审核完成
+     */
+    @Excel(name = "最终状态0 无效状态,1 各部门审核人通过审核,2财务审核完成", width = 15)
+    @ApiModelProperty(value = "最终状态0 无效状态,1 各部门审核人通过审核,2财务审核完成")
+    private String finalStatus;
+    /**
      * 创建时间
      */
     @ApiModelProperty(value = "创建时间")
@@ -128,4 +134,7 @@ public class ReimburseApply {
     @TableField(exist = false)
     private String endDate;
 
+    @TableField(exist = false)
+    private Integer financialReview;
+
 }

+ 9 - 5
jeecg-boot-module-system/src/main/java/cn/com/ctop/reimburse/mondule/mapper/ReimburseApplyMapper.java

@@ -1,15 +1,14 @@
 package cn.com.ctop.reimburse.mondule.mapper;
 
-import java.util.List;
-
-import com.alibaba.fastjson.JSONObject;
-import org.apache.ibatis.annotations.Param;
 import cn.com.ctop.reimburse.mondule.entity.ReimburseApply;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import org.jeecg.common.api.vo.Result;
+
+import java.util.List;
 
 /**
  * 报销申请提交表
+ *
  * @author jeecg-boot
  * 2022-11-21
  * @version V1.0
@@ -17,4 +16,9 @@ import org.jeecg.common.api.vo.Result;
 public interface ReimburseApplyMapper extends BaseMapper<ReimburseApply> {
 
     List<ReimburseApply> queryPageList(ReimburseApply reimburseApply);
+
+    List<JSONObject> queryList(ReimburseApply reimburseApply);
+
+    List<JSONObject> selectLeaders();
+
 }

+ 54 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/reimburse/mondule/mapper/xml/ReimburseApplyMapper.xml

@@ -4,10 +4,15 @@
 
     <select id="queryPageList" resultType="cn.com.ctop.reimburse.mondule.entity.ReimburseApply">
         SELECT * FROM ctop_reimburse_apply
-        where
+        where 1=1
+        <if test="financialReview == 1">
+            AND company_id =#{companyId}
+        </if>
+        <if test="financialReview != 1">
         ( user_id = #{userId}
         OR
         leader_id = #{userId})
+        </if>
         <if test="companyId != null and companyId != ''">
             AND company_id =#{companyId}
         </if>
@@ -25,4 +30,52 @@
             AND stat_date &lt;=#{endDate}
         </if>
     </select>
+
+    <select id="queryList" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t1.id,
+        t1.user_name as 'userName',
+        t1.depart_name as 'departName',
+        t1.company_name as 'companyName',
+        t1.media,
+        t2.type,
+        t2.project,
+        t2.amount,
+        t2.stat_date as 'expenseDate',
+        t1.stat_date as 'statDate',
+        t2.remarks,
+        t1.`status`
+        FROM ctop_reimburse_apply t1
+        LEFT JOIN ctop_reimburse_project t2 ON t1.id = t2.apply_id
+        WHERE  1=1
+        <if test="financialReview == 1">
+            AND t1.company_id =#{companyId}
+        </if>
+        <if test="financialReview != 1">
+        ( t1.user_id = #{userId}
+        OR
+            t1.leader_id = #{userId})
+        </if>
+        <if test="companyId != null and companyId != ''">
+            AND t1.company_id =#{companyId}
+        </if>
+        <if test="media != null and media != ''">
+            AND t1.media =#{media}
+        </if>
+        <if test="type != null and type != ''">
+            AND t1.`type` =#{type}
+        </if>
+        <if test="status != null and status != ''">
+            AND t1.status =#{status}
+        </if>
+        <if test="startDate != null and startDate != ''">
+            AND t1.stat_date >=#{startDate}
+            AND t1.stat_date &lt;=#{endDate}
+        </if>
+    </select>
+
+    <select id="selectLeaders" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT *
+        FROM ctop_reimburse_leader
+    </select>
 </mapper>

+ 7 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/reimburse/mondule/service/IReimburseApplyService.java

@@ -5,6 +5,8 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.jeecg.common.api.vo.Result;
 
+import java.util.List;
+
 /**
  * 报销申请提交表
  *
@@ -16,5 +18,10 @@ public interface IReimburseApplyService extends IService<ReimburseApply> {
 
     Result<Object> queryPageList(ReimburseApply reimburseApply, Integer pageNo, Integer pageSize);
 
+    List<JSONObject> queryList(ReimburseApply reimburseApply);
+
     Result<Object> add(JSONObject data);
+
+    Result<Object> edit(JSONObject data);
+
 }

+ 234 - 4
jeecg-boot-module-system/src/main/java/cn/com/ctop/reimburse/mondule/service/impl/ReimburseApplyServiceImpl.java

@@ -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;
+    }
+
+
 }