|
@@ -0,0 +1,492 @@
|
|
|
+package cn.ezhizao.project.business.controller;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import cn.ezhizao.common.utils.ServletUtils;
|
|
|
+import cn.ezhizao.framework.aspectj.lang.annotation.Log;
|
|
|
+import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
|
|
|
+import cn.ezhizao.framework.web.controller.BaseController;
|
|
|
+import cn.ezhizao.framework.web.domain.AjaxResult;
|
|
|
+import cn.ezhizao.framework.web.page.TableDataInfo;
|
|
|
+import cn.ezhizao.project.business.domain.*;
|
|
|
+import cn.ezhizao.project.business.service.IBizCompanyService;
|
|
|
+import cn.ezhizao.project.business.service.IBizProductService;
|
|
|
+import cn.ezhizao.project.business.service.IBizTenantService;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import cn.ezhizao.project.business.service.IBizCompanyMaterialService;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 客户物料Controller
|
|
|
+ *
|
|
|
+ * @author ezhizao
|
|
|
+ * @date 2025-05-27
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/business/companyMaterial")
|
|
|
+public class BizCompanyMaterialController extends BaseController
|
|
|
+{
|
|
|
+ @Resource
|
|
|
+ private IBizCompanyMaterialService bizCompanyMaterialService;
|
|
|
+ @Resource
|
|
|
+ private IBizTenantService bizTenantService;
|
|
|
+ @Resource
|
|
|
+ private IBizCompanyService bizCompanyService;
|
|
|
+ @Resource
|
|
|
+ private IBizProductService bizProductService;
|
|
|
+ public static final String PAGE_SIZE = "pageSize";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询客户物料列表
|
|
|
+ */
|
|
|
+ @GetMapping("/list")
|
|
|
+ public TableDataInfo list(BizCompanyMaterial bizCompanyMaterial) throws NoSuchFieldException, IllegalAccessException
|
|
|
+ {
|
|
|
+ String pageSizeStr = ServletUtils.getParameter(PAGE_SIZE);
|
|
|
+ if (pageSizeStr !=null) {
|
|
|
+ startPage();
|
|
|
+ }
|
|
|
+ List<BizCompanyMaterial> list = bizCompanyMaterialService.getList(bizCompanyMaterial);
|
|
|
+ return getDataTable(list);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 新增客户物料
|
|
|
+ */
|
|
|
+ @Log(title = "客户物料", businessType = BusinessType.INSERT)
|
|
|
+ @PostMapping
|
|
|
+ @Transactional
|
|
|
+ public AjaxResult add(@RequestBody List<BizCompanyMaterial> bizCompanyMaterialList) throws NoSuchFieldException, IllegalAccessException
|
|
|
+ {
|
|
|
+ //判断传入的个数
|
|
|
+ if(bizCompanyMaterialList.size() == 0){
|
|
|
+ throw new RuntimeException("新增失败,数据不能为空");
|
|
|
+ }
|
|
|
+ if(bizCompanyMaterialList.size() >100) {
|
|
|
+ throw new RuntimeException("新增失败,数据过多,不允许超过100条");
|
|
|
+ }
|
|
|
+ if (bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getCode() == null || companyMaterial.getCode() == "")) {
|
|
|
+ throw new RuntimeException("新增失败,单据编号不能为空");
|
|
|
+ }
|
|
|
+ if (bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getJdId() == null)) {
|
|
|
+ throw new RuntimeException("新增失败,金蝶id不能为空");
|
|
|
+ }
|
|
|
+ if (bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getCompanyMaterialCode() == null || companyMaterial.getCompanyMaterialCode() == "")) {
|
|
|
+ throw new RuntimeException("新增失败,客户物料编码不能为空");
|
|
|
+ }
|
|
|
+ if (bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getProductCode() == null || companyMaterial.getProductCode() == "")) {
|
|
|
+ throw new RuntimeException("新增失败,产品编码不能为空");
|
|
|
+ }
|
|
|
+ if (bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getIsStartUsing() == null)){
|
|
|
+ throw new RuntimeException("新增失败,是否启用不能为空");
|
|
|
+ }
|
|
|
+ if (bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getIsStartUsing() != 0) && bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getIsStartUsing() != 1)){
|
|
|
+ throw new RuntimeException("新增失败,是否启用只能为0或1");
|
|
|
+ }
|
|
|
+ if (bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getIsCarry() != null) && (bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getIsCarry() != 0) && bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getIsCarry() != 1))){
|
|
|
+ throw new RuntimeException("新增失败,默认携带只能为0或1");
|
|
|
+ }
|
|
|
+ if (bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getIsMutiCompany() != null) && (bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getIsMutiCompany() != 0) && bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getIsMutiCompany() != 1))){
|
|
|
+ throw new RuntimeException("新增失败,是否多选客户只能为0或1");
|
|
|
+ }
|
|
|
+ //查询厂别是否存在
|
|
|
+ Set<Long> tenantSet = bizCompanyMaterialList.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .map(BizCompanyMaterial::getTenantId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ List<Long> tenantIdsList = new ArrayList<>(tenantSet);
|
|
|
+ if (tenantIdsList.size() > 0) {
|
|
|
+ List<BizTenant> tenantList = bizTenantService.query().in("id", tenantIdsList).list();
|
|
|
+ if(tenantList.isEmpty() || tenantList.size() != tenantIdsList.size()){
|
|
|
+ throw new RuntimeException("新增失败,厂别不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断客户是否存在
|
|
|
+ Set<String> companySet = bizCompanyMaterialList.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .map(BizCompanyMaterial::getCompanyCode)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ List<String> companyCodesList = new ArrayList<>(companySet);
|
|
|
+ if (companyCodesList.size() > 0) {
|
|
|
+ List<BizCompany> companyList = bizCompanyService.query().in("company_code", companyCodesList).list();
|
|
|
+ if(companyList.isEmpty() || companyList.size() != companyCodesList.size()){
|
|
|
+ throw new RuntimeException("新增失败,客户不存在");
|
|
|
+ }
|
|
|
+ for (BizCompanyMaterial companyMaterial : bizCompanyMaterialList){
|
|
|
+ if(companyMaterial.getCompanyCode() != null && !companyMaterial.getCompanyCode().equals("")){
|
|
|
+ BizCompany bizCompany = companyList.stream().filter(company -> company.getCompanyCode().equals(companyMaterial.getCompanyCode())).findFirst().orElse(null);
|
|
|
+ if(bizCompany == null){
|
|
|
+ throw new RuntimeException("新增失败,客户不存在");
|
|
|
+ }
|
|
|
+ companyMaterial.setCompanyId(bizCompany.getId());
|
|
|
+ companyMaterial.setCompanyName(bizCompany.getCompanyName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断多选客户是否存在
|
|
|
+ Set<String> multiCompanySet = bizCompanyMaterialList.stream()
|
|
|
+ .filter(Objects::nonNull) // 确保 BizCompanyMaterial 对象不为 null
|
|
|
+ .map(BizCompanyMaterial::getCompanyCodes) // 获取 List<String>
|
|
|
+ .filter(Objects::nonNull) // 确保返回的 List 不为 null
|
|
|
+ .flatMap(List::stream) // 将 List<String> 展平为 Stream<String>
|
|
|
+ .filter(Objects::nonNull) // 确保每个字符串不为 null
|
|
|
+ .collect(Collectors.toSet()); // 收集到 Set 中
|
|
|
+ List<String> mutiCompanyCodesList = new ArrayList<>(multiCompanySet);
|
|
|
+ if (mutiCompanyCodesList.size() > 0) {
|
|
|
+ List<BizCompany> companyList = bizCompanyService.query().in("company_code", mutiCompanyCodesList).list();
|
|
|
+ if (companyList.isEmpty() || companyList.size() != mutiCompanyCodesList.size()) {
|
|
|
+ throw new RuntimeException("新增失败,多选客户不存在");
|
|
|
+ }
|
|
|
+ for (BizCompanyMaterial companyMaterial : bizCompanyMaterialList) {
|
|
|
+ if (companyMaterial.getCompanyCodes() != null && !companyMaterial.getCompanyCodes().isEmpty()) {
|
|
|
+ List<BizCompany> companylist = companyList.stream().filter(v -> companyMaterial.getCompanyCodes().contains(v.getCompanyCode())).collect(Collectors.toList());
|
|
|
+ if (companylist.isEmpty() || companylist.size() != companyMaterial.getCompanyCodes().size()) {
|
|
|
+ throw new RuntimeException("新增失败,多选客户不存在");
|
|
|
+ }
|
|
|
+ List<Long> ids = companylist.stream().map(BizCompany::getId).collect(Collectors.toList());
|
|
|
+ companyMaterial.setMutiCompanyIds(ids.stream()
|
|
|
+ .map(Object::toString)
|
|
|
+ .collect(Collectors.joining(",")));
|
|
|
+ companyMaterial.setMutiCompanyNames(companylist.stream()
|
|
|
+ .map(BizCompany::getCompanyName)
|
|
|
+ .collect(Collectors.joining(",")));
|
|
|
+ companyMaterial.setMutiCompanyCodes(companylist.stream()
|
|
|
+ .map(BizCompany::getCompanyCode)
|
|
|
+ .collect(Collectors.joining(",")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断客户物料是否存在
|
|
|
+ Set<String> companyMaterialSet = bizCompanyMaterialList.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .map(BizCompanyMaterial::getCompanyMaterialCode)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ List<String> companyMaterialCodesList = new ArrayList<>(companyMaterialSet);
|
|
|
+ if (companyMaterialCodesList.size() > 0) {
|
|
|
+ List<BizCompany> companyList = bizCompanyService.query().in("company_code", companyMaterialCodesList).list();
|
|
|
+ if(companyList.isEmpty() || companyList.size() != companyMaterialCodesList.size()){
|
|
|
+ throw new RuntimeException("新增失败,客户物料编码不存在");
|
|
|
+ }
|
|
|
+ for (BizCompanyMaterial companyMaterial : bizCompanyMaterialList){
|
|
|
+ BizCompany bizCompany = companyList.stream().filter(company -> company.getCompanyCode().equals(companyMaterial.getCompanyMaterialCode())).findFirst().orElse(null);
|
|
|
+ if(bizCompany == null){
|
|
|
+ throw new RuntimeException("新增失败,客户物料编码不存在");
|
|
|
+ }
|
|
|
+ companyMaterial.setCompanyMaterialId(bizCompany.getId());
|
|
|
+ companyMaterial.setCompanyMaterialName(bizCompany.getCompanyName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断产品是否存在
|
|
|
+ Set<String>productSet = bizCompanyMaterialList.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .map(BizCompanyMaterial::getProductCode)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ List<String> productCodesList = new ArrayList<>(productSet);
|
|
|
+ if (productCodesList.size() > 0) {
|
|
|
+ List<BizProduct> productList = bizProductService.query().in("product_code", productCodesList).list();
|
|
|
+ if(productList.isEmpty() || productList.size() != productCodesList.size()){
|
|
|
+ throw new RuntimeException("新增失败,产品不存在");
|
|
|
+ }
|
|
|
+ for (BizCompanyMaterial product : bizCompanyMaterialList){
|
|
|
+ BizProduct bizProduct = productList.stream().filter(v -> v.getProductCode().equals(product.getProductCode())).findFirst().orElse(null);
|
|
|
+ if(bizProduct == null){
|
|
|
+ throw new RuntimeException("新增失败,产品不存在");
|
|
|
+ }
|
|
|
+ product.setDescription(bizProduct.getDescription());
|
|
|
+ product.setProductId(bizProduct.getId());
|
|
|
+ product.setSpecification(bizProduct.getSpecification());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //保存
|
|
|
+ bizCompanyMaterialService.saveBatch(bizCompanyMaterialList);
|
|
|
+ return success(bizCompanyMaterialList.stream()
|
|
|
+ .map(v -> {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("id", v.getId());
|
|
|
+ map.put("code", v.getCode());
|
|
|
+ return map;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改客户物料
|
|
|
+ */
|
|
|
+ @Log(title = "客户物料", businessType = BusinessType.UPDATE)
|
|
|
+ @PutMapping
|
|
|
+ @Transactional
|
|
|
+ public AjaxResult edit(@RequestBody List<BizCompanyMaterial> bizCompanyMaterialList) throws NoSuchFieldException, IllegalAccessException
|
|
|
+ {
|
|
|
+ //判断传入的个数
|
|
|
+ if(bizCompanyMaterialList.size() == 0){
|
|
|
+ throw new RuntimeException("修改失败,数据不能为空");
|
|
|
+ }
|
|
|
+ if(bizCompanyMaterialList.size() >100) {
|
|
|
+ throw new RuntimeException("修改失败,数据过多,不允许超过100条");
|
|
|
+ }
|
|
|
+ if (bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getId() == null)) {
|
|
|
+ throw new RuntimeException("修改失败,id不能为空");
|
|
|
+ }
|
|
|
+ if (bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getJdId() == null)) {
|
|
|
+ throw new RuntimeException("修改失败,金蝶id不能为空");
|
|
|
+ }
|
|
|
+ if (bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getIsStartUsing() != null) && (bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getIsStartUsing() != 0) && bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getIsStartUsing() != 1))){
|
|
|
+ throw new RuntimeException("修改失败,是否启用只能为0或1");
|
|
|
+ }
|
|
|
+ if (bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getIsCarry() != null) && (bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getIsCarry() != 0) && bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getIsCarry() != 1))){
|
|
|
+ throw new RuntimeException("修改失败,默认携带只能为0或1");
|
|
|
+ }
|
|
|
+ if (bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getIsMutiCompany() != null) && (bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getIsMutiCompany() != 0) && bizCompanyMaterialList.stream().anyMatch(companyMaterial -> companyMaterial.getIsMutiCompany() != 1))){
|
|
|
+ throw new RuntimeException("修改失败,是否多选客户只能为0或1");
|
|
|
+ }
|
|
|
+ //查询厂别是否存在
|
|
|
+ Set<Long> tenantSet = bizCompanyMaterialList.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .map(BizCompanyMaterial::getTenantId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ List<Long> tenantIdsList = new ArrayList<>(tenantSet);
|
|
|
+ if (tenantIdsList.size() > 0) {
|
|
|
+ List<BizTenant> tenantList = bizTenantService.query().in("id", tenantIdsList).list();
|
|
|
+ if(tenantList.isEmpty() || tenantList.size() != tenantIdsList.size()){
|
|
|
+ throw new RuntimeException("修改失败,厂别不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断客户是否存在
|
|
|
+ Set<String> companySet = bizCompanyMaterialList.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .map(BizCompanyMaterial::getCompanyCode)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ List<String> companyCodesList = new ArrayList<>(companySet);
|
|
|
+ if (companyCodesList.size() > 0) {
|
|
|
+ List<BizCompany> companyList = bizCompanyService.query().in("company_code", companyCodesList).list();
|
|
|
+ if(companyList.isEmpty() || companyList.size() != companyCodesList.size()){
|
|
|
+ throw new RuntimeException("修改失败,客户不存在");
|
|
|
+ }
|
|
|
+ for (BizCompanyMaterial companyMaterial : bizCompanyMaterialList){
|
|
|
+ if(companyMaterial.getCompanyCode() != null && !companyMaterial.getCompanyCode().equals("")){
|
|
|
+ BizCompany bizCompany = companyList.stream().filter(company -> company.getCompanyCode().equals(companyMaterial.getCompanyCode())).findFirst().orElse(null);
|
|
|
+ if(bizCompany == null){
|
|
|
+ throw new RuntimeException("修改失败,客户不存在");
|
|
|
+ }
|
|
|
+ companyMaterial.setCompanyId(bizCompany.getId());
|
|
|
+ companyMaterial.setCompanyName(bizCompany.getCompanyName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断多选客户是否存在
|
|
|
+ Set<String> multiCompanySet = bizCompanyMaterialList.stream()
|
|
|
+ .filter(Objects::nonNull) // 确保 BizCompanyMaterial 对象不为 null
|
|
|
+ .map(BizCompanyMaterial::getCompanyCodes) // 获取 List<String>
|
|
|
+ .filter(Objects::nonNull) // 确保返回的 List 不为 null
|
|
|
+ .flatMap(List::stream) // 将 List<String> 展平为 Stream<String>
|
|
|
+ .filter(Objects::nonNull) // 确保每个字符串不为 null
|
|
|
+ .collect(Collectors.toSet()); // 收集到 Set 中
|
|
|
+ List<String> mutiCompanyCodesList = new ArrayList<>(multiCompanySet);
|
|
|
+ if (mutiCompanyCodesList.size() > 0) {
|
|
|
+ List<BizCompany> companyList = bizCompanyService.query().in("company_code", mutiCompanyCodesList).list();
|
|
|
+ if (companyList.isEmpty() || companyList.size() != multiCompanySet.size()) {
|
|
|
+ throw new RuntimeException("修改失败,多选客户不存在");
|
|
|
+ }
|
|
|
+ for (BizCompanyMaterial companyMaterial : bizCompanyMaterialList) {
|
|
|
+ if (companyMaterial.getCompanyCodes() != null && !companyMaterial.getCompanyCodes().isEmpty()) {
|
|
|
+ List<BizCompany> companylist = companyList.stream().filter(v -> companyMaterial.getCompanyCodes().contains(v.getCompanyCode())).collect(Collectors.toList());
|
|
|
+ if (companylist.isEmpty() || companylist.size() != companyMaterial.getCompanyCodes().size()) {
|
|
|
+ throw new RuntimeException("修改失败,多选客户不存在");
|
|
|
+ }
|
|
|
+ List<Long> ids = companylist.stream().map(BizCompany::getId).collect(Collectors.toList());
|
|
|
+ companyMaterial.setMutiCompanyIds(ids.stream()
|
|
|
+ .map(Object::toString)
|
|
|
+ .collect(Collectors.joining(",")));
|
|
|
+ companyMaterial.setMutiCompanyNames(companylist.stream()
|
|
|
+ .map(BizCompany::getCompanyName)
|
|
|
+ .collect(Collectors.joining(",")));
|
|
|
+ companyMaterial.setMutiCompanyCodes(companylist.stream()
|
|
|
+ .map(BizCompany::getCompanyCode)
|
|
|
+ .collect(Collectors.joining(",")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断客户物料是否存在
|
|
|
+ Set<String> companyMaterialSet = bizCompanyMaterialList.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .map(BizCompanyMaterial::getCompanyMaterialCode)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ List<String> companyMaterialCodesList = new ArrayList<>(companyMaterialSet);
|
|
|
+ if (companyMaterialCodesList.size() > 0) {
|
|
|
+ List<BizCompany> companyList = bizCompanyService.query().in("company_code", companyMaterialCodesList).list();
|
|
|
+ if(companyList.isEmpty() || companyList.size() != companyMaterialCodesList.size()){
|
|
|
+ throw new RuntimeException("修改失败,客户物料编码不存在");
|
|
|
+ }
|
|
|
+ for (BizCompanyMaterial companyMaterial : bizCompanyMaterialList){
|
|
|
+ BizCompany bizCompany = companyList.stream().filter(company -> company.getCompanyCode().equals(companyMaterial.getCompanyMaterialCode())).findFirst().orElse(null);
|
|
|
+ if(bizCompany == null){
|
|
|
+ throw new RuntimeException("修改失败,客户物料编码不存在");
|
|
|
+ }
|
|
|
+ companyMaterial.setCompanyMaterialId(bizCompany.getId());
|
|
|
+ companyMaterial.setCompanyMaterialName(bizCompany.getCompanyName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断产品是否存在
|
|
|
+ Set<String>productSet = bizCompanyMaterialList.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .map(BizCompanyMaterial::getProductCode)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ List<String> productCodesList = new ArrayList<>(productSet);
|
|
|
+ if (productCodesList.size() > 0) {
|
|
|
+ List<BizProduct> productList = bizProductService.query().in("product_code", productCodesList).list();
|
|
|
+ if(productList.isEmpty() || productList.size() != productCodesList.size()){
|
|
|
+ throw new RuntimeException("修改失败,产品不存在");
|
|
|
+ }
|
|
|
+ for (BizCompanyMaterial product : bizCompanyMaterialList){
|
|
|
+ BizProduct bizProduct = productList.stream().filter(v -> v.getProductCode().equals(product.getProductCode())).findFirst().orElse(null);
|
|
|
+ if(bizProduct == null){
|
|
|
+ throw new RuntimeException("修改失败,产品不存在");
|
|
|
+ }
|
|
|
+ product.setDescription(bizProduct.getDescription());
|
|
|
+ product.setProductId(bizProduct.getId());
|
|
|
+ product.setSpecification(bizProduct.getSpecification());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<BizCompanyMaterial> companyMaterialList = bizCompanyMaterialService.query().in("id", bizCompanyMaterialList.stream()
|
|
|
+ .map(BizCompanyMaterial::getId)
|
|
|
+ .collect(Collectors.toList())).list();
|
|
|
+ for(BizCompanyMaterial companyMaterial : bizCompanyMaterialList){
|
|
|
+ BizCompanyMaterial bizCompanyMaterial = companyMaterialList.stream().filter(v -> v.getId().equals(companyMaterial.getId())).findFirst().orElse(null);
|
|
|
+ if(bizCompanyMaterial == null){
|
|
|
+ throw new RuntimeException("修改失败,客户物料id不存在");
|
|
|
+ }
|
|
|
+ if (companyMaterial.getCode()!= null && !companyMaterial.getCode().equals("")){
|
|
|
+ bizCompanyMaterial.setCode(companyMaterial.getCode());
|
|
|
+ }
|
|
|
+ if (companyMaterial.getJdId() != null){
|
|
|
+ bizCompanyMaterial.setJdId(companyMaterial.getJdId());
|
|
|
+ }
|
|
|
+ if (companyMaterial.getTenantId() != null){
|
|
|
+ bizCompanyMaterial.setTenantId(companyMaterial.getTenantId());
|
|
|
+ }
|
|
|
+ if (companyMaterial.getCompanyId() != null){
|
|
|
+ bizCompanyMaterial.setCompanyId(companyMaterial.getCompanyId());
|
|
|
+ }
|
|
|
+ if (companyMaterial.getCompanyName() != null){
|
|
|
+ bizCompanyMaterial.setCompanyName(companyMaterial.getCompanyName());
|
|
|
+ }
|
|
|
+ if (companyMaterial.getCompanyCode() != null){
|
|
|
+ bizCompanyMaterial.setCompanyCode(companyMaterial.getCompanyCode());
|
|
|
+ }
|
|
|
+ if (companyMaterial.getMutiCompanyIds() != null){
|
|
|
+ bizCompanyMaterial.setMutiCompanyIds(companyMaterial.getMutiCompanyIds());
|
|
|
+ }
|
|
|
+ if(companyMaterial.getMutiCompanyCodes() != null){
|
|
|
+ bizCompanyMaterial.setMutiCompanyCodes(companyMaterial.getMutiCompanyCodes());
|
|
|
+ }
|
|
|
+ if (companyMaterial.getMutiCompanyNames() != null){
|
|
|
+ bizCompanyMaterial.setMutiCompanyNames(companyMaterial.getMutiCompanyNames());
|
|
|
+ }
|
|
|
+ if(companyMaterial.getStatus() != null){
|
|
|
+ bizCompanyMaterial.setStatus(companyMaterial.getStatus());
|
|
|
+ }
|
|
|
+ if (companyMaterial.getCompanyMaterialId() != null){
|
|
|
+ bizCompanyMaterial.setCompanyMaterialId(companyMaterial.getCompanyMaterialId());
|
|
|
+ }
|
|
|
+ if (companyMaterial.getCompanyMaterialName() != null){
|
|
|
+ bizCompanyMaterial.setCompanyMaterialName(companyMaterial.getCompanyMaterialName());
|
|
|
+ }
|
|
|
+ if (companyMaterial.getCompanyMaterialCode() != null){
|
|
|
+ bizCompanyMaterial.setCompanyMaterialCode(companyMaterial.getCompanyMaterialCode());
|
|
|
+ }
|
|
|
+ if (companyMaterial.getProductCode() != null){
|
|
|
+ bizCompanyMaterial.setProductCode(companyMaterial.getProductCode());
|
|
|
+ }
|
|
|
+ if (companyMaterial.getDescription() != null){
|
|
|
+ bizCompanyMaterial.setDescription(companyMaterial.getDescription());
|
|
|
+ }
|
|
|
+ if (companyMaterial.getProductId() != null){
|
|
|
+ bizCompanyMaterial.setProductId(companyMaterial.getProductId());
|
|
|
+ }
|
|
|
+ if (companyMaterial.getSpecification() != null){
|
|
|
+ bizCompanyMaterial.setSpecification(companyMaterial.getSpecification());
|
|
|
+ }
|
|
|
+ if (companyMaterial.getIsStartUsing() != null){
|
|
|
+ bizCompanyMaterial.setIsStartUsing(companyMaterial.getIsStartUsing());
|
|
|
+ }
|
|
|
+ if (companyMaterial.getIsCarry() != null){
|
|
|
+ bizCompanyMaterial.setIsCarry(companyMaterial.getIsCarry());
|
|
|
+ }
|
|
|
+ if (companyMaterial.getIsMutiCompany() != null){
|
|
|
+ bizCompanyMaterial.setIsMutiCompany(companyMaterial.getIsMutiCompany());
|
|
|
+ }
|
|
|
+ if (companyMaterial.getRemark() != null){
|
|
|
+ bizCompanyMaterial.setRemark(companyMaterial.getRemark());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bizCompanyMaterialService.updateBatchById(companyMaterialList);
|
|
|
+ return success(companyMaterialList.stream()
|
|
|
+ .map(v -> {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("id", v.getId());
|
|
|
+ map.put("code", v.getCode());
|
|
|
+ return map;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除客户物料
|
|
|
+ */
|
|
|
+ @Log(title = "客户物料", businessType = BusinessType.DELETE)
|
|
|
+ @DeleteMapping
|
|
|
+ public AjaxResult remove(@RequestBody List<Long> ids)
|
|
|
+ {
|
|
|
+ if(ids.isEmpty()){
|
|
|
+ return error("删除失败,id不能为空");
|
|
|
+ }
|
|
|
+ List<BizCompanyMaterial> companyMaterialList = bizCompanyMaterialService.query().in("id", ids).list();
|
|
|
+ if(companyMaterialList.isEmpty()){
|
|
|
+ return error("删除失败,数据不存在");
|
|
|
+ }
|
|
|
+ Set<Long> uniqueIds = new HashSet<>(ids);
|
|
|
+ // 获取companyMaterialList中的id集合
|
|
|
+ Set<Long> materialIds = companyMaterialList.stream()
|
|
|
+ .map(BizCompanyMaterial::getId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 比较去重后的ids列表和companyMaterialList的大小
|
|
|
+ if (uniqueIds.size() != materialIds.size()) {
|
|
|
+ // 获取不存在的id列表
|
|
|
+ Set<Long> nonExistentIds = new HashSet<>(uniqueIds);
|
|
|
+ nonExistentIds.removeAll(materialIds);
|
|
|
+ // 返回不存在的id列表
|
|
|
+ return error("删除失败,以下ID不存在: " + nonExistentIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ return toAjax(bizCompanyMaterialService.removeBatchByIds(companyMaterialList));
|
|
|
+ }
|
|
|
+}
|