自动化立体仓库 - WMS系统
zyh
1 天以前 3eee2147f220634b620b7ed84c97fbd8257205d5
src/main/java/com/zy/asrs/service/impl/DigitalTwinServiceImpl.java
@@ -1,15 +1,22 @@
package com.zy.asrs.service.impl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.zy.asrs.entity.BasCrnp;
import com.zy.asrs.entity.LocCount;
import com.zy.asrs.entity.LocDetl;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.entity.digitaltwin.*;
import com.zy.asrs.mapper.DigitalTwinMapper;
import com.zy.asrs.mapper.LocCountMapper;
import com.zy.asrs.service.BasCrnpService;
import com.zy.asrs.service.DigitalTwinService;
import com.zy.asrs.service.LocMastService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
@@ -57,21 +64,27 @@
     */
    public List<DtOrderVo> order(String startDate, String endDate) {
        String startTime;
        String endTime;
        Date startTime = new Date();
        Date endTime = new Date();
        if (startDate == null || endDate == null || startDate.isEmpty() || endDate.isEmpty()){
            Date now = new Date();
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(now);
            calendar.add(Calendar.DAY_OF_MONTH, -7);
            Date start = calendar.getTime();
            startTime = calendar.getTime();
            endTime = now;
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            endDate = sdf.format(now);
            startDate = sdf.format(start);
        } else {
            SimpleDateFormat sdf =
                    new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            try {
                startTime  = sdf.parse(startDate);
                endTime = sdf.parse(endDate);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        startTime = startDate.substring(0, 4) + "-" + startDate.substring(4, 6) + "-" + startDate.substring(6, 8) + "00:00:00";
        endTime = endDate.substring(0, 4) + "-" + endDate.substring(4, 6) + "-" + endDate.substring(6, 8) + "00:00:00";
        List<DtOrderVo> dbOrder = digitalTwinMapper.recentOrder(startTime, endTime);
        // 空日期补全
        for (DtOrderVo dtOrderVo : dbOrder) {
@@ -91,27 +104,34 @@
     */
    public List<DtInAndOutBoundVo> inAndOutBound(String areaId, String startDate, String endDate) {
        List<DtInAndOutBoundVo> dtInAndOutBoundVos = new ArrayList<>();
        String startTime;
        String endTime;
        Date startTime = new Date();
        Date endTime = new Date();
        if (startDate == null || endDate == null || startDate.isEmpty() || endDate.isEmpty()){
            Date now = new Date();
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(now);
            calendar.add(Calendar.DAY_OF_MONTH, -7);
            Date start = calendar.getTime();
            startTime = calendar.getTime();
            endTime = now;
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            endDate = sdf.format(now);
            startDate = sdf.format(start);
        } else {
            SimpleDateFormat sdf =
                    new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            try {
                startTime  = sdf.parse(startDate);
                endTime = sdf.parse(endDate);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        startTime = startDate.substring(0, 4) + "-" + startDate.substring(4, 6) + "-" + startDate.substring(6, 8) + "00:00:00";
        endTime = endDate.substring(0, 4) + "-" + endDate.substring(4, 6) + "-" + endDate.substring(6, 8) + "00:00:00";
        List<DtInAndOutBoundVo> dtInBoundVos = digitalTwinMapper.recentInBound(areaId, startTime, endTime);
        List<DtInAndOutBoundVo> dtOutBoundVos = digitalTwinMapper.recentOutBound(areaId, startTime, endTime);
        // 格式整理
        List<DtInAndOutBoundVo> dtInAndOutBoundVos = new ArrayList<>(dtInBoundVos);
        dtInAndOutBoundVos.addAll(dtOutBoundVos);
        return dtInAndOutBoundVos;
    }
@@ -136,13 +156,14 @@
        calendar.setTime(now);
        calendar.add(Calendar.DAY_OF_MONTH, -overDayNum);
        Date start = calendar.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String startTime = sdf.format(start);
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        Date startTime = sdf.parse(start);
        List<DtDetainMatVo> dbDetainMats = digitalTwinMapper.recentDetainMat(areaId, startTime, pageIndex, pageSize);
        return dbDetainMats;
        return digitalTwinMapper.recentDetainMat(areaId, start, pageIndex, pageSize);
    }
    @Resource
    private LocMastService locMastService;
    /**
     * 查询库存和库位详细信息
@@ -151,31 +172,39 @@
     * @return
     */
    public List<DtLocDetailVo> warehouseDetail(String areaId) {
        List<DtLocDetailVo> locDetailVos = new ArrayList<>();
        List<LocMast> locMasts = new ArrayList<>();
        List<LocDetl> locDetls = new ArrayList<>();
        for (LocMast locMast : locMasts) {
            DtLocDetailVo dtLocDetailVo = new DtLocDetailVo();
            dtLocDetailVo.setLocMast(locMast);
            dtLocDetailVo.setLocNo(locMast.getLocNo());
            dtLocDetailVo.setLocSts(locMast.getLocSts());
            dtLocDetailVo.setRow1(locMast.getRow1());
            dtLocDetailVo.setBay1(locMast.getBay1());
            dtLocDetailVo.setLev1(locMast.getLev1());
            for (LocDetl locDetl : locDetls) {
                List<LocDetl> locDetl1 = locDetls.parallelStream().filter(a -> a.getLocNo().equals(locDetl.getLocNo())).collect(Collectors.toList());
                if (locDetl1 != null && locDetl1.size() == 1) {
                    dtLocDetailVo.setLocDetl(locDetl1.get(0));
                    dtLocDetailVo.setAreaId(locDetl.getAreaId());
                    dtLocDetailVo.setAreaName(locDetl.getAreaName());
                }
            }
            locDetailVos.add(dtLocDetailVo);
        }
        return locDetailVos;
        List<LocMast> locMastList = locMastService.selectList(new EntityWrapper<>());
        return locMastList.stream()
                .map(loc -> {
                    DtLocDetailVo vo = new DtLocDetailVo();
                    BeanUtils.copyProperties(loc, vo);
                    return vo;
                })
                .collect(Collectors.toList());
//        List<DtLocDetailVo> locDetailVos = new ArrayList<>();
//
//        List<LocMast> locMasts = new ArrayList<>();
//        List<LocDetl> locDetls = new ArrayList<>();
//
//        for (LocMast locMast : locMasts) {
//            DtLocDetailVo dtLocDetailVo = new DtLocDetailVo();
//            dtLocDetailVo.setLocMast(locMast);
//            dtLocDetailVo.setLocNo(locMast.getLocNo());
//            dtLocDetailVo.setLocSts(locMast.getLocSts());
//            dtLocDetailVo.setRow1(locMast.getRow1());
//            dtLocDetailVo.setBay1(locMast.getBay1());
//            dtLocDetailVo.setLev1(locMast.getLev1());
//            for (LocDetl locDetl : locDetls) {
//                List<LocDetl> locDetl1 = locDetls.parallelStream().filter(a -> a.getLocNo().equals(locDetl.getLocNo())).collect(Collectors.toList());
//                if (locDetl1 != null && locDetl1.size() == 1) {
//                    dtLocDetailVo.setLocDetl(locDetl1.get(0));
//                    dtLocDetailVo.setAreaId(locDetl.getAreaId());
//                    dtLocDetailVo.setAreaName(locDetl.getAreaName());
//                }
//            }
//            locDetailVos.add(dtLocDetailVo);
//        }
//
//        return locDetailVos;
    }
    /**
@@ -203,11 +232,11 @@
        }
        List<LocCount> locCounts;
        if(areaId.isEmpty()){
            locCounts = locCountMapper.getByDate(Integer.parseInt(startDate), Integer.parseInt(endDate));
        } else {
            locCounts = locCountMapper.getByAreaAndDate(areaId, Integer.parseInt(startDate), Integer.parseInt(endDate));
        }
//        if(areaId.isEmpty()){
        locCounts = locCountMapper.getByDate(Integer.parseInt(startDate), Integer.parseInt(endDate));
//        } else {
//            locCounts = locCountMapper.getByAreaAndDate(areaId, Integer.parseInt(startDate), Integer.parseInt(endDate));
//        }
        for (LocCount locCount : locCounts) {
            String date = locCount.getDate().toString();
@@ -227,29 +256,30 @@
     *
     */
    public void locNumCount() {
        List<LocCount> result = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String date = sdf.format(new Date());
        List<LocCount> totalLoc = locCountMapper.totalLoc();
        List<LocCount> useLoc = locCountMapper.useLoc();
        for (LocCount locCount : totalLoc) {
            LocCount locCount1 = new LocCount();
            locCount1.setDate(Integer.valueOf(date));
            locCount1.setAreaId(locCount.getAreaId());
            locCount1.setLocNum(locCount1.getLocNum());
            for (LocCount locCount2 : useLoc) {
                if(locCount1.getAreaId().equals(locCount2.getAreaId())){
                    locCount1.setRemainNum(locCount1.getLocNum() - locCount2.getLocNum());
                }
            }
            result.add(locCount1);
        }
        for (LocCount locCount  : result) {
            locCountMapper.insertOrUpdate(locCount);
        }
        LocCount locCount1 = new LocCount();
        locCount1.setDate(Integer.valueOf(date));
        locCount1.setLocNum(totalLoc.get(0).getLocNum());
        locCount1.setRemainNum(locCount1.getLocNum() - useLoc.get(0).getLocNum());
        locCountMapper.insertOrUpdate(locCount1);
    }
    @Resource
    private BasCrnpService basCrnpService;
    @Override
    public DtEquipmentVo equipment(String areaId) {
        BasCrnp crnp = basCrnpService.selectOne(new EntityWrapper<>());
        return DtEquipmentVo.builder()
                .equipmentId("1").equipmentName("堆垛机1").equipmentType(1)
                .belongAreaId("C").belongAreaName("联结器库").verticalSpeed(Integer.valueOf(Cools.isEmpty(crnp.getCtlHp()) ? "0" : crnp.getCtlHp()))
                .horizontalSpeed(Integer.valueOf( Cools.isEmpty(crnp.getCtlRest()) ? "0" : crnp.getCtlRest())).voltage(220).status(crnp.getCrnErr() == 0 ? 1 : 3).operateMethod(crnp.getCrnSts() == 3 ? 1 : 3).build();
    }