Преглед изворни кода

新增个人碳汇量统计和证书生成去除最后一个逗号

赵冬冬 пре 4 година
родитељ
комит
1e08c4c436

+ 7 - 1
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/controller/web/CustomerController.java

@@ -5,6 +5,7 @@ import com.hcloud.microserver.h5.forms.CompanyValidateForm;
 import com.hcloud.microserver.h5.forms.LoginForm;
 import com.hcloud.microserver.h5.forms.PersonValidateForm;
 import com.hcloud.microserver.h5.forms.SmallCustomer;
+import com.hcloud.microserver.h5.service.CustomerCarbonValService;
 import com.hcloud.microserver.h5.service.CustomerCompanyInfoService;
 import com.hcloud.microserver.h5.service.CustomerInfoService;
 import com.hcloud.microserver.h5.service.CustomerService;
@@ -24,6 +25,7 @@ import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.data.redis.core.ValueOperations;
 import org.springframework.web.bind.annotation.*;
 
+import java.math.BigDecimal;
 import java.security.Principal;
 import java.util.Date;
 import java.util.HashMap;
@@ -78,6 +80,9 @@ public class CustomerController extends BaseController {
         return responseResultSuccess();
     }
 
+    @Autowired
+    private CustomerCarbonValService customerCarbonValService;
+
     @ApiOperation(value = "获取爱心用户登录信息", notes = "获取爱心用户登录信息,通过token")
     @ApiResponse(code = 0, message = "查询成功")
     @GetMapping("/getCustomerByToken")
@@ -87,7 +92,8 @@ public class CustomerController extends BaseController {
             responseError(new ResultVO(ResultEnum.UNAUTHORIZED));
         }
         CustomerInfoForm customerInfo = customerService.getCurrentMember();
-        Integer isCompany = customerInfo.getIsCompany();
+        BigDecimal  carbonAmount = customerCarbonValService.selectCarbonAmountByCustomerId(customerInfo.getGuid());
+        customerInfo.setCarbonAmount(carbonAmount);
 
         return responseResultSuccess(customerInfo);
     }

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

