skyouc
2025-05-28 b7b3328fdfa45cf13d1943fa79d47f1b6bb43f01
添加定时任务用户
12个文件已修改
1个文件已添加
541 ■■■■ 已修改文件
rsf-server/src/main/java/com/vincent/rsf/server/api/service/MobileService.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/WcsServiceImpl.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
rsf-server/src/main/java/com/vincent/rsf/server/api/utils/LocUtils.java 260 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
rsf-server/src/main/java/com/vincent/rsf/server/common/config/ConfigProperties.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
rsf-server/src/main/java/com/vincent/rsf/server/manager/controller/LocItemController.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
rsf-server/src/main/java/com/vincent/rsf/server/manager/entity/Task.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskSchedules.java 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/LocItemService.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocItemServiceImpl.java 40 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java 104 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaitPakinServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
rsf-server/src/main/java/com/vincent/rsf/server/system/utils/SystemAuthUtils.java 75 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
rsf-server/src/main/resources/application.yml 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
rsf-server/src/main/java/com/vincent/rsf/server/api/service/MobileService.java
@@ -40,7 +40,6 @@
    WaitPakin mergeItems(WaitPakinParam waitPakin, Long userId);
    WaitPakin unBind(WaitPakinParam param);
    R inspect(String code, Long loginUserId);
rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/WcsServiceImpl.java
@@ -414,10 +414,10 @@
                List<LocItem> locItems = locItemService.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getMatnrCode, matnr));
                for (LocItem locItem : locItems) {
                    Loc loc1 = locService.getById(locItem.getLocId());
                    if (LocUtils.isShallowLoc(slaveProperties, loc1.getCode())) {
                    if (LocUtils.isShallowLoc(loc1.getCode())) {
                        continue;
                    }
                    String shallowLocNo = LocUtils.getShallowLoc(slaveProperties, loc1.getCode());
                    String shallowLocNo = LocUtils.getShallowLoc(loc1.getCode());
                    // 检测目标库位是否为空库位
                    Loc shallowLoc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, shallowLocNo));
                    if (shallowLoc != null && shallowLoc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_O.type)) {
@@ -488,7 +488,7 @@
                if (!LocUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) {
                    continue;
                }
                String shallowLoc = LocUtils.getDeepLoc(slaveProperties, locMast1.getCode());
                String shallowLoc = LocUtils.getDeepLoc(locMast1.getCode());
                if ((ioType == 1 && deviceBind.getBeSimilar().equals("1"))) {
                    //相似物料打开,判断深库位有没有货,没货就放深库位,有货就不操作
                    Loc locMast2 = locService.getOne(new LambdaQueryWrapper<Loc>()
@@ -529,7 +529,7 @@
                        continue;
                    }
                    if (deviceBind.getBeSimilar().equals("1")) {
                        String shallowLoc = LocUtils.getDeepLoc(slaveProperties, locMast1.getCode());
                        String shallowLoc = LocUtils.getDeepLoc(locMast1.getCode());
                        Loc locMast2 = locService.getOne(new LambdaQueryWrapper<Loc>()
                                .eq(Loc::getCode, shallowLoc)
                                .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
rsf-server/src/main/java/com/vincent/rsf/server/api/utils/LocUtils.java
@@ -10,6 +10,7 @@
import com.vincent.rsf.server.api.entity.dto.LocTypeDto;
import com.vincent.rsf.server.manager.entity.*;
import com.vincent.rsf.server.manager.enums.LocStsType;
import com.vincent.rsf.server.manager.enums.TaskStsType;
import com.vincent.rsf.server.manager.enums.TaskType;
import com.vincent.rsf.server.manager.service.*;
import org.slf4j.Logger;
@@ -45,11 +46,11 @@
    /**
     * 获取 浅库位对应的深库位号
     */
    public static String getDeepLoc(SlaveProperties slaveProperties, String shallowLoc) {
    public static String getDeepLoc(String shallowLoc) {
        LocService locService = SpringUtils.getBean(LocService.class);
        Loc shaLoc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, shallowLoc));
        int row = shaLoc.getRow()-1;
        boolean contains = slaveProperties.getDoubleLocs().contains(row);
        boolean contains = doubleLocs.contains(row);
        Loc deepLoc = null;
        if (contains) {
            deepLoc = locService.getOne(new LambdaQueryWrapper<Loc>()
@@ -72,7 +73,7 @@
    /**
     * 获取 深库位对应的浅库位号
     */
    public static String getShallowLoc(SlaveProperties slaveProperties, String deepLoc) {
    public static String getShallowLoc(String deepLoc) {
        LocService locService = SpringUtils.getBean(LocService.class);
        Loc depLoc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, deepLoc));
        int row;
@@ -81,7 +82,7 @@
        } else {
            row = depLoc.getRow();
        }
        boolean contains = slaveProperties.getDoubleLocs().contains(row);
        boolean contains = doubleLocs.contains(row);
        Loc shallowLoc = null;
        if (!contains) {
            shallowLoc = locService.getOne(new LambdaQueryWrapper<Loc>()
@@ -104,10 +105,10 @@
    /**
     * 判断是否为浅库位
     */
    public static boolean isShallowLoc(SlaveProperties slaveProperties, String locNo) {
        if (slaveProperties.isDoubleDeep()) {
    public static boolean isShallowLoc(String locNo) {
        if (isDoubleDeep) {
            int row = getRow(locNo);
            return !slaveProperties.getDoubleLocs().contains(row);
            return !doubleLocs.contains(row);
        } else {
            return false;
        }
@@ -213,8 +214,8 @@
    }
    public static String  getCrnLoc() {
        SlaveProperties bean = SpringUtils.getBean(SlaveProperties.class);
        System.out.println(bean.getDoubleLocs());
//        SlaveProperties bean = SpringUtils.getBean(SlaveProperties.class);
        System.out.println(doubleLocs);
        return null;
    }
@@ -233,4 +234,245 @@
            return msgBuilder.toString();
        }
    }
    /**
     * 获取堆垛机库位信息
     * @param deviceBind
     * @param area
     * @param sourceStaNo
     * @param matnr
     * @param batch
     * @param locTypeDto
     * @param times
     * @param ioType 作业类型(*必传参数)
     * @return
     */
    public static InTaskMsgDto getLocNoCrn(DeviceBind deviceBind, Long area, Integer sourceStaNo, String matnr, String batch, LocTypeDto locTypeDto, int times, Integer ioType) {
        DeviceBindService deviceBindService = SpringUtils.getBean(DeviceBindService.class);
        DeviceSiteService deviceSiteService = SpringUtils.getBean(DeviceSiteService.class);
        LocService locService = SpringUtils.getBean(LocService.class);
        LocItemService locItemService = SpringUtils.getBean(LocItemService.class);
        if (Cools.isEmpty(matnr)) {  //物料号
            matnr = "";
        }
        if (Cools.isEmpty(batch)) {  //批次
            batch = "";
        }
        // 初始化参数
        int channel = 0;      //堆垛机号
        int nearRow = 0;    //最浅库位排
        int curRow = 0;     //最深库位排
        int rowCount = 0;   //轮询轮次
        Loc loc = null;     // 目标库位
        InTaskMsgDto inTaskMsgDto = new InTaskMsgDto();
        int sRow = deviceBind.getStartRow();
        int eRow = deviceBind.getEndRow();
        int deviceQty = deviceBind.getDeviceQty();
        // ===============>>>> 开始执行
        curRow = deviceBind.getCurrentRow();
        //此程序用于优化堆垛机异常时的运行时间
        for (int i = times; i <= deviceQty * 2; i++) {
            int[] locNecessaryParameters = LocUtils.LocNecessaryParameters(deviceBind, curRow, deviceQty);
            curRow = locNecessaryParameters[1];
            channel = locNecessaryParameters[2];
            rowCount = locNecessaryParameters[0];
            nearRow = locNecessaryParameters[3];
            break;
        }
        if (nearRow == 0) {
            throw new CoolException("无可用堆垛机");
        }
        //入库靠近摆放
        if (ioType == 1 && deviceBind.getBeSimilar().equals("1") && !Cools.isEmpty(matnr)) {
            if (nearRow != curRow) {
                List<LocItem> locItems = locItemService.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getMatnrCode, matnr));
                for (LocItem locItem : locItems) {
                    Loc loc1 = locService.getById(locItem.getLocId());
                    if (LocUtils.isShallowLoc(loc1.getCode())) {
                        continue;
                    }
                    String shallowLocNo = LocUtils.getShallowLoc(loc1.getCode());
                    // 检测目标库位是否为空库位
                    Loc shallowLoc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, shallowLocNo));
                    if (shallowLoc != null && shallowLoc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_O.type)) {
                        if (LocUtils.locMoveCheckLocTypeComplete(shallowLoc, locTypeDto)) {
                            loc = shallowLoc;
                            channel = shallowLoc.getChannel();
                            break;
                        }
                    }
                }
            }
        }
//        // 靠近摆放规则 --- 空托 //互通版
//        if (ioType == 10 && deviceBind.getEmptySimilar().equals("1")) {
//            List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>()
//                    .eq("loc_sts", "D").ge("row1", sRow).le("row1", eRow).eq("whs_type", rowLastnoType.getType().longValue()));
//            if (!locMasts.isEmpty()) {
//                for (LocMast loc : locMasts) {
//                    if (Utils.isShallowLoc(slaveProperties, loc.getLocNo())) {
//                        continue;
//                    }
//                    String shallowLocNo = Utils.getShallowLoc(slaveProperties, loc.getLocNo());
//                    // 检测目标库位是否为空库位
//                    LocMast shallowLoc = locMastService.selectById(shallowLocNo);
//                    if (shallowLoc != null && shallowLoc.getLocSts().equals("O")) {
//                        if (VersionUtils.locMoveCheckLocTypeComplete(shallowLoc, locTypeDto)) {
//                            if (basCrnpService.checkSiteError(shallowLoc.getCrnNo(), true)) {
//                                locMast = shallowLoc;
//                                crnNo = locMast.getCrnNo();
//                                break;
//                            }
//                        }
//                    }
//                }
//            }
//        }
        //查找路径
        DeviceSite deviceSite = deviceSiteService.getOne(new LambdaQueryWrapper<DeviceSite>()
                .eq(DeviceSite::getType, ioType)
                .eq(DeviceSite::getSite, sourceStaNo)
                .eq(DeviceSite::getChannel, channel)
        );
        if (Cools.isEmpty(deviceSite)) {
            channel = 0;
        } else {
            inTaskMsgDto.setStaNo(Integer.parseInt(deviceSite.getDeviceSite()));
        }
        //更新当前排
        deviceBind.setCurrentRow(curRow);
        deviceBindService.updateById(deviceBind);
        // 开始查找库位 ==============================>>
        // 1.按规则查找库位
        if (Cools.isEmpty(loc) && channel != 0) {
            List<Loc> locMasts = null;
            locMasts = locService.list(new LambdaQueryWrapper<Loc>()
                    .eq(Loc::getRow, nearRow)
                    .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
                    .eq(Loc::getType, locTypeDto.getLocType1())
                    .eq(Loc::getAreaId, area)
                    .orderByAsc(Loc::getLev)
                    .orderByAsc(Loc::getCol)
            );
            for (Loc locMast1 : locMasts) {
                if (!LocUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) {
                    continue;
                }
                String shallowLoc = LocUtils.getDeepLoc(locMast1.getCode());
                if ((ioType == TaskStsType.GENERATE_IN.id && deviceBind.getBeSimilar().equals("1"))) {
                    //相似物料打开,判断深库位有没有货,没货就放深库位,有货就不操作
                    Loc locMast2 = locService.getOne(new LambdaQueryWrapper<Loc>()
                            .eq(Loc::getCode, shallowLoc)
                            .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
                            .eq(Loc::getAreaId, area)
                    );
                    if (!Cools.isEmpty(locMast2)) {
                        loc = locMast2;
                        break;
                    }
                } else {
                    //相似物料关闭,判断深库位有没有货,有货就放浅库位,无货就不操作
                    Loc locMast2 = locService.getOne(new LambdaQueryWrapper<Loc>()
                            .eq(Loc::getCode, shallowLoc)
                            .in(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_D.type, LocStsType.LOC_STS_TYPE_F.type)
                            .eq(Loc::getAreaId, area)
                    );
                    if (!Cools.isEmpty(locMast2)) {
                        loc = locMast1;
                        break;
                    } else {
                        locMast2 = locService.getOne(new LambdaQueryWrapper<Loc>()
                                .eq(Loc::getCode, shallowLoc)
                                .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
                                .eq(Loc::getAreaId, area)
                        );
                        if (!Cools.isEmpty(locMast2)) {
                            loc = locMast2;
                            break;
                        }
                    }
                }
            }
            if (Cools.isEmpty(loc) && deviceBind.getBeSimilar().equals("1")) {
                for (Loc locMast1 : locMasts) {
                    if (!LocUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) {
                        continue;
                    }
                    if (deviceBind.getBeSimilar().equals("1")) {
                        String shallowLoc = LocUtils.getDeepLoc(locMast1.getCode());
                        Loc locMast2 = locService.getOne(new LambdaQueryWrapper<Loc>()
                                .eq(Loc::getCode, shallowLoc)
                                .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
                                .eq(Loc::getAreaId, area)
                        );
                        if (!Cools.isEmpty(locMast2)) {
                            loc = locMast2;
                            break;
                        } else {
                            locMast2 = locService.getOne(new LambdaQueryWrapper<Loc>()
                                    .eq(Loc::getCode, shallowLoc)
                                    .in(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_D.type, LocStsType.LOC_STS_TYPE_D.type)
                                    .eq(Loc::getAreaId, area)
                            );
                            if (!Cools.isEmpty(locMast2)) {
                                loc = locMast1;
                                break;
                            }
                        }
                    } else {
                        if (!Cools.isEmpty(locMast1)) {
                            loc = locMast1;
                            break;
                        }
                    }
                }
            }
        }
        //查询当前库位类型空库位 小于5个则locmast = null
        List<Loc> locTypeLocMasts = locService.list(new LambdaQueryWrapper<Loc>()
                .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
                .eq(Loc::getChannel, channel)
                .eq(Loc::getType, locTypeDto.getLocType1())
                .eq(Loc::getAreaId, area)
        );
        if (null != locTypeLocMasts && locTypeLocMasts.size() <= 5) {
            loc = null;
        }
        // 递归查询
        if (Cools.isEmpty(loc) || !loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_O.type)) {
            // 当前巷道无空库位时,递归调整至下一巷道,检索全部巷道无果后,跳出递归
            if (times < rowCount * 2) {
                times = times + 1;
                return getLocNoCrn(deviceBind, area, sourceStaNo, matnr, batch, locTypeDto, times, ioType);
            }
            // 2.库位当前所属尺寸无空库位时,调整尺寸参数,向上兼容检索库位
            if (locTypeDto.getLocType1() < 3) {
                int i = locTypeDto.getLocType1() + 1;
                locTypeDto.setLocType1(i);
                return getLocNoCrn(deviceBind, area, sourceStaNo, matnr, batch, locTypeDto, 0, ioType);
            }
            throw new CoolException("没有空库位");
        }
        String locNo = loc.getCode();
        // 返回dto
        inTaskMsgDto.setDeviceNo(channel);
        inTaskMsgDto.setSourceStaNo(sourceStaNo);
//        inTaskMsgDto.setStaNo();
        inTaskMsgDto.setLocNo(locNo);
        return inTaskMsgDto;
    }
}
rsf-server/src/main/java/com/vincent/rsf/server/common/config/ConfigProperties.java
@@ -70,6 +70,11 @@
     */
    private String securityCode;
    private String userName;
    private String password;
    public List<String> getSuperUserList() {
        return Arrays.stream(superUsername.split(",")).collect(Collectors.toList());
    }
