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.baomidou.mybatisplus.plugins.Page; import com.core.annotations.ManagerAuth; import com.core.common.BaseRes; 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.BusinessTripOther; import com.zy.crm.manager.service.BusinessTripOtherService; 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.*; import java.util.*; @RestController public class BusinessTripOtherController extends BaseController { @Autowired private BusinessTripOtherService businessTripOtherService; @Autowired private UserService userService; @RequestMapping(value = "/businessTripOther/{id}/auth2") @ManagerAuth public R get(@PathVariable("id") String id) { BusinessTripOther businessTripOther = businessTripOtherService.selectById(String.valueOf(id)); assert businessTripOther != null; JSONObject resultObj = JSON.parseObject(JSON.toJSONString(businessTripOther)); // 步骤条相关 resultObj.put("step", businessTripOther.getSettle() == 3 ? 0 : businessTripOther.getSettle() + 1); return R.ok().add(resultObj); } @RequestMapping(value = "/businessTripOther/list/auth") @ManagerAuth public R list(@RequestParam(defaultValue = "1")Integer curr, @RequestParam(defaultValue = "10")Integer limit, @RequestParam(required = false)String orderByField, @RequestParam(required = false)String orderByType, @RequestParam Map param){ EntityWrapper 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(businessTripOtherService.selectPage(new Page<>(curr, limit), wrapper)); } private void convert(Map map, EntityWrapper wrapper){ Long deptId = getDeptId(); boolean signUserId = false; boolean signDeptId = false; boolean signHostId = false; for (Map.Entry entry : map.entrySet()){ if (entry.getKey().equals("dept_id")){ signDeptId = true; if (String.valueOf(entry.getValue()).equals("19")){ signHostId = true; } } } for (Map.Entry 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 = "/businessTripOther/add/auth") @ManagerAuth(memo = "添加出差申请") public R add(BusinessTripOther businessTripOther) { if (Cools.isEmpty(businessTripOther)){ return R.error(); } Date now = new Date(); businessTripOther.setCarNumber("无"); businessTripOther.setKilometers("无"); businessTripOther.setBusinessPeersId(System.currentTimeMillis()); businessTripOther.setBusinessDuration(0.0); businessTripOther.setBusinessTripDays(0); businessTripOther.setUserId(getUserId()); businessTripOther.setDeptId(getDeptId()); businessTripOther.setCreateTime(now); businessTripOther.setUserId(getUserId()); businessTripOther.setUpdateTime(now); businessTripOther.setUpdateId(getUserId()); businessTripOther.setStatus(0); businessTripOther.setSettle(1); User manager = new User(); try{ manager = userService.getDeptManager(getHostId(), getUser().getDeptId()); // 获取部门领导 }catch (Exception e){ manager = getUser(); } businessTripOther.setSettleMsg(JSON.toJSONString(SettleDto.initBusiness(manager,getUser()))); businessTripOtherService.insert(businessTripOther); return R.ok(); } @RequestMapping(value = "/businessTripOther/update/auth") @ManagerAuth(memo = "更新出差申请") public R update(BusinessTripOther businessTripOther){ if (Cools.isEmpty(businessTripOther) || null==businessTripOther.getId()){ return R.error(); } Date now = new Date(); businessTripOther.setUpdateTime(now); businessTripOther.setUpdateId(getUserId()); businessTripOtherService.updateById(businessTripOther); return R.ok(); } @RequestMapping(value = "/businessTripOther/delete/auth") @ManagerAuth(memo = "删除出差申请") public R delete(@RequestParam(value="ids[]") Long[] ids){ for (Long id : ids){ businessTripOtherService.deleteById(id); } return R.ok(); } @RequestMapping(value = "/businessTripOther/export/auth") @ManagerAuth public R export(@RequestBody JSONObject param){ EntityWrapper wrapper = new EntityWrapper<>(); List fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); Map map = excludeTrash(param.getJSONObject("businessTrip")); convert(map, wrapper); List list = businessTripOtherService.selectList(wrapper); return R.ok(exportSupport(list, fields)); } @RequestMapping(value = "/businessTripOtherQuery/auth") @ManagerAuth public R query(String condition) { EntityWrapper wrapper = new EntityWrapper<>(); wrapper.like("id", condition); Page page = businessTripOtherService.selectPage(new Page<>(0, 10), wrapper); List> result = new ArrayList<>(); for (BusinessTripOther businessTripOther : page.getRecords()){ Map map = new HashMap<>(); map.put("id", businessTripOther.getId()); map.put("value", businessTripOther.getId()); result.add(map); } return R.ok(result); } @RequestMapping(value = "/businessTripOther/check/column/auth") @ManagerAuth public R query(@RequestBody JSONObject param) { Wrapper wrapper = new EntityWrapper().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val")); if (null != businessTripOtherService.selectOne(wrapper)){ return R.parse(BaseRes.REPEAT).add(getComment(BusinessTripOther.class, String.valueOf(param.get("key")))); } return R.ok(); } @PostMapping(value = "/businessTripOther/approval/auth") @ManagerAuth public R approvalBusinessTrip(@RequestParam Long planId, @RequestParam(required = false) Long plannerId){ BusinessTripOther businessTripOther = businessTripOtherService.selectById(planId); assert businessTripOther != null; Date now = new Date(); switch (businessTripOther.getSettle()) { case 1: // 本部门经理审核 User user = userService.selectById(businessTripOther.getUserId()); User manager = new User(); try{ manager = userService.getDeptManager(getHostId(), getUser().getDeptId()); // 获取部门领导 }catch (Exception e){ manager = user; } if (manager.getId().equals(getUserId())) { // 修改 settle 步骤数据 List list = JSON.parseArray(businessTripOther.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; } } businessTripOther.setSettleMsg(JSON.toJSONString(list)); // 修改规划单状态 businessTripOther.setSettle(2); // 申请通过 businessTripOther.setStatus(1); businessTripOther.setUpdateId(getUserId()); businessTripOther.setUpdateTime(now); if (!businessTripOtherService.updateById(businessTripOther)) { throw new CoolException("审核失败,请联系管理员"); } } else { return R.error("抱歉,您没有批准的权限!!!"); } break; default: return R.error(); } return R.ok("审批成功"); } }