Merge branch 'feature/DM/nflg-bom' of http://112.74.186.154:3000/nflj/nflg_project into feature/DM/nflg-bom
This commit is contained in:
commit
67477ec634
|
|
@ -114,9 +114,9 @@ public class OriginalBomApi extends BaseApi {
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
@LogRecord(success = "从cad获取bom到原始BOM,操作结果:{{#_ret}}",
|
||||
bizNo = "" ,type = "从CAD获取BOM数据")
|
||||
public ResultVO<List<ImportOriginalBomVO>> pullFromPlm() {
|
||||
public ResultVO<List<ImportOriginalBomVO>> pullFromCad() {
|
||||
|
||||
List<ImportOriginalBomVO> result = originalParentService.pullFromPlm(SessionUtil.getUserCode());
|
||||
List<ImportOriginalBomVO> result = originalParentService.pullFromCad(SessionUtil.getUserCode());
|
||||
|
||||
originalParentService.computeLevelNumAndRootState();
|
||||
|
||||
|
|
|
|||
|
|
@ -11,4 +11,6 @@ public class OriginalConstant {
|
|||
public static final String COMMON_MATERIAL_CATEGORY_CODE = "200901";
|
||||
|
||||
public static final String NO_BOM_VERSION="A-1";
|
||||
|
||||
public static final String DEFAULT_BOM_VERSION="A00";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,8 +117,8 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
|
|||
}
|
||||
if (StrUtil.isNotBlank(materialNo)) {
|
||||
List<BomNewEbomParentEntity> materialBoms = this.lambdaQuery().eq(BomNewEbomParentEntity::getMaterialNo, materialNo).eq(BomNewEbomParentEntity::getLastVersionIs, 1)
|
||||
.ne(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue()).list();
|
||||
if (query.getDataType().equals(0) && CollUtil.isEmpty(materialBoms)) {
|
||||
.eq(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue()).list();
|
||||
if (query.getDataType().equals(0) && CollUtil.isNotEmpty(materialBoms)) {
|
||||
return returnResult;
|
||||
}
|
||||
List<String> materialNos = new ArrayList<>();
|
||||
|
|
@ -645,9 +645,12 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
public void generateVirtualPackage(VirtualPackageParamDto paramDto) {
|
||||
try {
|
||||
|
||||
|
||||
BomNewEbomParentEntity root = this.getById(paramDto.getBomRowId());
|
||||
|
||||
VUtils.isTure(Objects.isNull(root)).throwMessage("不存在的bom");
|
||||
VUtils.isTure(!Objects.equals(root.getExceptionStatus(), EBomExceptionStatusEnum.OK.getValue()))
|
||||
.throwMessage("异常状态下不允许生成虚拟包");
|
||||
|
||||
LogRecordContext.putVariable("bom", root);
|
||||
//初始化虚拟包-判断枚举(不是手工生成虚拟包的情况)
|
||||
checkAndInitVirtualPackageEnum(paramDto, root);
|
||||
|
|
|
|||
|
|
@ -153,20 +153,29 @@ public class BomNewOriginalParentService extends ServiceImpl<BomNewOriginalParen
|
|||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(queryDrawingNos)) {
|
||||
List<BomNewOriginalParentEntity> materialBoms = this.lambdaQuery().in(BomNewOriginalParentEntity::getDrawingNo, queryDrawingNos).eq(BomNewOriginalParentEntity::getLastVersionIs, 1)
|
||||
.eq(BomNewOriginalParentEntity::getStatus, OriginalStatusEnum.UN_CONVERT.getValue()).list();
|
||||
if(query.getStatus().equals(1) && CollUtil.isEmpty(materialBoms)){
|
||||
return result;
|
||||
}
|
||||
// List<BomNewOriginalParentEntity> materialBoms = this.lambdaQuery().in(BomNewOriginalParentEntity::getDrawingNo, queryDrawingNos).eq(BomNewOriginalParentEntity::getLastVersionIs, 1)
|
||||
// .eq(BomNewOriginalParentEntity::getStatus, OriginalStatusEnum.UN_CONVERT.getValue()).list();
|
||||
// if(query.getStatus().equals(1) && CollUtil.isEmpty(materialBoms)){
|
||||
// return result;
|
||||
// }
|
||||
List<String> parentDrawingNos = new ArrayList<>(getParentDrawingNoByMaterialNo(queryDrawingNos));
|
||||
parentDrawingNos.addAll(queryDrawingNos);
|
||||
if (CollUtil.isNotEmpty(parentDrawingNos)) {
|
||||
List<BomOriginalListVO> parents = this.getBaseMapper().getParentForDrawingNoSeach(parentDrawingNos, query.getStatus());
|
||||
materialMainService.intiMaterialInfo(parents, EBomConstant.EBOM_IGNORED_FIELDS_INIT_MATERIAL_DEFAULT);
|
||||
List<BomOriginalListVO> childs = this.getBaseMapper().getChildForDrawingNoSeach(parentDrawingNos,query.getStatus());
|
||||
List<BomOriginalListVO> data = new ArrayList<>();
|
||||
data.addAll(parents);
|
||||
data.addAll(childs);
|
||||
materialMainService.intiMaterialInfo(data, EBomConstant.EBOM_IGNORED_FIELDS_INIT_MATERIAL_DEFAULT);
|
||||
materialMainService.intiMaterialInfo(childs, EBomConstant.EBOM_IGNORED_FIELDS_INIT_MATERIAL_DEFAULT);
|
||||
childs.stream().filter(f -> StrUtil.isBlank(f.getCurrentVersion())).forEach(f -> {
|
||||
if (MaterialshouldBomExistUtil.checkShouldBomExist(f.getMaterialCategoryCode(), f.getMaterialGetType())) {
|
||||
f.setCurrentVersion(OriginalConstant.NO_BOM_VERSION);
|
||||
} else {
|
||||
f.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION);
|
||||
}
|
||||
});
|
||||
// List<BomOriginalListVO> data = new ArrayList<>();
|
||||
// data.addAll(parents);
|
||||
// data.addAll(childs);
|
||||
// materialMainService.intiMaterialInfo(data, EBomConstant.EBOM_IGNORED_FIELDS_INIT_MATERIAL_DEFAULT);
|
||||
result = handSeachToTree(parents, childs);
|
||||
}
|
||||
}
|
||||
|
|
@ -393,7 +402,7 @@ public class BomNewOriginalParentService extends ServiceImpl<BomNewOriginalParen
|
|||
* @param
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public List<ImportOriginalBomVO> pullFromPlm(String userCode) {
|
||||
public List<ImportOriginalBomVO> pullFromCad(String userCode) {
|
||||
|
||||
List<BomOriginalCadParentEntity> parents = originalCadParentService.lambdaQuery().eq(BomOriginalCadParentEntity::getStatus, 1).eq(BomOriginalCadParentEntity::getCreatedBy, userCode).list();
|
||||
VUtils.isTure(CollUtil.isEmpty(parents)).throwMessage("没有你的数据,你无需转换");
|
||||
|
|
@ -411,8 +420,8 @@ public class BomNewOriginalParentService extends ServiceImpl<BomNewOriginalParen
|
|||
if (CollUtil.isNotEmpty(convert.getResultChild())) {
|
||||
originalChildService.saveOrUpdateBatch(convert.getResultChild());
|
||||
}
|
||||
//删除plm临时表数据
|
||||
List<Integer> delRowIds = parents.stream().map(u -> u.getRowId()).collect(Collectors.toList());
|
||||
//删除cad临时表数据
|
||||
List<Integer> delRowIds = parents.stream().map(BomOriginalCadParentEntity::getRowId).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(delRowIds)) {
|
||||
originalCadParentService.getBaseMapper().deleteBatchIds(delRowIds);
|
||||
originalCadParentService.getBaseMapper().delChildByParentRowIds(delRowIds);
|
||||
|
|
@ -486,11 +495,11 @@ public class BomNewOriginalParentService extends ServiceImpl<BomNewOriginalParen
|
|||
//开始转换
|
||||
for (BomNewOriginalParentEntity parent : bomNewOriginalParentEntities) {
|
||||
|
||||
if (!Objects.equals(parent.getCreatedBy(), SessionUtil.getUserCode())){
|
||||
importOriginalBomVOList.add(new ImportOriginalBomVO(parent.getDrawingNo(),"非本人创建"));
|
||||
log.warn(SessionUtil.getRealName()+"("+SessionUtil.getUserCode()+")转换原始bom("+parent.getRowId().toString()+")到ebom的操作被阻止");
|
||||
continue;
|
||||
}
|
||||
// if (!Objects.equals(parent.getCreatedBy(), SessionUtil.getUserCode())){
|
||||
// importOriginalBomVOList.add(new ImportOriginalBomVO(parent.getDrawingNo(),"非本人创建"));
|
||||
// log.warn(SessionUtil.getRealName()+"("+SessionUtil.getUserCode()+")转换原始bom("+parent.getRowId().toString()+")到ebom的操作被阻止");
|
||||
// continue;
|
||||
// }
|
||||
|
||||
LogRecordContext.putVariable("bom",parent);
|
||||
Long ebomRowId = IdWorker.getId();
|
||||
|
|
|
|||
|
|
@ -6,10 +6,7 @@ import cn.hutool.core.util.StrUtil;
|
|||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
||||
import com.nflg.product.bomnew.constant.EBomSourceEnum;
|
||||
import com.nflg.product.bomnew.constant.EbomEditStatusEnum;
|
||||
import com.nflg.product.bomnew.constant.ProjectTypeInputTypeEnum;
|
||||
import com.nflg.product.bomnew.constant.VirtualPackageTypeEnum;
|
||||
import com.nflg.product.bomnew.constant.*;
|
||||
import com.nflg.product.bomnew.pojo.dto.AddVirtrualMaterialDTO;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewEbomChildEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewEbomParentEntity;
|
||||
|
|
@ -129,7 +126,7 @@ public abstract class VirtualPackageBase {
|
|||
BomNewEbomParentEntity oldParent= SpringUtil.getBean(BomNewEbomParentService.class).lambdaQuery()
|
||||
.eq(BomNewEbomParentEntity::getMaterialNo, addM.getMaterialNo())
|
||||
.eq(BomNewEbomParentEntity::getLastVersionIs,1)
|
||||
.ne(BomNewEbomParentEntity::getStatus,4)
|
||||
.ne(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue())
|
||||
.one();
|
||||
|
||||
if(Objects.nonNull(oldParent)){
|
||||
|
|
|
|||
|
|
@ -50,9 +50,9 @@ public class VirtualPackageFor21 extends VirtualPackageBase {
|
|||
BomNewEbomParentEntity makingPackage=null;
|
||||
if((parent.getVirtrualPackageEnum()| VirtualPackageTypeEnum.MAKING_PACKAGE.getValue())!=VirtualPackageTypeEnum.MAKING_PACKAGE.getValue()) {
|
||||
//构建构建发货包下制作包
|
||||
makingPackage = buildParentVirtualPackage( parent.getRowId(), VirtualPackageTypeEnum.MAKING_PACKAGE,parent.getOrderNumber());
|
||||
makingPackage = buildParentVirtualPackage( parent.getRowId(), VirtualPackageTypeEnum.MAKING_PACKAGE,"001");
|
||||
//构建构建发货包下直发
|
||||
BomNewEbomParentEntity directDeliveryPackage = buildParentVirtualPackage(parent.getRowId(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE,parent.getOrderNumber());
|
||||
BomNewEbomParentEntity directDeliveryPackage = buildParentVirtualPackage(parent.getRowId(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE,"002");
|
||||
//构建产品-子级为制作包合直发包
|
||||
buildChild(makingPackage, bomRowId, "001", VirtualPackageTypeEnum.MAKING_PACKAGE,parent.getMaterialNo());
|
||||
buildChild(directDeliveryPackage, bomRowId, "002", VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE,parent.getMaterialNo());
|
||||
|
|
|
|||
|
|
@ -64,16 +64,16 @@ public class VirtualPackageFor31 extends VirtualPackageBase {
|
|||
//构建发货包
|
||||
BomNewEbomParentEntity deliveryPackage = buildParentVirtualPackage(item.getRowId(), VirtualPackageTypeEnum.DELIVERY_PACKAGE,item.getOrderNumber());
|
||||
//构建构建发货包下制作包
|
||||
makingPackage = buildParentVirtualPackage(item.getRowId(), VirtualPackageTypeEnum.MAKING_PACKAGE,item.getOrderNumber());
|
||||
makingPackage = buildParentVirtualPackage(item.getRowId(), VirtualPackageTypeEnum.MAKING_PACKAGE,"002");
|
||||
//构建构建发货包下直发
|
||||
BomNewEbomParentEntity directDeliveryPackage = buildParentVirtualPackage(item.getRowId(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE,item.getOrderNumber());
|
||||
BomNewEbomParentEntity directDeliveryPackage = buildParentVirtualPackage(item.getRowId(), VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE,"001");
|
||||
|
||||
//构建-产品下发货包-子级
|
||||
buildChild(deliveryPackage, bomRowId, "001", VirtualPackageTypeEnum.DELIVERY_PACKAGE,parent.getMaterialNo());
|
||||
buildChild(deliveryPackage, bomRowId, item.getOrderNumber(), VirtualPackageTypeEnum.DELIVERY_PACKAGE,parent.getMaterialNo());
|
||||
|
||||
//构建发货包-子级
|
||||
buildChild(makingPackage, deliveryPackage.getRowId(), "001", VirtualPackageTypeEnum.MAKING_PACKAGE,parent.getMaterialNo());
|
||||
buildChild(directDeliveryPackage, deliveryPackage.getRowId(), "002", VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE,parent.getMaterialNo());
|
||||
buildChild(makingPackage, deliveryPackage.getRowId(), "002", VirtualPackageTypeEnum.MAKING_PACKAGE,parent.getMaterialNo());
|
||||
buildChild(directDeliveryPackage, deliveryPackage.getRowId(), "001", VirtualPackageTypeEnum.DIRECT_DELIVERY_PACKAGE,parent.getMaterialNo());
|
||||
|
||||
BomNewEbomChildEntity itemUp = new BomNewEbomChildEntity();
|
||||
itemUp.setRowId(item.getRowId());
|
||||
|
|
|
|||
|
|
@ -47,9 +47,15 @@ public class PlmBomToOriginalConvert extends BaseConvert {
|
|||
childs = Convert.toList(BomOriginalPlmBomVO.class, SpringUtil.getBean(BomOriginalCadChildService.class).lambdaQuery().eq(BomOriginalCadChildEntity::getParentRowId, inParent.getRowId()).list());
|
||||
parent = Convert.convert(BomOriginalPlmBomVO.class, inParent);
|
||||
//图号-初始化缺编码的物料
|
||||
if(StrUtil.isBlank(parent.getMaterialNo()) || parent.getMaterialNo().trim().equalsIgnoreCase("无")){
|
||||
if(parent.getMaterialNo().trim().equalsIgnoreCase("无")){
|
||||
parent.setMaterialNo("");
|
||||
}
|
||||
if(StrUtil.isBlank(parent.getMaterialNo())){
|
||||
SpringUtil.getBean(MaterialMainService.class).initMaterialForDrawdingNo(ImmutableList.of(parent) ,BomOriginalPlmBomVO::getDrawingNo,BomOriginalPlmBomVO::setMaterialNo,BomOriginalPlmBomVO::setMaterialName);
|
||||
}
|
||||
childs.stream().filter(f->f.getMaterialNo().trim().equalsIgnoreCase("无")).forEach(it->{
|
||||
it.setMaterialNo("");
|
||||
});
|
||||
List<BomOriginalPlmBomVO> noMaterialNoList = childs.stream().filter(u -> StrUtil.isBlank(u.getMaterialNo())).collect(Collectors.toList());
|
||||
if(CollUtil.isNotEmpty(noMaterialNoList)){
|
||||
SpringUtil.getBean(MaterialMainService.class).initMaterialForDrawdingNo(noMaterialNoList ,BomOriginalPlmBomVO::getDrawingNo,BomOriginalPlmBomVO::setMaterialNo,BomOriginalPlmBomVO::setMaterialName);
|
||||
|
|
|
|||
|
|
@ -1,37 +1,43 @@
|
|||
package com.nflg.product.bomnew.service.log;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.mzt.logapi.beans.LogRecord;
|
||||
import com.mzt.logapi.service.ILogRecordService;
|
||||
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewLogEntity;
|
||||
import com.nflg.product.bomnew.service.BomNewLogService;
|
||||
import com.nflg.product.bomnew.util.StringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DbLogRecordServiceImpl implements ILogRecordService {
|
||||
|
||||
@Resource
|
||||
BomNewLogService logService;
|
||||
@Override
|
||||
public void record(LogRecord logRecord) {
|
||||
|
||||
BomNewLogEntity logEnt=new BomNewLogEntity();
|
||||
logEnt.setRowId(IdWorker.getId());
|
||||
logEnt.setModelName(logRecord.getTenant());
|
||||
logEnt.setOpBizNo(logRecord.getBizNo());
|
||||
logEnt.setOpAction(logRecord.getType());
|
||||
logEnt.setOpContent(logRecord.getAction());
|
||||
logEnt.setOpContentExt(logRecord.getExtra());
|
||||
logEnt.setOpUserJobNo(SessionUtil.getUserCode());
|
||||
logEnt.setOpUserName(SessionUtil.getUserName());
|
||||
logEnt.setOpTime(LocalDateTime.now());
|
||||
logEnt.setDptName(SessionUtil.getDepartName());
|
||||
logService.save(logEnt);
|
||||
BomNewLogEntity logEnt = new BomNewLogEntity();
|
||||
try {
|
||||
logEnt.setRowId(IdWorker.getId());
|
||||
logEnt.setModelName(StringUtil.trimText(logRecord.getTenant(),60));
|
||||
logEnt.setOpBizNo(StringUtil.trimText(logRecord.getBizNo(),30));
|
||||
logEnt.setOpAction(StringUtil.trimText(logRecord.getType(),30));
|
||||
logEnt.setOpContent(StringUtil.trimText(logRecord.getAction(),600));
|
||||
logEnt.setOpContentExt(StringUtil.trimText(logRecord.getExtra(),4000));
|
||||
logEnt.setOpUserJobNo(StringUtil.trimText(SessionUtil.getUserCode(),20));
|
||||
logEnt.setOpUserName(StringUtil.trimText(SessionUtil.getUserName(),20));
|
||||
logEnt.setOpTime(LocalDateTime.now());
|
||||
logEnt.setDptName(SessionUtil.getDepartName());
|
||||
logService.save(logEnt);
|
||||
} catch (Exception ex) {
|
||||
log.error("保存操作日志出错:" + ex.getMessage() + ",数据:" + JSON.toJSONString(logEnt));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@ import com.nflg.product.base.core.exception.NflgBusinessException;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import nflg.product.common.constant.STATE;
|
||||
import okhttp3.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -26,8 +24,6 @@ public class HttpUtils {
|
|||
//请求类
|
||||
private OkHttpClient okHttpClient;
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(HttpUtils.class);
|
||||
|
||||
//请求头类型
|
||||
private final MediaType jsonMediaType = MediaType.parse("application/json;charset=utf-8");
|
||||
|
||||
|
|
@ -217,7 +213,7 @@ public class HttpUtils {
|
|||
public String doPost(String url, String json) throws IOException {
|
||||
String ret = null;
|
||||
String traceId = IdWorker.getIdStr();
|
||||
LOGGER.info(traceId + ",http请求,地址:" + url + ",参数:" + json);
|
||||
log.info(traceId + ",http请求,地址:" + url + ",参数:" + json);
|
||||
long start = System.currentTimeMillis();
|
||||
try (Response response = doPostRtnRsp(url, json)) {
|
||||
if (response == null || response.body() == null) {
|
||||
|
|
@ -225,10 +221,10 @@ public class HttpUtils {
|
|||
}
|
||||
ret = response.body().string();
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error(traceId + ",http请求,出错", ex);
|
||||
log.error(traceId + ",http请求,出错", ex);
|
||||
} finally {
|
||||
long end = System.currentTimeMillis();
|
||||
LOGGER.info(traceId + ",http请求,耗时:" + (end - start) + "毫秒,返回:" + ret);
|
||||
log.info(traceId + ",http请求,耗时:" + (end - start) + "毫秒,返回:" + ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,15 +28,12 @@ public class MaterialshouldBomExistUtil {
|
|||
}
|
||||
|
||||
public static boolean checkShouldBomExist(BaseMaterialVO material){
|
||||
|
||||
if(StrUtil.isNotBlank(material.getMaterialCategoryCode()) &&
|
||||
(material.getMaterialCategoryCode().startsWith("30") || material.getMaterialCategoryCode().equals(OriginalConstant.COMMON_MATERIAL_CATEGORY_CODE) ||
|
||||
( material.getMaterialCategoryCode().startsWith("20") && MaterialGetEnum.developing.equalsValue(material.getMaterialGetType()) ))){
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return checkShouldBomExist(material.getMaterialCategoryCode(), material.getMaterialGetType());
|
||||
}
|
||||
public static boolean checkShouldBomExist(String materialCategoryCode, Integer materialGetType){
|
||||
return StrUtil.isNotBlank(materialCategoryCode) &&
|
||||
(materialCategoryCode.startsWith("30") || materialCategoryCode.equals(OriginalConstant.COMMON_MATERIAL_CATEGORY_CODE) ||
|
||||
(materialCategoryCode.startsWith("20") && MaterialGetEnum.developing.equalsValue(materialGetType)));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,107 @@
|
|||
package com.nflg.product.bomnew.util;
|
||||
|
||||
/**
|
||||
* @author 曹鹏飞
|
||||
* @date 2024-03-29 16:52:05
|
||||
*/
|
||||
public class StringUtil {
|
||||
|
||||
public static String subString(String input,int maxLen){
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int byteCount = 0;
|
||||
int charCount = 0;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
// 遍历字符串的每一个字符
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
char c = input.charAt(i);
|
||||
|
||||
// 检查字符是否是双字节或多字节字符,这里简单地通过Character.isHighSurrogate检查,适用于大部分情况
|
||||
if (Character.isHighSurrogate(c)) {
|
||||
// 如果是高代理项,则下一个字符也是有效部分,一起计算长度
|
||||
if (i + 1 < input.length() && Character.isLowSurrogate(input.charAt(i + 1))) {
|
||||
sb.append(c);
|
||||
sb.append(input.charAt(i + 1));
|
||||
i++; // 跳过低代理项
|
||||
byteCount += 3; // 中文等宽字体一般认为占3个长度单位
|
||||
charCount += 1; // Unicode字符数增加1
|
||||
} else {
|
||||
// 不完整的 surrogate pair,跳过
|
||||
continue;
|
||||
}
|
||||
} else if (c > '\u00ff') { // 这里假设非代理项的非ASCII字符都按3个长度单位计算
|
||||
sb.append(c);
|
||||
byteCount += 3;
|
||||
charCount += 1;
|
||||
} else {
|
||||
sb.append(c);
|
||||
byteCount += 1;
|
||||
charCount += 1;
|
||||
}
|
||||
|
||||
if (byteCount > maxLen) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 截取文本,只取30个有效长度,每个中文占用3个长度,其余字符占用1个长度。
|
||||
*
|
||||
* @param text 需要截取的文本
|
||||
* @param maxLength 有效长度上限
|
||||
* @return 截取后的文本
|
||||
*/
|
||||
public static String trimText(String text, int maxLength) {
|
||||
if (text == null || text.isEmpty()) {
|
||||
return text;
|
||||
}
|
||||
|
||||
int lengthCount = 0; // 用于记录有效长度
|
||||
StringBuilder trimmedStringBuilder = new StringBuilder();
|
||||
|
||||
for (char c : text.toCharArray()) {
|
||||
if (isChineseCharacter(c)) {
|
||||
// 如果是中文字符,检查剩余有效长度是否足够3个长度
|
||||
if (lengthCount + 3 <= maxLength) {
|
||||
trimmedStringBuilder.append(c);
|
||||
lengthCount += 3;
|
||||
} else {
|
||||
// 不足3个长度,直接返回已截取的文本
|
||||
return trimmedStringBuilder.toString();
|
||||
}
|
||||
} else {
|
||||
// 非中文字符,检查剩余有效长度是否足够1个长度
|
||||
if (lengthCount + 1 <= maxLength) {
|
||||
trimmedStringBuilder.append(c);
|
||||
lengthCount++;
|
||||
} else {
|
||||
// 不足1个长度,直接返回已截取的文本
|
||||
return trimmedStringBuilder.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return trimmedStringBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查字符是否为中文字符。
|
||||
*
|
||||
* @param ch 需要检查的字符
|
||||
* @return 如果是中文字符则返回true,否则返回false
|
||||
*/
|
||||
private static boolean isChineseCharacter(char ch) {
|
||||
Character.UnicodeBlock block = Character.UnicodeBlock.of(ch);
|
||||
return block == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
|
||||
|| block == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|
||||
|| block == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
|
||||
|| block == Character.UnicodeBlock.GENERAL_PUNCTUATION
|
||||
|| block == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS;
|
||||
}
|
||||
}
|
||||
|
|
@ -216,8 +216,9 @@
|
|||
<!--物料编码搜索-子级-->
|
||||
<select id="getChildForDrawingNoSeach" resultType="com.nflg.product.bomnew.pojo.vo.BomOriginalListVO">
|
||||
select if(#{state}=1 and c.status=2,3,c.status) as status ,c.current_version , c.created_by as bomCreatedBy
|
||||
,c.devise_name,c.devise_user_code,c.dept_name ,
|
||||
c.source, c.row_id as bomRowId, c.row_id as childBomRowId, b.*
|
||||
,IFNULL(c.devise_name,a.devise_name) as devise_name,IFNULL(c.devise_user_code,a.devise_user_code) AS devise_user_code
|
||||
,IFNULL(c.dept_name,a.dept_name) AS dept_name,IFNULL(c.source,a.source) AS source,IFNULL(c.row_id,"0") as bomRowId
|
||||
,IFNULL(c.row_id,"0") as childBomRowId, b.*
|
||||
from t_bom_new_original_parent a
|
||||
join t_bom_new_original_child b on a.row_id =b.parent_row_id
|
||||
left join t_bom_new_original_parent c on b.drawing_no=c.drawing_no and c.last_version_is=1
|
||||
|
|
|
|||
|
|
@ -0,0 +1,78 @@
|
|||
package com.nflg.product.bomnew.service.test;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.nflg.product.bomnew.constant.EBomStatusEnum;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewLogEntity;
|
||||
import com.nflg.product.bomnew.util.StringUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author 曹鹏飞
|
||||
* @date 2024-03-06 14:24:10
|
||||
*/
|
||||
public class OtherTest {
|
||||
|
||||
@Test
|
||||
public void test1(){
|
||||
Integer d=2;
|
||||
System.out.println("他人创建的"+ EBomStatusEnum.findByValue(2).getDescription() +"数据");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2(){
|
||||
BomNewLogEntity logEnt=new BomNewLogEntity();
|
||||
logEnt.setRowId(IdWorker.getId());
|
||||
System.out.println("数据:"+ JSON.toJSONString(logEnt));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3(){
|
||||
String data1="12345ds67八九dsf";
|
||||
String data2="12345ds67";
|
||||
Assert.assertEquals(data2,StringUtil.trimText(data1,9));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test4(){
|
||||
String data1="12345ds67八九dsf";
|
||||
String data2="12345ds67";
|
||||
Assert.assertEquals(data2,StringUtil.trimText(data1,11));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test5(){
|
||||
String data1="12345ds67八九dsf";
|
||||
String data2="12345ds67八九";
|
||||
Assert.assertEquals(data2,StringUtil.trimText(data1,15));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test6(){
|
||||
String data1="12345ds67八九dsf";
|
||||
String data2="12345ds67八九d";
|
||||
Assert.assertEquals(data2,StringUtil.trimText(data1,16));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test7(){
|
||||
String data1="12345ds67八九dsf";
|
||||
String data2="12345ds67八九dsf";
|
||||
Assert.assertEquals(data2,StringUtil.trimText(data1,50));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test8(){
|
||||
String data1="12345ds67八九dsf";
|
||||
String data2="1";
|
||||
Assert.assertEquals(data2,StringUtil.trimText(data1,1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test9(){
|
||||
String data1="12345ds67八九dsf";
|
||||
String data2="";
|
||||
Assert.assertEquals(data2,StringUtil.trimText(data1,0));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue