feat(生产进站):编码规则
This commit is contained in:
parent
ebe14de71d
commit
03f0a63393
@ -6,4 +6,6 @@ package com.foreverwin.iep.prd.constant;
|
||||
public interface OperationCustomFieldsConstants {
|
||||
|
||||
String NEXT_NUMBER_TYPE = "NEXT_NUMBER_TYPE";
|
||||
|
||||
String IS_FIND_PARENT = "IS_FIND_PARENT";
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package com.foreverwin.iep.prd.constant;
|
||||
|
||||
/**
|
||||
* Created by Syngna on 2020/2/1.
|
||||
*/
|
||||
public interface ShopOrderCustomFieldsConstants {
|
||||
|
||||
String XF_ITEM_TYPE = "XF_ITEM_TYPE";
|
||||
}
|
||||
@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, mom All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the foreverwin.com developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: mom
|
||||
*/
|
||||
|
||||
package com.foreverwin.iep.sys.entity;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import com.foreverwin.iep.common.utils.HandleBoProcessor;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author hipi
|
||||
* @date 2023-04-17 17:16:02
|
||||
*/
|
||||
@Data
|
||||
@TableName("z_next_number")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(value = "")
|
||||
public class ZNextNumber extends Model<ZNextNumber> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
public static final String KW_ZNEXT_NUMBER_BO = "NextNumberBO";
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value="主键")
|
||||
private String handle;
|
||||
|
||||
/**
|
||||
* 站点
|
||||
*/
|
||||
@ApiModelProperty(value="站点")
|
||||
private String site;
|
||||
|
||||
/**
|
||||
* 编号类型
|
||||
*/
|
||||
@ApiModelProperty(value="编号类型")
|
||||
private String numberType;
|
||||
|
||||
/**
|
||||
* 前缀
|
||||
*/
|
||||
@ApiModelProperty(value="前缀")
|
||||
private String prefix;
|
||||
|
||||
/**
|
||||
* 后缀
|
||||
*/
|
||||
@ApiModelProperty(value="后缀")
|
||||
private String suffix;
|
||||
|
||||
/**
|
||||
* 序列长度
|
||||
*/
|
||||
@ApiModelProperty(value="序列长度")
|
||||
private BigDecimal sequenceLength;
|
||||
|
||||
/**
|
||||
* 样本
|
||||
*/
|
||||
@ApiModelProperty(value="样本")
|
||||
private String sample;
|
||||
|
||||
/**
|
||||
* 重复:日:Day;永不:NoEver;月:Mouth;年:Year
|
||||
*/
|
||||
@ApiModelProperty(value="重复:日:Day;永不:NoEver;月:Mouth;年:Year")
|
||||
private String repetition;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@ApiModelProperty(value = "描述")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* startSequence
|
||||
*/
|
||||
@ApiModelProperty(value="startSequence")
|
||||
private BigDecimal startSequence;
|
||||
|
||||
/**
|
||||
* 是否允许跳号(Y:允许 N:不允许)
|
||||
*/
|
||||
@ApiModelProperty(value="是否允许跳号(Y:允许 N:不允许)")
|
||||
private String skipNumber;
|
||||
|
||||
/**
|
||||
* 序列号进制数
|
||||
*/
|
||||
@ApiModelProperty(value="序列号进制数")
|
||||
private BigDecimal sequenceBase;
|
||||
|
||||
/**
|
||||
* 创建日期
|
||||
*/
|
||||
private LocalDateTime dateCreate;
|
||||
|
||||
/**
|
||||
* 创建人员
|
||||
*/
|
||||
@ApiModelProperty(value="创建人员")
|
||||
private String creator;
|
||||
|
||||
/**
|
||||
* 更新日期
|
||||
*/
|
||||
@ApiModelProperty(value="更新日期")
|
||||
private LocalDateTime dateUpdate;
|
||||
|
||||
/**
|
||||
* 更新人员
|
||||
*/
|
||||
@ApiModelProperty(value="更新人员")
|
||||
private String updater;
|
||||
|
||||
public static String genHandle(String site, String nextNumberType) {
|
||||
return HandleBoProcessor.genHandle(KW_ZNEXT_NUMBER_BO, site, nextNumberType);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, mom All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the foreverwin.com developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: mom
|
||||
*/
|
||||
|
||||
package com.foreverwin.iep.sys.entity;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import com.foreverwin.iep.common.utils.HandleBoProcessor;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author hipi
|
||||
* @date 2023-04-17 17:16:18
|
||||
*/
|
||||
@Data
|
||||
@TableName("z_next_number_code")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(value = "")
|
||||
public class ZNextNumberCode extends Model<ZNextNumberCode> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final String KW_NEXT_NUMBER_CODE_BO = "NextNumberCodeBO";
|
||||
|
||||
/**
|
||||
* handle
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value="handle")
|
||||
private String handle;
|
||||
|
||||
/**
|
||||
* site
|
||||
*/
|
||||
@ApiModelProperty(value="site")
|
||||
private String site;
|
||||
|
||||
/**
|
||||
* nextNumberBo
|
||||
*/
|
||||
@ApiModelProperty(value="nextNumberBo")
|
||||
private String nextNumberBo;
|
||||
|
||||
/**
|
||||
* code
|
||||
*/
|
||||
@ApiModelProperty(value="code")
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* currentSeq
|
||||
*/
|
||||
@ApiModelProperty(value="currentSeq")
|
||||
private BigDecimal currentSeq;
|
||||
|
||||
/**
|
||||
* modifiedDateTime
|
||||
*/
|
||||
@ApiModelProperty(value="modifiedDateTime")
|
||||
private LocalDateTime modifiedDateTime;
|
||||
|
||||
public static String genHandle(String site, String nextNumberType, String code) {
|
||||
return HandleBoProcessor.genHandle(KW_NEXT_NUMBER_CODE_BO, site, nextNumberType, code);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package com.foreverwin.iep.wip.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class EqpFeedingLotItemGroupInfo {
|
||||
|
||||
private String itemGroup;
|
||||
|
||||
private String materialLot;
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
package com.foreverwin.iep.common.utils;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Locale;
|
||||
|
||||
public final class RadixNumberUtil
|
||||
{
|
||||
@ -24,4 +25,43 @@ public final class RadixNumberUtil
|
||||
public static String format(long number, int radix) {
|
||||
return Long.toString(number, radix);
|
||||
}
|
||||
|
||||
public static final String toStringWithBase(long number, int base) {
|
||||
String temp = format(number, base).toUpperCase(Locale.ENGLISH);
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
if (base != 34)
|
||||
return temp;
|
||||
for (int i = 0; i < temp.length(); i++) {
|
||||
char c = temp.charAt(i);
|
||||
if (c >= 'I') {
|
||||
c = (char)(c + '\001');
|
||||
}
|
||||
if (c >= 'O') {
|
||||
c = (char)(c + '\001');
|
||||
}
|
||||
sb.append(c);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static long toLongWithBase(String number, int base) {
|
||||
if (base != 34) {
|
||||
return parseLong(number, base);
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
for (int i = 0; i < number.length(); i++) {
|
||||
char c = number.charAt(i);
|
||||
if (c > 'I') {
|
||||
c = (char)(c - '\001');
|
||||
}
|
||||
if (c > 'O') {
|
||||
c = (char)(c - '\001');
|
||||
}
|
||||
sb.append(c);
|
||||
}
|
||||
return parseLong(sb.toString(), base);
|
||||
}
|
||||
}
|
||||
@ -15,5 +15,5 @@ public interface UserWorkShiftService extends IService<UserWorkShift> {
|
||||
|
||||
boolean updateFullById(UserWorkShift userWorkShift);
|
||||
|
||||
UserWorkShift getCurrentShift(String site);
|
||||
String getCurrentShift(String site);
|
||||
}
|
||||
|
||||
@ -495,6 +495,9 @@ public class ShopOrderServiceImpl extends ServiceImpl<ShopOrderMapper, ShopOrder
|
||||
throw new ProductionException(I18nUtil.getI18nText("iep.error5", shopOrder.getShopOrder()));
|
||||
}
|
||||
BigDecimal qtyReleased = genShopOrder.getQtyReleased(); // 已下达数量
|
||||
if(qtyReleased == null) {
|
||||
qtyReleased = BigDecimal.ZERO;
|
||||
}
|
||||
BigDecimal releasableQty = genShopOrder.getQty().subtract(qtyReleased);// 可下达数量
|
||||
String bomBo = shopOrder.getPlannedBomBo();
|
||||
String operationBo = Operation.genHandle(site, ProductionBaseConstants.MO_RELEASE, BaseConstants.CURRENT_REVISION);
|
||||
|
||||
@ -2,6 +2,7 @@ package com.foreverwin.iep.prd.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.foreverwin.iep.pod.entity.PodModule;
|
||||
@ -12,6 +13,7 @@ import com.foreverwin.iep.prd.mapper.WorkGroupCalendarMapper;
|
||||
import com.foreverwin.iep.prd.domain.SaveCustomDataRequest;
|
||||
import com.foreverwin.iep.prd.service.CustomFieldsService;
|
||||
import com.foreverwin.iep.prd.service.UserWorkShiftService;
|
||||
import com.foreverwin.iep.wip.dto.OperationOutDTO;
|
||||
import com.foreverwin.mom.common.core.exception.BusinessException;
|
||||
import com.foreverwin.mom.common.core.util.I18nUtil;
|
||||
import com.foreverwin.mom.common.security.util.SecurityUtils;
|
||||
@ -20,6 +22,8 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -100,18 +104,43 @@ public class UserWorkShiftServiceImpl extends ServiceImpl<UserWorkShiftMapper, U
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserWorkShift getCurrentShift(String site) {
|
||||
// 获取当前时间对应的事件字符串,格式为 HH:mm
|
||||
String currentTime = LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("HH:mm"));
|
||||
// 获取currentTime在shiftFrom和shiftTo之间的数据,有可能跨天shiftFrom大于shiftTo
|
||||
// sql 判断字符串在时间区间内,有可能跨天shiftFrom大于shiftTo
|
||||
List<UserWorkShift> userWorkShiftList = this.list(Wrappers.<UserWorkShift>lambdaQuery().eq(UserWorkShift::getSite, site)
|
||||
.and(wrapper -> wrapper.ge(UserWorkShift::getShiftFrom, currentTime)
|
||||
.lt(UserWorkShift::getShiftTo, currentTime).or()
|
||||
.ge(UserWorkShift::getShiftTo, currentTime)
|
||||
.lt(UserWorkShift::getShiftFrom, currentTime)));
|
||||
return userWorkShiftList == null || userWorkShiftList.isEmpty() ? null : userWorkShiftList.get(0);
|
||||
|
||||
public String getCurrentShift(String site) {
|
||||
// 班制ID
|
||||
String userWorkShiftId = "";
|
||||
// 获取当前时间
|
||||
LocalTime currentTime = LocalTime.now();
|
||||
// 使用 DateTimeFormatter 格式化时间
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
|
||||
String formattedTime = currentTime.format(formatter);
|
||||
LocalTime timeToCheck = LocalTime.parse(formattedTime);
|
||||
// 获取班制时间
|
||||
List<UserWorkShift> userWorkShiftList = this.list(Wrappers.<UserWorkShift>lambdaQuery()
|
||||
.eq(UserWorkShift::getSite, site)
|
||||
);
|
||||
if (CollectionUtils.isNotEmpty(userWorkShiftList)) {
|
||||
for (UserWorkShift userWorkShift : userWorkShiftList) {
|
||||
// 指定时间区间
|
||||
LocalTime startTime = LocalTime.parse(userWorkShift.getShiftFrom(), formatter);
|
||||
LocalTime endTime = LocalTime.parse(userWorkShift.getShiftTo(), formatter);
|
||||
// 判断时间是否在区间内
|
||||
if (isTimeInRange(timeToCheck, startTime, endTime)) {
|
||||
// 在区间内直接赋值后跳出
|
||||
userWorkShiftId = userWorkShift.getUserWorkShift();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return userWorkShiftId;
|
||||
}
|
||||
|
||||
// 判断时间是否在给定的时间区间内
|
||||
public static boolean isTimeInRange(LocalTime timeToCheck, LocalTime startTime, LocalTime endTime) {
|
||||
// 如果结束时间小于开始时间,表示跨天的区间,需要特殊处理
|
||||
if (endTime.isBefore(startTime)) {
|
||||
return timeToCheck.isAfter(startTime) || timeToCheck.isBefore(endTime);
|
||||
} else {
|
||||
return timeToCheck.isAfter(startTime) && timeToCheck.isBefore(endTime);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateBeforeSaveOrUpdate(UserWorkShift userWorkShift) {
|
||||
|
||||
@ -0,0 +1,245 @@
|
||||
package com.foreverwin.iep.sys.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.foreverwin.iep.prd.domain.GenerateNextNumberRequest;
|
||||
import com.foreverwin.iep.sys.entity.ZNextNumber;
|
||||
import com.foreverwin.iep.sys.entity.ZNextNumberCode;
|
||||
import com.foreverwin.iep.sys.service.ZNextNumberCodeService;
|
||||
import com.foreverwin.iep.sys.service.ZNextNumberService;
|
||||
import com.foreverwin.mom.common.core.exception.BusinessException;
|
||||
import com.foreverwin.mom.common.core.util.R;
|
||||
import com.foreverwin.mom.common.data.tenant.TenantContextHolder;
|
||||
import com.foreverwin.mom.common.excel.annotation.ResponseExcel;
|
||||
import com.foreverwin.mom.common.log.annotation.SysLog;
|
||||
import com.foreverwin.mom.common.security.util.SecurityUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author hipi
|
||||
* @date 2023-04-17 17:16:02
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/z-next-number" )
|
||||
@Api(value = "z-next-number", tags = "管理")
|
||||
public class ZNextNumberController {
|
||||
|
||||
private final ZNextNumberService zNextNumberService;
|
||||
|
||||
private final ZNextNumberCodeService nextNumberCodeService;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param page 分页对象
|
||||
* @param zNextNumber
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "分页查询", notes = "分页查询")
|
||||
@GetMapping("/page" )
|
||||
@PreAuthorize("@pms.hasPermission('generator_znextnumber_view')" )
|
||||
public R getZNextNumberPage(Page page, ZNextNumber zNextNumber) {
|
||||
return R.ok(zNextNumberService.page(page, Wrappers.query(zNextNumber)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
* @param handle id
|
||||
* @return R
|
||||
*/
|
||||
@ApiOperation(value = "通过id查询", notes = "通过id查询")
|
||||
@GetMapping("/{handle}" )
|
||||
@PreAuthorize("@pms.hasPermission('generator_znextnumber_view')" )
|
||||
public R getById(@PathVariable("handle" ) String handle) {
|
||||
return R.ok(zNextNumberService.getById(handle));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* @param zNextNumber
|
||||
* @return R
|
||||
*/
|
||||
@ApiOperation(value = "新增", notes = "新增")
|
||||
@SysLog("新增" )
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('generator_znextnumber_add')" )
|
||||
public R save(@RequestBody ZNextNumber zNextNumber) {
|
||||
return R.ok(zNextNumberService.save(zNextNumber));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param zNextNumber
|
||||
* @return R
|
||||
*/
|
||||
@ApiOperation(value = "修改", notes = "修改")
|
||||
@SysLog("修改" )
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('generator_znextnumber_edit')" )
|
||||
public R updateById(@RequestBody ZNextNumber zNextNumber) {
|
||||
return R.ok(zNextNumberService.updateById(zNextNumber));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
* @param handle id
|
||||
* @return R
|
||||
*/
|
||||
@ApiOperation(value = "通过id删除", notes = "通过id删除")
|
||||
@SysLog("通过id删除" )
|
||||
@DeleteMapping("/{handle}" )
|
||||
@PreAuthorize("@pms.hasPermission('production_next_number_del')" )
|
||||
public R removeById(@PathVariable String handle) {
|
||||
List<ZNextNumberCode> result = nextNumberCodeService.list(Wrappers.lambdaQuery(ZNextNumberCode.class).eq(ZNextNumberCode::getNextNumberBo, handle));
|
||||
if (result.size() > 0){
|
||||
throw BusinessException.build("该编码规则已使用,不允许删除");
|
||||
}else {
|
||||
zNextNumberService.removeById(handle);
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出excel 表格
|
||||
* @param zNextNumber 查询条件
|
||||
* @return excel 文件流
|
||||
*/
|
||||
@ResponseExcel
|
||||
@GetMapping("/export")
|
||||
@PreAuthorize("@pms.hasPermission('generator_znextnumber_export')" )
|
||||
public List<ZNextNumber> export(ZNextNumber zNextNumber) {
|
||||
return zNextNumberService.list(Wrappers.query(zNextNumber));
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping("/selectByNumberType")
|
||||
public R selectByNumberType(ZNextNumber zNextNumber) {
|
||||
String site = TenantContextHolder.getTenantId();
|
||||
String numberType = zNextNumber.getNumberType();
|
||||
|
||||
if (StrUtil.isBlank(numberType)) {
|
||||
throw BusinessException.build("编号类型不能为空");
|
||||
}
|
||||
|
||||
String handle = ZNextNumber.genHandle(site, numberType);
|
||||
ZNextNumber result = zNextNumberService.getById(handle);
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/saveNumberType")
|
||||
@PreAuthorize("@pms.hasPermission('production_next_number_save')" )
|
||||
public R saveNumberType(@RequestBody ZNextNumber zNextNumber) {
|
||||
try {
|
||||
String site = TenantContextHolder.getTenantId();
|
||||
String user = SecurityUtils.getUserName();
|
||||
String numberType = zNextNumber.getNumberType();
|
||||
String handle = ZNextNumber.genHandle(site, numberType);
|
||||
|
||||
String prefix = zNextNumber.getPrefix();
|
||||
String suffix = zNextNumber.getSuffix();
|
||||
BigDecimal sequenceLength = zNextNumber.getSequenceLength();
|
||||
String sample = zNextNumber.getSample();
|
||||
String repetition = zNextNumber.getRepetition();
|
||||
String description = zNextNumber.getDescription();
|
||||
String skipNumber = zNextNumber.getSkipNumber();
|
||||
Long sequenceBase = zNextNumber.getSequenceBase().longValue();
|
||||
BigDecimal startSequence = zNextNumber.getStartSequence();
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
if (!StrUtil.isBlank(prefix)) {
|
||||
prefix = prefix.toUpperCase();
|
||||
}
|
||||
if (!StrUtil.isBlank(suffix)) {
|
||||
suffix = suffix.toUpperCase();
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
if (StrUtil.isBlank(numberType)) {
|
||||
throw BusinessException.build("编号类型不能为空");
|
||||
}
|
||||
if (sequenceLength == null) {
|
||||
throw BusinessException.build("序列长度不能为空");
|
||||
}
|
||||
if (startSequence.compareTo(BigDecimal.ZERO) <= 0){
|
||||
throw BusinessException.build("开始序列必须大于0");
|
||||
}
|
||||
|
||||
if (sequenceBase == 0) {
|
||||
sequenceBase = 10L;
|
||||
}
|
||||
|
||||
ZNextNumber oldNumberRule = zNextNumberService.getById(handle);
|
||||
List<ZNextNumberCode> oldNumberRuleCode = nextNumberCodeService.list(Wrappers.lambdaQuery(ZNextNumberCode.class).eq(ZNextNumberCode::getNextNumberBo, handle));
|
||||
if (oldNumberRuleCode.size() > 0){
|
||||
if (oldNumberRule.getSequenceBase().longValue() != (sequenceBase)){
|
||||
throw BusinessException.build("该编码规则已使用,进制数不允许修改");
|
||||
}
|
||||
if (oldNumberRule.getSequenceLength().compareTo(sequenceLength) > 0){
|
||||
throw BusinessException.build("该编码规则已使用,序列长度只能改大,不允许改小");
|
||||
}
|
||||
if (!oldNumberRule.getRepetition().equals(repetition)){
|
||||
throw BusinessException.build("该编码规则已使用,重置序号不允许修改");
|
||||
}
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
ZNextNumber nextNumber = new ZNextNumber();
|
||||
if (oldNumberRule != null) {
|
||||
oldNumberRule.setPrefix(prefix);
|
||||
oldNumberRule.setSuffix(suffix);
|
||||
oldNumberRule.setSequenceLength(sequenceLength);
|
||||
oldNumberRule.setSample(sample);
|
||||
oldNumberRule.setRepetition(repetition);
|
||||
oldNumberRule.setDescription(description);
|
||||
oldNumberRule.setStartSequence(startSequence);
|
||||
oldNumberRule.setSequenceBase(new BigDecimal(sequenceBase));
|
||||
oldNumberRule.setSkipNumber(skipNumber);
|
||||
oldNumberRule.setUpdater(user);
|
||||
oldNumberRule.setDateUpdate(LocalDateTime.now());
|
||||
zNextNumberService.updateById(oldNumberRule);
|
||||
} else {
|
||||
nextNumber.setHandle(handle);
|
||||
nextNumber.setSite(site);
|
||||
nextNumber.setNumberType(numberType);
|
||||
nextNumber.setPrefix(prefix);
|
||||
nextNumber.setSuffix(suffix);
|
||||
nextNumber.setSequenceLength(sequenceLength);
|
||||
nextNumber.setSample(sample);
|
||||
nextNumber.setRepetition(repetition);
|
||||
nextNumber.setDescription(description);
|
||||
nextNumber.setStartSequence(startSequence);
|
||||
nextNumber.setSequenceBase(new BigDecimal(sequenceBase));
|
||||
nextNumber.setSkipNumber(skipNumber);
|
||||
nextNumber.setCreator(user);
|
||||
nextNumber.setDateCreate(LocalDateTime.now());
|
||||
zNextNumberService.save(nextNumber);
|
||||
}//if
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
return R.ok("保存成功");
|
||||
} catch (Exception e) {
|
||||
return R.failed(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/getNextNumber")
|
||||
public R getNextNumber(@RequestBody GenerateNextNumberRequest generateNextNumberRequest){
|
||||
String site = TenantContextHolder.getTenantId();
|
||||
String numberType = generateNextNumberRequest.getNextNumberType();
|
||||
int qty = generateNextNumberRequest.getNumberOfValues();
|
||||
Map paramMap = generateNextNumberRequest.getCustomData();
|
||||
return R.ok(zNextNumberService.getNextNumber(site, numberType, qty, paramMap));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package com.foreverwin.iep.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.foreverwin.iep.sys.entity.ZNextNumber;
|
||||
import com.foreverwin.iep.sys.entity.ZNextNumberCode;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author hipi
|
||||
* @date 2023-04-17 17:16:18
|
||||
*/
|
||||
public interface ZNextNumberCodeService extends IService<ZNextNumberCode> {
|
||||
|
||||
ZNextNumberCode selectForUpdateById(String id);
|
||||
|
||||
Integer getCodeSequence(String site, int qty, String code, ZNextNumber zNextNumber);
|
||||
|
||||
Integer getCodeSequenceByIsolatedTransaction(String site, int qty, String code, ZNextNumber zNextNumber);
|
||||
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package com.foreverwin.iep.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.foreverwin.iep.sys.entity.ZNextNumber;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author hipi
|
||||
* @date 2023-04-17 17:16:02
|
||||
*/
|
||||
public interface ZNextNumberService extends IService<ZNextNumber> {
|
||||
|
||||
List<String> getNextNumber(String site, String numberType, int qty, Map paramMap);
|
||||
}
|
||||
@ -0,0 +1,138 @@
|
||||
package com.foreverwin.iep.sys.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.foreverwin.iep.sys.entity.ZNextNumber;
|
||||
import com.foreverwin.iep.sys.entity.ZNextNumberCode;
|
||||
import com.foreverwin.iep.sys.mapper.ZNextNumberCodeMapper;
|
||||
import com.foreverwin.iep.sys.service.ZNextNumberCodeService;
|
||||
import com.foreverwin.mom.common.core.exception.BusinessException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author hipi
|
||||
* @date 2023-04-17 17:16:18
|
||||
*/
|
||||
@Service
|
||||
public class ZNextNumberCodeServiceImpl extends ServiceImpl<ZNextNumberCodeMapper, ZNextNumberCode> implements ZNextNumberCodeService {
|
||||
|
||||
@Override
|
||||
public ZNextNumberCode selectForUpdateById(String id) {
|
||||
return baseMapper.selectForUpdateById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
|
||||
public Integer getCodeSequenceByIsolatedTransaction(String site, int qty, String code, ZNextNumber nextNumber) {
|
||||
return getCodeSequence(site, qty, code, nextNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getCodeSequence(String site, int qty, String code, ZNextNumber nextNumber) {
|
||||
//查询编号是否存在
|
||||
String currentSeq;
|
||||
String sequenceLength = StrUtil.toString(nextNumber.getSequenceLength());
|
||||
String handle = ZNextNumberCode.genHandle(site, nextNumber.getNumberType(), code);
|
||||
ZNextNumberCode nextNumberCode = selectForUpdateById(handle);
|
||||
//计算当前序列号:编号不存在时,当前序列等于生成编号的个数,否则等于查询的序列号+生成编号个数
|
||||
if (nextNumberCode == null) {
|
||||
if (nextNumber.getStartSequence() == null) {
|
||||
currentSeq = qty + "";
|
||||
} else {
|
||||
currentSeq = (nextNumber.getStartSequence().intValue() -1 + qty) + "";
|
||||
}
|
||||
} else {
|
||||
String reset = StrUtil.toString(nextNumber.getRepetition());
|
||||
boolean isReset = isReset(nextNumberCode, reset);
|
||||
if (isReset) {
|
||||
if (nextNumber.getStartSequence() == null) {
|
||||
currentSeq = qty + "";
|
||||
} else {
|
||||
currentSeq = (nextNumber.getStartSequence().intValue() -1 + qty) + "";
|
||||
}
|
||||
} else {
|
||||
currentSeq = (nextNumberCode.getCurrentSeq().longValue() + qty) + "";
|
||||
}
|
||||
}//if
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
//流水号检测最大值
|
||||
long sequenceBase = nextNumber.getSequenceBase() == null || nextNumber.getSequenceBase().longValue() <= 0 ? 10 : nextNumber.getSequenceBase().longValue();
|
||||
long maxSeq = BigDecimal.valueOf(Math.pow(sequenceBase, Long.parseLong(sequenceLength))).longValue() -1;
|
||||
if (maxSeq < Long.parseLong(currentSeq)) throw BusinessException.build("编号类型"+nextNumber.getNumberType()+"序号已达到上限,不可使用");
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
String _currentSeq;
|
||||
if (nextNumberCode == null) {
|
||||
//新增
|
||||
if (nextNumber.getStartSequence() == null) {
|
||||
_currentSeq = "0";
|
||||
} else {
|
||||
_currentSeq = (nextNumber.getStartSequence().intValue()-1) + "";
|
||||
}//if
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
ZNextNumberCode entity = new ZNextNumberCode();
|
||||
entity.setHandle(handle);
|
||||
entity.setSite(site);
|
||||
entity.setNextNumberBo(nextNumber.getHandle());
|
||||
entity.setCode(code);
|
||||
entity.setCurrentSeq(new BigDecimal(currentSeq));
|
||||
entity.setModifiedDateTime(LocalDateTime.now());
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
save(entity);
|
||||
} else {
|
||||
//修改
|
||||
String reset = StrUtil.toString(nextNumber.getRepetition());
|
||||
boolean isReset = isReset(nextNumberCode, reset);
|
||||
if (isReset) {
|
||||
if (nextNumber.getStartSequence() == null) {
|
||||
_currentSeq = "0";
|
||||
} else {
|
||||
_currentSeq = (nextNumber.getStartSequence().intValue()-1) + "";
|
||||
}
|
||||
} else {
|
||||
_currentSeq = nextNumberCode.getCurrentSeq().longValue() + "";
|
||||
}//if
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime modifiedTime = nextNumberCode.getModifiedDateTime();
|
||||
if (modifiedTime.format(df).equals(now.format(df)) && new BigDecimal(currentSeq).compareTo(nextNumberCode.getCurrentSeq()) <=0) {
|
||||
throw BusinessException.build("未找到编码类型"+nextNumber.getNumberType()+"的编码规则");
|
||||
}
|
||||
nextNumberCode.setCurrentSeq(new BigDecimal(currentSeq));
|
||||
nextNumberCode.setModifiedDateTime(now);
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
updateById(nextNumberCode);
|
||||
}//if
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
return Integer.parseInt(_currentSeq);
|
||||
}
|
||||
|
||||
public static boolean isReset(ZNextNumberCode nextNumberCode, String reset) {
|
||||
if (nextNumberCode == null) {
|
||||
return false;
|
||||
}
|
||||
if (reset.equalsIgnoreCase("N")) {
|
||||
return false;
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
LocalDateTime modifyDate = nextNumberCode.getModifiedDateTime();
|
||||
if (reset.equalsIgnoreCase("Y")) {
|
||||
return LocalDateTime.now().toLocalDate().withDayOfYear(1).atStartOfDay().compareTo(modifyDate.toLocalDate().with(TemporalAdjusters.firstDayOfNextYear()).atStartOfDay()) > 0;
|
||||
} else if(reset.equalsIgnoreCase("M")) {
|
||||
return LocalDateTime.now().toLocalDate().withDayOfMonth(1).atStartOfDay().compareTo(modifyDate.toLocalDate().with(TemporalAdjusters.firstDayOfNextMonth()).atStartOfDay()) > 0;
|
||||
} else if(reset.equalsIgnoreCase("D")) {
|
||||
return LocalDateTime.now().toLocalDate().atStartOfDay().compareTo(modifyDate.toLocalDate().atStartOfDay()) > 0;
|
||||
}//if
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,182 @@
|
||||
package com.foreverwin.iep.sys.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.foreverwin.iep.common.utils.RadixNumberUtil;
|
||||
import com.foreverwin.iep.sys.entity.ZNextNumber;
|
||||
import com.foreverwin.iep.sys.mapper.ZNextNumberMapper;
|
||||
import com.foreverwin.iep.sys.service.ZNextNumberCodeService;
|
||||
import com.foreverwin.iep.sys.service.ZNextNumberService;
|
||||
import com.foreverwin.mom.common.core.exception.BusinessException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author hipi
|
||||
* @date 2023-04-17 17:16:02
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class ZNextNumberServiceImpl extends ServiceImpl<ZNextNumberMapper, ZNextNumber> implements ZNextNumberService {
|
||||
|
||||
static public final String KW_YY = "{YY}";
|
||||
|
||||
static public final String KW_YYYY = "{YYYY}";
|
||||
|
||||
static public final String KW_MM = "{MM}";
|
||||
|
||||
static public final String KW_DD = "{DD}";
|
||||
|
||||
static public final String KW_HH = "{HH}";
|
||||
|
||||
static public final String KW_YY_MM_DD = "{YYMMDD}";
|
||||
|
||||
static public final String KW_YYYY_MM_DD = "{YYYYMMDD}";
|
||||
|
||||
private final ZNextNumberCodeService nextNumberCodeService;
|
||||
|
||||
@Override
|
||||
public List<String> getNextNumber(String site, String numberType, int qty, Map paramMap) {
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
ZNextNumber nextNumber = getById(ZNextNumber.genHandle(site, numberType));
|
||||
if (nextNumber == null) {
|
||||
throw BusinessException.build(String.format("该编码类型【%s】未维护编码规则", numberType));
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
String prefix = nextNumber.getPrefix() != null ? StrUtil.toString(nextNumber.getPrefix()) : "";
|
||||
String code = preparePrefix(prefix);
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
String postfix = nextNumber.getSuffix() != null ? StrUtil.toString(nextNumber.getSuffix()) : "";
|
||||
postfix = preparePrefix(postfix);
|
||||
String sequenceLength = StrUtil.toString(nextNumber.getSequenceLength());
|
||||
long sequenceBase = nextNumber.getSequenceBase() == null || nextNumber.getSequenceBase().longValue() <= 0 ? 10 : nextNumber.getSequenceBase().longValue();
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
//判断是否传入自定义字段
|
||||
if (paramMap != null) {
|
||||
//postfix 替换自定义字段
|
||||
postfix = preparePrefix(postfix, paramMap);
|
||||
//code增加自定义字段
|
||||
code = preparePrefix(code, paramMap);
|
||||
}//if
|
||||
if (StrUtil.isBlank(code)) {
|
||||
throw BusinessException.build(String.format("编码规则【%s】【%s】替换变量后仍然为空值,请检查编码规则维护是否正确", nextNumber.getNumberType(), nextNumber.getDescription()));
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
int currentMaxSequence = 0;
|
||||
if ("Y".equals(nextNumber.getSkipNumber())) {
|
||||
currentMaxSequence = nextNumberCodeService.getCodeSequenceByIsolatedTransaction(site, qty, code, nextNumber);
|
||||
} else {
|
||||
currentMaxSequence = nextNumberCodeService.getCodeSequence(site, qty, code, nextNumber);
|
||||
}//if
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
//生成编号结果集
|
||||
List<String> numberList = new ArrayList();
|
||||
for (int i = 1; i <= qty; i++) {
|
||||
String lastNumber = "";
|
||||
int seq = currentMaxSequence + i;
|
||||
String _seq = RadixNumberUtil.toStringWithBase(seq, (int)sequenceBase);
|
||||
lastNumber = code + space(_seq, Integer.parseInt(sequenceLength)) + postfix;
|
||||
numberList.add(lastNumber);
|
||||
}//for
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
return numberList;
|
||||
}
|
||||
|
||||
public String preparePrefix(String prefix) {
|
||||
String temp = "";
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Timestamp(System.currentTimeMillis()));
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
int year = calendar.get(Calendar.YEAR);
|
||||
int month = calendar.get(Calendar.MONTH) + 1;
|
||||
int day = calendar.get(Calendar.DATE);
|
||||
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||
temp = space(year, 4);
|
||||
prefix = replace(prefix, KW_YYYY, temp);
|
||||
temp = space(year % 100, 2);
|
||||
prefix = replace(prefix, KW_YY, temp);
|
||||
temp = space(month, 2);
|
||||
prefix = replace(prefix, KW_MM, temp);
|
||||
temp = space(day, 2);
|
||||
prefix = replace(prefix, KW_DD, temp);
|
||||
temp = space(hour, 2);
|
||||
prefix = replace(prefix, KW_HH, temp);
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
temp = space(year % 100, 2) +space(month, 2)+space(day, 2);
|
||||
prefix = replace(prefix, KW_YY_MM_DD, temp);
|
||||
temp = space(year, 4)+space(month, 2)+space(day, 2);
|
||||
prefix = replace(prefix, KW_YYYY_MM_DD, temp);
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public String preparePrefix(String prefix, Map paramMap) {
|
||||
Iterator<Map.Entry<String, String>> iterator = paramMap.entrySet().iterator();
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, String> entry = iterator.next();
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
prefix = replace(prefix, "{" + key + "}", value);
|
||||
}//while
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public String space(String value, int slotcnt) {
|
||||
return space(value, '0', slotcnt);
|
||||
}
|
||||
|
||||
public String space(int value, int slotcnt) {
|
||||
return space(value + "", '0', slotcnt);
|
||||
}
|
||||
|
||||
public String space(String str, char spacer, int slotcnt) {
|
||||
if (slotcnt <= 0) {
|
||||
return "";
|
||||
}
|
||||
if (str.length() >= slotcnt) {
|
||||
return str;
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
StringBuffer str_buf = new StringBuffer();
|
||||
slotcnt = slotcnt - str.length();
|
||||
for (int i = 0; i < slotcnt; i++) {
|
||||
str_buf.append(spacer);
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
str_buf.append(str);
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
return str_buf.toString();
|
||||
}
|
||||
|
||||
public String replace(String str, String replaced, String replacement) {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
if (str.equals("")) {
|
||||
return "";
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
StringBuilder str_buf = new StringBuilder();
|
||||
int start = 0, i = 0;
|
||||
i = str.indexOf(replaced, start);
|
||||
while (i >= 0) {
|
||||
str_buf.append(str.substring(start, i));
|
||||
str_buf.append(replacement);
|
||||
start = i + replaced.length();
|
||||
i = str.indexOf(replaced, start);
|
||||
}//while
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
if (start < str.length()) {
|
||||
str_buf.append(str.substring(start));
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
return str_buf.toString();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package com.foreverwin.iep.wip.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 在制品通用服务接口
|
||||
*
|
||||
* @version 1.0
|
||||
* @since 2024-11-12
|
||||
*/
|
||||
public interface NlvWipCommonService {
|
||||
|
||||
|
||||
List<String> genOpNextNumber(String site, String operation, String resrce, String shopOrder,
|
||||
Map<String, Object> customData, Integer numberOfValues);
|
||||
}
|
||||
@ -1,19 +1,25 @@
|
||||
package com.foreverwin.iep.wip.service.impl;
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.foreverwin.iep.common.base.FrontPage;
|
||||
import com.foreverwin.iep.common.exceptions.ProductionException;
|
||||
import com.foreverwin.iep.common.model.CustomValue;
|
||||
import com.foreverwin.iep.prd.constant.OperationCustomFieldsConstants;
|
||||
import com.foreverwin.iep.prd.constant.ShopOrderCustomFieldsConstants;
|
||||
import com.foreverwin.iep.prd.domain.GenerateNextNumberRequest;
|
||||
import com.foreverwin.iep.prd.domain.GenerateNextNumberResponse;
|
||||
import com.foreverwin.iep.prd.domain.ReleaseShopOrderResponse;
|
||||
import com.foreverwin.iep.prd.dto.ShopOrderDTO;
|
||||
import com.foreverwin.iep.prd.entity.CustomFields;
|
||||
import com.foreverwin.iep.prd.entity.Operation;
|
||||
import com.foreverwin.iep.prd.entity.ShopOrder;
|
||||
import com.foreverwin.iep.prd.entity.UserWorkShift;
|
||||
import com.foreverwin.iep.prd.service.CustomFieldsService;
|
||||
import com.foreverwin.iep.prd.service.NextNumberService;
|
||||
import com.foreverwin.iep.prd.service.ShopOrderService;
|
||||
import com.foreverwin.iep.prd.service.UserWorkShiftService;
|
||||
import com.foreverwin.iep.wip.domain.NlvStartRequest;
|
||||
import com.foreverwin.iep.wip.domain.NlvStartResponse;
|
||||
import com.foreverwin.iep.wip.domain.ShopOrderReleaseItemInfo;
|
||||
@ -24,6 +30,7 @@ import com.foreverwin.iep.wip.entity.LotBasis;
|
||||
import com.foreverwin.iep.wip.entity.LotState;
|
||||
import com.foreverwin.iep.wip.mapper.NlvLotStartMapper;
|
||||
import com.foreverwin.iep.wip.service.NlvLotStartService;
|
||||
import com.foreverwin.iep.wip.service.NlvWipCommonService;
|
||||
import com.foreverwin.iep.wip.service.ProcessService;
|
||||
import com.foreverwin.iep.wip.service.ValidationService;
|
||||
import com.foreverwin.mom.common.core.exception.BusinessException;
|
||||
@ -51,9 +58,7 @@ public class NlvLotStartServiceImpl implements NlvLotStartService {
|
||||
|
||||
private final ShopOrderService shopOrderService;
|
||||
|
||||
private final NextNumberService nextNumberService;
|
||||
|
||||
private final CustomFieldsService customFieldsService;
|
||||
private final NlvWipCommonService nlvWipCommonService;
|
||||
|
||||
/**
|
||||
* 获取开始工单弹窗列表
|
||||
@ -151,32 +156,14 @@ public class NlvLotStartServiceImpl implements NlvLotStartService {
|
||||
// 将releaseList按照shopOrder进行分组Map<String, List<ShopOrderReleaseItemInfo>>
|
||||
Map<String, List<ShopOrderReleaseItemInfo>> groupedByShopOrder = releaseList.stream().collect(
|
||||
Collectors.groupingBy(ShopOrderReleaseItemInfo::getShopOrder));
|
||||
// 获取工序自定义字段NEXT_NUMBER_TYPE
|
||||
String operationBo = Operation.genHandle(site, startRequest.getOperation(), "#");
|
||||
List<CustomValue> customValueList = customFieldsService.retrieveCustomValues(operationBo);
|
||||
String nextNumberTypeErrorMsg = "工序[" + startRequest.getOperation() + "]未配置自定义字段NEXT_NUMBER_TYPE";
|
||||
if(customValueList == null || customValueList.isEmpty()) {
|
||||
throw BusinessException.build(nextNumberTypeErrorMsg);
|
||||
}
|
||||
// 获取customValueList中fieldName='NEXT_NUMBER_TYPE'的记录
|
||||
CustomValue customValue = customValueList.stream().filter(c -> OperationCustomFieldsConstants.NEXT_NUMBER_TYPE.equals(c.getFieldName())).findFirst().orElse(null);
|
||||
if(customValue == null) {
|
||||
throw BusinessException.build(nextNumberTypeErrorMsg);
|
||||
}
|
||||
// TODO 修改为调用共用方法
|
||||
GenerateNextNumberRequest generateNextNumberRequest = new GenerateNextNumberRequest();
|
||||
generateNextNumberRequest.setSite(site);
|
||||
generateNextNumberRequest.setNextNumberType(customValue.getFieldValue());
|
||||
generateNextNumberRequest.setNumberOfValues(releaseList.size());
|
||||
GenerateNextNumberResponse nextNumberResponse = nextNumberService.generateNextValues(generateNextNumberRequest);
|
||||
List<String> ids = nextNumberResponse.getIds();
|
||||
int index = 0;
|
||||
for(Map.Entry<String, List<ShopOrderReleaseItemInfo>> entry : groupedByShopOrder.entrySet()) {
|
||||
List<SpecifyReleaseLotInfo> specifyReleaseLotInfoList = new ArrayList<>();
|
||||
// 生成LOT编号
|
||||
String shopOrderNo = entry.getKey();
|
||||
List<ShopOrderReleaseItemInfo> shopOrderReleaseItemInfoList = entry.getValue();
|
||||
List<String> ids = nlvWipCommonService.genOpNextNumber(site, startRequest.getOperation(), startRequest.getResource(), shopOrderNo, null, shopOrderReleaseItemInfoList.size());
|
||||
BigDecimal releaseQty = BigDecimal.ZERO;
|
||||
int index = 0;
|
||||
for(ShopOrderReleaseItemInfo releaseItemInfo : shopOrderReleaseItemInfoList) {
|
||||
releaseQty = releaseQty.add(BigDecimal.ONE);
|
||||
SpecifyReleaseLotInfo info = new SpecifyReleaseLotInfo();
|
||||
|
||||
@ -0,0 +1,157 @@
|
||||
package com.foreverwin.iep.wip.service.impl;
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.foreverwin.iep.common.constant.BaseConstants;
|
||||
import com.foreverwin.iep.common.model.CustomValue;
|
||||
import com.foreverwin.iep.prd.constant.OperationCustomFieldsConstants;
|
||||
import com.foreverwin.iep.prd.constant.ShopOrderCustomFieldsConstants;
|
||||
import com.foreverwin.iep.prd.entity.CustomFields;
|
||||
import com.foreverwin.iep.prd.entity.Operation;
|
||||
import com.foreverwin.iep.prd.entity.ShopOrder;
|
||||
import com.foreverwin.iep.prd.entity.UserWorkShift;
|
||||
import com.foreverwin.iep.prd.service.CustomFieldsService;
|
||||
import com.foreverwin.iep.prd.service.ShopOrderService;
|
||||
import com.foreverwin.iep.prd.service.UserWorkShiftService;
|
||||
import com.foreverwin.iep.smd.entity.Resrce;
|
||||
import com.foreverwin.iep.sys.service.ZNextNumberService;
|
||||
import com.foreverwin.iep.wip.domain.EqpFeedingLotItemGroupInfo;
|
||||
import com.foreverwin.iep.wip.mapper.NlvWipCommonMapper;
|
||||
import com.foreverwin.iep.wip.service.NlvWipCommonService;
|
||||
import com.foreverwin.mom.admin.api.entity.SysDictItem;
|
||||
import com.foreverwin.mom.admin.api.feign.RemoteDictService;
|
||||
import com.foreverwin.mom.admin.api.feign.RemoteParamService;
|
||||
import com.foreverwin.mom.common.core.constant.SecurityConstants;
|
||||
import com.foreverwin.mom.common.core.exception.BusinessException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 在制品通用服务
|
||||
*
|
||||
* @version 1.0
|
||||
* @since 2024-11-14
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class NlvWipCommonServiceImpl implements NlvWipCommonService {
|
||||
|
||||
private final CustomFieldsService customFieldsService;
|
||||
|
||||
private final ZNextNumberService nextNumberService;
|
||||
|
||||
private final UserWorkShiftService userWorkShiftService;
|
||||
|
||||
private final NlvWipCommonMapper nlvWipCommonMapper;
|
||||
|
||||
private final RemoteDictService remoteDictService;
|
||||
|
||||
private final RemoteParamService remoteParamService;
|
||||
|
||||
private final ShopOrderService shopOrderService;
|
||||
|
||||
public static final String EQ_SUFFIX = "EQ_SUFFIX";
|
||||
|
||||
public static final String EQ_SUFFIX_ALPHA = "EQ_SUFFIX_ALPHA";
|
||||
|
||||
public static final String SHIFT = "SHIFT";
|
||||
|
||||
public static final String TBDJ = "TBDJ";
|
||||
|
||||
public static final String SITE_CODE = "SITE_CODE";
|
||||
|
||||
/**
|
||||
* 获取各工序编号规则对应的编号
|
||||
* @param site
|
||||
* @param operation
|
||||
* @param resrce
|
||||
* @param shopOrder
|
||||
* @param customData
|
||||
* @param numberOfValues
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<String> genOpNextNumber(String site, String operation, String resrce, String shopOrder,
|
||||
Map<String, Object> customData, Integer numberOfValues) {
|
||||
if(customData == null) {
|
||||
customData = new HashMap<>();
|
||||
}
|
||||
// 获取工序自定义字段NEXT_NUMBER_TYPE
|
||||
String operationBo = Operation.genHandle(site, operation, "#");
|
||||
List<CustomValue> customValueList = customFieldsService.retrieveCustomValues(operationBo);
|
||||
String nextNumberTypeErrorMsg = "工序[" + operation + "]未配置自定义字段NEXT_NUMBER_TYPE";
|
||||
if(customValueList == null || customValueList.isEmpty()) {
|
||||
throw BusinessException.build(nextNumberTypeErrorMsg);
|
||||
}
|
||||
// 获取customValueList中fieldName='NEXT_NUMBER_TYPE'的记录
|
||||
CustomValue numberTypeCustomValue = customValueList.stream().filter(c -> OperationCustomFieldsConstants.NEXT_NUMBER_TYPE.equals(c.getFieldName())).findFirst().orElse(null);
|
||||
if(numberTypeCustomValue == null || StrUtil.isBlank(numberTypeCustomValue.getFieldValue())) {
|
||||
throw BusinessException.build(nextNumberTypeErrorMsg);
|
||||
}
|
||||
// 获取resrce后两位,如果少于2位,则为空
|
||||
String eqSuffix;
|
||||
if (resrce == null || resrce.length() < 2) {
|
||||
eqSuffix = "";
|
||||
} else {
|
||||
eqSuffix = resrce.substring(resrce.length() - 2);
|
||||
}
|
||||
customData.put(EQ_SUFFIX, eqSuffix);
|
||||
// 将eqSuffix转换为A、B、C、D...的形式,01转换为空,02转换为A,03转换为B...
|
||||
String result = NumberUtil.isNumber(eqSuffix) ? String.valueOf((char) ('A' + Integer.parseInt(eqSuffix) - 1)) : eqSuffix;
|
||||
if("01".equals(eqSuffix)) {
|
||||
result = "";
|
||||
}
|
||||
customData.put(EQ_SUFFIX_ALPHA, result);
|
||||
if(StrUtil.isNotBlank(shopOrder)) {
|
||||
// 修复涂料类型:取工单计划物料在自定表中自定义字段为XF_ITEM_TYPE对应的值
|
||||
String shopOrderBo = ShopOrder.genHandle(site, shopOrder);
|
||||
ShopOrder shopOrderData = shopOrderService.getById(shopOrderBo);
|
||||
if(shopOrderData == null) {
|
||||
throw BusinessException.build("工单[" + shopOrder + "]不存在");
|
||||
}
|
||||
CustomFields shopOrderCustomFields = customFieldsService.getOne(Wrappers.<CustomFields>lambdaQuery()
|
||||
.eq(CustomFields::getHandle, shopOrderData.getPlannedItemBo())
|
||||
.eq(CustomFields::getFieldName, ShopOrderCustomFieldsConstants.XF_ITEM_TYPE), false);
|
||||
if(shopOrderCustomFields != null && !StrUtil.isBlank(shopOrderCustomFields.getFieldValue())) {
|
||||
customData.put(ShopOrderCustomFieldsConstants.XF_ITEM_TYPE, shopOrderCustomFields.getFieldValue());
|
||||
}
|
||||
}
|
||||
String userWorkShift = userWorkShiftService.getCurrentShift(site);
|
||||
customData.put(SHIFT, userWorkShift == null ? "" : userWorkShift);
|
||||
// 设置涂布大卷的值
|
||||
// 获取customValueList中fieldName='IS_FIND_PARENT'的记录,为Y的需要获取涂布大卷
|
||||
CustomValue isFindParentCustomValue = customValueList.stream().filter(c -> OperationCustomFieldsConstants.IS_FIND_PARENT.equals(c.getFieldName())).findFirst().orElse(null);
|
||||
if(isFindParentCustomValue != null && BaseConstants.Y.equals(isFindParentCustomValue.getFieldValue())) {
|
||||
String materialLot = null;
|
||||
List<EqpFeedingLotItemGroupInfo> eqpFeedingLotItemGroupInfoList = nlvWipCommonMapper.findResourceParentLotNo(Resrce.genHandle(site, resrce));
|
||||
if(eqpFeedingLotItemGroupInfoList == null || eqpFeedingLotItemGroupInfoList.isEmpty()) {
|
||||
throw BusinessException.build("资源[" + resrce + "]未找到已上料的涂布大卷");
|
||||
}
|
||||
List<SysDictItem> sysDictItem = remoteDictService.getDictByType("OUT_ITEM_TYPE", SecurityConstants.FROM_IN).getData();
|
||||
if(sysDictItem == null || sysDictItem.isEmpty()) {
|
||||
throw BusinessException.build("未找到字典项OUT_ITEM_TYPE");
|
||||
}
|
||||
for(SysDictItem item : sysDictItem) {
|
||||
for(EqpFeedingLotItemGroupInfo info : eqpFeedingLotItemGroupInfoList) {
|
||||
if(info.getItemGroup() != null && info.getItemGroup().equals(item.getItemValue())) {
|
||||
materialLot = info.getMaterialLot();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(materialLot == null) {
|
||||
throw BusinessException.build("资源[" + resrce + "]未找到已上料的涂布大卷");
|
||||
}
|
||||
customData.put(TBDJ, materialLot);
|
||||
}
|
||||
// 设置工厂代码的值
|
||||
String siteCode = remoteParamService.getByKey(SITE_CODE, SecurityConstants.FROM_IN).getData();
|
||||
customData.put(SITE_CODE, siteCode);
|
||||
List<String> ids = nextNumberService.getNextNumber(site, numberTypeCustomValue.getFieldValue(), numberOfValues, customData);
|
||||
return ids;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package com.foreverwin.iep.sys.mapper;
|
||||
|
||||
import com.foreverwin.iep.sys.entity.ZNextNumberCode;
|
||||
import com.foreverwin.mom.common.data.datascope.MomBaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author hipi
|
||||
* @date 2023-04-17 17:16:18
|
||||
*/
|
||||
@Mapper
|
||||
public interface ZNextNumberCodeMapper extends MomBaseMapper<ZNextNumberCode> {
|
||||
ZNextNumberCode selectForUpdateById(@Param("handle") String handle);
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.foreverwin.iep.sys.mapper;
|
||||
|
||||
import com.foreverwin.iep.sys.entity.ZNextNumber;
|
||||
import com.foreverwin.mom.common.data.datascope.MomBaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author hipi
|
||||
* @date 2023-04-17 17:16:02
|
||||
*/
|
||||
@Mapper
|
||||
public interface ZNextNumberMapper extends MomBaseMapper<ZNextNumber> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.foreverwin.iep.wip.mapper;
|
||||
|
||||
import com.foreverwin.iep.wip.domain.EqpFeedingLotItemGroupInfo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 在制品通用Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface NlvWipCommonMapper {
|
||||
|
||||
List<EqpFeedingLotItemGroupInfo> findResourceParentLotNo(@Param("resourceBo") String resourceBo);
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.foreverwin.iep.sys.mapper.ZNextNumberCodeMapper">
|
||||
|
||||
<resultMap id="nextNumberCodeMap" type="com.foreverwin.iep.sys.entity.ZNextNumberCode">
|
||||
<id property="handle" column="HANDLE"/>
|
||||
<result property="site" column="SITE"/>
|
||||
<result property="nextNumberBo" column="NEXT_NUMBER_BO"/>
|
||||
<result property="code" column="CODE"/>
|
||||
<result property="currentSeq" column="CURRENT_SEQ"/>
|
||||
<result property="modifiedDateTime" column="MODIFIED_DATE_TIME"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectForUpdateById" resultMap="nextNumberCodeMap">
|
||||
SELECT * FROM Z_NEXT_NUMBER_CODE WHERE HANDLE=#{handle} FOR UPDATE
|
||||
</select>
|
||||
</mapper>
|
||||
24
mes-db/src/main/resources/mapper/sys/ZNextNumberMapper.xml
Normal file
24
mes-db/src/main/resources/mapper/sys/ZNextNumberMapper.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.foreverwin.iep.sys.mapper.ZNextNumberMapper">
|
||||
<resultMap id="zNextNumberMap" type="com.foreverwin.iep.sys.entity.ZNextNumber">
|
||||
<id property="handle" column="HANDLE"/>
|
||||
<result property="site" column="SITE"/>
|
||||
<result property="numberType" column="NUMBER_TYPE"/>
|
||||
<result property="prefix" column="PREFIX"/>
|
||||
<result property="suffix" column="SUFFIX"/>
|
||||
<result property="sequenceLength" column="SEQUENCE_LENGTH"/>
|
||||
<result property="sample" column="SAMPLE"/>
|
||||
<result property="repetition" column="REPETITION"/>
|
||||
<result property="description" column="DESCRIPTION"/>
|
||||
<result property="startSequence" column="START_SEQUENCE"/>
|
||||
<result property="skipNumber" column="SKIP_NUMBER"/>
|
||||
<result property="sequenceBase" column="SEQUENCE_BASE"/>
|
||||
<result property="dateCreate" column="DATE_CREATE"/>
|
||||
<result property="dateUpdate" column="DATE_UPDATE"/>
|
||||
<result property="creator" column="CREATOR"/>
|
||||
<result property="updater" column="UPDATER"/>
|
||||
</resultMap>
|
||||
</mapper>
|
||||
14
mes-db/src/main/resources/mapper/wip/NlvWipCommonMapper.xml
Normal file
14
mes-db/src/main/resources/mapper/wip/NlvWipCommonMapper.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.foreverwin.iep.wip.mapper.NlvWipCommonMapper">
|
||||
|
||||
<select id="findResourceParentLotNo" resultType="com.foreverwin.iep.wip.domain.EqpFeedingLotItemGroupInfo">
|
||||
SELECT CF.FIELD_VALUE AS ITEM_GROUP, EF.MATERIAL_LOT
|
||||
FROM EQP_FEEDING EF
|
||||
INNER JOIN CUSTOM_FIELDS CF
|
||||
ON CF.HANDLE = EF.ITEM_BO AND CF.FIELD_NAME = 'ITEM_GROUP'
|
||||
WHERE EF.RESOURCE_BO = #{resourceBo}
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue
Block a user