Commit 65adfe23 by zhu.zewen

更新配置

parent 8ac0af24
package com.jmai.physic.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* 交接单取消配置
*/
@Data
@Component
@ConfigurationProperties(prefix = "handover.cancel")
public class HandoverCancelProperties {
/**
* 是否允许交班人取消(默认false)
*/
private Boolean allowTransferor = false;
/**
* 是否允许接班人取消(默认false)
*/
private Boolean allowReceiver = false;
/**
* 允许取消的天数限制(默认3天,从0时开始,含当天)
*/
private Integer dayLimit = 3;
/**
* 是否允许取消已完成的交接班(默认false)
*/
private Boolean allowCancelCompleted = false;
}
......@@ -8,7 +8,9 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jmai.api.exception.ServiceException;
import com.jmai.physic.cloudsign.CloudsignService;
import com.jmai.physic.config.HandoverCancelProperties;
import com.jmai.sys.service.ConfigService;
import com.jmai.sys.consts.ConfigTypes;
import com.jmai.sys.dto.ConfigDto;
import com.jmai.physic.dto.*;
import com.jmai.physic.entity.PhysicBill;
import com.jmai.physic.entity.PhysicBillHandover;
......@@ -32,6 +34,9 @@ import java.util.Collections;
import java.util.List;
import java.util.Optional;
import static com.jmai.sys.consts.ConfigTypes.PHYSIC_HANDOVER;
import static com.jmai.sys.consts.ConfigTypes.PhysicHandoverCancelConfig.*;
@Service
public class PhysicBillServiceImpl extends AbstractService implements PhysicBillService {
......@@ -44,7 +49,10 @@ public class PhysicBillServiceImpl extends AbstractService implements PhysicBill
private CloudsignService cloudsignService;
@Resource
private HandoverCancelProperties handoverCancelProperties;
private ConfigService configService;
// 缓存交接班取消配置,避免重复查询
private volatile ConfigDto handoverCancelConfig;
@Resource
private SysUserMapper sysUserMapper;
......@@ -313,8 +321,13 @@ public class PhysicBillServiceImpl extends AbstractService implements PhysicBill
if (!handover.getDeptId().equals(currentDeptId)) {
throw new ServiceException("交接班只能在同一部门内进行");
}
// 获取配置对象一次,作为参数传入验证方法
ConfigDto config = configService.getConfig(PHYSIC_HANDOVER, HANDOVER_CANCEL)
.orElse(new ConfigDto());
if (handover.getStatus().equals(100)) {
if (!handoverCancelProperties.getAllowCancelCompleted()) {
if (!isAllowCancelCompleted(config)) {
throw new ServiceException("已完成交接班不能取消");
}
}
......@@ -333,10 +346,10 @@ public class PhysicBillServiceImpl extends AbstractService implements PhysicBill
}
// 验证操作权限
validateCancelPermission(handover, currentUserId);
validateCancelPermission(handover, currentUserId, config);
// 验证时间限制
validateCancelTimeLimit(handover);
validateCancelTimeLimit(handover, config);
handover.setStatus(-100);
physicBillHandoverMapper.updateById(handover);
......@@ -345,7 +358,7 @@ public class PhysicBillServiceImpl extends AbstractService implements PhysicBill
/**
* 验证取消操作的权限
*/
private void validateCancelPermission(PhysicBillHandover handover, Long currentUserId) {
private void validateCancelPermission(PhysicBillHandover handover, Long currentUserId, ConfigDto config) {
List<String> msg = new ArrayList<>(4);
// 检查是否为创建人
if (handover.getCreateBy() != null && handover.getCreateBy().equals(currentUserId)) {
......@@ -363,7 +376,7 @@ public class PhysicBillServiceImpl extends AbstractService implements PhysicBill
}
// 检查是否允许交班人取消且为交班人
boolean isTransferor = handoverCancelProperties.getAllowTransferor() && handover.getYjUser() != null;
boolean isTransferor = isAllowTransferor(config) && handover.getYjUser() != null;
if (isTransferor) {
SignInfoDTO yjUserInfo = JSONUtil.toBean(handover.getYjUser(), SignInfoDTO.class);
if (yjUserInfo.getUserId().equals(currentUserId)) {
......@@ -374,7 +387,7 @@ public class PhysicBillServiceImpl extends AbstractService implements PhysicBill
}
// 检查是否允许接班人取消且为接班人
boolean isReceiver = handoverCancelProperties.getAllowReceiver() && handover.getJsUser() != null;
boolean isReceiver = isAllowReceiver(config) && handover.getJsUser() != null;
if (isReceiver) {
SignInfoDTO jsUserInfo = JSONUtil.toBean(handover.getJsUser(), SignInfoDTO.class);
if (jsUserInfo.getUserId().equals(currentUserId)) {
......@@ -392,7 +405,7 @@ public class PhysicBillServiceImpl extends AbstractService implements PhysicBill
* 验证取消时间限制
* 仅对未完成的交接单进行时间限制校验,已完成的交接单不受时间限制
*/
private void validateCancelTimeLimit(PhysicBillHandover handover) {
private void validateCancelTimeLimit(PhysicBillHandover handover, ConfigDto config) {
// 未完成的交接单不受时间限制
if (handover.getStatus().equals(-100)) {
return;
......@@ -406,12 +419,41 @@ public class PhysicBillServiceImpl extends AbstractService implements PhysicBill
// 计算创建日期的开始时间(0时)
LocalDateTime createdDateStart = createdTime.toLocalDate().atStartOfDay();
// 计算允许取消的最后一天的结束时间
LocalDateTime cancelDeadline = createdDateStart.plusDays(handoverCancelProperties.getDayLimit());
LocalDateTime cancelDeadline = createdDateStart.plusDays(getDayLimit(config));
// 当前时间
LocalDateTime now = LocalDateTime.now();
if (now.isAfter(cancelDeadline)) {
throw new ServiceException("超过" + handoverCancelProperties.getDayLimit() + "天的交接单不允许取消");
throw new ServiceException("超过" + getDayLimit(config) + "天的交接单不允许取消");
}
}
/**
* 是否允许交班人取消
*/
private boolean isAllowTransferor(ConfigDto config) {
return config.getBoolFromJsonValue(ALLOW_TRANSFEROR, true);
}
/**
* 是否允许接班人取消
*/
private boolean isAllowReceiver(ConfigDto config) {
return config.getBoolFromJsonValue(ALLOW_RECEIVER, true);
}
/**
* 是否允许取消已完成的交接班
*/
private boolean isAllowCancelCompleted(ConfigDto config) {
return config.getBoolFromJsonValue(ALLOW_CANCEL_COMPLETED, false);
}
/**
* 获取允许取消的天数限制
*/
private Integer getDayLimit(ConfigDto config) {
Integer dayLimit = config.getIntFromJsonValue(DAY_LIMIT);
return dayLimit != null ? dayLimit : 3;
}
}
\ No newline at end of file
......@@ -124,71 +124,26 @@ public interface ConfigTypes extends VerifyConfigs {
String CHECK_CODE ="checkCode";
}
/**
* 物料设置
*/
String IVS_ITEM_SETTING = "ivs.item.setting";
interface IvsCodeSetting {
// 物料设置
String ITEM_SETTING = "itemSetting";
}
/**
* 核验单识别配置
*/
@Deprecated
String IVS_OCR_LASER = "ivs.ocr.laser";
interface IvsOcrConfig {
//MOCK服务识别地址
String INFYOCR_MOCK_CONFIG = "infyocrMockConfig";
//本地识别地址
String INFYOCR_LOCAL_CONFIG = "infyocrLocalConfig";
//云服务识别地址
String INFYOCR_CLOUD_CONFIG = "infyocrCloudConfig";
//启用OCR渠道
String CHANNEL_TYPE = "channelType";
}
String OCR_LOCAL_CHANNEL = "local";
String OCR_CLOUD_CHANNEL = "cloud";
String OCR_MOCK_CHANNEL = "mock";
String IVS_OCR_RECOGNIZER = "ivs.ocr.recognizer";
interface OcrCertReader {
// 镭射码识别器
String LASER_CODE_RECOGNIZER = "laserCodeRecognizer";
// 合格证内容识别器
String CERT_TEXT_RECOGNIZER = "certTextRecognizer";
// 合格证UDI识别器
String CERT_UDI_RECOGNIZER = "certUdiRecognizer";
// 备份识别器
String BACKUP_RECOGNIZER = ".bak";
// 已开启识别器
String KEY_ENABLED_RECOGNIZER = "enabledRecognizer";
// 识别器配置(JSON)
String KEY_RECOGNIZER_CONFIG = "recognizerConfig";
}
/**
* 快照设置
*/
String IVS_SNAP_SETTING = "ivs.snap.setting";
interface IvsSnapSetting {
// 设置
String SNAP_SETTING = "snapSetting";
}
/*******************************************************************
* PHYSIC - 物理专账
******************************************************************/
/**
* 文件存储器
* 交接班取消配置
*/
String SYS_FILE_STORER = "sys.file.storer";
interface SysFileStorer {
String FILE_STORER = "fileStorer";
// 已开启识别器
String KEY_ENABLED_STORER = "enabledStorer";
String PHYSIC_HANDOVER = "physic.handover";
interface PhysicHandoverCancelConfig {
String HANDOVER_CANCEL = "handoverCancel";
// 是否允许交班人取消(默认false)
String ALLOW_TRANSFEROR = "allowTransferor";
// 是否允许接班人取消(默认false)
String ALLOW_RECEIVER = "allowReceiver";
// 允许取消的天数限制(默认3天,从0时开始,含当天)
String DAY_LIMIT = "dayLimit";
// 是否允许取消已完成的交接班(默认false)
String ALLOW_CANCEL_COMPLETED = "allowCancelCompleted";
}
/*******************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment