yuansh 2 miesięcy temu
rodzic
commit
a268713bfc

+ 102 - 3
srm-module-code/src/main/java/org/jeecg/modules/baseCode/controller/BaseProductClassController.java

@@ -1,10 +1,10 @@
 package org.jeecg.modules.baseCode.controller;
 
-import java.util.Arrays;
-import java.util.List;
+import java.util.*;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import org.jeecg.modules.baseCode.entity.BaseProductClass;
 import org.jeecg.modules.baseCode.service.IBaseProductClassService;
 import org.jeecg.modules.baseCode.service.ISerialPatternService;
@@ -147,7 +147,11 @@ public class BaseProductClassController extends JeecgController<BaseProductClass
         }
 
         if(StringUtils.isBlank(baseProductClass.getParentId())){
-            baseProductClass.setParentId("");
+            baseProductClass.setParentId(null);
+            baseProductClassService.update(baseProductClass,
+                    new UpdateWrapper<BaseProductClass>().lambda()
+                            .set(BaseProductClass::getParentId,null)
+                            .eq(BaseProductClass::getId,baseProductClass.getId()));
         }
 
         baseProductClassService.updateById(baseProductClass);
@@ -246,6 +250,101 @@ public class BaseProductClassController extends JeecgController<BaseProductClass
         return Result.OK(list);
     }
 
