update 生产计划添加优化、生成编号规则

master
yinq 5 days ago
parent fd4f8264d5
commit 9d6cb93e57

@ -320,4 +320,26 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
/**
* *
*
* @param object Object
* @return true false
*/
public static boolean isNull(Object object)
{
return object == null;
}
/**
* *
*
* @param object Object
* @return true false
*/
public static boolean isNotNull(Object object)
{
return !isNull(object);
}
} }

@ -0,0 +1,49 @@
package org.dromara.common.core.utils.uuid;
/**
* ID
*
* @author ruoyi
*/
public class IdUtils
{
/**
* UUID
*
* @return UUID
*/
public static String randomUUID()
{
return UUID.randomUUID().toString();
}
/**
* UUID线
*
* @return UUID线
*/
public static String simpleUUID()
{
return UUID.randomUUID().toString(true);
}
/**
* UUID使ThreadLocalRandomUUID
*
* @return UUID
*/
public static String fastUUID()
{
return UUID.fastUUID().toString();
}
/**
* UUID线使ThreadLocalRandomUUID
*
* @return UUID线
*/
public static String fastSimpleUUID()
{
return UUID.fastUUID().toString(true);
}
}

@ -0,0 +1,134 @@
package org.dromara.common.core.utils.uuid;
import org.dromara.common.core.utils.DateUtils;
import org.dromara.common.core.utils.StringUtils;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author ruoyi
*/
public class Seq {
// 通用序列类型
public static final String commSeqType = "COMMON";
// 上传序列类型
public static final String uploadSeqType = "UPLOAD";
// 通用接口序列数
private static AtomicInteger commSeq = new AtomicInteger(1);
// 上传接口序列数
private static AtomicInteger uploadSeq = new AtomicInteger(1);
// 机器标识
private static final String machineCode = "A";
// 计划编号记录标识
public static final String mesPlanCodeSeqType = "MES_PLAN_CODE";
// 计划编号序列数
private static AtomicInteger mesPlanCodeSeq = new AtomicInteger(1);
// 计划编号标识
public static final String mesPlanCodeCode = "PL";
/**
*
*
* @return
*/
public static String getId() {
return getId(commSeqType);
}
/**
* 16 yyMMddHHmmss + + 3
*
* @return
*/
public static String getId(String type) {
AtomicInteger atomicInt = commSeq;
if (uploadSeqType.equals(type)) {
atomicInt = uploadSeq;
}
return getId(atomicInt, 3);
}
/**
* yyMMddHHmmss + + length
*
* @param atomicInt
* @param length
* @return
*/
public static String getId(AtomicInteger atomicInt, int length) {
String result = DateUtils.dateTimeNow();
result += machineCode;
result += getSeq(atomicInt, length);
return result;
}
/**
* [1, 10 (length)), 0length
*
* @return
*/
private synchronized static String getSeq(AtomicInteger atomicInt, int length) {
// 先取值再+1
int value = atomicInt.getAndIncrement();
// 如果更新后值>=10 的 (length)幂次方则重置为1
int maxSeq = (int) Math.pow(10, length);
if (atomicInt.get() >= maxSeq) {
atomicInt.set(1);
}
// 转字符串用0左补齐
return StringUtils.padl(value, length);
}
/**
* 16 yyMMddHHmmss + + 3
*
* @return
*/
public static String getId(String type,String code) {
AtomicInteger atomicInt = commSeq;
if (mesPlanCodeSeqType.equals(type)) {
atomicInt = mesPlanCodeSeq;
}
return getId(atomicInt, 4, code);
}
/**
* yyMMddHHmmss + + length
*
* @param atomicInt
* @param length
* @return
*/
public static String getId(AtomicInteger atomicInt, int length, String code) {
String result = DateUtils.dateTimeNow();
result += code;
result += getSeq(atomicInt, length);
return result;
}
/**
* +yyMMdd + length
*
* @param atomicInt
* @param length
* @return
*/
public static String getNewId(AtomicInteger atomicInt, int length, String code) {
String result = code;
result += DateUtils.dateTime();
result += getSeq(atomicInt, length);
return result;
}
}

