作者 shenhailong

修改水费充值逻辑

  1 +package com.sunyo.energy.location.dao;
  2 +
  3 +import com.sunyo.energy.location.model.WaterMeterSacc;
  4 +
  5 +public interface WaterMeterSaccMapper {
  6 + int deleteByPrimaryKey(String wmId);
  7 +
  8 + int insert(WaterMeterSacc record);
  9 +
  10 + int insertSelective(WaterMeterSacc record);
  11 +
  12 + WaterMeterSacc selectByPrimaryKey(String wmId);
  13 +
  14 + int updateByPrimaryKeySelective(WaterMeterSacc record);
  15 +
  16 + int updateByPrimaryKey(WaterMeterSacc record);
  17 +}
  1 +package com.sunyo.energy.location.model;
  2 +
  3 +import java.math.BigDecimal;
  4 +
  5 +public class WaterMeterSacc {
  6 + private String wmId;
  7 +
  8 + private String ardname;
  9 +
  10 + private BigDecimal unitPrice;
  11 +
  12 + private BigDecimal wmSacc;
  13 +
  14 + public String getWmId() {
  15 + return wmId;
  16 + }
  17 +
  18 + public void setWmId(String wmId) {
  19 + this.wmId = wmId == null ? null : wmId.trim();
  20 + }
  21 +
  22 + public String getArdname() {
  23 + return ardname;
  24 + }
  25 +
  26 + public void setArdname(String ardname) {
  27 + this.ardname = ardname == null ? null : ardname.trim();
  28 + }
  29 +
  30 + public BigDecimal getUnitPrice() {
  31 + return unitPrice;
  32 + }
  33 +
  34 + public void setUnitPrice(BigDecimal unitPrice) {
  35 + this.unitPrice = unitPrice;
  36 + }
  37 +
  38 + public BigDecimal getWmSacc() {
  39 + return wmSacc;
  40 + }
  41 +
  42 + public void setWmSacc(BigDecimal wmSacc) {
  43 + this.wmSacc = wmSacc;
  44 + }
  45 +}
@@ -6,9 +6,11 @@ import com.sunyo.energy.location.controller.response.ResultJson; @@ -6,9 +6,11 @@ import com.sunyo.energy.location.controller.response.ResultJson;
6 import com.sunyo.energy.location.dao.LocationMapper; 6 import com.sunyo.energy.location.dao.LocationMapper;
7 import com.sunyo.energy.location.dao.PayRecordsMapper; 7 import com.sunyo.energy.location.dao.PayRecordsMapper;
8 import com.sunyo.energy.location.dao.WaterMeterMapper; 8 import com.sunyo.energy.location.dao.WaterMeterMapper;
  9 +import com.sunyo.energy.location.dao.WaterMeterSaccMapper;
9 import com.sunyo.energy.location.demopay.QrDemo; 10 import com.sunyo.energy.location.demopay.QrDemo;
10 import com.sunyo.energy.location.model.PayRecords; 11 import com.sunyo.energy.location.model.PayRecords;
11 import com.sunyo.energy.location.model.WaterMeter; 12 import com.sunyo.energy.location.model.WaterMeter;
  13 +import com.sunyo.energy.location.model.WaterMeterSacc;
