作者 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
* <p>
* 2020/6/5/10:44
*/
@RequestMapping(value = "/eeInfo")
@Component
public class EeInfoController {
@Autowired
EeInfoService eeInfoService;
@ApiOperation(value = "查询电表充值失败信息")
@RequestMapping("/list")
@ResponseBody
public PageInfo<ElectricityInfo> list(@RequestParam(value = "pageSize", required = false, defaultValue = "1") int pageSize,
@RequestParam(value = "pageNum", required = false, defaultValue = "5") int pageNum,
@RequestParam(value = "deviceId", required = false) String deviceId){
PageInfo<ElectricityInfo> eeInfo = eeInfoService.getEeInfo(pageSize, pageNum, deviceId);
return eeInfo;
}
}
... ...
... ... @@ -31,11 +31,21 @@ public class LocationController {
@RequestParam(value = "pageSize",required = false,defaultValue = "5")
int pageSize,
@RequestParam(value = "processName", required = false)
String adrname){
String adrname,
@RequestParam(value = "parent", required = false)
int parent){
Page<Location> page = PageHelper.startPage(pageNum,pageSize);
List<Location> list = null;
if (StringUtils.isEmpty(adrname)) {
list= locationMapper.selectAll(0);
list = locationMapper.selectAll(parent);
if (parent == 0){
Location location = list.get(0);
List<Location> locationsList = locationMapper.selectAll(location.getId());
for (Location loc: list){
loc.setChildren(locationsList);
}
}
}else {
list= locationMapper.selectAllAdrName(adrname);
}
... ...
... ... @@ -30,7 +30,7 @@ public class UserPayController {
@Autowired
private WaterMeterService waterMeterService;
@ApiOperation(value = "查询缴费订单")
@ApiOperation(value = "查看缴费房间")
@RequestMapping("/list")
public List userPayList(@RequestParam(value = "roomNumber", required = false) String roomNumber ){
... ...
package com.sunyo.energy.location.dao;
import com.sunyo.energy.location.model.ElectricityInfo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
... ... @@ -13,7 +14,7 @@ public interface ElectricityInfoMapper {
ElectricityInfo selectByPrimaryKey(String orderNumber);
List<ElectricityInfo> selectAll();
List<ElectricityInfo> selectAll(@Param("deviceId") String deviceId);
int updateByPrimaryKeySelective(ElectricityInfo record);
... ...
package com.sunyo.energy.location.dao;
import com.sunyo.energy.location.model.ElectricityMeter;
public interface ElectricityMeterMapper {
int deleteByPrimaryKey(String deviceId);
int insert(ElectricityMeter record);
int insertSelective(ElectricityMeter record);
ElectricityMeter selectByPrimaryKey(String deviceId);
int updateByPrimaryKeySelective(ElectricityMeter record);
int updateByPrimaryKey(ElectricityMeter record);
}
\ No newline at end of file
package com.sunyo.energy.location.service;
import com.github.pagehelper.PageInfo;
import com.sunyo.energy.location.model.ElectricityInfo;
import com.sunyo.energy.location.model.PayRecords;
import java.util.List;
/**
* @author shenhailong
* <p>
* 2020/6/5/10:45
*/
public interface EeInfoService {
int deleteByPrimaryKey(String orderNumber);
int insert(ElectricityInfo record);
int insertSelective(ElectricityInfo record);
ElectricityInfo selectByPrimaryKey(String orderNumber);
PageInfo<ElectricityInfo> getEeInfo(int pageSize, int pageNum, String deviceId);
int updateByPrimaryKeySelective(ElectricityInfo record);
int updateByPrimaryKey(ElectricityInfo record);
}
... ...
package com.sunyo.energy.location.service.imp;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sunyo.energy.location.dao.ElectricityInfoMapper;
import com.sunyo.energy.location.model.ElectricityInfo;
import com.sunyo.energy.location.model.PayRecords;
import com.sunyo.energy.location.service.EeInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;
/**
* @author shenhailong
* <p>
* 2020/6/5/10:45
*/
@Service
public class EeInfoServiceImpl implements EeInfoService {
@Autowired
ElectricityInfoMapper electricityInfoMapper;
@Override
public int deleteByPrimaryKey(String orderNumber) {
return 0;
}
@Override
public int insert(ElectricityInfo record) {
return 0;
}
@Override
public int insertSelective(ElectricityInfo record) {
return 0;
}
@Override
public ElectricityInfo selectByPrimaryKey(String orderNumber) {
return null;
}
@Override
public PageInfo<ElectricityInfo> getEeInfo(int pageSize, int pageNum, String deviceId) {
PageHelper.startPage(pageNum,pageSize);
List<ElectricityInfo> list = electricityInfoMapper.selectAll(deviceId);
PageInfo<ElectricityInfo> result = new PageInfo<>(list);
return result;
}
@Override
public int updateByPrimaryKeySelective(ElectricityInfo record) {
return 0;
}
@Override
public int updateByPrimaryKey(ElectricityInfo record) {
return 0;
}
}
... ...
... ... @@ -2,7 +2,6 @@ package com.sunyo.energy.location.service.imp;
import com.alibaba.fastjson.JSON;
import com.sunyo.energy.location.dao.ElectricityInfoMapper;
import com.sunyo.energy.location.dao.ElectricityMeterMapper;
import com.sunyo.energy.location.dao.PayRecordsMapper;
import com.sunyo.energy.location.model.*;
import com.sunyo.energy.location.service.ElectricityMeterService;
... ... @@ -25,9 +24,6 @@ import java.util.Map;
public class ElectricityMeterServiceImp implements ElectricityMeterService {
@Autowired
ElectricityMeterMapper electricityMeterMapper;
@Autowired
ElectricityInfoMapper electricityInfoMapper;
@Autowired
... ... @@ -47,39 +43,26 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService {
* 电表充值接口地址
*/
private final static String rechargeDevicesUrl = "http://192.168.1.2:18080/api/emcs/rechargeDevices";
/**
* 获取全部电表设备数据 定时查询 入临时电表
* 获取设备跟公寓信息
*/
@Scheduled(cron = "0 0 03 * * ?" )
public void balanceList(){
try {
Map<String, Object> stringObjectMap = eeInfo("all");
String infoForRealTime = HttpsUtils.sendPost(electricityBanlanceUrl, stringObjectMap);
ElectricityBalanceOne electricityBalanceOne = JSON.parseObject(infoForRealTime, ElectricityBalanceOne.class);
List<ElectricityMeter> electricityMeterList = electricityBalanceOne.getData().getDatas();
for (ElectricityMeter electricityMeter : electricityMeterList){
electricityMeterMapper.insertSelective(electricityMeter);
}
}catch (Exception e){
e.printStackTrace();
}
}
private final static String getRoomAndDeviceUrl = "http://192.168.1.2:18080/api/emcs/getRoomAndDevice";
/**
* 实施获取电表数据
*/
@Override
public ElectricityMeter getEnergyInfoForRealTime(String deviceId){
try {
Map<String, Object> stringObjectMap = eeInfo(deviceId);
String infoForRealTime = HttpsUtils.sendPost(electricityBanlanceUrl, stringObjectMap);
ElectricityBalanceOne electricityBalanceOne = JSON.parseObject(infoForRealTime, ElectricityBalanceOne.class);
List<ElectricityMeter> infoForRealTimeList = electricityBalanceOne.getData().getDatas();
for (ElectricityMeter electricityBalanceThree: infoForRealTimeList){
if (electricityBalanceThree != null){
return electricityBalanceThree;
if(!"".equals(deviceId)){
Map<String, Object> stringObjectMap = eeInfo(deviceId);
String infoForRealTime = HttpsUtils.sendPost(electricityBanlanceUrl, stringObjectMap);
ElectricityBalanceOne electricityBalanceOne = JSON.parseObject(infoForRealTime, ElectricityBalanceOne.class);
List<ElectricityMeter> infoForRealTimeList = electricityBalanceOne.getData().getDatas();
for (ElectricityMeter electricityBalanceThree: infoForRealTimeList){
if (electricityBalanceThree != null){
return electricityBalanceThree;
}
}
}
return null;
... ... @@ -89,6 +72,14 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService {
}
}
/**
* 电表充值
* @param deviceId 设备编号
* @param money 充值金额
* @param actionType 充值类型 0 充值 1 扣费
* @param orderNumber 订单号
* @return
*/
@Override
public int rechargeDevices(String deviceId, String money, String actionType, String orderNumber) {
... ... @@ -146,7 +137,7 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService {
*/
@Scheduled(fixedDelay = 5000)
public void electricityInfo(){
List<ElectricityInfo> electricityInfos = electricityInfoMapper.selectAll();
List<ElectricityInfo> electricityInfos = electricityInfoMapper.selectAll("");
if (electricityInfos.size() > 0){
for (ElectricityInfo electricityInfo: electricityInfos){
Map<String, Object> stringObjectMap = mapCommon(electricityInfo.getActionType(),
... ... @@ -158,15 +149,17 @@ public class ElectricityMeterServiceImp implements ElectricityMeterService {
log.info("电表临时表充值请求信息:{}", electricityInfo.toString());
log.info("电表临时表充值返回信息:{}", result);
RechargeDevicesResult rechargeDevicesResult = JSON.parseObject(result, RechargeDevicesResult.class);
List<RechargeDevicesResultData> data = rechargeDevicesResult.getData().getDatas();
Boolean message = null;
for (RechargeDevicesResultData rechargeDevicesResultData : data){
message = rechargeDevicesResultData.getSuccess();
}
if ("0".equals(rechargeDevicesResult.getErrcode()) && message == true){
payRecordsMapper.updateStatus(electricityInfo.getOrderNumber());
electricityInfo.setStatus("0");
electricityInfoMapper.updateByPrimaryKeySelective(electricityInfo);
if(rechargeDevicesResult.getData()!= null){
List<RechargeDevicesResultData> data = rechargeDevicesResult.getData().getDatas();
Boolean message = null;
for (RechargeDevicesResultData rechargeDevicesResultData : data){
message = rechargeDevicesResultData.getSuccess();
}
if ("0".equals(rechargeDevicesResult.getErrcode()) && message == true){
payRecordsMapper.updateStatus(electricityInfo.getOrderNumber());
electricityInfo.setStatus("0");
electricityInfoMapper.updateByPrimaryKeySelective(electricityInfo);
}
}
}
}
... ...
package com.sunyo.energy.location.service.imp;
import com.sunyo.energy.location.dao.ElectricityMeterMapper;
import com.sunyo.energy.location.dao.LocationMapper;
import com.sunyo.energy.location.model.ElectricityMeter;
import com.sunyo.energy.location.model.WaterMeter;
import com.sunyo.energy.location.service.ElectricityMeterService;
import com.sunyo.energy.location.service.LocationService;
import com.sunyo.energy.location.utils.AllUtils;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -21,8 +21,9 @@ public class LocationServiceImp implements LocationService {
@Autowired
LocationMapper locationMapper;
@Autowired
ElectricityMeterMapper electricityMeterMapper;
ElectricityMeterService electricityMeterService;
@Override
public List userPayList(String roomNumber) {
... ... @@ -66,14 +67,15 @@ public class LocationServiceImp implements LocationService {
* 电费查询 通过房间号查询设备id
*/
String eeId = locationMapper.eeId(roomNumber);
ElectricityMeter electricityMeter = electricityMeterMapper.selectByPrimaryKey(eeId);
Map<String, Object> eeMap = new HashMap<>();
if (electricityMeter != null){
eeMap.put("deviceId", electricityMeter.getDeviceId());
eeMap.put("balance", electricityMeter.getBalance());
eeMap.put("wmId", "");
list.add(eeMap);
if (!"".equals(eeId)){
ElectricityMeter energyInfoForRealTime = electricityMeterService.getEnergyInfoForRealTime(eeId);
Map<String, Object> eeMap = new HashMap<>();
if (energyInfoForRealTime != null){
eeMap.put("deviceId", energyInfoForRealTime.getDeviceId());
eeMap.put("balance", energyInfoForRealTime.getBalance());
eeMap.put("wmId", "");
list.add(eeMap);
}
}
return list;
}
... ... @@ -83,4 +85,8 @@ public class LocationServiceImp implements LocationService {
return null;
}
}
}
... ...
... ... @@ -24,11 +24,15 @@
where order_number = #{orderNumber,jdbcType=VARCHAR}
</select>
<select id="selectAll" resultMap="BaseResultMap">
<select id="selectAll" resultMap="BaseResultMap" parameterType="string">
select
<include refid="Base_Column_List" />
from electricity_info
where status = '1'
<if test="deviceId != null and deviceId != ''" >
and device_id = #{deviceId, jdbcType=VARCHAR}
</if>
order by opert_time desc
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.sunyo.energy.location.dao.ElectricityMeterMapper" >
<resultMap id="BaseResultMap" type="com.sunyo.energy.location.model.ElectricityMeter" >
<id column="device_id" property="deviceId" jdbcType="VARCHAR" />
<result column="total_energy" property="totalEnergy" jdbcType="DECIMAL" />
<result column="tip_energy" property="tipEnergy" jdbcType="DECIMAL" />
<result column="peak_energy" property="peakEnergy" jdbcType="DECIMAL" />
<result column="valley_energy" property="valleyEnergy" jdbcType="DECIMAL" />
<result column="flat_energy" property="flatEnergy" jdbcType="DECIMAL" />
<result column="balance" property="balance" jdbcType="DECIMAL" />
<result column="acTime" property="actime" jdbcType="TIMESTAMP" />
<result column="updateTime" property="updatetime" jdbcType="TIMESTAMP" />
<result column="reamke1" property="reamke1" jdbcType="VARCHAR" />
<result column="reamke2" property="reamke2" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
device_id, total_energy, tip_energy, peak_energy, valley_energy, flat_energy, balance,
acTime, updateTime, reamke1, reamke2
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
from electricity_meter
where device_id = #{deviceId,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
delete from electricity_meter
where device_id = #{deviceId,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="com.sunyo.energy.location.model.ElectricityMeter" >
insert into electricity_meter (device_id, total_energy, tip_energy,
peak_energy, valley_energy, flat_energy,
balance, acTime, updateTime,
reamke1, reamke2)
values (#{deviceId,jdbcType=VARCHAR}, #{totalEnergy,jdbcType=DECIMAL}, #{tipEnergy,jdbcType=DECIMAL},
#{peakEnergy,jdbcType=DECIMAL}, #{valleyEnergy,jdbcType=DECIMAL}, #{flatEnergy,jdbcType=DECIMAL},
#{balance,jdbcType=DECIMAL}, #{actime,jdbcType=TIMESTAMP}, #{updatetime,jdbcType=TIMESTAMP},
#{reamke1,jdbcType=VARCHAR}, #{reamke2,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.sunyo.energy.location.model.ElectricityMeter" >
insert into electricity_meter
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="deviceId != null" >
device_id,
</if>
<if test="totalEnergy != null" >
total_energy,
</if>
<if test="tipEnergy != null" >
tip_energy,
</if>
<if test="peakEnergy != null" >
peak_energy,
</if>
<if test="valleyEnergy != null" >
valley_energy,
</if>
<if test="flatEnergy != null" >
flat_energy,
</if>
<if test="balance != null" >
balance,
</if>
<if test="actime != null" >
acTime,
</if>
<if test="updatetime != null" >
updateTime,
</if>
<if test="reamke1 != null" >
reamke1,
</if>
<if test="reamke2 != null" >
reamke2,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="deviceId != null" >
#{deviceId,jdbcType=VARCHAR},
</if>
<if test="totalEnergy != null" >
#{totalEnergy,jdbcType=DECIMAL},
</if>
<if test="tipEnergy != null" >
#{tipEnergy,jdbcType=DECIMAL},
</if>
<if test="peakEnergy != null" >
#{peakEnergy,jdbcType=DECIMAL},
</if>
<if test="valleyEnergy != null" >
#{valleyEnergy,jdbcType=DECIMAL},
</if>
<if test="flatEnergy != null" >
#{flatEnergy,jdbcType=DECIMAL},
</if>
<if test="balance != null" >
#{balance,jdbcType=DECIMAL},
</if>
<if test="actime != null" >
#{actime,jdbcType=TIMESTAMP},
</if>
<if test="updatetime != null" >
#{updatetime,jdbcType=TIMESTAMP},
</if>
<if test="reamke1 != null" >
#{reamke1,jdbcType=VARCHAR},
</if>
<if test="reamke2 != null" >
#{reamke2,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.sunyo.energy.location.model.ElectricityMeter" >
update electricity_meter
<set >
<if test="totalEnergy != null" >
total_energy = #{totalEnergy,jdbcType=DECIMAL},
</if>
<if test="tipEnergy != null" >
tip_energy = #{tipEnergy,jdbcType=DECIMAL},
</if>
<if test="peakEnergy != null" >
peak_energy = #{peakEnergy,jdbcType=DECIMAL},
</if>
<if test="valleyEnergy != null" >
valley_energy = #{valleyEnergy,jdbcType=DECIMAL},
</if>
<if test="flatEnergy != null" >
flat_energy = #{flatEnergy,jdbcType=DECIMAL},
</if>
<if test="balance != null" >
balance = #{balance,jdbcType=DECIMAL},
</if>
<if test="actime != null" >
acTime = #{actime,jdbcType=TIMESTAMP},
</if>
<if test="updatetime != null" >
updateTime = #{updatetime,jdbcType=TIMESTAMP},
</if>
<if test="reamke1 != null" >
reamke1 = #{reamke1,jdbcType=VARCHAR},
</if>
<if test="reamke2 != null" >
reamke2 = #{reamke2,jdbcType=VARCHAR},
</if>
</set>
where device_id = #{deviceId,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="com.sunyo.energy.location.model.ElectricityMeter" >
update electricity_meter
set total_energy = #{totalEnergy,jdbcType=DECIMAL},
tip_energy = #{tipEnergy,jdbcType=DECIMAL},
peak_energy = #{peakEnergy,jdbcType=DECIMAL},
valley_energy = #{valleyEnergy,jdbcType=DECIMAL},
flat_energy = #{flatEnergy,jdbcType=DECIMAL},
balance = #{balance,jdbcType=DECIMAL},
acTime = #{actime,jdbcType=TIMESTAMP},
updateTime = #{updatetime,jdbcType=TIMESTAMP},
reamke1 = #{reamke1,jdbcType=VARCHAR},
reamke2 = #{reamke2,jdbcType=VARCHAR}
where device_id = #{deviceId,jdbcType=VARCHAR}
</update>
</mapper>
\ No newline at end of file
... ... @@ -8,7 +8,7 @@
<result column="adrName" property="adrname" jdbcType="VARCHAR" />
<result column="parent" property="parent" jdbcType="INTEGER" />
<result column="type" property="type" jdbcType="INTEGER" />
<collection property="children" select="selectAll" column="id"></collection>
<!-- <collection property="children" select="selectAll" column="id"></collection>-->
</resultMap>
<sql id="Base_Column_List" >
id, adrName, parent, type, wm_id, ee_id
... ... @@ -140,6 +140,9 @@
<if test="wmid != null" >
wm_id = #{wmid,jdbcType=VARCHAR},
</if>
<if test="eeid != null" >
ee_id = #{eeid,jdbcType=VARCHAR}
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
... ...