rsf-server/src/main/java/com/vincent/rsf/server/manager/controller/LocItemController.java
@@ -97,7 +97,7 @@
        }
        param.setType(Constants.TASK_TYPE_OUT_STOCK);
        return locItemService.generateTask(param);
        return locItemService.generateTask(param, getLoginUserId());
    }
    /**
@@ -112,7 +112,7 @@
        if (Objects.isNull(map)) {
            return R.error("参数不能为空!!");
        }
        return R.ok("任务生成成功").add(locItemService.genMoveTask(map));
        return R.ok("任务生成成功").add(locItemService.genMoveTask(map, getLoginUserId()));
    }
    /**
@@ -129,7 +129,7 @@
        }
        map.setType(Constants.TASK_TYPE_OUT_CHECK);
        return R.ok("任务生成成功").add(locItemService.generateTask(map));
        return R.ok("任务生成成功").add(locItemService.generateTask(map, getLoginUserId()));
    }
rsf-server/src/main/java/com/vincent/rsf/server/manager/entity/Task.java
@@ -9,6 +9,7 @@
import com.vincent.rsf.server.system.entity.DictData;
import com.vincent.rsf.server.system.service.DictDataService;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -31,6 +32,7 @@
import com.vincent.rsf.server.system.entity.User;
import java.io.Serializable;
import java.util.Date;
import java.util.stream.Collectors;
@Data
@Accessors(chain = true)
@@ -259,6 +261,18 @@
        return dictDatas.getValue() + "." + dictDatas.getLabel();
    }
    public String getWarehType$(){
        if (null == this.warehType){ return null; }
        DictDataService dictDataService = SpringUtils.getBean(DictDataService.class);
        DictData dictDatas = dictDataService.getOne(new LambdaQueryWrapper<DictData>()
                .eq(DictData::getDictTypeCode, DictTypeCode.DICT_SYS_DEVICE_TYPE)
                .eq(DictData::getValue, warehType));
        if (Objects.isNull(dictDatas)) {
            return null;
        }
        return dictDatas.getLabel();
    }
    public String getTaskType$() {
        if (Cools.isEmpty(this.taskType)) {
            return null;
rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskSchedules.java
@@ -8,6 +8,9 @@
import com.vincent.rsf.server.system.constant.GlobalConfigCode;
import com.vincent.rsf.server.system.entity.Config;
import com.vincent.rsf.server.system.service.ConfigService;
import com.vincent.rsf.server.system.utils.SystemAuthUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
@@ -27,6 +30,8 @@
@Component
public class TaskSchedules {
    public static Logger logger = LoggerFactory.getLogger(TaskSchedules.class);
    @Autowired
    private TaskService taskService;
    @Autowired
@@ -35,18 +40,6 @@
    private TaskLogService taskLogService;
    @Autowired
    private TaskItemLogService taskItemLogService;
    @Autowired
    private StockItemService stockItemService;
    @Autowired
    private PurchaseService purchaseService;
    @Autowired
    private AsnOrderService asnOrderService;
    @Autowired
    private AsnOrderItemService asnOrderItemService;
    @Autowired
    private StockService stockService;
    @Autowired
    private LocService locService;
    @Autowired
    private ConfigService configService;
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/LocItemService.java
@@ -6,12 +6,10 @@
import com.vincent.rsf.server.manager.entity.LocItem;
import com.vincent.rsf.server.manager.entity.Task;
import java.util.Map;
public interface LocItemService extends IService<LocItem> {
    R generateTask(LocToTaskParams map);
    R generateTask(LocToTaskParams map, Long loginUserId);
    Task genMoveTask(LocToTaskParams map);
    Task genMoveTask(LocToTaskParams map, Long loginUserId);
}
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/LocItemServiceImpl.java
@@ -1,7 +1,5 @@
package com.vincent.rsf.server.manager.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.vincent.rsf.framework.common.R;
import com.vincent.rsf.framework.exception.CoolException;
@@ -14,7 +12,6 @@
import com.vincent.rsf.server.manager.controller.params.LocToTaskParams;
import com.vincent.rsf.server.manager.entity.*;
import com.vincent.rsf.server.manager.enums.*;
import com.vincent.rsf.server.manager.enums.LocType;
import com.vincent.rsf.server.manager.mapper.LocItemMapper;
import com.vincent.rsf.server.manager.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -27,7 +24,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.lang.reflect.Array;
import java.util.*;
import java.util.stream.Collectors;
@@ -55,12 +51,13 @@
     * type: check 盘点, stock: 库存出库
     *
     * @param map
     * @param loginUserId
     * @return
     */
    @Override
    @Synchronized
    @Transactional(rollbackFor = Exception.class)
    public R generateTask(LocToTaskParams map) {
    public R generateTask(LocToTaskParams map, Long loginUserId) {
        if (Objects.isNull(map.getSiteNo())) {
            throw new CoolException("站点不能为空!");
        }
@@ -84,9 +81,9 @@
            }
            Task moveTask = new Task();
            if (!LocUtils.isShallowLoc(slaveProperties, loc.getCode())) {
            if (!LocUtils.isShallowLoc(loc.getCode())) {
                //获取深库位对应浅库位
                String shallowLoc = LocUtils.getShallowLoc(slaveProperties, loc.getCode());
                String shallowLoc = LocUtils.getShallowLoc(loc.getCode());
                Loc one = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, shallowLoc));
                if (Objects.isNull(one)) {
                    throw new CoolException("对应库位不存在!!");
@@ -94,7 +91,7 @@
                map.setOrgLoc(one.getCode());
                //优先生成移库任务
                if (!one.getUseStatus().equals(LocStsType.LOC_STS_TYPE_O.type)) {
                    moveTask = genMoveTask(map);
                    moveTask = genMoveTask(map, loginUserId);
                }
            }
@@ -103,6 +100,10 @@
                    .setTaskCode(ruleCode)
                    .setParentId(moveTask.getId())
                    .setTargSite(siteNo)
                    .setUpdateBy(loginUserId)
                    .setCreateBy(loginUserId)
                    .setCreateTime(new Date())
                    .setUpdateTime(new Date())
                    .setTaskStatus(TaskStsType.GENERATE_OUT.id)
                    .setBarcode(loc.getBarcode());
@@ -125,7 +126,6 @@
                Double useQty = Math.round((outQty + workQty) * 10000) / 10000.0;
                if (orgQty.compareTo(useQty) > 0) {
                    //拣料出库
                    task.setTaskType(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type);
                    DeviceSite deviceSite = deviceSiteService.getOne(new LambdaQueryWrapper<DeviceSite>()
                            .eq(DeviceSite::getSite, siteNo)
@@ -134,19 +134,21 @@
                    if (Objects.isNull(deviceSite)) {
                        throw new CoolException("站点不支持拣料出库!!");
                    }
                    task.setTaskType(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type).setWarehType(deviceSite.getDevice());
                } else {
                    //全板出库
                    task.setTaskType(TaskType.TASK_TYPE_OUT.type);
                    DeviceSite deviceSite = deviceSiteService.getOne(new LambdaQueryWrapper<DeviceSite>()
                            .eq(DeviceSite::getChannel, loc.getChannel())
                            .eq(DeviceSite::getSite, siteNo).eq(DeviceSite::getType, TaskType.TASK_TYPE_OUT.type));
                    if (Objects.isNull(deviceSite)) {
                        throw new CoolException("站点不支持全板出库!!");
                    }
                    task.setTaskType(TaskType.TASK_TYPE_OUT.type).setWarehType(deviceSite.getDevice());
                }
            } else if (map.getType().equals(Constants.TASK_TYPE_OUT_CHECK)) {
                //盘点出库
                task.setTaskType(TaskType.TASK_TYPE_CHECK_OUT.type);
                DeviceSite deviceSite = deviceSiteService.getOne(new LambdaQueryWrapper<DeviceSite>()
                        .eq(DeviceSite::getChannel, loc.getChannel())
                        .eq(DeviceSite::getSite, siteNo)
@@ -154,6 +156,9 @@
                if (Objects.isNull(deviceSite)) {
                    throw new CoolException("当前站点不支持盘点出库!!");
                }
                task.setTaskType(TaskType.TASK_TYPE_CHECK_OUT.type).setWarehType(deviceSite.getDevice());
            }
            if (!taskService.save(task)) {
@@ -166,6 +171,10 @@
                taskItem.setTaskId(task.getId())
                        .setAnfme(item.getOutQty())
                        .setBatch(item.getBatch())
                        .setUpdateBy(loginUserId)
                        .setCreateBy(loginUserId)
                        .setCreateTime(new Date())
                        .setUpdateTime(new Date())
                        .setOrderType(OrderType.ORDER_OUT.type)
                        .setWkType(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_STOCK_OUT.type));
                taskItems.add(taskItem);
@@ -186,6 +195,8 @@
                } else {
                    item.setWorkQty(qty);
                }
                item.setUpdateBy(loginUserId).setUpdateTime(new Date());
                if (!locItemService.updateById(item)) {
                    throw new CoolException("库存信息修改失败!!");
                }
@@ -203,11 +214,12 @@
     * 生成移库任务
     *
     * @param map
     * @param loginUserId
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Task genMoveTask(LocToTaskParams map) {
    public Task genMoveTask(LocToTaskParams map, Long loginUserId) {
        if (Objects.isNull(map.getOrgLoc()) || StringUtils.isBlank(map.getOrgLoc())) {
            throw new CoolException("源库位不能为空!");
        }
@@ -270,6 +282,8 @@
                .setTaskCode(ruleCode)
                .setTaskType(TaskType.TASK_TYPE_LOC_MOVE.type)
                .setTargLoc(targetLoc.getCode())
                .setUpdateBy(loginUserId)
                .setUpdateTime(new Date())
                .setTaskStatus(TaskStsType.GENERATE_IN.id)
                .setBarcode(orgLoc.getBarcode());
@@ -286,6 +300,8 @@
                taskItem.setTaskId(task.getId())
                        .setAnfme(item.getAnfme())
                        .setBatch(item.getBatch())
                        .setUpdateBy(loginUserId)
                        .setUpdateTime(new Date())
                        .setOrderType(OrderType.ORDER_IN.type)
                        .setWkType(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_OTHER_IN.type));
                taskItems.add(taskItem);
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java
@@ -13,7 +13,6 @@
import com.vincent.rsf.server.api.utils.LocUtils;
import com.vincent.rsf.server.manager.controller.params.GenerateTaskParams;
import com.vincent.rsf.server.manager.entity.*;
import com.vincent.rsf.server.manager.enums.LocType;
import com.vincent.rsf.server.manager.mapper.TaskMapper;
import com.vincent.rsf.server.manager.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -21,8 +20,11 @@
import com.vincent.rsf.server.system.constant.SerialRuleCode;
import com.vincent.rsf.server.manager.enums.LocStsType;
import com.vincent.rsf.server.system.utils.SerialRuleUtils;
import com.vincent.rsf.server.system.utils.SystemAuthUtils;
import lombok.Synchronized;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -33,6 +35,8 @@
@Service("taskService")
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements TaskService {
    public static final Logger logger = LoggerFactory.getLogger(TaskServiceImpl.class);
    @Autowired
    private WaitPakinService waitPakinService;
@@ -385,23 +389,24 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void complateInTask(List<Task> tasks) throws Exception {
        Long loginUserId = SystemAuthUtils.getLoginUserId();
        for (Task task : tasks) {
            if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)) {
                //1.入库
                complateInstock(task);
                complateInstock(task, loginUserId);
            } else if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type) || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)) {
                //53.拣料再入库
                //57.盘点再入库
                pickComplateInStock(task);
                pickComplateInStock(task, loginUserId);
            } else if (task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
                //移库
                moveInStock(task);
                moveInStock(task, loginUserId);
            }
        }
    }
    @Transactional(rollbackFor = Exception.class)
    public void moveInStock(Task task) {
    public void moveInStock(Task task, Long loginUserId) {
        if (Objects.isNull(task)) {
            return;
        }
@@ -430,7 +435,7 @@
            //移库有可能是空板
            try {
                //更新库位明细
                saveLocItem(taskItems, task.getId());
                saveLocItem(taskItems, task.getId(), loginUserId);
            } catch (Exception e) {
                throw new CoolException("库位明细更新失败!!");
            }
@@ -445,18 +450,25 @@
        if (!locService.update(new LambdaUpdateWrapper<Loc>()
                        .set(Loc::getBarcode, task.getBarcode())
                .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type)
                        .set(Loc::getUpdateBy, loginUserId)
                        .set(Loc::getUpdateTime, new Date())
                .eq(Loc::getCode, task.getTargLoc()))) {
            throw new CoolException("库位状态修改失败!!");
        }
        if (!locService.update(new LambdaUpdateWrapper<Loc>()
                        .set(Loc::getBarcode, null)
                .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type).eq(Loc::getCode, task.getOrgLoc()))) {
                        .set(Loc::getUpdateBy, loginUserId)
                        .set(Loc::getUpdateTime, new Date())
                        .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
                .eq(Loc::getCode, task.getOrgLoc()))) {
            throw new CoolException("库位状态修改失败!!");
        }
        if (!this.update(new LambdaUpdateWrapper<Task>().eq(Task::getId, task.getId()).set(Task::getTaskStatus, TaskStsType.UPDATED_IN.id))) {
        if (!this.update(new LambdaUpdateWrapper<Task>().eq(Task::getId, task.getId())
                        .set(Task::getUpdateBy, loginUserId)
                        .set(Task::getUpdateTime, new Date())
                .set(Task::getTaskStatus, TaskStsType.UPDATED_IN.id))) {
            throw new CoolException("任务状态修改失败!!");
        }
@@ -473,17 +485,18 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void completeTask(List<Task> tasks) throws Exception {
        Long loginUserId = SystemAuthUtils.getLoginUserId();
        for (Task task : tasks) {
            //出库任务
            if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)) {
                //全托出库
                complateOutStock(task);
                complateOutStock(task, loginUserId);
            } else if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type)) {
                //拣料出库
                complateOutStock(task);
                complateOutStock(task, loginUserId);
            } else if (task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)) {
                //盘点出库
                complateOutStock(task);
                complateOutStock(task, loginUserId);
            }
        }
    }
