package zy.cloud.wms.manager.controller; import com.alibaba.fastjson.JSONArray; 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 lombok.val; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import zy.cloud.wms.common.web.BaseController; import zy.cloud.wms.manager.entity.*; import zy.cloud.wms.manager.service.*; import java.text.SimpleDateFormat; import java.util.*; @RestController public class ItemController extends BaseController { @Autowired private ItemService itemService; @Autowired private ProjectPlanService planService; @Autowired private FlowStatusService flowStatusService; @Autowired private CstmrService cstmrService; @Autowired private ProjectStatusService projectStatusService; @RequestMapping(value = "/item/{id}/auth") @ManagerAuth public R get(@PathVariable("id") String id) { return R.ok(itemService.selectById(String.valueOf(id))); } @RequestMapping(value = "/item/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(required = false)String condition, @RequestParam Map param){ EntityWrapper wrapper = new EntityWrapper<>(); HashSet excludeField = new HashSet<>(); allLike(Item.class, param.keySet(), wrapper, condition); // allLike(Item.class,excludeField,wrapper, (String) param.get("id")); excludeTrash(param); convert(param, wrapper); hostEq(wrapper); // wrapper.orderBy("status",true); wrapper.orderBy("id",false); if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} return R.ok(itemService.selectPage(new Page<>(curr, limit), wrapper)); } private void convert(Map map, EntityWrapper wrapper){ 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 { wrapper.like(entry.getKey(), val); } } } @RequestMapping(value = "/item/list/chaoPirce") @ManagerAuth public R list1(@RequestParam(defaultValue = "1")Integer curr, @RequestParam(defaultValue = "10")Integer limit, @RequestParam(required = false)String orderByField, @RequestParam(required = false)String orderByType, @RequestParam Map param){ val id = param.get("id"); String uuid=null; if(id!=null){ uuid = id.toString(); } Page projectPlanPage = itemService.chaoPirce(toPage(curr,limit,param,Item.class),uuid); return R.ok(projectPlanPage); } @RequestMapping(value = "/item/list/chaoTime") @ManagerAuth public R list2(@RequestParam(defaultValue = "1")Integer curr, @RequestParam(defaultValue = "10")Integer limit, @RequestParam(required = false)String orderByField, @RequestParam(required = false)String orderByType, @RequestParam Map param){ val id = param.get("id"); String uuid=null; if(id!=null){ uuid = id.toString(); } Page projectPlanPage = itemService.chaoTime(toPage(curr,limit,param,Item.class),uuid); return R.ok(projectPlanPage); } @RequestMapping(value = "/item/add/auth") @ManagerAuth public R add(Item item) { /** * 控管 */ if (Cools.isEmpty(item)) { return R.error("参数为空,请联系管理员"); } //item.setType("1"); // if (!item.getType().equals("1")) { // throw new CoolException("目前仅支持集成项目"); // } Item name = itemService.selectOne(new EntityWrapper() .eq("name", item.getName())); if (!Cools.isEmpty(name)) { throw new CoolException("不可有重复项目名"); } if (item.getRealMonth() < 0){ throw new CoolException("实施周期不可为负数"); } if (Cools.isEmpty(item.getCstmrUuid())) { throw new CoolException("请选择客户"); } Cstmr cstmr = cstmrService.selectOne(new EntityWrapper() .eq("id",Long.parseLong(item.getUuid()))); if (Cools.isEmpty(cstmr)) { throw new CoolException("找不到该客户,请检查"); } item.setCustMan(cstmr.getName()); item.setCustMobile(cstmr.getTel()); item.setCustAdress(cstmr.getAddr()); item.setHostId(getHostId()); item.setCreateBy(getUserId()); item.setCreateTime(new Date()); item.setStatus(1); item.setUpdateBy(getUserId()); item.setUpdateTime(new Date()); itemService.insertAll(item); return R.ok(); } @RequestMapping(value = "/item/update/auth") @ManagerAuth public R update(Item item){ EntityWrapper wapper = new EntityWrapper(); Item newitem = itemService.selectOne(wapper.eq("id", item.getId())); if (Cools.isEmpty(item)) { return R.error("参数为空,请联系管理员"); } // item.setType("1"); // if (!item.getType().equals("1")) { // throw new CoolException("目前仅支持集成项目"); // } // item.setRealMonth(1); // if (item.getRealMonth() < 0){ // throw new CoolException("实施周期不可为负数"); // } if(!(newitem.getStartTime()==null || newitem.getEndTime()==null || newitem.getRealStartTime()==null || newitem.getRealEndTime()==null)){ item.setStartTime(newitem.getStartTime()); item.setEndTime(newitem.getEndTime()); item.setRealEndTime(newitem.getRealEndTime()); item.setRealStartTime(newitem.getRealStartTime()); } //超出运费 if(item.getPlandeAmt()!=null && item.getRealdeAmt()!=null){ item.setExcessAmount(item.getRealdeAmt()-item.getPlandeAmt()); } //超出天数 if(item.getRealinDate()!=null && item.getPlaninDate()!=null){ Double days = (double) ((item.getRealinDate().getTime() - item.getPlaninDate().getTime()) / (1000*3600*24)); Integer day= (int) Math.ceil(days); item.setExcessTime(day); } item.setUpdateBy(getUserId()); item.setUpdateTime(new Date()); itemService.update(item,new EntityWrapper() .eq("id",item.getId())); // itemService.updateById(item); return R.ok(); } @RequestMapping(value = "/item/delete/auth") @ManagerAuth public R delete(@RequestParam("ids[]") String param){ // if (param != null){ // itemService.delete(new EntityWrapper() // .eq("id",param)); // planService.delete(new EntityWrapper() // .eq("item_id",param)); // } if (param != null){ String[] split = param.split(","); for (String s : split) { Item item = itemService.selectOne(new EntityWrapper() .eq("id", s)); item.setStatus(2); itemService.update(item,new EntityWrapper() .eq("id",item.getId())); } } return R.ok(); } @RequestMapping(value = "/item/export/auth") @ManagerAuth public R export(@RequestBody JSONObject param){ EntityWrapper wrapper = new EntityWrapper<>(); hostEq(wrapper); List fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); Map map = excludeTrash(param.getJSONObject("item")); convert(map, wrapper); List list = itemService.selectList(wrapper); return R.ok(exportSupport(list, fields)); } @RequestMapping(value = "/itemQuery/auth") @ManagerAuth public R query(String condition) { EntityWrapper wrapper = new EntityWrapper<>(); wrapper.like("uuid", condition); hostEq(wrapper); Page page = itemService.selectPage(new Page<>(0, 10), wrapper); List> result = new ArrayList<>(); for (Item item : page.getRecords()){ Map map = new HashMap<>(); map.put("id", item.getUuid()); map.put("value", item.getUuid()); result.add(map); } return R.ok(result); } @RequestMapping(value = "/item/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 != itemService.selectOne(wrapper)){ return R.parse(BaseRes.REPEAT).add(getComment(Item.class, String.valueOf(param.get("key")))); } return R.ok(); } /** * 初始化生成项目节点 * @param param * @return */ @RequestMapping(value = "/item/initPlan/auth") @ManagerAuth public R initPlan(@RequestParam("id") String param){ if (param != null){ List projectPlans = planService.selectList(new EntityWrapper().eq("item_id",param)); if(!Cools.isEmpty(projectPlans) && projectPlans.size()>0){ return R.error("该项目已有节点计划"); } List flowStatuses = flowStatusService.selectList(new EntityWrapper()); if(!Cools.isEmpty(flowStatuses) && flowStatuses.size()>0){ for(FlowStatus flowStatus : flowStatuses){ ProjectPlan projectPlan = new ProjectPlan(); projectPlan.setItemId(Long.parseLong(param)); projectPlan.setWeightNum(flowStatus.getWeightNum()); projectPlan.setFlowId(flowStatus.getId()); planService.insert(projectPlan); } } else { return R.error("项目计划节点基础数据为空"); } } else { return R.error("项目参数错误"); } return R.ok(); } @RequestMapping(value = "/progressRate/auth") @ManagerAuth public R queryProgressRate(String condition) { List> result = new ArrayList<>(); List projectStatuses = projectStatusService.selectList(null); for (ProjectStatus projectStatus : projectStatuses) { Map map = new HashMap<>(); map.put("id", projectStatus.getId()); map.put("value", projectStatus.getStatusName()); result.add(map); } return R.ok(result); } }