feat: 绑定零部件新增更改删除PDM判断

This commit is contained in:
2024-04-30 17:13:40 +08:00
parent 0369417e07
commit f958d0a68a
6 changed files with 118 additions and 10 deletions
@@ -66,8 +66,9 @@ public class LawsBindPartController {
@AutoLog(value = "绑定零部件-使用绑定关系")
@ApiOperation(value="绑定零部件-使用绑定关系", notes="绑定零部件-使用绑定关系")
@GetMapping(value = "/useBindRelation")
public Result<LawsBindPart> useBindRelation(@RequestParam("id") String id) {
return Result.OK(lawsBindPartService.useBindRelation(id));
public Result<?> useBindRelation(@RequestParam("id") String id) {
lawsBindPartService.useBindRelation(id);
return Result.OK();
}
/**
@@ -78,7 +78,7 @@ public interface ILawsBindPartService extends IService<LawsBindPart> {
* @param id
* @return
*/
LawsBindPart useBindRelation(String id);
void useBindRelation(String id);
/**
* 使用绑定关系
@@ -1,11 +1,13 @@
package com.jero.modules.docking.bindPart.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.api.dto.message.SendMessageDTO;
import com.jero.common.api.vo.SendMessageAPI;
import com.jero.common.exception.JeroBootException;
import com.jero.common.system.vo.LoginUser;
import com.jero.modules.activiti.process.common.enums.StandardStateEnum;
@@ -16,6 +18,11 @@ import com.jero.modules.docking.bindPart.mapper.LawsBindPartMapper;
import com.jero.modules.docking.bindPart.service.ILawsBindPartDocService;
import com.jero.modules.docking.bindPart.service.ILawsBindPartService;
import com.jero.modules.docking.srms.service.SrmsApiService;
import com.jero.modules.laws.common.constant.MessageTemplateCodeCommon;
import com.jero.modules.laws.documenttool.entity.LawsDocumentSplit;
import com.jero.modules.laws.documenttool.mapper.DocumentSplitMapper;
import com.jero.modules.laws.documenttool.mapper.LawsDocumentSplitMapper;
import com.jero.modules.laws.documenttool.service.IDocumentSplitService;
import com.jero.modules.laws.enterprise.util.BeanCopyUtils;
import com.jero.modules.laws.standard.entity.LawsDomesticStandard;
import com.jero.modules.laws.standard.entity.LawsEnterpriseStandard;
@@ -23,10 +30,13 @@ import com.jero.modules.laws.standard.entity.LawsOverseasStandard;
import com.jero.modules.laws.standard.service.ILawsDomesticStandardService;
import com.jero.modules.laws.standard.service.ILawsEnterpriseStandardService;
import com.jero.modules.laws.standard.service.ILawsOverseasStandardService;
import com.jero.modules.message.handle.ISendMsgHandle;
import com.jero.modules.onlyoffice.entity.StandardFileType;
import com.jero.modules.split.entity.SarFileSplitInfoEO;
import com.jero.modules.split.service.ISarFileSplitInfoService;
import com.jero.modules.sys.utils.UserUtils;
import com.jero.modules.system.entity.SysUser;
import com.jero.modules.system.service.ISysUserService;
import com.jero.modules.tag.enums.TableNameEnum;
import org.springframework.stereotype.Service;
@@ -66,6 +76,15 @@ public class LawsBindPartServiceImpl extends ServiceImpl<LawsBindPartMapper, Law
@Resource
private SrmsApiService srmsApiService;
@Resource
private ISysUserService sysUserService;
@Resource
private SendMessageAPI sendMessageAPI;
@Resource
private DocumentSplitMapper documentSplitMapper;
@Override
public IPage<LawsBindPart> queryPage(LawsBindPart lawsBindPart, Integer pageNo, Integer pageSize) {
IPage<LawsBindPart> page = new Page<>(pageNo, pageSize);
@@ -75,10 +94,19 @@ public class LawsBindPartServiceImpl extends ServiceImpl<LawsBindPartMapper, Law
@Override
public void add(LawsBindPart lawsBindPart) {
// 访问PDM校验该零部件号是否可以修改
boolean canEdit = srmsApiService.validPartNoEdit(lawsBindPart.getPartNo(),
lawsBindPart.getPartName(),
getBindUsernameAndRealName(lawsBindPart.getBindUser()));
if (!canEdit) {
throw new JeroBootException("零部件号" + lawsBindPart.getPartNo() + "不可新增");
}
lawsBindPart.setBindTime(new Date());
save(lawsBindPart);
String clauseIds = lawsBindPart.getClauseIds();
this.saveBindPartDoc(clauseIds, lawsBindPart.getId());
// 发消息
this.sendMessageToBindUser(lawsBindPart);
}
private void saveBindPartDoc(String clauseIds, String bindId) {
@@ -96,11 +124,44 @@ public class LawsBindPartServiceImpl extends ServiceImpl<LawsBindPartMapper, Law
lawsBindPartDocService.saveBatch(lawsBindPartDocList);
}
private String getBindUsernameAndRealName(String userId) {
SysUser user = sysUserService.getById(userId);
return user.getRealname() + "(" + user.getUsername() + ")";
}
/**
* 向pdm确认零部件是否可以修改
* @param ids
*/
private void pdmValidPartEdit(List<String> ids) {
List<LawsBindPart> lawsBindParts = lawsBindPartMapper.selectBatchIds(ids);
if (CollectionUtil.isEmpty(lawsBindParts)) {
return;
}
// 转换为Map
Map<String, LawsBindPart> lawsBindPartMap = lawsBindParts.stream().collect(Collectors.toMap(LawsBindPart::getId, e -> e));
Set<String> errPartSet = new HashSet<>();
// 访问PDM校验该零部件号是否可以修改
for (String id : ids) {
LawsBindPart existBindPart = lawsBindPartMap.get(id);
boolean canEdit = srmsApiService.validPartNoEdit(existBindPart.getPartNo(),
existBindPart.getPartName(),
getBindUsernameAndRealName(existBindPart.getBindUser()));
if (!canEdit) {
errPartSet.add(existBindPart.getPartNo());
}
}
if (CollectionUtil.isNotEmpty(errPartSet)) {
throw new JeroBootException("零部件号" + String.join(",", errPartSet) + "不能修改");
}
}
@Override
public void editById(LawsBindPart lawsBindPart) {
if (StrUtil.isBlank(lawsBindPart.getId())) {
throw new JeroBootException("id不能为空");
}
this.pdmValidPartEdit(Collections.singletonList(lawsBindPart.getId()));
updateById(lawsBindPart);
// 清空关联关系
removeBindPartDoc(lawsBindPart.getId());
@@ -121,12 +182,16 @@ public class LawsBindPartServiceImpl extends ServiceImpl<LawsBindPartMapper, Law
@Override
public void deleteById(String id) {
// 访问PDM校验该零部件号是否可以修改
this.pdmValidPartEdit(Collections.singletonList(id));
removeById(id);
removeBindPartDoc(id);
}
@Override
public void deleteByIds(List<String> ids) {
// 访问PDM校验该零部件号是否可以修改
this.pdmValidPartEdit(ids);
removeByIds(ids);
removeBindPartDoc(ids.stream().map(String::valueOf).collect(Collectors.joining(",")));
}
@@ -228,7 +293,7 @@ public class LawsBindPartServiceImpl extends ServiceImpl<LawsBindPartMapper, Law
}
@Override
public LawsBindPart useBindRelation(String id) {
public void useBindRelation(String id) {
LawsBindPart bindPart = getById(id);
LawsBindPart newBindPart = BeanCopyUtils.copyBean(bindPart, LawsBindPart.class);
LoginUser currentUser = UserUtils.getCurrentUser();
@@ -249,7 +314,9 @@ public class LawsBindPartServiceImpl extends ServiceImpl<LawsBindPartMapper, Law
b.setBindId(newId);
});
lawsBindPartDocService.saveBatch(list);
return null;
// 发消息
this.sendMessageToBindUser(newBindPart);
}
/**
@@ -281,6 +348,45 @@ public class LawsBindPartServiceImpl extends ServiceImpl<LawsBindPartMapper, Law
}
return null;
}
private void sendMessageToBindUser(LawsBindPart lawsBindPart) {
String userId = UserUtils.getUserId();
String standardId = lawsBindPart.getStandardId();
String clauseIds = lawsBindPart.getClauseIds();
Map<String, String> sendMap = new HashMap<>();
if (StrUtil.isBlank(clauseIds)) {
sendMap.put("clause", "");
} else {
List<String> clauseIdList = Arrays.asList(clauseIds.split(","));
List<LawsDocumentSplit> lawsDocumentSplits = documentSplitMapper.selectBatchIds(clauseIdList);
String clause = lawsDocumentSplits.stream().sorted()
.map(LawsDocumentSplit::getItemNum).collect(Collectors.joining(","));
String msg = "" + clause + "条款";
sendMap.put("clause", msg);
}
String standardNumber = "";
LawsEnterpriseStandard es = esService.getById(standardId);
if (es != null) {
standardNumber = es.getStandardNumber();
}
LawsDomesticStandard gb = gbService.getById(standardId);
if (gb != null) {
standardNumber = gb.getStandardNumber();
}
LawsOverseasStandard fb = fbService.getById(standardId);
if (fb != null) {
standardNumber = fb.getStandardNumber();
}
// 发送消息
SendMessageDTO sendMessageDTO = new SendMessageDTO();
sendMessageDTO.setTemplateCode(MessageTemplateCodeCommon.BIND_PART_ADD);
sendMessageDTO.setToUserId(userId);
sendMap.put("standardNo", standardNumber);
sendMap.put("partNo", lawsBindPart.getPartNo() + lawsBindPart.getPartName());
sendMessageDTO.setMap(sendMap);
sendMessageAPI.sendMessage(sendMessageDTO);
}
}
@@ -6,8 +6,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jero.common.api.vo.Result;
import com.jero.common.aspect.annotation.AutoLog;
import com.jero.common.constant.CommonConstant;
import com.jero.common.exception.JeroBootException;
import com.jero.modules.docking.srms.entity.LawsPartStandard;
import com.jero.modules.docking.srms.service.SrmsApiService;
import com.jero.modules.docking.srms.vo.ByFileRows;
import com.jero.modules.docking.srms.vo.StandardPageVO;
@@ -198,6 +196,7 @@ public class SrmsApiController {
try {
List<JSONObject> rows = srmsApiService.getBindPartStandardInfo(json);
JSONObject resultJson = new JSONObject();
// TODO interface_id
resultJson.put("MessageHeader", srmsApiService.getMessageHandler("interface_id", uuid));
JSONObject jsonResponses = ResponsesUtil.getJsonOkUpper();
if (!Objects.isNull(rows)) {
@@ -49,6 +49,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@@ -783,10 +784,10 @@ public class SrmsApiServiceImpl implements SrmsApiService {
}
@Override
public boolean validPartNoEdit(String partNo, String partName, String bindUserInfo) {
public boolean validPartNoEdit(@NotNull String partNo, String partName, @NotNull String bindUserInfo) {
try {
JSONObject all = new JSONObject();
// todo Interface_IDUUID
// todo Interface_ID
all.put(MESSAGE_HANDLER, getMessageHandler("interfaceId", null));
JSONObject requests = new JSONObject();
requests.put("PartNum", partNo);