@@ -492,9 +505,10 @@
     * 拣料再入库
     *
     * @param task
     * @param loginUserId
     */
    @Transactional(rollbackFor = Exception.class)
    public void pickComplateInStock(Task task) throws Exception {
    public void pickComplateInStock(Task task, Long loginUserId) throws Exception {
        if (Objects.isNull(task)) {
            return;
        }
@@ -506,7 +520,9 @@
            throw new CoolException("当前库位状态不处于S.入库预约,不可执行入库操作!");
        }
        loc.setUseStatus(LocStsType.LOC_STS_TYPE_F.type).setBarcode(task.getBarcode());
        loc.setUseStatus(LocStsType.LOC_STS_TYPE_F.type)
                .setBarcode(task.getBarcode())
                .setUpdateBy(loginUserId).setUpdateTime(new Date());
        if (!locService.updateById(loc)) {
            throw new CoolException("库位信息更新失败!!");
@@ -531,7 +547,7 @@
                locWorking.setAnfme(taskItem.getAnfme());
            }
            BeanUtils.copyProperties(locWorking, locItem);
            locItem.setWorkQty(0.0).setLocCode(loc.getCode()).setLocId(loc.getId()).setId(null);
            locItem.setWorkQty(0.0).setLocCode(loc.getCode()).setLocId(loc.getId()).setId(null).setUpdateBy(loginUserId).setUpdateTime(new Date());
            items.add(locItem);
        }