@@ -6,6 +6,7 @@ import com.hcloud.microserver.h5.facade.carbon.forms.CustomerCarbonValRankForm;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.math.BigDecimal;
 import java.util.List;
 @Mapper
 public interface CustomerCarbonValMapper {
@@ -38,4 +39,11 @@ public interface CustomerCarbonValMapper {
      * @return
      */
     List<CustomerCarbonValRankForm> getCustomerCarbonValRankList(CustomerCarbonValRankForm form);
+
+    /**
+     * 统计个人总碳汇量
+     * @param guid
+     * @return
+     */
+    BigDecimal selectCarbonAmountByCustomerId(@Param("guid") String guid);
 }

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

@@ -3,6 +3,8 @@ package com.hcloud.microserver.h5.service;
 import com.hcloud.microserver.h5.facade.carbon.forms.CustomerCarbonValRankForm;
 import com.hcloud.microserver.h5.facade.carbon.vo.CustomerCarbonValRankVO;
 
+import java.math.BigDecimal;
+
 public interface CustomerCarbonValService {
 
     /**
@@ -12,4 +14,6 @@ public interface CustomerCarbonValService {
      * @return
      */
     CustomerCarbonValRankVO getCustomerCarbonValRankList(CustomerCarbonValRankForm form);
+
+    BigDecimal selectCarbonAmountByCustomerId(String guid);
 }

+ 42 - 22
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/service/impl/CredentialInfoServiceImpl.java

@@ -13,6 +13,7 @@ import com.hcloud.microserver.h5.facade.carbon.entity.GoodsCredentialInfo;
 import com.hcloud.microserver.h5.facade.carbon.entity.GoodsOrderInfo;
 import com.hcloud.microserver.h5.facade.carbon.forms.GoodsCredentialInfoForm;
 import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
 
 import javax.annotation.Resource;
 import java.text.SimpleDateFormat;
@@ -40,7 +41,6 @@ public class CredentialInfoServiceImpl implements CredentialInfoService {
     private GoodsOrderInfoMapper goodsOrderInfoMapper;
 
 
-
     /**
      * 生成证书记录
      *
@@ -49,15 +49,15 @@ public class CredentialInfoServiceImpl implements CredentialInfoService {
      */
     @Override
     public int saveCredentialInfo(String orderId) {
-        if(null!=orderId && !"".equals(orderId)){
+        if (null != orderId && !"".equals(orderId)) {
             GoodsCredentialInfoForm goodsCredentialInfoForm = new GoodsCredentialInfoForm();
             //查询订单信息
             GoodsOrderInfo goodsOrderInfo = goodsOrderInfoMapper.selectByPrimaryKey(orderId);
             //查询农户信息
-            List<CredentialInfoBO> list =  goodsCredentialInfoMapper.getCredentialFarmerInfoByOrderId(orderId);
-           //获取最大证书最大编码
+            List<CredentialInfoBO> list = goodsCredentialInfoMapper.getCredentialFarmerInfoByOrderId(orderId);
+            //获取最大证书最大编码
             Integer currentNum = getCurrentCode();
-            String maxCode = BusinessCodeRule.notYearCodeRule(CODE_PREFIX,currentNum,15);
+            String maxCode = BusinessCodeRule.notYearCodeRule(CODE_PREFIX, currentNum, 15);
             goodsCredentialInfoForm.setFkOrderId(orderId);
             goodsCredentialInfoForm.setFkCustomerId(goodsOrderInfo.getFkCustomerGuid());
             goodsCredentialInfoForm.setBuyDate(new Date());
@@ -65,15 +65,31 @@ public class CredentialInfoServiceImpl implements CredentialInfoService {
             goodsCredentialInfoForm.setCredentialNo(maxCode);
             String farmerNames = "";
             String farmerAreas = "";
-            Integer farmerCount=0;
-            if(null!=list && list.size()>0){
-               for (CredentialInfoBO bo:list) {
-                   if(Objects.isNull(bo)){continue;}
-                   Integer temp = bo.getFarmerNum()==null?0:bo.getFarmerNum();
-                   farmerNames+=bo.getFarmerName()+",";
-                   farmerAreas+=bo.getFarmerVillage()+",";
-                   farmerCount+=temp;
-               }
+            Integer farmerCount = 0;
+            if (null != list && list.size() > 0) {
+                for (CredentialInfoBO bo : list) {
+                    if (Objects.isNull(bo)) {
+                        continue;
+                    }
+                    Integer temp = bo.getFarmerNum() == null ? 0 : bo.getFarmerNum();
+                    String farmerName = bo.getFarmerName();
+                    if (!StringUtils.isEmpty(farmerName)) {
+                        farmerNames += farmerName + ",";
+                    }
+                    String farmerVillage = bo.getFarmerVillage();
+                    if (!StringUtils.isEmpty(farmerVillage)) {
+                        farmerAreas += farmerVillage + ",";
+                    }
+                    farmerCount += temp;
+                }
+                //去除最后一个,号
+                if (farmerNames.length() > 0) {
+                    farmerNames = farmerNames.substring(0, farmerNames.length() - 1);
+                }
+                //去除最后一个,号
+                if (farmerAreas.length() > 0) {
+                    farmerAreas = farmerAreas.substring(0, farmerAreas.length() - 1);
+                }
                 goodsCredentialInfoForm.setFarmerNames(farmerNames);
                 goodsCredentialInfoForm.setProductAddress(farmerAreas);
                 goodsCredentialInfoForm.setFarmerCount(farmerCount);
@@ -87,13 +103,14 @@ public class CredentialInfoServiceImpl implements CredentialInfoService {
 
     /**
      * 分页查询用户证书信息
+     *
      * @param goodsCredentialInfoForm
      * @return
      */
     @Override
     public PageInfo searchCredentialByPage(GoodsCredentialInfoForm goodsCredentialInfoForm) {
         String customId = goodsCredentialInfoForm.getFkCustomerId();
-        PageHelper.startPage(goodsCredentialInfoForm.getPageNo(),goodsCredentialInfoForm.getPageSize());
+        PageHelper.startPage(goodsCredentialInfoForm.getPageNo(), goodsCredentialInfoForm.getPageSize());
         List<GoodsCredentialInfo> list = goodsCredentialInfoMapper.getCredentialInfoByCustomerId(customId);
         return new PageInfo(list);
     }
@@ -111,12 +128,15 @@ public class CredentialInfoServiceImpl implements CredentialInfoService {
 
     /**
      * 获取当前编码流水号的数字形式
+     *
      * @return
      */
-    private Integer getCurrentCode(){
+    private Integer getCurrentCode() {
         StringBuffer sbb = new StringBuffer();
         String maxCode = goodsCredentialInfoMapper.getMaxCode();
-        if(maxCode==null){return 500;}
+        if (maxCode == null) {
+            return 500;
+        }
         sbb.append(CODE_PREFIX);
         String currentNum = maxCode.substring(sbb.toString().length());
         return Integer.valueOf(currentNum);
@@ -132,7 +152,7 @@ public class CredentialInfoServiceImpl implements CredentialInfoService {
     public int save(GoodsCredentialInfoForm record) {
         record.setGuid(GetUUID.getUUID());
         record.setModifiedTime(new Date());
-        GoodsCredentialInfo goodsCredentialInfo = BeanCopyUtil.convertBean(record,GoodsCredentialInfo.class);
+        GoodsCredentialInfo goodsCredentialInfo = BeanCopyUtil.convertBean(record, GoodsCredentialInfo.class);
         return goodsCredentialInfoMapper.insert(goodsCredentialInfo);
     }
 
@@ -140,19 +160,19 @@ public class CredentialInfoServiceImpl implements CredentialInfoService {
     public int saveSelective(GoodsCredentialInfoForm record) {
         record.setGuid(GetUUID.getUUID());
         record.setModifiedTime(new Date());
-        GoodsCredentialInfo goodsCredentialInfo = BeanCopyUtil.convertBean(record,GoodsCredentialInfo.class);
+        GoodsCredentialInfo goodsCredentialInfo = BeanCopyUtil.convertBean(record, GoodsCredentialInfo.class);
         return goodsCredentialInfoMapper.insertSelective(goodsCredentialInfo);
     }
 
     @Override
     public GoodsCredentialInfoForm queryByPrimaryKey(String guid) {
         GoodsCredentialInfo goodsCredentialInfo = goodsCredentialInfoMapper.selectByPrimaryKey(guid);
-        return BeanCopyUtil.convertBean(goodsCredentialInfo,GoodsCredentialInfoForm.class);
+        return BeanCopyUtil.convertBean(goodsCredentialInfo, GoodsCredentialInfoForm.class);
     }
 
     @Override
     public int modifyByPrimaryKeySelective(GoodsCredentialInfoForm record) {
-        GoodsCredentialInfo goodsCredentialInfo = BeanCopyUtil.convertBean(record,GoodsCredentialInfo.class);
+        GoodsCredentialInfo goodsCredentialInfo = BeanCopyUtil.convertBean(record, GoodsCredentialInfo.class);
         return goodsCredentialInfoMapper.updateByPrimaryKeySelective(goodsCredentialInfo);
     }
 
@@ -164,7 +184,7 @@ public class CredentialInfoServiceImpl implements CredentialInfoService {
 
     @Override
     public int modifyByPrimaryKey(GoodsCredentialInfoForm record) {
-        GoodsCredentialInfo goodsCredentialInfo = BeanCopyUtil.convertBean(record,GoodsCredentialInfo.class);
+        GoodsCredentialInfo goodsCredentialInfo = BeanCopyUtil.convertBean(record, GoodsCredentialInfo.class);
         return goodsCredentialInfoMapper.updateByPrimaryKey(goodsCredentialInfo);
     }
 }

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

@@ -7,6 +7,7 @@ import com.hcloud.microserver.h5.service.CustomerCarbonValService;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
 import java.util.List;
 
 @Service
@@ -30,4 +31,8 @@ public class CustomerCarbonValServiceImpl implements CustomerCarbonValService {
         }
         return null;
     }
+    @Override
+    public BigDecimal selectCarbonAmountByCustomerId(String guid){
+       return customerCarbonValMapper.selectCarbonAmountByCustomerId(guid);
+    }
 }

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

@@ -375,4 +375,12 @@
           AND obj.CustomerId = #{customerId}
         </if>
   </select>
+    <select id="selectCarbonAmountByCustomerId" resultType="java.math.BigDecimal">
+        SELECT
+            SUM(a.carbon_val)
+        FROM
+            t_customer_carbon_val a
+        WHERE
+            a.t_customer_id = #{guid}
+    </select>
 </mapper>