|
|
@@ -0,0 +1,294 @@
|
|
|
+package org.dromara.customer.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.dromara.customer.domain.SupplierProcurement;
|
|
|
+import org.dromara.customer.domain.SupplyArea;
|
|
|
+import org.dromara.customer.domain.vo.SupplierInformationVo;
|
|
|
+import org.dromara.customer.service.ISupplierProcurementService;
|
|
|
+import org.dromara.customer.service.ISupplyAreaService;
|
|
|
+import org.dromara.system.api.RemoteComStaffService;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.dromara.customer.domain.bo.SupplierInfoBo;
|
|
|
+import org.dromara.customer.domain.vo.SupplierInfoVo;
|
|
|
+import org.dromara.customer.domain.SupplierInfo;
|
|
|
+import org.dromara.customer.mapper.SupplierInfoMapper;
|
|
|
+import org.dromara.customer.service.ISupplierInfoService;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 供应商信息Service业务层处理
|
|
|
+ *
|
|
|
+ * @author LionLi
|
|
|
+ * @date 2026-01-09
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Service
|
|
|
+public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, SupplierInfo> implements ISupplierInfoService {
|
|
|
+
|
|
|
+ private final SupplierInfoMapper baseMapper;
|
|
|
+
|
|
|
+ private final ISupplierProcurementService supplierProcurementService;
|
|
|
+
|
|
|
+ private final ISupplyAreaService supplyAreaService;
|
|
|
+
|
|
|
+ private final RemoteComStaffService remoteComStaffService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询供应商信息
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return 供应商信息
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public SupplierInfoVo queryById(Long id){
|
|
|
+ return baseMapper.selectVoById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询供应商信息列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @param pageQuery 分页参数
|
|
|
+ * @return 供应商信息分页列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<SupplierInfoVo> queryPageList(SupplierInfoBo bo, PageQuery pageQuery) {
|
|
|
+ LambdaQueryWrapper<SupplierInfo> lqw = buildQueryWrapper(bo);
|
|
|
+ Page<SupplierInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
+ return TableDataInfo.build(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<SupplierInformationVo> getSupplierInformation(SupplierInfoBo bo, PageQuery pageQuery) {
|
|
|
+ LambdaQueryWrapper<SupplierInfo> lqw = buildQueryWrapper(bo);
|
|
|
+ Page<SupplierInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
+ List<SupplierInformationVo> supplierInformationVos = handleProcurementInfo(result.getRecords());
|
|
|
+ Page<SupplierInformationVo> newPage = new Page<>();
|
|
|
+ newPage.setRecords(supplierInformationVos);
|
|
|
+ newPage.setTotal(result.getTotal());
|
|
|
+ newPage.setCurrent(result.getCurrent());
|
|
|
+ newPage.setSize(result.getSize());
|
|
|
+ return TableDataInfo.build(newPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<SupplierInformationVo> getSupplierApproveInformation(SupplierInfoBo bo, PageQuery pageQuery) {
|
|
|
+ LambdaQueryWrapper<SupplierInfo> lqw = buildQueryWrapper(bo);
|
|
|
+ if (bo.getSupplyStatus() == null){
|
|
|
+ List<Long> status = new ArrayList<>();
|
|
|
+ status.add(0L);
|
|
|
+ status.add(4L);
|
|
|
+ lqw.in(SupplierInfo::getSupplyStatus,status);
|
|
|
+ }
|
|
|
+ Page<SupplierInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
+ List<SupplierInformationVo> supplierInformationVos = handleProcurementInfo(result.getRecords());
|
|
|
+ Page<SupplierInformationVo> newPage = new Page<>();
|
|
|
+ newPage.setRecords(supplierInformationVos);
|
|
|
+ newPage.setTotal(result.getTotal());
|
|
|
+ newPage.setCurrent(result.getCurrent());
|
|
|
+ newPage.setSize(result.getSize());
|
|
|
+ return TableDataInfo.build(newPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理采购员和产品经理信息
|
|
|
+ */
|
|
|
+ private List<SupplierInformationVo> handleProcurementInfo(List<SupplierInfoVo> records) {
|
|
|
+ List<SupplierInformationVo> supplierInformationVos = records.stream()
|
|
|
+ .map(supplierInfoVo -> {
|
|
|
+ SupplierInformationVo targetVo = new SupplierInformationVo();
|
|
|
+ BeanUtils.copyProperties(supplierInfoVo, targetVo);
|
|
|
+ return targetVo;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for (SupplierInformationVo vo : supplierInformationVos) {
|
|
|
+ // 查询管理人员和采购人员
|
|
|
+ Long id = vo.getId();
|
|
|
+ LambdaQueryWrapper<SupplierProcurement> procurementLqw = Wrappers.lambdaQuery();
|
|
|
+ procurementLqw.eq(SupplierProcurement::getSupplierId, id);
|
|
|
+ SupplierProcurement one = supplierProcurementService.getOne(procurementLqw);
|
|
|
+ if (one != null) {
|
|
|
+ Long productManager = one.getProductManager();
|
|
|
+ Long purchaser = one.getPurchaser();
|
|
|
+ Set<Long> Ids = new HashSet<>();
|
|
|
+ if (purchaser != null) Ids.add(purchaser);
|
|
|
+ if (productManager != null) Ids.add(productManager);
|
|
|
+
|
|
|
+ if (!Ids.isEmpty()) {
|
|
|
+ Map<Long, String> longStringMap = remoteComStaffService.selectStaffNameByIds(Ids);
|
|
|
+ vo.setProductManager(longStringMap.get(productManager));
|
|
|
+ vo.setBuyer(longStringMap.get(purchaser));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询供应地区
|
|
|
+ LambdaQueryWrapper<SupplyArea> supplyProvinceAreaLqw = Wrappers.lambdaQuery();
|
|
|
+ supplyProvinceAreaLqw.eq(SupplyArea::getSupplierId, id)
|
|
|
+ .eq(SupplyArea::getLevel,"1");
|
|
|
+ List<SupplyArea> supplyProvinceArealist = supplyAreaService.list(supplyProvinceAreaLqw);
|
|
|
+
|
|
|
+ LambdaQueryWrapper<SupplyArea> supplyCityAreaLqw = Wrappers.lambdaQuery();
|
|
|
+ supplyCityAreaLqw.eq(SupplyArea::getSupplierId, id)
|
|
|
+ .eq(SupplyArea::getLevel,"2");
|
|
|
+ List<SupplyArea> supplyCityArealist = supplyAreaService.list(supplyCityAreaLqw);
|
|
|
+
|
|
|
+ // 拼接省份名称
|
|
|
+ String provinceNames = supplyProvinceArealist.stream()
|
|
|
+ .map(SupplyArea::getAreaName)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+
|
|
|
+ // 拼接城市名称
|
|
|
+ String cityNames = supplyCityArealist.stream()
|
|
|
+ .map(SupplyArea::getAreaName)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+
|
|
|
+ vo.setProvince(provinceNames);
|
|
|
+ vo.setCity(cityNames);
|
|
|
+ }
|
|
|
+ return supplierInformationVos;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询符合条件的供应商信息列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @return 供应商信息列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<SupplierInfoVo> queryList(SupplierInfoBo bo) {
|
|
|
+ LambdaQueryWrapper<SupplierInfo> lqw = buildQueryWrapper(bo);
|
|
|
+ return baseMapper.selectVoList(lqw);
|
|
|
+ }
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<SupplierInfo> buildQueryWrapper(SupplierInfoBo bo) {
|
|
|
+ Map<String, Object> params = bo.getParams();
|
|
|
+ LambdaQueryWrapper<SupplierInfo> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.orderByAsc(SupplierInfo::getId);
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getSupplierNo()), SupplierInfo::getSupplierNo, bo.getSupplierNo());
|
|
|
+ lqw.like(StringUtils.isNotBlank(bo.getEnterpriseName()), SupplierInfo::getEnterpriseName, bo.getEnterpriseName());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getMembershipSize()), SupplierInfo::getMembershipSize, bo.getMembershipSize());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getSupplierType()), SupplierInfo::getSupplierType, bo.getSupplierType());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getCooperationType()), SupplierInfo::getCooperationType, bo.getCooperationType());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getFixedPhone()), SupplierInfo::getFixedPhone, bo.getFixedPhone());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getFax()), SupplierInfo::getFax, bo.getFax());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getUrl()), SupplierInfo::getUrl, bo.getUrl());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getPostCode()), SupplierInfo::getPostCode, bo.getPostCode());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getMailbox()), SupplierInfo::getMailbox, bo.getMailbox());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getOfficeProvince()), SupplierInfo::getOfficeProvince, bo.getOfficeProvince());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getOfficeCity()), SupplierInfo::getOfficeCity, bo.getOfficeCity());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getOfficeCounty()), SupplierInfo::getOfficeCounty, bo.getOfficeCounty());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getOfficeAddress()), SupplierInfo::getOfficeAddress, bo.getOfficeAddress());
|
|
|
+ lqw.like(StringUtils.isNotBlank(bo.getBusinessName()), SupplierInfo::getBusinessName, bo.getBusinessName());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getSocialCreditCode()), SupplierInfo::getSocialCreditCode, bo.getSocialCreditCode());
|
|
|
+ lqw.like(StringUtils.isNotBlank(bo.getLegalPersonName()), SupplierInfo::getLegalPersonName, bo.getLegalPersonName());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getLegalPersonId()), SupplierInfo::getLegalPersonId, bo.getLegalPersonId());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getRegisteredCapital()), SupplierInfo::getRegisteredCapital, bo.getRegisteredCapital());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getBusinessProvince()), SupplierInfo::getBusinessProvince, bo.getBusinessProvince());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getBusinessCity()), SupplierInfo::getBusinessCity, bo.getBusinessCity());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getBusinessCounty()), SupplierInfo::getBusinessCounty, bo.getBusinessCounty());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getBusinessAddress()), SupplierInfo::getBusinessAddress, bo.getBusinessAddress());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getBusinessLicense()), SupplierInfo::getBusinessLicense, bo.getBusinessLicense());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getInvoiceType()), SupplierInfo::getInvoiceType, bo.getInvoiceType());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getInvoiceHeader()), SupplierInfo::getInvoiceHeader, bo.getInvoiceHeader());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getTaxpayerIdentifier()), SupplierInfo::getTaxpayerIdentifier, bo.getTaxpayerIdentifier());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getDepositaryBank()), SupplierInfo::getDepositaryBank, bo.getDepositaryBank());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getRowNum()), SupplierInfo::getRowNum, bo.getRowNum());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getBankAccounts()), SupplierInfo::getBankAccounts, bo.getBankAccounts());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getInvoiceAddress()), SupplierInfo::getInvoiceAddress, bo.getInvoiceAddress());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getInvoiceLandline()), SupplierInfo::getInvoiceLandline, bo.getInvoiceLandline());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getScopeSupply()), SupplierInfo::getScopeSupply, bo.getScopeSupply());
|
|
|
+ lqw.eq(bo.getCooperateWay() != null, SupplierInfo::getCooperateWay, bo.getCooperateWay());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getCooperateLevel()), SupplierInfo::getCooperateLevel, bo.getCooperateLevel());
|
|
|
+ lqw.eq(bo.getContractEndTime() != null, SupplierInfo::getContractEndTime, bo.getContractEndTime());
|
|
|
+ lqw.eq(bo.getSupplyStatus() != null, SupplierInfo::getSupplyStatus, bo.getSupplyStatus());
|
|
|
+ lqw.eq(bo.getSupplyScore() != null, SupplierInfo::getSupplyScore, bo.getSupplyScore());
|
|
|
+ lqw.eq(bo.getYearSales() != null, SupplierInfo::getYearSales, bo.getYearSales());
|
|
|
+ lqw.like(StringUtils.isNotBlank(bo.getSupplierName()), SupplierInfo::getSupplierName, bo.getSupplierName());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getSupplierPhone()), SupplierInfo::getSupplierPhone, bo.getSupplierPhone());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getSupplierPassword()), SupplierInfo::getSupplierPassword, bo.getSupplierPassword());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getOperatingCategory()), SupplierInfo::getOperatingCategory, bo.getOperatingCategory());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getOperatingBrand()), SupplierInfo::getOperatingBrand, bo.getOperatingBrand());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getOtherCustomers()), SupplierInfo::getOtherCustomers, bo.getOtherCustomers());
|
|
|
+ lqw.like(StringUtils.isNotBlank(bo.getShortName()), SupplierInfo::getShortName, bo.getShortName());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getIndustrCategory()), SupplierInfo::getIndustrCategory, bo.getIndustrCategory());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getType()), SupplierInfo::getType, bo.getType());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getOwnedCompany()), SupplierInfo::getOwnedCompany, bo.getOwnedCompany());
|
|
|
+ lqw.eq(bo.getPushStatus() != null, SupplierInfo::getPushStatus, bo.getPushStatus());
|
|
|
+ lqw.eq(bo.getCreated() != null, SupplierInfo::getCreated, bo.getCreated());
|
|
|
+ lqw.eq(bo.getModify() != null, SupplierInfo::getModify, bo.getModify());
|
|
|
+ lqw.eq(bo.getValidityFromDate() != null, SupplierInfo::getValidityFromDate, bo.getValidityFromDate());
|
|
|
+ lqw.eq(bo.getValidityToDate() != null, SupplierInfo::getValidityToDate, bo.getValidityToDate());
|
|
|
+ lqw.eq(bo.getRowNo() != null, SupplierInfo::getRowNo, bo.getRowNo());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getPersonImage()), SupplierInfo::getPersonImage, bo.getPersonImage());
|
|
|
+ lqw.eq(bo.getAbutmentNo() != null, SupplierInfo::getAbutmentNo, bo.getAbutmentNo());
|
|
|
+ lqw.eq(bo.getCooperative() != null, SupplierInfo::getCooperative, bo.getCooperative());
|
|
|
+ return lqw;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增供应商信息
|
|
|
+ *
|
|
|
+ * @param bo 供应商信息
|
|
|
+ * @return 是否新增成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean insertByBo(SupplierInfoBo bo) {
|
|
|
+ SupplierInfo add = MapstructUtils.convert(bo, SupplierInfo.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ boolean flag = baseMapper.insert(add) > 0;
|
|
|
+ if (flag) {
|
|
|
+ bo.setId(add.getId());
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改供应商信息
|
|
|
+ *
|
|
|
+ * @param bo 供应商信息
|
|
|
+ * @return 是否修改成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean updateByBo(SupplierInfoBo bo) {
|
|
|
+ SupplierInfo update = MapstructUtils.convert(bo, SupplierInfo.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ return baseMapper.updateById(update) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(SupplierInfo entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验并批量删除供应商信息信息
|
|
|
+ *
|
|
|
+ * @param ids 待删除的主键集合
|
|
|
+ * @param isValid 是否进行有效性校验
|
|
|
+ * @return 是否删除成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return baseMapper.deleteByIds(ids) > 0;
|
|
|
+ }
|
|
|
+}
|