Helius
2021-06-30 3770d2aeba14f7aed10180283dd8cb18552da377
modify
1 files added
6 files modified
89 ■■■■■ changed files
gc-shop/src/main/java/com/xzx/gc/shop/controller/ApiOrderController.java 11 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/mapper/ScoreDetailsMapper.java 3 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/mapper/ScoreOrderMapper.java 3 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/service/OrderService.java 19 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/vo/StatisticsVo.java 30 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/resources/mapper/shop/ScoreDetailsMapper.xml 6 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/resources/mapper/shop/ScoreOrderMapper.xml 17 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/controller/ApiOrderController.java
@@ -8,6 +8,7 @@
import com.xzx.gc.shop.dto.AddGoodsOrderDto;
import com.xzx.gc.shop.dto.XcxOrderListDto;
import com.xzx.gc.shop.service.OrderService;
import com.xzx.gc.shop.vo.StatisticsVo;
import com.xzx.gc.shop.vo.XcxOrderDetailsVo;
import com.xzx.gc.shop.vo.XcxOrderListVo;
import io.swagger.annotations.Api;
@@ -16,10 +17,7 @@
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
@@ -79,4 +77,9 @@
    }
    @ApiOperation("首页统计")
    @GetMapping(value = "/order/statistics")
    public JsonResult<StatisticsVo> orderStatistics(HttpServletRequest request) {
        return JsonResult.success(orderService.orderStatistics(getUserId(request)));
    }
}
gc-shop/src/main/java/com/xzx/gc/shop/mapper/ScoreDetailsMapper.java
@@ -8,6 +8,7 @@
import com.xzx.gc.util.GcMapper;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.List;
public interface ScoreDetailsMapper extends GcMapper<ScoreDetails> {
@@ -15,4 +16,6 @@
    List<QueryScoreDetailsListVo> queryScoreDetailsList(@Param("record") QueryScoreDetailsListDto model);
    List<XcxScoreDetailsVo> selectXcxScoreDetailsList(@Param("record") XcxScoreDetailsDto xcxScoreDetailsDto);
    BigDecimal selectTotalScoreByUserId(@Param("userId") String userId, @Param("type") Integer type);
}
gc-shop/src/main/java/com/xzx/gc/shop/mapper/ScoreOrderMapper.java
@@ -11,6 +11,7 @@
import java.util.Date;
import java.util.List;
import java.util.Map;
public interface ScoreOrderMapper extends GcMapper<ScoreOrder> {
@@ -25,4 +26,6 @@
    XcxOrderDetailsVo selectXcxOrderDetails(@Param("id") Long id);
    int updateOrderStatus(@Param("id") Long id, @Param("status") Integer status, @Param("userId") String userId);
    Map<String, Object> selectOrderStastics(@Param("userId") String userId);
}
gc-shop/src/main/java/com/xzx/gc/shop/service/OrderService.java
@@ -382,4 +382,23 @@
            }
        }
    }
    public StatisticsVo orderStatistics(String userId) {
        BigDecimal score = scoreDetailsMapper.selectTotalScoreByUserId(userId, ScoreDetails.SCORE_TYPE_EXCHANGE);
        Map<String, Object> userData = scoreOrderMapper.selectOrderStastics(userId);
        Map<String, Object> allData = scoreOrderMapper.selectOrderStastics(null);
        StatisticsVo statisticsVo = new StatisticsVo();
        statisticsVo.setScore(score);
        BigDecimal userPrice = (BigDecimal) userData.get("totalPrice");
        statisticsVo.setReduceCarbon(userPrice.divide(BigDecimal.TEN, 2, BigDecimal.ROUND_DOWN));
        statisticsVo.setOrderCnt(Integer.parseInt(userData.get("totalOrder").toString()));
        BigDecimal totalPrice = (BigDecimal) allData.get("totalPrice");
        statisticsVo.setTotalReduceCarbon(totalPrice.divide(BigDecimal.TEN, 2, BigDecimal.ROUND_DOWN));
        statisticsVo.setTotalOrderCnt(Integer.parseInt(allData.get("totalOrder").toString()));
        statisticsVo.setTotalBuyCnt(Integer.parseInt(allData.get("totalBuy").toString()));
        return statisticsVo;
    }
}
gc-shop/src/main/java/com/xzx/gc/shop/vo/StatisticsVo.java
New file
@@ -0,0 +1,30 @@
package com.xzx.gc.shop.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
@Data
@ApiModel(value = "StatisticsVo", description = "统计")
public class StatisticsVo {
    @ApiModelProperty(value = "个人参与次数")
    private Integer orderCnt;
    @ApiModelProperty(value = "获得积分")
    private BigDecimal score;
    @ApiModelProperty(value = "减少碳排放量")
    private BigDecimal reduceCarbon;
    @ApiModelProperty(value = "用户参与次数")
    private Integer totalOrderCnt;
    @ApiModelProperty(value = "积分兑换次数")
    private Integer totalBuyCnt;
    @ApiModelProperty(value = "总减少排放量")
    private BigDecimal totalReduceCarbon;
}
gc-shop/src/main/resources/mapper/shop/ScoreDetailsMapper.xml
@@ -35,4 +35,10 @@
        where user_id=#{record.userId}
        order by id desc
    </select>
    <select id="selectTotalScoreByUserId" resultType="java.math.BigDecimal">
        select sum(change_score)
        from xzx_score_details
        where user_id=#{userId} and type=#{type}
    </select>
</mapper>
gc-shop/src/main/resources/mapper/shop/ScoreOrderMapper.xml
@@ -82,4 +82,21 @@
        set status=#{status}
        where id=#{id} and user_id=#{userId}
    </update>
    <select id="selectOrderStastics" resultType="java.util.Map">
        select
            IFNULL(count(1), 0) totalBuy,
            IFNULL(sum(IFNULL(total_price,0)),0) totalPrice,
            (
                select IFNULL(count(1),0) from xzx_jhy_order where status = 3
                <if test="userId != null and userId != ''">
                    and user_id=#{userId}
                </if>
            ) totalOrder
        from xzx_score_order
        where status=3
        <if test="userId != null and userId != ''">
            and user_id=#{userId}
        </if>
    </select>
</mapper>