Explorar o código

合并创业学校电表管理

zhengqiang %!s(int64=5) %!d(string=hai) anos
pai
achega
5b4195656b
Modificáronse 59 ficheiros con 1142 adicións e 456 borrados
  1. 0 1
      pom.xml
  2. 8 8
      src/main/java/com/jpsoft/smart/SmartCommunityServerApplication.java
  3. 171 17
      src/main/java/com/jpsoft/smart/modules/base/controller/ElectricClientInfoController.java
  4. 11 1
      src/main/java/com/jpsoft/smart/modules/base/controller/ElectricMeterInfoController.java
  5. 62 13
      src/main/java/com/jpsoft/smart/modules/base/controller/RechargeRecordController.java
  6. 38 1
      src/main/java/com/jpsoft/smart/modules/base/controller/RoomInfoController.java
  7. 8 2
      src/main/java/com/jpsoft/smart/modules/base/controller/TerminalInfoController.java
  8. 1 0
      src/main/java/com/jpsoft/smart/modules/base/dao/ElectricClientInfoDAO.java
  9. 1 0
      src/main/java/com/jpsoft/smart/modules/base/dao/ElectricMeterInfoDAO.java
  10. 1 0
      src/main/java/com/jpsoft/smart/modules/base/dao/RoomInfoDAO.java
  11. 2 0
      src/main/java/com/jpsoft/smart/modules/base/dao/TerminalInfoDAO.java
  12. 22 0
      src/main/java/com/jpsoft/smart/modules/base/entity/ElectricClientInfo.java
  13. 15 0
      src/main/java/com/jpsoft/smart/modules/base/entity/ElectricMeterInfo.java
  14. 9 0
      src/main/java/com/jpsoft/smart/modules/base/entity/RechargeRecord.java
  15. 13 0
      src/main/java/com/jpsoft/smart/modules/base/entity/TerminalInfo.java
  16. 1 0
      src/main/java/com/jpsoft/smart/modules/base/service/ElectricClientInfoService.java
  17. 1 0
      src/main/java/com/jpsoft/smart/modules/base/service/ElectricMeterInfoService.java
  18. 1 0
      src/main/java/com/jpsoft/smart/modules/base/service/RechargeRecordService.java
  19. 2 1
      src/main/java/com/jpsoft/smart/modules/base/service/RoomInfoService.java
  20. 3 0
      src/main/java/com/jpsoft/smart/modules/base/service/TerminalInfoService.java
  21. 5 0
      src/main/java/com/jpsoft/smart/modules/base/service/impl/ElectricClientInfoServiceImpl.java
  22. 5 0
      src/main/java/com/jpsoft/smart/modules/base/service/impl/ElectricMeterInfoServiceImpl.java
  23. 14 5
      src/main/java/com/jpsoft/smart/modules/base/service/impl/RechargeRecordServiceImpl.java
  24. 5 0
      src/main/java/com/jpsoft/smart/modules/base/service/impl/RoomInfoServiceImpl.java
  25. 10 0
      src/main/java/com/jpsoft/smart/modules/base/service/impl/TerminalInfoServiceImpl.java
  26. 1 1
      src/main/java/com/jpsoft/smart/modules/business/controller/DemoController.java
  27. 38 20
      src/main/java/com/jpsoft/smart/modules/business/controller/MobileApiController.java
  28. 1 1
      src/main/java/com/jpsoft/smart/modules/business/service/RechargeService.java
  29. 21 17
      src/main/java/com/jpsoft/smart/modules/business/service/impl/RechargeServiceImpl.java
  30. 79 0
      src/main/java/com/jpsoft/smart/modules/business/task/RechargeTask.java
  31. 6 7
      src/main/java/com/jpsoft/smart/modules/communication/server/codec/MeterDecodeHandler.java
  32. 13 1
      src/main/java/com/jpsoft/smart/modules/communication/server/handler/ActiveChannelHandler.java
  33. 16 1
      src/main/java/com/jpsoft/smart/modules/communication/server/handler/HeartbeatServerHandler.java
  34. 4 1
      src/main/java/com/jpsoft/smart/modules/communication/server/protocol/MeterReceivePacket.java
  35. 21 0
      src/main/java/com/jpsoft/smart/modules/pay/alipay/AlipayController.java
  36. 66 0
      src/main/java/com/jpsoft/smart/modules/pay/properties/WxJpsoftProperties.java
  37. 36 24
      src/main/java/com/jpsoft/smart/modules/pay/weixin/WxPayController.java
  38. 1 1
      src/main/java/com/jpsoft/smart/modules/sys/dao/MenuDAO.java
  39. 1 1
      src/main/java/com/jpsoft/smart/modules/sys/dao/PermissionDAO.java
  40. 1 2
      src/main/java/com/jpsoft/smart/modules/sys/dao/RoleDAO.java
  41. 1 2
      src/main/java/com/jpsoft/smart/modules/sys/dao/RoleMenuDAO.java
  42. 1 2
      src/main/java/com/jpsoft/smart/modules/sys/dao/RolePermissionDAO.java
  43. 1 1
      src/main/java/com/jpsoft/smart/modules/sys/dao/UserDAO.java
  44. 2 3
      src/main/java/com/jpsoft/smart/modules/sys/dao/UserRoleDAO.java
  45. 3 4
      src/main/java/com/jpsoft/smart/modules/sys/service/impl/MenuServiceImpl.java
  46. 3 4
      src/main/java/com/jpsoft/smart/modules/sys/service/impl/PermissionServiceImpl.java
  47. 3 4
      src/main/java/com/jpsoft/smart/modules/sys/service/impl/RoleMenuServiceImpl.java
  48. 3 4
      src/main/java/com/jpsoft/smart/modules/sys/service/impl/RolePermissionServiceImpl.java
  49. 3 4
      src/main/java/com/jpsoft/smart/modules/sys/service/impl/RoleServiceImpl.java
  50. 3 3
      src/main/java/com/jpsoft/smart/modules/sys/service/impl/UserRoleServiceImpl.java
  51. 3 4
      src/main/java/com/jpsoft/smart/modules/sys/service/impl/UserServiceImpl.java
  52. 0 2
      src/main/java/com/jpsoft/smart/modules/wechat/controller/WxController.java
  53. 1 1
      src/main/resources/application-test.yml
  54. 8 0
      src/main/resources/application.yml
  55. 157 125
      src/main/resources/mapper/base/ElectricClientInfo.xml
  56. 15 3
      src/main/resources/mapper/base/ElectricMeterInfo.xml
  57. 95 73
      src/main/resources/mapper/base/RechargeRecord.xml
  58. 17 2
      src/main/resources/mapper/base/RoomInfo.xml
  59. 109 89
      src/main/resources/mapper/base/TerminalInfo.xml

+ 0 - 1
pom.xml

@@ -24,7 +24,6 @@
         <alipay.version>4.8.10.ALL</alipay.version>
         <ijpay.version>2.3.2</ijpay.version>
     </properties>
-
     <dependencies>
         <dependency>
             <groupId>org.springframework.boot</groupId>

+ 8 - 8
src/main/java/com/jpsoft/smart/SmartCommunityServerApplication.java

@@ -21,13 +21,13 @@ public class SmartCommunityServerApplication implements CommandLineRunner {
 
 	@Override
 	public void run(String... args) throws Exception {
-//		tcpServer.start();
-//
-//		Runtime.getRuntime().addShutdownHook(new Thread(){
-//			@Override
-//			public void run() {
-//				tcpServer.stop();
-//			}
-//		});
+		tcpServer.start();
+
+		Runtime.getRuntime().addShutdownHook(new Thread(){
+			@Override
+			public void run() {
+				tcpServer.stop();
+			}
+		});
 	}
 }

+ 171 - 17
src/main/java/com/jpsoft/smart/modules/base/controller/ElectricClientInfoController.java

@@ -5,8 +5,11 @@ import com.jpsoft.smart.modules.base.entity.ElectricClientInfo;
 import com.jpsoft.smart.modules.base.entity.RoomInfo;
 import com.jpsoft.smart.modules.base.service.ElectricClientInfoService;
 import com.jpsoft.smart.modules.base.service.RoomInfoService;
+import com.jpsoft.smart.modules.business.service.RechargeService;
 import com.jpsoft.smart.modules.common.dto.MessageResult;
 import com.jpsoft.smart.modules.common.dto.Sort;
+import com.jpsoft.smart.modules.communication.server.protocol.MeterReceivePacket;
+import com.jpsoft.smart.modules.communication.server.protocol.MeterSendPacket;
 import com.jpsoft.smart.modules.sys.service.DataDictionaryService;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
@@ -15,8 +18,8 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
-import java.math.BigDecimal;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 
 @RestController
 @RequestMapping("/base/electricClientInfo")