+
+    /**
+     * 树形结构数据
+     *
+     */
+    @ApiOperation(value = "产品分类-树形结构数据", notes = "产品分类-树形结构数据")
+    @GetMapping(value = "/queryByTree")
+    public Result<List<BaseProductClass>> queryByTree() {
+
+        QueryWrapper<BaseProductClass> queryWrapper = new QueryWrapper();
+        queryWrapper.eq("del_flag", "0");
+
+        List<BaseProductClass> list = baseProductClassService.list(queryWrapper);
+
+       // 构建树形结构
+        List<BaseProductClass> tree = buildTree(list);
+
+        return Result.OK(tree);
+    }
+
+    public static List<BaseProductClass> buildTree(List<BaseProductClass> allList) {
+        // 用于快速查找每个节点的 Map
+        Map<String, BaseProductClass> idToNodeMap = new HashMap<>();
+
+        // 初始化 Map
+        for (BaseProductClass node : allList) {
+            idToNodeMap.put(node.getId(), node);
+        }
+
+        // 构建树形结构的根节点列表
+        List<BaseProductClass> rootList = new ArrayList<>();
+
+        for (BaseProductClass node : allList) {
+            String parentId = node.getParentId();
+
+            if (parentId == null || parentId.isEmpty()) {
+                // 如果没有 parentId,说明是根节点
+                rootList.add(node);
+            } else {
+                // 如果有 parentId,将当前节点添加到父节点的 childList 中
+                BaseProductClass parentNode = idToNodeMap.get(parentId);
+                if (parentNode != null) {
+                    parentNode.getChildren().add(node);
+                }
+            }
+        }
+
+        return rootList;
+    }
+
+    public static void main(String[] args) {
+        // 示例数据
+        List<BaseProductClass> allList = new ArrayList<>();
+
+        BaseProductClass category1 = new BaseProductClass();
+        category1.setId("1");
+        category1.setName("Electronics");
+        category1.setParentId(null);
+
+        BaseProductClass category2 = new BaseProductClass();
+        category2.setId("2");
+        category2.setName("Phones");
+        category2.setParentId("1");
+
+        BaseProductClass category3 = new BaseProductClass();
+        category3.setId("3");
+        category3.setName("Laptops");
+        category3.setParentId("1");
+
+        BaseProductClass category4 = new BaseProductClass();
+        category4.setId("4");
+        category4.setName("iPhone");
+        category4.setParentId("2");
+
+        BaseProductClass category5 = new BaseProductClass();
+        category5.setId("5");
+        category5.setName("Gaming Laptops");
+        category5.setParentId("3");
+
+        allList.add(category1);
+        allList.add(category2);
+        allList.add(category3);
+        allList.add(category4);
+        allList.add(category5);
+
+        // 构建树形结构
+        List<BaseProductClass> tree = buildTree(allList);
+
+        // 打印树形结构
+        for (BaseProductClass root : tree) {
+            System.out.println(root);
+        }
+    }
+
+
     /**
      * 导出excel
      *

+ 7 - 4
srm-module-code/src/main/java/org/jeecg/modules/baseCode/entity/BaseProductClass.java

@@ -2,12 +2,12 @@ package org.jeecg.modules.baseCode.entity;
 
 import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
 import java.util.Date;
 import java.math.BigDecimal;
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
-import com.baomidou.mybatisplus.annotation.TableLogic;
+import java.util.List;
+
+import com.baomidou.mybatisplus.annotation.*;
 import org.jeecg.common.constant.ProvinceCityArea;
 import org.jeecg.common.util.SpringContextUtils;
 import lombok.Data;
@@ -86,4 +86,7 @@ public class BaseProductClass implements Serializable {
 	@Excel(name = "税率(tax rate)", width = 15)
     @ApiModelProperty(value = "税率")
     private Double taxRate;
+
+	@TableField(exist = false)
+    private List<BaseProductClass> children = new ArrayList<>();
 }

+ 6 - 4
srm-module-code/src/main/java/org/jeecg/modules/purCode/service/impl/PurQuotationSelectionServiceImpl.java

@@ -209,8 +209,6 @@ public class PurQuotationSelectionServiceImpl extends ServiceImpl<PurQuotationSe
         if (StringUtils.isNotBlank(sourceOld)) {
             String saleInCode = "";
             for (String o : sourceOld.split(",")) {
-                purPurchaseQuotationMapper.changeType(o, "0");//进行中
-                purInquiryFormMapper.changeType(o, "0");//进行中
                 if (StringUtils.isBlank(saleInCode)) {
                     QueryWrapper<PurInquiryForm> queryWrapper = new QueryWrapper();
                     queryWrapper.eq("bill_code", o);
@@ -219,6 +217,8 @@ public class PurQuotationSelectionServiceImpl extends ServiceImpl<PurQuotationSe
                         saleInCode = list.get(0).getSourceCode();
                     }
                 }
+                purPurchaseQuotationMapper.changeType(o, "0");//进行中
+                purInquiryFormMapper.changeType(o, "0");//进行中
             }
             if (StringUtils.isNotBlank(saleInCode)) {
                 saleInquiryFormMapper.changeType(saleInCode, "0");//执行中
@@ -240,8 +240,7 @@ public class PurQuotationSelectionServiceImpl extends ServiceImpl<PurQuotationSe
             if (StringUtils.isNotBlank(sourceOld)) {
                 String saleInCode = "";
                 for (String o : sourceOld.split(",")) {
-                    purPurchaseQuotationMapper.changeType(o, "0");//进行中
-                    purInquiryFormMapper.changeType(o, "0");//进行中
+
                     if (StringUtils.isBlank(saleInCode)) {
                         QueryWrapper<PurInquiryForm> queryWrapper = new QueryWrapper();
                         queryWrapper.eq("bill_code", o);
@@ -250,6 +249,9 @@ public class PurQuotationSelectionServiceImpl extends ServiceImpl<PurQuotationSe
                             saleInCode = list.get(0).getSourceCode();
                         }
                     }
+
+                    purPurchaseQuotationMapper.changeType(o, "0");//进行中
+                    purInquiryFormMapper.changeType(o, "0");//进行中
                 }
                 if (StringUtils.isNotBlank(saleInCode)) {
                     saleInquiryFormMapper.changeType(saleInCode, "0");//执行中

+ 4 - 4
srm-module-code/src/main/java/org/jeecg/modules/saleCode/controller/SaleContractHisController.java

@@ -96,7 +96,7 @@ public class SaleContractHisController {
 	 */
 	@AutoLog(value = "销售合同主表历史-添加")
 	@ApiOperation(value="销售合同主表历史-添加", notes="销售合同主表历史-添加")
