add:页面国际化

This commit is contained in:
2025-12-05 09:45:10 +08:00
parent de009fadbb
commit e0e8678001
11 changed files with 1498 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
package org.nl.wms.sch.forewarn.service.dao;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* <p>
* 载具扩展属性信息表
* </p>
*
* @author Liuxy
* @since 2025-05-23
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("md_pb_storagevehicleext")
public class MdPbStoragevehicleext implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 载具扩展标识
*/
@TableId(value = "storagevehicleext_id")
private String storagevehicleext_id;
/**
* 载具编码
*/
private String storagevehicle_code;
/**
* 物料标识
*/
private String material_id;
/**
* 批次
*/
private String pcsn;
/**
* 数量计量单位标识
*/
private String qty_unit_id;
/**
* 数量计量单位名称
*/
private String qty_unit_name;
/**
* 可用数
*/
private BigDecimal canuse_qty;
/**
* 冻结数
*/
private BigDecimal frozen_qty;
/**
* 备注
*/
private String remark;
/**
* 修改人
*/
private String update_optid;
/**
* 修改人姓名
*/
private String update_optname;
/**
* 修改时间
*/
private String update_time;
/**
* 入库时间
*/
private String insert_time;
}

View File

@@ -0,0 +1,224 @@
package org.nl.wms.sch.task_manage;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.nl.wms.sch.forewarn.service.dao.StIvtOverdueforewarning;
import org.nl.wms.sch.forewarn.service.dto.MdPbStoragevehicleextDto;
import org.nl.wms.sch.forewarn.service.IStIvtForewarningconfigService;
import org.nl.wms.sch.forewarn.service.IStIvtForewarningmaterialService;
import org.nl.wms.sch.forewarn.service.IStIvtOverdueforewarningService;
import org.nl.wms.sch.forewarn.service.IStIvtSafetyforewarningService;
import org.nl.wms.sch.forewarn.service.dao.StIvtForewarningconfig;
import org.nl.wms.sch.forewarn.service.dao.StIvtForewarningmaterial;
import org.nl.wms.sch.forewarn.service.dao.StIvtSafetyforewarning;
import org.nl.wms.sch.forewarn.service.dto.MdPbStoragevehicleextDto;
import org.nl.wms.sch.group.service.dao.mapper.MdPbGroupplateMapper;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Slf4j
@Component
@RequiredArgsConstructor
public class ForewarningTask {
@Autowired
private IStIvtOverdueforewarningService stIvtOverdueforewarningService;
@Autowired
private IStIvtSafetyforewarningService stIvtSafetyforewarningService;
@Autowired
private IStIvtForewarningconfigService forewarningconfigService;
@Autowired
private IStIvtForewarningmaterialService stIvtForewarningmaterialService;
@Autowired
private final RedissonClient redissonClient;
@Autowired
private MdPbGroupplateMapper mdPbGroupplateMapper;
//定时任务
@SneakyThrows
public void run() {
RLock lock = redissonClient.getLock(this.getClass().getName());
boolean tryLock = lock.tryLock(2, TimeUnit.SECONDS);
try {
if (tryLock) {
runTask();
}
lock.unlock();
} catch (Exception e) {
if (tryLock) {
lock.unlock();
}
}
}
/**
* 预警数据生成
* <p>
* 1、查询st_ivt_forewarningconfig获取正在启用的、未删除的配置
* 2、通过st_ivt_forewarningconfig表的id字段匹配上st_ivt_forewarningmaterial表的config_id字段获取对应的物料。赋值给
* StIvtForewarningconfigDto的tableData
* 3、循环判断每条数据下的对应物料的安全库存数量、入库时间以组盘时间为准
* 其中库存表md_pb_groupplate实体类GroupPlate组盘时间create_time物料编码id material_id
* 4、 分别生成st_ivt_safetyforewarning(安全库存数量超期) 和 st_ivt_overdueforewarning超期天数超期 ,插入到对应数据库中
*/
private void runTask() {
// 1. 删除st_ivt_overdueforewarning、st_ivt_safetyforewarning表中的全部数据
// stIvtOverdueforewarningService.deleteAllNoParam();
// stIvtSafetyforewarningService.deleteAllNoParam();
// 2. 查询st_ivt_forewarningconfig获取正在启用的、未删除的配置
List<StIvtForewarningconfig> configList = forewarningconfigService.list(new LambdaQueryWrapper<StIvtForewarningconfig>()
.eq(StIvtForewarningconfig::getIs_active, true)
.eq(StIvtForewarningconfig::getIs_delete, false));
if (CollectionUtil.isEmpty(configList)) {
return;
}
List<String> configStringList = configList.stream().map(StIvtForewarningconfig::getId).collect(Collectors.toList());
// 获取配置文件下的所有物料
List<StIvtForewarningmaterial> materialList = stIvtForewarningmaterialService.list(new LambdaQueryWrapper<StIvtForewarningmaterial>()
.eq(StIvtForewarningmaterial::getIs_active, true)
.eq(StIvtForewarningmaterial::getIs_delete, false)
.in(StIvtForewarningmaterial::getConfig_id, configStringList));
Set<String> materialCodeList = materialList.stream().map(StIvtForewarningmaterial::getMaterial_code).collect(Collectors.toSet());
Set<String> storCodeList = configList.stream().map(StIvtForewarningconfig::getStor_code).collect(Collectors.toSet());
// 查询库存信息
Map<String, Object> queryMap = new HashMap();
queryMap.put("stor_code_list", storCodeList);
queryMap.put("material_code_list", materialCodeList);
List<MdPbStoragevehicleextDto> mdPbStoragevehicleextDtos = mdPbGroupplateMapper.queryAll(queryMap);
if (CollectionUtil.isEmpty(mdPbStoragevehicleextDtos)) {
return;
}
for (StIvtForewarningconfig config : configList) {
//3. 通过st_ivt_forewarningconfig表的id字段匹配上st_ivt_forewarningmaterial表的config_id字段获取对应的物料
List<StIvtForewarningmaterial> configMaterialList = materialList.stream().
filter(a -> config.getId().equals(a.getConfig_id())).collect(Collectors.toList());
// 按照struct_code对mdPbStoragevehicleextDtos进行分组
Map<String, List<MdPbStoragevehicleextDto>> structCodeGroupMap = mdPbStoragevehicleextDtos.stream()
.filter(a->config.getStor_code().equals(a.getStor_code()))
.collect(Collectors.groupingBy(MdPbStoragevehicleextDto::getStruct_code));
// 4. 循环,判断每条数据下的对应物料的安全库存数量、入库时间(以组盘时间为准)
for (StIvtForewarningmaterial material : configMaterialList) {
// 遍历structCodeGroupMap获取每个struct_code下的mdPbStoragevehicleextDtos
for (Map.Entry<String, List<MdPbStoragevehicleextDto>> entry : structCodeGroupMap.entrySet()) {
List<MdPbStoragevehicleextDto> mdPbStoragevehicleextDtoStructs = entry.getValue();
// 计算安全库存数量
BigDecimal totalQty = mdPbStoragevehicleextDtoStructs.stream()
.filter(a -> config.getStor_code().equals(a.getStor_code())
&& material.getMaterial_id().equals(a.getMaterial_id()))
.map(MdPbStoragevehicleextDto::getQty)
.reduce(BigDecimal.ZERO, BigDecimal::add);
// 计算最早的组盘时间
LocalDateTime earliestPlate = null;
try {
earliestPlate = mdPbStoragevehicleextDtoStructs.stream()
.filter(a -> config.getStor_code().equals(a.getStor_code())
&& material.getMaterial_id().equals(a.getMaterial_id()))
.map(a -> {
try {
String createTimeStr = a.getCreate_time();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return LocalDateTime.parse(createTimeStr, formatter);
} catch (Exception ex) {
// 解析失败返回null
return null;
}
})
.filter(Objects::nonNull)
.min(LocalDateTime::compareTo)
.orElse(null);
} catch (Exception ex) {
// 处理整体异常
earliestPlate = null;
}
// 计算 earliestPlate 与当前时间的天数差返回int类型
BigDecimal daysDiff = BigDecimal.ZERO;
if (earliestPlate != null) {
long millis = java.time.Duration.between(earliestPlate, LocalDateTime.now()).toMillis();
daysDiff = new BigDecimal(millis)
.divide(new BigDecimal(1000 * 60 * 60 * 24), 4, BigDecimal.ROUND_HALF_UP);
}
// 5. 分别生成st_ivt_safetyforewarning(安全库存数量超期) 和 st_ivt_overdueforewarning超期天数超期
// 安全库存数量超限
if ((config.getSafe_qty_lower_limit() != null && totalQty.compareTo(config.getSafe_qty_lower_limit()) < 0)
|| (config.getSafe_qty_upper_limit() != null && totalQty.compareTo(config.getSafe_qty_upper_limit()) > 0)) {
StIvtSafetyforewarning safety = new StIvtSafetyforewarning();
safety.setId(IdUtil.getSnowflake(1, 1).nextIdStr());
safety.setConfig_id(config.getId());
safety.setMaterial_code(material.getMaterial_code());
safety.setMaterial_name(material.getMaterial_name());
safety.setSect_code(mdPbStoragevehicleextDtoStructs.get(0).getSect_code());
safety.setSect_name(mdPbStoragevehicleextDtoStructs.get(0).getSect_name());
safety.setStruct_code(mdPbStoragevehicleextDtoStructs.get(0).getStruct_code());
safety.setStruct_name(mdPbStoragevehicleextDtoStructs.get(0).getStruct_name());
safety.setSafe_qty_lower_limit(config.getSafe_qty_lower_limit());
safety.setSafe_qty_upper_limit(config.getSafe_qty_upper_limit());
safety.setStor_code(config.getStor_code());
safety.setCurrent_qty(totalQty);
safety.setCreate_name("JOB");
safety.setCreate_time(DateUtil.now());
stIvtSafetyforewarningService.save(safety);
}
// 超期天数超期
if (config.getSafe_days() != null && daysDiff.compareTo(config.getSafe_days()) > 0) {
// 将 earliestPlate 转化成 yyyy-MM-dd HH:mm:ss 的String 类型
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String earliestPlateStr = earliestPlate.format(formatter);
StIvtOverdueforewarning overdue = new StIvtOverdueforewarning();
overdue.setId(IdUtil.getSnowflake(1, 1).nextIdStr());
overdue.setConfig_id(config.getId());
overdue.setMaterial_code(material.getMaterial_code());
overdue.setMaterial_name(material.getMaterial_name());
overdue.setOverdue_days(daysDiff);
overdue.setStor_code(config.getStor_code());
overdue.setSect_code(mdPbStoragevehicleextDtoStructs.get(0).getSect_code());
overdue.setSect_name(mdPbStoragevehicleextDtoStructs.get(0).getSect_name());
overdue.setStruct_code(mdPbStoragevehicleextDtoStructs.get(0).getStruct_code());
overdue.setStruct_name(mdPbStoragevehicleextDtoStructs.get(0).getStruct_name());
overdue.setSafe_days(config.getSafe_days());
overdue.setInsert_time(earliestPlateStr);
overdue.setCreate_name("JOB");
overdue.setCreate_time(DateUtil.now());
stIvtOverdueforewarningService.save(overdue);
}
}
}
}
}
}