Merge remote-tracking branch 'origin/feature/DM/nflg-bom' into feature/DM/nflg-bom
# Conflicts: # nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomParentService.java
This commit is contained in:
commit
689bdaba18
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -646,10 +646,10 @@ 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("gvbom", root);
|
||||
//初始化虚拟包-判断枚举(不是手工生成虚拟包的情况)
|
||||
checkAndInitVirtualPackageEnum(paramDto, root);
|
||||
|
|
|
|||
|
|
@ -402,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("没有你的数据,你无需转换");
|
||||
|
|
@ -420,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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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