package com.zy.ints.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 com.zy.asrs.entity.LocDetl; import com.zy.asrs.entity.LocMast; import com.zy.asrs.entity.MatCode; import com.zy.asrs.service.LocDetlService; import com.zy.asrs.service.LocMastService; import com.zy.asrs.service.MatCodeService; import com.zy.common.web.BaseController; import com.zy.ints.entity.WaitMatchk; import com.zy.ints.service.WaitMatchkLogService; import com.zy.ints.service.WaitMatchkService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import java.util.*; @RestController public class WaitMatchkController extends BaseController { @Autowired private WaitMatchkService waitMatchkService; @Autowired private WaitMatchkLogService waitMatchkLogService; @Autowired private LocMastService locMastService; @Autowired private LocDetlService locDetlService; @Autowired private MatCodeService matCodeService; //盘点通知档 @RequestMapping(value = "/waitMatchk/{id}/auth") @ManagerAuth public R get(@PathVariable("id") String id) { return R.ok(waitMatchkService.selectById(String.valueOf(id))); } @RequestMapping(value = "/waitMatchk/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<>(); excludeTrash(param); convert(param, wrapper); allLike(WaitMatchk.class, param.keySet(), wrapper, condition); if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} return R.ok(waitMatchkService.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 = "/waitMatchk/add/auth") @ManagerAuth public R add(WaitMatchk waitMatchk) { waitMatchkService.insert(waitMatchk); return R.ok(); } @RequestMapping(value = "/waitMatchk/update/auth") @ManagerAuth public R update(WaitMatchk waitMatchk){ if (Cools.isEmpty(waitMatchk) || null==waitMatchk.getMatNo()){ return R.error(); } waitMatchkService.updateById(waitMatchk); return R.ok(); } /** * 删除盘点通知档,删除前转历史档 * @param param * @return */ @RequestMapping(value = "/waitMatchk/delete/auth") @ManagerAuth @Transactional public R delete(@RequestParam String param){ List list = JSONArray.parseArray(param, WaitMatchk.class); if (Cools.isEmpty(list)){ return R.error(); } for (WaitMatchk entity : list){ boolean res = waitMatchkLogService.save(entity.getBillNo(),entity.getLocNo(),entity.getMatNo()); if(!res){ throw new CoolException("转历史档出错[locNo:"+entity.getLocNo()+"],[matNo:"+entity.getMatNo()+"]"); }else { waitMatchkService.delete(new EntityWrapper<>(entity)); } } return R.ok(); } /** * 审核盘点单据 * @param param * @return */ @RequestMapping(value = "/waitMatchk/verify/auth") @ManagerAuth @Transactional public R verify(@RequestParam String param){ List list = JSONArray.parseArray(param, WaitMatchk.class); if (Cools.isEmpty(list)){ return R.error(); } Date now = new Date(); for (WaitMatchk entity : list){ LocMast locMast = locMastService.selectOne(new EntityWrapper().eq("loc_no",entity.getLocNo())); if(null != locMast && locMast.getLocSts().equals("F")){ Wrapper wrapperDetl = new EntityWrapper().eq("loc_no",entity.getLocNo()).eq("mat_no",entity.getMatNo()); LocDetl locDetl = locDetlService.selectOne(wrapperDetl); if(null != locDetl) {//更新数量,删除明细 if(entity.getCheckQty().equals(0)){ if(!locDetlService.delete(wrapperDetl)){ throw new CoolException("删除数量为0明细出错[locNo:"+locDetl.getLocNo()+"],[matNo:"+locDetl.getMatNo()+"]"); } }else{ if(!entity.getCheckQty().equals(locDetl.getQty())){ //库存数量与盘点数量相同不用更新 locDetl.setQty(entity.getCheckQty()); if(!locDetlService.update(locDetl,wrapperDetl)){ throw new CoolException("更新库存明细出错[locNo:"+locDetl.getLocNo()+"],[matNo:"+locDetl.getMatNo()+"]"); } } } } else {//插入明细 LocDetl one = new LocDetl(); one.setLocNo(entity.getLocNo()); one.setMatNo(entity.getMatNo()); one.setQty(entity.getCheckQty()); one.setModiUser(getUserId()); one.setModiTime(now); one.setAppeUser(getUserId()); one.setAppeTime(now); WaitMatchk waitMatchk = waitMatchkService.selectOne(new EntityWrapper().eq("loc_no",entity.getLocNo())); if(null != waitMatchk){ one.setZpallet(waitMatchk.getZpallet()); } MatCode matCode = matCodeService.selectOne(new EntityWrapper().eq("mat_no",entity.getMatNo())); if(null != matCode) { one.setMatName(matCode.getMatName()); one.setUnit(matCode.getUnit()); one.setSpecs(matCode.getSpecs()); one.setSize(matCode.getSize()); one.setColor(matCode.getColor()); } else { throw new CoolException("新增明细物料编码不存在出错[matNo:"+entity.getMatNo()+"]"); } if(!locDetlService.insert(one)){ throw new CoolException("插入库存明细出错[locNo:"+entity.getLocNo()+"],[matNo:"+entity.getMatNo()+"]"); } } entity.setVerifyStatus(1); entity.setVerifyUser(getUserId()); entity.setModiTime(now); Wrapper wrapper = new EntityWrapper().eq("loc_no",entity.getLocNo()).eq("mat_no",entity.getMatNo()); waitMatchkService.update(entity,wrapper); } else { throw new CoolException("库位非在库状态:" + locMast.getLocNo()); } } return R.ok(); } @RequestMapping(value = "/waitMatchk/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("waitMatchk")); convert(map, wrapper); List list = waitMatchkService.selectList(wrapper); return R.ok(exportSupport(list, fields)); } @RequestMapping(value = "/waitMatchkQuery/auth") @ManagerAuth public R query(String condition) { EntityWrapper wrapper = new EntityWrapper<>(); wrapper.like("mat_no", condition); Page page = waitMatchkService.selectPage(new Page<>(0, 10), wrapper); List> result = new ArrayList<>(); for (WaitMatchk waitMatchk : page.getRecords()){ Map map = new HashMap<>(); map.put("id", waitMatchk.getMatNo()); map.put("value", waitMatchk.getMatNo()); result.add(map); } return R.ok(result); } @RequestMapping(value = "/waitMatchk/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 != waitMatchkService.selectOne(wrapper)){ return R.parse(BaseRes.REPEAT).add(getComment(WaitMatchk.class, String.valueOf(param.get("key")))); } return R.ok(); } }