|
@@ -1,17 +1,14 @@
|
|
package com.jpsoft.epay.modules.base.controller;
|
|
package com.jpsoft.epay.modules.base.controller;
|
|
|
|
|
|
import com.github.pagehelper.Page;
|
|
import com.github.pagehelper.Page;
|
|
-import com.jpsoft.epay.modules.base.entity.ElectricClientInfo;
|
|
|
|
-import com.jpsoft.epay.modules.base.entity.ElectricMeterInfo;
|
|
|
|
-import com.jpsoft.epay.modules.base.entity.RechargeRecord;
|
|
|
|
-import com.jpsoft.epay.modules.base.entity.TerminalInfo;
|
|
|
|
|
|
+import com.jpsoft.epay.modules.base.entity.*;
|
|
import com.jpsoft.epay.modules.base.service.*;
|
|
import com.jpsoft.epay.modules.base.service.*;
|
|
import com.jpsoft.epay.modules.business.service.RechargeService;
|
|
import com.jpsoft.epay.modules.business.service.RechargeService;
|
|
import com.jpsoft.epay.modules.common.dto.MessageResult;
|
|
import com.jpsoft.epay.modules.common.dto.MessageResult;
|
|
import com.jpsoft.epay.modules.common.dto.Sort;
|
|
import com.jpsoft.epay.modules.common.dto.Sort;
|
|
-import com.jpsoft.epay.modules.common.utils.PojoUtils;
|
|
|
|
import com.jpsoft.epay.modules.common.utils.StringUtils;
|
|
import com.jpsoft.epay.modules.common.utils.StringUtils;
|
|
import com.jpsoft.epay.modules.communication.server.protocol.MeterReceivePacket;
|
|
import com.jpsoft.epay.modules.communication.server.protocol.MeterReceivePacket;
|
|
|
|
+import com.jpsoft.epay.modules.sys.entity.DataDictionary;
|
|
import com.jpsoft.epay.modules.sys.service.DataDictionaryService;
|
|
import com.jpsoft.epay.modules.sys.service.DataDictionaryService;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
@@ -20,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/base/rechargeRecord")
|
|
@RequestMapping("/base/rechargeRecord")
|
|
@@ -211,6 +209,7 @@ public class RechargeRecordController {
|
|
@RequestMapping(value = "pageList",method = RequestMethod.POST)
|
|
@RequestMapping(value = "pageList",method = RequestMethod.POST)
|
|
public MessageResult<Map> pageList(
|
|
public MessageResult<Map> pageList(
|
|
String id,
|
|
String id,
|
|
|
|
+ @RequestParam(name="serialNumber",defaultValue = "") String serialNumber,
|
|
@RequestParam(name="pageIndex",defaultValue = "1") int pageIndex,
|
|
@RequestParam(name="pageIndex",defaultValue = "1") int pageIndex,
|
|
@RequestParam(name="pageSize",defaultValue = "10") int pageSize,
|
|
@RequestParam(name="pageSize",defaultValue = "10") int pageSize,
|
|
@RequestAttribute String subject){
|
|
@RequestAttribute String subject){
|
|
@@ -229,10 +228,40 @@ public class RechargeRecordController {
|
|
searchParams.put("id","%" + id + "%");
|
|
searchParams.put("id","%" + id + "%");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(serialNumber)) {
|
|
|
|
+ searchParams.put("serialNumber","%" + serialNumber + "%");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
Page<RechargeRecord> page = rechargeRecordService.pageSearch(searchParams,pageIndex,pageSize,sortList);
|
|
Page<RechargeRecord> page = rechargeRecordService.pageSearch(searchParams,pageIndex,pageSize,sortList);
|
|
|
|
+ List<RechargeRecord> resultRecordList = new ArrayList<>();
|
|
|
|
+ List<RechargeRecord> recordList = page.getResult();
|
|
|
|
+ for(RechargeRecord rechargeRecord :recordList){
|
|
|
|
+ RoomInfo room = roomInfoService.get(rechargeRecord.getRoomId());
|
|
|
|
+ RoomInfo building = new RoomInfo();
|
|
|
|
+ RoomInfo area = new RoomInfo();
|
|
|
|
+ if(room != null){
|
|
|
|
+ building = roomInfoService.get(room.getParentId());
|
|
|
|
+ if(building != null){
|
|
|
|
+ area = roomInfoService.get(building.getParentId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ rechargeRecord.setRoom(room);
|
|
|
|
+ rechargeRecord.setBuilding(building);
|
|
|
|
+ rechargeRecord.setArea(area);
|
|
|
|
+ resultRecordList.add(rechargeRecord);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Map<String,Object> pageMap = new HashMap<>();
|
|
|
|
+ pageMap.put("recordsTotal",page.getTotal());
|
|
|
|
+ pageMap.put("recordsFiltered",page.getTotal());
|
|
|
|
+ pageMap.put("totalPage",page.getPages());
|
|
|
|
+ pageMap.put("pageNumber",page.getPageNum());
|
|
|
|
+ pageMap.put("pageSize",page.getPageSize());
|
|
|
|
+ pageMap.put("data", resultRecordList);
|
|
|
|
|
|
msgResult.setResult(true);
|
|
msgResult.setResult(true);
|
|
- msgResult.setData(PojoUtils.pageWrapper(page));
|
|
|
|
|
|
+ msgResult.setData(pageMap);
|
|
|
|
|
|
return msgResult;
|
|
return msgResult;
|
|
}
|
|
}
|
|
@@ -242,6 +271,7 @@ public class RechargeRecordController {
|
|
@PostMapping("saveRecord")
|
|
@PostMapping("saveRecord")
|
|
public MessageResult<RechargeRecord> saveRecord(@RequestBody RechargeRecord rechargeRecord,@RequestAttribute String subject) throws Exception {
|
|
public MessageResult<RechargeRecord> saveRecord(@RequestBody RechargeRecord rechargeRecord,@RequestAttribute String subject) throws Exception {
|
|
MessageResult<RechargeRecord> msgResult = new MessageResult<>();
|
|
MessageResult<RechargeRecord> msgResult = new MessageResult<>();
|
|
|
|
+ boolean isOk = true;
|
|
try {
|
|
try {
|
|
|
|
|
|
ElectricClientInfo clientInfo = electricClientInfoService.get(rechargeRecord.getClientId());
|
|
ElectricClientInfo clientInfo = electricClientInfoService.get(rechargeRecord.getClientId());
|
|
@@ -262,16 +292,16 @@ public class RechargeRecordController {
|
|
Integer buyElectricity = rechargeRecord.getBuyElectricity();//购买电量
|
|
Integer buyElectricity = rechargeRecord.getBuyElectricity();//购买电量
|
|
|
|
|
|
//充电
|
|
//充电
|
|
- //MeterReceivePacket meterReceivePacket = rechargeService.recharge(clientInfo.getRoomId(), buyElectricity, 10, TimeUnit.SECONDS);
|
|
|
|
- MeterReceivePacket meterReceivePacket = new MeterReceivePacket();
|
|
|
|
- meterReceivePacket.setValidateResult(true);
|
|
|
|
|
|
+ MeterReceivePacket meterReceivePacket = rechargeService.recharge(clientInfo.getRoomId(), buyElectricity, 10, TimeUnit.SECONDS);
|
|
|
|
+ //MeterReceivePacket meterReceivePacket = new MeterReceivePacket();
|
|
|
|
+ //meterReceivePacket.setValidateResult(true);
|
|
|
|
|
|
if (meterReceivePacket == null) {
|
|
if (meterReceivePacket == null) {
|
|
rechargeRecord.setErrorLog("线下充电失败-返回null");
|
|
rechargeRecord.setErrorLog("线下充电失败-返回null");
|
|
|
|
+ isOk = false;
|
|
} else {
|
|
} else {
|
|
if (meterReceivePacket.isValidateResult()) {
|
|
if (meterReceivePacket.isValidateResult()) {
|
|
//返回参数如果为true则表示充值成功
|
|
//返回参数如果为true则表示充值成功
|
|
-
|
|
|
|
//剩余电量
|
|
//剩余电量
|
|
Integer electricityRemaining = clientInfo.getElectricityRemaining();
|
|
Integer electricityRemaining = clientInfo.getElectricityRemaining();
|
|
if (electricityRemaining == null) {
|
|
if (electricityRemaining == null) {
|
|
@@ -292,6 +322,7 @@ public class RechargeRecordController {
|
|
clientInfo.setUpdateTime(new Date());
|
|
clientInfo.setUpdateTime(new Date());
|
|
electricClientInfoService.update(clientInfo);
|
|
electricClientInfoService.update(clientInfo);
|
|
} else {
|
|
} else {
|
|
|
|
+ isOk = false;
|
|
rechargeRecord.setErrorLog("线下充电失败-返回状态为false");
|
|
rechargeRecord.setErrorLog("线下充电失败-返回状态为false");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -307,8 +338,13 @@ public class RechargeRecordController {
|
|
|
|
|
|
int affectCount = rechargeRecordService.insert(rechargeRecord);
|
|
int affectCount = rechargeRecordService.insert(rechargeRecord);
|
|
if (affectCount > 0) {
|
|
if (affectCount > 0) {
|
|
- msgResult.setResult(true);
|
|
|
|
- msgResult.setData(rechargeRecord);
|
|
|
|
|
|
+ if(isOk){
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(rechargeRecord);
|
|
|
|
+ }else{
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage(rechargeRecord.getErrorLog());
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
msgResult.setResult(false);
|
|
msgResult.setResult(false);
|
|
msgResult.setMessage("数据库添加失败");
|
|
msgResult.setMessage("数据库添加失败");
|
|
@@ -335,11 +371,15 @@ public class RechargeRecordController {
|
|
throw new Exception("该房间绑定电表!");
|
|
throw new Exception("该房间绑定电表!");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ RoomInfo roomInfo = roomInfoService.get(clientInfo.getRoomId());
|
|
|
|
+ DataDictionary dataDictionary = dataDictionaryService.get(roomInfo.getUseType());
|
|
|
|
+ if(dataDictionary == null){
|
|
|
|
+ throw new Exception("该房间没有绑定用电类型!");
|
|
|
|
+ }
|
|
Map<String,Object> resultMaps = new HashMap();
|
|
Map<String,Object> resultMaps = new HashMap();
|
|
resultMaps.put("roomId",clientInfo.getRoomId());
|
|
resultMaps.put("roomId",clientInfo.getRoomId());
|
|
- resultMaps.put("useTypeN",clientInfo.getRoomUseTypeN());//中文翻译
|
|
|
|
- resultMaps.put("useTypeV",clientInfo.getRoomUseTypeV());//值
|
|
|
|
-
|
|
|
|
|
|
+ resultMaps.put("useTypeN",dataDictionary.getName());//中文翻译
|
|
|
|
+ resultMaps.put("useTypeV",dataDictionary.getValue());//值
|
|
msgResult.setData(resultMaps);
|
|
msgResult.setData(resultMaps);
|
|
msgResult.setResult(true);
|
|
msgResult.setResult(true);
|
|
|
|
|