|
|
|
@ -1,13 +1,20 @@
|
|
|
|
package com.zbkj.modules.autogencode.controller;
|
|
|
|
package com.zbkj.modules.autogencode.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
import com.zbkj.common.request.PageParamRequest;
|
|
|
|
import com.zbkj.common.request.PageParamRequest;
|
|
|
|
import com.zbkj.common.response.CommonResult;
|
|
|
|
import com.zbkj.common.response.CommonResult;
|
|
|
|
import com.zbkj.common.page.CommonPage;
|
|
|
|
import com.zbkj.common.page.CommonPage;
|
|
|
|
|
|
|
|
import com.zbkj.modules.autogencode.entity.CmCustItem;
|
|
|
|
|
|
|
|
import com.zbkj.modules.autogencode.entity.CmCustQualify;
|
|
|
|
|
|
|
|
import com.zbkj.modules.autogencode.entity.CmCustQualifyFile;
|
|
|
|
|
|
|
|
import com.zbkj.modules.autogencode.service.CmCustItemService;
|
|
|
|
|
|
|
|
import com.zbkj.modules.autogencode.service.CmCustQualifyService;
|
|
|
|
|
|
|
|
import com.zbkj.modules.autogencode.service.CmCustQualifyFileService;
|
|
|
|
|
|
|
|
import com.zbkj.service.service.SystemAttachmentService;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
@ -15,13 +22,9 @@ import io.swagger.annotations.ApiOperation;
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
|
|
|
import com.zbkj.modules.autogencode.entity.CmCust;
|
|
|
|
import com.zbkj.modules.autogencode.entity.CmCust;
|
|
|
|
import com.zbkj.modules.autogencode.service.CmCustService;
|
|
|
|
import com.zbkj.modules.autogencode.service.CmCustService;
|
|
|
|
|
|
|
|
import com.zbkj.common.model.system.SystemAttachment;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@ -33,6 +36,17 @@ public class CmCustController {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private CmCustService cmCustService;
|
|
|
|
private CmCustService cmCustService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private CmCustQualifyService cmCustQualifyService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private CmCustQualifyFileService cmCustQualifyFileService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private SystemAttachmentService systemAttachmentService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private CmCustItemService cmCustItemService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@ -43,101 +57,185 @@ public class CmCustController {
|
|
|
|
if (request == null) {
|
|
|
|
if (request == null) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 根据实体类字段自动生成查询条件
|
|
|
|
// 根据实体类字段自动生成查询条件
|
|
|
|
|
|
|
|
|
|
|
|
// 主键
|
|
|
|
// 主键
|
|
|
|
if (request.getId() != null) {
|
|
|
|
if (request.getId() != null) {
|
|
|
|
queryWrapper.eq(CmCust::getId, request.getId());
|
|
|
|
queryWrapper.eq(CmCust::getId, request.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 客户代码
|
|
|
|
// 客户代码
|
|
|
|
if (StrUtil.isNotBlank(request.getCustCode())) {
|
|
|
|
if (StrUtil.isNotBlank(request.getCustCode())) {
|
|
|
|
queryWrapper.eq(CmCust::getCustCode, request.getCustCode());
|
|
|
|
queryWrapper.eq(CmCust::getCustCode, request.getCustCode());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 客户名称
|
|
|
|
// 客户名称
|
|
|
|
if (StrUtil.isNotBlank(request.getCustName())) {
|
|
|
|
if (StrUtil.isNotBlank(request.getCustName())) {
|
|
|
|
queryWrapper.eq(CmCust::getCustName, request.getCustName());
|
|
|
|
queryWrapper.eq(CmCust::getCustName, request.getCustName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 营业执照号码
|
|
|
|
// 营业执照号码
|
|
|
|
if (StrUtil.isNotBlank(request.getLicenseNumber())) {
|
|
|
|
if (StrUtil.isNotBlank(request.getLicenseNumber())) {
|
|
|
|
queryWrapper.eq(CmCust::getLicenseNumber, request.getLicenseNumber());
|
|
|
|
queryWrapper.eq(CmCust::getLicenseNumber, request.getLicenseNumber());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 联系方式
|
|
|
|
// 联系方式
|
|
|
|
if (StrUtil.isNotBlank(request.getContactWay())) {
|
|
|
|
if (StrUtil.isNotBlank(request.getContactWay())) {
|
|
|
|
queryWrapper.eq(CmCust::getContactWay, request.getContactWay());
|
|
|
|
queryWrapper.eq(CmCust::getContactWay, request.getContactWay());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 状态
|
|
|
|
// 状态
|
|
|
|
if (StrUtil.isNotBlank(request.getStatus())) {
|
|
|
|
if (StrUtil.isNotBlank(request.getStatus())) {
|
|
|
|
queryWrapper.eq(CmCust::getStatus, request.getStatus());
|
|
|
|
queryWrapper.eq(CmCust::getStatus, request.getStatus());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 联系人
|
|
|
|
// 联系人
|
|
|
|
if (StrUtil.isNotBlank(request.getContactPerson())) {
|
|
|
|
if (StrUtil.isNotBlank(request.getContactPerson())) {
|
|
|
|
queryWrapper.eq(CmCust::getContactPerson, request.getContactPerson());
|
|
|
|
queryWrapper.eq(CmCust::getContactPerson, request.getContactPerson());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 备注
|
|
|
|
// 备注
|
|
|
|
if (StrUtil.isNotBlank(request.getRemark())) {
|
|
|
|
if (StrUtil.isNotBlank(request.getRemark())) {
|
|
|
|
queryWrapper.eq(CmCust::getRemark, request.getRemark());
|
|
|
|
queryWrapper.eq(CmCust::getRemark, request.getRemark());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 删除标志(0代表存在 2代表删除)
|
|
|
|
// 删除标志(0代表存在 2代表删除)
|
|
|
|
if (StrUtil.isNotBlank(request.getDelFlag())) {
|
|
|
|
if (StrUtil.isNotBlank(request.getDelFlag())) {
|
|
|
|
queryWrapper.eq(CmCust::getDelFlag, request.getDelFlag());
|
|
|
|
queryWrapper.eq(CmCust::getDelFlag, request.getDelFlag());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 创建部门
|
|
|
|
// 创建部门
|
|
|
|
if (request.getCreateDept() != null) {
|
|
|
|
if (request.getCreateDept() != null) {
|
|
|
|
queryWrapper.eq(CmCust::getCreateDept, request.getCreateDept());
|
|
|
|
queryWrapper.eq(CmCust::getCreateDept, request.getCreateDept());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 创建人
|
|
|
|
// 创建人
|
|
|
|
if (request.getCreateBy() != null) {
|
|
|
|
if (request.getCreateBy() != null) {
|
|
|
|
queryWrapper.eq(CmCust::getCreateBy, request.getCreateBy());
|
|
|
|
queryWrapper.eq(CmCust::getCreateBy, request.getCreateBy());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 创建时间
|
|
|
|
// 创建时间
|
|
|
|
if (request.getCreateTime() != null) {
|
|
|
|
if (request.getCreateTime() != null) {
|
|
|
|
queryWrapper.eq(CmCust::getCreateTime, request.getCreateTime());
|
|
|
|
queryWrapper.eq(CmCust::getCreateTime, request.getCreateTime());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 修改人
|
|
|
|
// 修改人
|
|
|
|
if (request.getUpdateBy() != null) {
|
|
|
|
if (request.getUpdateBy() != null) {
|
|
|
|
queryWrapper.eq(CmCust::getUpdateBy, request.getUpdateBy());
|
|
|
|
queryWrapper.eq(CmCust::getUpdateBy, request.getUpdateBy());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 修改时间
|
|
|
|
// 修改时间
|
|
|
|
if (request.getUpdateTime() != null) {
|
|
|
|
if (request.getUpdateTime() != null) {
|
|
|
|
queryWrapper.eq(CmCust::getUpdateTime, request.getUpdateTime());
|
|
|
|
queryWrapper.eq(CmCust::getUpdateTime, request.getUpdateTime());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
if (StrUtil.isNotBlank(request.getTenantId())) {
|
|
|
|
if (StrUtil.isNotBlank(request.getTenantId())) {
|
|
|
|
queryWrapper.eq(CmCust::getTenantId, request.getTenantId());
|
|
|
|
queryWrapper.eq(CmCust::getTenantId, request.getTenantId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 分页显示客户信息
|
|
|
|
* 分页显示客户信息
|
|
|
|
* @param request 搜索条件
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param request 搜索条件
|
|
|
|
* @param pageParamRequest 分页参数
|
|
|
|
* @param pageParamRequest 分页参数
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ApiOperation(value = "分页列表")
|
|
|
|
@ApiOperation(value = "分页列表")
|
|
|
|
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
|
|
|
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
|
|
|
public CommonResult<CommonPage<CmCust>> getList(@Validated CmCust request, @Validated PageParamRequest pageParamRequest) {
|
|
|
|
public CommonResult<CommonPage<CmCust>> getList(@Validated CmCust request, @Validated PageParamRequest pageParamRequest) {
|
|
|
|
LambdaQueryWrapper<CmCust> queryWrapper = new LambdaQueryWrapper();
|
|
|
|
LambdaQueryWrapper<CmCust> queryWrapper = new LambdaQueryWrapper();
|
|
|
|
|
|
|
|
|
|
|
|
// 应用搜索条件
|
|
|
|
// 应用搜索条件
|
|
|
|
condition(queryWrapper, request);
|
|
|
|
condition(queryWrapper, request);
|
|
|
|
|
|
|
|
|
|
|
|
CommonPage<CmCust> page = CommonPage.restPage(cmCustService.pageList(queryWrapper, pageParamRequest));
|
|
|
|
CommonPage<CmCust> page = CommonPage.restPage(cmCustService.pageList(queryWrapper, pageParamRequest));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 优化版:批量查询数据,减少数据库交互
|
|
|
|
|
|
|
|
List<CmCust> supplierList = page.getList();
|
|
|
|
|
|
|
|
if (supplierList.isEmpty()) {
|
|
|
|
|
|
|
|
return CommonResult.success(page);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 1. 提取所有供应商ID
|
|
|
|
|
|
|
|
List<Long> supplierIds = supplierList.stream().map(CmCust::getId).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 批量查询所有供应商对应的供应商类别,构建custId到supplierItem的映射
|
|
|
|
|
|
|
|
Map<Long, CmCustItem> supplierItemMap = new HashMap<>();
|
|
|
|
|
|
|
|
List<CmCustItem> allSupplierItems = cmCustItemService.list(new LambdaQueryWrapper<CmCustItem>()
|
|
|
|
|
|
|
|
.in(CmCustItem::getCustId, supplierIds));
|
|
|
|
|
|
|
|
for (CmCustItem item : allSupplierItems) {
|
|
|
|
|
|
|
|
supplierItemMap.put(item.getCustId(), item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 3. 收集所有需要的itemCode,批量查询对应的资质类型
|
|
|
|
|
|
|
|
Set<String> itemCodes = new HashSet<>();
|
|
|
|
|
|
|
|
for (CmCustItem item : allSupplierItems) {
|
|
|
|
|
|
|
|
if (StrUtil.isNotBlank(item.getItemCode())) {
|
|
|
|
|
|
|
|
itemCodes.add(item.getItemCode());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构建itemCode到qualifies列表的映射
|
|
|
|
|
|
|
|
Map<String, List<CmCustQualify>> qualifyMap = new HashMap<>();
|
|
|
|
|
|
|
|
if (!itemCodes.isEmpty()) {
|
|
|
|
|
|
|
|
List<CmCustQualify> allQualifies = cmCustQualifyService.list(new LambdaQueryWrapper<CmCustQualify>()
|
|
|
|
|
|
|
|
.in(CmCustQualify::getQualifyType, itemCodes));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (CmCustQualify qualify : allQualifies) {
|
|
|
|
|
|
|
|
qualifyMap.computeIfAbsent(qualify.getQualifyType(), k -> new ArrayList<>()).add(qualify);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 4. 批量查询所有供应商已通过审核的资质文件
|
|
|
|
|
|
|
|
Map<Long, List<CmCustQualifyFile>> passedFilesMap = new HashMap<>();
|
|
|
|
|
|
|
|
List<CmCustQualifyFile> allPassedFiles = cmCustQualifyFileService.list(new LambdaQueryWrapper<CmCustQualifyFile>()
|
|
|
|
|
|
|
|
.in(CmCustQualifyFile::getCustId, supplierIds)
|
|
|
|
|
|
|
|
.eq(CmCustQualifyFile::getStatus, 2));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (CmCustQualifyFile file : allPassedFiles) {
|
|
|
|
|
|
|
|
passedFilesMap.computeIfAbsent(file.getCustId(), k -> new ArrayList<>()).add(file);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 5. 遍历供应商列表,使用映射数据设置资质状态
|
|
|
|
|
|
|
|
for (CmCust supplier : supplierList) {
|
|
|
|
|
|
|
|
// 默认资质状态:0为资质不完整
|
|
|
|
|
|
|
|
String qualifyStatus = "0";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取供应商对应的类别
|
|
|
|
|
|
|
|
CmCustItem supplierItem = supplierItemMap.get(supplier.getId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (supplierItem != null && StrUtil.isNotBlank(supplierItem.getItemCode())) {
|
|
|
|
|
|
|
|
// 获取该类别需要的资质列表
|
|
|
|
|
|
|
|
List<CmCustQualify> requiredQualifies = qualifyMap.getOrDefault(supplierItem.getItemCode(), Collections.emptyList());
|
|
|
|
|
|
|
|
int requiredCount = requiredQualifies.size();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (requiredCount > 0) {
|
|
|
|
|
|
|
|
// 获取该供应商已通过的资质文件
|
|
|
|
|
|
|
|
List<CmCustQualifyFile> passedFiles = passedFilesMap.getOrDefault(supplier.getId(), Collections.emptyList());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 统计已通过的不同资质类型数量
|
|
|
|
|
|
|
|
Set<Long> passedQualifyIds = new HashSet<>();
|
|
|
|
|
|
|
|
for (CmCustQualifyFile file : passedFiles) {
|
|
|
|
|
|
|
|
if (file.getQualifyId() != null) {
|
|
|
|
|
|
|
|
passedQualifyIds.add(file.getQualifyId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断资质状态:只有当所有必需的资质类型都有通过审核的文件时,才为1(资质完整)
|
|
|
|
|
|
|
|
if (passedQualifyIds.size() == requiredCount) {
|
|
|
|
|
|
|
|
qualifyStatus = "1";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 直接设置资质状态到实体类的虚拟字段中
|
|
|
|
|
|
|
|
supplier.setQualifyStatus(qualifyStatus);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return CommonResult.success(page);
|
|
|
|
return CommonResult.success(page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -146,8 +244,105 @@ public class CmCustController {
|
|
|
|
* 详情数据
|
|
|
|
* 详情数据
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
|
|
|
|
@RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
|
|
|
|
public CommonResult<CmCust> info(@PathVariable("id") Long id){
|
|
|
|
public CommonResult<CmCust> info(@PathVariable("id") Long id) {
|
|
|
|
CmCust cmCust = cmCustService.getById(id);
|
|
|
|
// 参数验证
|
|
|
|
|
|
|
|
if (id == null) {
|
|
|
|
|
|
|
|
return CommonResult.failed("ID不能为空");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CmCust cmCust = cmCustService.getById(id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cmCust != null) {
|
|
|
|
|
|
|
|
// 1. 查询该供应商相关的所有资质类型
|
|
|
|
|
|
|
|
List<CmCustItem> cmCustItems = cmCustItemService.list(new LambdaQueryWrapper<CmCustItem>()
|
|
|
|
|
|
|
|
.eq(CmCustItem::getCustId, cmCust.getId()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> itemCodeList = Optional.ofNullable(cmCustItems)
|
|
|
|
|
|
|
|
.orElse(Collections.emptyList()) // 集合为 null 时返回空集合
|
|
|
|
|
|
|
|
.stream()
|
|
|
|
|
|
|
|
.filter(Objects::nonNull) // 过滤 null 的 CmCustItem 元素
|
|
|
|
|
|
|
|
.map(CmCustItem::getItemCode) // 提取 itemCode
|
|
|
|
|
|
|
|
.filter(StrUtil::isNotBlank) // 过滤 null 或空的 itemCode
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 只有当itemCodeList非空时才执行后续查询和处理
|
|
|
|
|
|
|
|
if (!itemCodeList.isEmpty()) {
|
|
|
|
|
|
|
|
// 构建资质查询条件
|
|
|
|
|
|
|
|
LambdaQueryWrapper<CmCustQualify> qualifyQuery = new LambdaQueryWrapper<CmCustQualify>()
|
|
|
|
|
|
|
|
.eq(CmCustQualify::getDelFlag, "0")
|
|
|
|
|
|
|
|
.in(CmCustQualify::getQualifyType, itemCodeList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<CmCustQualify> qualifyList = cmCustQualifyService.list(qualifyQuery);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!qualifyList.isEmpty()) {
|
|
|
|
|
|
|
|
// 提取所有资质ID
|
|
|
|
|
|
|
|
List<Long> qualifyIds = qualifyList.stream()
|
|
|
|
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
|
|
|
.map(CmCustQualify::getId)
|
|
|
|
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 批量查询该供应商的所有资质文件
|
|
|
|
|
|
|
|
LambdaQueryWrapper<CmCustQualifyFile> fileQuery = new LambdaQueryWrapper<CmCustQualifyFile>()
|
|
|
|
|
|
|
|
.eq(CmCustQualifyFile::getCustId, id)
|
|
|
|
|
|
|
|
.eq(CmCustQualifyFile::getDelFlag, "0");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 只有当qualifyIds非空时才添加in条件
|
|
|
|
|
|
|
|
if (!qualifyIds.isEmpty()) {
|
|
|
|
|
|
|
|
fileQuery.in(CmCustQualifyFile::getQualifyId, qualifyIds);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<CmCustQualifyFile> fileList = cmCustQualifyFileService.list(fileQuery);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!fileList.isEmpty()) {
|
|
|
|
|
|
|
|
// 提取所有文件ID并转换为String类型
|
|
|
|
|
|
|
|
List<String> fileIds = fileList.stream()
|
|
|
|
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
|
|
|
.filter(file -> file.getFileId() != null)
|
|
|
|
|
|
|
|
.map(file -> file.getFileId().toString())
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 3. 批量查询所有系统附件,先检查fileIds是否为空
|
|
|
|
|
|
|
|
List<SystemAttachment> attachments = new ArrayList<>();
|
|
|
|
|
|
|
|
if (!fileIds.isEmpty()) {
|
|
|
|
|
|
|
|
attachments = systemAttachmentService.list(new LambdaQueryWrapper<SystemAttachment>()
|
|
|
|
|
|
|
|
.in(SystemAttachment::getFileId, fileIds));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构建文件ID到附件列表的映射
|
|
|
|
|
|
|
|
Map<String, List<SystemAttachment>> fileToAttachmentMap = attachments.stream()
|
|
|
|
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
|
|
|
.collect(Collectors.groupingBy(SystemAttachment::getFileId));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 为每个资质文件设置附件列表
|
|
|
|
|
|
|
|
for (CmCustQualifyFile file : fileList) {
|
|
|
|
|
|
|
|
if (file != null && file.getFileId() != null) {
|
|
|
|
|
|
|
|
file.setFiles(fileToAttachmentMap.getOrDefault(file.getFileId().toString(), Collections.emptyList()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构建资质ID到文件列表的映射
|
|
|
|
|
|
|
|
Map<Long, List<CmCustQualifyFile>> qualifyToFileMap = fileList.stream()
|
|
|
|
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
|
|
|
.filter(file -> file.getQualifyId() != null)
|
|
|
|
|
|
|
|
.collect(Collectors.groupingBy(CmCustQualifyFile::getQualifyId));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 为每个资质设置文件列表
|
|
|
|
|
|
|
|
for (CmCustQualify qualify : qualifyList) {
|
|
|
|
|
|
|
|
if (qualify != null && qualify.getId() != null) {
|
|
|
|
|
|
|
|
qualify.setCmCustQualifyFileList(qualifyToFileMap.getOrDefault(qualify.getId(), Collections.emptyList()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置供应商的资质列表
|
|
|
|
|
|
|
|
cmCust.setCmCustQualifyList(qualifyList);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 如果没有资质类型,设置空列表避免空指针
|
|
|
|
|
|
|
|
cmCust.setCmCustQualifyList(Collections.emptyList());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return CommonResult.success(cmCust);
|
|
|
|
return CommonResult.success(cmCust);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -156,7 +351,7 @@ public class CmCustController {
|
|
|
|
* 新增数据
|
|
|
|
* 新增数据
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
|
|
|
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
|
|
|
public CommonResult<String> save(@RequestBody CmCust cmCust){
|
|
|
|
public CommonResult<String> save(@RequestBody CmCust cmCust) {
|
|
|
|
if (cmCustService.save(cmCust)) {
|
|
|
|
if (cmCustService.save(cmCust)) {
|
|
|
|
return CommonResult.success();
|
|
|
|
return CommonResult.success();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -167,22 +362,72 @@ public class CmCustController {
|
|
|
|
* 修改数据
|
|
|
|
* 修改数据
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
|
|
|
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
|
|
|
public CommonResult<String> update(@RequestBody CmCust cmCust){
|
|
|
|
public CommonResult<String> update(@RequestBody CmCust cmCust) {
|
|
|
|
if (cmCustService.updateById(cmCust)) {
|
|
|
|
if (cmCustService.updateById(cmCust)) {
|
|
|
|
return CommonResult.success();
|
|
|
|
return CommonResult.success();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CommonResult.failed();
|
|
|
|
return CommonResult.failed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 修改数据
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@RequestMapping(value = "/updateByFiles", method = RequestMethod.POST)
|
|
|
|
|
|
|
|
public CommonResult<String> updateByFiles(@RequestBody CmCust cmCust) {
|
|
|
|
|
|
|
|
List<CmCustQualify> cmCustQualifyList = cmCust.getCmCustQualifyList();
|
|
|
|
|
|
|
|
if (null != cmCustQualifyList && cmCustQualifyList.size() > 0) {
|
|
|
|
|
|
|
|
for (CmCustQualify cmQualify : cmCustQualifyList) {
|
|
|
|
|
|
|
|
List<CmCustQualifyFile> cmCustQualifyFileList = cmQualify.getCmCustQualifyFileList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (CmCustQualifyFile cmCustQualifyFile : cmCustQualifyFileList) {
|
|
|
|
|
|
|
|
if (null == cmCustQualifyFile.getId()) {
|
|
|
|
|
|
|
|
cmCustQualifyFile.setCustId(cmCust.getId());
|
|
|
|
|
|
|
|
cmCustQualifyFile.setQualifyId(cmQualify.getId());
|
|
|
|
|
|
|
|
cmCustQualifyFile.setQualifyName(cmQualify.getQualifyName());
|
|
|
|
|
|
|
|
cmCustQualifyFileService.save(cmCustQualifyFile);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (null != cmCustQualifyFile) {
|
|
|
|
|
|
|
|
updateFile(cmCustQualifyFile);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return CommonResult.success();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void updateFile(CmCustQualifyFile cmCustQualifyFile) {
|
|
|
|
|
|
|
|
Long newId = System.currentTimeMillis() + new Random().nextInt(100);
|
|
|
|
|
|
|
|
List<SystemAttachment> files = cmCustQualifyFile.getFiles();
|
|
|
|
|
|
|
|
if (null != files) {
|
|
|
|
|
|
|
|
for (SystemAttachment cmAttach : files) {
|
|
|
|
|
|
|
|
cmAttach.setFileId(String.valueOf(newId));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
systemAttachmentService.updateBatchById(files);
|
|
|
|
|
|
|
|
cmCustQualifyFile.setFileId(newId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cmCustQualifyFileService.updateById(cmCustQualifyFile);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void setFile(CmCustQualifyFile cmCustQualifyFile) {
|
|
|
|
|
|
|
|
Long fileId = cmCustQualifyFile.getFileId();
|
|
|
|
|
|
|
|
if (null != fileId) {
|
|
|
|
|
|
|
|
List<SystemAttachment> list = systemAttachmentService.list(new LambdaQueryWrapper<SystemAttachment>()
|
|
|
|
|
|
|
|
.eq(SystemAttachment::getFileId, fileId));
|
|
|
|
|
|
|
|
cmCustQualifyFile.setFiles(list);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 删除:根据id集合
|
|
|
|
* 删除:根据id集合
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
|
|
|
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
|
|
|
public CommonResult<String> delete(@RequestBody Long[] ids){
|
|
|
|
public CommonResult<String> delete(@RequestBody Long[] ids) {
|
|
|
|
if (cmCustService.removeByIds(Arrays.asList(ids))) {
|
|
|
|
if (cmCustService.removeByIds(Arrays.asList(ids))) {
|
|
|
|
return CommonResult.success();
|
|
|
|
return CommonResult.success();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CommonResult.failed();
|
|
|
|
return CommonResult.failed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|