自动化立体仓库 - WMS系统
zyh
23 小时以前 701542ac0a90cf0e3a0a81ec2bb8066b5de68e75
src/main/java/com/zy/asrs/service/impl/DigitalTwinServiceImpl.java
@@ -1,20 +1,29 @@
package com.zy.asrs.service.impl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.common.R;
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.mapper.LocDetlMapper;
import com.zy.asrs.mapper.LocMastMapper;
import com.zy.asrs.service.BasCrnpService;
import com.zy.asrs.service.DigitalTwinService;
import com.zy.asrs.service.LocDetlService;
import com.zy.asrs.service.LocMastService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@Service
@@ -24,6 +33,12 @@
    private DigitalTwinMapper digitalTwinMapper;
    @Resource
    private LocCountMapper locCountMapper;
    @Resource
    private LocMastMapper locMastMapper;
    @Resource
    private LocDetlMapper locDetlMapper;
    @Resource
    private LocMastService locMastService;
    /**
     * 总览:总库位、已用库位、剩余库位、今日出库、今日入库、剩余库位
@@ -57,21 +72,49 @@
     */
    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;
            try {
                // 尝试解析yyyyMMdd格式
                if (startDate.length() == 8 && endDate.length() == 8) {
                    sdf = new SimpleDateFormat("yyyyMMdd");
                    startTime = sdf.parse(startDate);
                    endTime = sdf.parse(endDate);
                    // 设置结束时间为当天的23:59:59.999
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(endTime);
                    calendar.set(Calendar.HOUR_OF_DAY, 23);
                    calendar.set(Calendar.MINUTE, 59);
                    calendar.set(Calendar.SECOND, 59);
                    calendar.set(Calendar.MILLISECOND, 999);
                    endTime = calendar.getTime();
                } else {
                    // 尝试解析yyyy-MM-dd HH:mm:ss.SSS格式
                    sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
                    startTime = sdf.parse(startDate);
                    endTime = sdf.parse(endDate);
                }
            } catch (ParseException e) {
                e.printStackTrace();
                // 解析失败时使用默认的7天时间范围
                Date now = new Date();
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(now);
                calendar.add(Calendar.DAY_OF_MONTH, -7);
                startTime = calendar.getTime();
                endTime = now;
            }
        }
        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,31 +134,59 @@
     */
    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;
            try {
                // 尝试解析yyyyMMdd格式
                if (startDate.length() == 8 && endDate.length() == 8) {
                    sdf = new SimpleDateFormat("yyyyMMdd");
                    startTime = sdf.parse(startDate);
                    endTime = sdf.parse(endDate);
                    // 设置结束时间为当天的23:59:59.999
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(endTime);
                    calendar.set(Calendar.HOUR_OF_DAY, 23);
                    calendar.set(Calendar.MINUTE, 59);
                    calendar.set(Calendar.SECOND, 59);
                    calendar.set(Calendar.MILLISECOND, 999);
                    endTime = calendar.getTime();
                } else {
                    // 尝试解析yyyy-MM-dd HH:mm:ss.SSS格式
                    sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
                    startTime = sdf.parse(startDate);
                    endTime = sdf.parse(endDate);
                }
            } catch (ParseException e) {
                e.printStackTrace();
                // 解析失败时使用默认的7天时间范围
                Date now = new Date();
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(now);
                calendar.add(Calendar.DAY_OF_MONTH, -7);
                startTime = calendar.getTime();
                endTime = now;
            }
        }
        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;
    }
    /**
     * 近期近期呆滞品信息,默认超过30天为呆滞品
     *
@@ -123,9 +194,10 @@
     * @param overDayNum
     * @param pageIndex
     * @param pageSize
     * @param condition 搜索条件
     * @return
     */
    public List<DtDetainMatVo> recentDetainMat(String areaId, Integer overDayNum, Integer pageIndex, Integer pageSize) {
    public List<DtDetainMatVo> recentDetainMat(String areaId, Integer overDayNum, Integer pageIndex, Integer pageSize, String condition) {
        overDayNum = overDayNum == null ? 30 : overDayNum;
        pageIndex = pageIndex == null ? 1 : pageIndex;
@@ -136,10 +208,10 @@
        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");
        String startTime = sdf.format(start);*/
        List<DtDetainMatVo> dbDetainMats = digitalTwinMapper.recentDetainMat(areaId, startTime, pageIndex, pageSize);
        List<DtDetainMatVo> dbDetainMats = digitalTwinMapper.recentDetainMat(areaId, start, pageIndex, pageSize);
        return dbDetainMats;
    }
@@ -151,31 +223,15 @@
     * @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());
    }
    /**
@@ -201,13 +257,13 @@
            endDate = sdf.format(now);
            startDate = sdf.format(start);
        }
        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();
@@ -226,30 +282,33 @@
     * 定期统计剩余库存
     *
     */
    @Transactional
    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("D").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();
    }
@@ -270,5 +329,50 @@
    // 输送线拍照、称重
    // endregion
    @Resource
    private LocDetlService locDetlService;
    @Override
    public List<AllLocationsVo> getAllLocations() {
        List<AllLocationsVo> allLocationsVos = new ArrayList<>();
        List<LocMast> locMastList = locMastService.selectList(new EntityWrapper<>());
        locMastList.forEach(locMast -> {
            AllLocationsVo allLocationsVo = new AllLocationsVo();
            allLocationsVo.setLocNo(locMast.getLocNo());
            String locSts = locMast.getLocSts();
            allLocationsVo.setLocSts(locSts);
            // 有库存
            if (locSts.equals("F") || locSts.equals("P") || locSts.equals("Q") || locSts.equals("R")) {
                List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", locMast.getLocNo()));
                if (!locDetls.isEmpty()) {
                    List<AllLocationsVo.LocDetl> locDetlList = locDetls.stream().map(locDetl -> {
                                AllLocationsVo.LocDetl locDetl1 = new AllLocationsVo.LocDetl();
                                BeanUtils.copyProperties(locDetl, locDetl1);
                                return locDetl1;
                            }
                    ).collect(Collectors.toList());
                    allLocationsVo.setLocDetls(locDetlList);
                }
            }
            allLocationsVos.add(allLocationsVo);
        });
        return allLocationsVos;
    }
    public List<Map<String, Object>> getLocalDetal() {
        List<LocDetl> locDetls = locDetlMapper.selectList(new EntityWrapper<>());
        List<Map<String, Object>> result = new ArrayList<>();
        for (LocDetl locDetl : locDetls) {
            Map<String, Object> item = new HashMap<>();
            item.put("zpallet", locDetl.getZpallet());
            item.put("anfme", locDetl.getAnfme());
            item.put("matnr", locDetl.getMatnr());
            item.put("maktx", locDetl.getMaktx());
            result.add(item);
        }
        return result;
    }
}