Procházet zdrojové kódy

sz 流水信息创建等功能

xiao547607 před 5 roky
rodič
revize
1ec1676a3a

+ 123 - 44
src/main/java/com/jpsoft/epay/modules/base/controller/RechargeRecordController.java

@@ -2,16 +2,18 @@ package com.jpsoft.epay.modules.base.controller;
 
 import com.github.pagehelper.Page;
 import com.jpsoft.epay.modules.base.entity.ElectricClientInfo;
+import com.jpsoft.epay.modules.base.entity.ElectricMeterInfo;
 import com.jpsoft.epay.modules.base.entity.RechargeRecord;
-import com.jpsoft.epay.modules.base.service.ElectricClientInfoService;
-import com.jpsoft.epay.modules.base.service.RechargeRecordService;
-import com.jpsoft.epay.modules.base.service.RoomInfoService;
+import com.jpsoft.epay.modules.base.entity.TerminalInfo;
+import com.jpsoft.epay.modules.base.service.*;
+import com.jpsoft.epay.modules.business.service.RechargeService;
 import com.jpsoft.epay.modules.common.dto.MessageResult;
 import com.jpsoft.epay.modules.common.dto.Sort;
 import com.jpsoft.epay.modules.common.utils.PojoUtils;
+import com.jpsoft.epay.modules.common.utils.StringUtils;
+import com.jpsoft.epay.modules.communication.server.protocol.MeterReceivePacket;
 import com.jpsoft.epay.modules.sys.service.DataDictionaryService;
 import io.swagger.annotations.ApiOperation;
