| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.R; |
| | | import com.zy.asrs.entity.Pla; |
| | | import com.zy.asrs.service.PlaService; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.GlobleParameter; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.utils.PlaExcelListener; |
| | | import com.zy.asrs.utils.SaasUtils; |
| | | import com.zy.common.CodeRes; |
| | | import com.zy.common.entity.PlaExcel; |
| | | import com.zy.common.web.BaseController; |
| | | import lombok.Synchronized; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.util.*; |
| | | |
| | | @RestController |
| | | @Slf4j |
| | | public class PlaController extends BaseController { |
| | | |
| | | @Autowired |
| | | private PlaService plaService; |
| | | @Autowired |
| | | private PlaQtyService plaQtyService; |
| | | @Autowired |
| | | private ManPakOutService manPakOutService; |
| | | @Autowired |
| | | private OrderService orderService; |
| | | @Autowired |
| | | private OrderDetlService orderDetlService; |
| | | @Autowired |
| | | private PlaLogService plaLogService; |
| | | @Autowired |
| | | private MatService matService; |
| | | |
| | | @RequestMapping(value = "/pla/list/auth") |
| | | @ManagerAuth |
| | |
| | | @RequestParam Map<String, Object> param){ |
| | | excludeTrash(param); |
| | | EntityWrapper<Pla> wrapper = new EntityWrapper<>(); |
| | | |
| | | if(!Cools.isEmpty(param.get("brand"))){ |
| | | wrapper.eq("brand",param.get("brand")); |
| | | param.remove("brand"); |
| | | } |
| | | // 没有选择的时候默认不显示已出库的物料 |
| | | if (Cools.isEmpty(param.get("status"))) { |
| | | wrapper.ne("status", "全部出库"); |
| | | } |
| | | |
| | | |
| | | convert(param, wrapper); |
| | | wrapper.orderBy("batch",true).orderBy("package_no" ,true); |
| | | allLike(Pla.class, param.keySet(), wrapper, condition); |
| | | return R.ok(plaService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | } |
| | |
| | | public R update(@RequestBody List<Pla> plas) { |
| | | System.out.println(plas.toString()); |
| | | plas.forEach(pla -> { |
| | | Pla plaSave = plaService.selectById(pla.getId()); |
| | | pla.setModifyTime(new Date()); |
| | | plaService.updateById(pla); |
| | | |
| | | PlaLog plaLog = new PlaLog(); |
| | | BeanUtils.copyProperties(plaSave,plaLog); |
| | | plaLog.setId(null); |
| | | plaLog.setCreateTime(new Date()); |
| | | plaLog.setModifyUser(getUser().getUsername()); |
| | | plaLogService.insert(plaLog); |
| | | |
| | | }); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/pla/delete/auth") |
| | | @ManagerAuth |
| | | public R delete(@RequestBody List<Pla> plas) { |
| | | System.out.println(plas.toString()); |
| | | plas.forEach(pla -> { |
| | | if(!pla.getStatus().equals(GlobleParameter.PLA_STATUS_00) && !pla.getStatus().equals(GlobleParameter.PLA_STATUS_0) && !pla.getStatus().equals(GlobleParameter.PLA_STATUS_1)){ |
| | | throw new CoolException("已入库的数据无法被删除"); |
| | | } |
| | | Pla plaSave = plaService.selectById(pla.getId()); |
| | | pla.setModifyTime(new Date()); |
| | | plaService.deleteById(pla.getId()); |
| | | |
| | | PlaLog plaLog = new PlaLog(); |
| | | BeanUtils.copyProperties(plaSave,plaLog); |
| | | plaLog.setId(null); |
| | | plaLog.setCreateTime(new Date()); |
| | | plaLog.setModifyUser(getUser().getUsername()); |
| | | plaLogService.insert(plaLog); |
| | | |
| | | }); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/pla/delivery/auth") |
| | | @ManagerAuth |
| | | public R delivery() { |
| | | return R.ok(plaQtyService.getDeliveryDate()); |
| | | } |
| | | |
| | | @RequestMapping(value = "/pla/sellout/auth") |
| | | @ManagerAuth |
| | | @Transactional |
| | | @Synchronized |
| | | public R sellout(@RequestBody List<Pla> plas) { |
| | | |
| | | String orderNo = plas.get(0).getOrderNo(); |
| | | String maktx = plas.get(0).getBrand(); |
| | | Double allOrderWeight = 0.0; |
| | | Order order = orderService.selectByNo(orderNo); |
| | | OrderDetl orderDetl = orderDetlService.selectByOrderNoAndMaktx(orderNo, maktx); |
| | | |
| | | for (Pla pla : plas){ |
| | | |
| | | if(pla.getStockFreeze() == 0){ |
| | | throw new CoolException("库存已被冻结,请重新选择库存"); |
| | | } |
| | | |
| | | allOrderWeight += pla.getOrderWeight(); |
| | | |
| | | if(pla.getWeightAnfme() - pla.getQtyAnfme() - pla.getOrderWeight() < 0){ |
| | | throw new CoolException("批号:" + pla.getBatch() +",包号:" + pla.getPackageNo() +" 剩余可出库重量不足,请调整出库重量"); |
| | | } |
| | | pla.setQtyAnfme(pla.getQtyAnfme() + pla.getOrderWeight()); |
| | | pla.setHandlerBy(getUser().getUsername()); |
| | | pla.setStatus(GlobleParameter.PLA_STATUS_2); |
| | | pla.setModifyTime(new Date()); |
| | | pla.setPakoutTime(pla.getPakoutTime().split("\\(")[0]); |
| | | //生成此次作业信息 |
| | | PlaQty plaQty = new PlaQty(); |
| | | BeanUtils.copyProperties(pla,plaQty); |
| | | plaQty.setCreateTime(new Date()); |
| | | plaQty.setId(null); |
| | | plaQty.setTransfer(order.getDocType$()); |
| | | plaQty.setOrderDetlId(orderDetl.getId()); |
| | | plaService.updateById(pla); |
| | | plaQtyService.insert(plaQty); |
| | | //生成拣货单 |
| | | addPakOUT(plaQty,getUserId()); |
| | | |
| | | }; |
| | | |
| | | //修改单据信息 |
| | | if(orderDetl.getAnfme()-orderDetl.getWorkQty()-allOrderWeight < 0){ |
| | | throw new CoolException("该订单出库数量大于订单待出数量,请重新选择出库数量"); |
| | | } |
| | | if(order.getStatus() < 2){ |
| | | orderService.updateSettle(order.getId(),2L,getUserId()); |
| | | } |
| | | |
| | | orderDetl.setWorkQty(orderDetl.getWorkQty() + allOrderWeight); |
| | | orderDetlService.updateById(orderDetl); |
| | | |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/pla/returned/auth") |
| | | @ManagerAuth |
| | | public R returned(@RequestBody List<PlaQty> plaQties) { |
| | | plaService.returned(plaQties,getUser()); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/pla/viladate/auth") |
| | | @ManagerAuth |
| | | public R viladate(@RequestBody List<Pla> plas) { |
| | | plaService.viladate(plas,getUser()); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/pla/rework/auth") |
| | | @ManagerAuth |
| | | public R rework(@RequestBody List<Pla> plas) { |
| | | plas.forEach(pla -> { |
| | | Double anfme = pla.getWeightAnfme(); |
| | | pla.setStatus("全部出库"); |
| | | pla.setModifyTime(new Date()); |
| | | pla.setWeightAnfme(0.0); |
| | | plaService.updateById(pla); |
| | | SaasUtils.insertLog(1,pla.getLocNo(),pla.getBrand(),anfme,getUser().getUsername(), |
| | | null,pla.getBatch(),pla.getPackageNo(),pla.getOwner(),pla.getWorkshop()); |
| | | }); |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/pla/updateStockFreeze") |
| | | @Transactional |
| | | @ManagerAuth(memo = "库位冻结") |
| | | public R updateStockFreeze(@RequestBody List<Pla> plas){ |
| | | if (Cools.isEmpty(plas)){ |
| | | return R.error("无数据"); |
| | | } |
| | | for (Pla pla : plas){ |
| | | if (pla.getStockFreeze() == 0){ |
| | | throw new CoolException("库存已被冻结!"); |
| | | } |
| | | pla.setStockFreeze(0); |
| | | pla.setStockFreezeBy(getUser().getUsername()); |
| | | pla.setStockFreezeDate(new Date()); |
| | | pla.setModifyTime(new Date()); |
| | | plaService.updateById(pla); |
| | | } |
| | | return R.ok("冻结成功"); |
| | | } |
| | | |
| | | @RequestMapping(value = "/pla/updateStockDisFreeze") |
| | | @ManagerAuth(memo = "库位解冻") |
| | | public R updateStockDisFreeze(@RequestBody List<Pla> plas){ |
| | | if (Cools.isEmpty(plas)){ |
| | | return R.error("无数据"); |
| | | } |
| | | for (Pla pla : plas){ |
| | | if (pla.getStockFreeze() == 1){ |
| | | throw new CoolException("库位未冻结,无需解冻"); |
| | | } |
| | | if(!Cools.eq(pla.getStockFreezeBy(),getUser().getUsername())){ |
| | | throw new CoolException("无法解冻其他用户冻结的库位"); |
| | | } |
| | | pla.setStockFreeze(1); |
| | | pla.setStockFreezeBy(getUser().getUsername()); |
| | | pla.setStockFreezeDate(new Date()); |
| | | pla.setModifyTime(new Date()); |
| | | plaService.updateById(pla); |
| | | |
| | | } |
| | | return R.ok("解除冻结成功"); |
| | | } |
| | | |
| | | @RequestMapping(value = "/matMaktxQuery/auth") |
| | | @ManagerAuth |
| | | public R queryMat(String condition) { |
| | | EntityWrapper<Mat> wrapper = new EntityWrapper<>(); |
| | | wrapper.like("maktx", condition); |
| | | Page<Mat> page = matService.selectPage(new Page<>(0, 10), wrapper); |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | for (Mat mat : page.getRecords()){ |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("id", mat.getMaktx()); |
| | | map.put("value", mat.getMaktx()); |
| | | result.add(map); |
| | | } |
| | | return R.ok(result); |
| | | } |
| | | |
| | | @RequestMapping(value = "/pla/statis/auth") |
| | | @ManagerAuth |
| | | public R statis(@RequestParam(defaultValue = "1")Integer curr, |
| | | @RequestParam(defaultValue = "10")Integer limit, |
| | | @RequestParam Map<String, Object> param) { |
| | | |
| | | Page<Pla> stockStatis = plaService.getStockStatisAll(toPage(curr, limit, param, Pla.class)); |
| | | |
| | | return R.ok().add(stockStatis); |
| | | } |
| | | |
| | | /** |
| | | * excel导入模板下载 |
| | | */ |
| | | @RequestMapping(value = "/pla/excel/import/mould") |
| | | public void plaExcelImportMould(HttpServletResponse response) throws IOException { |
| | | List<PlaExcel> excels = new ArrayList<>(); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | String fileName = URLEncoder.encode("聚乳酸Excel导入模板", "UTF-8"); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); |
| | | EasyExcel.write(response.getOutputStream(), PlaExcel.class) |
| | | .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) |
| | | .sheet("sheet1") |
| | | .doWrite(excels); |
| | | } |
| | | |
| | | // excel导入 |
| | | @PostMapping(value = "/pla/excel/import/auth") |
| | | @ManagerAuth(memo = "pla档案数据导入") |
| | | @Transactional |
| | | public R matExcelImport(MultipartFile file) throws IOException { |
| | | PlaExcelListener listener = new PlaExcelListener(getUserId()); |
| | | try { |
| | | EasyExcel.read(file.getInputStream(), PlaExcel.class, listener).sheet().doRead(); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | int index = listener.getIndex() - 1; |
| | | throw new CoolException("导入的数据格式错误,原因:" + e.getMessage() + ",第" + index + ",数据格式不对"); |
| | | } |
| | | log.info("导入修改信息输出:" + listener.getRecordLog()); |
| | | return R.ok("成功同步"+listener.getTotal()+"条pla物料数据"); |
| | | } |
| | | |
| | | // 打印 |
| | | @RequestMapping(value = "/pla/print/auth") |
| | | @ManagerAuth(memo = "pla编码打印") |
| | | public R matCodePrint(@RequestBody List<Pla> plas) { |
| | | if(Cools.isEmpty(plas)) { |
| | | return R.parse(CodeRes.EMPTY); |
| | | } |
| | | List<Pla> res = new ArrayList<>(); |
| | | for (Pla pla : plas){ |
| | | res.add(pla); |
| | | } |
| | | return R.ok().add(res); |
| | | } |
| | | |
| | | private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){ |
| | | for (Map.Entry<String, Object> entry : map.entrySet()){ |
| | |
| | | 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().contains("Min")){ |
| | | wrapper.ge(entry.getKey().substring(0,entry.getKey().length()-3),val); |
| | | }else if (entry.getKey().contains("Max")){ |
| | | wrapper.le(entry.getKey().substring(0,entry.getKey().length()-3),val); |
| | | } else { |
| | | wrapper.like(entry.getKey(), val); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private R addPakOUT(PlaQty plaQty,Long userId){ |
| | | ManPakOut manPakOut=new ManPakOut(); |
| | | manPakOut.setWrkNo(plaQty.getOrderNo()+"-"+System.currentTimeMillis()); |
| | | manPakOut.setWrkSts((long)1); |
| | | manPakOut.setAnfme(plaQty.getOrderWeight()); |
| | | manPakOut.setMaktx(plaQty.getBrand()); |
| | | manPakOut.setLocNo(plaQty.getLocNo()); |
| | | manPakOut.setBatch(plaQty.getBatch()); |
| | | manPakOut.setBarcode(plaQty.getPackageNo() + ""); |
| | | manPakOut.setUuid(String.valueOf(System.currentTimeMillis())); |
| | | manPakOut.setCreateTime(new Date()); |
| | | manPakOut.setUpdateTime(new Date()); |
| | | manPakOut.setCount(0.0); |
| | | manPakOut.setDocNum(plaQty.getOrderNo()); |
| | | manPakOut.setStatus(0); |
| | | manPakOut.setDocId(plaQty.getOrderDetlId()); |
| | | manPakOut.setNodeId(plaQty.getId()); |
| | | manPakOut.setCustName(plaQty.getCustomer()); |
| | | manPakOut.setCreateBy(userId); |
| | | //预计发货时间 |
| | | manPakOut.setSpecs(plaQty.getPakoutTime()); |
| | | //manPakOut.setNodeId(plaQty.getOrderDetlId()); |
| | | manPakOutService.insert(manPakOut); |
| | | return R.ok(); |
| | | } |
| | | |
| | | } |