@@ -541,13 +557,13 @@
        TaskItem taskItem = taskItems.stream().findFirst().get();
        //保存入出库流水
        saveStockItems(taskItems, task, null, null, taskItem.getWkType(), taskItem.getOrderType());
        saveStockItems(taskItems, task, null, null, taskItem.getWkType(), taskItem.getOrderType(), loginUserId);
        if (!locItemWorkingService.remove(new LambdaQueryWrapper<LocItemWorking>().eq(LocItemWorking::getTaskId, task.getId()))) {
            throw new CoolException("作业中库存删除失败!!");
        }
        task.setTaskStatus(TaskStsType.UPDATED_IN.id).setUpdateTime(null);
        task.setTaskStatus(TaskStsType.UPDATED_IN.id).setUpdateTime(new Date()).setUpdateBy(loginUserId);
        if (!taskService.updateById(task)) {
            throw new CoolException("任务状态修改失败!!");
        }
@@ -577,7 +593,7 @@
                    .eq(WaitPakin::getBarcode, task.getBarcode())
            );
            if (null != waitPakin) {
                waitPakin.setIoStatus(Short.valueOf(PakinIOStatus.PAKIN_IO_STATUS_DONE.val));
                waitPakin.setIoStatus(PakinIOStatus.PAKIN_IO_STATUS_DONE.val);
                if (!waitPakinService.updateById(waitPakin)) {
                    throw new CoolException("更新组托状态失败!!");
                }
@@ -736,11 +752,10 @@
     */
    @Synchronized
    @Transactional(rollbackFor = Exception.class)
    public void complateOutStock(Task task) throws Exception {
    public void complateOutStock(Task task, Long loginUserId) throws Exception {
        if (Objects.isNull(task)) {
            throw new CoolException("参数不能为空!!");
        }
        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, task.getOrgLoc()));
        if (Objects.isNull(loc)) {
            throw new CoolException("库位不存在!!");
@@ -763,7 +778,11 @@
        for (LocItem item : locItems) {
            LocItemWorking working = new LocItemWorking();
            BeanUtils.copyProperties(item, working);
            working.setId(null).setTaskId(task.getId()).setLocItemId(item.getId());
            working.setId(null)
                    .setTaskId(task.getId())
                    .setLocItemId(item.getId())
                    .setUpdateBy(loginUserId)
                    .setUpdateTime(new Date());
            workings.add(working);
        }
@@ -775,7 +794,7 @@
            //更新库位明细
            subtractLocItem(loc);
        } catch (Exception e) {
            log.error("<UNK>", e);
            logger.error("<UNK>", e);
            throw new CoolException(e.getMessage());
        }
@@ -794,14 +813,14 @@
                    throw new CoolException("波次明细不存在!!");
                }
                try {
                    saveOutStockItem(maps.get(key), waveItem);
                    saveOutStockItem(maps.get(key), waveItem, loginUserId);
                } catch (Exception e) {
                    throw new CoolException(e.getMessage());
                }
            });
        } else {
            try {
                saveOutStockItem(taskItems, null);
                saveOutStockItem(taskItems, null, loginUserId);
            } catch (Exception e) {
                throw new CoolException(e.getMessage());
            }
@@ -811,6 +830,8 @@
        if (!locService.update(new LambdaUpdateWrapper<Loc>()
                .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
                .set(Loc::getBarcode, null)
                        .set(Loc::getUpdateBy, loginUserId)
                        .set(Loc::getUpdateTime, new Date())
                .eq(Loc::getId, loc.getId()))) {
            throw new CoolException("库位状态修改失败!!");
        }
@@ -818,21 +839,23 @@
        if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type) || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)) {
            if (!this.update(new LambdaUpdateWrapper<Task>()
                    .eq(Task::getId, task.getId())
                    .set(Task::getUpdateBy, loginUserId)
                    .set(Task::getUpdateTime, new Date())
                    .set(Task::getTaskStatus, TaskStsType.WAVE_SEED.id))) {
                throw new CoolException("库存状态更新失败!!");
            }
        } else {
            if (!this.update(new LambdaUpdateWrapper<Task>()
                    .eq(Task::getId, task.getId())
                    .set(Task::getUpdateBy, loginUserId)
                    .set(Task::getUpdateTime, new Date())
                    .set(Task::getTaskStatus, TaskStsType.UPDATED_OUT.id))) {
                throw new CoolException("库存状态更新失败!!");
            }
            //全板出库,删除临时库存
            if (!locItemWorkingService.remove(new LambdaQueryWrapper<LocItemWorking>().eq(LocItemWorking::getTaskId, task.getId()))) {
                throw new CoolException("临时库存清除失败!!");
            }
        }
    }