-import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -32,19 +34,21 @@ public class RechargeRecordController {
     private DataDictionaryService dataDictionaryService;
     @Autowired
     private RoomInfoService roomInfoService;
+    @Autowired
+    private TerminalInfoService terminalInfoService;
+    @Autowired
+    private ElectricMeterInfoService electricMeterInfoService;
+    @Autowired
+    private RechargeService rechargeService;
 
     @ApiOperation(value="创建空记录")
-    @GetMapping("create/{clientId}")
-    public MessageResult<Map<String,Object>> create(@PathVariable("clientId") String clientId,@RequestAttribute String subject){
-        MessageResult<Map<String,Object>> msgResult = new MessageResult<>();
+    @GetMapping("create")
+    public MessageResult<RechargeRecord> create(@RequestAttribute String subject){
+        MessageResult<RechargeRecord> msgResult = new MessageResult<>();
 
-        ElectricClientInfo clientInfo = electricClientInfoService.getRoomMessage(clientId);        //充值类型
-        Map<String,Object> resultMaps = new HashMap();
+        RechargeRecord rechargeRecord = new RechargeRecord();
 
-        resultMaps.put("useTypeN",clientInfo.getRoomUseTypeN());//中文翻译
-        resultMaps.put("useTypeV",clientInfo.getRoomUseTypeV());//值
-
-        msgResult.setData(resultMaps);
+        msgResult.setData(rechargeRecord);
         msgResult.setResult(true);
 
         return msgResult;
@@ -234,55 +238,84 @@ public class RechargeRecordController {
     }
 
 
-    @ApiOperation(value="添加信息")
+    @ApiOperation(value="保存电量")
     @PostMapping("saveRecord")
-    public MessageResult<RechargeRecord> saveRecord(@RequestBody RechargeRecord rechargeRecord,@RequestAttribute String subject){
+    public MessageResult<RechargeRecord> saveRecord(@RequestBody RechargeRecord rechargeRecord,@RequestAttribute String subject) throws  Exception {
         MessageResult<RechargeRecord> msgResult = new MessageResult<>();
-
         try {
-            rechargeRecord.setId(UUID.randomUUID().toString());
-            rechargeRecord.setDelFlag(false);
-            rechargeRecord.setCreateBy(subject);
-            rechargeRecord.setCreateTime(new Date());
 
-            int affectCount = rechargeRecordService.insert(rechargeRecord);
 
-            if (affectCount > 0) {
+            ElectricClientInfo clientInfo = electricClientInfoService.findOneByRoomId(rechargeRecord.getRoomId());
 
-                ElectricClientInfo electricClientInfo = electricClientInfoService.get(rechargeRecord.getClientId());
-                //新增电量等信息补充到电表中
-                //BigDecimal buyAmount = rechargeRecord.getBuyAmount();//购买金额
-                Integer buyElectricity = rechargeRecord.getBuyElectricity();//购买电量
+            if(clientInfo==null){
+                throw new Exception("该房间没有绑定电表!");
+            }
 
-                Integer electricityRemaining = electricClientInfo.getElectricityRemaining();//剩余电量
-                if(electricityRemaining == null){
-                    electricityRemaining = 0;
-                }
-                Integer newElectricity = electricityRemaining + buyElectricity;//最新的剩余电量
+            ElectricMeterInfo meterInfo = electricMeterInfoService.get(clientInfo.getMeterId());
+            TerminalInfo terminalInfo = terminalInfoService.get(meterInfo.getTerminalId());
 
-                Integer electricityTotal = electricClientInfo.getElectricityTotal();//总电量
-                if(electricityTotal == null){
-                    electricityTotal = 0;
-                }
-                Integer newElectricityTotal = electricityTotal + buyElectricity;//最新的总电量
+            if (terminalInfo==null){
+                throw new Exception("该房间绑定电表没有设置对应终端!");
+            }
 
+            //新增电量等信息补充到电表中
+            //BigDecimal buyAmount = rechargeRecord.getBuyAmount();//购买金额
+            Integer buyElectricity = rechargeRecord.getBuyElectricity();//购买电量
 
-                electricClientInfo.setElectricityRemaining(newElectricity);
-                electricClientInfo.setElectricityTotal(newElectricityTotal);
+            //充电
+            //MeterReceivePacket meterReceivePacket = rechargeService.recharge(clientInfo.getRoomId(), buyElectricity, 10, TimeUnit.SECONDS);
+            MeterReceivePacket meterReceivePacket = new MeterReceivePacket();
+            meterReceivePacket.setValidateResult(true);
 
-                electricClientInfo.setUpdateBy(subject);
-                electricClientInfo.setUpdateTime(new Date());
-                electricClientInfoService.update(electricClientInfo);
+            if (meterReceivePacket == null) {
+                rechargeRecord.setErrorLog("线下充电失败-返回null");
+            } else {
+                if (meterReceivePacket.isValidateResult()) {
+                    //返回参数如果为true则表示充值成功
+
+                    //剩余电量
+                    Integer electricityRemaining = clientInfo.getElectricityRemaining();
+                    if (electricityRemaining == null) {
+                        electricityRemaining = 0;
+                    }
+                    Integer newElectricity = electricityRemaining + buyElectricity;//计算后电量
+
+                    Integer electricityTotal = clientInfo.getElectricityTotal();//原总电量
+                    if (electricityTotal == null) {
+                        electricityTotal = 0;
+                    }
+                    Integer newElectricityTotal = electricityTotal + buyElectricity;//最新的总电量
+
+                    clientInfo.setElectricityRemaining(newElectricity);
+                    clientInfo.setElectricityTotal(newElectricityTotal);
+
+                    clientInfo.setUpdateBy(subject);
+                    clientInfo.setUpdateTime(new Date());
+                    electricClientInfoService.update(clientInfo);
+                } else {
+                    rechargeRecord.setErrorLog("线下充电失败-返回状态为false");
+                }
+            }
 
+            rechargeRecord.setId(UUID.randomUUID().toString());
+            rechargeRecord.setDelFlag(false);
+            rechargeRecord.setCreateBy(subject);
+            rechargeRecord.setCreateTime(new Date());
+            rechargeRecord.setBuyType("线下支付");
+            rechargeRecord.setRoomId(clientInfo.getRoomId());
+            rechargeRecord.setPaymentTime(new Date());
+            rechargeRecord.setCustomerNo(clientInfo.getCustomerNo());
+
+            int affectCount = rechargeRecordService.insert(rechargeRecord);
+            if (affectCount > 0) {
                 msgResult.setResult(true);
                 msgResult.setData(rechargeRecord);
             } else {
                 msgResult.setResult(false);
                 msgResult.setMessage("数据库添加失败");
             }
-        }
-        catch(Exception ex){
-            logger.error(ex.getMessage(),ex);
+        } catch (Exception ex) {
+            logger.error(ex.getMessage(), ex);
 
             msgResult.setResult(false);
             msgResult.setMessage(ex.getMessage());
@@ -290,4 +323,50 @@ public class RechargeRecordController {
 
         return msgResult;
     }
+
+
+    @ApiOperation(value="线下充值前查询房间信息")
+    @GetMapping("queryRoomMessage/{clientId}")
+    public MessageResult<Map<String,Object>> queryRoomMessage(@PathVariable("clientId") String clientId,@RequestAttribute String subject){
+        MessageResult<Map<String,Object>> msgResult = new MessageResult<>();
+
+        ElectricClientInfo clientInfo = electricClientInfoService.getRoomMessage(clientId);        //充值类型
+        Map<String,Object> resultMaps = new HashMap();
+
+        resultMaps.put("useTypeN",clientInfo.getRoomUseTypeN());//中文翻译
+        resultMaps.put("useTypeV",clientInfo.getRoomUseTypeV());//值
+
+        msgResult.setData(resultMaps);
+        msgResult.setResult(true);
+
+        return msgResult;
+    }
+
+    @ApiOperation(value="创建交易信息")
+    @GetMapping("createSerial")
+    public MessageResult<String> createSerial(@RequestAttribute String subject){
+        MessageResult<String> msgResult = new MessageResult<>();
+
+        String serialNumber = StringUtils.getOutTradeNo();
+
+        RechargeRecord rechargeRecord = new RechargeRecord();
+        rechargeRecord.setId(UUID.randomUUID().toString());
+        rechargeRecord.setDelFlag(false);
+        rechargeRecord.setCreateBy(subject);
+        rechargeRecord.setCreateTime(new Date());
+        rechargeRecord.setSerialNumber(serialNumber);
+        rechargeRecord.setPaymentStatus("10");//10为未支付 20为支付成功
+        rechargeRecord.setChargingStatus("10");//10为未充电 20为充电成功
+
+        int affectCount = rechargeRecordService.insert(rechargeRecord);
+        if (affectCount > 0) {
+            msgResult.setResult(true);
+            msgResult.setData(serialNumber);
+        } else {
+            msgResult.setResult(false);
+            msgResult.setMessage("创建失败");
+        }
+        return msgResult;
+    }
+
 }

+ 3 - 3
src/main/java/com/jpsoft/epay/modules/base/entity/RechargeRecord.java

@@ -27,7 +27,7 @@ public class RechargeRecord {
 	private String productTheme;
 	private String paymentStatus;
 	private String chargingStatus;
-	private String paymentTime;
+	private Date paymentTime;
 	private String openId;
 	private String errorLog;
 	
@@ -267,14 +267,14 @@ public class RechargeRecord {
 	/**
 	 *获取支付时间
 	 */
-	public String getPaymentTime(){
+	public Date getPaymentTime(){
 		return paymentTime;
 	}
 
 	/**
 	 *设置支付时间
 	 */
-	public void setPaymentTime(String paymentTime){
+	public void setPaymentTime(Date paymentTime){
 		this.paymentTime = paymentTime;
 	}
 

+ 1 - 1
src/main/resources/mapper/base/RechargeRecord.xml

@@ -117,7 +117,7 @@
 				charging_status=#{chargingStatus,jdbcType=VARCHAR},
 			</if>
 			<if test="paymentTime!=null">
-				payment_time=#{paymentTime,jdbcType=VARCHAR},
+				payment_time=#{paymentTime,jdbcType=TIMESTAMP},
 			</if>
 			<if test="openId!=null">
 				open_id=#{openId,jdbcType=VARCHAR},