自动化立体仓库 - WMS系统
zyx
2024-01-15 35309c86535d392d593471236585b4b36fb417d6
src/main/java/com/zy/asrs/controller/PlaController.java
@@ -1,19 +1,32 @@
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.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.entity.PlaExcel;
import com.zy.common.web.BaseController;
import lombok.Synchronized;
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 javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -22,6 +35,16 @@
    @Autowired
    private PlaService plaService;
    @Autowired
    private PlaQtyService plaQtyService;
    @Autowired
    private ManPakOutService manPakOutService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderDetlService orderDetlService;
    @Autowired
    private PlaLogService plaLogService;
    @RequestMapping(value = "/pla/list/auth")
    @ManagerAuth
@@ -32,6 +55,7 @@
        excludeTrash(param);
        EntityWrapper<Pla> wrapper = new EntityWrapper<>();
        convert(param, wrapper);
        wrapper.orderBy("pakin_time",false);
        allLike(Pla.class, param.keySet(), wrapper, condition);
        return R.ok(plaService.selectPage(new Page<>(curr, limit), wrapper));
    }
@@ -51,9 +75,157 @@
    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());
            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)){
                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());
            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){
            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.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);
        };
        //修改单据信息
        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.getBatch()+","+pla.getPackageNo(),anfme,getUser().getUsername());
        });
        return R.ok();
    }
    /**
     * 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){
            throw new CoolException("导入的数据格式错误,原因:" + e.getMessage());
        }
        return R.ok("成功同步"+listener.getTotal()+"条pla物料数据");
    }
    private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){
@@ -63,10 +235,36 @@
                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){
        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.setNodeId(plaQty.getOrderDetlId());
        manPakOutService.insert(manPakOut);
        return R.ok();
    }
}