瀏覽代碼

树形优化

home 2 年之前
父節點
當前提交
64b15f5019

+ 50 - 0
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/entity/supplier/SupplierPrice.java

@@ -0,0 +1,50 @@
+package com.fjhx.entity.supplier;
+
+import java.math.BigDecimal;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.Version;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.fjhx.base.BaseEntity;
+import com.baomidou.mybatisplus.annotation.TableField;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * <p>
+ * 供应商价格
+ * </p>
+ *
+ * @author ${author}
+ * @since 2022-11-25
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class SupplierPrice extends BaseEntity {
+
+
+    /**
+     * 供应商id
+     */
+    private Long supplierId;
+
+    /**
+     * 物料id
+     */
+    private Long materialId;
+
+    /**
+     * 单价
+     */
+    private BigDecimal price;
+
+    /**
+     * 逻辑删除 0未删除 1已删除
+     */
+    @TableField(fill = FieldFill.INSERT)
+    @TableLogic
+    private Integer delFlag;
+
+
+}

+ 17 - 0
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/params/supplier/SupplierPriceEx.java

@@ -0,0 +1,17 @@
+package com.fjhx.params.supplier;
+
+import com.fjhx.entity.supplier.SupplierPrice;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 供应商价格
+ *
+ * @author ${author}
+ * @since 2022-11-25
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class SupplierPriceEx extends SupplierPrice {
+
+}

+ 17 - 0
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/params/supplier/SupplierPriceVo.java

@@ -0,0 +1,17 @@
+package com.fjhx.params.supplier;
+
+import com.fjhx.entity.supplier.SupplierPrice;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 供应商价格
+ *
+ * @author ${author}
+ * @since 2022-11-25
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class SupplierPriceVo extends SupplierPrice {
+
+}

+ 253 - 57
hx-service/victoriatourist/src/main/java/com/fjhx/config/LogicDeleteInterceptor.java

@@ -12,8 +12,8 @@ import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
 import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
 import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
 import net.sf.jsqlparser.expression.operators.relational.ExistsExpression;
+import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
 import net.sf.jsqlparser.expression.operators.relational.InExpression;
-import net.sf.jsqlparser.expression.operators.relational.ItemsList;
 import net.sf.jsqlparser.parser.CCJSqlParserUtil;
 import net.sf.jsqlparser.schema.Column;
 import net.sf.jsqlparser.schema.Table;
@@ -23,10 +23,12 @@ import org.apache.ibatis.mapping.BoundSql;
 import org.apache.ibatis.mapping.MappedStatement;
 import org.apache.ibatis.session.ResultHandler;
 import org.apache.ibatis.session.RowBounds;
