Procházet zdrojové kódy

fix(supplier): 修复供应商审核流程中的状态判断和数据同步问题

- 修改密码认证策略中供应商状态检查,支持状态1和4
- 优化供应商信息服务中的临时表数据处理逻辑
- 统一供应商状态变更时临时表数据的更新方式
- 重构供应商审批信息查询方法,统一查询临时表逻辑
- 修复供应商临时表服务中的数据插入和更新逻辑
- 优化供应商审核流程中的状态同步机制
肖路 před 3 týdny
rodič
revize
e8314efcf4

+ 1 - 1
ruoyi-auth/src/main/java/org/dromara/auth/service/impl/PasswordAuthStrategy.java

@@ -89,7 +89,7 @@ public class PasswordAuthStrategy implements IAuthStrategy {
         });
         if(ObjectUtil.isNotEmpty(loginUser.getSupplierId())) {
             Long supplierStatus = remoteSupplierInfoService.selectSupplierStatusById(loginUser.getSupplierId());
-            if(!Objects.equals(supplierStatus,1L)){
+            if(supplierStatus !=1L && supplierStatus !=4L){
                 throw new ServiceException("供应商用户未审核通过");
             }
         }

+ 105 - 148
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/impl/SupplierInfoServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.crypto.digest.BCrypt;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
@@ -141,6 +142,7 @@ public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, Sup
             bo.setId(add.getId());
             // 解析 otherCustomers JSON 并保存工商信息
             saveSupplierBusinessInfoFromJson(bo.getOtherCustomers(), add.getId());
+            //
         }
         return flag;
     }
@@ -204,7 +206,13 @@ public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, Sup
             //状态为修改待审核
             supplierInfoVo.setSupplyStatus(SupplierStatusEnum.REVIEW_UPDATED.getCode());
             //先copy到临时表
-            SupplierInfoTemporary supplierInfoTemporary = new SupplierInfoTemporary();
+            SupplierInfoTemporary supplierInfoTemporary =  supplierInfoTemporaryService.getOne(Wrappers.lambdaQuery(SupplierInfoTemporary.class)
+                .eq(SupplierInfoTemporary::getSupplierId, bo.getId())
+                .last("limit 1")
+            );
+            if(supplierInfoTemporary == null){
+                supplierInfoTemporary = new SupplierInfoTemporary();
+            }
             BeanUtils.copyProperties(bo, supplierInfoTemporary, "id");
             //修改待审核
             //ID一对一
@@ -219,7 +227,8 @@ public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, Sup
             ObjectMapper objectMapper = new ObjectMapper();
             String areaListJson = objectMapper.writeValueAsString(supplyAreaVoTableDataInfo);
             supplierInfoTemporary.setAreaListJson(areaListJson);
-            boolean save = supplierInfoTemporaryService.save(supplierInfoTemporary);
+            supplierInfoTemporary.setSupplyStatus(bo.getSupplyStatus());
+            boolean save = supplierInfoTemporaryService.saveOrUpdate(supplierInfoTemporary);
             return baseMapper.updateById(supplierInfoVo) > 0;
         }
 
@@ -302,9 +311,13 @@ public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, Sup
                 if (updateMain == false) {
                     throw new RuntimeException("更新供应商信息失败");
                 }
-                boolean remove = supplierInfoTemporaryService.remove(new LambdaQueryWrapper<SupplierInfoTemporary>().eq(SupplierInfoTemporary::getSupplierId, id));
-                // 6. 返回最终结果(地址批量插入 + 主表更新都成功才返回 true)
-                return batchSave && updateMain && remove;
+
+                // 6. 不删除临时表数据,而是将临时表的supplyStatus改为和主表一样
+                supplierInfoTemporary.setSupplyStatus(SupplierStatusEnum.OFFICIAL_SUPPLIER.getCode());
+                boolean updateTemp = supplierInfoTemporaryService.updateById(supplierInfoTemporary);
+
+                // 7. 返回最终结果(地址批量插入 + 主表更新 + 临时表状态更新都成功才返回 true)
+                return batchSave && updateMain && updateTemp;
 
             } catch (JsonProcessingException e) {
                 // JSON解析异常处理(可打印日志、抛出业务异常等)
@@ -319,8 +332,10 @@ public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, Sup
             SupplierInfo update = MapstructUtils.convert(bo, SupplierInfo.class);
             update.setCooperative(0L);
             // 补充:审核未通过,建议同时删除临时表的待审核数据,避免残留
-            supplierInfoTemporaryService.remove(new LambdaQueryWrapper<SupplierInfoTemporary>()
-                .eq(SupplierInfoTemporary::getSupplierId, update.getId()));
+            supplierInfoTemporaryService.update(new LambdaUpdateWrapper<SupplierInfoTemporary>()
+                .eq(SupplierInfoTemporary::getSupplierId, update.getId())
+                .set(SupplierInfoTemporary::getSupplyStatus, bo.getSupplyStatus())
+            );
             return baseMapper.updateById(update) > 0;
         }
 
