瀏覽代碼

Merge branch 'feature-operating-report' of http://git.dayaedu.com/yonge/mec into feature-operating-report

zouxuan 4 年之前
父節點
當前提交
25cd59c6db

+ 9 - 2
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/GoodsDao.java

@@ -36,13 +36,20 @@ public interface GoodsDao extends BaseDAO<Integer, Goods> {
     List<Goods> findTypeGoods(@Param("type") String type);
 
     /**
+     * @param goodsList:
+     * @return void
      * @describe 批量新增
      * @apiNote 时光荏苒,认真工作的时间总是过得很快,而我、享受这一刻!
      * @author zouxuan
      * @date 2020/9/4
      * @time 14:39
-     * @param goodsList:
-     * @return void
      */
     void batchInsert(@Param("goodsList") List<Goods> goodsList);
+
+    /**
+     * 获取商品列表
+     * @param goodsIds
+     * @return
+     */
+    List<Goods> getGoodies(@Param("goodsIds") List<Integer> goodsIds);
 }

+ 14 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentRepair.java

@@ -20,6 +20,12 @@ public class StudentRepair {
     @ApiModelProperty(value = "分部id", required = false)
     private Integer organId;
 
+    /**
+     * 分部id
+     */
+    @ApiModelProperty(value = "乐团id", required = false)
+    private String musicGroupId;
+
 
     /**
     * 分部名称
@@ -413,4 +419,12 @@ public class StudentRepair {
     public String toString() {
         return ToStringBuilder.reflectionToString(this);
     }
+
+    public String getMusicGroupId() {
+        return musicGroupId;
+    }
+
+    public void setMusicGroupId(String musicGroupId) {
+        this.musicGroupId = musicGroupId;
+    }
 }

+ 12 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/SellOrderService.java

@@ -4,7 +4,19 @@ package com.ym.mec.biz.service;
 import com.ym.mec.biz.dal.entity.SellOrder;
 import com.ym.mec.common.service.BaseService;
 
+import java.math.BigDecimal;
+import java.util.List;
+
 
 public interface SellOrderService extends BaseService<Integer, SellOrder> {
 
+    /**
+     * 添加销售订单
+     *
+     * @param goodsIds
+     * @param totalAmount
+     * @param balance
+     * @return
+     */
+    List<SellOrder> addSellOrder(Long orderId, String musicGroupId, List<Integer> goodsIds, BigDecimal totalAmount, BigDecimal balance);
 }

+ 99 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SellOrderServiceImpl.java

@@ -1,18 +1,33 @@
 package com.ym.mec.biz.service.impl;
 
 
+import com.alibaba.fastjson.JSON;
+import com.ym.mec.biz.dal.dao.GoodsDao;
+import com.ym.mec.biz.dal.dao.MusicGroupDao;
 import com.ym.mec.biz.dal.dao.SellOrderDao;
+import com.ym.mec.biz.dal.dao.StudentPaymentOrderDao;
 import com.ym.mec.biz.dal.entity.*;
+import com.ym.mec.biz.dal.enums.GoodsType;
+import com.ym.mec.biz.dal.enums.SellTypeEnum;
 import com.ym.mec.biz.service.*;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