@ -0,0 +1,486 @@
package org.dromara.common.core.utils.uuid;
import cn.hutool.core.exceptions.UtilException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
/**
* universally unique identifierUUID
*
* @author ruoyi
*/
public final class UUID implements java.io.Serializable, Comparable<UUID>
{
private static final long serialVersionUID = -1185015143654744140L;
/**
* SecureRandom
*
*/
private static class Holder
{
static final SecureRandom numberGenerator = getSecureRandom();
}
/** 此UUID的最高64有效位 */
private final long mostSigBits;
/** 此UUID的最低64有效位 */
private final long leastSigBits;
/**
*
*
* @param data
*/
private UUID(byte[] data)
{
long msb = 0;
long lsb = 0;
assert data.length == 16 : "data must be 16 bytes in length";
for (int i = 0; i < 8; i++)
{
msb = (msb << 8) | (data[i] & 0xff);
}
for (int i = 8; i < 16; i++)
{
lsb = (lsb << 8) | (data[i] & 0xff);
}
this.mostSigBits = msb;
this.leastSigBits = lsb;
}
/**
* 使 UUID
*
* @param mostSigBits {@code UUID} 64
* @param leastSigBits {@code UUID} 64
*/
public UUID(long mostSigBits, long leastSigBits)
{
this.mostSigBits = mostSigBits;
this.leastSigBits = leastSigBits;
}
/**
* 4UUID
*
* @return {@code UUID}
*/
public static UUID fastUUID()
{
return randomUUID(false);
}
/**
* 4UUID 使 UUID
*
* @return {@code UUID}
*/
public static UUID randomUUID()
{
return randomUUID(true);
}
/**
* 4UUID 使 UUID
*
* @param isSecure 使{@link SecureRandom}
* @return {@code UUID}
*/
public static UUID randomUUID(boolean isSecure)
{
final Random ng = isSecure ? Holder.numberGenerator : getRandom();
byte[] randomBytes = new byte[16];
ng.nextBytes(randomBytes);
randomBytes[6] &= 0x0f; /* clear version */
randomBytes[6] |= 0x40; /* set to version 4 */
randomBytes[8] &= 0x3f; /* clear variant */
randomBytes[8] |= 0x80; /* set to IETF variant */
return new UUID(randomBytes);
}
/**
* 3UUID
*
* @param name UUID
*
* @return {@code UUID}
*/
public static UUID nameUUIDFromBytes(byte[] name)
{
MessageDigest md;
try
{
md = MessageDigest.getInstance("MD5");
}
catch (NoSuchAlgorithmException nsae)
{
throw new InternalError("MD5 not supported");
}
byte[] md5Bytes = md.digest(name);
md5Bytes[6] &= 0x0f; /* clear version */
md5Bytes[6] |= 0x30; /* set to version 3 */
md5Bytes[8] &= 0x3f; /* clear variant */
md5Bytes[8] |= 0x80; /* set to IETF variant */
return new UUID(md5Bytes);
}
/**
* {@link #toString()} {@code UUID}
*
* @param name {@code UUID}
* @return {@code UUID}
* @throws IllegalArgumentException name {@link #toString}
*
*/
public static UUID fromString(String name)
{
String[] components = name.split("-");
if (components.length != 5)
{
throw new IllegalArgumentException("Invalid UUID string: " + name);
}
for (int i = 0; i < 5; i++)
{
components[i] = "0x" + components[i];
}
long mostSigBits = Long.decode(components[0]).longValue();
mostSigBits <<= 16;
mostSigBits |= Long.decode(components[1]).longValue();
mostSigBits <<= 16;
mostSigBits |= Long.decode(components[2]).longValue();
long leastSigBits = Long.decode(components[3]).longValue();
leastSigBits <<= 48;
leastSigBits |= Long.decode(components[4]).longValue();
return new UUID(mostSigBits, leastSigBits);
}
/**
* UUID 128 64
*
* @return UUID 128 64
*/
public long getLeastSignificantBits()
{
return leastSigBits;
}
/**
* UUID 128 64
*
* @return UUID 128 64
*/
public long getMostSignificantBits()
{
return mostSigBits;
}
/**
* {@code UUID} . {@code UUID}
* <p>
* :
* <ul>
* <li>1 UUID
* <li>2 DCE UUID
* <li>3 UUID
* <li>4 UUID
* </ul>
*
* @return {@code UUID}
*/
public int version()
{
// Version is bits masked by 0x000000000000F000 in MS long
return (int) ((mostSigBits >> 12) & 0x0f);
}
/**
* {@code UUID} {@code UUID}
* <p>
*
* <ul>
* <li>0 NCS
* <li>2 <a href="http://www.ietf.org/rfc/rfc4122.txt">IETF&nbsp;RFC&nbsp;4122</a>(Leach-Salz),
* <li>6
* <li>7 使
* </ul>
*
* @return {@code UUID}
*/
public int variant()
{
// This field is composed of a varying number of bits.
// 0 - - Reserved for NCS backward compatibility
// 1 0 - The IETF aka Leach-Salz variant (used by this class)
// 1 1 0 Reserved, Microsoft backward compatibility
// 1 1 1 Reserved for future definition.
return (int) ((leastSigBits >>> (64 - (leastSigBits >>> 62))) & (leastSigBits >> 63));
}
/**
* UUID
*
* <p>
* 60 {@code UUID} time_lowtime_mid time_hi <br>
* 100 UTC 1582 10 15
*
* <p>
* UUID version 1<br>
* {@code UUID} UUID UnsupportedOperationException
*
* @throws UnsupportedOperationException {@code UUID} version 1 UUID
*/
public long timestamp() throws UnsupportedOperationException
{
checkTimeBase();
return (mostSigBits & 0x0FFFL) << 48//
| ((mostSigBits >> 16) & 0x0FFFFL) << 32//
| mostSigBits >>> 32;
}
/**
* UUID
*
* <p>
* 14 UUID clock_seq clock_seq UUID
* <p>
* {@code clockSequence} UUID version 1 UUID UUID
* UnsupportedOperationException
*
* @return {@code UUID}
*
* @throws UnsupportedOperationException UUID version 1
*/
public int clockSequence() throws UnsupportedOperationException
{
checkTimeBase();
return (int) ((leastSigBits & 0x3FFF000000000000L) >>> 48);
}
/**
* UUID
*
* <p>
* 48 UUID node IEEE 802 UUID
* <p>
* UUID version 1<br>
* UUID UUID UnsupportedOperationException
*
* @return {@code UUID}
*
* @throws UnsupportedOperationException UUID version 1
*/
public long node() throws UnsupportedOperationException
{
checkTimeBase();
return leastSigBits & 0x0000FFFFFFFFFFFFL;
}
/**
* {@code UUID}
*
* <p>
* UUID BNF
*
* <pre>
* {@code
* UUID = <time_low>-<time_mid>-<time_high_and_version>-<variant_and_sequence>-<node>
* time_low = 4*<hexOctet>
* time_mid = 2*<hexOctet>
* time_high_and_version = 2*<hexOctet>
* variant_and_sequence = 2*<hexOctet>
* node = 6*<hexOctet>
* hexOctet = <hexDigit><hexDigit>
* hexDigit = [0-9a-fA-F]
* }
* </pre>
*
* </blockquote>
*
* @return {@code UUID}
* @see #toString(boolean)
*/
@Override
public String toString()
{
return toString(false);
}
/**
* {@code UUID}
*
* <p>
* UUID BNF
*
* <pre>
* {@code
* UUID = <time_low>-<time_mid>-<time_high_and_version>-<variant_and_sequence>-<node>
* time_low = 4*<hexOctet>
* time_mid = 2*<hexOctet>
* time_high_and_version = 2*<hexOctet>
* variant_and_sequence = 2*<hexOctet>
* node = 6*<hexOctet>
* hexOctet = <hexDigit><hexDigit>
* hexDigit = [0-9a-fA-F]
* }
* </pre>
*
* </blockquote>
*
* @param isSimple '-'UUID
* @return {@code UUID}
*/
public String toString(boolean isSimple)
{
final StringBuilder builder = new StringBuilder(isSimple ? 32 : 36);
// time_low
builder.append(digits(mostSigBits >> 32, 8));
if (false == isSimple)
{
builder.append('-');
}
// time_mid
builder.append(digits(mostSigBits >> 16, 4));
if (false == isSimple)
{
builder.append('-');
}
// time_high_and_version
builder.append(digits(mostSigBits, 4));
if (false == isSimple)
{
builder.append('-');
}
// variant_and_sequence
builder.append(digits(leastSigBits >> 48, 4));
if (false == isSimple)
{
builder.append('-');
}
// node
builder.append(digits(leastSigBits, 12));
return builder.toString();
}
/**
* UUID
*
* @return UUID
*/
@Override
public int hashCode()
{
long hilo = mostSigBits ^ leastSigBits;
return ((int) (hilo >> 32)) ^ (int) hilo;
}
/**
*
* <p>
* {@code null} UUID UUID varriant {@code true}
*
* @param obj
*
* @return {@code true} {@code false}
*/
@Override
public boolean equals(Object obj)
{
if ((null == obj) || (obj.getClass() != UUID.class))
{
return false;
}
UUID id = (UUID) obj;
return (mostSigBits == id.mostSigBits && leastSigBits == id.leastSigBits);
}
// Comparison Operations
/**
* UUID UUID
*
* <p>
* UUID UUID UUID UUID UUID
*
* @param val UUID UUID
*
* @return UUID val -10 1
*
*/
@Override
public int compareTo(UUID val)
{
// The ordering is intentionally set up so that the UUIDs
// can simply be numerically compared as two numbers
return (this.mostSigBits < val.mostSigBits ? -1 : //
(this.mostSigBits > val.mostSigBits ? 1 : //
(this.leastSigBits < val.leastSigBits ? -1 : //
(this.leastSigBits > val.leastSigBits ? 1 : //
0))));
}
// -------------------------------------------------------------------------------------------------------------------
// Private method start
/**
* hex
*
* @param val
* @param digits
* @return
*/
private static String digits(long val, int digits)
{
long hi = 1L << (digits * 4);
return Long.toHexString(hi | (val & (hi - 1))).substring(1);
}
/**
* time-basedUUID
*/
private void checkTimeBase()
{
if (version() != 1)
{
throw new UnsupportedOperationException("Not a time-based UUID");
}
}
/**
* {@link SecureRandom} (RNG)
*
* @return {@link SecureRandom}
*/
public static SecureRandom getSecureRandom()
{
try
{
return SecureRandom.getInstance("SHA1PRNG");
}
catch (NoSuchAlgorithmException e)
{
throw new UtilException(e);
}
}
/**
* <br>
* ThreadLocalRandomJDK 7线
*
* @return {@link ThreadLocalRandom}
*/
public static ThreadLocalRandom getRandom()
{
return ThreadLocalRandom.current();
}
}

