fix(设备主数据):修复
This commit is contained in:
parent
862ed22228
commit
b59a89beeb
@ -153,7 +153,6 @@
|
||||
<artifactId>itextpdf</artifactId>
|
||||
<version>5.5.10</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.foreverwin</groupId>
|
||||
<artifactId>mes-mdm</artifactId>
|
||||
@ -186,5 +185,26 @@
|
||||
<artifactId>pms-db</artifactId>
|
||||
<version>4.5.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.foreverwin</groupId>
|
||||
<artifactId>mom-common-oss</artifactId>
|
||||
<version>4.5.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.7</version>
|
||||
<configuration>
|
||||
<nonFilteredFileExtensions>
|
||||
<!--不加这一行,xlsx文件会被过滤,然后在maven build的时候,去target下看对应的xlsx就是损坏的-->
|
||||
<nonFilteredFileExtension>xlsx</nonFilteredFileExtension>
|
||||
</nonFilteredFileExtensions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
package com.foreverwin.mom.pms.controller;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import com.foreverwin.mom.common.core.exception.BusinessException;
|
||||
import com.google.common.net.HttpHeaders;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* @author Yohann
|
||||
* @since 2023/11/24
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/exportTemplate")
|
||||
@AllArgsConstructor
|
||||
public class ExportTemplateController {
|
||||
|
||||
@SneakyThrows
|
||||
@GetMapping("/export")
|
||||
public void export(String fileName, HttpServletResponse response) {
|
||||
ClassPathResource resource = new ClassPathResource("file/" + fileName);
|
||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||
IoUtil.copy(resource.getInputStream(), response.getOutputStream());
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,6 +2,7 @@ package com.foreverwin.mom.pms.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.foreverwin.mom.common.data.tenant.TenantContextHolder;
|
||||
import com.foreverwin.mom.pms.dto.CommonAttachmentDTO;
|
||||
import com.foreverwin.mom.pms.dto.ErrorMsgDTO;
|
||||
import com.foreverwin.mom.pms.dto.ResrceExtDTO;
|
||||
|
||||
@ -36,7 +36,7 @@ public interface ResrceExtService extends IService<ResrceExt> {
|
||||
* @param searchText
|
||||
* @return
|
||||
*/
|
||||
IPage<SegmentBasis> getProcessPage(Page page,String searchText);
|
||||
IPage<Operation> getProcessPage(Page page,String searchText);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -6,7 +6,10 @@ import com.foreverwin.iep.common.file.domain.SmbFileInfo;
|
||||
import com.foreverwin.iep.common.file.service.FileServerConfigService;
|
||||
import com.foreverwin.iep.common.file.service.SmbService;
|
||||
import com.foreverwin.iep.common.utils.SidUtils;
|
||||
import com.foreverwin.mom.common.core.exception.BaseException;
|
||||
import com.foreverwin.mom.common.core.exception.BusinessException;
|
||||
import com.foreverwin.mom.common.file.core.FileProperties;
|
||||
import com.foreverwin.mom.common.file.core.FileTemplate;
|
||||
import com.foreverwin.mom.common.security.util.SecurityUtils;
|
||||
import com.foreverwin.mom.pms.dto.CommonAttachmentDTO;
|
||||
import com.foreverwin.mom.pms.service.CommonAttachmentService;
|
||||
@ -16,6 +19,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
@ -34,6 +38,8 @@ public class CommonAttachmentServiceImpl implements CommonAttachmentService {
|
||||
|
||||
private final SmbService smbService;
|
||||
private final FileServerConfigService fileServerConfigService;
|
||||
private final FileTemplate fileTemplate;
|
||||
private final FileProperties properties;
|
||||
|
||||
|
||||
/**
|
||||
@ -59,9 +65,12 @@ public class CommonAttachmentServiceImpl implements CommonAttachmentService {
|
||||
String remoteFileName = SidUtils.genSid();
|
||||
|
||||
// 获取文件上传服务配置信息
|
||||
SmbFileInfo smbFileInfo = getSmbFileInfo(remoteFileName, commonAttachmentDTO.getModelFunctionName());
|
||||
smbFileInfo.setMultipartFile(multipartFile);
|
||||
smbService.uploadFile(smbFileInfo);
|
||||
try (InputStream inputStream = multipartFile.getInputStream()) {
|
||||
fileTemplate.createBucket(properties.getBucketName());
|
||||
fileTemplate.putObject(properties.getBucketName(), remoteFileName, inputStream, multipartFile.getContentType());
|
||||
} catch (Exception e) {
|
||||
throw new BaseException("上传失败:" + e);
|
||||
}
|
||||
|
||||
// 创建初始化数据返回对象
|
||||
CommonAttachmentDTO responseCommonAttachmentDTO = new CommonAttachmentDTO();
|
||||
|
||||
@ -8,9 +8,14 @@ import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.foreverwin.iep.common.constant.BaseConstants;
|
||||
import com.foreverwin.iep.common.model.CustomValue;
|
||||
import com.foreverwin.iep.common.utils.ListUtils;
|
||||
import com.foreverwin.iep.prd.domain.SaveCustomDataRequest;
|
||||
import com.foreverwin.iep.prd.entity.CustomFieldDef;
|
||||
import com.foreverwin.iep.prd.entity.CustomFields;
|
||||
import com.foreverwin.iep.prd.feign.RemoteCustomFieldsService;
|
||||
import com.foreverwin.mom.common.core.util.I18nUtil;
|
||||
import com.foreverwin.mom.common.security.util.SecurityUtils;
|
||||
import com.foreverwin.mom.pms.dto.CommonAttachmentDTO;
|
||||
import com.foreverwin.mom.pms.dto.ErrorMsgDTO;
|
||||
@ -20,6 +25,7 @@ import com.foreverwin.mom.pms.entity.ResrceExt;
|
||||
import com.foreverwin.mom.pms.mapper.CustomFieldsByCustomMapper;
|
||||
import com.foreverwin.mom.pms.mapper.CustomFieldsByIepMapper;
|
||||
import com.foreverwin.mom.pms.mapper.ResrceExtMapper;
|
||||
import com.foreverwin.mom.pms.service.CustomFieldsService;
|
||||
import com.foreverwin.mom.pms.service.PmsResrceExtUploadService;
|
||||
import com.foreverwin.mom.pms.service.ResrceExtService;
|
||||
import com.foreverwin.mom.pms.service.CommonAttachmentService;
|
||||
@ -84,8 +90,9 @@ public class ResrceExtServiceImpl extends ServiceImpl<ResrceExtMapper, ResrceExt
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<SegmentBasis> getProcessPage(Page page, String searchText) {
|
||||
return resrceExtMapper.getProcessPage(page, searchText);
|
||||
public IPage<Operation> getProcessPage(Page page, String searchText) {
|
||||
String tenantId = TenantContextHolder.getTenantId();
|
||||
return resrceExtMapper.getProcessPage(page, tenantId, searchText);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -102,7 +109,8 @@ public class ResrceExtServiceImpl extends ServiceImpl<ResrceExtMapper, ResrceExt
|
||||
@Override
|
||||
@Transactional
|
||||
public Boolean saveResrceExt(ResrceExt resrceExt) {
|
||||
String handle = ResrceExt.genHandle(TenantContextHolder.getTenantId(), resrceExt.getResrce());
|
||||
String tenantId = TenantContextHolder.getTenantId();
|
||||
String handle = ResrceExt.genHandle(tenantId, resrceExt.getResrce());
|
||||
resrceExt.setHandle(handle);
|
||||
if (StrUtil.isNotBlank(resrceExt.getOperationManual())) {
|
||||
PmsResrceExtUpload byId = pmsResrceExtUploadService.getById(resrceExt.getOperationManual());
|
||||
@ -112,9 +120,14 @@ public class ResrceExtServiceImpl extends ServiceImpl<ResrceExtMapper, ResrceExt
|
||||
PmsEquip pmsEquip = new PmsEquip();
|
||||
pmsEquip.setId(resrceExt.getHandle());
|
||||
pmsEquip.setEquipName(resrceExt.getResrce());
|
||||
pmsEquip.setSite(TenantContextHolder.getTenantId());
|
||||
pmsEquip.setSite(tenantId);
|
||||
pmsEquip.setEquipDescription(resrceExt.getDescription());
|
||||
pmsEquipMapper.insert(pmsEquip);
|
||||
resrceExt.setSite(tenantId);
|
||||
// 自定义字段
|
||||
if (!resrceExt.getCustomFields().isEmpty()) {
|
||||
saveOrUpdateCustomFiels(resrceExt);
|
||||
}
|
||||
return save(resrceExt);
|
||||
}
|
||||
|
||||
@ -220,11 +233,131 @@ public class ResrceExtServiceImpl extends ServiceImpl<ResrceExtMapper, ResrceExt
|
||||
byId.setZPmsResrceExtBo(resrce.getHandle());
|
||||
pmsResrceExtUploadService.updateById(byId);
|
||||
}
|
||||
List<CustomValue> customFields = resrce.getCustomFields();
|
||||
// 更新自定义字段
|
||||
updateCustomField(customFields, resrce.getHandle(), "RESRCE");
|
||||
|
||||
// 自定义字段
|
||||
if (!resrce.getCustomFields().isEmpty()) {
|
||||
saveOrUpdateCustomFiels(resrce);
|
||||
}
|
||||
return updateById(resrce);
|
||||
}
|
||||
|
||||
private void saveOrUpdateCustomFiels(ResrceExt resrce) {
|
||||
String tableName = TableInfoHelper.getTableInfo(currentModelClass()).getTableName().toUpperCase();
|
||||
List<CustomValue> customFields = resrce.getCustomFields();
|
||||
String site = TenantContextHolder.getTenantId();
|
||||
String user = SecurityUtils.getUserName();
|
||||
String ref = resrce.getHandle();
|
||||
Boolean fieldMerge = false;
|
||||
if (StrUtil.isBlank(ref)) {
|
||||
throw BusinessException.build("自定义数据:REF不能没有数据值!");
|
||||
}
|
||||
if (StrUtil.isBlank(tableName)) {
|
||||
throw BusinessException.build("自定义数据:TABLE_NAME不能没有数据值!");
|
||||
}
|
||||
if (customFields == null) {
|
||||
customFields = new ArrayList<>();
|
||||
}
|
||||
List<CustomFields> existsList = customFieldsByIepMapper.findCustomFieldsListByHandle(site, ref);
|
||||
|
||||
List<CustomFieldDef> customFieldDefList = customFieldsByIepMapper.findCustomFieldDefListByHandle(site, tableName);
|
||||
/*if (customFieldDefList == null || customFieldDefList.size() == 0) {
|
||||
throw BusinessException.build("类型[" + request.getObjectAlias() + "]未维护自定义数据定义");
|
||||
}*/
|
||||
// 校验是否必填
|
||||
String requiredNullField = null;
|
||||
for (CustomFieldDef customFieldDef : customFieldDefList) {
|
||||
if (BaseConstants.Y.equals(customFieldDef.getRequiredFlag())) {
|
||||
boolean inputFieldExists = this.fieldExists(customFieldDef.getFieldName(), customFields);
|
||||
if (fieldMerge != null && !fieldMerge) {
|
||||
if (!inputFieldExists) {
|
||||
requiredNullField = customFieldDef.getFieldName();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (!inputFieldExists && this.getExistsRecord(customFieldDef.getFieldName(), existsList) == null) {
|
||||
requiredNullField = customFieldDef.getFieldName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (requiredNullField != null) {
|
||||
throw BusinessException.build(I18nUtil.getI18nText("iep.error84", requiredNullField));
|
||||
}
|
||||
|
||||
if (fieldMerge != null && !fieldMerge) {
|
||||
// 将原有数据移除
|
||||
customFieldsByIepMapper.delete(Wrappers.<CustomFields>lambdaUpdate()
|
||||
.eq(CustomFields::getHandle, ref));
|
||||
existsList = new ArrayList<>();
|
||||
}
|
||||
// List<CustomFields> addList = new ArrayList<>();
|
||||
List<CustomFields> updateList = new ArrayList<>();
|
||||
for (CustomValue customValue : customFields) {
|
||||
if (StrUtil.isBlank(customValue.getFieldName())) {
|
||||
throw BusinessException.build(I18nUtil.getI18nText("iep.error85"));
|
||||
}
|
||||
|
||||
CustomFieldDef customFieldDef = customFieldDefList.stream()
|
||||
.filter(filters -> filters.getFieldName()
|
||||
.equals(customValue.getFieldName()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (ObjectUtil.isNotNull(customFieldDef)) {
|
||||
if (BaseConstants.Y.equals(customFieldDef.getRequiredFlag())) {
|
||||
if (StrUtil.isBlank(customValue.getFieldValue())) {
|
||||
throw BusinessException.build(I18nUtil.getI18nText("iep.error84", customValue.getFieldName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CustomFields existsRecord = this.getExistsRecord(customValue.getFieldName(), existsList);
|
||||
if (existsRecord == null) {
|
||||
CustomFields customFieldsNew = new CustomFields();
|
||||
customFieldsNew.setHandle(ref);
|
||||
customFieldsNew.setSite(site);
|
||||
customFieldsNew.setTableName(tableName);
|
||||
customFieldsNew.setFieldName(customValue.getFieldName());
|
||||
customFieldsNew.setFieldValue(customValue.getFieldValue());
|
||||
customFieldsNew.setUpdater(user);
|
||||
customFieldsNew.setDateUpdate(LocalDateTime.now());
|
||||
customFieldsNew.setCreator(user);
|
||||
customFieldsNew.setDateCreate(LocalDateTime.now());
|
||||
// addList.add(customFieldsNew);
|
||||
customFieldsByIepMapper.insert(customFieldsNew);
|
||||
} else {
|
||||
existsRecord.setFieldValue(customValue.getFieldValue());
|
||||
existsRecord.setUpdater(user);
|
||||
existsRecord.setDateUpdate(LocalDateTime.now());
|
||||
existsRecord.setDateCreate(null);
|
||||
updateList.add(existsRecord);
|
||||
}
|
||||
}
|
||||
if (ListUtils.isNotEmpty(updateList)) {
|
||||
updateList.forEach(obj -> customFieldsByIepMapper.update(obj, Wrappers.lambdaUpdate(CustomFields.class)
|
||||
.eq(CustomFields::getHandle, obj.getHandle())
|
||||
.eq(CustomFields::getFieldName, obj.getFieldName())));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean fieldExists(String fieldName, List<CustomValue> customValueList) {
|
||||
for (CustomValue customValue : customValueList) {
|
||||
if (fieldName.equals(customValue.getFieldName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private CustomFields getExistsRecord(String name, List<CustomFields> existsList) {
|
||||
for (CustomFields customFields : existsList) {
|
||||
if (name.equals(customFields.getFieldName())) {
|
||||
return customFields;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private void checkResrce(String resrce, String site, List<String> errors) {
|
||||
ResrceExt re = getById(Resrce.genHandle(site, resrce));
|
||||
|
||||
BIN
mom-pms-core/src/main/resources/file/EqpDataTemplate.xlsx
Normal file
BIN
mom-pms-core/src/main/resources/file/EqpDataTemplate.xlsx
Normal file
Binary file not shown.
@ -1,8 +1,12 @@
|
||||
package com.foreverwin.mom.pms.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.foreverwin.iep.prd.entity.CustomFieldDef;
|
||||
import com.foreverwin.iep.prd.entity.CustomFields;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhaofeng_cheng
|
||||
@ -11,5 +15,9 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
*/
|
||||
@Mapper
|
||||
public interface CustomFieldsByIepMapper extends BaseMapper<CustomFields> {
|
||||
|
||||
|
||||
|
||||
List<CustomFields> findCustomFieldsListByHandle(@Param("site") String site, @Param("ref") String ref);
|
||||
|
||||
List<CustomFieldDef> findCustomFieldDefListByHandle(@Param("site") String site, @Param("tableName") String tableName);
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ public interface ResrceExtMapper extends MomBaseMapper<ResrceExt> {
|
||||
* @param searchText
|
||||
* @return
|
||||
*/
|
||||
IPage<SegmentBasis> getProcessPage(Page page,@Param ( "searchText" )String searchText);
|
||||
IPage<Operation> getProcessPage(Page page,@Param ( "tenantId" ) String tenantId, @Param ( "searchText" )String searchText);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
|
||||
@ -55,4 +55,10 @@
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="findCustomFieldsListByHandle" resultType="com.foreverwin.iep.prd.entity.CustomFields">
|
||||
select * from wip.custom_fields cf where cf.SITE = #{site} and cf.HANDLE = #{ref};
|
||||
</select>
|
||||
<select id="findCustomFieldDefListByHandle" resultType="com.foreverwin.iep.prd.entity.CustomFieldDef">
|
||||
select * from wip.custom_field_def cfd where cfd.SITE = #{site} and cfd.TABLE_NAME = #{tableName};
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@ -43,15 +43,13 @@
|
||||
<result property="ext5" column="EXT5"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="getProcessPage" resultType="com.foreverwin.iep.prd.entity.SegmentBasis">
|
||||
SELECT SEGMENT_NO, DESCRIPTION
|
||||
FROM `segment_basis`
|
||||
<where>
|
||||
<if test="searchText != null and searchText != ''">
|
||||
AND (DESCRIPTION LIKE concat('%', #{searchText}, '%')
|
||||
OR SEGMENT_NO LIKE concat('%', #{searchText}, '%'))
|
||||
</if>
|
||||
</where>
|
||||
<select id="getProcessPage" resultType="com.foreverwin.iep.prd.entity.Operation">
|
||||
SELECT OPERATION, DESCRIPTION
|
||||
FROM wip.operation o where o.SITE = #{tenantId}
|
||||
<if test="searchText != null and searchText != ''">
|
||||
AND (DESCRIPTION LIKE concat('%', #{searchText}, '%')
|
||||
OR OPERATION LIKE concat('%', #{searchText}, '%'))
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="getPage" resultType="com.foreverwin.mom.pms.dto.ResrceExtDTO">
|
||||
@ -78,6 +76,7 @@
|
||||
r.operation_manual,
|
||||
r.is_have_rfid,
|
||||
r.`PROCEDURE`,
|
||||
o.DESCRIPTION PROCEDURE_DESCRIPTION,
|
||||
r.site,
|
||||
r.date_create,
|
||||
r.creator,
|
||||
|
||||
6
pom.xml
6
pom.xml
@ -38,6 +38,12 @@
|
||||
<artifactId>mom-pms-db</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>mom-common-oss</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user