Helius
2021-07-08 12ade37f986328c62d85255105cbb206f458f069
fix tj
2 files added
6 files modified
164 ■■■■■ changed files
gc-shop/src/main/java/com/xzx/gc/shop/controller/ApiOrderController.java 6 ●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/mapper/JhyOrderMapper.java 9 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/mapper/OrderInfoMapper.java 17 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/mapper/ScoreOrderMapper.java 2 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/service/JhyService.java 69 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/resources/mapper/shop/JhyOrderMapper.xml 24 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/resources/mapper/shop/OrderInfoMapper.xml 29 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/resources/mapper/shop/ScoreOrderMapper.xml 8 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/controller/ApiOrderController.java
@@ -7,6 +7,7 @@
import com.xzx.gc.model.JsonResult;
import com.xzx.gc.shop.dto.AddGoodsOrderDto;
import com.xzx.gc.shop.dto.XcxOrderListDto;
import com.xzx.gc.shop.service.JhyService;
import com.xzx.gc.shop.service.OrderService;
import com.xzx.gc.shop.vo.StatisticsVo;
import com.xzx.gc.shop.vo.XcxOrderDetailsVo;
@@ -28,6 +29,9 @@
    @Autowired
    private OrderService orderService;
    @Autowired
    private JhyService jhyService;
    @ApiOperation("积分商城下单")
    @PostMapping(value = "/goods/order/add")
@@ -80,6 +84,6 @@
    @ApiOperation("首页统计")
    @GetMapping(value = "/order/statistics")
    public JsonResult<StatisticsVo> orderStatistics(HttpServletRequest request) {
        return JsonResult.success(orderService.orderStatistics(getUserId(request)));
        return JsonResult.success(jhyService.orderStatistics(getUserId(request)));
    }
}
gc-shop/src/main/java/com/xzx/gc/shop/mapper/JhyOrderMapper.java
@@ -7,11 +7,20 @@
import com.xzx.gc.util.GcMapper;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public interface JhyOrderMapper  extends GcMapper<JhyOrder> {
    List<QueryJhyOrderListVo> queryOrderList(@Param("record") QueryJhyOrderListDto model);
    ViewJhyOrderVo viewJhyOrder(@Param("id") Long id);
    List<Map<String, Object>> selectJhyOrderTitleStatistics(@Param("userId") String userId);
    Integer selectJhyOrderCnt(@Param("userId") String userId);
    BigDecimal selectTotalScoreHasGet(@Param("userId") String userId);
}
gc-shop/src/main/java/com/xzx/gc/shop/mapper/OrderInfoMapper.java
New file
@@ -0,0 +1,17 @@
package com.xzx.gc.shop.mapper;
import com.xzx.gc.entity.OrderInfo;
import com.xzx.gc.util.GcMapper;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public interface OrderInfoMapper extends GcMapper<OrderInfo> {
    List<Map<String, Object>> selectOrderTitleStatistics(@Param("userId") String userId);
    Integer selectOrderCnt(@Param("userId") String userId);
}
gc-shop/src/main/java/com/xzx/gc/shop/mapper/ScoreOrderMapper.java
@@ -28,4 +28,6 @@
    int updateOrderStatus(@Param("id") Long id, @Param("status") Integer status, @Param("userId") String userId);
    Map<String, Object> selectOrderStastics(@Param("userId") String userId);
    Integer selectScoreOrderCnt(@Param("userId") String userId);
}
gc-shop/src/main/java/com/xzx/gc/shop/service/JhyService.java
@@ -9,13 +9,17 @@
import com.xzx.gc.common.utils.StringUtils;
import com.xzx.gc.entity.JhyOrder;
import com.xzx.gc.entity.JhyOrderItems;
import com.xzx.gc.entity.ScoreOrder;
import com.xzx.gc.entity.ScoreOrderDetails;
import com.xzx.gc.shop.dto.CancelJhyOrderDto;
import com.xzx.gc.shop.dto.QueryJhyOrderListDto;
import com.xzx.gc.shop.mapper.JhyOrderItemsMapper;
import com.xzx.gc.shop.mapper.JhyOrderMapper;
import com.xzx.gc.shop.mapper.OrderInfoMapper;
import com.xzx.gc.shop.mapper.ScoreOrderMapper;
import com.xzx.gc.shop.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
@@ -36,6 +40,12 @@
    JhyOrderMapper jhyOrderMapper;
    @Resource
    JhyOrderItemsMapper jhyOrderItemsMapper;
    @Autowired
    private OrderInfoMapper orderInfoMapper;
    @Autowired
    private ScoreOrderMapper scoreOrderMapper;
    public Map<String, Object> queryOrderList(QueryJhyOrderListDto model) {
        PageHelper.startPage(model.getPage(), model.getLimit());
@@ -95,4 +105,63 @@
        jhyOrder.setStatus(JhyOrder.ORDER_STATUS_CANCEL);
        jhyOrderMapper.updateByPrimaryKey(jhyOrder);
    }
    public StatisticsVo orderStatistics(String userId) {
        // 骑手订单
        List<Map<String, Object>> qsAllData = orderInfoMapper.selectOrderTitleStatistics(null);
        List<Map<String, Object>> qsUserData = orderInfoMapper.selectOrderTitleStatistics(userId);
        // 集物员订单
        List<Map<String, Object>> jhyAllData = jhyOrderMapper.selectJhyOrderTitleStatistics(null);
        List<Map<String, Object>> jhyUserData = jhyOrderMapper.selectJhyOrderTitleStatistics(userId);
        BigDecimal allCarbon = totalData(qsAllData).add(totalData(jhyAllData));
        BigDecimal userCarbon = totalData(qsUserData).add(totalData(jhyUserData));
        Integer qsAllCnt = orderInfoMapper.selectOrderCnt(null);
        Integer qsUserCnt = orderInfoMapper.selectOrderCnt(userId);
        Integer jhyAllCnt = jhyOrderMapper.selectJhyOrderCnt(null);
        Integer jhyUserCnt = jhyOrderMapper.selectJhyOrderCnt(userId);
        Integer allCnt = scoreOrderMapper.selectScoreOrderCnt(null);
        BigDecimal score = jhyOrderMapper.selectTotalScoreHasGet(userId);
        StatisticsVo result = new StatisticsVo();
        result.setTotalReduceCarbon(allCarbon.divide(BigDecimal.valueOf(1000), 2, BigDecimal.ROUND_DOWN));
        result.setReduceCarbon(userCarbon.setScale(2, BigDecimal.ROUND_DOWN));
        result.setOrderCnt(qsUserCnt + jhyUserCnt);
        result.setTotalOrderCnt(qsAllCnt + jhyAllCnt);
        result.setTotalBuyCnt(allCnt);
        result.setScore(score);
        return result;
    }
    private BigDecimal totalData(List<Map<String, Object>> data) {
        Map<String, BigDecimal> type = new HashMap<>();
        type.put("金属", BigDecimal.valueOf(0.02));
        type.put("纸类", BigDecimal.valueOf(1.5));
        type.put("塑料", BigDecimal.valueOf(0.61));
        type.put("衣服", BigDecimal.valueOf(1.63));
        if (CollUtil.isEmpty(data)) {
            return BigDecimal.ZERO;
        }
        BigDecimal total = BigDecimal.ZERO;
        for (Map<String, Object> map : data) {
            String title = (String) map.get("title");
            BigDecimal value = type.get(title);
            if (value == null) {
                continue;
            }
            BigDecimal weight = new BigDecimal(map.get("weight").toString());
            total = total.add(weight.multiply(value));
        }
        return total;
    }
}
gc-shop/src/main/resources/mapper/shop/JhyOrderMapper.xml
@@ -72,6 +72,30 @@
        WHERE a.id=#{id}
    </select>
    <select id="selectJhyOrderTitleStatistics" resultType="java.util.Map">
        select d.title title, sum(b.weight) weight
        from xzx_jhy_order a
           inner join xzx_jhy_order_items b on a.id=b.order_id
           inner join xzx_sys_environmental_info c on b.item_type=c.id
           inner join xzx_sys_environmental_info d on c.parent_id = d.id
        where a.status in (3, 4)
        <if test="userId != null and userId != ''">
            and a.user_id=#{userId}
        </if>
        group by d.title
    </select>
    <select id="selectJhyOrderCnt" resultType="java.lang.Integer">
        select IFNULL(count(1),0) from xzx_jhy_order
        where status in (3, 4)
        <if test="userId != null and userId != ''">
            and user_id=#{userId}
        </if>
    </select>
    <select id="selectTotalScoreHasGet" resultType="java.math.BigDecimal">
        select IFNULL(SUM(b.score), 0) from xzx_jhy_order a
        inner join xzx_jhy_order_items b on a.id=b.order_id
        where a.user_id=#{userId}
    </select>
