linbl 1 éve
szülő
commit
cb094d6e9c

+ 31 - 0
sp-service/level-two-server/src/main/java/com/pj/tb_item_rules/TbItemRulesAppController.java

@@ -0,0 +1,31 @@
+package com.pj.tb_item_rules;
+
+import com.pj.utils.sg.AjaxJson;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+
+/**
+ * Controller: tb_item_rules -- 费项因子
+ * @author lbl
+ */
+@RestController
+@RequestMapping("/app/TbItemRules/")
+public class TbItemRulesAppController {
+
+	/** 底层 Service 对象 */
+	@Autowired
+	TbItemRulesService tbItemRulesService;
+
+	/** 查集合 - 根据条件(参数为空时代表忽略指定条件) */
+	@RequestMapping("getAllList")
+	public AjaxJson getAllList() {
+		List<TbItemRulesVo> list = tbItemRulesService.getAllList();
+		return AjaxJson.getSuccessData(list);
+	}
+
+
+}

+ 4 - 3
sp-service/level-two-server/src/main/java/com/pj/tb_item_rules/TbItemRulesMapper.java

@@ -10,7 +10,7 @@ import org.springframework.stereotype.Repository;
 
 /**
  * Mapper: tb_item_rules -- 费项因子
- * @author lbl 
+ * @author lbl
  */
 
 @Mapper
@@ -21,10 +21,11 @@ public interface TbItemRulesMapper extends BaseMapper <TbItemRules> {
 
 	/**
 	 * 查集合 - 根据条件(参数为空时代表忽略指定条件)
-	 * @param so 参数集合 
-	 * @return 数据列表 
+	 * @param so 参数集合
+	 * @return 数据列表
 	 */
 	List<TbItemRules> getList(SoMap so);
 
+	List<TbItemRulesVo> getAllList();
 
 }

+ 19 - 14
sp-service/level-two-server/src/main/java/com/pj/tb_item_rules/TbItemRulesMapper.xml

@@ -7,17 +7,17 @@
 
 	<!-- ================================== 查询相关 ================================== -->
 	<!-- select id, goods_codes, create_time, update_by, update_by_name, update_time, update_by_id, fee_type, percent, fee_money from tb_item_rules  -->
-	
+
 	<!-- 通用映射:自动模式 -->
 	<resultMap id="model" autoMapping="true" type="com.pj.tb_item_rules.TbItemRules"></resultMap>
-	
+
 	<!-- 公共查询sql片段 -->
 	<sql id="select_sql">
-		select * 
-		from tb_item_rules 
+		select *
+		from tb_item_rules
 	</sql>
 
-	
+
 	<!-- 查集合 - 根据条件(参数为空时代表忽略指定条件) [G] -->
 	<select id="getList" resultMap="model">
 		<include refid="select_sql"></include>
@@ -30,6 +30,7 @@
 			<if test=' this.has("feeType") '> and fee_type = #{feeType} </if>
 			<if test=' this.has("percent") '> and percent = #{percent} </if>
 			<if test=' this.has("feeMoney") '> and fee_money = #{feeMoney} </if>
+			<if test=' this.has("itemId") '> and item_id = #{itemId} </if>
 		</where>
 		order by
 		<choose>
@@ -46,14 +47,18 @@
 			<otherwise> id desc </otherwise>
 		</choose>
 	</select>
-	
-	
-	
-	
-	
-	
-	
-	
-	
+
+
+	<select id="getAllList" resultType="com.pj.tb_item_rules.TbItemRulesVo">
+		select r.*
+		from tb_fee_item i
+		left join tb_item_rules r on i.id = r.item_id
+	</select>
+
+
+
+
+
+
 
 </mapper>

+ 8 - 4
sp-service/level-two-server/src/main/java/com/pj/tb_item_rules/TbItemRulesService.java

@@ -13,7 +13,7 @@ import com.pj.utils.sg.*;
 
 /**
  * Service: tb_item_rules -- 费项因子
- * @author lbl 
+ * @author lbl
  */
 @Service
 @Transactional(rollbackFor = Exception.class)
@@ -44,11 +44,15 @@ public class TbItemRulesService extends ServiceImpl<TbItemRulesMapper, TbItemRul
 		return super.getById(id);
 	}
 
