Sfoglia il codice sorgente

修改用户下单重销售表获取数据

赵冬冬 4 anni fa
parent
commit
84c158ceef

+ 13 - 0
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/bo/ContributionBO.java

@@ -0,0 +1,13 @@
+package com.hcloud.microserver.h5.bo;
+
+import com.hcloud.microserver.h5.facade.carbon.entity.CustomerCarbonVal;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class ContributionBO extends CustomerCarbonVal {
+
+    private BigDecimal carbonAmount;
+
+}

+ 12 - 0
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/dao/CustomerCarbonValMapper.java

@@ -1,13 +1,17 @@
 package com.hcloud.microserver.h5.dao;
 
+import com.hcloud.microserver.h5.bo.ContributionBO;
 import com.hcloud.microserver.h5.facade.carbon.entity.CustomerCarbonVal;
 import com.hcloud.microserver.h5.facade.carbon.entity.CustomerCarbonValExample;
 import com.hcloud.microserver.h5.facade.carbon.forms.CustomerCarbonValRankForm;
+import org.apache.ibatis.annotations.MapKey;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
 import java.math.BigDecimal;
 import java.util.List;
+import java.util.Map;
+
 @Mapper
 public interface CustomerCarbonValMapper {
     int countByExample(CustomerCarbonValExample example);
@@ -46,4 +50,12 @@ public interface CustomerCarbonValMapper {
      * @return
      */
     BigDecimal selectCarbonAmountByCustomerId(@Param("guid") String guid);
+
+    @MapKey("tCustomerId")
+    Map<String, ContributionBO> totalcarbonVal(@Param("year") Integer year);
+
+    @MapKey("tCustomerId")
+    Map<String, ContributionBO> subcarbonVal(@Param("year") Integer year);
+
+    void insertSelectiveList(@Param("year") List<CustomerCarbonVal> list);
 }

+ 2 - 0
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/service/CustomerCarbonValService.java

@@ -16,4 +16,6 @@ public interface CustomerCarbonValService {
     CustomerCarbonValRankVO getCustomerCarbonValRankList(CustomerCarbonValRankForm form);
 
     BigDecimal selectCarbonAmountByCustomerId(String guid);
+
+    void contribution();
 }

+ 69 - 5
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/service/impl/CustomerCarbonValServiceImpl.java

@@ -1,14 +1,20 @@
 package com.hcloud.microserver.h5.service.impl;
 
+import com.hcloud.microserver.commoncore.util.UUIDUtils;
+import com.hcloud.microserver.h5.bo.ContributionBO;
 import com.hcloud.microserver.h5.dao.CustomerCarbonValMapper;
+import com.hcloud.microserver.h5.facade.carbon.entity.CustomerCarbonVal;
 import com.hcloud.microserver.h5.facade.carbon.forms.CustomerCarbonValRankForm;
 import com.hcloud.microserver.h5.facade.carbon.vo.CustomerCarbonValRankVO;
 import com.hcloud.microserver.h5.service.CustomerCarbonValService;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.StringUtils;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
-import java.util.List;
+import java.util.*;
 
 @Service
 public class CustomerCarbonValServiceImpl implements CustomerCarbonValService {
@@ -19,11 +25,11 @@ public class CustomerCarbonValServiceImpl implements CustomerCarbonValService {
     @Override
     public CustomerCarbonValRankVO getCustomerCarbonValRankList(CustomerCarbonValRankForm form) {
         List<CustomerCarbonValRankForm> list = customerCarbonValMapper.getCustomerCarbonValRankList(form);
-        if (list != null && list.size() > 0){
+        if (list != null && list.size() > 0) {
             CustomerCarbonValRankVO vo = new CustomerCarbonValRankVO();
             form.setCurrCustomerRank(true); //查询当前客户排名
             List<CustomerCarbonValRankForm> currCustomerRankList = customerCarbonValMapper.getCustomerCarbonValRankList(form);
-            if (currCustomerRankList != null && currCustomerRankList.size() > 0){
+            if (currCustomerRankList != null && currCustomerRankList.size() > 0) {
                 vo.setCurrCustomerRankForm(currCustomerRankList.get(0));
             }
             vo.setList(list);
@@ -31,8 +37,66 @@ public class CustomerCarbonValServiceImpl implements CustomerCarbonValService {
         }
         return null;
     }
+
+    @Override
+    public BigDecimal selectCarbonAmountByCustomerId(String guid) {
+        return customerCarbonValMapper.selectCarbonAmountByCustomerId(guid);
+    }
+
+    @Transactional
     @Override
-    public BigDecimal selectCarbonAmountByCustomerId(String guid){
-       return customerCarbonValMapper.selectCarbonAmountByCustomerId(guid);
+    public void contribution() {
+        Integer year = getYear();
+        //获取前3年的数据进行
+        Integer newYear = year - 4;
+        //获取总碳汇量
+        Map<String, ContributionBO> sumCarbonAmount = customerCarbonValMapper.totalcarbonVal(newYear);
+        //获取消去碳汇量
+        Map<String, ContributionBO> subcarbonVal = customerCarbonValMapper.subcarbonVal(newYear);
+
+        List<CustomerCarbonVal> customerCarbonValList=new ArrayList<>();
+        for (String tCustomerId : sumCarbonAmount.keySet()) {
+            //获取单独一个人的总碳汇量
+            BigDecimal totalcarbonAmount =new BigDecimal(0);
+            ContributionBO contributionRe = sumCarbonAmount.get(tCustomerId);
+            totalcarbonAmount = contributionRe.getCarbonAmount();
+            //获取使用的碳汇量
+            BigDecimal subCarbonAmount = new BigDecimal(0);
+            ContributionBO subcarbonValRe = subcarbonVal.get(tCustomerId);
+            //获取不到不赋值
+            if(!StringUtils.isEmpty(subcarbonValRe)){
+                subCarbonAmount = subcarbonValRe.getCarbonAmount();
+            }
+            //得到剩余碳汇量
+            BigDecimal subtract = totalcarbonAmount.subtract(subCarbonAmount);
+
+            CustomerCarbonVal customerCarbonVal=new CustomerCarbonVal();
+            BeanUtils.copyProperties(contributionRe,customerCarbonVal);
+            String guid = UUIDUtils.randomUUID();
+            customerCarbonVal.setGuid(guid);
+            customerCarbonVal.setCarbonVal(subtract);
+            //使用碳汇量
+            customerCarbonVal.setStatus(0);
+            //类型 1购买碳汇 2企业碳中和 3大型活动碳中和 4碳履约 5为重庆市碳排放量做贡献
+            customerCarbonVal.setType(5);
+            //来源表
+            customerCarbonVal.setTbGuid(guid);
+            //
+            customerCarbonVal.setYearTime(newYear);
+            customerCarbonVal.setTbName("t_customer_carbon_val");
+            //为重庆排放做贡献
+            customerCarbonVal.setRemarks("为重庆市碳排放量做贡献");
+            customerCarbonVal.setCreateUser(customerCarbonVal.gettCustomerId());
+            customerCarbonVal.setCreateTime(new Date());
+        }
+        if(customerCarbonValList.size()!=0){
+            customerCarbonValMapper.insertSelectiveList(customerCarbonValList);
+        }
+    }
+
+    public Integer getYear() {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(new Date());
+        return calendar.get(Calendar.YEAR);
     }
 }

+ 23 - 17
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/service/impl/OrderInfoServiceImpl.java

@@ -345,11 +345,11 @@ public class OrderInfoServiceImpl implements OrderInfoService {
     public int rollbackOrderInfo(String orderId) {
         GoodsOrderInfo goodsOrderInfo = goodsOrderInfoMapper.selectByPrimaryKey(orderId);
         Integer orderStatus = goodsOrderInfo.getOrderStatus();
-        if(orderStatus.intValue() !=1){
+        if (orderStatus.intValue() != 1) {
             throw new RuntimeException("该订单已支付款订单无法取消!");
         }
         Integer state = goodsOrderInfo.getState();
-        if(state.intValue() ==0){
+        if (state.intValue() == 0) {
             throw new RuntimeException("该订单为无效订单!");
         }
         goodsOrderInfo.setState(0);
@@ -365,7 +365,7 @@ public class OrderInfoServiceImpl implements OrderInfoService {
                 BigDecimal saleCarbon = bean.getSaleNum();
                 String goodsGuid = bean.getFkGoodsGuid();
                 GoodsSaleInfoForm goodsSaleInfoForm = orderSaleInfoService.getGoodsSaleInfoByGoodsId(goodsGuid);
-                if(!StringUtils.isEmpty(goodsSaleInfoForm)){
+                if (!StringUtils.isEmpty(goodsSaleInfoForm)) {
                     BigDecimal saledCarbonSkin = goodsSaleInfoForm.getSaledCarbonSkin().subtract(saleCarbon);
                     BigDecimal unSaleCarbonSkin = goodsSaleInfoForm.getUnsaledCarbonSkin().add(saleCarbon);
                     goodsSaleInfoForm.setSaledCarbonSkin(saledCarbonSkin);
@@ -532,7 +532,7 @@ public class OrderInfoServiceImpl implements OrderInfoService {
         if (customerInfo == null) {
             throw new RuntimeException("获取登陆信息失败");
         }
-        if(customerInfo.getIsCompany() == 1){
+        if (customerInfo.getIsCompany() == 1) {
             throw new RuntimeException("不是自然人无法购买商品!");
         }
         String customerId = customerInfo.getGuid();
@@ -548,10 +548,14 @@ public class OrderInfoServiceImpl implements OrderInfoService {
             String goodsId = good.getGoodsId();
             //购买的碳汇量
             BigDecimal carbonVal = good.getCarbonVal();
-            GoodsInfo goodsInfo = goodsInfoMapper.selectByPrimaryKey(goodsId);
-            String goodsInfoGuid = goodsInfo.getGuid();
+            //获取销售信息
+            GoodsSaleInfoForm goodsInfo = orderSaleInfoService.getGoodsSaleInfoByGoodsId(goodsId);
+            if (StringUtils.isEmpty(goodsInfo)) {
+                throw new RuntimeException("该商品不存在");
+            }
+            String goodsInfoGuid = goodsInfo.getFkGoodsGuid();
             //还剩碳汇量
-            BigDecimal carbonValRe = goodsInfo.getCarbonVal();
+            BigDecimal carbonValRe = goodsInfo.getUnsaledCarbonSkin();
             if (StringUtils.isEmpty(carbonValRe)) {
                 throw new RuntimeException("碳汇量不够了");
             }
@@ -559,7 +563,7 @@ public class OrderInfoServiceImpl implements OrderInfoService {
                 throw new RuntimeException("购买的碳汇量大于剩余的碳汇量");
             }
             //商品单价
-            BigDecimal price = goodsInfo.getPrice();
+            BigDecimal price = goodsInfo.getSalePrice();
             //单个碳汇总价
             BigDecimal sum = carbonVal.multiply(price);
 
@@ -571,7 +575,7 @@ public class OrderInfoServiceImpl implements OrderInfoService {
 //            goodsInfo.setCarbonVal(reCarbonVal);
 //            goodsInfoMapper.updateByPrimaryKeySelective(goodsInfo);
 
-            updateGoods(carbonVal,goodsInfoGuid);
+            updateGoods(carbonVal, goodsInfoGuid);
 
             //获取小订单
             addGoodsOrderDetail(customerId, orderId, dataList, good, goodsInfo, sum);
@@ -584,7 +588,7 @@ public class OrderInfoServiceImpl implements OrderInfoService {
         //新增小定单
         goodsOrderDetailMapper.batchSaveOrderDetailList(dataList);
 
-        String message = "order-" +orderId;
+        String message = "order-" + orderId;
         //延时消息队列
         messageService.send(MQConstant.HELLO_QUEUE_NAME, message, 60000);
         return goodsOrderInfo;
@@ -612,20 +616,21 @@ public class OrderInfoServiceImpl implements OrderInfoService {
         goodsOrderInfo.setOrderCarbonAmount(carbonTotal);
     }
 
-    private void addGoodsOrderDetail(String customerId, String orderId, List<GoodsOrderDetail> dataList, CreateOrderDetailFrom good, GoodsInfo goodsInfo, BigDecimal sum) {
+    private void addGoodsOrderDetail(String customerId, String orderId, List<GoodsOrderDetail> dataList, CreateOrderDetailFrom good, GoodsSaleInfoForm goodsInfo, BigDecimal sum) {
         GoodsOrderDetail goodsOrderDetail = new GoodsOrderDetail();
         goodsOrderDetail.setGuid(GetUUID.getUUID());
         goodsOrderDetail.setCreateUser(customerId);
         goodsOrderDetail.setCreateTime(new Date());
-        goodsOrderDetail.setGoodsPrice(goodsInfo.getPrice());
+        goodsOrderDetail.setGoodsPrice(goodsInfo.getSalePrice());
         //设置单个销售总价
         goodsOrderDetail.setAmount(sum);
         //设置谈汇量
         goodsOrderDetail.setSaleNum(good.getCarbonVal());
         //设置商品id
-        goodsOrderDetail.setFkGoodsGuid(goodsInfo.getGuid());
+        goodsOrderDetail.setFkGoodsGuid(goodsInfo.getFkGoodsGuid());
         //设置商品名称
-        goodsOrderDetail.setGoodsName(goodsInfo.getGoodsName());
+        GoodsInfo goods = goodsInfoMapper.selectByPrimaryKey(goodsInfo.getFkGoodsGuid());
+        goodsOrderDetail.setGoodsName(goods.getGoodsName());
         goodsOrderDetail.setFkOrderGuid(orderId);
         goodsOrderDetail.setState(1);
 
@@ -656,15 +661,16 @@ public class OrderInfoServiceImpl implements OrderInfoService {
         goodsPayOrder.setPayNo(orderNum);
         goodsPayOrderMapper.insertSelective(goodsPayOrder);
     }
+
     @Override
-    public void payOrder(String orderId){
+    public void payOrder(String orderId) {
         GoodsOrderInfo goodsOrderInfo = goodsOrderInfoMapper.selectByPrimaryKey(orderId);
         Integer orderStatus = goodsOrderInfo.getOrderStatus();
-        if(orderStatus.intValue() !=1){
+        if (orderStatus.intValue() != 1) {
             throw new RuntimeException("该订单已支付!");
         }
         Integer state = goodsOrderInfo.getState();
-        if(state.intValue() == 0){
+        if (state.intValue() == 0) {
             throw new RuntimeException("该订单为无效订单!");
         }
         goodsOrderInfo.setOrderStatus(2);

+ 23 - 0
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/task/AutoTask.java

@@ -0,0 +1,23 @@
+package com.hcloud.microserver.h5.task;
+
+import com.hcloud.microserver.h5.service.CustomerCarbonValService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+@EnableScheduling
+@Component
+@Slf4j
+public class AutoTask {
+
+    @Autowired
+    private CustomerCarbonValService customerCarbonValService;
+
+    @Scheduled(cron="*/15 * * * * ?")
+    public void process(){
+        log.info("autoTask ");
+        customerCarbonValService.contribution();
+    }
+}

+ 387 - 311
carbon-h5/carbon-h5-service/src/main/resources/com/hcloud/microserver/h5/dao/CustomerCarbonValMapper.xml

@@ -1,115 +1,119 @@
 <?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.hcloud.microserver.h5.dao.CustomerCarbonValMapper" >
-  <resultMap id="BaseResultMap" type="com.hcloud.microserver.h5.facade.carbon.entity.CustomerCarbonVal" >
-    <id column="guid" property="guid" jdbcType="CHAR" />
-    <result column="t_customer_id" property="tCustomerId" jdbcType="CHAR" />
-    <result column="t_customer_name" property="tCustomerName" jdbcType="VARCHAR" />
-    <result column="carbon_val" property="carbonVal" jdbcType="DECIMAL" />
-    <result column="status" property="status" jdbcType="INTEGER" />
-    <result column="type" property="type" jdbcType="INTEGER" />
-    <result column="tb_guid" property="tbGuid" jdbcType="CHAR" />
-    <result column="tb_name" property="tbName" jdbcType="CHAR" />
-    <result column="remarks" property="remarks" jdbcType="CHAR" />
-    <result column="year_time" property="yearTime" jdbcType="INTEGER" />
-    <result column="create_user" property="createUser" jdbcType="CHAR" />
-    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
-    <result column="update_user" property="updateUser" jdbcType="CHAR" />
-    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
-  </resultMap>
-  <sql id="Example_Where_Clause" >
-    <where >
-      <foreach collection="oredCriteria" item="criteria" separator="or" >
-        <if test="criteria.valid" >
-          <trim prefix="(" suffix=")" prefixOverrides="and" >
-            <foreach collection="criteria.criteria" item="criterion" >
-              <choose >
-                <when test="criterion.noValue" >
-                  and ${criterion.condition}
-                </when>
-                <when test="criterion.singleValue" >
-                  and ${criterion.condition} #{criterion.value}
-                </when>
-                <when test="criterion.betweenValue" >
-                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
-                </when>
-                <when test="criterion.listValue" >
-                  and ${criterion.condition}
-                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
-                    #{listItem}
-                  </foreach>
-                </when>
-              </choose>
+<mapper namespace="com.hcloud.microserver.h5.dao.CustomerCarbonValMapper">
+    <resultMap id="BaseResultMap" type="com.hcloud.microserver.h5.facade.carbon.entity.CustomerCarbonVal">
+        <id column="guid" property="guid" jdbcType="CHAR"/>
+        <result column="t_customer_id" property="tCustomerId" jdbcType="CHAR"/>
+        <result column="t_customer_name" property="tCustomerName" jdbcType="VARCHAR"/>
+        <result column="carbon_val" property="carbonVal" jdbcType="DECIMAL"/>
+        <result column="status" property="status" jdbcType="INTEGER"/>
+        <result column="type" property="type" jdbcType="INTEGER"/>
+        <result column="tb_guid" property="tbGuid" jdbcType="CHAR"/>
+        <result column="tb_name" property="tbName" jdbcType="CHAR"/>
+        <result column="remarks" property="remarks" jdbcType="CHAR"/>
+        <result column="year_time" property="yearTime" jdbcType="INTEGER"/>
+        <result column="create_user" property="createUser" jdbcType="CHAR"/>
+        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
+        <result column="update_user" property="updateUser" jdbcType="CHAR"/>
+        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
+    </resultMap>
+    <sql id="Example_Where_Clause">
+        <where>
+            <foreach collection="oredCriteria" item="criteria" separator="or">
+                <if test="criteria.valid">
+                    <trim prefix="(" suffix=")" prefixOverrides="and">
+                        <foreach collection="criteria.criteria" item="criterion">
+                            <choose>
+                                <when test="criterion.noValue">
+                                    and ${criterion.condition}
+                                </when>
+                                <when test="criterion.singleValue">
+                                    and ${criterion.condition} #{criterion.value}
+                                </when>
+                                <when test="criterion.betweenValue">
+                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
+                                </when>
+                                <when test="criterion.listValue">
+                                    and ${criterion.condition}
+                                    <foreach collection="criterion.value" item="listItem" open="(" close=")"
+                                             separator=",">
+                                        #{listItem}
+                                    </foreach>
+                                </when>
+                            </choose>
+                        </foreach>
+                    </trim>
+                </if>
             </foreach>
-          </trim>
-        </if>
-      </foreach>
-    </where>
-  </sql>
-  <sql id="Update_By_Example_Where_Clause" >
-    <where >
-      <foreach collection="example.oredCriteria" item="criteria" separator="or" >
-        <if test="criteria.valid" >
-          <trim prefix="(" suffix=")" prefixOverrides="and" >
-            <foreach collection="criteria.criteria" item="criterion" >
-              <choose >
-                <when test="criterion.noValue" >
-                  and ${criterion.condition}
-                </when>
-                <when test="criterion.singleValue" >
-                  and ${criterion.condition} #{criterion.value}
-                </when>
-                <when test="criterion.betweenValue" >
-                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
-                </when>
-                <when test="criterion.listValue" >
-                  and ${criterion.condition}
-                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
-                    #{listItem}
-                  </foreach>
-                </when>
-              </choose>
+        </where>
+    </sql>
+    <sql id="Update_By_Example_Where_Clause">
+        <where>
+            <foreach collection="example.oredCriteria" item="criteria" separator="or">
+                <if test="criteria.valid">
+                    <trim prefix="(" suffix=")" prefixOverrides="and">
+                        <foreach collection="criteria.criteria" item="criterion">
+                            <choose>
+                                <when test="criterion.noValue">
+                                    and ${criterion.condition}
+                                </when>
+                                <when test="criterion.singleValue">
+                                    and ${criterion.condition} #{criterion.value}
+                                </when>
+                                <when test="criterion.betweenValue">
+                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
+                                </when>
+                                <when test="criterion.listValue">
+                                    and ${criterion.condition}
+                                    <foreach collection="criterion.value" item="listItem" open="(" close=")"
+                                             separator=",">
+                                        #{listItem}
+                                    </foreach>
+                                </when>
+                            </choose>
+                        </foreach>
+                    </trim>
+                </if>
             </foreach>
-          </trim>
-        </if>
-      </foreach>
-    </where>
-  </sql>
-  <sql id="Base_Column_List" >
+        </where>
+    </sql>
+    <sql id="Base_Column_List">
     guid, t_customer_id, t_customer_name, carbon_val, status, type, tb_guid, tb_name, 
     remarks, year_time, create_user, create_time, update_user, update_time
   </sql>
-  <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.hcloud.microserver.h5.facade.carbon.entity.CustomerCarbonValExample" >
-    select
-    <if test="distinct" >
-      distinct
-    </if>
-    <include refid="Base_Column_List" />
-    from t_customer_carbon_val
-    <if test="_parameter != null" >
-      <include refid="Example_Where_Clause" />
-    </if>
-    <if test="orderByClause != null" >
-      order by ${orderByClause}
-    </if>
-  </select>
-  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
-    select 
-    <include refid="Base_Column_List" />
-    from t_customer_carbon_val
-    where guid = #{guid,jdbcType=CHAR}
-  </select>
-  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
+    <select id="selectByExample" resultMap="BaseResultMap"
+            parameterType="com.hcloud.microserver.h5.facade.carbon.entity.CustomerCarbonValExample">
+        select
+        <if test="distinct">
+            distinct
+        </if>
+        <include refid="Base_Column_List"/>
+        from t_customer_carbon_val
+        <if test="_parameter != null">
+            <include refid="Example_Where_Clause"/>
+        </if>
+        <if test="orderByClause != null">
+            order by ${orderByClause}
+        </if>
+    </select>
+    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String">
+        select
+        <include refid="Base_Column_List"/>
+        from t_customer_carbon_val
+        where guid = #{guid,jdbcType=CHAR}
+    </select>
+    <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
     delete from t_customer_carbon_val
     where guid = #{guid,jdbcType=CHAR}
   </delete>
-  <delete id="deleteByExample" parameterType="com.hcloud.microserver.h5.facade.carbon.entity.CustomerCarbonValExample" >
-    delete from t_customer_carbon_val
-    <if test="_parameter != null" >
-      <include refid="Example_Where_Clause" />
-    </if>
-  </delete>
-  <insert id="insert" parameterType="com.hcloud.microserver.h5.facade.carbon.entity.CustomerCarbonVal" >
+    <delete id="deleteByExample"
+            parameterType="com.hcloud.microserver.h5.facade.carbon.entity.CustomerCarbonValExample">
+        delete from t_customer_carbon_val
+        <if test="_parameter != null">
+            <include refid="Example_Where_Clause"/>
+        </if>
+    </delete>
+    <insert id="insert" parameterType="com.hcloud.microserver.h5.facade.carbon.entity.CustomerCarbonVal">
     insert into t_customer_carbon_val (guid, t_customer_id, t_customer_name, 
       carbon_val, status, type, 
       tb_guid, tb_name, remarks, year_time, 
@@ -121,219 +125,222 @@
       #{createUser,jdbcType=CHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateUser,jdbcType=CHAR}, 
       #{updateTime,jdbcType=TIMESTAMP})
   </insert>
-  <insert id="insertSelective" parameterType="com.hcloud.microserver.h5.facade.carbon.entity.CustomerCarbonVal" >
-    insert into t_customer_carbon_val
-    <trim prefix="(" suffix=")" suffixOverrides="," >
-      <if test="guid != null" >
-        guid,
-      </if>
-      <if test="tCustomerId != null" >
-        t_customer_id,
-      </if>
-      <if test="tCustomerName != null" >
-        t_customer_name,
-      </if>
-      <if test="carbonVal != null" >
-        carbon_val,
-      </if>
-      <if test="status != null" >
-        status,
-      </if>
-      <if test="type != null" >
-        type,
-      </if>
-      <if test="tbGuid != null" >
-        tb_guid,
-      </if>
-      <if test="tbName != null" >
-        tb_name,
-      </if>
-      <if test="remarks != null" >
-        remarks,
-      </if>
-      <if test="yearTime != null" >
-        year_time,
-      </if>
-      <if test="createUser != null" >
-        create_user,
-      </if>
-      <if test="createTime != null" >
-        create_time,
-      </if>
-      <if test="updateUser != null" >
-        update_user,
-      </if>
-      <if test="updateTime != null" >
-        update_time,
-      </if>
-    </trim>
-    <trim prefix="values (" suffix=")" suffixOverrides="," >
-      <if test="guid != null" >
-        #{guid,jdbcType=CHAR},
-      </if>
-      <if test="tCustomerId != null" >
-        #{tCustomerId,jdbcType=CHAR},
-      </if>
-      <if test="tCustomerName != null" >
-        #{tCustomerName,jdbcType=VARCHAR},
-      </if>
-      <if test="carbonVal != null" >
-        #{carbonVal,jdbcType=DECIMAL},
-      </if>
-      <if test="status != null" >
-        #{status,jdbcType=INTEGER},
-      </if>
-      <if test="type != null" >
-        #{type,jdbcType=INTEGER},
-      </if>
-      <if test="tbGuid != null" >
-        #{tbGuid,jdbcType=CHAR},
-      </if>
-      <if test="tbName != null" >
-        #{tbName,jdbcType=CHAR},
-      </if>
-      <if test="remarks != null" >
-        #{remarks,jdbcType=CHAR},
-      </if>
-      <if test="yearTime != null" >
-        #{yearTime,jdbcType=INTEGER},
-      </if>
-      <if test="createUser != null" >
-        #{createUser,jdbcType=CHAR},
-      </if>
-      <if test="createTime != null" >
-        #{createTime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="updateUser != null" >
-        #{updateUser,jdbcType=CHAR},
-      </if>
-      <if test="updateTime != null" >
-        #{updateTime,jdbcType=TIMESTAMP},
-      </if>
-    </trim>
-  </insert>
-  <select id="countByExample" parameterType="com.hcloud.microserver.h5.facade.carbon.entity.CustomerCarbonValExample" resultType="java.lang.Integer" >
-    select count(*) from t_customer_carbon_val
-    <if test="_parameter != null" >
-      <include refid="Example_Where_Clause" />
-    </if>
-  </select>
-  <update id="updateByExampleSelective" parameterType="map" >
-    update t_customer_carbon_val
-    <set >
-      <if test="record.guid != null" >
-        guid = #{record.guid,jdbcType=CHAR},
-      </if>
-      <if test="record.tCustomerId != null" >
+    <insert id="insertSelective" parameterType="com.hcloud.microserver.h5.facade.carbon.entity.CustomerCarbonVal">
+        insert into t_customer_carbon_val
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="guid != null">
+                guid,
+            </if>
+            <if test="tCustomerId != null">
+                t_customer_id,
+            </if>
+            <if test="tCustomerName != null">
+                t_customer_name,
+            </if>
+            <if test="carbonVal != null">
+                carbon_val,
+            </if>
+            <if test="status != null">
+                status,
+            </if>
+            <if test="type != null">
+                type,
+            </if>
+            <if test="tbGuid != null">
+                tb_guid,
+            </if>
+            <if test="tbName != null">
+                tb_name,
+            </if>
+            <if test="remarks != null">
+                remarks,
+            </if>
+            <if test="yearTime != null">
+                year_time,
+            </if>
+            <if test="createUser != null">
+                create_user,
+            </if>
+            <if test="createTime != null">
+                create_time,
+            </if>
+            <if test="updateUser != null">
+                update_user,
+            </if>
+            <if test="updateTime != null">
+                update_time,
+            </if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="guid != null">
+                #{guid,jdbcType=CHAR},
+            </if>
+            <if test="tCustomerId != null">
+                #{tCustomerId,jdbcType=CHAR},
+            </if>
+            <if test="tCustomerName != null">
+                #{tCustomerName,jdbcType=VARCHAR},
+            </if>
+            <if test="carbonVal != null">
+                #{carbonVal,jdbcType=DECIMAL},
+            </if>
+            <if test="status != null">
+                #{status,jdbcType=INTEGER},
+            </if>
+            <if test="type != null">
+                #{type,jdbcType=INTEGER},
+            </if>
+            <if test="tbGuid != null">
+                #{tbGuid,jdbcType=CHAR},
+            </if>
+            <if test="tbName != null">
+                #{tbName,jdbcType=CHAR},
+            </if>
+            <if test="remarks != null">
+                #{remarks,jdbcType=CHAR},
+            </if>
+            <if test="yearTime != null">
+                #{yearTime,jdbcType=INTEGER},
+            </if>
+            <if test="createUser != null">
+                #{createUser,jdbcType=CHAR},
+            </if>
+            <if test="createTime != null">
+                #{createTime,jdbcType=TIMESTAMP},
+            </if>
+            <if test="updateUser != null">
+                #{updateUser,jdbcType=CHAR},
+            </if>
+            <if test="updateTime != null">
+                #{updateTime,jdbcType=TIMESTAMP},
+            </if>
+        </trim>
+    </insert>
+
+    <select id="countByExample" parameterType="com.hcloud.microserver.h5.facade.carbon.entity.CustomerCarbonValExample"
+            resultType="java.lang.Integer">
+        select count(*) from t_customer_carbon_val
+        <if test="_parameter != null">
+            <include refid="Example_Where_Clause"/>
+        </if>
+    </select>
+    <update id="updateByExampleSelective" parameterType="map">
+        update t_customer_carbon_val
+        <set>
+            <if test="record.guid != null">
+                guid = #{record.guid,jdbcType=CHAR},
+            </if>
+            <if test="record.tCustomerId != null">
+                t_customer_id = #{record.tCustomerId,jdbcType=CHAR},
+            </if>
+            <if test="record.tCustomerName != null">
+                t_customer_name = #{record.tCustomerName,jdbcType=VARCHAR},
+            </if>
+            <if test="record.carbonVal != null">
+                carbon_val = #{record.carbonVal,jdbcType=DECIMAL},
+            </if>
+            <if test="record.status != null">
+                status = #{record.status,jdbcType=INTEGER},
+            </if>
+            <if test="record.type != null">
+                type = #{record.type,jdbcType=INTEGER},
+            </if>
+            <if test="record.tbGuid != null">
+                tb_guid = #{record.tbGuid,jdbcType=CHAR},
+            </if>
+            <if test="record.tbName != null">
+                tb_name = #{record.tbName,jdbcType=CHAR},
+            </if>
+            <if test="record.remarks != null">
+                remarks = #{record.remarks,jdbcType=CHAR},
+            </if>
+            <if test="record.yearTime != null">
+                year_time = #{record.yearTime,jdbcType=INTEGER},
+            </if>
+            <if test="record.createUser != null">
+                create_user = #{record.createUser,jdbcType=CHAR},
+            </if>
+            <if test="record.createTime != null">
+                create_time = #{record.createTime,jdbcType=TIMESTAMP},
+            </if>
+            <if test="record.updateUser != null">
+                update_user = #{record.updateUser,jdbcType=CHAR},
+            </if>
+            <if test="record.updateTime != null">
+                update_time = #{record.updateTime,jdbcType=TIMESTAMP},
+            </if>
+        </set>
+        <if test="_parameter != null">
+            <include refid="Update_By_Example_Where_Clause"/>
+        </if>
+    </update>
+    <update id="updateByExample" parameterType="map">
+        update t_customer_carbon_val
+        set guid = #{record.guid,jdbcType=CHAR},
         t_customer_id = #{record.tCustomerId,jdbcType=CHAR},
-      </if>
-      <if test="record.tCustomerName != null" >
         t_customer_name = #{record.tCustomerName,jdbcType=VARCHAR},
-      </if>
-      <if test="record.carbonVal != null" >
         carbon_val = #{record.carbonVal,jdbcType=DECIMAL},
-      </if>
-      <if test="record.status != null" >
         status = #{record.status,jdbcType=INTEGER},
-      </if>
-      <if test="record.type != null" >
         type = #{record.type,jdbcType=INTEGER},
-      </if>
-      <if test="record.tbGuid != null" >
         tb_guid = #{record.tbGuid,jdbcType=CHAR},
-      </if>
-      <if test="record.tbName != null" >
         tb_name = #{record.tbName,jdbcType=CHAR},
-      </if>
-      <if test="record.remarks != null" >
         remarks = #{record.remarks,jdbcType=CHAR},
-      </if>
-      <if test="record.yearTime != null" >
         year_time = #{record.yearTime,jdbcType=INTEGER},
-      </if>
-      <if test="record.createUser != null" >
         create_user = #{record.createUser,jdbcType=CHAR},
-      </if>
-      <if test="record.createTime != null" >
         create_time = #{record.createTime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="record.updateUser != null" >
         update_user = #{record.updateUser,jdbcType=CHAR},
-      </if>
-      <if test="record.updateTime != null" >
-        update_time = #{record.updateTime,jdbcType=TIMESTAMP},
-      </if>
-    </set>
-    <if test="_parameter != null" >
-      <include refid="Update_By_Example_Where_Clause" />
-    </if>
-  </update>
-  <update id="updateByExample" parameterType="map" >
-    update t_customer_carbon_val
-    set guid = #{record.guid,jdbcType=CHAR},
-      t_customer_id = #{record.tCustomerId,jdbcType=CHAR},
-      t_customer_name = #{record.tCustomerName,jdbcType=VARCHAR},
-      carbon_val = #{record.carbonVal,jdbcType=DECIMAL},
-      status = #{record.status,jdbcType=INTEGER},
-      type = #{record.type,jdbcType=INTEGER},
-      tb_guid = #{record.tbGuid,jdbcType=CHAR},
-      tb_name = #{record.tbName,jdbcType=CHAR},
-      remarks = #{record.remarks,jdbcType=CHAR},
-      year_time = #{record.yearTime,jdbcType=INTEGER},
-      create_user = #{record.createUser,jdbcType=CHAR},
-      create_time = #{record.createTime,jdbcType=TIMESTAMP},
-      update_user = #{record.updateUser,jdbcType=CHAR},
-      update_time = #{record.updateTime,jdbcType=TIMESTAMP}
-    <if test="_parameter != null" >
-      <include refid="Update_By_Example_Where_Clause" />
-    </if>
-  </update>
-  <update id="updateByPrimaryKeySelective" parameterType="com.hcloud.microserver.h5.facade.carbon.entity.CustomerCarbonVal" >
-    update t_customer_carbon_val
-    <set >
-      <if test="tCustomerId != null" >
-        t_customer_id = #{tCustomerId,jdbcType=CHAR},
-      </if>
-      <if test="tCustomerName != null" >
-        t_customer_name = #{tCustomerName,jdbcType=VARCHAR},
-      </if>
-      <if test="carbonVal != null" >
-        carbon_val = #{carbonVal,jdbcType=DECIMAL},
-      </if>
-      <if test="status != null" >
-        status = #{status,jdbcType=INTEGER},
-      </if>
-      <if test="type != null" >
-        type = #{type,jdbcType=INTEGER},
-      </if>
-      <if test="tbGuid != null" >
-        tb_guid = #{tbGuid,jdbcType=CHAR},
-      </if>
-      <if test="tbName != null" >
-        tb_name = #{tbName,jdbcType=CHAR},
-      </if>
-      <if test="remarks != null" >
-        remarks = #{remarks,jdbcType=CHAR},
-      </if>
-      <if test="yearTime != null" >
-        year_time = #{yearTime,jdbcType=INTEGER},
-      </if>
-      <if test="createUser != null" >
-        create_user = #{createUser,jdbcType=CHAR},
-      </if>
-      <if test="createTime != null" >
-        create_time = #{createTime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="updateUser != null" >
-        update_user = #{updateUser,jdbcType=CHAR},
-      </if>
-      <if test="updateTime != null" >
-        update_time = #{updateTime,jdbcType=TIMESTAMP},
-      </if>
-    </set>
-    where guid = #{guid,jdbcType=CHAR}
-  </update>
-  <update id="updateByPrimaryKey" parameterType="com.hcloud.microserver.h5.facade.carbon.entity.CustomerCarbonVal" >
+        update_time = #{record.updateTime,jdbcType=TIMESTAMP}
+        <if test="_parameter != null">
+            <include refid="Update_By_Example_Where_Clause"/>
+        </if>
+    </update>
+    <update id="updateByPrimaryKeySelective"
+            parameterType="com.hcloud.microserver.h5.facade.carbon.entity.CustomerCarbonVal">
+        update t_customer_carbon_val
+        <set>
+            <if test="tCustomerId != null">
+                t_customer_id = #{tCustomerId,jdbcType=CHAR},
+            </if>
+            <if test="tCustomerName != null">
+                t_customer_name = #{tCustomerName,jdbcType=VARCHAR},
+            </if>
+            <if test="carbonVal != null">
+                carbon_val = #{carbonVal,jdbcType=DECIMAL},
+            </if>
+            <if test="status != null">
+                status = #{status,jdbcType=INTEGER},
+            </if>
+            <if test="type != null">
+                type = #{type,jdbcType=INTEGER},
+            </if>
+            <if test="tbGuid != null">
+                tb_guid = #{tbGuid,jdbcType=CHAR},
+            </if>
+            <if test="tbName != null">
+                tb_name = #{tbName,jdbcType=CHAR},
+            </if>
+            <if test="remarks != null">
+                remarks = #{remarks,jdbcType=CHAR},
+            </if>
+            <if test="yearTime != null">
+                year_time = #{yearTime,jdbcType=INTEGER},
+            </if>
+            <if test="createUser != null">
+                create_user = #{createUser,jdbcType=CHAR},
+            </if>
+            <if test="createTime != null">
+                create_time = #{createTime,jdbcType=TIMESTAMP},
+            </if>
+            <if test="updateUser != null">
+                update_user = #{updateUser,jdbcType=CHAR},
+            </if>
+            <if test="updateTime != null">
+                update_time = #{updateTime,jdbcType=TIMESTAMP},
+            </if>
+        </set>
+        where guid = #{guid,jdbcType=CHAR}
+    </update>
+    <update id="updateByPrimaryKey" parameterType="com.hcloud.microserver.h5.facade.carbon.entity.CustomerCarbonVal">
     update t_customer_carbon_val
     set t_customer_id = #{tCustomerId,jdbcType=CHAR},
       t_customer_name = #{tCustomerName,jdbcType=VARCHAR},
@@ -351,9 +358,10 @@
     where guid = #{guid,jdbcType=CHAR}
   </update>
 
-  <select id="getCustomerCarbonValRankList" parameterType="com.hcloud.microserver.h5.facade.carbon.forms.CustomerCarbonValRankForm"
-      resultType="com.hcloud.microserver.h5.facade.carbon.forms.CustomerCarbonValRankForm">
-      SELECT obj.* from (SELECT @rownum := @rownum + 1 AS rank,tmp.t_customer_id AS customerId,tmp.carbonVal
+    <select id="getCustomerCarbonValRankList"
+            parameterType="com.hcloud.microserver.h5.facade.carbon.forms.CustomerCarbonValRankForm"
+            resultType="com.hcloud.microserver.h5.facade.carbon.forms.CustomerCarbonValRankForm">
+        SELECT obj.* from (SELECT @rownum := @rownum + 1 AS rank,tmp.t_customer_id AS customerId,tmp.carbonVal
         ,IFNULL(c.customer_name,c.nick_name) AS customerName,c.head_image AS headImage
         FROM (SELECT @rownum := 0) r,(SELECT a.t_customer_id,SUM(a.carbon_val) AS carbonVal
         FROM t_customer_carbon_val a
@@ -361,20 +369,20 @@
         WHERE a.year_time BETWEEN YEAR(DATE_SUB(NOW(),INTERVAL 3 YEAR)) AND YEAR(NOW())
         AND a.type = 1
         <if test="type != null and type == 1">
-          AND b.customer_type = 1
+            AND b.customer_type = 1
         </if>
         <if test="type != null and type == 2">
-          AND b.customer_type != 1
+            AND b.customer_type != 1
         </if>
         GROUP BY t_customer_id
         ) tmp
         LEFT JOIN t_customer_info c ON tmp.t_customer_id = c.guid
         ORDER BY tmp.carbonVal DESC
-      ) obj WHERE 1 = 1
+        ) obj WHERE 1 = 1
         <if test="customerId != null and isCurrCustomerRank != null and isCurrCustomerRank == true">
-          AND obj.CustomerId = #{customerId}
+            AND obj.CustomerId = #{customerId}
         </if>
-  </select>
+    </select>
     <select id="selectCarbonAmountByCustomerId" resultType="java.math.BigDecimal">
         SELECT
             SUM(a.carbon_val)
@@ -383,4 +391,72 @@
         WHERE
             a.t_customer_id = #{guid}
     </select>
+    <select id="totalcarbonVal" resultType="com.hcloud.microserver.h5.bo.ContributionBO">
+     SELECT
+        a.t_customer_id AS tCustomerId,
+        a.t_customer_name AS tCustomerName,
+        IFNULL(SUM(a.carbon_val), 0) AS carbonAmount,
+        a.year_time AS yearTime
+      FROM
+      t_customer_carbon_val a
+      WHERE
+      a.year_time <![CDATA[=]]> #{year}
+      AND a.`status` = 1
+      GROUP BY
+      a.t_customer_id
+    </select>
+    <select id="subcarbonVal" resultType="com.hcloud.microserver.h5.bo.ContributionBO">
+     SELECT
+        a.t_customer_id AS tCustomerId,
+        a.t_customer_name AS tCustomerName,
+        IFNULL(SUM(a.carbon_val), 0) AS carbonAmount,
+        a.year_time AS yearTime
+      FROM
+      t_customer_carbon_val a
+      WHERE
+      a.year_time <![CDATA[=]]> #{year}
+      AND a.`status` = 0
+      GROUP BY
+      a.t_customer_id
+    </select>
+
+    <insert id="insertSelectiveList">
+        INSERT INTO `t_customer_carbon_val` (
+            `guid`,
+            `t_customer_id`,
+            `t_customer_name`,
+            `carbon_val`,
+            `status`,
+            `type`,
+            `tb_guid`,
+            `tb_name`,
+            `remarks`,
+            `year_time`,
+            `create_user`,
+            `create_time`,
+            `update_user`,
+            `update_time`
+        )
+        VALUES
+        <foreach collection="list" item="item" index="index" separator=",">
+            (
+            #{item.guid},
+            #{item.tCustomerId},
+            #{item.tCustomerName},
+            #{item.carbonVal},
+            #{item.status},
+            #{item.type},
+            #{item.tbGuid},
+            #{item.tbName},
+            #{item.remarks},
+            #{item.yearTime},
+            #{item.createUser},
+            #{item.createTime},
+            #{item.updateUser},
+            #{item.updateTime}
+            )
+        </foreach>
+
+
+    </insert>
 </mapper>

+ 1 - 1
sql/表结构变化语句/更新sql.sql

@@ -6,7 +6,7 @@ ALTER TABLE `t_goods_info` MODIFY COLUMN  `is_sale` int(11) DEFAULT NULL COMMENT
 ALTER TABLE `t_goods_order_info` MODIFY COLUMN `state` int(11) DEFAULT NULL COMMENT '记录状态 0无效 1有效';
 
 #修改证书表 state 字段备注
-ALTER TABLE `t_goods_credential_info` MODIFY COLUMN `state` int(11) DEFAULT NULL COMMENT '类型 1购买碳汇';
+ALTER TABLE `t_goods_credential_info` MODIFY COLUMN `state` int(11) DEFAULT NULL COMMENT '类型 1 购买碳汇';
 
 #新增企业类型表 lym
 CREATE TABLE `t_customer_company_type` (