@@ -345,7 +360,7 @@ public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, Sup
             BeanUtils.copyProperties(tempMain, tempSupplier, "id", "supplierId", "areaListJson");
             // 忽略:主键、关联字段、区域JSON(区域JSON已由insertByBo处理完成)
             // 3.2 保持临时表状态仍为「待修改审核」(兜底,避免意外修改)
-            tempSupplier.setSupplyStatus(SupplierStatusEnum.REVIEW_UPDATED.getCode());
+            tempSupplier.setSupplyStatus(bo.getSupplyStatus());
             // 4. 更新临时表的基础信息(区域JSON已由insertByBo更新,此处仅更新基础信息)
             try {
                 boolean operateResult = supplierInfoTemporaryService.saveOrUpdate(tempSupplier);
@@ -355,6 +370,15 @@ public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, Sup
                 throw new RuntimeException("更新供应商待审核基础数据失败,请联系管理员", e);
             }
         }
+        SupplierInfoTemporary supplierInfoTemporary =  supplierInfoTemporaryService.getOne(Wrappers.lambdaQuery(SupplierInfoTemporary.class)
+            .eq(SupplierInfoTemporary::getSupplierId, bo.getId())
+            .last("limit 1")
+        );
+        if(supplierInfoTemporary == null){
+            supplierInfoTemporary = new SupplierInfoTemporary();
+        }
+        BeanUtils.copyProperties(bo, supplierInfoTemporary, "id");
+        supplierInfoTemporaryService.saveOrUpdate(supplierInfoTemporary);
 
         SupplierInfo update = MapstructUtils.convert(bo, SupplierInfo.class);
         return baseMapper.updateById(update) > 0;
@@ -452,13 +476,11 @@ public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, Sup
 
             // 待审核
             case PENDING_REVIEW:
-                return updateSupplier(bo);
+                return handleOfficialSupplierUpdate(bo, supplier);
 
             // 审核失败 -> 重新待审核
             case REVIEW_FAILED:
-                SupplierInfo update = MapstructUtils.convert(bo, SupplierInfo.class);
-                update.setSupplyStatus(SupplierStatusEnum.PENDING_REVIEW.getCode());
-                return baseMapper.updateById(update) > 0;
+                return handleOfficialSupplierUpdate(bo, supplier);
 
             // 正式供应商 -> 进入修改审核
             case OFFICIAL_SUPPLIER:
@@ -607,13 +629,14 @@ public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, Sup
         SupplierInfoVo supplierInfoVo1 = baseMapper.selectVoOne(new LambdaQueryWrapper<SupplierInfo>().select(SupplierInfo::getSupplyStatus)
             .eq(SupplierInfo::getId, id));
         SupplierInfoVo supplierInfoVo = new SupplierInfoVo();
