diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/entity/FontSupplierEntity.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/entity/FontSupplierEntity.java new file mode 100644 index 0000000..82babdb --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/entity/FontSupplierEntity.java @@ -0,0 +1,46 @@ +package com.digiwin.athena.app.infra.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.digiwin.athena.opt.persistence.domain.BaseMgrEntity; +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 人资报道对象 cim_item_supplier + * + * @author bk + * @date 2023-04-28 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +@TableName(value = "cim_item_supplier", autoResultMap = true) +public class FontSupplierEntity extends BaseMgrEntity { + private static final long serialVersionUID = 1L; + + + /** 品号 */ + @SerializedName("item_no") + private String itemNo; + + /** 品名 */ + @SerializedName("item_name") + private String itemName; + + /** 供应商编号 */ + @SerializedName("supplier_no") + private String supplierNo; + + /** 供应商名称 */ + @SerializedName("supplier_name") + private String supplierName; + + /** 单价 */ + @SerializedName("price") + private String price; + +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/repository/FontSupplierRepository.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/repository/FontSupplierRepository.java new file mode 100644 index 0000000..2570407 --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/repository/FontSupplierRepository.java @@ -0,0 +1,11 @@ +package com.digiwin.athena.app.infra.repository; + +import com.digiwin.athena.app.infra.entity.FontSupplierEntity; +import com.digiwin.athena.opt.persistence.repository.BaseRepository; + +/** + * @auther: bk + * @date: 2023/9/1 + */ +public interface FontSupplierRepository extends BaseRepository { +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/service/FontSupplierService.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/service/FontSupplierService.java new file mode 100644 index 0000000..8d11c9d --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/service/FontSupplierService.java @@ -0,0 +1,11 @@ +package com.digiwin.athena.app.infra.service; + +import com.digiwin.athena.app.infra.entity.FontSupplierEntity; +import com.digiwin.athena.opt.persistence.service.IBaseService; + +/** + * @auther: zhenggl + * @date: 2023/9/1 + */ +public interface FontSupplierService extends IBaseService { +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/service/Impl/FontSupplierServiceImpl.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/service/Impl/FontSupplierServiceImpl.java new file mode 100644 index 0000000..ad1fafa --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/infra/service/Impl/FontSupplierServiceImpl.java @@ -0,0 +1,16 @@ +package com.digiwin.athena.app.infra.service.Impl; + + +import com.digiwin.athena.app.infra.entity.FontSupplierEntity; +import com.digiwin.athena.app.infra.repository.FontSupplierRepository; +import com.digiwin.athena.app.infra.service.FontSupplierService; +import com.digiwin.athena.opt.persistence.service.impl.AbsBaseService; +import org.springframework.stereotype.Service; + +/** + * @auther: bk + * @date: 2023/9/1 + */ +@Service +public class FontSupplierServiceImpl extends AbsBaseService implements FontSupplierService { +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/provider/FontSupplierEAIService.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/provider/FontSupplierEAIService.java new file mode 100644 index 0000000..2d5fae5 --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/provider/FontSupplierEAIService.java @@ -0,0 +1,56 @@ +package com.digiwin.athena.app.provider; + +import com.digiwin.app.service.DWEAIResult; +import com.digiwin.app.service.DWService; +import com.digiwin.app.service.eai.EAIService; +import com.digiwin.athena.app.service.supplier.FontSupplierUtil; + +import java.util.Map; + +/** + * @auther: bk + * @date: 2023/9/1 + */ +public interface FontSupplierEAIService extends DWService { + + + /** + * 品号供应商修改 + * @param headers + * @param messageBody + * @return + * @throws Exception + */ + @EAIService(id = FontSupplierUtil.DEMO_FONT_ITEM_SUPPLIER_INFO_UPDATE) + DWEAIResult update(Map headers, String messageBody) throws Exception; + + /** + * 品号供应商获取 + * @param headers + * @param messageBody + * @return + * @throws Exception + */ + @EAIService(id = FontSupplierUtil.DEMO_FONT_ITEM_SUPPLIER_INFO_GET) + DWEAIResult get(Map headers, String messageBody) throws Exception; + + /** + * 品号供应商新增 + * @param headers + * @param messageBody + * @return + * @throws Exception + */ + @EAIService(id = FontSupplierUtil.DEMO_FONT_ITEM_SUPPLIER_INFO_CREATE) + DWEAIResult create(Map headers, String messageBody) throws Exception; + + /** + * 品号供应商删除 + * @param headers + * @param messageBody + * @return + * @throws Exception + */ + @EAIService(id = FontSupplierUtil.DEMO_FONT_ITEM_SUPPLIER_INFO_DELETE) + DWEAIResult delete(Map headers, String messageBody) throws Exception; +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/provider/impl/FontSupplierEAIServiceImpl.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/provider/impl/FontSupplierEAIServiceImpl.java new file mode 100644 index 0000000..07c4855 --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/provider/impl/FontSupplierEAIServiceImpl.java @@ -0,0 +1,40 @@ +package com.digiwin.athena.app.provider.impl; + +import com.digiwin.app.service.DWEAIResult; +import com.digiwin.athena.app.provider.FontSupplierEAIService; +import com.digiwin.athena.app.service.supplier.FontSupplierUtil; +import com.digiwin.athena.opt.common.eai.service.EAIServiceContext; + +import javax.annotation.Resource; +import java.util.Map; + +/** + * @auther: bk + * @date: 2023/9/1 + */ +public class FontSupplierEAIServiceImpl implements FontSupplierEAIService { + + @Resource + private EAIServiceContext eaiServiceContext; + + @Override + public DWEAIResult update(Map headers, String messageBody) throws Exception { + return eaiServiceContext.execute(FontSupplierUtil.DEMO_FONT_ITEM_SUPPLIER_INFO_UPDATE,headers,messageBody); + } + + @Override + public DWEAIResult get(Map headers, String messageBody) throws Exception { + return eaiServiceContext.execute(FontSupplierUtil.DEMO_FONT_ITEM_SUPPLIER_INFO_GET,headers,messageBody); + } + + + @Override + public DWEAIResult create(Map headers, String messageBody) throws Exception { + return eaiServiceContext.execute(FontSupplierUtil.DEMO_FONT_ITEM_SUPPLIER_INFO_CREATE,headers,messageBody); + } + + @Override + public DWEAIResult delete(Map headers, String messageBody) throws Exception { + return eaiServiceContext.execute(FontSupplierUtil.DEMO_FONT_ITEM_SUPPLIER_INFO_DELETE,headers,messageBody); + } +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/supplier/FontSupplierCreateEAIService.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/supplier/FontSupplierCreateEAIService.java new file mode 100644 index 0000000..72c5f67 --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/supplier/FontSupplierCreateEAIService.java @@ -0,0 +1,109 @@ +package com.digiwin.athena.app.service.supplier; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.digiwin.app.container.exceptions.DWBusinessException; +import com.digiwin.app.service.DWEAIResult; +import com.digiwin.athena.app.infra.entity.FontSupplierEntity; +import com.digiwin.athena.app.infra.entity.ItemExecutorEntity; +import com.digiwin.athena.app.infra.repository.FontSupplierRepository; +import com.digiwin.athena.app.infra.service.FontSupplierService; +import com.digiwin.athena.opt.common.eai.EAIRequest; +import com.digiwin.athena.opt.common.eai.EAIUtil; +import com.digiwin.athena.opt.common.eai.service.AbsEAIService; +import com.digiwin.athena.opt.common.security.SecurityUtil; +import lombok.extern.log4j.Log4j2; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentSkipListMap; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * @auther: bk + * @date: 2023/9/1 + */ +@Log4j2 +@Service +public class FontSupplierCreateEAIService extends AbsEAIService { + + @Resource + private FontSupplierService fontSupplierService; + + @Override + public String getServiceName() { + return FontSupplierUtil.DEMO_FONT_ITEM_SUPPLIER_INFO_CREATE; + } + + @Override + public DWEAIResult execute(Map headers, String messageBody) throws Exception { + EAIRequest eaiRequest = EAIRequest.build(messageBody); + List supplierInfo = eaiRequest.getObject("item_supplier_info", FontSupplierUtil.LIST_ENTITY_SUPPLIER); + //对必传参数 且 品号和供应商编号不可以重复 进行校验 + validateParameter(supplierInfo); + + fontSupplierService.saveBatch(supplierInfo); + return EAIUtil.buildEAIResult(new JSONObject().fluentPut("item_supplier_info", supplierInfo)); + } + + private void validateParameter(List supplierInfo) throws DWBusinessException { + if (Objects.isNull(supplierInfo) || supplierInfo.isEmpty()) { + throw new DWBusinessException("入参数据为空"); + } + for (FontSupplierEntity item : supplierInfo) { + if (StringUtils.isEmpty(item.getItemNo())) { + throw new DWBusinessException("品号字段值不为空或者NULL"); + } + if (StringUtils.isEmpty(item.getItemName())) { + throw new DWBusinessException("品名字段值不为空或者NULL"); + } + if (StringUtils.isEmpty(item.getSupplierNo())) { + throw new DWBusinessException("供应商编号字段值不为空或者NULL"); + } + if (StringUtils.isEmpty(item.getSupplierName())) { + throw new DWBusinessException("供应商名称字段值不为空或者NULL"); + } + } + List distinctList = supplierInfo.stream().filter(distinctByKey(item -> Stream.of(item.getItemNo(), item.getSupplierNo()).toArray())).collect(Collectors.toList()); + if (supplierInfo.size() > distinctList.size()) { + throw new DWBusinessException("品号和供应商编号入参重复"); + } + + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(FontSupplierEntity::getTenantSid, SecurityUtil.getUserProfile().getTenantSid()); + List entityList =fontSupplierService.list(queryWrapper); + + if (!entityList.isEmpty()) { + for (FontSupplierEntity executorEntity : entityList) { + String itemNo = executorEntity.getItemNo(); + String executorNo = executorEntity.getSupplierNo(); + boolean match = supplierInfo.stream().anyMatch(item -> Objects.equals(item.getItemNo(), itemNo) + && Objects.equals(item.getSupplierNo(), executorNo)); + if (match) { + throw new DWBusinessException("品号和供应商编号入参重复"); + } + } + } + } + + /** + * 用于对象去重 + * + * @param keyExtractor 需要去重的属性 + * @param + * @return + */ + private static Predicate distinctByKey(Function keyExtractor) { + //记录已有对象或者属性 + ConcurrentSkipListMap skipListMap = new ConcurrentSkipListMap<>(); + return t -> skipListMap.putIfAbsent(JSON.toJSONString(keyExtractor.apply(t)), Boolean.TRUE) == null; + } +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/supplier/FontSupplierDeleteEAIService.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/supplier/FontSupplierDeleteEAIService.java new file mode 100644 index 0000000..8a8283e --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/supplier/FontSupplierDeleteEAIService.java @@ -0,0 +1,46 @@ +package com.digiwin.athena.app.service.supplier; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.digiwin.app.service.DWEAIResult; +import com.digiwin.athena.app.infra.entity.FontSupplierEntity; +import com.digiwin.athena.app.infra.service.FontSupplierService; +import com.digiwin.athena.opt.common.eai.EAIRequest; +import com.digiwin.athena.opt.common.eai.EAIUtil; +import com.digiwin.athena.opt.common.eai.service.AbsEAIService; +import lombok.extern.log4j.Log4j2; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @auther: bk + * @date: 2023/8/31 + */ +@Service +@Log4j2 +public class FontSupplierDeleteEAIService extends AbsEAIService { + + + @Resource + private FontSupplierService fontSupplierService; + + @Override + public String getServiceName() { + return FontSupplierUtil.DEMO_FONT_ITEM_SUPPLIER_INFO_DELETE; + } + + @Override + public DWEAIResult execute(Map headers, String messageBody) throws Exception { + EAIRequest eaiRequest = EAIRequest.build(messageBody); + List supplierInfo = eaiRequest.getObject("item_supplier_info", FontSupplierUtil.LIST_ENTITY_SUPPLIER); + List collect = supplierInfo.stream().map(FontSupplierEntity::getId).collect(Collectors.toList()); + LambdaQueryWrapper lmq = new LambdaQueryWrapper<>(); + lmq.in(FontSupplierEntity::getId,collect); + fontSupplierService.remove(lmq); + return EAIUtil.buildEAIResult(new HashMap<>()); + } +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/supplier/FontSupplierGetEAIService.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/supplier/FontSupplierGetEAIService.java new file mode 100644 index 0000000..009fcdd --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/supplier/FontSupplierGetEAIService.java @@ -0,0 +1,61 @@ +package com.digiwin.athena.app.service.supplier; + +import com.alibaba.fastjson.JSONObject; +import com.alibaba.nacos.common.utils.CollectionUtils; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.digiwin.app.service.DWEAIResult; +import com.digiwin.athena.app.infra.entity.FontSupplierEntity; +import com.digiwin.athena.app.infra.service.FontSupplierService; +import com.digiwin.athena.opt.common.eai.EAIRequest; +import com.digiwin.athena.opt.common.eai.EAIUtil; +import com.digiwin.athena.opt.common.eai.service.AbsEAIService; +import com.digiwin.athena.opt.common.security.SecurityUtil; +import lombok.extern.log4j.Log4j2; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; + +/** + * @auther: bk + * @date: 2023/8/31 + */ +@Service +@Log4j2 +public class FontSupplierGetEAIService extends AbsEAIService { + + + @Resource + private FontSupplierService fontSupplierService; + + @Override + public String getServiceName() { + return FontSupplierUtil.DEMO_FONT_ITEM_SUPPLIER_INFO_GET; + } + + @Override + public DWEAIResult execute(Map headers, String messageBody) throws Exception { + EAIRequest eaiRequest = EAIRequest.build(messageBody); + List supplierInfo = eaiRequest.getObject("item_supplier_info", FontSupplierUtil.LIST_ENTITY_SUPPLIER); + LambdaQueryWrapper lmq = new LambdaQueryWrapper<>(); + lmq.eq(FontSupplierEntity::getTenantId, SecurityUtil.getUserProfile().getTenantId()); + if (CollectionUtils.isNotEmpty(supplierInfo)) { + lmq.and( + queryWrapperInner -> { + for (FontSupplierEntity fontSupplierEntity : supplierInfo) { + queryWrapperInner.or( + wrapper -> wrapper + .eq(FontSupplierEntity::getItemNo, fontSupplierEntity.getItemNo()) + .eq(FontSupplierEntity::getItemName, fontSupplierEntity.getItemName()) + .eq(FontSupplierEntity::getSupplierNo, fontSupplierEntity.getSupplierNo()) + .eq(FontSupplierEntity::getSupplierName, fontSupplierEntity.getSupplierName()) + ); + } + }); + } + + List list = fontSupplierService.list(lmq); + return EAIUtil.buildEAIResult(new JSONObject().fluentPut("item_supplier_info", list)); + } +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/supplier/FontSupplierUpdateEAIService.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/supplier/FontSupplierUpdateEAIService.java new file mode 100644 index 0000000..be3ae56 --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/supplier/FontSupplierUpdateEAIService.java @@ -0,0 +1,91 @@ +package com.digiwin.athena.app.service.supplier; + +import com.alibaba.fastjson.JSON; +import com.digiwin.app.container.exceptions.DWBusinessException; +import com.digiwin.app.service.DWEAIResult; +import com.digiwin.athena.app.infra.entity.FontSupplierEntity; +import com.digiwin.athena.app.infra.entity.ItemExecutorEntity; +import com.digiwin.athena.app.infra.service.FontSupplierService; +import com.digiwin.athena.opt.common.eai.EAIRequest; +import com.digiwin.athena.opt.common.eai.EAIUtil; +import com.digiwin.athena.opt.common.eai.service.AbsEAIService; +import lombok.extern.log4j.Log4j2; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentSkipListMap; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * @auther: bk + * @date: 2023/8/31 + */ +@Service +@Log4j2 +public class FontSupplierUpdateEAIService extends AbsEAIService { + + @Resource + private FontSupplierService supplierService; + + @Override + public String getServiceName() { + return FontSupplierUtil.DEMO_FONT_ITEM_SUPPLIER_INFO_UPDATE; + } + + @Override + public DWEAIResult execute(Map headers, String messageBody) throws Exception { + EAIRequest eaiRequest = EAIRequest.build(messageBody); + List supplierInfo = eaiRequest.getObject("item_supplier_info", FontSupplierUtil.LIST_ENTITY_SUPPLIER); + + //对必传参数 且 品号和执行人编号不可以重复 进行校验 + validateParameter(supplierInfo); + + supplierService.updateBatchById(supplierInfo); + return EAIUtil.buildEAIResult(new HashMap<>()); + } + + private void validateParameter(List supplierInfo) throws DWBusinessException { + if (Objects.isNull(supplierInfo) || supplierInfo.isEmpty()) { + throw new DWBusinessException("入参数据为空"); + } + for (FontSupplierEntity item : supplierInfo) { + if (StringUtils.isEmpty(item.getItemNo())) { + throw new DWBusinessException("品号字段值为空或者NULL"); + } + if (StringUtils.isEmpty(item.getItemName())) { + throw new DWBusinessException("品名字段值为空或者NULL"); + } + if (StringUtils.isEmpty(item.getSupplierNo())) { + throw new DWBusinessException("供应商no为空或者NULL"); + } + if (StringUtils.isEmpty(item.getSupplierName())) { + throw new DWBusinessException("供应商name为空或者NULL"); + } + } + List distinctList = supplierInfo.stream().filter(distinctByKey(item -> Stream.of(item.getItemNo(), item.getSupplierNo()).toArray())).collect(Collectors.toList()); + if (supplierInfo.size() > distinctList.size()) { + throw new DWBusinessException("品号和供应商编号入参重复"); + } + } + + /** + * 用于对象去重 + * + * @param keyExtractor 需要去重的属性 + * @param + * @return + */ + private static Predicate distinctByKey(Function keyExtractor) { + //记录已有对象或者属性 + ConcurrentSkipListMap skipListMap = new ConcurrentSkipListMap<>(); + return t -> skipListMap.putIfAbsent(JSON.toJSONString(keyExtractor.apply(t)), Boolean.TRUE) == null; + } +} diff --git a/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/supplier/FontSupplierUtil.java b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/supplier/FontSupplierUtil.java new file mode 100644 index 0000000..82e6f5a --- /dev/null +++ b/demo-athenaopt_backend/develop/src/main/java/com/digiwin/athena/app/service/supplier/FontSupplierUtil.java @@ -0,0 +1,29 @@ +package com.digiwin.athena.app.service.supplier; + +import com.alibaba.fastjson.TypeReference; +import com.digiwin.athena.app.infra.entity.FontSupplierEntity; +import com.digiwin.athena.app.infra.entity.ItemSupplierEntity; + +import java.awt.*; +import java.util.List; + +/** + * @auther: bk + * @date: 2023/8/31 + */ +public class FontSupplierUtil { + + /** + * 品号供应商get,update,delete + */ + public static final String DEMO_FONT_ITEM_SUPPLIER_INFO_UPDATE = "demo.font.item.supplier.info.update"; + + public static final String DEMO_FONT_ITEM_SUPPLIER_INFO_GET = "demo.font.item.supplier.info.get"; + + public static final String DEMO_FONT_ITEM_SUPPLIER_INFO_DELETE = "demo.font.item.supplier.info.delete"; + + public static final String DEMO_FONT_ITEM_SUPPLIER_INFO_CREATE = "demo.font.item.supplier.info.create"; + + public static final TypeReference> LIST_ENTITY_SUPPLIER = new TypeReference>() { + }; +}