+import java.util.*;
+
 @Service
 public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> implements SellOrderService {
     @Autowired
     private SellOrderDao sellOrderDao;
+    @Autowired
+    private GoodsDao goodsDao;
+    @Autowired
+    private StudentPaymentOrderDao studentPaymentOrderDao;
+    @Autowired
+    private MusicGroupDao musicGroupDao;
 
     @Override
     public BaseDAO<Integer, SellOrder> getDAO() {
@@ -20,4 +35,88 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
     }
 
 
+    @Override
+    public List<SellOrder> addSellOrder(Long orderId, String musicGroupId, List<Integer> goodsIds, BigDecimal totalAmount, BigDecimal balance) {
+        if (goodsIds == null || goodsIds.size() <= 0) {
+            return null;
+        }
+        if (balance == null) {
+            balance = BigDecimal.ZERO;
+        }
+        StudentPaymentOrder order = studentPaymentOrderDao.get(orderId);
+        MusicGroup musicGroup = new MusicGroup();
+        if (musicGroupId != null) {
+            musicGroup = musicGroupDao.get(musicGroupId);
+        }
+        int goodsNum = goodsIds.size();
+        BigDecimal goodsTotalPrice = BigDecimal.ZERO;
+        List<Goods> goodies = goodsDao.getGoodies(goodsIds);
+        int i = 1;
+        for (Integer goodsId : goodsIds) {
+            for (Goods goods : goodies) {
+                if (goods.getId().equals(goodsId)) {
+                    goodsTotalPrice = goodsTotalPrice.add(goods.getGroupPurchasePrice());
+                    break;
+                }
+            }
+        }
+
+        BigDecimal hasRouteBalance = BigDecimal.ZERO;
+        BigDecimal goodsTotalBalance = goodsTotalPrice.multiply(balance).divide(totalAmount, 2, BigDecimal.ROUND_HALF_UP);
+        List<SellOrder> sellOrders = new ArrayList<>();
+        for (Integer goodsId : goodsIds) {
+            SellOrder sellOrder = new SellOrder();
+            BigDecimal goodsPrice = BigDecimal.ZERO;
+            Goods nowGoods = new Goods();
+            for (Goods goods : goodies) {
+                if (goods.getId().equals(goodsId)) {
+                    nowGoods = goods;
+                    break;
+                }
+            }
+            goodsPrice = nowGoods.getGroupPurchasePrice();
+
+            BigDecimal goodsBalance = goodsTotalBalance.multiply(goodsPrice).divide(totalAmount, 2, BigDecimal.ROUND_HALF_UP);
+            if (i == goodsNum) {
+                goodsBalance = goodsTotalBalance.subtract(hasRouteBalance);
+            }
+            hasRouteBalance = hasRouteBalance.add(goodsBalance);
+            sellOrder.setGoodsId(goodsId);
+            sellOrder.setGoodsName(nowGoods.getName());
+            sellOrder.setExpectAmount(goodsPrice);
+            sellOrder.setBalanceAmount(goodsBalance);
+            sellOrder.setActualAmount(goodsPrice.subtract(goodsBalance));
+            Map<String, BigDecimal> CostMap = new HashMap<>();
+            CostMap.put("sellCost", nowGoods.getDiscountPrice());
+            if (nowGoods.getAgreeCostPrice() != null) {
+                CostMap.put("SellCost2", nowGoods.getAgreeCostPrice());
+            }
+            sellOrder.setSellCost2(JSON.toJSONString(CostMap));
+
+            sellOrder.setOrganId(order.getOrganId());
+            sellOrder.setCooperationOrganId(musicGroup.getCooperationOrganId());
+            sellOrder.setTransNo(order.getTransNo());
+            sellOrder.setOrderId(order.getId());
+            sellOrder.setOrderNo(order.getOrderNo());
+            sellOrder.setSellCost(nowGoods.getDiscountPrice());
+            sellOrder.setNum(1);
+            sellOrder.setUserId(order.getUserId());
+            sellOrder.setPaymentChannel(order.getPaymentChannel());
+            sellOrder.setMerNo(order.getMerNos());
+            sellOrder.setSellTime(order.getCreateTime());
+            sellOrder.setCreateIme(new Date());
+            sellOrder.setUpdateTime(new Date());
+            if (nowGoods.getType().equals(GoodsType.INSTRUMENT)) {
+                sellOrder.setType(SellTypeEnum.INSTRUMENT);
+            } else if (nowGoods.getType().equals(GoodsType.ACCESSORIES)) {
+                sellOrder.setType(SellTypeEnum.ACCESSORIES);
+            } else {
+                sellOrder.setType(SellTypeEnum.OTHER);
+            }
+            sellOrders.add(sellOrder);
+            i++;
+        }
+        sellOrderDao.batchInsert(sellOrders);
+        return sellOrders;
+    }
 }

+ 10 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRepairServiceImpl.java

@@ -63,6 +63,8 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
     private GoodsService goodsService;
     @Autowired
     private StudentPaymentRouteOrderService studentPaymentRouteOrderService;
+    @Autowired
+    private SellOrderService sellOrderService;
 
     @Override
     public BaseDAO<Integer, StudentRepair> getDAO() {
@@ -617,7 +619,14 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
                 rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount().negate());
             }
             sysUserCashAccountDetailService.insert(paymentDetail);
-            //
+            //生成销售订单
+            List<Integer> goodsIds = new ArrayList<>();
+            if(StringUtils.isNotBlank(repairInfo.getGoodsJson())){
+                List<Goods> goods = JSONObject.parseArray(repairInfo.getGoodsJson(), Goods.class);
+                goodsIds = goods.stream().map(Goods::getId).collect(Collectors.toList());
+            }
+
+            sellOrderService.addSellOrder(studentPaymentOrder.getId(),repairInfo.getMusicGroupId(),goodsIds,studentPaymentOrder.getExpectAmount(),studentPaymentOrder.getBalancePaymentAmount());
 
             String imContent = repairInfo.getStudentName() + "学员您好,您的乐器维修已受理,我们会尽快完成保养维修";
 