</mapper>
gc-shop/src/main/resources/mapper/shop/OrderInfoMapper.xml
New file
@@ -0,0 +1,29 @@
<?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.xzx.gc.shop.mapper.OrderInfoMapper">
    <select id="selectOrderTitleStatistics" resultType="java.util.Map">
        select
            f.title title,
            sum(e.weight) weight
        from xzx_order_info a
            inner join xzx_electronic_fence b on a.town_id=b.id
            inner join xzx_sys_address_level_info c on b.town_code=c.adcode
            inner join xzx_sys_environmental_info d on c.level_3_id=d.city_id
            inner join xzx_order_item_info e on d.item_type=e.item_type and a.order_id=e.order_id and e.weight !=0
            inner join xzx_sys_environmental_info f on f.id=d.parent_id
        where a.order_status in (5)
        <if test="userId != null and userId != ''">
            and a.create_user_id = #{userId}
        </if>
        group by f.title
    </select>
    <select id="selectOrderCnt" resultType="java.lang.Integer">
        select IFNULL(count(1),0) from xzx_order_info
        where order_status = 5
        <if test="userId != null and userId != ''">
            and create_user_id = #{userId}
        </if>
    </select>
</mapper>
gc-shop/src/main/resources/mapper/shop/ScoreOrderMapper.xml
@@ -100,4 +100,12 @@
            and user_id=#{userId}
        </if>
    </select>
    <select id="selectScoreOrderCnt" resultType="java.lang.Integer">
        select IFNULL(count(1), 0) from xzx_score_order
        where status in (3, 4)
        <if test="userId != null and userId != ''">
            and user_id=#{userId}
        </if>
    </select>
</mapper>