Fancy
2024-07-19 1d27648989e69042db607d14c474d9ea90f86d7b
pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/workOrder/WorkOrderSv.java
@@ -15,6 +15,7 @@
import com.dy.pmsGlobal.pojoPr.PrProductionNode;
import com.dy.pmsGlobal.pojoSta.StaAssemblyWorkHistory;
import com.dy.pmsGlobal.pojoSta.StaAssemblyWorkLast;
import com.dy.pmsGlobal.util.QrCodeConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -32,6 +33,11 @@
    private static final int STATUS_WORK_LAST_LOGOUT = 2;
    private static final int STATUS_REPAIR = 3;
    private static final int STATUS_WASTE = 4;
    private static final String WORK_TYPE_ASSEMBLY = "1";
    private static final String WORK_TYPE_TEST = "2";
    private static final String WORK_TYPE_INSPECTION = "3";
    private static final String WORK_TYPE_REPAIR = "4";
    private static final String USER_PREFIX = "101";
    private static final String STATION_PREFIX = "103";
@@ -155,11 +161,16 @@
        if (workLasts.size() > 0) {
            List<StaAssemblyWorkLast> userStationList = workLasts.stream().filter(item -> userId == item.getUserId()).collect(Collectors.toList());
            if (userStationList.size() == 0) {
                throw new RuntimeException("员工(" + workLasts.get(0).getUserName() + ")编码:" + workLasts.get(0).getUserId() + "已经绑定该工站(" + workLasts.get(0).getStationName() + ")编码:" + workLasts.get(0).getStationId() + ".请先让其解绑");
                //删除工站登录信息
                for (int i = 0; i < workLasts.size(); i++) {
                    logout(workLasts.get(i).getId().toString());
                }
                //throw new RuntimeException("员工(" +userInfo.getName() + ")编码:" + workLasts.get(0).getUserId() + "已经绑定该工站(" + stationInfo.getName() + ")编码:" + workLasts.get(0).getStationId() + ".请先让其解绑");
            } else {
                BeanUtils.copyProperties(userStationList.get(0), result);
            }
        } else {
        }
        if (result.getId() == null) {
            result.setUserId(userInfo.getId());
            result.setUserName(userInfo.getName());
            result.setStationId(stationInfo.getId());
@@ -170,48 +181,56 @@
    }
    public StaAssemblyWorkLast getWorkLast(String workId) {
        if (StringUtils.isBlank(workId)) {
            throw new RuntimeException("登录ID为空,请联系管理员查看并解决问题.");
        }
        StaAssemblyWorkLast result = assemblyWorkLastDao.selectByPrimaryKey(Long.parseLong(workId));
        if (result == null) {
            return null;
            throw new RuntimeException("系统中没有该条登录信息");
            //return null;
        }
        BaUser userInfo = getUserInfo(result.getUserId().toString());
        PltStation stationInfo = getStationInfo(result.getStationId().toString());
        //校验planId processId nodeId
        PrAssemblyPlan assyPlan = assemblyDao.selectByPrimaryKey(result.getPlanId());
        boolean hasNodeId = assyPlan.getProcess().getNodes().stream()
                .anyMatch(node -> node.id.equals(result.getNodeId()));
        if (userInfo == null || stationInfo == null || assyPlan == null || (!hasNodeId)) {
            //直接删除记录
            logout(result.getId().toString());
            result.setId(null);
            if(userInfo == null){
                result.setUserId(null);
                result.setUserName("");
            }
            if(stationInfo == null){
                result.setStationId(null);
                result.setStationName("");
            }
            if(assyPlan == null){
                result.setPlanId(null);
                result.setPlanName("");
            }
            if(!hasNodeId){
                result.setNodeId(null);
                result.setNodeName("");
            }
            return result;
        }else {
            result.setPlanName(assyPlan.getName());
            result.setProcessName(assyPlan.getProcessName());
            result.setNodeName(assyPlan.getProcess().getNodes().get(0).getContent());
            //找到对应的产品信息
            PltProduct  product = productDao.selectByPrimaryKey(assyPlan.getProId());
            if (product != null) {
                result.setProId(product.getId());
                result.setProName(product.getName());
                String devicePrefix = "110" + product.getCode() + assyPlan.getBatchNo();
                result.setDevicePrefix(devicePrefix);
        //如果是维修work_type 没有 planId processId nodeId
        if (WORK_TYPE_REPAIR.equals(result.getWorkType())) {
            //校验planId processId nodeId
            PrAssemblyPlan assyPlan = assemblyDao.selectByPrimaryKey(result.getPlanId());
            boolean hasNodeId = assyPlan.getProcess().getNodes().stream()
                    .anyMatch(node -> node.id.equals(result.getNodeId()));
            if (userInfo == null || stationInfo == null || assyPlan == null || (!hasNodeId)) {
                //直接删除记录
                logout(result.getId().toString());
                result.setId(null);
                result.setStatus(STATUS_WORK_LAST_LOGOUT);
                if (userInfo == null) {
                    result.setUserId(null);
                    result.setUserName("");
                }
                if (stationInfo == null) {
                    result.setStationId(null);
                    result.setStationName("");
                }
                if (assyPlan == null) {
                    result.setPlanId(null);
                    result.setPlanName("");
                }
                if (!hasNodeId) {
                    result.setNodeId(null);
                    result.setNodeName("");
                }
                return result;
            } else {
                result.setPlanName(assyPlan.getName());
                result.setProcessName(assyPlan.getProcessName());
                result.setNodeName(assyPlan.getProcess().getNodes().get(0).getContent());
                //找到对应的产品信息
                PltProduct product = productDao.selectByPrimaryKey(assyPlan.getProId());
                if (product != null) {
                    result.setProId(product.getId());
                    result.setProName(product.getName());
                    String devicePrefix = QrCodeConstant.TypeProduct + product.getCode() + assyPlan.getBatchNo();
                    result.setDevicePrefix(devicePrefix);
                }
            }
        }
        result.setStationId(stationInfo.getId());
@@ -234,7 +253,7 @@
        param.setStatus(STATUS_NORMAL);
        List<StaAssemblyWorkLast> workLasts = assemblyWorkLastDao.selectList(param);
        if (workLasts.size() > 0) {
            result =  getWorkLast(workLasts.get(0).getId().toString());
            result = getWorkLast(workLasts.get(0).getId().toString());
        }
        result.setStationId(stationInfo.getId());
        result.setStationName(stationInfo.getName());
@@ -292,13 +311,13 @@
        result.setProcessName(assyPlan.getProcessName());
        result.setNodeName(assyPlan.getProcess().getNodes().get(0).getContent());
        //找到对应的产品信息
        PltProduct  product = productDao.selectByPrimaryKey(assyPlan.getProId());
        PltProduct product = productDao.selectByPrimaryKey(assyPlan.getProId());
        if (product == null) {
            throw new RuntimeException("产品信息有误或被其他人员修改,请登录管理系统查看任务关联产品ID为:" + assyPlan.getProId());
        }
        result.setProId(product.getId());
        result.setProName(product.getName());
        String devicePrefix = "110" + product.getCode() + assyPlan.getBatchNo();
        String devicePrefix = QrCodeConstant.TypeProduct + product.getCode() + assyPlan.getBatchNo();
        result.setDevicePrefix(devicePrefix);
        return result;
    }
@@ -316,6 +335,7 @@
        // 保存history
        StaAssemblyWorkHistory history = new StaAssemblyWorkHistory();
        BeanUtils.copyProperties(workLast, history);
        history.setWorkId(workLast.getId());
        //history.setId(null);
        int count = assemblyWorkHistoryDao.insertSelective(history);
        //删除last