春风项目四线(合箱线、总装线)
wujian
2024-10-23 2c65c31aceb16c1d06c692266e3fb555ecafdfb5
jcdm-main/src/main/java/com/jcdm/main/bs/orderScheduling/controller/BsOrderSchedulingController.java
@@ -1,10 +1,12 @@
package com.jcdm.main.bs.orderScheduling.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.github.pagehelper.PageInfo;
import com.jcdm.common.annotation.Log;
import com.jcdm.common.core.controller.BaseController;
import com.jcdm.common.core.domain.AjaxResult;
@@ -12,7 +14,7 @@
import com.jcdm.common.core.domain.entity.SysDictData;
import com.jcdm.common.core.page.TableDataInfo;
import com.jcdm.common.enums.BusinessType;
import com.jcdm.common.utils.SecurityUtils;
import com.jcdm.common.exception.ServiceException;
import com.jcdm.common.utils.StringUtils;
import com.jcdm.common.utils.poi.ExcelUtil;
import com.jcdm.main.bs.orderScheduling.common.Constants;
@@ -23,8 +25,10 @@
import com.jcdm.main.bs.orderScheduling.vo.SumDataVO;
import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
import com.jcdm.main.da.paramCollection.mapper.DaParamCollectionMapper;
import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
import com.jcdm.main.da.passingStationCollection.domain.ProductNewPassStation;
import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
import com.jcdm.main.da.passingStationCollection.service.ProductNewPassStationService;
import com.jcdm.main.da.tileMatchCollection.domain.DaTileMatchCollection;
import com.jcdm.main.da.tileMatchCollection.service.IDaTileMatchCollectionService;
import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
@@ -43,9 +47,7 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -71,6 +73,11 @@
    private DaParamCollectionMapper daParamCollectionService;
    @Resource
    private IDaTileMatchCollectionService daTileMatchCollectionService;
    @Resource
    private ProductNewPassStationService productNewPassStationService;
    @Resource
    private IDaPassingStationCollectionService daPassingStationCollectionService;
    @Autowired
    MiloService miloService;