+ 6 - 0
mec-biz/src/main/resources/config/mybatis/GoodsMapper.xml

@@ -197,4 +197,10 @@
     <select id="findTypeGoods" resultMap="Goods">
         SELECT * FROM goods WHERE type_ = #{type} AND status_ != 0
     </select>
+    <select id="getGoodies" resultMap="Goods">
+        SELECT * FROM goods WHERE id_ IN
+        <foreach collection="goodsIds" item="goodsId" open="(" close=")">
+            #{goodsId}
+        </foreach>
+    </select>
 </mapper>

+ 2 - 2
mec-biz/src/main/resources/config/mybatis/SellOrderMapper.xml

@@ -242,7 +242,7 @@
         GROUP BY spo.organ_id_, co.id_
         ]]></select>
 
-    <!-- 获取分部学校的收入支出(充值) -->
+    <!-- 获取分部学校的收入(充值) -->
     <select id="getRechargeMonthReport" resultMap="com.ym.mec.biz.dal.dao.OperatingReportDao.OperatingReport"><![CDATA[
         SELECT spo.organ_id_,
                co.id_                  cooperation_organ_id_,
@@ -259,7 +259,7 @@
         GROUP BY spo.organ_id_, co.id_
         ]]></select>
 
-    <!-- 获取分部学校的收入支出(零星支付) -->
+    <!-- 获取分部学校的收入(零星支付) -->
     <select id="getSporadicMonthReport" resultMap="com.ym.mec.biz.dal.dao.OperatingReportDao.OperatingReport"><![CDATA[
         SELECT spo.organ_id_,
                co.id_                  cooperation_organ_id_,

+ 7 - 2
mec-biz/src/main/resources/config/mybatis/StudentRepairMapper.xml

@@ -3,6 +3,8 @@
 <mapper namespace="com.ym.mec.biz.dal.dao.StudentRepairDao">
     <resultMap id="StudentRepair" type="com.ym.mec.biz.dal.entity.StudentRepair">
         <result column="id_" jdbcType="INTEGER" property="id"/>
+        <result column="music_group_id_" jdbcType="VARCHAR" property="musicGroupId"/>
+        <result column="trans_no_" jdbcType="VARCHAR" property="transNo"/>
         <result column="trans_no_" jdbcType="VARCHAR" property="transNo"/>
         <result column="organ_id_" jdbcType="INTEGER" property="organId"/>
         <result column="name_" jdbcType="INTEGER" property="organName"/>
@@ -42,7 +44,7 @@
     <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.StudentRepair" useGeneratedKeys="true" keyColumn="id"
             keyProperty="id">
         <!--@mbg.generated-->
-        insert into student_repair (id_, trans_no_, organ_id_,
+        insert into student_repair (id_,music_group_id_, trans_no_, organ_id_,
         student_id_, student_name_, student_school_,
         employee_id_, employee_name_, subject_id_,
         subject_name_, type_, instrument_no_,fee_list_,
@@ -50,7 +52,7 @@
         send_type_, contact_name_, contact_mobile_,
         address_, pay_status_, create_time_,
         update_time_,repair_status_,goods_json_)
-        values (#{id,jdbcType=INTEGER}, #{transNo,jdbcType=VARCHAR}, #{organId,jdbcType=INTEGER},
+        values (#{id,jdbcType=INTEGER},#{musicGroupId}, #{transNo,jdbcType=VARCHAR}, #{organId,jdbcType=INTEGER},
         #{studentId,jdbcType=INTEGER}, #{studentName,jdbcType=VARCHAR}, #{studentSchool,jdbcType=VARCHAR},
         #{employeeId,jdbcType=INTEGER}, #{employeeName,jdbcType=VARCHAR}, #{subjectId,jdbcType=INTEGER},
         #{subjectName,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER}, #{instrumentNo,jdbcType=VARCHAR},
@@ -62,6 +64,9 @@
     <update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentRepair">
         UPDATE student_repair
         <set>
+            <if test="musicGroupId != null">
+                music_group_id_ = #{musicGroupId},
+            </if>
             <if test="goodsJson != null">
                 goods_json_ = #{goodsJson},
             </if>