@ -45,7 +45,7 @@ public class ProdPlanInfoBo extends BaseEntity {
/** /**
* *
*/ */
@NotBlank(message = "工单编号不能为空", groups = { AddGroup.class, EditGroup.class }) // @NotBlank(message = "工单编号不能为空", groups = { AddGroup.class, EditGroup.class })
private String planCode; private String planCode;
/** /**
@ -56,13 +56,13 @@ public class ProdPlanInfoBo extends BaseEntity {
/** /**
* ID;ID * ID;ID
*/ */
@NotNull(message = "物料ID;成品ID不能为空", groups = { AddGroup.class, EditGroup.class }) @NotNull(message = "物料不能为空", groups = { AddGroup.class, EditGroup.class })
private Long materialId; private Long materialId;
/** /**
* BOM_ID * BOM_ID
*/ */
@NotNull(message = "物料BOM_ID不能为空", groups = { AddGroup.class, EditGroup.class }) @NotNull(message = "物料BOM不能为空", groups = { AddGroup.class, EditGroup.class })
private Long materialBomId; private Long materialBomId;
/** /**
@ -109,7 +109,7 @@ public class ProdPlanInfoBo extends BaseEntity {
/** /**
* *
*/ */
@NotNull(message = "派工数量不能为空", groups = { AddGroup.class, EditGroup.class }) // @NotNull(message = "派工数量不能为空", groups = { AddGroup.class, EditGroup.class })
private Long dispatchAmount; private Long dispatchAmount;
/** /**

@ -227,4 +227,6 @@ public class ProdPlanInfoVo implements Serializable {
private String processName; private String processName;
private String shiftName; private String shiftName;
private String teamName; private String teamName;
private String materialBomName;
private String releaseName;
} }

@ -83,6 +83,13 @@ public class ProdMaterialBomServiceImpl implements IProdMaterialBomService {
*/ */
@Override @Override
public Boolean insertByBo(ProdMaterialBomBo bo) { public Boolean insertByBo(ProdMaterialBomBo bo) {
isTopFlag(bo);
ProdMaterialBomVo info = baseMapper.selectVoById(bo.getParentId());
if (StringUtils.isNull(info)) {
bo.setAncestors(bo.getParentId().toString());
} else {
bo.setAncestors(info.getAncestors() + "," + bo.getParentId());
}
ProdMaterialBom add = MapstructUtils.convert(bo, ProdMaterialBom.class); ProdMaterialBom add = MapstructUtils.convert(bo, ProdMaterialBom.class);
validEntityBeforeSave(add); validEntityBeforeSave(add);
boolean flag = baseMapper.insert(add) > 0; boolean flag = baseMapper.insert(add) > 0;
@ -100,6 +107,11 @@ public class ProdMaterialBomServiceImpl implements IProdMaterialBomService {
*/ */
@Override @Override
public Boolean updateByBo(ProdMaterialBomBo bo) { public Boolean updateByBo(ProdMaterialBomBo bo) {
isTopFlag(bo);
ProdMaterialBomVo info = baseMapper.selectVoById(bo.getParentId());
if (StringUtils.isNotNull(info)) {
bo.setAncestors(info.getAncestors() + "," + bo.getParentId());
}
ProdMaterialBom update = MapstructUtils.convert(bo, ProdMaterialBom.class); ProdMaterialBom update = MapstructUtils.convert(bo, ProdMaterialBom.class);
validEntityBeforeSave(update); validEntityBeforeSave(update);
return baseMapper.updateById(update) > 0; return baseMapper.updateById(update) > 0;
@ -126,4 +138,20 @@ public class ProdMaterialBomServiceImpl implements IProdMaterialBomService {
} }
return baseMapper.deleteByIds(ids) > 0; return baseMapper.deleteByIds(ids) > 0;
} }
/**
* SET
* BOM
*
* @param mesMaterialBom
*/
private void isTopFlag(ProdMaterialBomBo mesMaterialBom) {
// 顶级标识1=是0=否
if (StringUtils.isNull(mesMaterialBom.getParentId()) || mesMaterialBom.getParentId() == 0L) {
mesMaterialBom.setTopFlag(1L);
} else {
mesMaterialBom.setTopFlag(0L);
}
}
} }

@ -2,6 +2,7 @@ package org.dromara.mes.service.impl;
import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.core.utils.uuid.Seq;
import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -114,6 +115,8 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService {
*/ */
@Override @Override
public Boolean insertByBo(ProdPlanInfoBo bo) { public Boolean insertByBo(ProdPlanInfoBo bo) {
String planCode = Seq.getId(Seq.mesPlanCodeSeqType, Seq.mesPlanCodeCode);
bo.setPlanCode(planCode);
ProdPlanInfo add = MapstructUtils.convert(bo, ProdPlanInfo.class); ProdPlanInfo add = MapstructUtils.convert(bo, ProdPlanInfo.class);
validEntityBeforeSave(add); validEntityBeforeSave(add);
boolean flag = baseMapper.insert(add) > 0; boolean flag = baseMapper.insert(add) > 0;

@ -10,6 +10,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
${ew.getSqlSelect}, ${ew.getSqlSelect},
bmi.material_code, bmi.material_code,
bmi.material_name, bmi.material_name,
bomi.material_name material_bom_name,
pbsi.station_name release_name,
pbpi.process_name, pbpi.process_name,
bsi.shift_name, bsi.shift_name,
bcti.team_name bcti.team_name
@ -19,6 +21,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if> </if>
from prod_plan_info t from prod_plan_info t
left join base_material_info bmi on bmi.material_id = t.material_id left join base_material_info bmi on bmi.material_id = t.material_id
left join base_material_info bomi on bomi.material_id = t.material_bom_id
left join prod_base_station_info pbsi on pbsi.station_id = t.release_id
left join prod_base_process_info pbpi on pbpi.process_id = t.process_id left join prod_base_process_info pbpi on pbpi.process_id = t.process_id
left join base_shift_info bsi on bsi.shift_id = t.shift_id left join base_shift_info bsi on bsi.shift_id = t.shift_id
left join base_class_team_info bcti on bcti.class_team_id = t.class_team_id left join base_class_team_info bcti on bcti.class_team_id = t.class_team_id

Loading…
Cancel
Save