-    @RequiresPermissions("saleCode:sale_contract_his:add")
+	// @RequiresPermissions("saleCode:sale_contract_his:add")
 	@PostMapping(value = "/add")
 	public Result<String> add(@RequestBody SaleContractHisPage saleContractHisPage) {
 		SaleContractHis saleContractHis = new SaleContractHis();
@@ -113,7 +113,7 @@ public class SaleContractHisController {
 	 */
 	@AutoLog(value = "销售合同主表历史-编辑")
 	@ApiOperation(value="销售合同主表历史-编辑", notes="销售合同主表历史-编辑")
-    @RequiresPermissions("saleCode:sale_contract_his:edit")
+	// @RequiresPermissions("saleCode:sale_contract_his:edit")
 	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
 	public Result<String> edit(@RequestBody SaleContractHisPage saleContractHisPage) {
 		SaleContractHis saleContractHis = new SaleContractHis();
@@ -134,7 +134,7 @@ public class SaleContractHisController {
 	 */
 	@AutoLog(value = "销售合同主表历史-通过id删除")
 	@ApiOperation(value="销售合同主表历史-通过id删除", notes="销售合同主表历史-通过id删除")
-    @RequiresPermissions("saleCode:sale_contract_his:delete")
+	//@RequiresPermissions("saleCode:sale_contract_his:delete")
 	@DeleteMapping(value = "/delete")
 	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
 		saleContractHisService.delMain(id);
@@ -149,7 +149,7 @@ public class SaleContractHisController {
 	 */
 	@AutoLog(value = "销售合同主表历史-批量删除")
 	@ApiOperation(value="销售合同主表历史-批量删除", notes="销售合同主表历史-批量删除")
-    @RequiresPermissions("saleCode:sale_contract_his:deleteBatch")
+	//  @RequiresPermissions("saleCode:sale_contract_his:deleteBatch")
 	@DeleteMapping(value = "/deleteBatch")
 	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
 		this.saleContractHisService.delBatchMain(Arrays.asList(ids.split(",")));

+ 4 - 4
srm-module-code/src/main/java/org/jeecg/modules/saleCode/controller/SaleQuotationHisController.java

@@ -96,7 +96,7 @@ public class SaleQuotationHisController {
 	 */
 	@AutoLog(value = "销售报价单历史-添加")
 	@ApiOperation(value="销售报价单历史-添加", notes="销售报价单历史-添加")
-    @RequiresPermissions("saleCode:sale_quotation_his:add")
+//    @RequiresPermissions("saleCode:sale_quotation_his:add")
 	@PostMapping(value = "/add")
 	public Result<String> add(@RequestBody SaleQuotationHisPage saleQuotationHisPage) {
 		SaleQuotationHis saleQuotationHis = new SaleQuotationHis();
@@ -113,7 +113,7 @@ public class SaleQuotationHisController {
 	 */
 	@AutoLog(value = "销售报价单历史-编辑")
 	@ApiOperation(value="销售报价单历史-编辑", notes="销售报价单历史-编辑")
-    @RequiresPermissions("saleCode:sale_quotation_his:edit")
+	//   @RequiresPermissions("saleCode:sale_quotation_his:edit")
 	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
 	public Result<String> edit(@RequestBody SaleQuotationHisPage saleQuotationHisPage) {
 		SaleQuotationHis saleQuotationHis = new SaleQuotationHis();
@@ -134,7 +134,7 @@ public class SaleQuotationHisController {
 	 */
 	@AutoLog(value = "销售报价单历史-通过id删除")
 	@ApiOperation(value="销售报价单历史-通过id删除", notes="销售报价单历史-通过id删除")
-    @RequiresPermissions("saleCode:sale_quotation_his:delete")
+	//   @RequiresPermissions("saleCode:sale_quotation_his:delete")
 	@DeleteMapping(value = "/delete")
 	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
 		saleQuotationHisService.delMain(id);
@@ -149,7 +149,7 @@ public class SaleQuotationHisController {
 	 */
 	@AutoLog(value = "销售报价单历史-批量删除")
 	@ApiOperation(value="销售报价单历史-批量删除", notes="销售报价单历史-批量删除")
-    @RequiresPermissions("saleCode:sale_quotation_his:deleteBatch")
+//    @RequiresPermissions("saleCode:sale_quotation_his:deleteBatch")
 	@DeleteMapping(value = "/deleteBatch")
 	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
 		this.saleQuotationHisService.delBatchMain(Arrays.asList(ids.split(",")));