作者 shenhailong

完善 修改水表编号 逻辑

1 package com.sunyo.energy.location.controller; 1 package com.sunyo.energy.location.controller;
2 2
3 import com.github.pagehelper.PageInfo; 3 import com.github.pagehelper.PageInfo;
4 -import com.sunyo.energy.location.controller.response.ResultJson;  
5 import com.sunyo.energy.location.model.ElectricityInfo; 4 import com.sunyo.energy.location.model.ElectricityInfo;
6 import com.sunyo.energy.location.service.EeInfoService; 5 import com.sunyo.energy.location.service.EeInfoService;
7 import io.swagger.annotations.ApiOperation; 6 import io.swagger.annotations.ApiOperation;
8 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.stereotype.Component; 8 import org.springframework.stereotype.Component;
10 -import org.springframework.stereotype.Controller;  
11 import org.springframework.web.bind.annotation.RequestMapping; 9 import org.springframework.web.bind.annotation.RequestMapping;
12 import org.springframework.web.bind.annotation.RequestParam; 10 import org.springframework.web.bind.annotation.RequestParam;
13 import org.springframework.web.bind.annotation.ResponseBody; 11 import org.springframework.web.bind.annotation.ResponseBody;
14 -import sun.jvm.hotspot.debugger.Page;  
15 -  
16 -import java.util.List;  
17 12
18 /** 13 /**
19 * @author shenhailong 14 * @author shenhailong
@@ -6,24 +6,18 @@ import com.github.pagehelper.PageHelper; @@ -6,24 +6,18 @@ import com.github.pagehelper.PageHelper;
6 import com.github.pagehelper.PageInfo; 6 import com.github.pagehelper.PageInfo;
7 import com.sunyo.energy.location.controller.response.ResultJson; 7 import com.sunyo.energy.location.controller.response.ResultJson;
8 import com.sunyo.energy.location.dao.LocationMapper; 8 import com.sunyo.energy.location.dao.LocationMapper;
9 -import com.sunyo.energy.location.dao.WaterMeterMapper;  
10 import com.sunyo.energy.location.dao.WaterMeterSaccMapper; 9 import com.sunyo.energy.location.dao.WaterMeterSaccMapper;
11 import com.sunyo.energy.location.model.Location; 10 import com.sunyo.energy.location.model.Location;
12 import com.sunyo.energy.location.model.WaterMeter; 11 import com.sunyo.energy.location.model.WaterMeter;
13 import com.sunyo.energy.location.model.WaterMeterSacc; 12 import com.sunyo.energy.location.model.WaterMeterSacc;
14 import com.sunyo.energy.location.service.WaterMeterService; 13 import com.sunyo.energy.location.service.WaterMeterService;
15 -import com.sunyo.energy.location.utils.AllUtils;  
16 import com.sunyo.energy.location.utils.HttpsUtils; 14 import com.sunyo.energy.location.utils.HttpsUtils;
17 import io.swagger.annotations.ApiOperation; 15 import io.swagger.annotations.ApiOperation;
18 -import lombok.extern.log4j.Log4j;  
19 import lombok.extern.slf4j.Slf4j; 16 import lombok.extern.slf4j.Slf4j;
20 -import org.apache.ibatis.annotations.Param;  
21 -import org.omg.CORBA.OBJECT_NOT_EXIST;  
22 import org.springframework.beans.factory.annotation.Autowired; 17 import org.springframework.beans.factory.annotation.Autowired;
23 import org.springframework.util.StringUtils; 18 import org.springframework.util.StringUtils;
24 import org.springframework.web.bind.annotation.*; 19 import org.springframework.web.bind.annotation.*;
25 20
26 -import java.math.BigDecimal;  
27 import java.util.HashMap; 21 import java.util.HashMap;
28 import java.util.List; 22 import java.util.List;
29 import java.util.Map; 23 import java.util.Map;
@@ -126,29 +120,37 @@ public class LocationController { @@ -126,29 +120,37 @@ public class LocationController {
126 public ResultJson editLocation(@RequestBody Location location) throws Exception { 120 public ResultJson editLocation(@RequestBody Location location) throws Exception {
127 121
128 ResultJson resultJson = new ResultJson(); 122 ResultJson resultJson = new ResultJson();
  123 + // 旧表 表号
129 String wmId = locationMapper.findWmId(location.getAdrname()); 124 String wmId = locationMapper.findWmId(location.getAdrname());
  125 + // 水表 累计充值量记录表
130 WaterMeterSacc waterMeterSacc = new WaterMeterSacc(); 126 WaterMeterSacc waterMeterSacc = new WaterMeterSacc();
131 - waterMeterSacc.setOrderWmId(wmId);  
132 - waterMeterSacc.setWmId(location.getWmid());  
133 - // 查询旧表实施数据 127 + // 判断是否存在 存在修改楼层 不存在修改水表
  128 + if (!StringUtils.isEmpty(wmId)){
  129 + // 修改 房间号
  130 + int i1 = locationMapper.updateByPrimaryKeySelective(location);
  131 + log.info("楼层编辑:{}", i1);
  132 + }else {
  133 + // 查询旧表 实时数据
134 WaterMeter realTime = waterMeterService.findRealTime(wmId); 134 WaterMeter realTime = waterMeterService.findRealTime(wmId);
135 - // 计算旧表余量 新表累计充值量 = 旧表余量  
136 -// String newWmIdSacc = AllUtils.nubmerSubtraction(realTime.getWmSacc(), realTime.getWmLacc());  
137 log.info("旧表累计充值量:{}",realTime.getWmSacc()); 135 log.info("旧表累计充值量:{}",realTime.getWmSacc());
138 -// waterMeterSacc.setWmSacc(new BigDecimal(newWmIdSacc));  
139 - // 充值新表水量 136 + // 充值新表
140 Map<String, Object> datas = new HashMap<>(); 137 Map<String, Object> datas = new HashMap<>();
141 - datas.put("MtId", wmId); 138 + datas.put("MtId", location.getWmid());
142 datas.put("Add_sacc", realTime.getWmSacc()); 139 datas.put("Add_sacc", realTime.getWmSacc());
143 - datas.put("Add_addmode", "2"); 140 + datas.put("Add_lacc", realTime.getWmLacc());
  141 + datas.put("Add_addmode", "3");
144 String status = HttpsUtils.httpRequest("http://123.56.159.203:8023/mtfmset/allWMadd", datas); 142 String status = HttpsUtils.httpRequest("http://123.56.159.203:8023/mtfmset/allWMadd", datas);
145 datas.put("status", status); 143 datas.put("status", status);
146 log.info("新表充值:{}",status); 144 log.info("新表充值:{}",status);
147 log.info("充值成功更新水表"); 145 log.info("充值成功更新水表");
148 - if (locationMapper.updateByPrimaryKeySelective(location) > 0 && waterMeterSaccMapper.updateWater(waterMeterSacc) > 0) { 146 + }
  147 + waterMeterSacc.setWmId(location.getWmid());
  148 + waterMeterSacc.setOrderWmId(wmId);
  149 + // 更新表号 累计充值量 记录表
  150 + if (waterMeterSaccMapper.updateWater(waterMeterSacc) > 0) {
149 log.info("更新成功"); 151 log.info("更新成功");
150 resultJson.setCode("200"); 152 resultJson.setCode("200");
151 - } else { 153 + }else {
152 resultJson.setCode("201"); 154 resultJson.setCode("201");
153 } 155 }
154 return resultJson; 156 return resultJson;
@@ -40,6 +40,9 @@ public interface LocationMapper { @@ -40,6 +40,9 @@ public interface LocationMapper {
40 40
41 String eeId(String roomNumber); 41 String eeId(String roomNumber);
42 42
  43 + int adrNameWmId(@Param(value = "adrName") String adrName,
  44 + @Param(value = "wmId") String wmId);
  45 +
43 int editEeId(@Param(value = "name") String name, 46 int editEeId(@Param(value = "name") String name,
44 @Param(value = "deviceId") String deviceId); 47 @Param(value = "deviceId") String deviceId);
45 48
@@ -88,6 +88,10 @@ @@ -88,6 +88,10 @@
88 select ee_id from location where adrname = #{value} 88 select ee_id from location where adrname = #{value}
89 </select> 89 </select>
90 90
  91 + <select id="adrNameWmId" parameterType="string" resultType="int">
  92 + select count(*) from location where adrname = #{adrName} and wmId = #{wmId}
  93 + </select>
  94 +
91 <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"> 95 <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
92 delete from location 96 delete from location
93 where id = #{id,jdbcType=INTEGER} 97 where id = #{id,jdbcType=INTEGER}
@@ -87,10 +87,7 @@ @@ -87,10 +87,7 @@
87 update water_meter_sacc 87 update water_meter_sacc
88 <set > 88 <set >
89 <if test="wmId != null" > 89 <if test="wmId != null" >
90 - wm_id = #{wmId,jdbcType=VARCHAR},  
91 - </if>  
92 - <if test="wmSacc != null" >  
93 - wm_sacc = #{wmSacc,jdbcType=VARCHAR} 90 + wm_id = #{wmId,jdbcType=VARCHAR}
94 </if> 91 </if>
95 </set> 92 </set>
96 where wm_id = #{orderWmId,jdbcType=VARCHAR} 93 where wm_id = #{orderWmId,jdbcType=VARCHAR}