| | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.core.common.DateUtils; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import zy.cloud.wms.manager.entity.*; |
| | | import zy.cloud.wms.manager.entity.dto.PutShelfDTO; |
| | | import zy.cloud.wms.manager.service.*; |
| | | 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 zy.cloud.wms.common.web.BaseController; |
| | | 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.ReceiveDetl; |
| | | import zy.cloud.wms.manager.service.ReceiveDetlService; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | @RestController |
| | | public class ReceiveDetlController extends BaseController { |
| | | |
| | | @Autowired |
| | | private ReceiveDetlService receiveDetlService; |
| | | @Autowired |
| | | private LocDetlService locDetlService; |
| | | @Autowired |
| | | private NodeService nodeService; |
| | | @Autowired |
| | | private ReceiveLogService receiveLogService; |
| | | @Autowired |
| | | private ReceiveService receiveService; |
| | | |
| | | @RequestMapping(value = "/receiveDetl/{id}/auth") |
| | | @ManagerAuth |
| | |
| | | return R.ok(receiveDetlService.selectById(String.valueOf(id))); |
| | | } |
| | | |
| | | @RequestMapping(value = "/receiveDetl/list/auth") |
| | | @RequestMapping(value ="/receiveDetl/list/auth") |
| | | @ManagerAuth |
| | | public R list(@RequestParam(defaultValue = "1")Integer curr, |
| | | @RequestParam(defaultValue = "10")Integer limit, |
| | |
| | | @RequestParam(required = false)String orderByType, |
| | | @RequestParam Map<String, Object> param){ |
| | | EntityWrapper<ReceiveDetl> wrapper = new EntityWrapper<>(); |
| | | param.values(); |
| | | excludeTrash(param); |
| | | convert(param, wrapper); |
| | | hostEq(wrapper); |
| | | if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} |
| | | return R.ok(receiveDetlService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | return R.ok(receiveDetlService.selectPage(new Page<>(curr, limit), wrapper.orderBy("id",false))); |
| | | } |
| | | |
| | | private void convert(Map<String, Object> map, EntityWrapper wrapper){ |
| | |
| | | wrapper.ge(entry.getKey(), DateUtils.convert(dates[0])); |
| | | wrapper.le(entry.getKey(), DateUtils.convert(dates[1])); |
| | | } else { |
| | | wrapper.eq(entry.getKey(), val); |
| | | wrapper.like(entry.getKey(), val); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | @RequestMapping(value = "/receiveDetl/delete/auth") |
| | | @ManagerAuth |
| | | public R delete(@RequestParam String param){ |
| | | List<ReceiveDetl> list = JSONArray.parseArray(param, ReceiveDetl.class); |
| | | if (Cools.isEmpty(list)){ |
| | | return R.error(); |
| | | } |
| | | for (ReceiveDetl entity : list){ |
| | | receiveDetlService.delete(new EntityWrapper<>(entity)); |
| | | public R delete(@RequestParam(value="ids[]") Long[] ids){ |
| | | for (Long id : ids){ |
| | | receiveDetlService.deleteById(id); |
| | | } |
| | | return R.ok(); |
| | | } |
| | |
| | | @ManagerAuth |
| | | public R export(@RequestBody JSONObject param){ |
| | | EntityWrapper<ReceiveDetl> wrapper = new EntityWrapper<>(); |
| | | hostEq(wrapper); |
| | | List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); |
| | | Map<String, Object> map = excludeTrash(param.getJSONObject("orderDetl")); |
| | | Map<String, Object> map = excludeTrash(param.getJSONObject("receiveDetl")); |
| | | convert(map, wrapper); |
| | | List<ReceiveDetl> list = receiveDetlService.selectList(wrapper); |
| | | return R.ok(exportSupport(list, fields)); |
| | |
| | | public R query(String condition) { |
| | | EntityWrapper<ReceiveDetl> wrapper = new EntityWrapper<>(); |
| | | wrapper.like("id", condition); |
| | | hostEq(wrapper); |
| | | Page<ReceiveDetl> page = receiveDetlService.selectPage(new Page<>(0, 10), wrapper); |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | for (ReceiveDetl receiveDetl : page.getRecords()){ |
| | |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 上架动作,插入库存明细,更新单据明细 |
| | | * @param putShelfDTO |
| | | * @return |
| | | */ |
| | | @RequestMapping("/receiveDetl/addIn") |
| | | @ManagerAuth |
| | | public R addIn(@RequestBody PutShelfDTO putShelfDTO){ |
| | | /** |
| | | * 控管与数据初始化 |
| | | */ |
| | | if (Cools.isEmpty(putShelfDTO.getId(),putShelfDTO.getRemain(),putShelfDTO.getSelect())){ |
| | | return R.error("输入数据有误,请重新输入"); |
| | | } |
| | | Date date = new Date(); |
| | | double remain = Double.parseDouble(putShelfDTO.getRemain()); |
| | | double anfme = Double.parseDouble(putShelfDTO.getAnfme()); |
| | | double inQty = Double.parseDouble(putShelfDTO.getInQty()); |
| | | if (anfme - (remain + inQty) < 0){ |
| | | return R.error("本次入库数量大于所需入库数量"); |
| | | } |
| | | Node targetLoc = nodeService.selectOne(new EntityWrapper<Node>() |
| | | .eq("id", putShelfDTO.getSelect())); |
| | | /** |
| | | * 更新库存 |
| | | */ |
| | | LocDetl checkLoc = locDetlService.selectOne(new EntityWrapper<LocDetl>() |
| | | .eq("loc_no", targetLoc.getName()) |
| | | .eq("matnr", putShelfDTO.getMatnr()) |
| | | .eq("batch", putShelfDTO.getBatch())); |
| | | if (Cools.isEmpty(checkLoc)) { |
| | | LocDetl locDetl = new LocDetl(); |
| | | locDetl.setHostId(getHostId()); |
| | | locDetl.setLocNo(targetLoc.getName()); |
| | | locDetl.setNodeId(targetLoc.getId()); |
| | | locDetl.setAnfme(remain); |
| | | locDetl.setMatnr(putShelfDTO.getMatnr()); |
| | | locDetl.setMaktx(putShelfDTO.getMaktx()); |
| | | locDetl.setCreateBy(getUserId()); |
| | | locDetl.setCreateTime(date); |
| | | locDetl.setUpdateBy(getUserId()); |
| | | locDetl.setUpdateTime(date); |
| | | locDetl.setBatch(putShelfDTO.getBatch()); |
| | | locDetlService.insert(locDetl); |
| | | }else { |
| | | checkLoc.setAnfme(checkLoc.getAnfme() + remain); |
| | | locDetlService.update(checkLoc,new EntityWrapper<LocDetl>() |
| | | .eq("loc_no", targetLoc.getName()) |
| | | .eq("matnr", putShelfDTO.getMatnr()) |
| | | .eq("batch", putShelfDTO.getBatch())); |
| | | } |
| | | |
| | | /** |
| | | * 反写订单数量 |
| | | */ |
| | | |
| | | ReceiveDetl targetRece = receiveDetlService.selectOne(new EntityWrapper<ReceiveDetl>() |
| | | .eq("id", putShelfDTO.getId())); |
| | | targetRece.setInQty((targetRece.getInQty() + remain)); |
| | | receiveDetlService.update(targetRece,new EntityWrapper<ReceiveDetl>() |
| | | .eq("id",targetRece.getId())); |
| | | /** |
| | | * 反写订单状态 |
| | | */ |
| | | if(!Cools.isEmpty(putShelfDTO.getOrderNo())){ |
| | | List<ReceiveDetl> list = receiveDetlService.selectList(new EntityWrapper<ReceiveDetl>().eq("order_no",putShelfDTO.getOrderNo())); |
| | | boolean flag = true; |
| | | |
| | | if(list.size()>0){ |
| | | for (ReceiveDetl receiveDetl : list){ |
| | | if(receiveDetl.getInQty() < receiveDetl.getCount()){ |
| | | flag = false; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if(flag){ |
| | | Receive receive = receiveService.selectOne(new EntityWrapper<Receive>().eq("order_no",putShelfDTO.getOrderNo())); |
| | | receive.setSettle(Long.valueOf(4)); |
| | | receiveService.updateById(receive); |
| | | } |
| | | // ReceiveDetl receiveDetl = receiveDetlService.selectOne(new EntityWrapper<ReceiveDetl>().eq("order_no",putShelfDTO.getOrderNo()).eq("matnr",putShelfDTO.getMatnr())); |
| | | // for(int i=0;i<list.size();i++){ |
| | | // if(list.get(i).getMatnr().equals(receiveDetl.getMatnr())){ |
| | | // if(list.get(i).getInQty()>=list.get(i).getCount()){ |
| | | // Receive receive = receiveService.selectOne(new EntityWrapper<Receive>().eq("order_no",putShelfDTO.getOrderNo())); |
| | | // receive.setSettle(Long.valueOf(4)); |
| | | // receiveService.updateById(receive); |
| | | // break; |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | } |
| | | /** |
| | | * 上架完成之后,存放数据至上架统计表 man_receive_log |
| | | */ |
| | | ReceiveLog receiveLog = new ReceiveLog(); |
| | | receiveLog.setOrderNo(putShelfDTO.getOrderNo()); |
| | | receiveLog.setNodeId(targetLoc.getId()); |
| | | receiveLog.setNodeName(targetLoc.getName()); |
| | | receiveLog.setMatnr(putShelfDTO.getMatnr()); |
| | | receiveLog.setAnfme(remain); |
| | | receiveLog.setBatch(putShelfDTO.getBatch()); |
| | | receiveLog.setCreateBy(getUserId()); |
| | | receiveLog.setUpdateBy(getUserId()); |
| | | receiveLog.setIoType(1); |
| | | receiveLogService.insert(receiveLog); |
| | | return R.ok("添加成功"); |
| | | } |
| | | |
| | | /** |
| | | * 撤销上架操作 |
| | | */ |
| | | @RequestMapping("/receiveDetl/renew/auth") |
| | | @ManagerAuth |
| | | @Transactional |
| | | public R renew(@RequestBody ReceiveDetl receiveDetl){ |
| | | /** |
| | | * 控管 |
| | | */ |
| | | if (receiveDetl.getInQty() <= 0){ |
| | | return R.error("没有上架记录,无法撤回"); |
| | | } |
| | | Receive receive = receiveService.selectOne(new EntityWrapper<Receive>() |
| | | .eq("id", receiveDetl.getOrderId())); |
| | | if (Cools.isEmpty(receive)) { |
| | | return R.error("找不到该单据,请联系管理员"); |
| | | } |
| | | if (receive.getSettle() == 4){ |
| | | return R.error("该单据已经完结"); |
| | | } |
| | | |
| | | /** |
| | | * 修改库存数量,同时撤回上架完成后,将操作记录反写回上架统计表 man_receive_log |
| | | */ |
| | | List<ReceiveLog> receiveLogs = receiveLogService.selectList(new EntityWrapper<ReceiveLog>() |
| | | .eq("order_no", receiveDetl.getOrderNo()) |
| | | .eq("matnr", receiveDetl.getMatnr()) |
| | | .eq("batch", receiveDetl.getBatch()) |
| | | .eq("io_type", 1)); |
| | | if (Cools.isEmpty(receiveLogs)) { |
| | | return R.error("找不到入库记录"); |
| | | } |
| | | for (ReceiveLog receiveLog : receiveLogs) { |
| | | locDetlService.delete(new EntityWrapper<LocDetl>() |
| | | .eq("loc_no",receiveLog.getNodeName()) |
| | | .eq("matnr",receiveLog.getMatnr()) |
| | | .eq("batch",receiveLog.getBatch())); |
| | | receiveLog.setIoType(101); |
| | | receiveLog.setCreateBy(getUserId()); |
| | | receiveLog.setUpdateBy(getUserId()); |
| | | receiveLogService.insert(receiveLog); |
| | | } |
| | | |
| | | /** |
| | | * 反写回入库档 |
| | | */ |
| | | receiveDetl.setInQty(0.0); |
| | | receiveDetl.setUpdateTime(new Date()); |
| | | receiveDetl.setUpdateBy(getUserId()); |
| | | receiveDetlService.update(receiveDetl,new EntityWrapper<ReceiveDetl>() |
| | | .eq("id",receiveDetl.getId())); |
| | | return R.ok("撤回成功"); |
| | | } |
| | | |
| | | } |