+import org.springframework.stereotype.Component;
 
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
+@Component
 @Slf4j
 public class LogicDeleteInterceptor implements InnerInterceptor {
 
@@ -34,9 +36,9 @@ public class LogicDeleteInterceptor implements InnerInterceptor {
     private static final Expression delFlagValue = new LongValue(0);
 
     /**
-     * 赋值存在del_flag字段的表名
+     * 不要拼接逻辑删除的表
      */
-    private static final List<String> delFlagTableNameList = Collections.emptyList();
+    private static final List<String> delFlagTableNameList = Arrays.asList();
 
 
     @SneakyThrows
@@ -65,7 +67,7 @@ public class LogicDeleteInterceptor implements InnerInterceptor {
         return select.toString();
     }
 
-    private void processSelectBody(SelectBody selectBody) {
+    protected void processSelectBody(SelectBody selectBody) {
         if (selectBody == null) {
             return;
         }
@@ -76,8 +78,9 @@ public class LogicDeleteInterceptor implements InnerInterceptor {
             processSelectBody(withItem.getSubSelect().getSelectBody());
         } else {
             SetOperationList operationList = (SetOperationList) selectBody;
-            if (operationList.getSelects() != null && operationList.getSelects().size() > 0) {
-                operationList.getSelects().forEach(this::processSelectBody);
+            List<SelectBody> selectBodyList = operationList.getSelects();
+            if (CollectionUtils.isNotEmpty(selectBodyList)) {
+                selectBodyList.forEach(this::processSelectBody);
             }
         }
     }
@@ -85,24 +88,31 @@ public class LogicDeleteInterceptor implements InnerInterceptor {
     /**
      * 处理 PlainSelect
      */
-    private void processPlainSelect(PlainSelect plainSelect) {
-        FromItem fromItem = plainSelect.getFromItem();
+    protected void processPlainSelect(PlainSelect plainSelect) {
+        //#3087 github
+        List<SelectItem> selectItems = plainSelect.getSelectItems();
+        if (CollectionUtils.isNotEmpty(selectItems)) {
+            selectItems.forEach(this::processSelectItem);
+        }
+
+        // 处理 where 中的子查询
         Expression where = plainSelect.getWhere();
         processWhereSubSelect(where);
-        if (fromItem instanceof Table) {
-            Table fromTable = (Table) fromItem;
-            if (delFlagTableNameList.contains(fromTable.getName()) && !where.toString().contains(delFlagName)) {
-                plainSelect.setWhere(builderExpression(where, fromTable));
-            }
-        } else {
-            processFromItem(fromItem);
-        }
+
+        // 处理 fromItem
+        FromItem fromItem = plainSelect.getFromItem();
+        List<Table> list = processFromItem(fromItem);
+        List<Table> mainTables = new ArrayList<>(list);
+
+        // 处理 join
         List<Join> joins = plainSelect.getJoins();
-        if (joins != null && joins.size() > 0) {
-            joins.forEach(j -> {
-                processJoin(j);
-                processFromItem(j.getRightItem());
-            });
+        if (CollectionUtils.isNotEmpty(joins)) {
+            mainTables = processJoins(mainTables, joins);
+        }
+
+        // 当有 mainTable 时,进行 where 条件追加
+        if (CollectionUtils.isNotEmpty(mainTables)) {
+            plainSelect.setWhere(builderExpression(where, mainTables));
         }
     }
 
@@ -126,12 +136,12 @@ public class LogicDeleteInterceptor implements InnerInterceptor {
      *
      * @param where where 条件
      */
-    private void processWhereSubSelect(Expression where) {
+    protected void processWhereSubSelect(Expression where) {
         if (where == null) {
             return;
         }
         if (where instanceof FromItem) {
-            processFromItem((FromItem) where);
+            processOtherFromItem((FromItem) where);
             return;
         }
         if (where.toString().indexOf("SELECT") > 0) {
@@ -144,9 +154,9 @@ public class LogicDeleteInterceptor implements InnerInterceptor {
             } else if (where instanceof InExpression) {
                 // in
                 InExpression expression = (InExpression) where;
-                ItemsList itemsList = expression.getRightItemsList();
-                if (itemsList instanceof SubSelect) {
-                    processSelectBody(((SubSelect) itemsList).getSelectBody());
+                Expression inExpression = expression.getRightExpression();
+                if (inExpression instanceof SubSelect) {
+                    processSelectBody(((SubSelect) inExpression).getSelectBody());
                 }
             } else if (where instanceof ExistsExpression) {
                 // exists
@@ -163,25 +173,55 @@ public class LogicDeleteInterceptor implements InnerInterceptor {
         }
     }
 
+    protected void processSelectItem(SelectItem selectItem) {
+        if (selectItem instanceof SelectExpressionItem) {
+            SelectExpressionItem selectExpressionItem = (SelectExpressionItem) selectItem;
+            if (selectExpressionItem.getExpression() instanceof SubSelect) {
+                processSelectBody(((SubSelect) selectExpressionItem.getExpression()).getSelectBody());
+            } else if (selectExpressionItem.getExpression() instanceof Function) {
+                processFunction((Function) selectExpressionItem.getExpression());
+            }
+        }
+    }
+
+    private List<Table> processFromItem(FromItem fromItem) {
+        // 处理括号括起来的表达式
+        while (fromItem instanceof ParenthesisFromItem) {
+            fromItem = ((ParenthesisFromItem) fromItem).getFromItem();
+        }
+
+        List<Table> mainTables = new ArrayList<>();
+        // 无 join 时的处理逻辑
+        if (fromItem instanceof Table) {
+            Table fromTable = (Table) fromItem;
+            mainTables.add(fromTable);
+        } else if (fromItem instanceof SubJoin) {
+            // SubJoin 类型则还需要添加上 where 条件
+            List<Table> tables = processSubJoin((SubJoin) fromItem);
+            mainTables.addAll(tables);
+        } else {
+            // 处理下 fromItem
+            processOtherFromItem(fromItem);
+        }
+        return mainTables;
+    }
+
     /**
      * 处理子查询等
      */
-    private void processFromItem(FromItem fromItem) {
-        if (fromItem instanceof SubJoin) {
-            SubJoin subJoin = (SubJoin) fromItem;
-            if (subJoin.getJoinList() != null) {
-                subJoin.getJoinList().forEach(this::processJoin);
-            }
-            if (subJoin.getLeft() != null) {
-                processFromItem(subJoin.getLeft());
-            }
-        } else if (fromItem instanceof SubSelect) {
+    protected void processOtherFromItem(FromItem fromItem) {
+        // 去除括号
+        while (fromItem instanceof ParenthesisFromItem) {
+            fromItem = ((ParenthesisFromItem) fromItem).getFromItem();
+        }
+
+        if (fromItem instanceof SubSelect) {
             SubSelect subSelect = (SubSelect) fromItem;
             if (subSelect.getSelectBody() != null) {
                 processSelectBody(subSelect.getSelectBody());
             }
         } else if (fromItem instanceof ValuesList) {
-            log.debug("Perform a subquery, if you do not give us feedback");
+            log.debug("Perform a subQuery, if you do not give us feedback");
         } else if (fromItem instanceof LateralSubSelect) {
             LateralSubSelect lateralSubSelect = (LateralSubSelect) fromItem;
             if (lateralSubSelect.getSubSelect() != null) {
@@ -194,47 +234,203 @@ public class LogicDeleteInterceptor implements InnerInterceptor {
     }
 
     /**
-     * 处理联接语句
+     * 处理 sub join
+     *
+     * @param subJoin subJoin
+     * @return Table subJoin 中的主表
      */
-    private void processJoin(Join join) {
-        if (join.getRightItem() instanceof Table) {
-            Table fromTable = (Table) join.getRightItem();
-            if (delFlagTableNameList.contains(fromTable.getName())) {
-                join.setOnExpression(builderExpression(join.getOnExpression(), fromTable));
+    private List<Table> processSubJoin(SubJoin subJoin) {
+        List<Table> mainTables = new ArrayList<>();
+        if (subJoin.getJoinList() != null) {
+            List<Table> list = processFromItem(subJoin.getLeft());
+            mainTables.addAll(list);
+            mainTables = processJoins(mainTables, subJoin.getJoinList());
+        }
+        return mainTables;
+    }
+
+
+    /**
+     * 处理函数
+     * <p>支持: 1. select fun(args..) 2. select fun1(fun2(args..),args..)<p>
+     * <p> fixed gitee pulls/141</p>
+     *
+     * @param function
+     */
+    protected void processFunction(Function function) {
+        ExpressionList parameters = function.getParameters();
+        if (parameters != null) {
+            parameters.getExpressions().forEach(expression -> {
+                if (expression instanceof SubSelect) {
+                    processSelectBody(((SubSelect) expression).getSelectBody());
+                } else if (expression instanceof Function) {
+                    processFunction((Function) expression);
+                }
+            });
+        }
+    }
+
+    /**
+     * 处理 joins
+     *
+     * @param mainTables 可以为 null
+     * @param joins      join 集合
+     * @return List<Table> 右连接查询的 Table 列表
+     */
+    private List<Table> processJoins(List<Table> mainTables, List<Join> joins) {
+        // join 表达式中最终的主表
+        Table mainTable = null;
+        // 当前 join 的左表
+        Table leftTable = null;
+
+        if (mainTables == null) {
+            mainTables = new ArrayList<>();
+        } else if (mainTables.size() == 1) {
+            mainTable = mainTables.get(0);
+            leftTable = mainTable;
+        }
+
+        //对于 on 表达式写在最后的 join,需要记录下前面多个 on 的表名
+        Deque<List<Table>> onTableDeque = new LinkedList<>();
+        for (Join join : joins) {
+            // 处理 on 表达式
+            FromItem joinItem = join.getRightItem();
+
+            // 获取当前 join 的表,subJoint 可以看作是一张表
+            List<Table> joinTables = null;
+            if (joinItem instanceof Table) {
+                joinTables = new ArrayList<>();
+                joinTables.add((Table) joinItem);
+            } else if (joinItem instanceof SubJoin) {
+                joinTables = processSubJoin((SubJoin) joinItem);
+            }
+
+            if (joinTables != null) {
+
+                // 如果是隐式内连接
+                if (join.isSimple()) {
+                    mainTables.addAll(joinTables);
+                    continue;
+                }
+
+                // 当前表是否忽略
+                Table joinTable = joinTables.get(0);
+
+                List<Table> onTables = null;
+                // 如果不要忽略,且是右连接,则记录下当前表
+                if (join.isRight()) {
+                    mainTable = joinTable;
+                    if (leftTable != null) {
+                        onTables = Collections.singletonList(leftTable);
+                    }
+                } else if (join.isLeft()) {
+                    onTables = Collections.singletonList(joinTable);
+                } else if (join.isInner()) {
+                    if (mainTable == null) {
+                        onTables = Collections.singletonList(joinTable);
+                    } else {
+                        onTables = Arrays.asList(mainTable, joinTable);
+                    }
+                    mainTable = null;
+                }
+
+                mainTables = new ArrayList<>();
+                if (mainTable != null) {
+                    mainTables.add(mainTable);
+                }
+
+                // 获取 join 尾缀的 on 表达式列表
+                Collection<Expression> originOnExpressions = join.getOnExpressions();
+                // 正常 join on 表达式只有一个,立刻处理
+                if (originOnExpressions.size() == 1 && onTables != null) {
+                    List<Expression> onExpressions = new LinkedList<>();
+                    onExpressions.add(builderExpression(originOnExpressions.iterator().next(), onTables));
+                    join.setOnExpressions(onExpressions);
+                    leftTable = joinTable;
+                    continue;
+                }
+                // 表名压栈,忽略的表压入 null,以便后续不处理
+                onTableDeque.push(onTables);
+                // 尾缀多个 on 表达式的时候统一处理
+                if (originOnExpressions.size() > 1) {
+                    Collection<Expression> onExpressions = new LinkedList<>();
+                    for (Expression originOnExpression : originOnExpressions) {
+                        List<Table> currentTableList = onTableDeque.poll();
+                        if (CollectionUtils.isEmpty(currentTableList)) {
+                            onExpressions.add(originOnExpression);
+                        } else {
+                            onExpressions.add(builderExpression(originOnExpression, currentTableList));
+                        }
+                    }
+                    join.setOnExpressions(onExpressions);
+                }
+                leftTable = joinTable;
+            } else {
+                processOtherFromItem(joinItem);
+                leftTable = null;
             }
         }
+
+        return mainTables;
     }
 
     /**
      * 处理条件
      */
-    private Expression builderExpression(Expression currentExpression, Table table) {
-        EqualsTo equalsTo = new EqualsTo();
-        equalsTo.setLeftExpression(getAliasColumn(table));
-        equalsTo.setRightExpression(delFlagValue);
-        if (currentExpression == null) {
-            return equalsTo;
+    protected Expression builderExpression(Expression currentExpression, List<Table> tables) {
+        // 没有表需要处理直接返回
+        if (CollectionUtils.isEmpty(tables)) {
+            return currentExpression;
         }
+        // 构造每张表的条件
+        List<Table> tempTables = tables.stream()
+                .filter(x -> !delFlagTableNameList.contains(x.getName()))
+                .collect(Collectors.toList());
 
+        // 没有表需要处理直接返回
+        if (CollectionUtils.isEmpty(tempTables)) {
+            return currentExpression;
+        }
+
+        List<EqualsTo> equalsTos = tempTables.stream()
+                .map(item -> new EqualsTo(getAliasColumn(item), delFlagValue))
+                .collect(Collectors.toList());
+
+        // 注入的表达式
+        Expression injectExpression = equalsTos.get(0);
+        // 如果有多表,则用 and 连接
+        if (equalsTos.size() > 1) {
+            for (int i = 1; i < equalsTos.size(); i++) {
+                injectExpression = new AndExpression(injectExpression, equalsTos.get(i));
+            }
+        }
+
+        if (currentExpression == null) {
+            return injectExpression;
+        }
         if (currentExpression instanceof OrExpression) {
-            return new AndExpression(new Parenthesis(currentExpression), equalsTo);
+            return new AndExpression(new Parenthesis(currentExpression), injectExpression);
         } else {
-            return new AndExpression(currentExpression, equalsTo);
+            return new AndExpression(currentExpression, injectExpression);
         }
     }
 
     /**
-     * 逻辑删除字段别名设置
+     * 租户字段别名设置
+     * <p>tenantId 或 tableAlias.tenantId</p>
      *
      * @param table 表对象
      * @return 字段
      */
-    private Column getAliasColumn(Table table) {
+    protected Column getAliasColumn(Table table) {
         StringBuilder column = new StringBuilder();
+        // 为了兼容隐式内连接,没有别名时条件就需要加上表名
         if (table.getAlias() != null) {
-            column.append(table.getAlias().getName()).append(StringPool.DOT);
+            column.append(table.getAlias().getName());
+        } else {
+            column.append(table.getName());
         }
-        column.append(delFlagName);
+        column.append(StringPool.DOT).append(delFlagName);
         return new Column(column.toString());
     }
 

+ 3 - 4
hx-service/victoriatourist/src/main/java/com/fjhx/config/MybatisConfig.java

@@ -31,8 +31,10 @@ public class MybatisConfig {
     public MybatisPlusInterceptor mybatisPlusInterceptorPage() {
         MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
 
-        interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(new TenantLineHandler() {
+        // 拼接逻辑删除字段
+        interceptor.addInnerInterceptor(new LogicDeleteInterceptor());
 
+        interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(new TenantLineHandler() {
             @Override
             public Expression getTenantId() {
                 return new StringValue(AuthUtil.getTenantId());
@@ -45,9 +47,6 @@ public class MybatisConfig {
 
         }));
 
-        // 拼接逻辑删除字段
-        interceptor.addInnerInterceptor(new LogicDeleteInterceptor());
-
         // 分页
         interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
 

+ 56 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/controller/supplier/SupplierPriceController.java

@@ -0,0 +1,56 @@
+package com.fjhx.controller.supplier;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.entity.supplier.SupplierPrice;
+import com.fjhx.params.supplier.SupplierPriceVo;
+import com.fjhx.service.supplier.SupplierPriceService;
+import org.springblade.core.tool.api.R;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Map;
+
+/**
+ * <p>
+ * 供应商价格 前端控制器
+ * </p>
+ *
+ * @author ${author}
+ * @since 2022-11-25
+ */
+@RestController
+@RequestMapping("/supplierPrice")
+public class SupplierPriceController {
+
+    @Autowired
+    private SupplierPriceService supplierPriceService;
+
+    @PostMapping("/page")
+    public R page(@RequestBody Map<String, Object> condition) {
+        Page<SupplierPrice> result = supplierPriceService.getPage(condition);
+        return R.success(result);
+    }
+
+    @PostMapping("/add")
+    public R add(@RequestBody SupplierPriceVo supplierPriceVo) {
+        supplierPriceService.add(supplierPriceVo);
+        return R.success();
+    }
+
+    @PostMapping("/edit")
+    public R edit(@RequestBody SupplierPriceVo supplierPriceVo) {
+        supplierPriceService.edit(supplierPriceVo);
+        return R.success();
+    }
+
+    @PostMapping("/delete")
+    public R delete(@RequestBody SupplierPriceVo supplierPriceVo) {
+        supplierPriceService.delete(supplierPriceVo);
+        return R.success();
+    }
+
+}
+

+ 21 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/mapper/supplier/SupplierPriceMapper.java

@@ -0,0 +1,21 @@
+package com.fjhx.mapper.supplier;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.entity.supplier.SupplierPrice;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.fjhx.utils.wrapperUtil.IWrapper;
+import org.apache.ibatis.annotations.Param;
+
+/**
+ * <p>
+ * 供应商价格 Mapper 接口
+ * </p>
+ *
+ * @author ${author}
+ * @since 2022-11-25
+ */
+public interface SupplierPriceMapper extends BaseMapper<SupplierPrice> {
+
+    Page<SupplierPrice> getPage(@Param("page") Page<SupplierPrice> page, @Param("ew") IWrapper<SupplierPrice> wrapper);
+
+}

+ 20 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/mapper/supplier/SupplierPriceMapper.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fjhx.mapper.supplier.SupplierPriceMapper">
+
+    <select id="getPage" resultType="java.util.LinkedHashMap">
+        SELECT sp.id,
+               sp.price,
+               sp.material_id,
+               sp.supplier_id,
+               s.`name` supplierName,
+               m.`name` materialName,
+               m.`code` materialCode,
+               m.type   materialType
+        FROM supplier_price sp
+                 INNER JOIN supplier s ON sp.supplier_id = s.id
+                 INNER JOIN material m ON sp.material_id = m.id
+            ${ew.customSqlSegment}
+    </select>
+
+</mapper>

+ 28 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/service/supplier/SupplierPriceService.java

@@ -0,0 +1,28 @@
+package com.fjhx.service.supplier;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.entity.supplier.SupplierPrice;
+import com.fjhx.params.supplier.SupplierPriceVo;
+import com.fjhx.base.BaseService;
+
+import java.util.Map;
+
+/**
+ * <p>
+ * 供应商价格 服务类
+ * </p>
+ *
+ * @author ${author}
+ * @since 2022-11-25
+ */
+public interface SupplierPriceService extends BaseService<SupplierPrice> {
+
+    Page<SupplierPrice> getPage(Map<String, Object> condition);
+
+    void add(SupplierPriceVo supplierPriceVo);
+
+    void edit(SupplierPriceVo supplierPriceVo);
+
+    void delete(SupplierPriceVo supplierPriceVo);
+
+}

+ 73 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/service/supplier/impl/SupplierPriceServiceImpl.java

@@ -0,0 +1,73 @@
+package com.fjhx.service.supplier.impl;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fjhx.entity.material.Material;
+import com.fjhx.entity.supplier.Supplier;
+import com.fjhx.entity.supplier.SupplierPrice;
+import com.fjhx.mapper.supplier.SupplierPriceMapper;
+import com.fjhx.params.supplier.SupplierPriceVo;
+import com.fjhx.service.supplier.SupplierPriceService;
+import com.fjhx.utils.Assert;
+import com.fjhx.utils.wrapperUtil.IWrapper;
+import com.fjhx.utils.wrapperUtil.KeywordData;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.util.Map;
+
+/**
+ * <p>
+ * 供应商价格 服务实现类
+ * </p>
+ *
+ * @author ${author}
+ * @since 2022-11-25
+ */
+@Service
+public class SupplierPriceServiceImpl extends ServiceImpl<SupplierPriceMapper, SupplierPrice> implements SupplierPriceService {
+
+    @Override
+    public Page<SupplierPrice> getPage(Map<String, Object> condition) {
+
+        IWrapper<SupplierPrice> wrapper = IWrapper.getWrapper(condition);
+        wrapper.keyword(new KeywordData("s", Supplier::getName),
+                        new KeywordData("m", Material::getName),
+                        new KeywordData("m", Material::getCode))
+                .eq("s", Supplier::getId, condition.get("supplierId"))
+                .eq("m", Material::getId, condition.get("materialId"))
+                .like("s", Supplier::getName, condition.get("supplierName"))
+                .like("m", Material::getName, condition.get("materialName"))
+                .like("m", Material::getCode, condition.get("materialCode"))
+                .eq("m", Material::getType, condition.get("materialType"));
+
+        return baseMapper.getPage(createPage(condition), wrapper);
+    }
+
+    @Override
+    public void add(SupplierPriceVo supplierPriceVo) {
+        Long supplierId = supplierPriceVo.getSupplierId();
+        Long materialId = supplierPriceVo.getMaterialId();
+        BigDecimal price = supplierPriceVo.getPrice();
+
+        Assert.notEmpty(supplierId, "供应商id不能为空");
+        Assert.notEmpty(materialId, "物料id不能为空");
+        Assert.notEmpty(price, "物料价格不能为空");
+
+        long count = count(q -> q.eq(SupplierPrice::getSupplierId, supplierId).eq(SupplierPrice::getMaterialId, materialId));
+
+        Assert.eqZero(count, "此供应商物料价格已存在");
+        save(supplierPriceVo);
+    }
+
+    @Override
+    public void edit(SupplierPriceVo supplierPriceVo) {
+        updateById(supplierPriceVo);
+    }
+
+    @Override
+    public void delete(SupplierPriceVo supplierPriceVo) {
+        removeById(supplierPriceVo.getId());
+    }
+
+}