12 import com.sunyo.energy.location.service.WaterMeterService; 14 import com.sunyo.energy.location.service.WaterMeterService;
13 import com.sunyo.energy.location.utils.AllUtils; 15 import com.sunyo.energy.location.utils.AllUtils;
14 import com.sunyo.energy.location.utils.HttpsUtils; 16 import com.sunyo.energy.location.utils.HttpsUtils;
@@ -35,6 +37,10 @@ public class WaterMeterServiceImp implements WaterMeterService { @@ -35,6 +37,10 @@ public class WaterMeterServiceImp implements WaterMeterService {
35 37
36 @Autowired 38 @Autowired
37 private LocationMapper locationMapper; 39 private LocationMapper locationMapper;
  40 +
  41 + @Autowired
  42 + WaterMeterSaccMapper waterMeterSaccMapper;
  43 +
38 /** 44 /**
39 * 查询所有水表 45 * 查询所有水表
40 */ 46 */
@@ -130,9 +136,22 @@ public class WaterMeterServiceImp implements WaterMeterService { @@ -130,9 +136,22 @@ public class WaterMeterServiceImp implements WaterMeterService {
130 // 得到请求接口 返回值 和总水量 136 // 得到请求接口 返回值 和总水量
131 Map<String, Object> map = allWater(payFees, wmId); 137 Map<String, Object> map = allWater(payFees, wmId);
132 Map hashMap = JSON.parseObject(map.get("status").toString(), HashMap.class); 138 Map hashMap = JSON.parseObject(map.get("status").toString(), HashMap.class);
  139 + /**
  140 + * 外部充值水表成功
  141 + */
133 if ("0".equals(hashMap.get("state").toString())) { 142 if ("0".equals(hashMap.get("state").toString())) {
134 - int update = waterMeterMapper.update(wmId, map.get("allSacc").toString());  
135 - resultJson.setCode("200"); 143 + WaterMeterSacc waterMeterSacc = new WaterMeterSacc();
  144 + waterMeterSacc.setWmId(AllUtils.wmIdUtils(wmId));
  145 + waterMeterSacc.setWmSacc(new BigDecimal(String.valueOf(map.get("Add_sacc"))));
  146 + /**
  147 + * 修改本地累计充值量
  148 + */
  149 + int i = waterMeterSaccMapper.updateByPrimaryKeySelective(waterMeterSacc);
  150 + if (i > 0){
  151 + resultJson.setCode("200");
  152 + }else {
  153 + resultJson.setCode("203");
  154 + }
136 } else { 155 } else {
137 resultJson.setCode("203"); 156 resultJson.setCode("203");
138 } 157 }
@@ -217,8 +236,8 @@ public class WaterMeterServiceImp implements WaterMeterService { @@ -217,8 +236,8 @@ public class WaterMeterServiceImp implements WaterMeterService {
217 // 充值最后立方水数值 236 // 充值最后立方水数值
218 String s = AllUtils.nubmerDivision(payFees); 237 String s = AllUtils.nubmerDivision(payFees);
219 // 查询累计充值量 238 // 查询累计充值量
220 - WaterMeter realTime = findRealTime(wmId);  
221 - String allSacc = AllUtils.nubmerAdd(s, realTime.getWmSacc()); 239 + WaterMeterSacc waterMeterSacc = waterMeterSaccMapper.selectByPrimaryKey(AllUtils.wmIdUtils(wmId));
  240 + String allSacc = AllUtils.nubmerAdd(s, waterMeterSacc.getWmSacc());
222 Map<String, Object> datas = new HashMap<>(); 241 Map<String, Object> datas = new HashMap<>();
223 datas.put("MtId", wmId); 242 datas.put("MtId", wmId);
224 datas.put("Add_sacc", allSacc); 243 datas.put("Add_sacc", allSacc);
@@ -265,4 +284,5 @@ public class WaterMeterServiceImp implements WaterMeterService { @@ -265,4 +284,5 @@ public class WaterMeterServiceImp implements WaterMeterService {
265 284
266 return payRecords; 285 return payRecords;
267 } 286 }
  287 +
268 } 288 }
@@ -35,11 +35,10 @@ public class AllUtils { @@ -35,11 +35,10 @@ public class AllUtils {
35 35
36 36
37 //数字相加 参数1加参数2 37 //数字相加 参数1加参数2
38 - public static String nubmerAdd(String oneWmSacc, String s) { 38 + public static String nubmerAdd(String oneWmSacc, BigDecimal s) {
39 39
40 BigDecimal bigDecimal = new BigDecimal(oneWmSacc); 40 BigDecimal bigDecimal = new BigDecimal(oneWmSacc);
41 - BigDecimal bigDecimal1 = new BigDecimal(s);  
42 - String s1 = bigDecimal.add(bigDecimal1).toString(); 41 + String s1 = bigDecimal.add(s).toString();
43 return s1; 42 return s1;
44 } 43 }
45 44
@@ -56,5 +55,23 @@ public class AllUtils { @@ -56,5 +55,23 @@ public class AllUtils {
56 return merchantId + result; 55 return merchantId + result;
57 } 56 }
58 57
  58 + /**
  59 + * 处理水表编号加 '-' 问题
  60 + * @param replace 水表编号
  61 + * @return
  62 + */
  63 + public static String wmIdUtils(String replace) {
  64 + if (!replace.contains("-")){
  65 + String regex = "(.{2})";
  66 + replace = replace.replaceAll(regex, "$1-");
  67 + String substring = replace.substring(0, replace.length() - 1);
  68 +
  69 + return substring;
  70 + }else {
  71 + return replace;
  72 + }
  73 +
  74 + }
  75 +
59 76
60 } 77 }
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3 +<mapper namespace="com.sunyo.energy.location.dao.WaterMeterSaccMapper" >
  4 + <resultMap id="BaseResultMap" type="com.sunyo.energy.location.model.WaterMeterSacc" >
  5 + <id column="wm_id" property="wmId" jdbcType="VARCHAR" />
  6 + <result column="ardname" property="ardname" jdbcType="VARCHAR" />
  7 + <result column="unit_price" property="unitPrice" jdbcType="DECIMAL" />
  8 + <result column="wm_sacc" property="wmSacc" jdbcType="DECIMAL" />
  9 + </resultMap>
  10 + <sql id="Base_Column_List" >
  11 + wm_id, ardname, unit_price, wm_sacc
  12 + </sql>
  13 + <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
  14 + select
  15 + <include refid="Base_Column_List" />
  16 + from water_meter_sacc
  17 + where wm_id = #{wmId,jdbcType=VARCHAR}
  18 + </select>
  19 + <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
  20 + delete from water_meter_sacc
  21 + where wm_id = #{wmId,jdbcType=VARCHAR}
  22 + </delete>
  23 + <insert id="insert" parameterType="com.sunyo.energy.location.model.WaterMeterSacc" >
  24 + insert into water_meter_sacc (wm_id, ardname, unit_price,
  25 + wm_sacc)
  26 + values (#{wmId,jdbcType=VARCHAR}, #{ardname,jdbcType=VARCHAR}, #{unitPrice,jdbcType=DECIMAL},
  27 + #{wmSacc,jdbcType=DECIMAL})
  28 + </insert>
  29 + <insert id="insertSelective" parameterType="com.sunyo.energy.location.model.WaterMeterSacc" >
  30 + insert into water_meter_sacc
  31 + <trim prefix="(" suffix=")" suffixOverrides="," >
  32 + <if test="wmId != null" >
  33 + wm_id,
  34 + </if>
  35 + <if test="ardname != null" >
  36 + ardname,
  37 + </if>
  38 + <if test="unitPrice != null" >
  39 + unit_price,
  40 + </if>
  41 + <if test="wmSacc != null" >
  42 + wm_sacc,
  43 + </if>
  44 + </trim>
  45 + <trim prefix="values (" suffix=")" suffixOverrides="," >
  46 + <if test="wmId != null" >
  47 + #{wmId,jdbcType=VARCHAR},
  48 + </if>
  49 + <if test="ardname != null" >
  50 + #{ardname,jdbcType=VARCHAR},
  51 + </if>
  52 + <if test="unitPrice != null" >
  53 + #{unitPrice,jdbcType=DECIMAL},
  54 + </if>
  55 + <if test="wmSacc != null" >
  56 + #{wmSacc,jdbcType=DECIMAL},
  57 + </if>
  58 + </trim>
  59 + </insert>
  60 + <update id="updateByPrimaryKeySelective" parameterType="com.sunyo.energy.location.model.WaterMeterSacc" >
  61 + update water_meter_sacc
  62 + <set >
  63 + <if test="ardname != null" >
  64 + ardname = #{ardname,jdbcType=VARCHAR},
  65 + </if>
  66 + <if test="unitPrice != null" >
  67 + unit_price = #{unitPrice,jdbcType=DECIMAL},
  68 + </if>
  69 + <if test="wmSacc != null" >
  70 + wm_sacc = #{wmSacc,jdbcType=DECIMAL},
  71 + </if>
  72 + </set>
  73 + where wm_id = #{wmId,jdbcType=VARCHAR}
  74 + </update>
  75 + <update id="updateByPrimaryKey" parameterType="com.sunyo.energy.location.model.WaterMeterSacc" >
  76 + update water_meter_sacc
  77 + set ardname = #{ardname,jdbcType=VARCHAR},
  78 + unit_price = #{unitPrice,jdbcType=DECIMAL},
  79 + wm_sacc = #{wmSacc,jdbcType=DECIMAL}
  80 + where wm_id = #{wmId,jdbcType=VARCHAR}
  81 + </update>
  82 +</mapper>