@@ -25,11 +28,16 @@ public class ElectricClientInfoController {
 
     @Autowired
     private ElectricClientInfoService electricClientInfoService;
+
     @Autowired
     private RoomInfoService roomInfoService;
+
     @Autowired
     private DataDictionaryService dataDictionaryService;
 
+    @Autowired
+    private RechargeService rechargeService;
+
     @ApiOperation(value="创建空记录")
     @GetMapping("create")
     public MessageResult<ElectricClientInfo> create(){
@@ -54,18 +62,30 @@ public class ElectricClientInfoController {
             electricClientInfo.setCreateBy(subject);
             electricClientInfo.setCreateTime(new Date());
 
-            RoomInfo roomInfo = roomInfoService.get(electricClientInfo.getRoomId());
+            //RoomInfo roomInfo = roomInfoService.get(electricClientInfo.getRoomId());
             //金额计算
             //获取房间用电类型
-            String uType = "";
-            BigDecimal ePrice ;
-            BigDecimal erPrice = new BigDecimal(electricClientInfo.getElectricityRemaining());
-            if(StringUtils.isNotEmpty(roomInfo.getUseType())) {
-                ePrice =  new BigDecimal(dataDictionaryService.getValue(roomInfo.getUseType()));
-                BigDecimal totalPrice = ePrice.multiply(erPrice);
-                electricClientInfo.setAmountRemaining(totalPrice);
+//            String uType = "";
+//            BigDecimal ePrice ;
+//            BigDecimal erPrice = new BigDecimal(electricClientInfo.getElectricityRemaining());
+//            if(StringUtils.isNotEmpty(roomInfo.getUseType())) {
+//                ePrice =  new BigDecimal(dataDictionaryService.getValue(roomInfo.getUseType()));
+//                BigDecimal totalPrice = ePrice.multiply(erPrice);
+//                electricClientInfo.setAmountRemaining(totalPrice);
+//            }
+
+            electricClientInfo.setActive(false);
+
+            int haveCount = electricClientInfoService.getCountByCNo(electricClientInfo.getCustomerNo(),electricClientInfo.getId());
+            if(haveCount > 0){
+                throw new Exception("该户号已存在!");
             }
 
+            //查询该户当前电量
+            MeterReceivePacket mrp = rechargeService.sendCommand(electricClientInfo.getRoomId(), MeterSendPacket.READ,3, TimeUnit.SECONDS);
+
+            electricClientInfo.setRechargeTimes(mrp.getRechargeTimes());
+            electricClientInfo.setElectricityRemaining(mrp.getRemain());
             int affectCount = electricClientInfoService.insert(electricClientInfo);
 
             if (affectCount > 0) {
@@ -112,6 +132,45 @@ public class ElectricClientInfoController {
         return msgResult;
     }
 
+
+    @ApiOperation(value="同步设备信息")
+    @GetMapping("syncDevice")
+    public MessageResult<ElectricClientInfo> syncDevice(String id){
+        MessageResult<ElectricClientInfo> msgResult = new MessageResult<>();
+
+        try {
+            ElectricClientInfo electricClientInfo = electricClientInfoService.get(id);
+
+            //查询该户当前电量
+            MeterReceivePacket mrp = rechargeService.sendCommand(electricClientInfo.getRoomId(), MeterSendPacket.READ,3, TimeUnit.SECONDS);
+            int affectCount = 0;
+
+            if(mrp!=null){
+                electricClientInfo.setRechargeTimes(mrp.getRechargeTimes());
+                electricClientInfo.setElectricityRemaining(mrp.getRemain());
+                electricClientInfo.setUpdateTime(new Date());
+
+                affectCount = electricClientInfoService.update(electricClientInfo);
+            }
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(electricClientInfo);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("设备同步失败");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
     @ApiOperation(value="更新用户")
     @PostMapping("update")
     public MessageResult<ElectricClientInfo> update(@RequestBody ElectricClientInfo electricClientInfo,@RequestAttribute String subject){
@@ -121,16 +180,21 @@ public class ElectricClientInfoController {
             electricClientInfo.setUpdateBy(subject);
             electricClientInfo.setUpdateTime(new Date());
 
-            RoomInfo roomInfo = roomInfoService.get(electricClientInfo.getRoomId());
+            //RoomInfo roomInfo = roomInfoService.get(electricClientInfo.getRoomId());
             //金额计算
             //获取房间用电类型
-            String uType = "";
-            BigDecimal ePrice ;
-            BigDecimal erPrice = new BigDecimal(electricClientInfo.getElectricityRemaining());
-            if(StringUtils.isNotEmpty(roomInfo.getUseType())) {
-                ePrice =  new BigDecimal(dataDictionaryService.getValue(roomInfo.getUseType()));
-                BigDecimal totalPrice = ePrice.multiply(erPrice);
-                electricClientInfo.setAmountRemaining(totalPrice);
+//            String uType = "";
+//            BigDecimal ePrice ;
+//            BigDecimal erPrice = new BigDecimal(electricClientInfo.getElectricityRemaining());
+//            if(StringUtils.isNotEmpty(roomInfo.getUseType())) {
+//                ePrice =  new BigDecimal(dataDictionaryService.getValue(roomInfo.getUseType()));
+//                BigDecimal totalPrice = ePrice.multiply(erPrice);
+//                electricClientInfo.setAmountRemaining(totalPrice);
+//            }
+
+            int haveCount = electricClientInfoService.getCountByCNo(electricClientInfo.getCustomerNo(),electricClientInfo.getId());
+            if(haveCount > 0){
+                throw new Exception("该户号已存在!");
             }
 
             int affectCount = electricClientInfoService.update(electricClientInfo);
@@ -225,6 +289,10 @@ public class ElectricClientInfoController {
     public MessageResult<Map> pageList(
             String id,
             @RequestParam(name="customerNo",defaultValue = "") String customerNo,
+            @RequestParam(name="meterName",defaultValue = "") String meterName,
+            @RequestParam(name = "areaId", defaultValue = "") String areaId,
+            @RequestParam(name = "buildingId", defaultValue = "") String buildingId,
+            @RequestParam(name = "roomsId", defaultValue = "") String roomsId,
             @RequestParam(name="pageIndex",defaultValue = "1") int pageIndex,
             @RequestParam(name="pageSize",defaultValue = "10") int pageSize,
             @RequestAttribute String subject){
@@ -244,6 +312,37 @@ public class ElectricClientInfoController {
         if (StringUtils.isNotEmpty(customerNo)) {
             searchParams.put("customerNo",customerNo);
         }
+        if (StringUtils.isNotEmpty(meterName)) {
+            searchParams.put("meterName","%" + meterName + "%");
+        }
+
+        //先判断是否选择房间
+        if (StringUtils.isNotEmpty(roomsId)) {
+            //选择了房间
+            List<String> roomsIds = new ArrayList();
+            roomsIds.add(roomsId);
+
+            searchParams.put("roomsIds", roomsIds);
+        }else if (StringUtils.isNotEmpty(buildingId)) {
+            //没有选择房间,选择楼栋
+            List<String> buildingIds = new ArrayList();
+            buildingIds.add(buildingId);
+            List<String> roomsIds = roomInfoService.findIdByTypeAndParentIds("3",buildingIds);
+            if(roomsIds.size() < 1){
+                roomsIds.add("");
+            }
+            searchParams.put("roomsIds", roomsIds);
+        }else if (StringUtils.isNotEmpty(areaId)) {
+            //没有选择房间和楼栋,选择的园区
+            List<String> areaIds = new ArrayList();
+            areaIds.add(areaId);
+            List<String> buildingIds = roomInfoService.findIdByTypeAndParentIds("2",areaIds);
+            List<String> roomsIds = roomInfoService.findIdByTypeAndParentIds("3",buildingIds);
+            if(roomsIds.size() < 1){
+                roomsIds.add("");
+            }
+            searchParams.put("roomsIds", roomsIds);
+        }
 
         Page<ElectricClientInfo> page = electricClientInfoService.pageSearch(searchParams,pageIndex,pageSize,sortList);
 
@@ -251,8 +350,23 @@ public class ElectricClientInfoController {
         List<ElectricClientInfo> clientList = page.getResult();
         for(ElectricClientInfo clientInfo :clientList){
             RoomInfo room = roomInfoService.get(clientInfo.getRoomId());
+            if(room == null){
+                resultClientList.add(clientInfo);
+                continue;
+            }
             RoomInfo building = roomInfoService.get(room.getParentId());
+            if(building == null){
+                clientInfo.setRoom(room);
+                resultClientList.add(clientInfo);
+                continue;
+            }
             RoomInfo area = roomInfoService.get(building.getParentId());
+            if(area == null){
+                clientInfo.setRoom(room);
+                clientInfo.setBuilding(building);
+                resultClientList.add(clientInfo);
+                continue;
+            }
 
             clientInfo.setRoom(room);
             clientInfo.setBuilding(building);
@@ -272,4 +386,44 @@ public class ElectricClientInfoController {
         msgResult.setData(pageMap);
         return msgResult;
     }
+
+    @ApiOperation(value="打开或关闭电源")
+    @PostMapping("powerSwitch")
+    public MessageResult<MeterReceivePacket> powerSwitch(String roomId, int cmd) {
+        MessageResult<MeterReceivePacket> msgResult = new MessageResult<>();
+
+        try {
+            MeterReceivePacket mrp = null;
+
+            if(cmd==1) {
+                mrp = rechargeService.sendCommand(roomId, MeterSendPacket.ON,5, TimeUnit.SECONDS);
+            }
+            else {
+                mrp = rechargeService.sendCommand(roomId, MeterSendPacket.OFF,5,TimeUnit.SECONDS);
+            }
+
+            if(mrp!=null && mrp.isValidateResult()){
+                ElectricClientInfo clientInfo = electricClientInfoService.findOneByRoomId(roomId);
+
+                clientInfo.setActive(mrp.getState()!=1);
+
+                electricClientInfoService.update(clientInfo);
+
+                msgResult.setResult(true);
+                msgResult.setData(mrp);
+            }
+            else{
+                msgResult.setResult(false);
+                msgResult.setMessage("命令超时!");
+            }
+
+        } catch (Exception e) {
+            logger.error(e.getMessage(),e);
+
+            msgResult.setMessage(e.getMessage());
+            msgResult.setResult(false);
+        }
+
+        return msgResult;
+    }
 }

+ 11 - 1
src/main/java/com/jpsoft/smart/modules/base/controller/ElectricMeterInfoController.java

@@ -47,6 +47,11 @@ public class ElectricMeterInfoController {
             electricMeterInfo.setCreateBy(subject);
             electricMeterInfo.setCreateTime(new Date());
 
+            int haveCount = electricMeterInfoService.getCountByMNoAndUNo(electricMeterInfo.getMeterNo(),electricMeterInfo.getUnitNo(),electricMeterInfo.getId());
+            if(haveCount > 0){
+                throw new Exception("表号加单位不能重复!");
+            }
+            
             int affectCount = electricMeterInfoService.insert(electricMeterInfo);
 
             if (affectCount > 0) {
@@ -101,7 +106,12 @@ public class ElectricMeterInfoController {
         try {
             electricMeterInfo.setUpdateBy(subject);
             electricMeterInfo.setUpdateTime(new Date());
-            
+
+            int haveCount = electricMeterInfoService.getCountByMNoAndUNo(electricMeterInfo.getMeterNo(),electricMeterInfo.getUnitNo(),electricMeterInfo.getId());
+            if(haveCount > 0){
+                throw new Exception("表号加单位不能重复!");
+            }
+
             int affectCount = electricMeterInfoService.update(electricMeterInfo);
 
             if (affectCount > 0) {

+ 62 - 13
src/main/java/com/jpsoft/smart/modules/base/controller/RechargeRecordController.java

@@ -209,6 +209,11 @@ public class RechargeRecordController {
     @RequestMapping(value = "pageList",method = RequestMethod.POST)
     public MessageResult<Map> pageList(
             String id,
+            @RequestParam(name = "buyType", defaultValue = "") String buyType,
+            @RequestParam(name = "paymentStatus", defaultValue = "") String paymentStatus,
+            @RequestParam(name = "areaId", defaultValue = "") String areaId,
+            @RequestParam(name = "buildingId", defaultValue = "") String buildingId,
+            @RequestParam(name = "roomsId", defaultValue = "") String roomsId,
             @RequestParam(name="serialNumber",defaultValue = "") String serialNumber,
             @RequestParam(name="pageIndex",defaultValue = "1") int pageIndex,
             @RequestParam(name="pageSize",defaultValue = "10") int pageSize,
@@ -222,7 +227,7 @@ public class RechargeRecordController {
         Map<String,Object> searchParams = new HashMap<>();
 
         List<Sort> sortList = new ArrayList<>();
-        sortList.add(new Sort("id_","asc"));
+        sortList.add(new Sort("create_time","desc"));
 
         if (StringUtils.isNotEmpty(id)) {
             searchParams.put("id","%" + id + "%");
@@ -232,10 +237,44 @@ public class RechargeRecordController {
             searchParams.put("serialNumber","%" + serialNumber + "%");
         }
 
+        if (StringUtils.isNotEmpty(buyType)) {
+            searchParams.put("buyType", buyType);
+        }
+        if (StringUtils.isNotEmpty(paymentStatus)) {
+            searchParams.put("paymentStatus", paymentStatus);
+        }
+
+        //先判断是否选择房间
+        if (StringUtils.isNotEmpty(roomsId)) {
+            //选择了房间
+            List<String> roomsIds = new ArrayList();
+            roomsIds.add(roomsId);
+            searchParams.put("roomsIds", roomsIds);
+        }else if (StringUtils.isNotEmpty(buildingId)) {
+            //没有选择房间,选择楼栋
+            List<String> buildingIds = new ArrayList();
+            buildingIds.add(buildingId);
+            List<String> roomsIds = roomInfoService.findIdByTypeAndParentIds("3",buildingIds);
+            if(roomsIds.size() < 1){
+                roomsIds.add("");
+            }
+            searchParams.put("roomsIds", roomsIds);
+        }else if (StringUtils.isNotEmpty(areaId)) {
+            //没有选择房间和楼栋,选择的园区
+            List<String> areaIds = new ArrayList();
+            areaIds.add(areaId);
+            List<String> buildingIds = roomInfoService.findIdByTypeAndParentIds("2",areaIds);
+            List<String> roomsIds = roomInfoService.findIdByTypeAndParentIds("3",buildingIds);
+            if(roomsIds.size() < 1){
+                roomsIds.add("");
+            }
+            searchParams.put("roomsIds", roomsIds);
+        }
 
         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();
@@ -246,6 +285,7 @@ public class RechargeRecordController {
                     area = roomInfoService.get(building.getParentId());
                 }
             }
+
             rechargeRecord.setRoom(room);
             rechargeRecord.setBuilding(building);
             rechargeRecord.setArea(area);
@@ -266,7 +306,6 @@ public class RechargeRecordController {
         return msgResult;
     }
 
-
     @ApiOperation(value="保存电量")
     @PostMapping("saveRecord")
     public MessageResult<RechargeRecord> saveRecord(@RequestBody RechargeRecord rechargeRecord,@RequestAttribute String subject) throws  Exception {
@@ -295,27 +334,27 @@ public class RechargeRecordController {
             MeterReceivePacket meterReceivePacket = rechargeService.recharge(clientInfo.getRoomId(), buyElectricity, 10, TimeUnit.SECONDS);
             //MeterReceivePacket meterReceivePacket = new MeterReceivePacket();
             //meterReceivePacket.setValidateResult(true);
-
+            //MeterReceivePacket meterReceivePacket = null;
             if (meterReceivePacket == null) {
                 rechargeRecord.setErrorLog("线下充电失败-返回null");
                 isOk = false;
             } else {
                 if (meterReceivePacket.isValidateResult()) {
-                    //返回参数如果为true则表示充值成功
-                    //剩余电量
-                    Integer electricityRemaining = clientInfo.getElectricityRemaining();
-                    if (electricityRemaining == null) {
-                        electricityRemaining = 0;
-                    }
-                    Integer newElectricity = electricityRemaining + buyElectricity;//计算后电量
+                    rechargeRecord.setDumpEnergy(meterReceivePacket.getRemain()); //当前剩余电量
 
                     Integer electricityTotal = clientInfo.getElectricityTotal();//原总电量
+
                     if (electricityTotal == null) {
                         electricityTotal = 0;
                     }
-                    Integer newElectricityTotal = electricityTotal + buyElectricity;//最新的总电量
 
-                    clientInfo.setElectricityRemaining(newElectricity);
+                    Integer newElectricityTotal = electricityTotal + buyElectricity;//总购电量
+
+                    clientInfo.setElectricityRemaining(meterReceivePacket.getRemain());
+                    clientInfo.setRechargeTimes(meterReceivePacket.getRechargeTimes());
+
+                    clientInfo.setActive(meterReceivePacket.getState()!=1);
+
                     clientInfo.setElectricityTotal(newElectricityTotal);
 
                     clientInfo.setUpdateBy(subject);
@@ -327,11 +366,21 @@ public class RechargeRecordController {
                 }
             }
 
+            String serialNumber = StringUtils.getOutTradeNo();
+            rechargeRecord.setSerialNumber(serialNumber);
             rechargeRecord.setId(UUID.randomUUID().toString());
             rechargeRecord.setDelFlag(false);
             rechargeRecord.setCreateBy(subject);
             rechargeRecord.setCreateTime(new Date());
-            rechargeRecord.setBuyType("线下支付");
+            rechargeRecord.setBuyType("cash");
+
+            if(isOk){
+                rechargeRecord.setPaymentStatus("20");
+                rechargeRecord.setChargingStatus("20");
+            }else{
+                rechargeRecord.setPaymentStatus("30");
+                rechargeRecord.setChargingStatus("30");
+            }
             rechargeRecord.setRoomId(clientInfo.getRoomId());
             rechargeRecord.setPaymentTime(new Date());
             rechargeRecord.setCustomerNo(clientInfo.getCustomerNo());

+ 38 - 1
src/main/java/com/jpsoft/smart/modules/base/controller/RoomInfoController.java

@@ -66,7 +66,7 @@ public class RoomInfoController {
             roomInfo.setDelFlag(false);
             roomInfo.setCreateBy(subject);
             roomInfo.setCreateTime(new Date());
-            
+
             int affectCount = roomInfoService.insert(roomInfo);
 
             if (affectCount > 0) {
@@ -259,6 +259,7 @@ public class RoomInfoController {
             String keywords,
             @RequestParam(value = "excludeId", defaultValue = "") String excludeId,
             @RequestParam(value = "type", defaultValue = "") String type,
+            @RequestParam(value = "parentId", defaultValue = "") String parentId,
             @RequestParam(value = "parentType", defaultValue = "") String parentType,
             @RequestParam(value = "length", defaultValue = "20") int limit,
             @RequestAttribute String subject) {
@@ -277,6 +278,9 @@ public class RoomInfoController {
             searchParams.put("excludeId", excludeId);
         }
 
+        if (StringUtils.isNotEmpty(parentId)) {
+            searchParams.put("parentId", parentId);
+        }
         if (StringUtils.isNotEmpty(parentType)) {
             if("1".equals(parentType)){
                 //选择为园区 则不查
@@ -305,4 +309,37 @@ public class RoomInfoController {
 
         return msgResult;
     }
+
+
+    @ApiOperation(value = "查询")
+    @RequestMapping(value = "queryTree", method = RequestMethod.POST)
+    public MessageResult<List> queryTree(
+            String keywords,
+            @RequestParam(value = "excludeId", defaultValue = "") String excludeId,
+            @RequestParam(value = "type", defaultValue = "") String type,
+            @RequestParam(value = "parentId", defaultValue = "") String parentId,
+            @RequestParam(value = "parentType", defaultValue = "") String parentType,
+            @RequestParam(value = "length", defaultValue = "20") int limit,
+            @RequestAttribute String subject) {
+        MessageResult<List> msgResult = new MessageResult<>();
+
+        Map<String, Object> searchParams = new HashMap<>();
+
+        List<Sort> sortList = new ArrayList<>();
+        sortList.add(new Sort("a.sort_no", "asc"));
+
+        if (StringUtils.isNotEmpty(parentId)) {
+            searchParams.put("parentId", parentId);
+        }else{
+            searchParams.put("type", 1);
+        }
+
+        Page<RoomInfo> page = roomInfoService.pageSearch(searchParams,0, limit,sortList);
+        List<RoomInfo> roomInfoList = page.getResult();
+
+        msgResult.setResult(true);
+        msgResult.setData(roomInfoList);
+
+        return msgResult;
+    }
 }

+ 8 - 2
src/main/java/com/jpsoft/smart/modules/base/controller/TerminalInfoController.java

@@ -46,7 +46,10 @@ public class TerminalInfoController {
             terminalInfo.setDelFlag(false);
             terminalInfo.setCreateBy(subject);
             terminalInfo.setCreateTime(new Date());
-            
+            int haveCount = terminalInfoService.getCountByName(terminalInfo.getName(),terminalInfo.getId());
+            if(haveCount > 0){
+                throw new Exception("该终端名称已存在!");
+            }
             int affectCount = terminalInfoService.insert(terminalInfo);
 
             if (affectCount > 0) {
@@ -101,7 +104,10 @@ public class TerminalInfoController {
         try {
             terminalInfo.setUpdateBy(subject);
             terminalInfo.setUpdateTime(new Date());
-            
+            int haveCount = terminalInfoService.getCountByName(terminalInfo.getName(),terminalInfo.getId());
+            if(haveCount > 0){
+                throw new Exception("该终端名称已存在!");
+            }
             int affectCount = terminalInfoService.update(terminalInfo);
 
             if (affectCount > 0) {

+ 1 - 0
src/main/java/com/jpsoft/smart/modules/base/dao/ElectricClientInfoDAO.java

@@ -13,6 +13,7 @@ public interface ElectricClientInfoDAO {
 	int insert(ElectricClientInfo entity);
 	int update(ElectricClientInfo entity);
 	int exist(String id);
+	int getCountByCNo(String customerNo,String excludeId);
 	ElectricClientInfo get(String id);
 	ElectricClientInfo getRoomMessage(String id);
 	int delete(String id);

+ 1 - 0
src/main/java/com/jpsoft/smart/modules/base/dao/ElectricMeterInfoDAO.java

@@ -14,6 +14,7 @@ public interface ElectricMeterInfoDAO {
 	int exist(String id);
 	ElectricMeterInfo get(String id);
 	int delete(String id);
+	int getCountByMNoAndUNo(String meterNo,String unitNo,String excludeId);
 	List<ElectricMeterInfo> list();
 	List<ElectricMeterInfo> search(Map<String, Object> searchParams, List<Sort> sortList);
 }

+ 1 - 0
src/main/java/com/jpsoft/smart/modules/base/dao/RoomInfoDAO.java

@@ -18,4 +18,5 @@ public interface RoomInfoDAO {
 	List<RoomInfo> search(Map<String, Object> searchParams, List<Sort> sortList);
 	List<RoomInfo> getChildren(String id);
     List<RoomInfo> findByTypeAndParentId(String type, String parentId);
+	List<String> findIdByTypeAndParentIds(String type, List<String> parentIds);
 }

+ 2 - 0
src/main/java/com/jpsoft/smart/modules/base/dao/TerminalInfoDAO.java

@@ -13,6 +13,8 @@ public interface TerminalInfoDAO {
 	int exist(String id);
 	TerminalInfo get(String id);
 	int delete(String id);
+	int getCountByName(String name,String excludeId);
 	List<TerminalInfo> list();
 	List<TerminalInfo> search(Map<String, Object> searchParams, List<Sort> sortList);
+    int updateActiveByTerminalNo(String terminalNo, boolean active);
 }

+ 22 - 0
src/main/java/com/jpsoft/smart/modules/base/entity/ElectricClientInfo.java

@@ -30,6 +30,8 @@ public class ElectricClientInfo {
 	private String updateBy;
 	private Date updateTime;
 	private Boolean delFlag;
+	private Integer rechargeTimes;
+	private Boolean active;
 	
 		/**
 	 *获取
@@ -297,4 +299,24 @@ public class ElectricClientInfo {
 	public void setArea(RoomInfo area){
 		this.area = area;
 	}
+
+	public Integer getRechargeTimes() {
+		return rechargeTimes;
+	}
+
+	public void setRechargeTimes(Integer rechargeTimes) {
+		this.rechargeTimes = rechargeTimes;
+	}
+
+	/**
+	 * 是否通电
+	 * @return
+	 */
+	public Boolean getActive() {
+		return active;
+	}
+
+	public void setActive(Boolean active) {
+		this.active = active;
+	}
 }

+ 15 - 0
src/main/java/com/jpsoft/smart/modules/base/entity/ElectricMeterInfo.java

@@ -15,6 +15,7 @@ public class ElectricMeterInfo {
 	private String name;
 	private String terminalId;
 	private String terminalName;
+	private String terminalRemark;
 	private String createBy;
 	private Date createTime;
 	private String updateBy;
@@ -100,6 +101,20 @@ public class ElectricMeterInfo {
 	public void setTerminalName(String terminalName){
 		this.terminalName = terminalName;
 	}
+	/**
+	 *获取所属终端备注
+	 */
+	public String getTerminalRemark(){
+		return terminalRemark;
+	}
+
+	/**
+	 *设置所属终端备注
+	 */
+	public void setTerminalRemark(String terminalRemark){
+		this.terminalRemark = terminalRemark;
+	}
+
 		/**
 	 *获取
 	 */

+ 9 - 0
src/main/java/com/jpsoft/smart/modules/base/entity/RechargeRecord.java

@@ -33,6 +33,7 @@ public class RechargeRecord {
 	private Date paymentTime;
 	private String openId;
 	private String errorLog;
+	private Integer dumpEnergy;
 	
 		/**
 	 *获取
@@ -354,4 +355,12 @@ public class RechargeRecord {
 	public void setArea(RoomInfo area){
 		this.area = area;
 	}
+
+	public Integer getDumpEnergy() {
+		return dumpEnergy;
+	}
+
+	public void setDumpEnergy(Integer dumpEnergy) {
+		this.dumpEnergy = dumpEnergy;
+	}
 }

+ 13 - 0
src/main/java/com/jpsoft/smart/modules/base/entity/TerminalInfo.java

@@ -18,6 +18,7 @@ public class TerminalInfo {
 	private Date updateTime;
 	private Boolean delFlag;
 	private Integer sortNo;
+	private Boolean active;
 	
 		/**
 	 *获取
@@ -140,4 +141,16 @@ public class TerminalInfo {
 	public void setSortNo(Integer sortNo){
 		this.sortNo = sortNo;
 	}
+
+	/**
+	 * 是否在线
+	 * @return
+	 */
+	public Boolean getActive() {
+		return active;
+	}
+
+	public void setActive(Boolean active) {
+		this.active = active;
+	}
 }

+ 1 - 0
src/main/java/com/jpsoft/smart/modules/base/service/ElectricClientInfoService.java

@@ -14,6 +14,7 @@ public interface ElectricClientInfoService {
 	int insert(ElectricClientInfo model);
 	int update(ElectricClientInfo model);
 	int delete(String id);
+	int getCountByCNo(String customerNo,String excludeId);
 	List<ElectricClientInfo> list();
 	Page<ElectricClientInfo> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize, List<Sort> sortList);
 

+ 1 - 0
src/main/java/com/jpsoft/smart/modules/base/service/ElectricMeterInfoService.java

@@ -13,6 +13,7 @@ public interface ElectricMeterInfoService {
 	int insert(ElectricMeterInfo model);
 	int update(ElectricMeterInfo model);
 	int delete(String id);
+	int getCountByMNoAndUNo(String meterNo,String unitNo,String excludeId);
 	List<ElectricMeterInfo> list();
 	Page<ElectricMeterInfo> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize, List<Sort> sortList);
 }

+ 1 - 0
src/main/java/com/jpsoft/smart/modules/base/service/RechargeRecordService.java

@@ -16,4 +16,5 @@ public interface RechargeRecordService {
 	RechargeRecord getBySerialNum(String erialNum);
 	List<RechargeRecord> list();
 	Page<RechargeRecord> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize, List<Sort> sortList);
+	Page<RechargeRecord> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList);
 }

+ 2 - 1
src/main/java/com/jpsoft/smart/modules/base/service/RoomInfoService.java

@@ -18,5 +18,6 @@ public interface RoomInfoService {
 	int deleteClient(RoomInfo roomInfo);
 	List<RoomInfo> list();
 	Page<RoomInfo> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize, List<Sort> sortList);
-    List<RoomInfo> findByTypeAndParentId(@Param("type") String type, @Param("parentId") String parentId);
+    List<RoomInfo> findByTypeAndParentId(@Param("type") String type,@Param("parentId") String parentId);
+	List<String> findIdByTypeAndParentIds(String type,List<String> parentIds);
 }

+ 3 - 0
src/main/java/com/jpsoft/smart/modules/base/service/TerminalInfoService.java

@@ -13,6 +13,9 @@ public interface TerminalInfoService {
 	int insert(TerminalInfo model);
 	int update(TerminalInfo model);
 	int delete(String id);
+	int getCountByName(String name,String excludeId);
 	List<TerminalInfo> list();
 	Page<TerminalInfo> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize, List<Sort> sortList);
+
+    void updateActiveByTerminalNo(String terminalNo, boolean active);
 }

+ 5 - 0
src/main/java/com/jpsoft/smart/modules/base/service/impl/ElectricClientInfoServiceImpl.java

@@ -30,6 +30,11 @@ public class ElectricClientInfoServiceImpl implements ElectricClientInfoService
 		return electricClientInfoDAO.getRoomMessage(id);
 	}
 
+	@Override
+	public int getCountByCNo(String customerNo,String excludeId){
+		return electricClientInfoDAO.getCountByCNo(customerNo,excludeId);
+	}
+
 	@Override
 	public int insert(ElectricClientInfo model) {
 		// TODO Auto-generated method stub

+ 5 - 0
src/main/java/com/jpsoft/smart/modules/base/service/impl/ElectricMeterInfoServiceImpl.java

@@ -45,6 +45,11 @@ public class ElectricMeterInfoServiceImpl implements ElectricMeterInfoService {
 		return electricMeterInfoDAO.delete(id);
 	}
 
+	@Override
+	public int getCountByMNoAndUNo(String meterNo,String unitNo,String excludeId){
+		return electricMeterInfoDAO.getCountByMNoAndUNo(meterNo,unitNo,excludeId);
+	}
+
 	@Override
 	public boolean exist(String id) {
 		// TODO Auto-generated method stub

+ 14 - 5
src/main/java/com/jpsoft/smart/modules/base/service/impl/RechargeRecordServiceImpl.java

@@ -66,10 +66,19 @@ public class RechargeRecordServiceImpl implements RechargeRecordService {
 		
 	@Override
 	public Page<RechargeRecord> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,List<Sort> sortList) {
-        Page<RechargeRecord> page = PageHelper.startPage(pageNumber,pageSize).doSelectPage(()->{
-            rechargeRecordDAO.search(searchParams,sortList);
-        });
-        
-        return page;
+		Page<RechargeRecord> page = PageHelper.startPage(pageNumber,pageSize).doSelectPage(()->{
+			rechargeRecordDAO.search(searchParams,sortList);
+		});
+
+		return page;
+	}
+
+	@Override
+	public Page<RechargeRecord> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
+		Page<RechargeRecord> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
+			rechargeRecordDAO.search(searchParams,sortList);
+		});
+
+		return page;
 	}
 }

+ 5 - 0
src/main/java/com/jpsoft/smart/modules/base/service/impl/RoomInfoServiceImpl.java

@@ -130,4 +130,9 @@ public class RoomInfoServiceImpl implements RoomInfoService {
 	public List<RoomInfo> findByTypeAndParentId(String type, String parentId) {
 		return roomInfoDAO.findByTypeAndParentId(type,parentId);
 	}
+
+	@Override
+	public List<String> findIdByTypeAndParentIds(String type,List<String> parentIds){
+		return roomInfoDAO.findIdByTypeAndParentIds(type,parentIds);
+	}
 }

+ 10 - 0
src/main/java/com/jpsoft/smart/modules/base/service/impl/TerminalInfoServiceImpl.java

@@ -58,6 +58,11 @@ public class TerminalInfoServiceImpl implements TerminalInfoService {
 		// TODO Auto-generated method stub
 		return terminalInfoDAO.list();
 	}
+
+	@Override
+	public int getCountByName(String name,String excludeId){
+		return terminalInfoDAO.getCountByName(name,excludeId);
+	}
 		
 	@Override
 	public Page<TerminalInfo> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,List<Sort> sortList) {
@@ -67,4 +72,9 @@ public class TerminalInfoServiceImpl implements TerminalInfoService {
         
         return page;
 	}
+
+	@Override
+	public void updateActiveByTerminalNo(String terminalNo, boolean active) {
+		terminalInfoDAO.updateActiveByTerminalNo(terminalNo,active);
+	}
 }

+ 1 - 1
src/main/java/com/jpsoft/smart/modules/business/controller/DemoController.java

@@ -99,7 +99,7 @@ public class DemoController {
             msp.setUnitNo(Integer.valueOf(unitNo,16));
             msp.setHouseNo(houseNo);
             msp.setCommand(MeterSendPacket.RECHARGE);
-            msp.setRechargeTimes(queryPacket.getChargeTimes() + 1);
+            msp.setRechargeTimes(queryPacket.getRechargeTimes() + 1);
             msp.setRechargeNum(num);
             msp.setRequestTime(new Date());
 

+ 38 - 20
src/main/java/com/jpsoft/smart/modules/business/controller/MobileApiController.java

@@ -3,17 +3,15 @@ package com.jpsoft.smart.modules.business.controller;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.github.pagehelper.Page;
 import com.jpsoft.smart.config.RedisConfig;
-import com.jpsoft.smart.modules.base.entity.RechargeRecord;
-import com.jpsoft.smart.modules.base.entity.RoomInfo;
-import com.jpsoft.smart.modules.base.service.InformationInfoService;
-import com.jpsoft.smart.modules.base.service.RechargeRecordService;
-import com.jpsoft.smart.modules.base.service.RoomInfoService;
+import com.jpsoft.smart.modules.base.entity.*;
+import com.jpsoft.smart.modules.base.service.*;
 import com.jpsoft.smart.modules.business.service.RechargeService;
 import com.jpsoft.smart.modules.common.dto.MessageResult;
 import com.jpsoft.smart.modules.common.dto.Sort;
 import com.jpsoft.smart.modules.common.utils.StringUtils;
 import com.jpsoft.smart.modules.communication.server.protocol.MeterReceivePacket;
-import com.jpsoft.smart.modules.pay.properties.WxPayProperties;
+import com.jpsoft.smart.modules.communication.server.protocol.MeterSendPacket;
+import com.jpsoft.smart.modules.pay.properties.WxJpsoftProperties;
 import com.jpsoft.smart.modules.sys.entity.DataDictionary;
 import com.jpsoft.smart.modules.sys.service.DataDictionaryService;
 import io.swagger.annotations.ApiImplicitParam;
@@ -48,15 +46,11 @@ public class MobileApiController {
     @Autowired
     private RechargeRecordService rechargeRecordService;
 
-    @Autowired
-    private InformationInfoService informationInfoService;
-
-
     @Autowired
     ValueOperations<String, Object> valueOperations;
 
     @Autowired
-    private WxPayProperties wxPayProperties;
+    private WxJpsoftProperties wxJpsoftProperties;
 
     /**
      * 查询房间
@@ -65,7 +59,7 @@ public class MobileApiController {
      * @return
      */
     @GetMapping("queryRoomList")
-    public MessageResult<List> queryRoomList(String type, String parentId){
+    public MessageResult<List> queryRoomList(String type,String parentId){
         MessageResult<List> msgResult = new MessageResult<>();
 
         try {
@@ -94,7 +88,7 @@ public class MobileApiController {
         MessageResult<MeterReceivePacket> msgResult = new MessageResult<>();
 
         try {
-            MeterReceivePacket mrp = rechargeService.query(roomId,10,TimeUnit.SECONDS);
+            MeterReceivePacket mrp = rechargeService.sendCommand(roomId, MeterSendPacket.READ,10,TimeUnit.SECONDS);
 
             msgResult.setData(mrp);
             msgResult.setCode(200);
@@ -190,8 +184,8 @@ public class MobileApiController {
 
         DecimalFormat df = new DecimalFormat("#.##");
 
-        //后续可能改为充钱,支付金额>=单价*数量
-        if(totalAmount.compareTo(amount)>0){
+        //支付金额>=单价*数量
+        if(totalAmount.compareTo(amount)<0){
             throw  new Exception("支付金额应为:" + df.format(totalAmount) + "!");
         }
 
@@ -205,7 +199,7 @@ public class MobileApiController {
         record.setChargingStatus("10");//10为未充电 20为充电成功
         record.setRoomId(roomId);
         record.setBuyElectricity(num);
-        record.setBuyAmount(amount);
+        record.setBuyAmount(totalAmount);
         record.setBuyType(buyType); //weipay alipay cash
 
         int affectCount = rechargeRecordService.insert(record);
@@ -225,7 +219,7 @@ public class MobileApiController {
 
         if(StringUtils.isEmpty(accessToken)){
             URL realUrl = new URL(String.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s",
-                    wxPayProperties.getAppId(),wxPayProperties.getAppSecret()));
+                    wxJpsoftProperties.getAppId(), wxJpsoftProperties.getAppSecret()));
 
             HttpsURLConnection conn = (HttpsURLConnection) realUrl.openConnection();
 
@@ -282,7 +276,7 @@ public class MobileApiController {
 
     public Map getAuthAccessToken(String code) throws Exception{
         String tokenUrl = String.format("https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code",
-                wxPayProperties.getAppId(),wxPayProperties.getAppSecret(),code);
+                wxJpsoftProperties.getAppId(), wxJpsoftProperties.getAppSecret(),code);
         String key = "AUTH_" + code;
 
         Map tokenMap = (Map)valueOperations.get(key);
@@ -313,7 +307,7 @@ public class MobileApiController {
         try {
             Map<String,Object> dataMap = new HashMap<>();
 
-            dataMap.put("appId",wxPayProperties.getAppId());
+            dataMap.put("appId", wxJpsoftProperties.getAppId());
             RechargeRecord record = createRechargeRecord(roomId,buyType,num,amount);
 
             if(record!=null){
@@ -341,7 +335,7 @@ public class MobileApiController {
         try {
             Map<String,Object> dataMap = new HashMap<>();
 
-            dataMap.put("appId",wxPayProperties.getAppId());
+            dataMap.put("appId", wxJpsoftProperties.getAppId());
             dataMap.put("ticket", getJSApiTicket());
 
             Map tokenMap = getAuthAccessToken(code);
@@ -393,6 +387,30 @@ public class MobileApiController {
         return msgResult;
     }
 
+    @GetMapping(value="queryRechargeRecord")
+    public MessageResult<RechargeRecord> queryRechargeRecord(String recordId){
+        MessageResult<RechargeRecord> msgResult = new MessageResult<>();
+
+        try {
+            if (StringUtils.isEmpty(recordId)){
+                throw new Exception("记录编号不能为空!");
+            }
+
+            RechargeRecord record = rechargeRecordService.get(recordId);
+
+            msgResult.setResult(true);
+            msgResult.setData(record);
+        }
+        catch(Exception ex){
+            log.error(ex.getMessage(),ex);
+
+            msgResult.setMessage(ex.getMessage());
+            msgResult.setResult(false);
+        }
+
+        return msgResult;
+    }
+
     @GetMapping(value="rechargeList")
     public MessageResult<Map> rechargeList(String roomId,
                                            @RequestParam(defaultValue = "1") Integer pageNum,

+ 1 - 1
src/main/java/com/jpsoft/smart/modules/business/service/RechargeService.java

@@ -5,6 +5,6 @@ import com.jpsoft.smart.modules.communication.server.protocol.MeterReceivePacket
 import java.util.concurrent.TimeUnit;
 
 public interface RechargeService {
-    MeterReceivePacket query(String roomId, int timeout, TimeUnit unit) throws  Exception;
+    MeterReceivePacket sendCommand(String roomId,int command, int timeout, TimeUnit unit) throws  Exception;
     MeterReceivePacket recharge(String roomId,int num,int timeout,TimeUnit unit) throws  Exception;
 }

+ 21 - 17
src/main/java/com/jpsoft/smart/modules/business/service/impl/RechargeServiceImpl.java

@@ -13,7 +13,6 @@ import com.jpsoft.smart.modules.communication.server.protocol.MeterReceivePacket
 import com.jpsoft.smart.modules.communication.server.protocol.MeterSendPacket;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
-
 import java.util.Date;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
@@ -36,7 +35,7 @@ public class RechargeServiceImpl implements RechargeService {
     private Map<String, ChannelWrapper> activeChannelMap;
 
     @Override
-    public MeterReceivePacket query(String roomId,int timeout,TimeUnit unit) throws  Exception {
+    public MeterReceivePacket sendCommand(String roomId,int command,int timeout,TimeUnit unit) throws  Exception {
         MeterReceivePacket mrp = null;
 
         ElectricClientInfo clientInfo = electricClientInfoService.findOneByRoomId(roomId);
@@ -62,7 +61,7 @@ public class RechargeServiceImpl implements RechargeService {
             msp.setMachineNo(Integer.valueOf(machineNo, 16));
             msp.setUnitNo(Integer.valueOf(unitNo, 16));
             msp.setHouseNo(Integer.valueOf(houseNo));
-            msp.setCommand(MeterSendPacket.READ);
+            msp.setCommand(command);
             msp.setRequestTime(new Date());
 
             activeChannelMap.get(terminalNo).getChannel().writeAndFlush(msp);
@@ -72,7 +71,7 @@ public class RechargeServiceImpl implements RechargeService {
             mrp = activeChannelMap.get(terminalNo).getReceivePacketQueue(key).poll(timeout, unit);
         }
         else{
-            throw new Exception("该房间对应电表未上线!");
+            throw new Exception(String.format("该房间对应电表%s-%s未上线!",machineNo,unitNo));
         }
 
         return mrp;
@@ -80,23 +79,28 @@ public class RechargeServiceImpl implements RechargeService {
 
     @Override
     public MeterReceivePacket recharge(String roomId, int num, int timeout,TimeUnit unit) throws Exception {
-        MeterReceivePacket queryPacket = query(roomId,timeout,unit);
+        MeterReceivePacket mrp = null;
+        MeterReceivePacket queryPacket = sendCommand(roomId,MeterSendPacket.READ,timeout,unit);
 
-        MeterSendPacket msp = new MeterSendPacket();
-        msp.setMachineNo(queryPacket.getMachineNo());
-        msp.setUnitNo(queryPacket.getUnitNo());
-        msp.setHouseNo(queryPacket.getHouseNo());
-        msp.setCommand(MeterSendPacket.RECHARGE);
-        msp.setRechargeTimes(queryPacket.getChargeTimes() + 1);
-        msp.setRechargeNum(num);
-        msp.setRequestTime(new Date());
+        if(queryPacket!=null){
+            MeterSendPacket msp = new MeterSendPacket();
+            msp.setMachineNo(queryPacket.getMachineNo());
+            msp.setUnitNo(queryPacket.getUnitNo());
+            msp.setHouseNo(queryPacket.getHouseNo());
+            msp.setCommand(MeterSendPacket.RECHARGE);
+            msp.setRechargeTimes(queryPacket.getRechargeTimes() + 1);
+            msp.setRechargeNum(num);
+            msp.setRequestTime(new Date());
 
-        activeChannelMap.get(queryPacket.getTerminalNo()).getChannel().writeAndFlush(msp);
+            activeChannelMap.get(queryPacket.getTerminalNo()).getChannel().writeAndFlush(msp);
 
-        //从队列中读取
-        String key = queryPacket.getMachineNo() + "-" + queryPacket.getUnitNo() + "-" + queryPacket.getHouseNo();
+            //从队列中读取
+
+            String key = Integer.toHexString(queryPacket.getMachineNo()) + "-" +
+                    Integer.toHexString(queryPacket.getUnitNo()) + "-" + queryPacket.getHouseNo();
 
-        MeterReceivePacket mrp = activeChannelMap.get(queryPacket.getTerminalNo()).getReceivePacketQueue(key).poll(timeout, unit);
+            mrp = activeChannelMap.get(queryPacket.getTerminalNo()).getReceivePacketQueue(key).poll(timeout, unit);
+        }
 
         return mrp;
     }

+ 79 - 0
src/main/java/com/jpsoft/smart/modules/business/task/RechargeTask.java

@@ -0,0 +1,79 @@
+package com.jpsoft.smart.modules.business.task;
+
+import com.github.pagehelper.Page;
+import com.jpsoft.smart.modules.base.entity.ElectricClientInfo;
+import com.jpsoft.smart.modules.base.entity.RechargeRecord;
+import com.jpsoft.smart.modules.base.service.ElectricClientInfoService;
+import com.jpsoft.smart.modules.base.service.RechargeRecordService;
+import com.jpsoft.smart.modules.business.service.RechargeService;
+import com.jpsoft.smart.modules.common.dto.Sort;
+import com.jpsoft.smart.modules.communication.server.protocol.MeterReceivePacket;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.*;
+import java.util.concurrent.TimeUnit;
+
+@Slf4j
+@Component
+public class RechargeTask {
+    @Autowired
+    private RechargeService rechargeService;
+
+    @Autowired
+    private RechargeRecordService rechargeRecordService;
+
+    @Autowired
+    private ElectricClientInfoService electricClientInfoService;
+
+    @Scheduled(cron = "0/30 * * * * *")
+    public void recharge(){
+        Map<String,Object> searchParams = new HashMap<>();
+
+        List<Sort> sortList = new ArrayList<>();
+        sortList.add(new Sort("create_time","asc"));
+
+        //查询已支付但未充电记录
+        searchParams.put("paymentStatus","20");
+        searchParams.put("chargingStatus","10");
+
+        Page<RechargeRecord> page = rechargeRecordService.pageSearch(searchParams,1,20,false, sortList);
+
+        for (RechargeRecord record : page) {
+            try {
+                MeterReceivePacket packet =  rechargeService.recharge(record.getRoomId(), record.getBuyElectricity(), 5, TimeUnit.SECONDS);
+
+                if(packet!=null && packet.isValidateResult()){
+                    record.setChargingStatus("20");
+                    record.setDumpEnergy(packet.getRemain()); //当前剩余电量
+
+                    ElectricClientInfo clientInfo = electricClientInfoService.findOneByRoomId(record.getRoomId());
+
+                    if (clientInfo!=null){
+                        //记录剩余电量
+                        clientInfo.setElectricityRemaining(packet.getRemain());
+
+                        //记录充电次数
+                        clientInfo.setRechargeTimes(packet.getRechargeTimes());
+
+                        clientInfo.setActive(packet.getState()!=1);
+
+                        clientInfo.setUpdateTime(new Date());
+
+                        electricClientInfoService.update(clientInfo);
+                    }
+                }
+            }
+            catch(Exception ex){
+                record.setErrorLog(ex.getMessage());
+                log.error(ex.getMessage(),ex);
+            }
+
+            record.setUpdateTime(new Date());
+
+            rechargeRecordService.update(record);
+        }
+    }
+}

+ 6 - 7
src/main/java/com/jpsoft/smart/modules/communication/server/codec/MeterDecodeHandler.java

@@ -27,11 +27,11 @@ public class MeterDecodeHandler extends ByteToMessageDecoder {
         printRecvData(ctx.channel().remoteAddress(),byteBuf);
 
         // 屏蔽非本协议的客户端 byteBuf中保留的累计接收数据,所以取第一个一定是开头
-        if (byteBuf.getUnsignedByte(0) != HB_START_SYMBOL
-         && byteBuf.getUnsignedByte(0)  != METER_START_SYMBOL) {
-            ctx.channel().close();
-            return;
-        }
+//        if (byteBuf.getUnsignedByte(0) != HB_START_SYMBOL
+//         && byteBuf.getUnsignedByte(0)  != METER_START_SYMBOL) {
+//            ctx.channel().close();
+//            return;
+//        }
 
         boolean result = parseHeartbeat(ctx,byteBuf,out);
         
@@ -50,7 +50,6 @@ public class MeterDecodeHandler extends ByteToMessageDecoder {
     private boolean parseMeterPacket(ChannelHandlerContext ctx, ByteBuf byteBuf, List<Object> out) {
         boolean result = false;
         int startIndex = -1;
-        int endIndex = -1;
 
         byteBuf.markReaderIndex();
 
@@ -99,7 +98,7 @@ public class MeterDecodeHandler extends ByteToMessageDecoder {
             meterPacket.setRemain(((buffer[9] & 0xff) << 8) + (buffer[10] & 0xff));
 
             //购电次数
-            meterPacket.setChargeTimes(((buffer[11] & 0xff) << 8) + (buffer[12] & 0xff));
+            meterPacket.setRechargeTimes(((buffer[11] & 0xff) << 8) + (buffer[12] & 0xff));
 
             //验证码1
             int valCode1 = buffer[16] & 0xff;

+ 13 - 1
src/main/java/com/jpsoft/smart/modules/communication/server/handler/ActiveChannelHandler.java

@@ -1,5 +1,6 @@
 package com.jpsoft.smart.modules.communication.server.handler;
 
+import com.jpsoft.smart.modules.base.service.TerminalInfoService;
 import com.jpsoft.smart.modules.communication.server.AttributeKeys;
 import com.jpsoft.smart.modules.communication.server.ChannelWrapper;
 import io.netty.channel.ChannelHandler;
@@ -12,6 +13,8 @@ import org.springframework.stereotype.Component;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 /**
  * 管理channel
@@ -23,6 +26,11 @@ public class ActiveChannelHandler extends ChannelInboundHandlerAdapter {
     @Autowired
     private Map<String, ChannelWrapper> activeChannelMap;
 
+    @Autowired
+    private TerminalInfoService terminalInfoService;
+
+    private ExecutorService threadPool = Executors.newFixedThreadPool(10);
+
     @Override
     public void channelActive(ChannelHandlerContext ctx) throws Exception {
         SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
@@ -35,7 +43,6 @@ public class ActiveChannelHandler extends ChannelInboundHandlerAdapter {
         ctx.channel().attr(AttributeKeys.UID).set(uid);
 
         //activeChannelMap.put(uid,new ChannelWrapper(ctx.channel()));
-
         super.channelActive(ctx);
     }
 
@@ -47,6 +54,11 @@ public class ActiveChannelHandler extends ChannelInboundHandlerAdapter {
         log.warn("连接已断开:" + uid + "," + terminalNo);
 
         if(terminalNo!=null){
+            //修改终端为离线状态
+            threadPool.submit(()-> {
+                terminalInfoService.updateActiveByTerminalNo(terminalNo,false);
+            });
+
             activeChannelMap.remove(terminalNo);
         }
 

+ 16 - 1
src/main/java/com/jpsoft/smart/modules/communication/server/handler/HeartbeatServerHandler.java

@@ -1,5 +1,6 @@
 package com.jpsoft.smart.modules.communication.server.handler;
 
+import com.jpsoft.smart.modules.base.service.TerminalInfoService;
 import com.jpsoft.smart.modules.communication.server.AttributeKeys;
 import com.jpsoft.smart.modules.communication.server.ChannelWrapper;
 import com.jpsoft.smart.modules.communication.server.protocol.HeartbeatReceivePacket;
@@ -11,6 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 @Slf4j
 @Component
@@ -19,6 +22,11 @@ public class HeartbeatServerHandler extends SimpleChannelInboundHandler<Heartbea
     @Autowired
     private Map<String, ChannelWrapper> activeChannelMap;
 
+    @Autowired
+    private TerminalInfoService terminalInfoService;
+
+    private ExecutorService threadPool = Executors.newFixedThreadPool(10);
+
     @Override
     protected void channelRead0(ChannelHandlerContext ctx, HeartbeatReceivePacket packet) throws Exception {
         log.warn(ctx.channel().remoteAddress().toString() + "对应终端号为" + packet.getTerminalNo());
@@ -30,9 +38,16 @@ public class HeartbeatServerHandler extends SimpleChannelInboundHandler<Heartbea
         **/
         if(ctx.channel().attr(AttributeKeys.TERMINAL_NO).get()==null){
             ctx.channel().attr(AttributeKeys.TERMINAL_NO).set(packet.getTerminalNo());
-            activeChannelMap.put(packet.getTerminalNo(),new ChannelWrapper(ctx.channel()));
+        }
 
+        if(!activeChannelMap.containsKey(packet.getTerminalNo())) {
+            activeChannelMap.put(packet.getTerminalNo(), new ChannelWrapper(ctx.channel()));
             log.warn(packet.getTerminalNo() + "已加入到activeChannelMap");
+
+            //设置终端为在线状态
+            threadPool.submit(()-> {
+                terminalInfoService.updateActiveByTerminalNo(packet.getTerminalNo(),true);
+            });
         }
     }
 }

+ 4 - 1
src/main/java/com/jpsoft/smart/modules/communication/server/protocol/MeterReceivePacket.java

@@ -12,8 +12,11 @@ public class MeterReceivePacket {
     private int machineNo;
     private int unitNo;
     private int houseNo;
-    private int chargeTimes;
+    private int rechargeTimes;
     private int remain;
+    /**
+     * 关闭:1,开启:0
+     */
     private int state;
     private String terminalNo;
     private boolean validateResult;

+ 21 - 0
src/main/java/com/jpsoft/smart/modules/pay/alipay/AlipayController.java

@@ -9,7 +9,9 @@ import com.alipay.api.internal.util.AlipaySignature;
 import com.alipay.api.request.AlipayTradePrecreateRequest;
 import com.alipay.api.response.AlipayTradePrecreateResponse;
 import com.ijpay.alipay.AliPayApi;
+import com.jpsoft.smart.modules.base.entity.ElectricClientInfo;
 import com.jpsoft.smart.modules.base.entity.RechargeRecord;
+import com.jpsoft.smart.modules.base.service.ElectricClientInfoService;
 import com.jpsoft.smart.modules.base.service.RechargeRecordService;
 import com.jpsoft.smart.modules.business.service.RechargeService;
 import com.jpsoft.smart.modules.common.dto.MessageResult;
@@ -50,6 +52,9 @@ public class AlipayController {
     @Autowired
     private RechargeService rechargeService;
 
+    @Autowired
+    private ElectricClientInfoService electricClientInfoService;
+
     @ApiOperation(value = "支付宝扫码支付")
     @GetMapping("/tradePrecreatePay")
     public MessageResult tradePrecreatePay(String recordId) {
@@ -151,6 +156,22 @@ public class AlipayController {
                             rechargeRecord.setErrorLog("校验失败");
                         }else {
                             rechargeRecord.setChargingStatus("20");
+                            rechargeRecord.setDumpEnergy(mp.getRemain()); //当前剩余电量
+
+                            ElectricClientInfo clientInfo = electricClientInfoService.findOneByRoomId(rechargeRecord.getRoomId());
+
+                            if (clientInfo!=null){
+                                //记录剩余电量
+                                clientInfo.setElectricityRemaining(mp.getRemain());
+
+                                //记录充电次数
+                                clientInfo.setRechargeTimes(mp.getRechargeTimes());
+                                clientInfo.setActive(mp.getState()!=1);
+
+                                clientInfo.setUpdateTime(new Date());
+
+                                electricClientInfoService.update(clientInfo);
+                            }
                         }
                     }
                 } catch (Exception e) {

+ 66 - 0
src/main/java/com/jpsoft/smart/modules/pay/properties/WxJpsoftProperties.java

@@ -0,0 +1,66 @@
+package com.jpsoft.smart.modules.pay.properties;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author 墨鱼_mo
+ * @date 2019-11-26 9:35
+ */
+
+@Data
+@ConfigurationProperties(prefix = "wx.jpsoft")
+@Component
+public class WxJpsoftProperties {
+
+    /**
+     * 设置微信公众号或者小程序等的appid
+     */
+    private String appId;
+
+    /**
+     * 设置微信公众号或者小程序等的appSecret
+     */
+    private String appSecret;
+
+    /**
+     * 微信支付商户号
+     */
+    private String mchId;
+
+    /**
+     * 微信支付商户密钥
+     */
+    private String mchKey;
+
+    /**
+     * 服务商模式下的子商户公众账号ID,普通模式请不要配置,请在配置文件中将对应项删除
+     */
+    private String subAppId;
+
+    /**
+     * 服务商模式下的子商户号,普通模式请不要配置,最好是请在配置文件中将对应项删除
+     */
+    private String subMchId;
+
+    /**
+     * apiclient_cert.p12文件的绝对路径,或者如果放在项目中,请以classpath:开头指定
+     */
+    private String keyPath;
+
+    /**
+     * 回调地址
+     */
+    private String notifyUrl;
+
+    /**
+     * 发起ip
+     */
+    private String ip;
+
+    /**
+     * 商品描述
+     */
+    private String body;
+}

+ 36 - 24
src/main/java/com/jpsoft/smart/modules/pay/weixin/WxPayController.java

@@ -7,14 +7,15 @@ import com.ijpay.core.enums.TradeType;
 import com.ijpay.core.kit.HttpKit;
 import com.ijpay.core.kit.WxPayKit;
 import com.ijpay.wxpay.WxPayApi;
-import com.ijpay.wxpay.WxPayApiConfigKit;
 import com.ijpay.wxpay.model.UnifiedOrderModel;
+import com.jpsoft.smart.modules.base.entity.ElectricClientInfo;
 import com.jpsoft.smart.modules.base.entity.RechargeRecord;
+import com.jpsoft.smart.modules.base.service.ElectricClientInfoService;
 import com.jpsoft.smart.modules.base.service.RechargeRecordService;
 import com.jpsoft.smart.modules.business.service.RechargeService;
 import com.jpsoft.smart.modules.common.dto.MessageResult;
 import com.jpsoft.smart.modules.communication.server.protocol.MeterReceivePacket;
-import com.jpsoft.smart.modules.pay.properties.WxPayProperties;
+import com.jpsoft.smart.modules.pay.properties.WxJpsoftProperties;
 import io.swagger.annotations.ApiOperation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -40,7 +41,7 @@ public class WxPayController {
     private Logger logger = LoggerFactory.getLogger(getClass());
 
     @Autowired
-    private WxPayProperties wxPayProperties;
+    private WxJpsoftProperties wxJpsoftProperties;
 
     @Autowired
     private RechargeRecordService rechargeRecordService;
@@ -48,10 +49,12 @@ public class WxPayController {
     @Autowired
     private RechargeService rechargeService;
 
+    @Autowired
+    private ElectricClientInfoService electricClientInfoService;
 
     @ApiOperation(value = "微信JSAPI支付")
     @GetMapping("/webPay")
-    public MessageResult webPay(String recordId, String openId) {
+    public MessageResult webPay(String recordId,String openId) {
         MessageResult msgResult = new MessageResult<>();
         try {
             RechargeRecord rechargeRecord = rechargeRecordService.get(recordId);
@@ -78,19 +81,19 @@ public class WxPayController {
             int wxTotalTee = rechargeRecord.getBuyAmount().multiply(new BigDecimal(100)).intValue();
             Map<String, String> params = UnifiedOrderModel
                     .builder()
-                    .appid(wxPayProperties.getAppId())
-                    .mch_id(wxPayProperties.getMchId())
-                    .sub_mch_id(wxPayProperties.getSubMchId())
+                    .appid(wxJpsoftProperties.getAppId())
+                    .mch_id(wxJpsoftProperties.getMchId())
+                    .sub_mch_id(wxJpsoftProperties.getSubMchId())
                     .nonce_str(WxPayKit.generateStr())
                     .body(rechargeRecord.getProductTheme())
                     .out_trade_no(rechargeRecord.getSerialNumber())
                     .total_fee(String.valueOf(wxTotalTee))
-                    .spbill_create_ip(wxPayProperties.getIp())
-                    .notify_url(wxPayProperties.getNotifyUrl())
+                    .spbill_create_ip(wxJpsoftProperties.getIp())
+                    .notify_url(wxJpsoftProperties.getNotifyUrl())
                     .trade_type(TradeType.JSAPI.getTradeType())
                     .openid(rechargeRecord.getOpenId())
                     .build()
-                    .createSign(wxPayProperties.getMchKey(), SignType.HMACSHA256);
+                    .createSign(wxJpsoftProperties.getMchKey(), SignType.HMACSHA256);
 
             String xmlResult = WxPayApi.pushOrder(false, params);
             logger.info(xmlResult);
@@ -113,8 +116,8 @@ public class WxPayController {
 
             String prepayId = resultMap.get("prepay_id");
 
-            Map<String, String> packageParams = WxPayKit.prepayIdCreateSign(prepayId, wxPayProperties.getAppId(),
-                    wxPayProperties.getMchKey(), SignType.HMACSHA256);
+            Map<String, String> packageParams = WxPayKit.prepayIdCreateSign(prepayId, wxJpsoftProperties.getAppId(),
+                    wxJpsoftProperties.getMchKey(), SignType.HMACSHA256);
 
             msgResult.setData(packageParams);
             msgResult.setResult(true);
@@ -140,8 +143,8 @@ public class WxPayController {
         String payTimeStr = params.get("time_end");
         Date payTime = DateUtil.parse(payTimeStr);
 
-        // 注意此处签名方式需与统一下单的签名类型一致
-        if (WxPayKit.verifyNotify(params, WxPayApiConfigKit.getWxPayApiConfig().getPartnerKey(), SignType.HMACSHA256)) {
+        // 注意此处签名方式需与统一下单的签名类型一致 WxPayApiConfigKit.getWxPayApiConfig().getPartnerKey()
+        if (WxPayKit.verifyNotify(params, wxJpsoftProperties.getMchKey(), SignType.HMACSHA256)) {
             if (WxPayKit.codeIsOk(returnCode)) {
                 // 更新订单信息
 
@@ -156,12 +159,11 @@ public class WxPayController {
 
                     rechargeRecord.setUpdateTime(new Date());
                     rechargeRecord.setUpdateBy(params.get("openid"));
-                    rechargeRecord.setBuyType("wechat");
+                    rechargeRecord.setBuyType("weipay");
                     rechargeRecord.setPaymentStatus("20");
                     rechargeRecord.setTransactionNumber(params.get("transaction_id"));
                     rechargeRecord.setPaymentTime(payTime);
 
-
                     try {
                         MeterReceivePacket mp = rechargeService.recharge(rechargeRecord.getRoomId(), rechargeRecord.getBuyElectricity(), 3, TimeUnit.SECONDS);
                         if (mp == null){
@@ -171,25 +173,38 @@ public class WxPayController {
                                 rechargeRecord.setErrorLog("校验失败");
                             }else {
                                 rechargeRecord.setChargingStatus("20");
-                            }
-                        }
+                                rechargeRecord.setDumpEnergy(mp.getRemain()); //当前剩余电量
+
+                                ElectricClientInfo clientInfo = electricClientInfoService.findOneByRoomId(rechargeRecord.getRoomId());
 
+                                if (clientInfo!=null){
+                                    //记录剩余电量
+                                    clientInfo.setElectricityRemaining(mp.getRemain());
 
+                                    //记录充电次数
+                                    clientInfo.setRechargeTimes(mp.getRechargeTimes());
+
+                                    clientInfo.setActive(mp.getState()!=1);
+
+                                    clientInfo.setUpdateTime(new Date());
+
+                                    electricClientInfoService.update(clientInfo);
+                                }
+                            }
+                        }
                     } catch (Exception e) {
                         rechargeRecord.setErrorLog(e.getMessage());
                         logger.error(e.getMessage(), e);
                         e.printStackTrace();
                     }
-                    rechargeRecordService.update(rechargeRecord);
 
+                    rechargeRecordService.update(rechargeRecord);
 
                     // 发送通知等
                     Map<String, String> xml = new HashMap<String, String>(2);
                     xml.put("return_code", "SUCCESS");
                     xml.put("return_msg", "OK");
                     return WxPayKit.toXml(xml);
-
-
                 } catch (Exception e) {
                     logger.error(e.getMessage(), e);
                     e.printStackTrace();
@@ -197,9 +212,6 @@ public class WxPayController {
             }
         }
 
-
         return null;
     }
-
-
 }

+ 1 - 1
src/main/java/com/jpsoft/smart/modules/sys/dao/MenuDAO.java

@@ -2,11 +2,11 @@ package com.jpsoft.smart.modules.sys.dao;
 
 import java.util.List;
 
-import com.jpsoft.smart.modules.common.dto.Sort;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 import com.jpsoft.smart.modules.sys.entity.Menu;
 import java.util.Map;
+import com.jpsoft.smart.modules.common.dto.Sort;
 
 @Repository
 public interface MenuDAO {

+ 1 - 1
src/main/java/com/jpsoft/smart/modules/sys/dao/PermissionDAO.java

@@ -2,11 +2,11 @@ package com.jpsoft.smart.modules.sys.dao;
 
 import java.util.List;
 
-import com.jpsoft.smart.modules.common.dto.Sort;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 import com.jpsoft.smart.modules.sys.entity.Permission;
 import java.util.Map;
+import com.jpsoft.smart.modules.common.dto.Sort;
 
 @Repository
 public interface PermissionDAO {

+ 1 - 2
src/main/java/com/jpsoft/smart/modules/sys/dao/RoleDAO.java

@@ -1,11 +1,10 @@
 package com.jpsoft.smart.modules.sys.dao;
 
 import java.util.List;
-
-import com.jpsoft.smart.modules.common.dto.Sort;
 import org.springframework.stereotype.Repository;
 import com.jpsoft.smart.modules.sys.entity.Role;
 import java.util.Map;
+import com.jpsoft.smart.modules.common.dto.Sort;
 
 @Repository
 public interface RoleDAO {

+ 1 - 2
src/main/java/com/jpsoft/smart/modules/sys/dao/RoleMenuDAO.java

@@ -1,11 +1,10 @@
 package com.jpsoft.smart.modules.sys.dao;
 
 import java.util.List;
-
-import com.jpsoft.smart.modules.common.dto.Sort;
 import org.springframework.stereotype.Repository;
 import com.jpsoft.smart.modules.sys.entity.RoleMenu;
 import java.util.Map;
+import com.jpsoft.smart.modules.common.dto.Sort;
 
 @Repository
 public interface RoleMenuDAO {

+ 1 - 2
src/main/java/com/jpsoft/smart/modules/sys/dao/RolePermissionDAO.java

@@ -1,11 +1,10 @@
 package com.jpsoft.smart.modules.sys.dao;
 
 import java.util.List;
-
-import com.jpsoft.smart.modules.common.dto.Sort;
 import org.springframework.stereotype.Repository;
 import com.jpsoft.smart.modules.sys.entity.RolePermission;
 import java.util.Map;
+import com.jpsoft.smart.modules.common.dto.Sort;
 
 @Repository
 public interface RolePermissionDAO {

+ 1 - 1
src/main/java/com/jpsoft/smart/modules/sys/dao/UserDAO.java

@@ -2,11 +2,11 @@ package com.jpsoft.smart.modules.sys.dao;
 
 import java.util.List;
 
-import com.jpsoft.smart.modules.common.dto.Sort;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 import com.jpsoft.smart.modules.sys.entity.User;
 import java.util.Map;
+import com.jpsoft.smart.modules.common.dto.Sort;
 
 @Repository
 public interface UserDAO {

+ 2 - 3
src/main/java/com/jpsoft/smart/modules/sys/dao/UserRoleDAO.java

@@ -3,11 +3,10 @@ package com.jpsoft.smart.modules.sys.dao;
 import java.util.List;
 
 import com.jpsoft.smart.modules.sys.entity.Role;
-import com.jpsoft.smart.modules.common.dto.Sort;
-import com.jpsoft.smart.modules.sys.entity.UserRole;
 import org.springframework.stereotype.Repository;
-
+import com.jpsoft.smart.modules.sys.entity.UserRole;
 import java.util.Map;
+import com.jpsoft.smart.modules.common.dto.Sort;
 
 @Repository
 public interface UserRoleDAO {

+ 3 - 4
src/main/java/com/jpsoft/smart/modules/sys/service/impl/MenuServiceImpl.java

@@ -3,14 +3,13 @@ package com.jpsoft.smart.modules.sys.service.impl;
 import java.util.List;
 import java.util.Map;
 import javax.annotation.Resource;
-
-import com.jpsoft.smart.modules.common.dto.Sort;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
 import com.jpsoft.smart.modules.sys.dao.MenuDAO;
 import com.jpsoft.smart.modules.sys.entity.Menu;
 import com.jpsoft.smart.modules.sys.service.MenuService;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
 import com.github.pagehelper.Page;
+import com.jpsoft.smart.modules.common.dto.Sort;
 import com.github.pagehelper.PageHelper;
 
 @Transactional

+ 3 - 4
src/main/java/com/jpsoft/smart/modules/sys/service/impl/PermissionServiceImpl.java

@@ -3,14 +3,13 @@ package com.jpsoft.smart.modules.sys.service.impl;
 import java.util.List;
 import java.util.Map;
 import javax.annotation.Resource;
-
-import com.jpsoft.smart.modules.common.dto.Sort;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
 import com.jpsoft.smart.modules.sys.dao.PermissionDAO;
 import com.jpsoft.smart.modules.sys.entity.Permission;
 import com.jpsoft.smart.modules.sys.service.PermissionService;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
 import com.github.pagehelper.Page;
+import com.jpsoft.smart.modules.common.dto.Sort;
 import com.github.pagehelper.PageHelper;
 
 @Transactional

+ 3 - 4
src/main/java/com/jpsoft/smart/modules/sys/service/impl/RoleMenuServiceImpl.java

@@ -3,14 +3,13 @@ package com.jpsoft.smart.modules.sys.service.impl;
 import java.util.List;
 import java.util.Map;
 import javax.annotation.Resource;
-
-import com.jpsoft.smart.modules.common.dto.Sort;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
 import com.jpsoft.smart.modules.sys.dao.RoleMenuDAO;
 import com.jpsoft.smart.modules.sys.entity.RoleMenu;
 import com.jpsoft.smart.modules.sys.service.RoleMenuService;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
 import com.github.pagehelper.Page;
+import com.jpsoft.smart.modules.common.dto.Sort;
 import com.github.pagehelper.PageHelper;
 
 @Transactional

+ 3 - 4
src/main/java/com/jpsoft/smart/modules/sys/service/impl/RolePermissionServiceImpl.java

@@ -3,14 +3,13 @@ package com.jpsoft.smart.modules.sys.service.impl;
 import java.util.List;
 import java.util.Map;
 import javax.annotation.Resource;
-
-import com.jpsoft.smart.modules.common.dto.Sort;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
 import com.jpsoft.smart.modules.sys.dao.RolePermissionDAO;
 import com.jpsoft.smart.modules.sys.entity.RolePermission;
 import com.jpsoft.smart.modules.sys.service.RolePermissionService;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
 import com.github.pagehelper.Page;
+import com.jpsoft.smart.modules.common.dto.Sort;
 import com.github.pagehelper.PageHelper;
 
 @Transactional

+ 3 - 4
src/main/java/com/jpsoft/smart/modules/sys/service/impl/RoleServiceImpl.java

@@ -3,14 +3,13 @@ package com.jpsoft.smart.modules.sys.service.impl;
 import java.util.List;
 import java.util.Map;
 import javax.annotation.Resource;
-
-import com.jpsoft.smart.modules.common.dto.Sort;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
 import com.jpsoft.smart.modules.sys.dao.RoleDAO;
 import com.jpsoft.smart.modules.sys.entity.Role;
 import com.jpsoft.smart.modules.sys.service.RoleService;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
 import com.github.pagehelper.Page;
+import com.jpsoft.smart.modules.common.dto.Sort;
 import com.github.pagehelper.PageHelper;
 
 @Transactional

+ 3 - 3
src/main/java/com/jpsoft/smart/modules/sys/service/impl/UserRoleServiceImpl.java

@@ -5,13 +5,13 @@ import java.util.Map;
 import javax.annotation.Resource;
 
 import com.jpsoft.smart.modules.sys.entity.Role;
-import com.jpsoft.smart.modules.common.dto.Sort;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
 import com.jpsoft.smart.modules.sys.dao.UserRoleDAO;
 import com.jpsoft.smart.modules.sys.entity.UserRole;
 import com.jpsoft.smart.modules.sys.service.UserRoleService;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
 import com.github.pagehelper.Page;
+import com.jpsoft.smart.modules.common.dto.Sort;
 import com.github.pagehelper.PageHelper;
 
 @Transactional

+ 3 - 4
src/main/java/com/jpsoft/smart/modules/sys/service/impl/UserServiceImpl.java

@@ -3,14 +3,13 @@ package com.jpsoft.smart.modules.sys.service.impl;
 import java.util.List;
 import java.util.Map;
 import javax.annotation.Resource;
-
-import com.jpsoft.smart.modules.common.dto.Sort;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
 import com.jpsoft.smart.modules.sys.dao.UserDAO;
 import com.jpsoft.smart.modules.sys.entity.User;
 import com.jpsoft.smart.modules.sys.service.UserService;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
 import com.github.pagehelper.Page;
+import com.jpsoft.smart.modules.common.dto.Sort;
 import com.github.pagehelper.PageHelper;
 
 @Transactional

+ 0 - 2
src/main/java/com/jpsoft/smart/modules/wechat/controller/WxController.java

@@ -442,8 +442,6 @@ public class WxController {
                 } else {
                     message = resultJSON.getString("msg");
                 }
-
-
             } else {
                 net.sf.json.JSONObject dataJSON = net.sf.json.JSONObject.fromObject(resultJSON.getString("data"));
                 List<Map> ownerInfoList = ownerInfoService.findByTel(bindPhoneVo.getPhoneNum());

+ 1 - 1
src/main/resources/application-test.yml

@@ -7,7 +7,7 @@ spring:
   datasource:
     url: jdbc:log4jdbc:mysql://127.0.0.1:3306/smart-community?autoReconnect=true&characterEncoding=utf8&serverTimezone=GMT%2B8
     username: root
-    password: slgo^Root_!Q@W#E)P(O*I
+    password: jpsoft2016
   devtools:
     restart:
       enabled: true

+ 8 - 0
src/main/resources/application.yml

@@ -118,6 +118,14 @@ wx:
     mchKey: jpsoft11111111111111111111111111
     notifyUrl: http://18891j25i6.iok.la:40309/epay-server/wxPay/payNotify
     ip: 101.37.31.116
+  jpsoft:
+    appId: wxe598c699aa68cffe
+    appSecret: ea20d2e9a36aace26b4f7654218129af
+    mchId: 1500160622
+    subMchId: 1505070291
+    mchKey: jpsoft11111111111111111111111111
+    notifyUrl: http://zldb.xiaoxinda.com:8088/smart-server/wxPay/payNotify
+    ip: 58.54.251.155
 
 doorApi:
   referer: http://58.54.251.155

+ 157 - 125
src/main/resources/mapper/base/ElectricClientInfo.xml

@@ -1,114 +1,125 @@
 <?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">
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <!-- namespace必须指向DAO接口 -->
 <mapper namespace="com.jpsoft.smart.modules.base.dao.ElectricClientInfoDAO">
-	<resultMap id="ElectricClientInfoMap" type="ElectricClientInfo">
-		<id property="id" column="id_" />
-			<result property="customerNo" column="customer_no" />
-			<result property="roomId" column="room_id" />
-			<result property="roomName" column="room_name" />
-			<result property="meterId" column="meter_id" />
-			<result property="meterName" column="meter_name" />
-			<result property="electricityTotal" column="electricity_total" />
-			<result property="amountTotal" column="amount_total" />
-			<result property="buyNum" column="buy_num" />
-			<result property="electricityRemaining" column="electricity_remaining" />
-			<result property="amountRemaining" column="amount_remaining" />
-			<result property="createBy" column="create_by" />
-			<result property="createTime" column="create_time" />
-			<result property="updateBy" column="update_by" />
-			<result property="updateTime" column="update_time" />
-			<result property="delFlag" column="del_flag" />
-			</resultMap>
-
-	<insert id="insert" parameterType="ElectricClientInfo">
-	<!--
-	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
-		select sys_guid() from dual
-	</selectKey>
-	-->
-	<![CDATA[
+    <resultMap id="ElectricClientInfoMap" type="com.jpsoft.smart.modules.base.entity.ElectricClientInfo">
+        <id property="id" column="id_"/>
+        <result property="customerNo" column="customer_no"/>
+        <result property="roomId" column="room_id"/>
+        <result property="roomName" column="room_name"/>
+        <result property="meterId" column="meter_id"/>
+        <result property="meterName" column="meter_name"/>
+        <result property="electricityTotal" column="electricity_total"/>
+        <result property="amountTotal" column="amount_total"/>
+        <result property="buyNum" column="buy_num"/>
+        <result property="electricityRemaining" column="electricity_remaining"/>
+        <result property="amountRemaining" column="amount_remaining"/>
+        <result property="createBy" column="create_by"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateBy" column="update_by"/>
+        <result property="updateTime" column="update_time"/>
+        <result property="delFlag" column="del_flag"/>
+        <result property="rechargeTimes" column="recharge_times"/>
+        <result property="active" column="active_"/>
+    </resultMap>
+    <insert id="insert" parameterType="com.jpsoft.smart.modules.base.entity.ElectricClientInfo">
+        <!--
+        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
+            select sys_guid() from dual
+        </selectKey>
+        -->
+        <![CDATA[
 		insert into base_electric_client_info
-	    (id_,customer_no,room_id,meter_id,electricity_total,amount_total,buy_num,electricity_remaining,amount_remaining,create_by,create_time,update_by,update_time,del_flag)
+	    (id_,customer_no,room_id,meter_id,electricity_total,amount_total,buy_num,
+	    electricity_remaining,amount_remaining,create_by,create_time,update_by,
+	    update_time,del_flag,recharge_times,active_)
 		values
 		(
-#{id,jdbcType=VARCHAR}
-,#{customerNo,jdbcType=VARCHAR}
-,#{roomId,jdbcType=VARCHAR}
-,#{meterId,jdbcType=VARCHAR}
-,#{electricityTotal,jdbcType= NUMERIC }
-,#{amountTotal,jdbcType= NUMERIC }
-,#{buyNum,jdbcType= NUMERIC }
-,#{electricityRemaining,jdbcType= NUMERIC }
-,#{amountRemaining,jdbcType= NUMERIC }
-,#{createBy,jdbcType=VARCHAR}
-,#{createTime,jdbcType= TIMESTAMP }
-,#{updateBy,jdbcType=VARCHAR}
-,#{updateTime,jdbcType= TIMESTAMP }
-,#{delFlag,jdbcType= NUMERIC }
+			#{id,jdbcType=VARCHAR}
+			,#{customerNo,jdbcType=VARCHAR}
+			,#{roomId,jdbcType=VARCHAR}
+			,#{meterId,jdbcType=VARCHAR}
+			,#{electricityTotal,jdbcType= NUMERIC }
+			,#{amountTotal,jdbcType= NUMERIC }
+			,#{buyNum,jdbcType= NUMERIC }
+			,#{electricityRemaining,jdbcType= NUMERIC }
+			,#{amountRemaining,jdbcType= NUMERIC }
+			,#{createBy,jdbcType=VARCHAR}
+			,#{createTime,jdbcType= TIMESTAMP }
+			,#{updateBy,jdbcType=VARCHAR}
+			,#{updateTime,jdbcType= TIMESTAMP }
+			,#{delFlag,jdbcType= NUMERIC }
+			,#{rechargeTimes,jdbcType= NUMERIC }
+			,#{active,jdbcType= NUMERIC }
 		)
 	]]>
-	</insert>
-	<delete id="delete" parameterType="string">
-		delete from base_electric_client_info where id_=#{id,jdbcType=VARCHAR}
-	</delete>
-	<update id="update" parameterType="ElectricClientInfo">
-		update base_electric_client_info
-		<set>
-				<if test="customerNo!=null">
-		customer_no=#{customerNo,jdbcType=VARCHAR},
-		</if>
-				<if test="roomId!=null">
-		room_id=#{roomId,jdbcType=VARCHAR},
-		</if>
-				<if test="meterId!=null">
-		meter_id=#{meterId,jdbcType=VARCHAR},
-		</if>
-				<if test="electricityTotal!=null">
-		electricity_total=#{electricityTotal,jdbcType= NUMERIC },
-		</if>
-				<if test="amountTotal!=null">
-		amount_total=#{amountTotal,jdbcType= NUMERIC },
-		</if>
-				<if test="buyNum!=null">
-		buy_num=#{buyNum,jdbcType= NUMERIC },
-		</if>
-				<if test="electricityRemaining!=null">
-		electricity_remaining=#{electricityRemaining,jdbcType= NUMERIC },
-		</if>
-				<if test="amountRemaining!=null">
-		amount_remaining=#{amountRemaining,jdbcType= NUMERIC },
-		</if>
-				<if test="createBy!=null">
-		create_by=#{createBy,jdbcType=VARCHAR},
-		</if>
-				<if test="createTime!=null">
-		create_time=#{createTime,jdbcType= TIMESTAMP },
-		</if>
-				<if test="updateBy!=null">
-		update_by=#{updateBy,jdbcType=VARCHAR},
-		</if>
-				<if test="updateTime!=null">
-		update_time=#{updateTime,jdbcType= TIMESTAMP },
-		</if>
-				<if test="delFlag!=null">
-		del_flag=#{delFlag,jdbcType= NUMERIC },
-		</if>
-		</set>
-	where id_=#{id}
-	</update>
-	<select id="get" parameterType="string" resultMap="ElectricClientInfoMap">
-		select a.* from base_electric_client_info a where id_=#{0} and del_flag = 0
-	</select>
-	<select id="exist" parameterType="string" resultType="int">
-		select count(*) from base_electric_client_info where id_=#{0} and del_flag = 0
-	</select>
-	<select id="list" resultMap="ElectricClientInfoMap">
-		select * from base_electric_client_info where del_flag = 0
-	</select>
-	<select id="search" parameterType="hashmap" resultMap="ElectricClientInfoMap">
-		<![CDATA[
+    </insert>
+    <delete id="delete" parameterType="string">
+        delete from base_electric_client_info where id_=#{id,jdbcType=VARCHAR}
+    </delete>
+    <update id="update" parameterType="com.jpsoft.smart.modules.base.entity.ElectricClientInfo">
+        update base_electric_client_info
+        <set>
+            <if test="customerNo!=null">
+                customer_no=#{customerNo,jdbcType=VARCHAR},
+            </if>
+            <if test="roomId!=null">
+                room_id=#{roomId,jdbcType=VARCHAR},
+            </if>
+            <if test="meterId!=null">
+                meter_id=#{meterId,jdbcType=VARCHAR},
+            </if>
+            <if test="electricityTotal!=null">
+                electricity_total=#{electricityTotal,jdbcType= NUMERIC },
+            </if>
+            <if test="amountTotal!=null">
+                amount_total=#{amountTotal,jdbcType= NUMERIC },
+            </if>
+            <if test="buyNum!=null">
+                buy_num=#{buyNum,jdbcType= NUMERIC },
+            </if>
+            <if test="electricityRemaining!=null">
+                electricity_remaining=#{electricityRemaining,jdbcType= NUMERIC },
+            </if>
+            <if test="amountRemaining!=null">
+                amount_remaining=#{amountRemaining,jdbcType= NUMERIC },
+            </if>
+            <if test="createBy!=null">
+                create_by=#{createBy,jdbcType=VARCHAR},
+            </if>
+            <if test="createTime!=null">
+                create_time=#{createTime,jdbcType= TIMESTAMP },
+            </if>
+            <if test="updateBy!=null">
+                update_by=#{updateBy,jdbcType=VARCHAR},
+            </if>
+            <if test="updateTime!=null">
+                update_time=#{updateTime,jdbcType= TIMESTAMP },
+            </if>
+            <if test="delFlag!=null">
+                del_flag=#{delFlag,jdbcType= NUMERIC },
+            </if>
+            <if test="rechargeTimes!=null">
+                recharge_times=#{rechargeTimes,jdbcType= NUMERIC },
+            </if>
+            <if test="active!=null">
+                active_=#{active,jdbcType= NUMERIC },
+            </if>
+        </set>
+        where id_=#{id}
+    </update>
+    <select id="get" parameterType="string" resultMap="ElectricClientInfoMap">
+        select a.* from base_electric_client_info a where id_=#{0} and del_flag = 0
+    </select>
+    <select id="exist" parameterType="string" resultType="int">
+        select count(*) from base_electric_client_info where id_=#{0} and del_flag = 0
+    </select>
+    <select id="list" resultMap="ElectricClientInfoMap">
+        select * from base_electric_client_info where del_flag = 0
+    </select>
+    <select id="search" parameterType="hashmap" resultMap="ElectricClientInfoMap">
+        <![CDATA[
 			select a.*,
 			b.name_ as room_name,
 			b.use_type as room_use_type,
@@ -118,28 +129,49 @@
 			left join base_room_info b on a.room_id = b.id_
 			left join base_electric_meter_info c on a.meter_id = c.id_
 		]]>
-		<where>
-			a.del_flag = 0
-			<if test="searchParams.id != null">
-				and a.ID_ like #{searchParams.id}
-			</if>
-			<if test="searchParams.customerNo != null">
-				and a.customer_no like #{searchParams.customerNo}
-			</if>
-		</where>
-		order by b.name_ asc, b.sort_no asc,a.create_time desc
-	</select>
+        <where>
+            a.del_flag = 0
+            <if test="searchParams.id != null">
+                and a.ID_ like #{searchParams.id}
+            </if>
+            <if test="searchParams.customerNo != null">
+                and a.customer_no like #{searchParams.customerNo}
+            </if>
+            <if test="searchParams.meterName != null">
+                and c.name_ like #{searchParams.meterName}
+            </if>
+            <if test="searchParams.roomsIds != null and searchParams.roomsIds.size() > 0">
+                and a.room_id in
+                <foreach item="rId" index="index" collection="searchParams.roomsIds" open="("  close=")" separator=",">
+                    #{rId}
+                </foreach>
+            </if>
+        </where>
+        order by b.name_ asc, b.sort_no asc,a.create_time desc
+    </select>
     <select id="findOneByRoomId" resultMap="ElectricClientInfoMap">
-		select * from base_electric_client_info where room_id=#{roomId} and del_flag=0 limit 1
-	</select>
-	<select id="getRoomMessage" parameterType="string" resultMap="ElectricClientInfoMap">
-		select a.*,
-		b.name_ as room_name,
-		b.use_type as room_use_type,
-		c.name_ as meter_name
-		from
-		base_electric_client_info a
-		left join base_room_info b on a.room_id = b.id_
-		left join base_electric_meter_info c on a.meter_id = c.id_ where a.id_=#{0} and a.del_flag = 0
-	</select>
+        select * from base_electric_client_info where room_id=#{roomId} and del_flag=0 limit 1
+    </select>
+    <select id="getRoomMessage" parameterType="string" resultMap="ElectricClientInfoMap">
+        select a.*,
+        b.name_ as room_name,
+        b.use_type as room_use_type,
+        c.name_ as meter_name
+        from
+        base_electric_client_info a
+        left join base_room_info b on a.room_id = b.id_
+        left join base_electric_meter_info c on a.meter_id = c.id_ where a.id_=#{0} and a.del_flag = 0
+    </select>
+
+    <select id="getCountByCNo" parameterType="string" resultType="int">
+			select count(a.id_)
+			from
+			base_electric_client_info a
+			where
+			a.customer_no = #{customerNo}
+            and a.del_flag = 0
+			<if test="excludeId != null">
+                and a.Id_ != #{excludeId}
+            </if>
+    </select>
 </mapper>

+ 15 - 3
src/main/resources/mapper/base/ElectricMeterInfo.xml

@@ -10,14 +10,13 @@
 			<result property="name" column="name_" />
 			<result property="terminalId" column="terminal_id" />
 			<result property="terminalName" column="terminal_name" />
-
+			<result property="terminalRemark" column="terminal_remark" />
 			<result property="createBy" column="create_by" />
 			<result property="createTime" column="create_time" />
 			<result property="updateBy" column="update_by" />
 			<result property="updateTime" column="update_time" />
 			<result property="delFlag" column="del_flag" />
 			</resultMap>
-
 	<insert id="insert" parameterType="ElectricMeterInfo">
 	<!--
 	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
@@ -89,7 +88,7 @@
 	</select>
 	<select id="search" parameterType="hashmap" resultMap="ElectricMeterInfoMap">
 		<![CDATA[
-			select a.*,b.name_ as terminal_name
+			select a.*,b.name_ as terminal_name,b.remark_ as terminal_remark
 			from base_electric_meter_info a
 			left join base_terminal_info b on a.terminal_id = b.id_
 		]]>
@@ -114,4 +113,17 @@
 	        ${sort.name} ${sort.order}
 	 	</foreach>
 	</select>
+
+	<select id="getCountByMNoAndUNo" parameterType="string" resultType="int">
+		select count(*)
+		from
+		base_electric_meter_info
+        where
+			meter_no = #{meterNo}
+			and unit_no = #{unitNo}
+			and del_flag = 0
+			<if test="excludeId != null">
+				and id_ != #{excludeId}
+			</if>
+	</select>
 </mapper>

+ 95 - 73
src/main/resources/mapper/base/RechargeRecord.xml

@@ -3,30 +3,30 @@
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <!-- namespace必须指向DAO接口 -->
 <mapper namespace="com.jpsoft.smart.modules.base.dao.RechargeRecordDAO">
-	<resultMap id="RechargeRecordMap" type="RechargeRecord">
+	<resultMap id="RechargeRecordMap" type="com.jpsoft.smart.modules.base.entity.RechargeRecord">
 		<id property="id" column="id_" />
-			<result property="createBy" column="create_by" />
-			<result property="createTime" column="create_time" />
-			<result property="updateBy" column="update_by" />
-			<result property="updateTime" column="update_time" />
-			<result property="delFlag" column="del_flag" />
-			<result property="serialNumber" column="serial_number" />
-			<result property="buyAmount" column="buy_amount" />
-			<result property="buyElectricity" column="buy_electricity" />
-			<result property="buyType" column="buy_type" />
-			<result property="clientId" column="client_id" />
-			<result property="customerNo" column="customer_no" />
-			<result property="roomId" column="room_id" />
-			<result property="transactionNumber" column="transaction_number" />
-			<result property="productTheme" column="product_theme" />
-			<result property="paymentStatus" column="payment_status" />
-			<result property="chargingStatus" column="charging_status" />
-			<result property="paymentTime" column="payment_time" />
-			<result property="openId" column="open_id" />
-			<result property="errorLog" column="error_log" />
-			</resultMap>
-
-	<insert id="insert" parameterType="RechargeRecord">
+		<result property="createBy" column="create_by" />
+		<result property="createTime" column="create_time" />
+		<result property="updateBy" column="update_by" />
+		<result property="updateTime" column="update_time" />
+		<result property="delFlag" column="del_flag" />
+		<result property="serialNumber" column="serial_number" />
+		<result property="buyAmount" column="buy_amount" />
+		<result property="buyElectricity" column="buy_electricity" />
+		<result property="buyType" column="buy_type" />
+		<result property="clientId" column="client_id" />
+		<result property="customerNo" column="customer_no" />
+		<result property="roomId" column="room_id" />
+		<result property="transactionNumber" column="transaction_number" />
+		<result property="productTheme" column="product_theme" />
+		<result property="paymentStatus" column="payment_status" />
+		<result property="chargingStatus" column="charging_status" />
+		<result property="paymentTime" column="payment_time" />
+		<result property="openId" column="open_id" />
+		<result property="errorLog" column="error_log" />
+		<result property="dumpEnergy" column="dump_energy" />
+	</resultMap>
+	<insert id="insert" parameterType="com.jpsoft.smart.modules.base.entity.RechargeRecord">
 	<!--
 	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
 		select sys_guid() from dual
@@ -35,66 +35,67 @@
 	<![CDATA[
 		insert into base_recharge_record
 	    (id_,create_by,create_time,update_by,update_time,del_flag,serial_number,buy_amount,buy_electricity,buy_type,client_id,customer_no,
-	    room_id,transaction_number,product_theme,payment_status,charging_status,payment_time,open_id,error_log
+	    room_id,transaction_number,product_theme,payment_status,charging_status,payment_time,open_id,error_log,dump_energy
 	    )
 		values
 		(
-#{id,jdbcType=VARCHAR}
-,#{createBy,jdbcType=VARCHAR}
-,#{createTime,jdbcType= TIMESTAMP }
-,#{updateBy,jdbcType=VARCHAR}
-,#{updateTime,jdbcType= TIMESTAMP }
-,#{delFlag,jdbcType= NUMERIC }
-,#{serialNumber,jdbcType=VARCHAR}
-,#{buyAmount,jdbcType= NUMERIC }
-,#{buyElectricity,jdbcType= NUMERIC }
-,#{buyType,jdbcType=VARCHAR}
-,#{clientId,jdbcType=VARCHAR}
-,#{customerNo,jdbcType=VARCHAR}
-,#{roomId,jdbcType=VARCHAR}
-,#{transactionNumber,jdbcType=VARCHAR}
-,#{productTheme,jdbcType=VARCHAR}
-,#{paymentStatus,jdbcType=VARCHAR}
-,#{chargingStatus,jdbcType=VARCHAR}
-,#{paymentTime,jdbcType=TIMESTAMP}
-,#{openId,jdbcType=VARCHAR}
-,#{errorLog,jdbcType=VARCHAR}
+			#{id,jdbcType=VARCHAR}
+			,#{createBy,jdbcType=VARCHAR}
+			,#{createTime,jdbcType= TIMESTAMP }
+			,#{updateBy,jdbcType=VARCHAR}
+			,#{updateTime,jdbcType= TIMESTAMP }
+			,#{delFlag,jdbcType= NUMERIC }
+			,#{serialNumber,jdbcType=VARCHAR}
+			,#{buyAmount,jdbcType= NUMERIC }
+			,#{buyElectricity,jdbcType= NUMERIC }
+			,#{buyType,jdbcType=VARCHAR}
+			,#{clientId,jdbcType=VARCHAR}
+			,#{customerNo,jdbcType=VARCHAR}
+			,#{roomId,jdbcType=VARCHAR}
+			,#{transactionNumber,jdbcType=VARCHAR}
+			,#{productTheme,jdbcType=VARCHAR}
+			,#{paymentStatus,jdbcType=VARCHAR}
+			,#{chargingStatus,jdbcType=VARCHAR}
+			,#{paymentTime,jdbcType=TIMESTAMP}
+			,#{openId,jdbcType=VARCHAR}
+			,#{errorLog,jdbcType=VARCHAR}
+			,#{dumpEnergy,jdbcType= NUMERIC}
 		)
 	]]>
 	</insert>
 	<delete id="delete" parameterType="string">
 		delete from base_recharge_record where id_=#{id,jdbcType=VARCHAR}
 	</delete>
-	<update id="update" parameterType="RechargeRecord">
+	<update id="update" parameterType="com.jpsoft.smart.modules.base.entity.RechargeRecord">
 		update base_recharge_record
 		<set>
-				<if test="createBy!=null">
-		create_by=#{createBy,jdbcType=VARCHAR},
-		</if>
-				<if test="createTime!=null">
-		create_time=#{createTime,jdbcType= TIMESTAMP },
-		</if>
-				<if test="updateBy!=null">
-		update_by=#{updateBy,jdbcType=VARCHAR},
-		</if>
-				<if test="updateTime!=null">
-		update_time=#{updateTime,jdbcType= TIMESTAMP },
-		</if>
-				<if test="delFlag!=null">
-		del_flag=#{delFlag,jdbcType= NUMERIC },
-		</if>
-				<if test="serialNumber!=null">
-		serial_number=#{serialNumber,jdbcType=VARCHAR},
-		</if>
-				<if test="buyAmount!=null">
-		buy_amount=#{buyAmount,jdbcType= NUMERIC },
-		</if>
-				<if test="buyElectricity!=null">
-		buy_electricity=#{buyElectricity,jdbcType= NUMERIC },
-		</if>
-				<if test="buyType!=null">
-		buy_type=#{buyType,jdbcType=VARCHAR},
-		</if>
+			<if test="createBy!=null">
+			create_by=#{createBy,jdbcType=VARCHAR},
+			</if>
+			<if test="createTime!=null">
+			create_time=#{createTime,jdbcType= TIMESTAMP },
+			</if>
+			<if test="updateBy!=null">
+			update_by=#{updateBy,jdbcType=VARCHAR},
+			</if>
+			<if test="updateTime!=null">
+			update_time=#{updateTime,jdbcType= TIMESTAMP },
+			</if>
+			<if test="delFlag!=null">
+			del_flag=#{delFlag,jdbcType= NUMERIC },
+			</if>
+			<if test="serialNumber!=null">
+			serial_number=#{serialNumber,jdbcType=VARCHAR},
+			</if>
+			<if test="buyAmount!=null">
+			buy_amount=#{buyAmount,jdbcType= NUMERIC },
+			</if>
+			<if test="buyElectricity!=null">
+			buy_electricity=#{buyElectricity,jdbcType= NUMERIC },
+			</if>
+			<if test="buyType!=null">
+			buy_type=#{buyType,jdbcType=VARCHAR},
+			</if>
 			<if test="clientId!=null">
 				client_id=#{clientId,jdbcType=VARCHAR},
 			</if>
@@ -126,8 +127,11 @@
 			<if test="errorLog!=null">
 				error_log=#{errorLog,jdbcType=VARCHAR},
 			</if>
+			<if test="dumpEnergy!=null">
+				dump_energy=#{dumpEnergy,jdbcType=NUMERIC},
+			</if>
 		</set>
-	where id_=#{id}
+		where id_=#{id}
 	</update>
 	<select id="get" parameterType="string" resultMap="RechargeRecordMap">
 		select a.* from base_recharge_record a where id_=#{0} and del_flag = 0
@@ -150,6 +154,24 @@
 			<if test="searchParams.serialNumber != null">
 				and serial_number like #{searchParams.serialNumber}
 			</if>
+			<if test="searchParams.roomId != null">
+				and room_id = #{searchParams.roomId}
+			</if>
+			<if test="searchParams.paymentStatus != null">
+				and payment_status = #{searchParams.paymentStatus}
+			</if>
+			<if test="searchParams.chargingStatus != null">
+				and charging_status = #{searchParams.chargingStatus}
+			</if>
+			<if test="searchParams.buyType != null">
+				and buy_type = #{searchParams.buyType}
+			</if>
+			<if test="searchParams.roomsIds != null and searchParams.roomsIds.size() > 0">
+				and room_id in
+				<foreach item="rId" index="index" collection="searchParams.roomsIds" open="("  close=")" separator=",">
+					#{rId}
+				</foreach>
+			</if>
 		</where>
 		<foreach item="sort" collection="sortList"  open="order by" separator=",">
 	        ${sort.name} ${sort.order}

+ 17 - 2
src/main/resources/mapper/base/RoomInfo.xml

@@ -19,9 +19,8 @@
 		<result property="delFlag" column="del_flag" />
 		<result property="hasChildren" column="has_children" />
 		<association property="useTypeN" column="use_type" select="com.jpsoft.smart.modules.sys.dao.DataDictionaryDAO.getName"/>
-		<!--<association property="children" column="id_" select="com.jpsoft.smart.modules.base.dao.RoomInfoDAO.getChildren"/>-->
+		<!--<association property="children" column="id_" select="com.jpsoft.smartt.modules.base.dao.RoomInfoDAO.getChildren"/>-->
 	</resultMap>
-
 	<insert id="insert" parameterType="RoomInfo">
 	<!--
 	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
@@ -150,4 +149,20 @@
 		</where>
 		order by sort_no asc
 	</select>
+	<select id="findIdByTypeAndParentIds" resultType="string">
+		select id_ from base_room_info
+		<where>
+			del_flag = 0
+			<if test="type!=null">
+				and type_=#{type}
+			</if>
+			<if test="parentIds != null and parentIds.size() > 0">
+				and parent_id in
+				<foreach item="pId" index="index" collection="parentIds" open="("  close=")" separator=",">
+					#{pId}
+				</foreach>
+			</if>
+		</where>
+		order by sort_no asc
+	</select>
 </mapper>

+ 109 - 89
src/main/resources/mapper/base/TerminalInfo.xml

@@ -1,100 +1,120 @@
 <?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">
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <!-- namespace必须指向DAO接口 -->
 <mapper namespace="com.jpsoft.smart.modules.base.dao.TerminalInfoDAO">
-	<resultMap id="TerminalInfoMap" type="TerminalInfo">
-		<id property="id" column="id_" />
-			<result property="name" column="name_" />
-			<result property="remark" column="remark_" />
-			<result property="createBy" column="create_by" />
-			<result property="createTime" column="create_time" />
-			<result property="updateBy" column="update_by" />
-			<result property="updateTime" column="update_time" />
-			<result property="delFlag" column="del_flag" />
-			<result property="sortNo" column="sort_no" />
-			</resultMap>
-
-	<insert id="insert" parameterType="TerminalInfo">
-	<!--
-	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
-		select sys_guid() from dual
-	</selectKey>
-	-->
-	<![CDATA[
+    <resultMap id="TerminalInfoMap" type="com.jpsoft.smart.modules.base.entity.TerminalInfo">
+        <id property="id" column="id_"/>
+        <result property="name" column="name_"/>
+        <result property="remark" column="remark_"/>
+        <result property="createBy" column="create_by"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateBy" column="update_by"/>
+        <result property="updateTime" column="update_time"/>
+        <result property="delFlag" column="del_flag"/>
+        <result property="sortNo" column="sort_no"/>
+        <result property="active" column="active_"/>
+    </resultMap>
+    <insert id="insert" parameterType="com.jpsoft.smart.modules.base.entity.TerminalInfo">
+        <!--
+        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
+            select sys_guid() from dual
+        </selectKey>
+        -->
+        <![CDATA[
 		insert into base_terminal_info
-	    (id_,name_,remark_,create_by,create_time,update_by,update_time,del_flag,sort_no)
+	    (id_,name_,remark_,create_by,create_time,
+	    update_by,update_time,del_flag,sort_no,active_)
 		values
 		(
-#{id,jdbcType=VARCHAR}
-,#{name,jdbcType=VARCHAR}
-,#{remark,jdbcType=VARCHAR}
-,#{createBy,jdbcType=VARCHAR}
-,#{createTime,jdbcType= TIMESTAMP }
-,#{updateBy,jdbcType=VARCHAR}
-,#{updateTime,jdbcType= TIMESTAMP }
-,#{delFlag,jdbcType= NUMERIC }
-,#{sortNo,jdbcType= NUMERIC }
+			#{id,jdbcType=VARCHAR}
+			,#{name,jdbcType=VARCHAR}
+			,#{remark,jdbcType=VARCHAR}
+			,#{createBy,jdbcType=VARCHAR}
+			,#{createTime,jdbcType= TIMESTAMP }
+			,#{updateBy,jdbcType=VARCHAR}
+			,#{updateTime,jdbcType= TIMESTAMP }
+			,#{delFlag,jdbcType= NUMERIC }
+			,#{sortNo,jdbcType= NUMERIC }
+			,#{active,jdbcType= BIT }
 		)
 	]]>
-	</insert>
-	<delete id="delete" parameterType="string">
-		delete from base_terminal_info where id_=#{id,jdbcType=VARCHAR}
-	</delete>
-	<update id="update" parameterType="TerminalInfo">
-		update base_terminal_info
-		<set>
-				<if test="name!=null">
-		name_=#{name,jdbcType=VARCHAR},
-		</if>
-				<if test="remark!=null">
-		remark_=#{remark,jdbcType=VARCHAR},
-		</if>
-				<if test="createBy!=null">
-		create_by=#{createBy,jdbcType=VARCHAR},
-		</if>
-				<if test="createTime!=null">
-		create_time=#{createTime,jdbcType= TIMESTAMP },
-		</if>
-				<if test="updateBy!=null">
-		update_by=#{updateBy,jdbcType=VARCHAR},
-		</if>
-				<if test="updateTime!=null">
-		update_time=#{updateTime,jdbcType= TIMESTAMP },
-		</if>
-				<if test="delFlag!=null">
-		del_flag=#{delFlag,jdbcType= NUMERIC },
-		</if>
-			<if test="sortNo!=null">
-				sort_no=#{sortNo,jdbcType= NUMERIC },
-			</if>
-		</set>
-	where id_=#{id}
-	</update>
-	<select id="get" parameterType="string" resultMap="TerminalInfoMap">
-		select  a.* from base_terminal_info a where del_flag = 0 and id_=#{0}
-	</select>
-	<select id="exist" parameterType="string" resultType="int">
-		select count(*) from base_terminal_info where del_flag = 0 and id_=#{0}
-	</select>
-	<select id="list" resultMap="TerminalInfoMap">
-		select * from base_terminal_info where del_flag = 0 order by sort_no asc
-	</select>
-	<select id="search" parameterType="hashmap" resultMap="TerminalInfoMap">
-		<![CDATA[
+    </insert>
+    <delete id="delete" parameterType="string">
+        delete from base_terminal_info where id_=#{id,jdbcType=VARCHAR}
+    </delete>
+    <update id="update" parameterType="com.jpsoft.smart.modules.base.entity.TerminalInfo">
+        update base_terminal_info
+        <set>
+            <if test="name!=null">
+                name_=#{name,jdbcType=VARCHAR},
+            </if>
+            <if test="remark!=null">
+                remark_=#{remark,jdbcType=VARCHAR},
+            </if>
+            <if test="createBy!=null">
+                create_by=#{createBy,jdbcType=VARCHAR},
+            </if>
+            <if test="createTime!=null">
+                create_time=#{createTime,jdbcType= TIMESTAMP },
+            </if>
+            <if test="updateBy!=null">
+                update_by=#{updateBy,jdbcType=VARCHAR},
+            </if>
+            <if test="updateTime!=null">
+                update_time=#{updateTime,jdbcType= TIMESTAMP },
+            </if>
+            <if test="delFlag!=null">
+                del_flag=#{delFlag,jdbcType= NUMERIC },
+            </if>
+            <if test="sortNo!=null">
+                sort_no=#{sortNo,jdbcType= NUMERIC },
+            </if>
+            <if test="active!=null">
+                active_=#{active,jdbcType= BIT },
+            </if>
+        </set>
+        where id_=#{id}
+    </update>
+    <update id="updateActiveByTerminalNo">
+        update base_terminal_info
+        set active_=#{active,jdbcType= BIT},update_time=now()
+        where name_=#{terminalNo,jdbcType=VARCHAR}
+    </update>
+    <select id="get" parameterType="string" resultMap="TerminalInfoMap">
+        select a.* from base_terminal_info a where del_flag = 0 and id_=#{0}
+    </select>
+    <select id="exist" parameterType="string" resultType="int">
+        select count(*) from base_terminal_info where del_flag = 0 and id_=#{0}
+    </select>
+    <select id="list" resultMap="TerminalInfoMap">
+        select * from base_terminal_info where del_flag = 0 order by sort_no asc
+    </select>
+    <select id="search" parameterType="hashmap" resultMap="TerminalInfoMap">
+        <![CDATA[
 			select * from base_terminal_info
 		]]>
-		<where>
-			del_flag = 0
-			<if test="searchParams.id != null">
-				and ID_ like #{searchParams.id}
-			</if>
-			<if test="searchParams.name != null">
-				and name_ like #{searchParams.name}
-			</if>
-		</where>
-		<foreach item="sort" collection="sortList"  open="order by" separator=",">
-	        ${sort.name} ${sort.order}
-	 	</foreach>
-	</select>
+        <where>
+            del_flag = 0
+            <if test="searchParams.id != null">
+                and ID_ like #{searchParams.id}
+            </if>
+            <if test="searchParams.name != null">
+                and name_ like #{searchParams.name}
+            </if>
+        </where>
+        <foreach item="sort" collection="sortList" open="order by" separator=",">
+            ${sort.name} ${sort.order}
+        </foreach>
+    </select>
+
+    <select id="getCountByName" parameterType="string" resultType="int">
+        select count(*) from base_terminal_info
+        where
+        name_ = #{name}
+        and del_flag = 0
+        <if test="excludeId != null">
+            and id_ != #{excludeId}
+        </if>
+    </select>
 </mapper>