|
@@ -0,0 +1,142 @@
|
|
|
+package com.kingtom.shengtai.app.srm.service.impl;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import com.kingtom.kirin.app.org.model.OrgPerson;
|
|
|
+import com.kingtom.kirin.app.org.service.IOrgPersonService;
|
|
|
+import com.kingtom.kirin.app.system.utils.SystemUtils;
|
|
|
+import com.kingtom.kirin.core.common.base.service.impl.BaseServiceImpl;
|
|
|
+import com.kingtom.kirin.core.common.exception.AppException;
|
|
|
+import com.kingtom.kirin.core.common.utils.CollectionUtils;
|
|
|
+import com.kingtom.kirin.core.common.utils.IDUtils;
|
|
|
+import com.kingtom.shengtai.app.srm.dao.ISrmSupplierDao;
|
|
|
+import com.kingtom.shengtai.app.srm.model.SrmSupplier;
|
|
|
+import com.kingtom.shengtai.app.srm.model.SrmSupplierDO;
|
|
|
+import com.kingtom.shengtai.app.srm.service.ISrmSupplierService;
|
|
|
+import com.mybatisflex.core.paginate.Page;
|
|
|
+import com.mybatisflex.core.query.QueryCondition;
|
|
|
+import com.mybatisflex.core.query.RawQueryCondition;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import static com.kingtom.shengtai.app.srm.model.table.SrmSupplierTableDef.SRM_SUPPLIER;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 供应商信息表 服务层实现。
|
|
|
+ *
|
|
|
+ * @author 86181
|
|
|
+ * @since 2023-12-21
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class SrmSupplierServiceImpl extends BaseServiceImpl<ISrmSupplierDao, SrmSupplier>
|
|
|
+ implements ISrmSupplierService{
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOrgPersonService personService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SrmSupplierDO create(SrmSupplier entity){
|
|
|
+ if(entity.getId() == null){
|
|
|
+ entity.setId(IDUtils.newUUID());
|
|
|
+ }
|
|
|
+ if(StringUtils.isEmpty(entity.getName())){
|
|
|
+ throw new AppException("供应商名称为空,新建供应商失败!");
|
|
|
+ }
|
|
|
+ if(StringUtils.isEmpty(entity.getType())){
|
|
|
+ throw new AppException("供应商类型为空,新建供应商失败!");
|
|
|
+ }
|
|
|
+ entity.setGmtCreate(new Date());
|
|
|
+ entity.setGmtModified(entity.getGmtCreate());
|
|
|
+ entity.setSysId(SystemUtils.getCurrentSystemId());
|
|
|
+ boolean f = mapper.insert(entity) > 0;
|
|
|
+ if(!f){
|
|
|
+ throw new AppException("落库出错,新建供应商失败!");
|
|
|
+ }
|
|
|
+ return findById(entity.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteById(String id){
|
|
|
+ if(StringUtils.isEmpty(id)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ boolean f = mapper.deleteById(id) > 0;
|
|
|
+ if(!f){
|
|
|
+ throw new AppException("落库出错,删除供应商失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteByIds(List<String> ids){
|
|
|
+ if(CollectionUtils.isEmpty(ids)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ boolean f = mapper.deleteBatchByIds(ids) > 0;
|
|
|
+ if(!f){
|
|
|
+ throw new AppException("落库出错,删除供应商失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SrmSupplierDO update(SrmSupplier entity){
|
|
|
+ if(entity == null || entity.getId() == null){
|
|
|
+ throw new AppException("参数错误,更新供应商失败!");
|
|
|
+ }
|
|
|
+ entity.setGmtModified(new Date());
|
|
|
+ boolean f = mapper.update(entity) > 0;
|
|
|
+ if(!f){
|
|
|
+ throw new AppException("落库出错,更新供应商失败!");
|
|
|
+ }
|
|
|
+ return findById(entity.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SrmSupplierDO findById(String id){
|
|
|
+ if(StringUtils.isEmpty(id)){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ SrmSupplier srmSupplier = mapper.selectOneById(id);
|
|
|
+ if(srmSupplier == null){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ SrmSupplierDO build = SrmSupplierDO.builder().supplier(srmSupplier).build();
|
|
|
+ if(StringUtils.isNotEmpty(srmSupplier.getPerson())){
|
|
|
+ build.setPerson(personService.findById(srmSupplier.getPerson()));
|
|
|
+ }
|
|
|
+ return build;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<SrmSupplierDO> page(String name, String type, String state, List<String> products, Integer pageNum,
|
|
|
+ Integer pageSize){
|
|
|
+ products = products == null ? new ArrayList<>() : products;
|
|
|
+ QueryCondition condition =
|
|
|
+ QueryCondition.createEmpty().and(SRM_SUPPLIER.NAME.like(name).when(StringUtils.isNotEmpty(name)))
|
|
|
+ .and(SRM_SUPPLIER.TYPE.like(type).when(StringUtils.isNotEmpty(type)))
|
|
|
+ .and(SRM_SUPPLIER.STATE.like(state).when(StringUtils.isNotEmpty(state)))
|
|
|
+ .and(new RawQueryCondition(
|
|
|
+ "product::jsonb ??& array['" + StringUtils.join(products, "','") + "']").when(
|
|
|
+ CollectionUtils.isNotEmpty(products)));
|
|
|
+ Page<SrmSupplier> paginate = mapper.paginate(pageNum, pageSize, condition);
|
|
|
+ if(CollectionUtils.isEmpty(paginate.getRecords())){
|
|
|
+ return new Page<>(new ArrayList<>(), pageNum, pageSize, paginate.getTotalRow());
|
|
|
+ }
|
|
|
+ List<String> personIds =
|
|
|
+ paginate.getRecords().stream().map(SrmSupplier::getPerson).collect(Collectors.toList());
|
|
|
+ List<OrgPerson> people = new ArrayList<>();
|
|
|
+ if(CollectionUtils.isNotEmpty(personIds)){
|
|
|
+ people = personService.listByIds(personIds);
|
|
|
+ }
|
|
|
+ Map<String, OrgPerson> personMap = people.stream().collect(Collectors.toMap(OrgPerson::getId, e -> e));
|
|
|
+ List<SrmSupplierDO> collect = paginate.getRecords().stream()
|
|
|
+ .map(e -> SrmSupplierDO.builder().supplier(e).person(personMap.get(e.getPerson())).build())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return new Page<>(collect, pageNum, pageSize, paginate.getTotalRow());
|
|
|
+ }
|
|
|
+
|
|
|
+}
|