春风项目四线(合箱线、总装线)
wujian
2024-07-12 d2daac02fbc20980162799fc7bf6b1ca59f5686a
jcdm-main/src/main/java/com/jcdm/main/bs/orderScheduling/controller/BsOrderSchedulingController.java
@@ -1,45 +1,54 @@
package com.jcdm.main.bs.orderScheduling.controller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
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.jcdm.common.annotation.Excel;
import com.jcdm.common.core.domain.R;
import com.jcdm.common.core.domain.entity.SysDictData;
import com.jcdm.common.utils.DictUtils;
import com.jcdm.common.utils.StringUtils;
import com.jcdm.main.bs.orderScheduling.vo.FollowReportVO;
import com.jcdm.main.bs.orderScheduling.vo.LineChartVO;
import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
import com.jcdm.system.service.ISysDictDataService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jcdm.common.annotation.Log;
import com.jcdm.common.core.controller.BaseController;
import com.jcdm.common.core.domain.AjaxResult;
import com.jcdm.common.core.domain.R;
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.StringUtils;
import com.jcdm.common.utils.poi.ExcelUtil;
import com.jcdm.main.bs.orderScheduling.common.Constants;
import com.jcdm.main.bs.orderScheduling.domain.BsOrderScheduling;
import com.jcdm.main.bs.orderScheduling.service.IBsOrderSchedulingService;
import com.jcdm.common.utils.poi.ExcelUtil;
import com.jcdm.common.core.page.TableDataInfo;
import com.jcdm.main.bs.orderScheduling.vo.FollowReportVO;
import com.jcdm.main.bs.orderScheduling.vo.LineChartVO;
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.passingStationCollection.domain.DaPassingStationCollection;
import com.jcdm.main.da.passingStationCollection.domain.ProductNewPassStation;
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;
import com.jcdm.main.om.productionOrde.service.impl.OmProductionOrdeInfoServiceImpl;
import com.jcdm.main.plcserver.conf.OPCElement;
import com.jcdm.main.plcserver.sub.OPCUaSubscription;
import com.jcdm.system.service.ISysDictDataService;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.service.MiloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
/**
 * 订单排产Controller
@@ -57,6 +66,33 @@
    @Resource
    private ISysDictDataService iSysDictDataService;
    @Resource
    private OmProductionOrdeInfoServiceImpl productionOrdeInfoService;
    @Resource
    private DaParamCollectionMapper daParamCollectionService;
    @Resource
    private IDaTileMatchCollectionService daTileMatchCollectionService;
    @Resource
    private ProductNewPassStationService productNewPassStationService;
    @Autowired
    MiloService miloService;
    @Value("${websocketUrl}")
    private String websocketUrl;
    @GetMapping("/forceUpload")
    public void forceUpload() throws Exception {
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP121_ZZ_CODE_CHECK, 1);
        miloService.writeToOpcByte(entity);
    }
    @GetMapping("/websocketUrl")
    public String websocketName() {
        return websocketUrl;
    }
    /**
     * 查询订单排产列表
@@ -168,6 +204,21 @@
        return getDataTable(list);
    }
    @GetMapping("/list3")
    public TableDataInfo list3(BsOrderScheduling bsOrderScheduling)
    {
        startPage();
        List<BsOrderScheduling> list = new ArrayList<>();
        if (StringUtils.isNotEmpty(bsOrderScheduling.getOrderNo())){
            list = bsOrderSchedulingService.selectBsOrderSchedulingPage(bsOrderScheduling);
        }
        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);
    }
    /**
     * 导出订单排产列表
     */
@@ -223,4 +274,137 @@
    {
        return toAjax(bsOrderSchedulingService.deleteBsOrderSchedulingByIds(ids));
    }
    @GetMapping("/getSumData")
    public R getSumData(BsOrderScheduling bsOrderScheduling){
        List<BsOrderScheduling> list = new ArrayList<>();
        int onlineNum = 0;
        int finishNum = 0;
        if (StringUtils.isNotEmpty(bsOrderScheduling.getOrderNo())){
            list = bsOrderSchedulingService.selectBsOrderSchedulingPage(bsOrderScheduling);
            List<BsOrderScheduling> onlineNumList = list.stream().filter(x -> Constants.ORDER_STATUS_ING.equals(x.getProductionStatus())).collect(Collectors.toList());
            if (CollUtil.isNotEmpty(onlineNumList)){
                onlineNum = onlineNumList.size();
            }
            List<BsOrderScheduling> finishNumList = list.stream().filter(x -> Constants.FINISH_PRODUCTION.equals(x.getProductionStatus())).collect(Collectors.toList());
            if (CollUtil.isNotEmpty(finishNumList)){
                finishNum = finishNumList.size();
            }
        }
        List<BsOrderScheduling> collect = list.stream().filter(x -> Constants.UN_QUALIFIED.equals(x.getQualityStatus())).collect(Collectors.toList());
        String unqualified = "0";
        if (CollUtil.isNotEmpty(collect)){
            unqualified = String.valueOf(collect.size());
        }
        SumDataVO vo = new SumDataVO();
        vo.setFinishNum(finishNum);
        vo.setOnlineNum(onlineNum);
        vo.setUnqualified(unqualified);
        return R.ok(vo);
    }
    /**
     * 校验发动机号是否和机型匹配、是否重复扫描、是否超出计划数量
     * @param engineNo 箱体码
     * @param model 机型
     * @return boolean
     */
    @Transactional(rollbackFor = Exception.class)
    @GetMapping("/engineNoIsInModel")
    public R engineNoIsInModel(String engineNo,String model,String orderNo) throws Exception {
        if (StringUtils.isEmpty(engineNo)){
            return R.ok(500,"箱体码为空或已存在,请重试");
        }
        BsOrderScheduling bsOrderScheduling = new BsOrderScheduling();
        bsOrderScheduling.setOrderNo(orderNo);
        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.setLocationCode("OP010");
//        List<DaParamCollection> list = daParamCollectionService.selectDaParamCollectionList(daParamCollection);
//        if (CollUtil.isNotEmpty(list)){
//            return R.ok(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,"超出计划数量,请检查后重试");
            }
        }
        //插入数据
        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();
    }
}