作者 shenhailong

添加 修改水表编号 远程水表阀开功能

... ... @@ -6,17 +6,28 @@ 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;
@Slf4j
@RestController
@RequestMapping("/location")
public class LocationController {
... ... @@ -24,6 +35,12 @@ public class LocationController {
@Autowired
private LocationMapper locationMapper;
@Autowired
private WaterMeterSaccMapper waterMeterSaccMapper;
@Autowired
private WaterMeterService waterMeterService;
@ApiOperation(value = "查询楼层")
@RequestMapping(value = "/list", method = RequestMethod.GET)
public ResultJson startActivityDemo(@RequestParam(value = "pageNum", required = false, defaultValue = "1")
... ... @@ -106,16 +123,49 @@ public class LocationController {
@ApiOperation(value = "修改楼层")
@PutMapping(value = "/edit")
public ResultJson editLocation(@RequestBody Location location) {
public ResultJson editLocation(@RequestBody Location location) throws Exception {
ResultJson resultJson = new ResultJson();
if (locationMapper.updateByPrimaryKeySelective(location) > 0) {
String wmId = locationMapper.findWmId(location.getAdrname());
WaterMeterSacc waterMeterSacc = new WaterMeterSacc();
waterMeterSacc.setOrderWmId(wmId);
waterMeterSacc.setWmId(location.getWmid());
// 查询旧表实施数据
WaterMeter realTime = waterMeterService.findRealTime(wmId);
// 计算旧表余量 新表累计充值量 = 旧表余量
String newWmIdSacc = AllUtils.nubmerSubtraction(realTime.getWmSacc(), realTime.getWmLacc());
log.info("旧表余量:{}",newWmIdSacc);
waterMeterSacc.setWmSacc(new BigDecimal(newWmIdSacc));
// 充值新表水量
Map<String, Object> datas = new HashMap<>();
datas.put("MtId", wmId);
datas.put("Add_sacc", newWmIdSacc);
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) {
log.info("更新成功");
resultJson.setCode("200");
} else {
resultJson.setCode("201");
}
return resultJson;
}
@ApiOperation(value = "远程水表阀开")
@GetMapping(value = "/allAddMtfmset")
public ResultJson allAddMtfmset(@RequestParam("MtId") String mtId,
@RequestParam("MtFm") String mtFm) throws Exception {
Map<String, Object> map = new HashMap<>();
map.put("MtId", mtId);
map.put("MtFm", mtFm);
String s = HttpsUtils.httpRequest("http://123.56.159.203:8023/mtfmset/allAddMtfmset", map);
if (s.contains("0")){
return new ResultJson("200", "success");
}
return new ResultJson("201", "error");
}
}
... ...
... ... @@ -18,5 +18,7 @@ public interface WaterMeterSaccMapper {
int updateByPrimaryKeySelective(WaterMeterSacc record);
int updateWater(WaterMeterSacc record);
int updateByPrimaryKey(WaterMeterSacc record);
}
\ No newline at end of file
... ...
... ... @@ -77,8 +77,9 @@ public class HttpClientUtil {
System.out.println("GetPage:" + url);
String content = null;
if (url == null || url.trim().length() == 0 || paramMap == null
|| paramMap.isEmpty())
|| paramMap.isEmpty()) {
return null;
}
HttpClient httpClient = new HttpClient();
//����header
httpClient.getParams().setParameter(HttpMethodParams.USER_AGENT, "Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.1.2) Gecko/20090803 Fedora/3.5.2-2.fc11 Firefox/3.5.2");//
... ... @@ -98,12 +99,13 @@ public class HttpClientUtil {
}
if (o != null && o instanceof String[]) {
String[] s = (String[]) o;
if (s != null)
if (s != null) {
for (int i = 0; i < s.length; i++) {
method.addParameter(new NameValuePair(key, s[i]));
}
}
}
}
try {
int statusCode = httpClient.executeMethod(method);
... ... @@ -117,7 +119,9 @@ public class HttpClientUtil {
System.out.println("time out");
e.printStackTrace();
} finally {
if (method != null) method.releaseConnection();
if (method != null) {
method.releaseConnection();
}
method = null;
httpClient = null;
}
... ...
... ... @@ -11,6 +11,8 @@ public class WaterMeterSacc {
private BigDecimal wmSacc;
private String orderWmId;
public String getWmId() {
return wmId;
}
... ... @@ -42,4 +44,12 @@ public class WaterMeterSacc {
public void setWmSacc(BigDecimal wmSacc) {
this.wmSacc = wmSacc;
}
public String getOrderWmId() {
return orderWmId;
}
public void setOrderWmId(String orderWmId) {
this.orderWmId = orderWmId;
}
}
\ No newline at end of file
... ...
... ... @@ -258,6 +258,7 @@ public class WaterMeterServiceImp implements WaterMeterService {
String s = AllUtils.nubmerDivision(payFees);
// 查询累计充值量
WaterMeterSacc waterMeterSacc = waterMeterSaccMapper.selectByPrimaryKey(AllUtils.wmIdUtils(wmId));
// 充值水量 + 累计充值量 = 总累计充值量
String allSacc = AllUtils.nubmerAdd(s, waterMeterSacc.getWmSacc());
Map<String, Object> datas = new HashMap<>();
datas.put("MtId", wmId);
... ...
... ... @@ -82,6 +82,20 @@
</set>
where wm_id = #{wmId,jdbcType=VARCHAR}
</update>
<update id="updateWater" parameterType="com.sunyo.energy.location.model.WaterMeterSacc" >
update water_meter_sacc
<set >
<if test="wmId != null" >
wm_id = #{wmId,jdbcType=VARCHAR},
</if>
<if test="wmSacc != null" >
wm_sacc = #{wmSacc,jdbcType=VARCHAR}
</if>
</set>
where wm_id = #{orderWmId,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="com.sunyo.energy.location.model.WaterMeterSacc" >
update water_meter_sacc
set ardname = #{ardname,jdbcType=VARCHAR},
... ...