-        if (supplierInfoVo1 != null && supplierInfoVo1.getSupplyStatus() == SupplierStatusEnum.REVIEW_UPDATED.getCode()) {
+//        if (supplierInfoVo1 != null && supplierInfoVo1.getSupplyStatus() == SupplierStatusEnum.REVIEW_UPDATED.getCode()) {
+        if (supplierInfoVo1 != null ) {
             SupplierInfoTemporaryVo supplierInfoTemporaryVo = supplierInfoTemporaryService.getVoOne(id);
             if (supplierInfoTemporaryVo != null) {
                 BeanUtils.copyProperties(supplierInfoTemporaryVo, supplierInfoVo);
             }
         } else {
-            supplierInfoVo = baseMapper.selectVoById(id);
+                supplierInfoVo = baseMapper.selectVoById(id);
         }
         SupplierInfoVo supplierInformationVo = handleProcurementInfo(supplierInfoVo);
         //返回工商信息
@@ -706,162 +729,79 @@ public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, Sup
 
     @Override
     public TableDataInfo<SupplierInfoVo> getSupplierApproveInformation(SupplierInfoBo bo, PageQuery pageQuery) {
-        if (bo.getSupplyStatus() == null) {
-            // 步骤1:定义两个列表,存储主表(状态0)和临时表(状态4)的数据
-            List<SupplierInfoVo> mainTableVoList = new ArrayList<>();
-            List<SupplierInfoVo> tempTableVoList = new ArrayList<>();
-
-            // 步骤2:查询主表(info)状态为 0 的数据
-            LambdaQueryWrapper<SupplierInfo> mainLqw = buildCommonQueryWrapper(bo);
-            mainLqw.eq(SupplierInfo::getSupplyStatus, SupplierStatusEnum.PENDING_REVIEW.getCode()); // 状态0:待审核(可替换为 SupplierStatusEnum.PENDING_REVIEW.getCode())
-            mainLqw.eq(StringUtils.isNotBlank(bo.getSupplierNo()), SupplierInfo::getSupplierNo, bo.getSupplierNo());
-            mainLqw.like(StringUtils.isNotBlank(bo.getEnterpriseName()), SupplierInfo::getEnterpriseName, bo.getEnterpriseName());
-            Page<SupplierInfoVo> mainPage = baseMapper.selectVoPage(new Page<>(1, Integer.MAX_VALUE), mainLqw); // 查询全部符合条件的数据,不做分页
-            if (!CollectionUtils.isEmpty(mainPage.getRecords())) {
-                mainTableVoList = mainPage.getRecords();
-            }
-
-            // 步骤3:查询临时表(temporary)状态为 4 的数据
-            LambdaQueryWrapper<SupplierInfoTemporary> tempLqw = new LambdaQueryWrapper<>();
-            tempLqw.eq(SupplierInfoTemporary::getSupplyStatus, SupplierStatusEnum.REVIEW_UPDATED.getCode()); // 状态4:修改待审核(可替换为 SupplierStatusEnum.REVIEW_UPDATED.getCode())
-            // 补充bo中的其他查询条件(如品牌,和主表查询保持一致)
-            if (bo.getOperatingBrand() != null && StringUtils.isNotBlank(bo.getOperatingBrand())) {
-                Long productBrandIdByName = remoteProductService.getProductBrandIdByName(bo.getOperatingBrand());
-                if (productBrandIdByName != null) {
-                    tempLqw.like(SupplierInfoTemporary::getOperatingBrand, productBrandIdByName);
-                }
-            }
-
-            // 若有区域、产品经理/采购人员过滤,需同步对临时表执行相同过滤逻辑(此处复用你原有的过滤方法)
-            List<Long> validSupplierIds = new ArrayList<>();
-            // 3.1 区域过滤(同步主表逻辑)
-            if (StringUtils.isNotBlank(bo.getProvince()) || StringUtils.isNotBlank(bo.getCity())) {
-                validSupplierIds = supplyAreaService.getSupplierIdsByArea(bo.getProvince(), bo.getCity());
-                if (CollectionUtils.isEmpty(validSupplierIds)) {
-                    validSupplierIds.add(-1L); // 无数据时添加无效ID,避免查询全部
-                }
-                tempLqw.in(SupplierInfoTemporary::getId, validSupplierIds);
-            }
-            // 3.2 产品经理/采购人员过滤(同步主表逻辑)
-            if (bo.getProductManager() != null || bo.getBuyer() != null) {
-                validSupplierIds = supplierProcurementService.getSupplierIdsByProcurement(bo.getProductManager(), bo.getBuyer());
-                if (CollectionUtils.isEmpty(validSupplierIds)) {
-                    validSupplierIds.add(-1L);
-                }
-                tempLqw.in(SupplierInfoTemporary::getId, validSupplierIds);
-            }
-
-            // 查询临时表全部符合条件数据,并转换为 SupplierInfoVo(保证和主表数据结构一致)
-            List<SupplierInfoTemporary> tempTableList = supplierInfoTemporaryService.list(tempLqw);
-            if (!CollectionUtils.isEmpty(tempTableList)) {
-                // 转换:SupplierInfoTemporary -> SupplierInfoVo(可使用Mapstruct,此处用BeanUtils示例,需保证字段一致)
-                tempTableVoList = tempTableList.stream().map(temp -> {
-                    SupplierInfoVo vo = new SupplierInfoVo();
-                    org.springframework.beans.BeanUtils.copyProperties(temp, vo);
-                    vo.setId(temp.getSupplierId());
-                    return vo;
-                }).collect(Collectors.toList());
-            }
-
-            // 步骤4:合并两个列表的数据
-            List<SupplierInfoVo> totalVoList = new ArrayList<>();
-            totalVoList.addAll(mainTableVoList);
-            totalVoList.addAll(tempTableVoList);
-
-            // 步骤5:按照 supplyNo 倒序排序(处理null值,避免排序异常)
-            if (!CollectionUtils.isEmpty(totalVoList)) {
-                totalVoList.sort((vo1, vo2) -> {
-                    // 优先处理null值,null值排后面
-                    if (vo1.getSupplierNo() == null && vo2.getSupplierNo() == null) {
-                        return 0;
-                    }
-                    if (vo1.getSupplierNo() == null) {
-                        return 1;
-                    }
-                    if (vo2.getSupplierNo() == null) {
-                        return -1;
-                    }
-                    // 倒序排序(compareTo反过来)
-                    return vo2.getSupplierNo().compareTo(vo1.getSupplierNo());
-                });
-
-                // 批量处理扩展信息(复用你原有的逻辑)
-                totalVoList = batchHandleBaseExtInfo(totalVoList);
-                handleEnterpriseScaleName(totalVoList);
-            }
-
-            // 步骤6:手动实现分页(关键:内存数据分页)
-            int pageNum = pageQuery.getPageNum();
-            int pageSize = pageQuery.getPageSize();
-            int totalCount = totalVoList.size();
-
-            // 计算分页参数
-            int startIndex = (pageNum - 1) * pageSize;
-            int endIndex = Math.min(startIndex + pageSize, totalCount);
-            List<SupplierInfoVo> pageVoList = new ArrayList<>();
-
-            // 截取当前页数据
-            if (startIndex < totalCount) {
-                pageVoList = totalVoList.subList(startIndex, endIndex);
-            }
-
-            // 步骤7:封装分页结果(构建Page对象,符合返回值要求)
-            Page<SupplierInfoVo> resultPage = new Page<>(pageNum, pageSize, totalCount);
-            resultPage.setRecords(pageVoList);
-
-            // 步骤8:返回封装后的TableDataInfo
-            return TableDataInfo.build(resultPage);
+        // 只查询临时表 supplier_info_temporary
+        LambdaQueryWrapper<SupplierInfoTemporary> lqw = new LambdaQueryWrapper<>();
 
+        // 如果未指定状态,默认查询状态为4(修改待审核)的数据
+        if (bo.getSupplyStatus() != null) {
+            lqw.eq(SupplierInfoTemporary::getSupplyStatus, bo.getSupplyStatus());
         }
 
-        // 1. 构建审批状态条件
-        LambdaQueryWrapper<SupplierInfo> lqw = new LambdaQueryWrapper<>();
-        lqw.eq(SupplierInfo::getSupplyStatus, bo.getSupplyStatus());
+        // 添加供应商编号过滤
+        if (StringUtils.isNotBlank(bo.getSupplierNo())) {
+            lqw.eq(SupplierInfoTemporary::getSupplierNo, bo.getSupplierNo());
+        }
+        // 添加企业名称模糊查询
+        if (StringUtils.isNotBlank(bo.getEnterpriseName())) {
+            lqw.like(SupplierInfoTemporary::getEnterpriseName, bo.getEnterpriseName());
+        }
 
-        // 2.添加品牌条件
+        // 添加品牌条件
         if (bo.getOperatingBrand() != null && StringUtils.isNotBlank(bo.getOperatingBrand())) {
-            if (StringUtils.isNotBlank(bo.getOperatingBrand())) {
-                Long productBrandIdByName = remoteProductService.getProductBrandIdByName(bo.getOperatingBrand());
-                if (productBrandIdByName != null) {
-                    lqw.like(SupplierInfo::getOperatingBrand, productBrandIdByName);
-                }
+            Long productBrandIdByName = remoteProductService.getProductBrandIdByName(bo.getOperatingBrand());
+            if (productBrandIdByName != null) {
+                lqw.like(SupplierInfoTemporary::getOperatingBrand, productBrandIdByName);
             }
         }
-        //3.可供货区域省和市 - 添加供应区域过滤
+
+        // 可供货区域省和市 - 添加供应区域过滤
         if (StringUtils.isNotBlank(bo.getProvince()) || StringUtils.isNotBlank(bo.getCity())) {
-            // 查询符合条件的供应商ID列表
             List<Long> supplierIds = supplyAreaService.getSupplierIdsByArea(bo.getProvince(), bo.getCity());
-            if (supplierIds != null && !supplierIds.isEmpty()) {
-                lqw.in(SupplierInfo::getId, supplierIds);
-
+            if (!CollectionUtils.isEmpty(supplierIds)) {
+                lqw.in(SupplierInfoTemporary::getId, supplierIds);
             } else {
-                lqw.in(SupplierInfo::getId, -1L);
-
+                lqw.in(SupplierInfoTemporary::getId, -1L);
             }
         }
-        //产品经理和采购人员
+
+        // 产品经理和采购人员过滤
         if (bo.getProductManager() != null || bo.getBuyer() != null) {
-            // 查询符合条件的供应商ID列表
             List<Long> supplierIds = supplierProcurementService.getSupplierIdsByProcurement(bo.getProductManager(), bo.getBuyer());
-            if (supplierIds != null && !supplierIds.isEmpty()) {
-                lqw.in(SupplierInfo::getId, supplierIds);
+            if (!CollectionUtils.isEmpty(supplierIds)) {
+                lqw.in(SupplierInfoTemporary::getId, supplierIds);
             } else {
-                lqw.in(SupplierInfo::getId, -1L);
+                lqw.in(SupplierInfoTemporary::getId, -1L);
             }
         }
-        // 2. 基础分页查询
-        Page<SupplierInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
-        List<SupplierInfoVo> supplierVos = result.getRecords();
 
-        // 3. 批量处理扩展信息
-        if (!CollectionUtils.isEmpty(supplierVos)) {
+        // 分页查询临时表数据
+        Page<SupplierInfoTemporary> tempPage = supplierInfoTemporaryService.page(pageQuery.build(), lqw);
+        List<SupplierInfoTemporary> tempRecords = tempPage.getRecords();
+
+        // 转换为 SupplierInfoVo
+        List<SupplierInfoVo> supplierVos = new ArrayList<>();
+        if (!CollectionUtils.isEmpty(tempRecords)) {
+            supplierVos = tempRecords.stream().map(temp -> {
+                SupplierInfoVo supplierInfo = baseMapper.selectVoById(temp.getSupplierId());
+                SupplierInfoVo vo = new SupplierInfoVo();
+
+                BeanUtil.copyProperties(temp, vo);
+                vo.setId(temp.getSupplierId());
+                vo.setSupplierNo(supplierInfo.getSupplierNo());
+//                vo.setSupplyStatus(supplierInfo.getSupplyStatus());
+                return vo;
+            }).collect(Collectors.toList());
+
+            // 批量处理扩展信息
             supplierVos = batchHandleBaseExtInfo(supplierVos);
             handleEnterpriseScaleName(supplierVos);
         }
 
-        // 4. 封装分页结果
-        Page<SupplierInfoVo> newPage = copyPageResult(result, supplierVos);
-        return TableDataInfo.build(newPage);
+        // 封装分页结果
+        Page<SupplierInfoVo> resultPage = new Page<>(tempPage.getCurrent(), tempPage.getSize(), tempPage.getTotal());
+        resultPage.setRecords(supplierVos);
+
+        return TableDataInfo.build(resultPage);
     }
 
     /*
@@ -2168,6 +2108,23 @@ public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, Sup
         if (baseMapper.insert(supplierInfo) <= 0) {
             throw new ServiceException("供应商信息注册失败");
         }
+        //先查询供应商是否做过修改,如果有则直接编辑
+        SupplierInfoTemporary supplierInfoTemporary = supplierInfoTemporaryService.getOne(
+            new LambdaQueryWrapper<SupplierInfoTemporary>()
+                .eq(SupplierInfoTemporary::getSupplierId, supplierInfo.getId())
+        );
+        if (supplierInfoTemporary != null) {
+            SupplierInfoTemporary add = BeanUtil.toBean(supplierInfo, SupplierInfoTemporary.class);
+            add.setId(supplierInfoTemporary.getId());
+            add.setSupplierId(supplierInfo.getId());
+            add.setSupplyStatus(0L);
+            supplierInfoTemporaryService.updateById(add);
+        }else {
+            SupplierInfoTemporary add = BeanUtil.toBean(supplierInfo, SupplierInfoTemporary.class);
+            add.setSupplierId(supplierInfo.getId());
+            add.setSupplyStatus(0L);
+            supplierInfoTemporaryService.save(add);
+        }
 
         Long supplierId = supplierInfo.getId();
 

+ 45 - 4
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/impl/SupplierInfoTemporaryServiceImpl.java

@@ -1,5 +1,6 @@
 package org.dromara.customer.service.impl;
 
+import cn.hutool.core.bean.BeanUtil;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.core.utils.StringUtils;
@@ -10,12 +11,16 @@ 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.SupplierInfo;
+import org.dromara.customer.domain.vo.SupplierInfoVo;
+import org.dromara.customer.mapper.SupplierInfoMapper;
 import org.springframework.stereotype.Service;
 import org.dromara.customer.domain.bo.SupplierInfoTemporaryBo;
 import org.dromara.customer.domain.vo.SupplierInfoTemporaryVo;
 import org.dromara.customer.domain.SupplierInfoTemporary;
 import org.dromara.customer.mapper.SupplierInfoTemporaryMapper;
 import org.dromara.customer.service.ISupplierInfoTemporaryService;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 import java.util.Map;
@@ -34,6 +39,8 @@ public class SupplierInfoTemporaryServiceImpl  extends ServiceImpl<SupplierInfoT
 
     private final SupplierInfoTemporaryMapper baseMapper;
 
+    private final SupplierInfoMapper supplierInfoMapper;
+
     /**
      * 查询供应商临时信息
      *
@@ -156,14 +163,48 @@ public class SupplierInfoTemporaryServiceImpl  extends ServiceImpl<SupplierInfoT
      * @return 是否新增成功
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public Boolean insertByBo(SupplierInfoTemporaryBo bo) {
         SupplierInfoTemporary add = MapstructUtils.convert(bo, SupplierInfoTemporary.class);
         validEntityBeforeSave(add);
-        boolean flag = baseMapper.insert(add) > 0;
-        if (flag) {
-            bo.setId(add.getId());
+        //先查询供应商是否做过修改,如果有则直接编辑
+        SupplierInfoTemporary supplierInfoTemporary = baseMapper.selectOne(
+            new LambdaQueryWrapper<SupplierInfoTemporary>()
+            .eq(SupplierInfoTemporary::getSupplierId, bo.getId())
+        );
+        if (supplierInfoTemporary != null) {
+            add.setId(supplierInfoTemporary.getId());
+            add.setSupplierId(bo.getId());
+            add.setSupplyStatus(bo.getSupplyStatus());
+            return baseMapper.updateById(add) > 0;
+        }else{
+            if (bo.getSupplierId() != null) {
+                SupplierInfo supplierInfo = supplierInfoMapper.selectById(bo.getId());
+                if (supplierInfo != null) {
+                    add.setSupplierId(supplierInfo.getId());
+                }
+            }else{
+                //获取供应商编号的最大值
+                SupplierInfoVo supplierInfoVo = supplierInfoMapper.selectVoOne(new LambdaQueryWrapper<SupplierInfo>()
+                    .select(SupplierInfo::getSupplierNo)
+                    .last("limit 1")
+                    .orderByDesc(SupplierInfo::getSupplierNo)
+                );
+                long l = Long.parseLong(supplierInfoVo.getSupplierNo()) + 1;
+                String supplierNo = String.valueOf(l);
+                SupplierInfo supplierInfo = BeanUtil.toBean(add, SupplierInfo.class);
+                supplierInfo.setSupplierNo(supplierNo);
+                supplierInfoMapper.insert(supplierInfo);
+                add.setSupplierId(supplierInfo.getId());
+            }
+            add.setId(null);
+            add.setSupplyStatus(bo.getSupplyStatus());
+            boolean flag = baseMapper.insert(add) > 0;
+            if (flag) {
+                bo.setId(add.getId());
+            }
+            return flag;
         }
-        return flag;
     }
 
     /**