@@ -844,7 +867,7 @@
     * @version 1.0
     */
    @Transactional(rollbackFor = Exception.class)
    public void saveOutStockItem(List<TaskItem> taskItems, WaveItem waveItem) throws Exception {
    public void saveOutStockItem(List<TaskItem> taskItems, WaveItem waveItem, Long loginUserId) throws Exception {
        Stock stock = new Stock();
        String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_STOCK_CODE, null);
        if (StringUtils.isBlank(ruleCode)) {
@@ -852,6 +875,8 @@
        }
        Double sum = taskItems.stream().mapToDouble(TaskItem::getAnfme).sum();
        stock.setCode(ruleCode)
                .setUpdateBy(loginUserId)
                .setUpdateTime(new Date())
                .setAnfme(sum);
        if (Objects.isNull(waveItem)) {
            stock.setWkType(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_STOCK_OUT.type))
@@ -870,6 +895,8 @@
            StockItem stockItem = new StockItem();
            BeanUtils.copyProperties(item, stockItem);
            stockItem.setSourceItemId(item.getOrderItemId())
                    .setUpdateBy(loginUserId)
                    .setUpdateTime(new Date())
                    .setStockCode(stock.getCode())
                    .setId(null)
                    .setStockId(stock.getId());
@@ -901,7 +928,7 @@
     * @version 1.0
     */
    @Transactional(rollbackFor = Exception.class)
    public void complateInstock(Task task) {
    public void complateInstock(Task task, Long loginUserId) {
        if (Objects.isNull(task)) {
            return;
        }
@@ -921,7 +948,7 @@
        }
        try {
            //更新库位明细
            saveLocItem(taskItems, task.getId());
            saveLocItem(taskItems, task.getId(), loginUserId);
        } catch (Exception e) {
            throw new CoolException("库位明细更新失败!!");
        }
@@ -936,10 +963,11 @@
            List<TaskItem> items = orderMap.get(key);
            try {
                //保存库存明细
                saveStockItems(items, task, pakinItem.getId(), pakinItem.getAsnCode(), pakinItem.getWkType(), pakinItem.getType());
                saveStockItems(items, task, pakinItem.getId(), pakinItem.getAsnCode(), pakinItem.getWkType(), pakinItem.getType(), loginUserId);
                //移出收货区库存, 修改组托状态
                removeReceiptStock(pakinItem);
                removeReceiptStock(pakinItem, loginUserId);
            } catch (Exception e) {
                logger.error("<UNK>", e);
                throw new CoolException(e.getMessage());
            }
        });
