|  |  |  | 
|---|
|  |  |  | 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.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; | 
|---|
|  |  |  | import com.zy.crm.system.entity.User; | 
|---|
|  |  |  | import com.zy.crm.system.service.UserService; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private BusinessTripService businessTripService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserService userService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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") | 
|---|
|  |  |  | 
|---|
|  |  |  | 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){ | 
|---|
|  |  |  | wrapper.eq("user_id", getUserId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (signHostId){ | 
|---|
|  |  |  | wrapper.or().eq("host_id",1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/businessTrip/add/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R add(BusinessTrip businessTrip) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (Cools.isEmpty(businessTrip)){ | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | //判断车牌号 | 
|---|
|  |  |  | if (businessTrip.getBusinessTransportation()==5 || businessTrip.getBusinessTransportation()==4){ | 
|---|
|  |  |  | 
|---|
|  |  |  | if (!carNumberBoolean){ | 
|---|
|  |  |  | return R.error("请输入有效车牌号"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | businessTrip.setCarNumber("无"); | 
|---|
|  |  |  | businessTrip.setKilometers("无"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | businessTrip.setBusinessPeersId(System.currentTimeMillis()); | 
|---|
|  |  |  | //        businessTrip.setBusinessDuration(TimeCalculatorUtils.getDifferenceDayDouble(businessTrip.getBusinessStartTimeDay$(),businessTrip.getBusinessEndTimeDay$())); | 
|---|
|  |  |  | businessTrip.setBusinessTripDays(TimeCalculatorUtils.getDifferenceDayInt(businessTrip.getBusinessStartTime(),businessTrip.getBusinessEndTime())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!TimeCalculatorUtils.CompareData(businessTrip.getBusinessStartTime(),businessTrip.getBusinessEndTime())){ | 
|---|
|  |  |  | return R.error("结束时间应大于等于开始时间"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (TimeCalculatorUtils.DifferenceYest(businessTrip.getBusinessStartTime(),businessTrip.getBusinessEndTime())!=0){ | 
|---|
|  |  |  | int month = TimeCalculatorUtils.DifferenceMonth(businessTrip.getBusinessStartTime(), businessTrip.getBusinessEndTime()); | 
|---|
|  |  |  | int yest = TimeCalculatorUtils.DifferenceYest(businessTrip.getBusinessStartTime(), businessTrip.getBusinessEndTime()); | 
|---|
|  |  |  | int i = month + yest * 12; | 
|---|
|  |  |  | if (i>12){ | 
|---|
|  |  |  | return R.error("出差时长不可超过一年"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | businessTrip.setBusinessDuration(TimeCalculatorUtils.DifferenceDayMorningAfternoon(businessTrip.getBusinessStartTime(),businessTrip.getBusinessEndTime(),businessTrip.getBusinessStartTimeDay(),businessTrip.getBusinessEndTimeDay())); | 
|---|
|  |  |  | businessTrip.setBusinessTripDays(TimeCalculatorUtils.DifferenceDayInt(businessTrip.getBusinessStartTime(),businessTrip.getBusinessEndTime())); | 
|---|
|  |  |  | businessTrip.setUserId(getUserId()); | 
|---|
|  |  |  | businessTrip.setDeptId(getDeptId()); | 
|---|
|  |  |  | businessTrip.setCreateTime(now); | 
|---|
|  |  |  | businessTrip.setUserId(getUserId()); | 
|---|
|  |  |  | businessTrip.setUpdateTime(now); | 
|---|
|  |  |  | businessTrip.setUpdateId(getUserId()); | 
|---|
|  |  |  | businessTrip.setStatus(0); | 
|---|
|  |  |  | businessTrip.setSettle(1); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | User manager = userService.getDeptManager(getHostId(), getUser().getDeptId());        // 获取部门领导 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | businessTrip.setSettleMsg(JSON.toJSONString(SettleDto.initBusiness(manager,getUser()))); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | businessTripService.insert(businessTrip); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | 
|---|
|  |  |  | if (Cools.isEmpty(businessTrip) || null==businessTrip.getId()){ | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | //判断车牌号 | 
|---|
|  |  |  | if (businessTrip.getBusinessTransportation()==5 || businessTrip.getBusinessTransportation()==4){ | 
|---|
|  |  |  | boolean carNumberBoolean = CarNumberUtils.isValidLicensePlate(businessTrip.getCarNumber()); | 
|---|
|  |  |  | if (!carNumberBoolean){ | 
|---|
|  |  |  | return R.error("请输入有效车牌号"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | businessTrip.setCarNumber("无"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | businessTrip.setBusinessPeersId(System.currentTimeMillis()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!TimeCalculatorUtils.CompareData(businessTrip.getBusinessStartTime(),businessTrip.getBusinessEndTime())){ | 
|---|
|  |  |  | return R.error("结束时间应大于等于开始时间"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (TimeCalculatorUtils.DifferenceYest(businessTrip.getBusinessStartTime(),businessTrip.getBusinessEndTime())!=0){ | 
|---|
|  |  |  | int month = TimeCalculatorUtils.DifferenceMonth(businessTrip.getBusinessStartTime(), businessTrip.getBusinessEndTime()); | 
|---|
|  |  |  | int yest = TimeCalculatorUtils.DifferenceYest(businessTrip.getBusinessStartTime(), businessTrip.getBusinessEndTime()); | 
|---|
|  |  |  | int i = month + yest * 12; | 
|---|
|  |  |  | if (i>12){ | 
|---|
|  |  |  | return R.error("出差时长不可超过一年"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | businessTrip.setBusinessDuration(TimeCalculatorUtils.DifferenceDayMorningAfternoon(businessTrip.getBusinessStartTime(),businessTrip.getBusinessEndTime(),businessTrip.getBusinessStartTimeDay(),businessTrip.getBusinessEndTimeDay())); | 
|---|
|  |  |  | businessTrip.setBusinessTripDays(TimeCalculatorUtils.DifferenceDayInt(businessTrip.getBusinessStartTime(),businessTrip.getBusinessEndTime())); | 
|---|
|  |  |  | businessTrip.setUpdateTime(now); | 
|---|
|  |  |  | businessTrip.setUpdateId(getUserId()); | 
|---|
|  |  |  | businessTripService.updateById(businessTrip); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | 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 = userService.getDeptManager(getHostId(), user.getDeptId()); | 
|---|
|  |  |  | 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.setUpdateId(getUserId()); | 
|---|
|  |  |  | businessTrip.setUpdateTime(now); | 
|---|
|  |  |  | if (!businessTripService.updateById(businessTrip)) { | 
|---|
|  |  |  | throw new CoolException("审核失败,请联系管理员"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return R.error("抱歉,您没有批准的权限!!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("审批成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|