作者 shenhailong

完善 修改水表编号 逻辑

package com.sunyo.energy.location.controller;
import com.github.pagehelper.PageInfo;
import com.sunyo.energy.location.controller.response.ResultJson;
import com.sunyo.energy.location.model.ElectricityInfo;
import com.sunyo.energy.location.service.EeInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.jvm.hotspot.debugger.Page;
import java.util.List;
/**
* @author shenhailong
... ...
... ... @@ -6,24 +6,18 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sunyo.energy.location.controller.response.ResultJson;
import com.sunyo.energy.location.dao.LocationMapper;
import com.sunyo.energy.location.dao.WaterMeterMapper;
import com.sunyo.energy.location.dao.WaterMeterSaccMapper;
import com.sunyo.energy.location.model.Location;
import com.sunyo.energy.location.model.WaterMeter;
import com.sunyo.energy.location.model.WaterMeterSacc;
import com.sunyo.energy.location.service.WaterMeterService;
import com.sunyo.energy.location.utils.AllUtils;
import com.sunyo.energy.location.utils.HttpsUtils;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.omg.CORBA.OBJECT_NOT_EXIST;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
... ... @@ -126,29 +120,37 @@ public class LocationController {
public ResultJson editLocation(@RequestBody Location location) throws Exception {
ResultJson resultJson = new ResultJson();
// 旧表 表号
String wmId = locationMapper.findWmId(location.getAdrname());
// 水表 累计充值量记录表
WaterMeterSacc waterMeterSacc = new WaterMeterSacc();
waterMeterSacc.setOrderWmId(wmId);
// 判断是否存在 存在修改楼层 不存在修改水表
if (!StringUtils.isEmpty(wmId)){
// 修改 房间号
int i1 = locationMapper.updateByPrimaryKeySelective(location);
log.info("楼层编辑:{}", i1);
}else {
// 查询旧表 实时数据
WaterMeter realTime = waterMeterService.findRealTime(wmId);
log.info("旧表累计充值量:{}",realTime.getWmSacc());
// 充值新表
Map<String, Object> datas = new HashMap<>();
datas.put("MtId", location.getWmid());
datas.put("Add_sacc", realTime.getWmSacc());
datas.put("Add_lacc", realTime.getWmLacc());
datas.put("Add_addmode", "3");
String status = HttpsUtils.httpRequest("http://123.56.159.203:8023/mtfmset/allWMadd", datas);
datas.put("status", status);
log.info("新表充值:{}",status);
log.info("充值成功更新水表");
}
waterMeterSacc.setWmId(location.getWmid());
// 查询旧表实施数据
WaterMeter realTime = waterMeterService.findRealTime(wmId);
// 计算旧表余量 新表累计充值量 = 旧表余量
// String newWmIdSacc = AllUtils.nubmerSubtraction(realTime.getWmSacc(), realTime.getWmLacc());
log.info("旧表累计充值量:{}",realTime.getWmSacc());
// waterMeterSacc.setWmSacc(new BigDecimal(newWmIdSacc));
// 充值新表水量
Map<String, Object> datas = new HashMap<>();
datas.put("MtId", wmId);
datas.put("Add_sacc", realTime.getWmSacc());
datas.put("Add_addmode", "2");
String status = HttpsUtils.httpRequest("http://123.56.159.203:8023/mtfmset/allWMadd", datas);
datas.put("status", status);
log.info("新表充值:{}",status);
log.info("充值成功更新水表");
if (locationMapper.updateByPrimaryKeySelective(location) > 0 && waterMeterSaccMapper.updateWater(waterMeterSacc) > 0) {
waterMeterSacc.setOrderWmId(wmId);
// 更新表号 累计充值量 记录表
if (waterMeterSaccMapper.updateWater(waterMeterSacc) > 0) {
log.info("更新成功");
resultJson.setCode("200");
} else {
}else {
resultJson.setCode("201");
}
return resultJson;
... ...
... ... @@ -40,7 +40,10 @@ public interface LocationMapper {
String eeId(String roomNumber);
int adrNameWmId(@Param(value = "adrName") String adrName,
@Param(value = "wmId") String wmId);
int editEeId(@Param(value = "name") String name,
@Param(value = "deviceId") String deviceId);
}
\ No newline at end of file
}
... ...
... ... @@ -88,14 +88,18 @@
select ee_id from location where adrname = #{value}
</select>
<select id="adrNameWmId" parameterType="string" resultType="int">
select count(*) from location where adrname = #{adrName} and wmId = #{wmId}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from location
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.sunyo.energy.location.model.Location">
insert into location (id, adrName, parent,
insert into location (id, adrName, parent,
type)
values (#{id,jdbcType=INTEGER}, #{adrname,jdbcType=VARCHAR}, #{parent,jdbcType=INTEGER},
values (#{id,jdbcType=INTEGER}, #{adrname,jdbcType=VARCHAR}, #{parent,jdbcType=INTEGER},
#{type,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.sunyo.energy.location.model.Location">
... ... @@ -163,4 +167,4 @@
set ee_id = #{deviceId,jdbcType=VARCHAR}
where adrName = #{name,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
</mapper>
... ...
... ... @@ -11,7 +11,7 @@
wm_id, ardname, unit_price, wm_sacc
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
select
<include refid="Base_Column_List" />
from water_meter_sacc
where wm_id = #{wmId,jdbcType=VARCHAR}
... ... @@ -31,9 +31,9 @@
where wm_id = #{wmId,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="com.sunyo.energy.location.model.WaterMeterSacc" >
insert into water_meter_sacc (wm_id, ardname, unit_price,
insert into water_meter_sacc (wm_id, ardname, unit_price,
wm_sacc)
values (#{wmId,jdbcType=VARCHAR}, #{ardname,jdbcType=VARCHAR}, #{unitPrice,jdbcType=DECIMAL},
values (#{wmId,jdbcType=VARCHAR}, #{ardname,jdbcType=VARCHAR}, #{unitPrice,jdbcType=DECIMAL},
#{wmSacc,jdbcType=DECIMAL})
</insert>
<insert id="insertSelective" parameterType="com.sunyo.energy.location.model.WaterMeterSacc" >
... ... @@ -87,10 +87,7 @@
update water_meter_sacc
<set >
<if test="wmId != null" >
wm_id = #{wmId,jdbcType=VARCHAR},
</if>
<if test="wmSacc != null" >
wm_sacc = #{wmSacc,jdbcType=VARCHAR}
wm_id = #{wmId,jdbcType=VARCHAR}
</if>
</set>
where wm_id = #{orderWmId,jdbcType=VARCHAR}
... ... @@ -103,4 +100,4 @@
wm_sacc = #{wmSacc,jdbcType=DECIMAL}
where wm_id = #{wmId,jdbcType=VARCHAR}
</update>
</mapper>
\ No newline at end of file
</mapper>
... ...