@@ -954,13 +982,14 @@
    /**
     * @param
     * @param loginUserId
     * @return
     * @author Ryan
     * @description 移除收货区库存
     * @time 2025/4/30 16:32
     */
    @Transactional(rollbackFor = Exception.class)
    public void removeReceiptStock(WaitPakinItem pakinItem) {
    public void removeReceiptStock(WaitPakinItem pakinItem, Long loginUserId) {
        WarehouseAreasItem itemServiceOne = warehouseAreasItemService.getOne(new LambdaQueryWrapper<WarehouseAreasItem>()
                .eq(WarehouseAreasItem::getId, pakinItem.getSource()));
        if (Objects.isNull(itemServiceOne)) {
@@ -972,6 +1001,7 @@
        if (!waitPakinService.update(new LambdaUpdateWrapper<WaitPakin>()
                .set(WaitPakin::getIoStatus, PakinIOStatus.PAKIN_IO_STATUS_TASK_DONE.val)
                        .set(WaitPakin::getUpdateBy, loginUserId)
                .eq(WaitPakin::getId, pakinItem.getPakinId()))) {
            throw new CoolException("组拖状态修改失败!!");
        }
@@ -981,6 +1011,7 @@
                throw new CoolException("收货区物料删除失败!!");
            }
        } else {
            itemServiceOne.setUpdateBy(loginUserId).setUpdateTime(null);
            if (!warehouseAreasItemService.updateById(itemServiceOne)) {
                throw new CoolException("收货区库完成数量修改失败!!");
            }
@@ -989,13 +1020,14 @@
    /**
     * @param
     * @param loginUserId
     * @return
     * @author Ryan
     * @description 更新库位明细
     * @time 2025/4/15 15:28
     */
    @Transactional(rollbackFor = Exception.class)
    public void saveLocItem(List<TaskItem> items, Long taskId) throws Exception {
    public void saveLocItem(List<TaskItem> items, Long taskId, Long loginUserId) throws Exception {
        Task task = this.getById(taskId);
        if (Objects.isNull(task)) {
            throw new CoolException("任务不存在!!");
@@ -1008,6 +1040,7 @@
            BeanUtils.copyProperties(taskItem, item);
            item.setLocCode(loc.getCode()).setId(null)
                    .setLocId(loc.getId())
                    .setUpdateBy(loginUserId)
                    .setWkType(taskItem.getWkType())
                    .setType(taskItem.getOrderType());
            locItems.add(item);
@@ -1021,10 +1054,11 @@
     * 生成入库库存明细
     *
     * @param items
     * @param loginUserId
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public void saveStockItems(List<TaskItem> items, Task task, Long id, String code, Short wkType, String type) throws
    public void saveStockItems(List<TaskItem> items, Task task, Long id, String code, Short wkType, String type, Long loginUserId) throws
            Exception {
        Stock stock = new Stock();
        String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_STOCK_CODE, null);
@@ -1038,6 +1072,7 @@
                .setAnfme(sum)
                .setWkType(wkType)
                .setBarcode(task.getBarcode())
                .setUpdateBy(loginUserId)
                .setType(type);
        if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type) ||
                task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_IN.type) ||
@@ -1061,6 +1096,7 @@
                    .setStockCode(stock.getCode())
                    .setBarcode(task.getBarcode())
                    .setSourceItemId(item.getOrderItemId())
                    .setUpdateBy(loginUserId)
                    .setId(null)
                    .setStockId(stock.getId());
            stockItems.add(stockItem);
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaitPakinServiceImpl.java
@@ -63,7 +63,7 @@
        if (StringUtils.isBlank(waitPakin.getBarcode())) {
            throw new CoolException("参数错误:托盘码为空!!");
        }
        List<Short> asList = Arrays.asList(Short.valueOf(PakinIOStatus.PAKIN_IO_STATUS_DONE.val), Short.valueOf(PakinIOStatus.PAKIN_IO_STATUS_DONE.val));
//        List<Short> asList = Arrays.asList(Short.valueOf(PakinIOStatus.PAKIN_IO_STATUS_DONE.val), Short.valueOf(PakinIOStatus.PAKIN_IO_STATUS_DONE.val));
        WaitPakin pakin = waitPakinService.getOne(new LambdaQueryWrapper<WaitPakin>()
                .eq(WaitPakin::getBarcode, waitPakin.getBarcode()));
        if (!Objects.isNull(pakin)) {
rsf-server/src/main/java/com/vincent/rsf/server/system/utils/SystemAuthUtils.java
New file
@@ -0,0 +1,75 @@
package com.vincent.rsf.server.system.utils;
import com.vincent.rsf.common.enums.SystemModeType;
import com.vincent.rsf.framework.common.R;
import com.vincent.rsf.framework.common.SpringUtils;
import com.vincent.rsf.server.common.config.ConfigProperties;
import com.vincent.rsf.server.common.domain.BusinessRes;
import com.vincent.rsf.server.common.security.JwtSubject;
import com.vincent.rsf.server.common.utils.JwtUtil;
import com.vincent.rsf.server.system.entity.Tenant;
import com.vincent.rsf.server.system.entity.User;
import com.vincent.rsf.server.system.entity.UserLogin;
import com.vincent.rsf.server.system.service.TenantService;
import com.vincent.rsf.server.system.service.UserLoginService;
import com.vincent.rsf.server.system.service.UserService;
import org.checkerframework.checker.units.qual.C;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import javax.annotation.PostConstruct;
import java.util.Objects;
@Component
public class SystemAuthUtils {
    public static Logger logger = LoggerFactory.getLogger(SystemAuthUtils.class);
    private static String username;
    private static String password;
    private static String tokenKey;
    private static Long tokenExpireTime;
    private static SystemModeType systemMode;
    @Autowired
    private ConfigProperties configProperties;
    @PostConstruct
    public void init() {
        username = configProperties.getUserName();
        password = configProperties.getPassword();
    }
    public static User getLoginUser() {
        try {
            Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
            if (authentication != null) {
                Object object = authentication.getPrincipal();
                if (object instanceof User) {
                    return (User) object;
                }
            } else {
                UserService userService = SpringUtils.getBean(UserService.class);
                return userService.getByUsername(username, null);
            }
        } catch (Exception e) {
            logger.error("<UNK>", e);
        }
        return null;
    }
    public static Long getLoginUserId() {
        User loginUser = getLoginUser();
        return loginUser == null ? null : loginUser.getId();
    }
}
rsf-server/src/main/resources/application.yml
@@ -11,6 +11,8 @@
  code-length: 6
  code-time: 300
  security-code: 951123
  username: super
  password: 123456
eureka:
  client:
@@ -37,6 +39,7 @@
super:
  pwd: xltys1995
logging:
  file:
    path: logs/@pom.artifactId@