| | |
| | | package com.zy.crm.manager.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.R; |
| | | import com.core.domain.KeyValueVo; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.crm.common.model.SettleDto; |
| | | import com.zy.crm.common.web.BaseController; |
| | | import com.zy.crm.manager.entity.Plan; |
| | | import com.zy.crm.manager.entity.Reimburse; |
| | | import com.zy.crm.manager.entity.ReimburseOnline; |
| | | import com.zy.crm.manager.entity.ReimburseOnlineDetl; |
| | | import com.zy.crm.manager.entity.*; |
| | | import com.zy.crm.manager.entity.param.ReimburseOnlineDomainParam; |
| | | import com.zy.crm.manager.service.*; |
| | | import com.zy.crm.manager.utils.RuleUtils; |
| | | import com.zy.crm.system.entity.User; |
| | | import com.zy.crm.system.service.UserService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.core.io.ClassPathResource; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | |
| | | @Autowired |
| | | private PlanService planService; |
| | | |
| | | @Autowired |
| | | private ReimburseOnlineDetlService reimburseOnlineDetlService; |
| | | |
| | | @Autowired |
| | | private RuleService ruleService; |
| | | |
| | | @Autowired |
| | | private UserService userService; |
| | | |
| | | @Autowired |
| | | private ProcessPermissionsService processPermissionsService; |
| | | |
| | | @RequestMapping(value = "/reimburseOnline/{id}/auth") |
| | | @ManagerAuth |
| | | public R get(@PathVariable("id") String id) { |
| | | return R.ok(reimburseOnlineService.selectById(String.valueOf(id))); |
| | | ReimburseOnline reimburseOnline = reimburseOnlineService.selectById(String.valueOf(id)); |
| | | assert reimburseOnline != null; |
| | | JSONObject resultObj = JSON.parseObject(JSON.toJSONString(reimburseOnline)); |
| | | if (!Cools.isEmpty(reimburseOnline.getForm())) { |
| | | JSONObject formObj = JSON.parseObject(reimburseOnline.getForm()); |
| | | formObj.forEach(resultObj::putIfAbsent); |
| | | } |
| | | |
| | | // 步骤条相关 |
| | | resultObj.put("step", reimburseOnline.getSettle() == 6 ? 0 : reimburseOnline.getSettle() + 1); |
| | | |
| | | return R.ok().add(resultObj); |
| | | } |
| | | |
| | | @RequestMapping(value = "/reimburseOnline/viewCheck/{id}/auth") |
| | |
| | | @RequestParam(required = false)String condition, |
| | | @RequestParam Map<String, Object> param){ |
| | | EntityWrapper<ReimburseOnline> wrapper = new EntityWrapper<>(); |
| | | wrapper.setSqlSelect("id,title,create_time as createTime,filepath,item_id as itemId,order_num as orderNum,template_name as templateName,user_id as userId,dept_id as deptId,status,update_time as updateTime,check_data as checkData,update_user_id as updateUserId,member_id as memberId"); |
| | | wrapper.in("member_id", getUserRoleBelongsToUserId("allopen")); |
| | | wrapper.setSqlSelect("id,settle,title,create_time as createTime,filepath,item_id as itemId,order_num as orderNum,template_name as templateName,user_id as userId,dept_id as deptId,status,update_time as updateTime,check_data as checkData,update_user_id as updateUserId,member_id as memberId,name"); |
| | | // wrapper.in("member_id", getUserRoleBelongsToUserId()); |
| | | wrapper.andNew(); |
| | | excludeTrash(param); |
| | | convert(param, wrapper); |
| | | allLike(ReimburseOnline.class, param.keySet(), wrapper, condition); |
| | | wrapper.or().eq("member_id",getUserId()); |
| | | if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} |
| | | return R.ok(reimburseOnlineService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | } |
| | |
| | | Long deptId = getDeptId(); |
| | | boolean signUserId = false; |
| | | boolean signDeptId = false; |
| | | boolean signHostId = false; |
| | | for (Map.Entry<String, Object> entry : map.entrySet()){ |
| | | if (entry.getKey().equals("dept_id")){ |
| | | signDeptId = true; |
| | | if (String.valueOf(entry.getValue()).equals("19")){ |
| | | signHostId = true; |
| | | } |
| | | } |
| | | } |
| | | for (Map.Entry<String, Object> entry : map.entrySet()){ |
| | |
| | | if (!signUserId && !signDeptId){ |
| | | wrapper.eq("user_id", getUserId()); |
| | | } |
| | | if (signHostId){ |
| | | wrapper.or().eq("host_id",1); |
| | | } |
| | | } |
| | | @RequestMapping(value = "/reimburseOnline/from/add/auth") |
| | | @ManagerAuth(memo = "添加报销单") |
| | | @Transactional |
| | | public R formAdd(@RequestBody ReimburseOnlineDomainParam param){ |
| | | System.out.println(param); |
| | | long planId = 0; |
| | | if (!param.getTemplateName().equals("非项目型报销")){ |
| | | if (Cools.isEmpty(param.getOrderNo())){ |
| | | return R.error("添加失败!"+param.getTemplateName()+"需要关联项目号"); |
| | | } |
| | | String[] split = param.getOrderNo().split("---"); |
| | | planId = Long.parseLong(split[1]); |
| | | } |
| | | Date now = new Date(); |
| | | Rule rule = ruleService.selectById(1); |
| | | ReimburseOnline reimburseOnline = new ReimburseOnline(planId,RuleUtils.rule(rule),now,getUser()); |
| | | reimburseOnline.setCheckData(param.getCheckData()); |
| | | reimburseOnline.setTemplateName(param.getTemplateName()); |
| | | reimburseOnline.setName(param.getName()); |
| | | |
| | | reimburseOnline.setSettle(0); // 0.创建 |
| | | User manager = userService.getDeptManager(getHostId(), getUser().getDeptId()); // 获取部门领导 |
| | | |
| | | ProcessPermissions processPermissions3 = processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 3).eq("process", param.getCheckData().equals("否")? "3-1" : "3-2"));//3:报销流程 |
| | | User president3 = userService.selectById(processPermissions3.getUserId()); // 获取报价流程节点3确认人 |
| | | |
| | | ProcessPermissions processPermissions4 = processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 3).eq("process", "4-1"));//3:报销流程 |
| | | User president4 = userService.selectById(processPermissions4.getUserId()); // 获取报价流程节点4确认人 |
| | | |
| | | ProcessPermissions processPermissions5 = processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 3).eq("process", "5-1"));//3:报销流程 |
| | | User president5 = userService.selectById(processPermissions5.getUserId()); // 获取报价流程节点5确认人 |
| | | |
| | | ProcessPermissions processPermissions6 = processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 3).eq("process", "6-1"));//3:报销流程 |
| | | User president6 = userService.selectById(processPermissions6.getUserId()); // 获取报价流程节点6确认人 |
| | | |
| | | reimburseOnline.setSettleMsg(JSON.toJSONString(SettleDto.initPriQuote(reimburseOnline, manager,president3,president4,president5,president6,getUser()))); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("title","非项目型报销"); |
| | | map.put("reimburseId",reimburseOnline.getPlanId$()); |
| | | map.put("docType",param.getDocType()); |
| | | map.put("orderNo",param.getOrderNo()); |
| | | map.put("templateName",param.getTemplateName()); |
| | | map.put("checkData",param.getCheckData()); |
| | | map.put("name",param.getName()); |
| | | reimburseOnline.setForm(JSON.toJSONString(map)); |
| | | reimburseOnline.setMemberId(getUser().getId()); |
| | | |
| | | if (!reimburseOnlineService.insert(reimburseOnline)){ |
| | | return R.error("添加报销主档失败"); |
| | | } |
| | | for (ReimburseOnlineDetl reimburseOnlineDetl:param.getReimburseOnlineDetls()){ |
| | | reimburseOnlineDetl.setOrderId(reimburseOnline.getId()); |
| | | reimburseOnlineDetlService.insert(reimburseOnlineDetl); |
| | | } |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/reimburseOnline/from/modify/auth") |
| | | @ManagerAuth(memo = "修改报销单") |
| | | @Transactional |
| | | public R formModify(@RequestBody ReimburseOnlineDomainParam param){ |
| | | System.out.println(param); |
| | | |
| | | long planId = 0; |
| | | if (!param.getTemplateName().equals("非项目型报销")){ |
| | | if (Cools.isEmpty(param.getOrderNo())){ |
| | | return R.error("修改失败!"+param.getTemplateName()+"需要关联项目号"); |
| | | } |
| | | String[] split = param.getOrderNo().split("---"); |
| | | planId = Long.parseLong(split[1]); |
| | | } |
| | | Date now = new Date(); |
| | | ReimburseOnline reimburseOnline = reimburseOnlineService.selectById(param.getReimburseId()); |
| | | |
| | | if (!reimburseOnline.getSettle().equals(0)){ |
| | | return R.error("修改失败!提交之后禁止修改!"); |
| | | } |
| | | if (!reimburseOnline.getUserId().equals(getUserId())){ |
| | | return R.error("非创建人员禁止修改!"); |
| | | } |
| | | |
| | | |
| | | reimburseOnline.setCheckData(param.getCheckData()); |
| | | reimburseOnline.setTemplateName(param.getTemplateName()); |
| | | reimburseOnline.setItemId(planId); |
| | | reimburseOnline.setName(param.getName()); |
| | | reimburseOnline.setUpdateTime(new Date()); |
| | | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("title",reimburseOnline.getPlanId$()); |
| | | map.put("reimburseId",param.getReimburseId()); |
| | | map.put("docType",param.getDocType()); |
| | | map.put("orderNo",param.getOrderNo()); |
| | | map.put("templateName",param.getTemplateName()); |
| | | map.put("checkData",param.getCheckData()); |
| | | map.put("name",param.getName()); |
| | | reimburseOnline.setForm(JSON.toJSONString(map)); |
| | | |
| | | if (!reimburseOnlineService.updateById(reimburseOnline)){ |
| | | return R.error("更新报销主档失败"); |
| | | } |
| | | |
| | | reimburseOnlineDetlService.delete(new EntityWrapper<ReimburseOnlineDetl>().eq("order_id",reimburseOnline.getId())); |
| | | |
| | | for (ReimburseOnlineDetl reimburseOnlineDetl:param.getReimburseOnlineDetls()){ |
| | | reimburseOnlineDetl.setOrderId(reimburseOnline.getId()); |
| | | reimburseOnlineDetlService.insert(reimburseOnlineDetl); |
| | | } |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/reimburseOnline/detl/all/auth") |
| | | @Transactional |
| | | public R head(@RequestParam Integer reimburseId){ |
| | | List<ReimburseOnlineDetl> reimburseOnlineDetls = reimburseOnlineDetlService.selectList(new EntityWrapper<ReimburseOnlineDetl>().eq("reimburse_id", reimburseId)); |
| | | List<ReimburseOnlineDetl> reimburseOnlineDetls = reimburseOnlineDetlService.selectList(new EntityWrapper<ReimburseOnlineDetl>().eq("order_id", reimburseId)); |
| | | return R.ok().add(reimburseOnlineDetls); |
| | | } |
| | | |
| | |
| | | return R.error(); |
| | | } |
| | | reimburseOnlineService.deleteBatchIds(Arrays.asList(ids)); |
| | | for (Long id : ids){ |
| | | reimburseOnlineDetlService.delete(new EntityWrapper<ReimburseOnlineDetl>().eq("order_id",id)); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | return R.ok().add(vos); |
| | | } |
| | | |
| | | @PostMapping(value = "/reimburseOnline/approval2/auth") |
| | | @ManagerAuth |
| | | public R approvalReimburseOnline(@RequestParam Long planId, |
| | | @RequestParam(required = false) Long plannerId){ |
| | | ReimburseOnline reimburseOnline = reimburseOnlineService.selectById(planId); |
| | | assert reimburseOnline != null; |
| | | Integer settle = reimburseOnline.getSettle(); |
| | | String process=""; |
| | | Date now = new Date(); |
| | | switch (reimburseOnline.getSettle()) { |
| | | case 0: |
| | | User user2 = userService.selectById(reimburseOnline.getUserId()); |
| | | User manager1 = userService.getDeptManager(getHostId(), user2.getDeptId()); |
| | | |
| | | if (Cools.isEmpty(getUser())) { |
| | | return R.error("抱歉,您没有提交的权限"); |
| | | } |
| | | if (!getUserId().equals(getUser().getId())) { |
| | | return R.error("抱歉,您没有提交的权限"); |
| | | } |
| | | // 修改 settle 步骤数据 |
| | | List<SettleDto> list1 = JSON.parseArray(reimburseOnline.getSettleMsg(), SettleDto.class); |
| | | for (SettleDto dto : list1) { |
| | | switch (dto.getStep()) { |
| | | case 0: |
| | | dto.setCurr(Boolean.FALSE); |
| | | break; |
| | | case 1: |
| | | dto.setCurr(Boolean.TRUE); |
| | | dto.setMsg(getUser().getNickname() + "提交完成"); |
| | | dto.setTime(DateUtils.convert(now)); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | reimburseOnline.setSettleMsg(JSON.toJSONString(list1)); |
| | | // 修改规划单状态 |
| | | reimburseOnline.setSettle(1); |
| | | reimburseOnline.setUpdateUserId(getUserId()); |
| | | reimburseOnline.setUpdateTime(now); |
| | | reimburseOnline.setMemberId(manager1.getId()); |
| | | |
| | | if (!reimburseOnlineService.updateById(reimburseOnline)) { |
| | | throw new CoolException("审核失败,请联系管理员"); |
| | | } |
| | | break; |
| | | case 1: |
| | | // 本部门经理审核 |
| | | User user = userService.selectById(reimburseOnline.getUserId()); |
| | | User manager = userService.getDeptManager(getHostId(), user.getDeptId()); |
| | | if (manager.getId().equals(getUserId())) { |
| | | |
| | | // 修改 settle 步骤数据 |
| | | List<SettleDto> list = JSON.parseArray(reimburseOnline.getSettleMsg(), SettleDto.class); |
| | | for (SettleDto dto : list) { |
| | | switch (dto.getStep()) { |
| | | case 1: |
| | | dto.setCurr(Boolean.FALSE); |
| | | break; |
| | | case 2: |
| | | dto.setCurr(Boolean.TRUE); |
| | | dto.setMsg("部门经理" + manager.getNickname() + "审批通过"); |
| | | dto.setTime(DateUtils.convert(now)); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | reimburseOnline.setSettleMsg(JSON.toJSONString(list)); |
| | | |
| | | // 修改规划单状态 |
| | | reimburseOnline.setSettle(2); // 总裁办待审 |
| | | reimburseOnline.setUpdateUserId(getUserId()); |
| | | reimburseOnline.setUpdateTime(now); |
| | | ProcessPermissions processPermissions = processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 3).eq("process", reimburseOnline.getCheckData().equals("否") ? "3-1" : "3-2"));//3:报销流程 |
| | | reimburseOnline.setMemberId(processPermissions.getUserId()); |
| | | |
| | | if (!reimburseOnlineService.updateById(reimburseOnline)) { |
| | | throw new CoolException("审核失败,请联系管理员"); |
| | | } |
| | | |
| | | } else { |
| | | return R.error("抱歉,您没有审核的权限"); |
| | | } |
| | | break; |
| | | case 2: |
| | | if (reimburseOnline.getCheckData().equals("否")){ |
| | | process="3-1"; |
| | | }else { |
| | | process="3-2"; |
| | | } |
| | | case 3: |
| | | if (Cools.isEmpty(process) || process.equals("")){ |
| | | process="4-1"; |
| | | } |
| | | case 4: |
| | | if (Cools.isEmpty(process) || process.equals("")){ |
| | | process="5-1"; |
| | | } |
| | | case 5: |
| | | if (Cools.isEmpty(process) || process.equals("")){ |
| | | process="6-1"; |
| | | } |
| | | ProcessPermissions processPermissions = processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 3).eq("process", process));//3:报销流程 |
| | | User planLeader = userService.selectById(processPermissions.getUserId()); // 获取报价流程节点确认人 |
| | | |
| | | if (Cools.isEmpty(planLeader)) { |
| | | throw new CoolException("未查找到报价流程节点"+process+"确认人,请联系在审批权限添加确认人!"); |
| | | } |
| | | if (!getUserId().equals(planLeader.getId())) { |
| | | return R.error("抱歉,您没有审核的权限"); |
| | | } |
| | | // 修改 settle 步骤数据 |
| | | List<SettleDto> list = JSON.parseArray(reimburseOnline.getSettleMsg(), SettleDto.class); |
| | | for (SettleDto dto : list) { |
| | | if (dto.getStep().equals(settle)){ |
| | | dto.setCurr(Boolean.FALSE); |
| | | }else if (dto.getStep().equals(settle+1)){ |
| | | dto.setCurr(Boolean.TRUE); |
| | | dto.setMsg("报价流程节点"+process+"确认人:"+planLeader.getNickname() + "审批通过"); |
| | | dto.setTime(DateUtils.convert(now)); |
| | | } |
| | | } |
| | | reimburseOnline.setSettleMsg(JSON.toJSONString(list)); |
| | | // 修改规划单状态 |
| | | reimburseOnline.setSettle(settle+1); |
| | | reimburseOnline.setUpdateUserId(getUserId()); |
| | | reimburseOnline.setUpdateTime(now); |
| | | String[] split = process.split("-"); |
| | | if (settle!=5){ |
| | | settle=settle+2; |
| | | }else { |
| | | settle++; |
| | | reimburseOnline.setStatus(1); |
| | | } |
| | | ProcessPermissions processPermissions2 = processPermissionsService.selectOne(new EntityWrapper<ProcessPermissions>().eq("process_memo", 3).eq("process", settle+"-"+split[1]));//3:报销流程 |
| | | reimburseOnline.setMemberId(processPermissions2.getUserId()); |
| | | |
| | | if (!reimburseOnlineService.updateById(reimburseOnline)) { |
| | | throw new CoolException("审核失败,请联系管理员"); |
| | | } |
| | | break; |
| | | default: |
| | | return R.error(); |
| | | } |
| | | return R.ok("审批成功"); |
| | | } |
| | | |
| | | } |