@@ -149,9 +156,9 @@
            WriteSheet sheet1 = EasyExcel.writerSheet(1, "拧紧数据")
                    .head(DaParamCollection.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
                    .build();
            WriteSheet sheet2 = EasyExcel.writerSheet(2, "相机检测")
                    .head(DaParamCollection.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
                    .build();
//            WriteSheet sheet2 = EasyExcel.writerSheet(2, "相机检测")
//                    .head(DaParamCollection.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
//                    .build();
            WriteSheet sheet3 = EasyExcel.writerSheet(3, "外漏检测")
                    .head(DaParamCollection.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
                    .build();
@@ -163,7 +170,7 @@
                    .build();
            excelWriter.write(followReportList.getMainList(),mainSheet);
            excelWriter.write(followReportList.getList1(),sheet1);
            excelWriter.write(followReportList.getList2(),sheet2);
//            excelWriter.write(followReportList.getList2(),sheet2);
            excelWriter.write(followReportList.getList3(),sheet3);
            excelWriter.write(followReportList.getList4(),sheet4);
            excelWriter.write(followReportList.getList5(),sheet5);
@@ -179,7 +186,6 @@
    /**
     * 查询下线数量
     */
    @PreAuthorize("@ss.hasPermi('bs:orderScheduling:list')")
    @GetMapping("/getOffLineNum")
    public TableDataInfo getOffLineNum(BsOrderScheduling bsOrderScheduling)
    {
@@ -205,14 +211,38 @@
    {
        startPage();
        List<BsOrderScheduling> list = new ArrayList<>();
        long total = 0;
        if (StringUtils.isNotEmpty(bsOrderScheduling.getOrderNo())){
            list = bsOrderSchedulingService.selectBsOrderSchedulingPage(bsOrderScheduling);
            if (CollUtil.isNotEmpty(list)){
                total = new PageInfo(list).getTotal();
                List<String> allEngineNoList = list.stream().map(BsOrderScheduling::getEngineNo).collect(Collectors.toList());
                List<ProductNewPassStation> productPassStationListByEngineList = productNewPassStationService.getProductPassStationListByEngineList(allEngineNoList);
                list.forEach(x -> {
                    if (StrUtil.isNotBlank(x.getWorkingHours())){
                        x.setWorkingHoursInt(Integer.parseInt(x.getWorkingHours()));
                    } else {
                        x.setWorkingHoursInt(0);
                    }
                    if (CollUtil.isNotEmpty(productPassStationListByEngineList)){
                        List<ProductNewPassStation> collect = productPassStationListByEngineList.stream().filter(y -> x.getEngineNo().equals(y.getSfcCode())).collect(Collectors.toList());
                        if (CollUtil.isNotEmpty(collect)){
                            ProductNewPassStation productNewPassStation = collect.get(0);
                            x.setBoxCode(productNewPassStation.getBoxCode());
                        }
                    }
                });
                list = list.stream().sorted(Comparator.comparing(BsOrderScheduling::getWorkingHoursInt)).collect(Collectors.toList());
            }
        }
        List<BsOrderScheduling> collect = list.stream().filter(x -> Constants.UN_QUALIFIED.equals(x.getQualityStatus())).collect(Collectors.toList());
        if (CollUtil.isNotEmpty(collect)){
            String.valueOf(collect.size());
        }
        return getDataTable(list);
//        List<BsOrderScheduling> collect = list.stream().filter(x -> Constants.UN_QUALIFIED.equals(x.getQualityStatus())).collect(Collectors.toList());
//        if (CollUtil.isNotEmpty(collect)){
//            String.valueOf(collect.size());
//        }
        TableDataInfo dataTable = getDataTable(list);
        dataTable.setTotal(total);
        return dataTable;
    }
    /**
@@ -307,83 +337,166 @@
     */
    @Transactional(rollbackFor = Exception.class)
    @GetMapping("/engineNoIsInModel")
    public R engineNoIsInModel(String engineNo,String model,String orderNo) throws Exception {
    public R engineNoIsInModel(String engineNo,String model,String orderNo,Boolean repairFlag) throws Exception {
        if (StringUtils.isEmpty(engineNo)){
            return R.ok(500,"箱体码为空或已存在,请重试");
            return R.fail(500,"箱体码不能为空,请重试");
        }
        BsOrderScheduling bsOrderScheduling = new BsOrderScheduling();
        bsOrderScheduling.setOrderNo(orderNo);
        //bsOrderScheduling.setProductionStatus("1");
        List<BsOrderScheduling> allList = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling);
        List<BsOrderScheduling> dlist = allList.stream().filter(x->x.getProductionStatus().equals(Constants.WAIT_PRODUCTION)).collect(Collectors.toList());
        List<BsOrderScheduling> collect = allList.stream().filter(x -> x.getProductionStatus().equals(Constants.ORDER_STATUS_ING)
                        ||x.getProductionStatus().equals(Constants.FINISH_PRODUCTION)).collect(Collectors.toList());
        BsOrderScheduling OrderScheduling=dlist.get(0);
        DaParamCollection daParamCollection = new DaParamCollection();
        daParamCollection.setParamValue(engineNo);
        daParamCollection.setSfcCode("OP010");
        List<DaParamCollection> list = daParamCollectionService.selectDaParamCollectionList(daParamCollection);
        if (CollUtil.isNotEmpty(list)){
            return R.ok(500,"已存在此箱体码,请勿重复扫描");
        if (!engineNo.contains(",")){
            return R.fail(500,"箱体码格式有误,请重试");
        }
        OmProductionOrdeInfo info = new OmProductionOrdeInfo();
        info.setWorkOrderNo(orderNo);
        List<OmProductionOrdeInfo> omProductionOrdeInfos = productionOrdeInfoService.selectOmProductionOrdeInfoList(info);
        if (CollUtil.isNotEmpty(omProductionOrdeInfos)){
            OmProductionOrdeInfo omProductionOrdeInfo = omProductionOrdeInfos.get(0);
            Long planQty = omProductionOrdeInfo.getPlanQty();
            if (planQty<collect.size()){
                return R.ok(500,"超出计划数量,请检查后重试");
        ProductNewPassStation checkStation = new ProductNewPassStation();
        checkStation.setBoxCode(engineNo);
        List<ProductNewPassStation> checkList = productNewPassStationService.getProductPassStationList(checkStation);
        if (!repairFlag){
            if (CollUtil.isNotEmpty(checkList)){
                return R.fail(500,"请勿重复扫描箱体码");
            }
        }
        //插入数据
        DaParamCollection saveData = new DaParamCollection();
        saveData.setSfcCode(OrderScheduling.getEngineNo());
        saveData.setParamValue(engineNo);
        saveData.setLocationCode("OP010");
        saveData.setParamCode("XTM");
        saveData.setParamName("箱体");
        daParamCollectionService.insertDaParamCollection(saveData);
        DaTileMatchCollection MatchCollection = new DaTileMatchCollection();
        MatchCollection.setSfcCode(OrderScheduling.getEngineNo());
        MatchCollection.setParamValue(engineNo);
        MatchCollection.setLocationCode("OP010");
        MatchCollection.setParamCode("XTM");
        MatchCollection.setParamName("箱体");
        daTileMatchCollectionService.insertDaTileMatchCollection(MatchCollection);
        //更新上线数量
        int onlineNum = 0;
        List<BsOrderScheduling> onlineNumList = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling)
                .stream().filter(x -> Constants.ORDER_STATUS_ING.equals(x.getProductionStatus())||x.getProductionStatus().equals(Constants.FINISH_PRODUCTION)).collect(Collectors.toList());
        if (CollUtil.isNotEmpty(onlineNumList)){
            onlineNum = onlineNumList.size();
        BsOrderScheduling bsOrderScheduling = new BsOrderScheduling();
        bsOrderScheduling.setOrderNo(orderNo);
        List<BsOrderScheduling> allList = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling);
        if (CollUtil.isNotEmpty(allList)){
            allList.forEach(x -> {
                if (StrUtil.isNotBlank(x.getWorkingHours())){
                    x.setWorkingHoursInt(Integer.parseInt(x.getWorkingHours()));
                } else {
                    x.setWorkingHoursInt(0);
                }
            });
            allList = allList.stream().sorted(Comparator.comparing(BsOrderScheduling::getWorkingHoursInt)).collect(Collectors.toList());
        }
        OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo();
        omProductionOrdeInfo.setWorkOrderNo(orderNo);
        List<OmProductionOrdeInfo> omList = productionOrdeInfoService.selectOmProductionOrdeInfoList(omProductionOrdeInfo);
        if (CollUtil.isNotEmpty(omList)){
            OmProductionOrdeInfo omInfo = omList.get(0);
            String s = String.valueOf(onlineNum);
            long l = Long.parseLong(s);
            omInfo.setActualOnlineQty(l);
            productionOrdeInfoService.updateOmProductionOrdeInfo(omInfo);
        List<BsOrderScheduling> dlist = allList.stream().filter(x->x.getProductionStatus().equals(Constants.WAIT_PRODUCTION)).collect(Collectors.toList());
        List<BsOrderScheduling> collect = allList.stream().filter(x -> x.getProductionStatus().equals(Constants.ORDER_STATUS_ING)
                ||x.getProductionStatus().equals(Constants.FINISH_PRODUCTION)).collect(Collectors.toList());
        if (CollUtil.isNotEmpty(checkList)){
            //重复扫码
            ProductNewPassStation productNewPassStation = checkList.get(0);
            String sfcCode = productNewPassStation.getSfcCode();
            DaPassingStationCollection passingStationCollection = new DaPassingStationCollection();
            passingStationCollection.setSfcCode(sfcCode);
            List<DaPassingStationCollection> daPassingStationCollections = daPassingStationCollectionService.selectDaPassingStationCollectionList(passingStationCollection);
            if (CollUtil.isNotEmpty(daPassingStationCollections)){
                //过站后重新上线
                //OPC操作
                logger.info("过站后重新上线,{}",sfcCode);
                ReadWriteEntity entity = new ReadWriteEntity("CFL4HX.OP010.Code", sfcCode);
                OPCUaSubscription.miloService.writeToOpcUa(entity);//写SN
                return R.ok();
            } else {
                //OPC操作
                logger.info("当前站重新扫码,{}",sfcCode);
//                ReadWriteEntity entity3 = new ReadWriteEntity("CFL4HX.OP010.ProductTypeSN",sfcCode);
//                OPCUaSubscription.miloService.writeToOpcUa(entity3);//写产品SN号反馈
                ReadWriteEntity entity = new ReadWriteEntity("CFL4HX.OP010.Code", sfcCode);
                OPCUaSubscription.miloService.writeToOpcUa(entity);//写SN
                return R.ok();
            }
        }else {
            if (CollUtil.isNotEmpty(dlist)){
                BsOrderScheduling OrderScheduling=dlist.get(0);
                OmProductionOrdeInfo info = new OmProductionOrdeInfo();
                info.setWorkOrderNo(orderNo);
                List<OmProductionOrdeInfo> omProductionOrdeInfos = productionOrdeInfoService.selectOmProductionOrdeInfoList(info);
                if (CollUtil.isNotEmpty(omProductionOrdeInfos)){
                    OmProductionOrdeInfo omProductionOrdeInfo = omProductionOrdeInfos.get(0);
                    Long planQty = omProductionOrdeInfo.getPlanQty();
                    if (planQty<collect.size()){
                        return R.fail(500,"超出计划数量,请检查后重试");
                    }
                }
                //插入数据
                DaParamCollection saveData = new DaParamCollection();
                saveData.setSfcCode(OrderScheduling.getEngineNo());
                saveData.setParamValue(engineNo);
                saveData.setLocationCode("OP010");
                saveData.setParamCode("XTM");
                saveData.setParamName("箱体");
                daParamCollectionService.insertDaParamCollection(saveData);
                DaTileMatchCollection MatchCollection = new DaTileMatchCollection();
                MatchCollection.setSfcCode(OrderScheduling.getEngineNo());
                MatchCollection.setParamValue(engineNo);
                MatchCollection.setLocationCode("OP010");
                MatchCollection.setParamCode("XTM");
                MatchCollection.setParamName("箱体");
                daTileMatchCollectionService.insertDaTileMatchCollection(MatchCollection);
                if (StrUtil.isNotBlank(OrderScheduling.getEngineNo())){
                    String snCode = OrderScheduling.getEngineNo();
                    if (snCode.startsWith("280") || snCode.startsWith("380")){
                        ProductNewPassStation productNewPassStation = new ProductNewPassStation();
                        UUID uuid = UUID.randomUUID();
                        productNewPassStation.setId(uuid.getMostSignificantBits());
                        productNewPassStation.setFinishFlag("0");
                        productNewPassStation.setSfcCode(OrderScheduling.getEngineNo());
                        productNewPassStation.setCreateTime(new Date());
                        productNewPassStation.setBoxCode(engineNo);
                        if (snCode.startsWith("280")){
                            productNewPassStation.setProductType("280");
                        } else {
                            productNewPassStation.setProductType("380");
                        }
                        productNewPassStationService.insertPassStation(productNewPassStation);
                    }
                }
                //更新上线数量
                int onlineNum = 0;
                List<BsOrderScheduling> onlineNumList = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling)
                        .stream().filter(x -> Constants.ORDER_STATUS_ING.equals(x.getProductionStatus())||x.getProductionStatus().equals(Constants.FINISH_PRODUCTION)).collect(Collectors.toList());
                if (CollUtil.isNotEmpty(onlineNumList)){
                    onlineNum = onlineNumList.size();
                }
                OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo();
                omProductionOrdeInfo.setWorkOrderNo(orderNo);
                List<OmProductionOrdeInfo> omList = productionOrdeInfoService.selectOmProductionOrdeInfoList(omProductionOrdeInfo);
                if (CollUtil.isNotEmpty(omList)){
                    OmProductionOrdeInfo omInfo = omList.get(0);
                    String s = String.valueOf(onlineNum);
                    long l = Long.parseLong(s);
                    omInfo.setActualOnlineQty(l);
                    productionOrdeInfoService.updateOmProductionOrdeInfo(omInfo);
                }
                //OPC操作
                ReadWriteEntity entity = new ReadWriteEntity("CFL4HX.OP010.Code", OrderScheduling.getEngineNo());
                OPCUaSubscription.miloService.writeToOpcUa(entity);//写SN
                OrderScheduling.setProductionStatus("2");
                bsOrderSchedulingService.updateBsOrderScheduling(OrderScheduling);
                return R.ok();
            } else {
                return R.fail(500,"超出计划数量,请检查后重试");
            }
        }
        //OPC操作
        ReadWriteEntity entity = new ReadWriteEntity("CFL4HX.HOP010.Code", OrderScheduling.getEngineNo());
        OPCUaSubscription.miloService.writeToOpcUa(entity);//写SN
        ReadWriteEntity entity2 = new ReadWriteEntity("CFL4HX.HOP010.SNDoor", 1);
        OPCUaSubscription.miloService.writeToOpcByte(entity2);//写完成
    }
        OrderScheduling.setProductionStatus("2");
        bsOrderSchedulingService.updateBsOrderScheduling(OrderScheduling);
        return R.ok();
    @GetMapping("/changeBoxCode")
    public R changeBoxCode(String sfcCode,String newBoxCode){
        if (StringUtils.isEmpty(newBoxCode)){
            return R.fail(500,"箱体码不能为空,请重试");
        }
        if (StringUtils.isEmpty(sfcCode)){
            return R.fail(500,"发动机号不能为空,请重试");
        }
        if (!newBoxCode.contains(",")){
            return R.fail(500,"箱体码格式有误,请重试");
        }
        ProductNewPassStation checkStation = new ProductNewPassStation();
        checkStation.setSfcCode(sfcCode);
        List<ProductNewPassStation> productPassStationList = productNewPassStationService.getProductPassStationList(checkStation);
        if (CollUtil.isNotEmpty(productPassStationList)){
            productNewPassStationService.updateBoxCodeBySfcCode(sfcCode, newBoxCode);
            return R.ok();
        } else {
            return R.fail("未查找到该发动机号对应的箱体");
        }
    }
}