-	/** 查集合 - 根据条件(参数为空时代表忽略指定条件) */  
-	List<TbItemRules> getList(SoMap so) { 
-		return tbItemRulesMapper.getList(so);	
+	/** 查集合 - 根据条件(参数为空时代表忽略指定条件) */
+	public List<TbItemRules> getList(SoMap so) {
+		return tbItemRulesMapper.getList(so);
 	}
 
+	/** 查集合 - 根据费项表) */
+	public List<TbItemRulesVo> getAllList() {
+		return tbItemRulesMapper.getAllList();
+	}
 
 	public List<TbItemRules> findByItemId(Long itemId) {
 		QueryWrapper<TbItemRules>ew=new QueryWrapper<>();

+ 54 - 0
sp-service/level-two-server/src/main/java/com/pj/tb_item_rules/TbItemRulesVo.java

@@ -0,0 +1,54 @@
+package com.pj.tb_item_rules;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import lombok.Data;
+import java.math.BigDecimal;
+
+/**
+ * Model: tb_item_rules -- 费项因子
+ * @author lbl
+ */
+@Data
+public class TbItemRulesVo  {
+
+
+	private Long itemId;
+
+	/**
+	 * 指定的商品
+	 */
+	private String goodsCodes;
+
+
+	/**
+	 * 类型(1=按交易额收取,2=按次收取,3=按顿收费)
+	 */
+	private String feeType;
+
+	/**
+	 * 百分比fee_type=1或3时生效
+	 */
+	private Double percent;
+
+	/**
+	 * 收费金额 fee_type=2时生效
+	 */
+	private BigDecimal feeMoney;
+
+
+	@TableField(exist = false)
+	private String goodsCodeStr;
+
+
+	/**
+	 * 收费企业
+	 */
+	private String companyName;
+
+	/**
+	 * 名称
+	 */
+	private String name;
+
+
+}

+ 8 - 0
sp-service/level-two-server/src/main/java/com/pj/tb_orders/TbOrdersApiController.java

@@ -110,6 +110,14 @@ public class TbOrdersApiController {
 		return AjaxJson.toAjax(tbOrdersService.addOrderByResale(so));
 	}
 
+	/** 计算 订单转售时,计算当前订单费项总和 */
+	@RequestMapping("countPrice")
+	public AjaxJson countPrice() {
+		SoMap so = SoMap.getRequestSoMap();
+		Double sumPrice = tbOrdersService.countPrice(so);
+		return AjaxJson.getSuccessData(sumPrice);
+	}
+
 	/** 查 根据订单Id查订单详情 */
 	@RequestMapping("getDetailById")
 	public AjaxJson getDetailById() {

+ 33 - 1
sp-service/level-two-server/src/main/java/com/pj/tb_orders/TbOrdersService.java

@@ -26,6 +26,8 @@ import com.pj.tb_fee_item_record.TbFeeItemRecordService;
 import com.pj.tb_goods_demand.TbGoodsDemand;
 import com.pj.tb_goods_demand.TbGoodsDemandService;
 import com.pj.tb_goods_demand.vo.GoodsDemandVo;
+import com.pj.tb_item_rules.TbItemRules;
+import com.pj.tb_item_rules.TbItemRulesService;
 import com.pj.tb_orders_cart.TbOrdersCart;
 import com.pj.tb_orders_cart.TbOrdersCartMapper;
 import com.pj.tb_purchaser.TbPurchaser;
@@ -37,6 +39,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
 
 /**
@@ -67,7 +70,9 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
     TbOrdersCartMapper tbOrdersCartMapper;
 
     @Autowired
-    TbFeeItemService tbFeeItemService;
+    private TbFeeItemService tbFeeItemService;
+    @Autowired
+    private TbItemRulesService tbItemRulesService;
 
     @Autowired
     TbFeeItemRecordService tbFeeItemRecordService;
@@ -336,6 +341,33 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
         return true;
     }
 
+    public Double countPrice(SoMap so) {
+        OrderDto orderDto = levelOneServerInterface.getOrderDtoById(so.getLong("id"));
+        if (null == orderDto) throw new RuntimeException("当前一级市场订单为空,请联系管理员!");
+
+        List<TbItemRules> ruleList = new ArrayList<>();
+        List<TbFeeItem> feeItemList = tbFeeItemService.getFeeItems();
+        feeItemList.forEach(feeItem -> {
+            ruleList.addAll(tbItemRulesService.getList(new SoMap().set("itemId", feeItem.getId())));
+        });
+
+        GoodsDto goods = levelOneServerInterface.getByGoodsId(orderDto.getGoodsId());
+        List<TbItemRules> newRuleList = ruleList.stream().filter(rule -> rule.getGoodsCodes().contains(goods.getCode())).collect(Collectors.toList());
+        AtomicReference<Float> sum= new AtomicReference<>(0.00F);
+        newRuleList.forEach(ruleItem -> {
+            //类型(1=按交易额收取,2=按次收取,3=按吨)
+            if("1".equals(ruleItem.getFeeType())) {
+                sum.updateAndGet(v -> new Float((float) (v +  (orderDto.getTotalPrice() * ruleItem.getPercent()/100)  )));
+            } else if("2".equals(ruleItem.getFeeType())) {
+                sum.updateAndGet(v -> new Float((float) (v +  ruleItem.getFeeMoney().doubleValue()  )));
+            } else if("3".equals(ruleItem.getFeeType())) {
+                sum.updateAndGet(v -> new Float((float) (v +  (orderDto.getTotalPrice() * ruleItem.getPercent() /100)  )));
+            }
+        });
+        Double sumPrice = sum.get() + orderDto.getTotalPrice() + 50;//50为利润,暂时写死
+        return sumPrice;
+    }
+
     /**
      * 根据一级市场id查询二级市场订单
      */