中扬CRM客户关系管理系统
#
LSH
2023-11-04 978a3733aedaaa505867b64edfbe1f6caedbc798
src/main/java/com/zy/crm/manager/controller/BusinessTripController.java
@@ -10,9 +10,13 @@
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.R;
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.BusinessTrip;
import com.zy.crm.manager.entity.PlanType;
import com.zy.crm.manager.entity.ProcessPermissions;
import com.zy.crm.manager.entity.ReimburseOnline;
import com.zy.crm.manager.service.BusinessTripService;
import com.zy.crm.manager.utils.CarNumberUtils;
import com.zy.crm.manager.utils.TimeCalculatorUtils;
@@ -34,7 +38,12 @@
    @RequestMapping(value = "/businessTrip/{id}/auth")
    @ManagerAuth
    public R get(@PathVariable("id") String id) {
        return R.ok(businessTripService.selectById(String.valueOf(id)));
        BusinessTrip businessTrip = businessTripService.selectById(String.valueOf(id));
        assert businessTrip != null;
        JSONObject resultObj = JSON.parseObject(JSON.toJSONString(businessTrip));
        // 步骤条相关
        resultObj.put("step", businessTrip.getSettle() == 3 ? 0 : businessTrip.getSettle() + 1);
        return R.ok().add(resultObj);
    }
    @RequestMapping(value = "/businessTrip/list/auth")
@@ -47,27 +56,59 @@
        EntityWrapper<BusinessTrip> wrapper = new EntityWrapper<>();
        excludeTrash(param);
        convert(param, wrapper);
        wrapper.or().eq("member_id",getUserId());
        if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
        return R.ok(businessTripService.selectPage(new Page<>(curr, limit), wrapper));
    }
    private <T> void convert(Map<String, Object> map, EntityWrapper<T> 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()){
            String val = String.valueOf(entry.getValue());
            if (val.contains(RANGE_TIME_LINK)){
                String[] dates = val.split(RANGE_TIME_LINK);
                wrapper.ge(entry.getKey(), DateUtils.convert(dates[0]));
                wrapper.le(entry.getKey(), DateUtils.convert(dates[1]));
            } else if (entry.getKey().equals("dept_id")){
                if (!val.equals("19")){
                    wrapper.eq(entry.getKey(), val);
                }
            } else if (entry.getKey().equals("user_id") && !signDeptId){
                signUserId = true;
                wrapper.eq(entry.getKey(), val);
            } else {
                wrapper.like(entry.getKey(), val);
            }
        }
        if (!signUserId && !signDeptId){
            if (getRole().getId()==1){
                wrapper.or().eq("host_id",1);
            }else if (getRole().getId()==2){
                wrapper.eq("dept_id",getDeptId());
            }else {
                wrapper.eq("user_id", getUserId());
            }
        }
        if (signHostId){
            wrapper.or().eq("host_id",1);
        }
    }
    @RequestMapping(value = "/businessTrip/add/auth")
    @ManagerAuth
    @ManagerAuth(memo = "添加出差申请")
    public R add(BusinessTrip businessTrip) {
        if (Cools.isEmpty(businessTrip) || null==businessTrip.getId()){
        if (Cools.isEmpty(businessTrip)){
            return R.error();
        }
        Date now = new Date();
@@ -79,6 +120,7 @@
            }
        }else {
            businessTrip.setCarNumber("无");
            businessTrip.setKilometers("无");
        }
        businessTrip.setBusinessPeersId(System.currentTimeMillis());
@@ -106,16 +148,23 @@
        businessTrip.setStatus(0);
        businessTrip.setSettle(1);
        User manager = userService.getDeptManager(getHostId(), getUser().getDeptId());        // 获取部门领导
        User manager = new User();
        try{
            manager = userService.getDeptManager(getHostId(), getUser().getDeptId());        // 获取部门领导
        }catch (Exception e){
            manager = getUser();
        }
        businessTrip.setSettleMsg(JSON.toJSONString(SettleDto.initBusiness(manager,getUser())));
        businessTrip.setMemberId(manager.getId());
        businessTripService.insert(businessTrip);
        return R.ok();
    }
   @RequestMapping(value = "/businessTrip/update/auth")
   @ManagerAuth
   @ManagerAuth(memo = "更新出差申请")
    public R update(BusinessTrip businessTrip){
        if (Cools.isEmpty(businessTrip) || null==businessTrip.getId()){
            return R.error();
@@ -153,7 +202,7 @@
    }
    @RequestMapping(value = "/businessTrip/delete/auth")
    @ManagerAuth
    @ManagerAuth(memo = "删除出差申请")
    public R delete(@RequestParam(value="ids[]") Long[] ids){
         for (Long id : ids){
            businessTripService.deleteById(id);
@@ -198,4 +247,60 @@
        return R.ok();
    }
    @PostMapping(value = "/businessTrip/approval/auth")
    @ManagerAuth
    public R approvalBusinessTrip(@RequestParam Long planId,
                                     @RequestParam(required = false) Long plannerId){
        BusinessTrip businessTrip = businessTripService.selectById(planId);
        assert businessTrip != null;
        Date now = new Date();
        switch (businessTrip.getSettle()) {
            case 1:
                // 本部门经理审核
                User user = userService.selectById(businessTrip.getUserId());
                User manager = new User();
                try{
                    manager = userService.getDeptManager(getHostId(), getUser().getDeptId());        // 获取部门领导
                }catch (Exception e){
                    manager = user;
                }
                if (manager.getId().equals(getUserId())) {
                    // 修改 settle 步骤数据
                    List<SettleDto> list = JSON.parseArray(businessTrip.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;
                        }
                    }
                    businessTrip.setSettleMsg(JSON.toJSONString(list));
                    // 修改规划单状态
                    businessTrip.setSettle(2);  // 申请通过
                    businessTrip.setStatus(1);
                    businessTrip.setUpdateId(getUserId());
                    businessTrip.setUpdateTime(now);
                    businessTrip.setMemberId(businessTrip.getUserId());
                    if (!businessTripService.updateById(businessTrip)) {
                        throw new CoolException("审核失败,请联系管理员");
                    }
                } else {
                    return R.error("抱歉,您没有批准的权限!!!");
                }
                break;
            default:
                return R.error();
        }
        return R.ok("审批成功");
    }
}