xiao547607 há 5 anos atrás
pai
commit
09619e0a0d

+ 26 - 4
src/main/java/com/jpsoft/epay/modules/base/controller/ElectricClientInfoController.java

@@ -7,7 +7,6 @@ import com.jpsoft.epay.modules.base.service.ElectricClientInfoService;
 import com.jpsoft.epay.modules.base.service.RoomInfoService;
 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.sys.service.DataDictionaryService;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
@@ -226,6 +225,7 @@ public class ElectricClientInfoController {
     @RequestMapping(value = "pageList",method = RequestMethod.POST)
     public MessageResult<Map> pageList(
             String id,
+            @RequestParam(name="customerNo",defaultValue = "") String customerNo,
             @RequestParam(name="pageIndex",defaultValue = "1") int pageIndex,
             @RequestParam(name="pageSize",defaultValue = "10") int pageSize,
             @RequestAttribute String subject){
@@ -238,17 +238,39 @@ public class ElectricClientInfoController {
         Map<String,Object> searchParams = new HashMap<>();
 
         List<Sort> sortList = new ArrayList<>();
-        sortList.add(new Sort("a.create_time","desc"));
 
         if (StringUtils.isNotEmpty(id)) {
             searchParams.put("id","%" + id + "%");
         }
+        if (StringUtils.isNotEmpty(customerNo)) {
+            searchParams.put("customerNo",customerNo);
+        }
 
         Page<ElectricClientInfo> page = electricClientInfoService.pageSearch(searchParams,pageIndex,pageSize,sortList);
 
-        msgResult.setResult(true);
-        msgResult.setData(PojoUtils.pageWrapper(page));
+        List<ElectricClientInfo> resultClientList = new ArrayList<>();
+        List<ElectricClientInfo> clientList = page.getResult();
+        for(ElectricClientInfo clientInfo :clientList){
+            RoomInfo room = roomInfoService.get(clientInfo.getRoomId());
+            RoomInfo building = roomInfoService.get(room.getParentId());
+            RoomInfo area = roomInfoService.get(building.getParentId());
+
+            clientInfo.setRoom(room);
+            clientInfo.setBuilding(building);
+            clientInfo.setArea(area);
+            resultClientList.add(clientInfo);
+        }
 
+        Map<String,Object> pageMap = new HashMap<>();
+        pageMap.put("recordsTotal",page.getTotal());
+        pageMap.put("recordsFiltered",page.getTotal());
+        pageMap.put("totalPage",page.getPages());
+        pageMap.put("pageNumber",page.getPageNum());
+        pageMap.put("pageSize",page.getPageSize());
+        pageMap.put("data", resultClientList);
+
+        msgResult.setResult(true);
+        msgResult.setData(pageMap);
         return msgResult;
     }
 }

+ 49 - 15
src/main/java/com/jpsoft/epay/modules/base/controller/RechargeRecordController.java

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

+ 4 - 1
src/main/java/com/jpsoft/epay/modules/base/controller/RoomInfoController.java

@@ -2,6 +2,7 @@ package com.jpsoft.epay.modules.base.controller;
 
 import com.github.pagehelper.Page;
 import com.jpsoft.epay.modules.base.entity.RoomInfo;
+import com.jpsoft.epay.modules.base.service.ElectricClientInfoService;
 import com.jpsoft.epay.modules.base.service.RoomInfoService;
 import com.jpsoft.epay.modules.common.dto.MessageResult;
 import com.jpsoft.epay.modules.common.dto.Sort;
@@ -22,6 +23,8 @@ public class RoomInfoController {
 
     @Autowired
     private RoomInfoService roomInfoService;
+    @Autowired
+    private ElectricClientInfoService electricClientInfoService;
 
     @ApiOperation(value="创建空记录")
     @GetMapping("create")
@@ -150,7 +153,7 @@ public class RoomInfoController {
             roomInfo.setUpdateBy(subject);
             roomInfo.setUpdateTime(new Date());
 
-            int affectCount = roomInfoService.update(roomInfo);
+            int affectCount = roomInfoService.deleteAll(roomInfo);
 
             if (affectCount > 0) {
                 msgResult.setResult(true);

+ 28 - 15
src/main/java/com/jpsoft/epay/modules/base/entity/ElectricClientInfo.java

@@ -13,10 +13,11 @@ public class ElectricClientInfo {
 	private String id;
 	private String customerNo;
 	private String roomId;
+	private RoomInfo room;
+	private RoomInfo building;
+	private RoomInfo area;
 	private String roomName;
 	private String roomUseType;
-	private String roomUseTypeN;
-	private String roomUseTypeV;
 	private String meterId;
 	private String meterName;
 	private Integer electricityTotal;
@@ -256,32 +257,44 @@ public class ElectricClientInfo {
 	public void setRoomUseType(String roomUseType){
 		this.roomUseType = roomUseType;
 	}
+
 	/**
-	 *获取用电类型翻译
+	 *获取
 	 */
-	public String getRoomUseTypeN(){
-		return roomUseTypeN;
+	public RoomInfo getRoom(){
+		return room;
 	}
 
 	/**
-	 *设置用电类型翻译
+	 *设置
 	 */
-	public void setRoomUseTypeN(String roomUseTypeN){
-		this.roomUseTypeN = roomUseTypeN;
+	public void setRoom(RoomInfo room){
+		this.room = room;
 	}
-
 	/**
-	 *获取用电类型
+	 *获取
 	 */
-	public String getRoomUseTypeV(){
-		return roomUseTypeV;
+	public RoomInfo getBuilding(){
+		return building;
 	}
 
 	/**
-	 *设置用电类型
+	 *设置
 	 */
-	public void setRoomUseTypeV(String roomUseTypeV){
-		this.roomUseTypeV = roomUseTypeV;
+	public void setBuilding(RoomInfo building){
+		this.building = building;
+	}
+	/**
+	 *获取
+	 */
+	public RoomInfo getArea(){
+		return area;
 	}
 
+	/**
+	 *设置
+	 */
+	public void setArea(RoomInfo area){
+		this.area = area;
+	}
 }

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

@@ -21,6 +21,9 @@ public class RechargeRecord {
 	private Integer buyElectricity;
 	private String buyType;
 	private String roomId;
+	private RoomInfo room;
+	private RoomInfo building;
+	private RoomInfo area;
 	private String clientId;
 	private String customerNo;
 	private String transactionNumber;
@@ -305,4 +308,48 @@ public class RechargeRecord {
 	public void setErrorLog(String errorLog){
 		this.errorLog = errorLog;
 	}
+
+
+
+	/**
+	 *获取
+	 */
+	public RoomInfo getRoom(){
+		return room;
+	}
+
+	/**
+	 *设置
+	 */
+	public void setRoom(RoomInfo room){
+		this.room = room;
+	}
+
+	/**
+	 *获取
+	 */
+	public RoomInfo getBuilding(){
+		return building;
+	}
+
+	/**
+	 *设置
+	 */
+	public void setBuilding(RoomInfo building){
+		this.building = building;
+	}
+
+	/**
+	 *获取
+	 */
+	public RoomInfo getArea(){
+		return area;
+	}
+
+	/**
+	 *设置
+	 */
+	public void setArea(RoomInfo area){
+		this.area = area;
+	}
 }

+ 6 - 3
src/main/java/com/jpsoft/epay/modules/base/service/RoomInfoService.java

@@ -1,18 +1,21 @@
 package com.jpsoft.epay.modules.base.service;
 
-import java.util.List;
-import java.util.Map;
-import com.jpsoft.epay.modules.base.entity.RoomInfo;
 import com.github.pagehelper.Page;
+import com.jpsoft.epay.modules.base.entity.RoomInfo;
 import com.jpsoft.epay.modules.common.dto.Sort;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+import java.util.Map;
+
 public interface RoomInfoService {
 	RoomInfo get(String id);
 	boolean exist(String id);
 	int insert(RoomInfo model);
 	int update(RoomInfo model);
 	int delete(String id);
+	int deleteAll(RoomInfo model);
+	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);

+ 58 - 0
src/main/java/com/jpsoft/epay/modules/base/service/impl/RoomInfoServiceImpl.java

@@ -2,7 +2,9 @@ package com.jpsoft.epay.modules.base.service.impl;
 
 import com.github.pagehelper.Page;
 import com.github.pagehelper.PageHelper;
+import com.jpsoft.epay.modules.base.dao.ElectricClientInfoDAO;
 import com.jpsoft.epay.modules.base.dao.RoomInfoDAO;
+import com.jpsoft.epay.modules.base.entity.ElectricClientInfo;
 import com.jpsoft.epay.modules.base.entity.RoomInfo;
 import com.jpsoft.epay.modules.base.service.RoomInfoService;
 import com.jpsoft.epay.modules.common.dto.Sort;
@@ -10,6 +12,7 @@ import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -19,6 +22,10 @@ public class RoomInfoServiceImpl implements RoomInfoService {
 	@Resource(name="roomInfoDAO")
 	private RoomInfoDAO roomInfoDAO;
 
+	@Resource(name="electricClientInfoDAO")
+	private ElectricClientInfoDAO electricClientInfoDAO;
+
+
 	@Override
 	public RoomInfo get(String id) {
 		// TODO Auto-generated method stub
@@ -45,6 +52,57 @@ public class RoomInfoServiceImpl implements RoomInfoService {
 		return roomInfoDAO.delete(id);
 	}
 
+	@Override
+	public int deleteAll(RoomInfo roomInfo){
+		if("1".equals(roomInfo.getType())){
+			//园区
+			//删除楼栋和房间和户号信息
+			List<RoomInfo> buildingList = findByTypeAndParentId("2",roomInfo.getId());
+			for(RoomInfo buliding : buildingList){
+				buliding.setDelFlag(true);
+				roomInfo.setUpdateBy(roomInfo.getUpdateBy());
+				roomInfo.setUpdateTime(new Date());
+				update(buliding);
+				List<RoomInfo> roomInfoList = findByTypeAndParentId("3",buliding.getId());
+				for(RoomInfo room : roomInfoList){
+					room.setDelFlag(true);
+					room.setUpdateBy(roomInfo.getUpdateBy());
+					room.setUpdateTime(new Date());
+					update(room);
+					deleteClient(room);
+				}
+			}
+		}else if("2".equals(roomInfo.getType())){
+			//楼栋
+			//删除房间和户号信息
+			List<RoomInfo> roomInfoList = findByTypeAndParentId("3",roomInfo.getId());
+			for(RoomInfo room : roomInfoList){
+				room.setDelFlag(true);
+				room.setUpdateBy(roomInfo.getUpdateBy());
+				room.setUpdateTime(new Date());
+				update(room);
+				deleteClient(room);
+			}
+		}else if("3".equals(roomInfo.getType())){
+			//删除户号信息
+			deleteClient(roomInfo);
+		}
+		return roomInfoDAO.update(roomInfo);
+	}
+
+	@Override
+	public int deleteClient(RoomInfo roomInfo) {
+		ElectricClientInfo electricClientInfo = electricClientInfoDAO.findOneByRoomId(roomInfo.getId());
+		if(electricClientInfo != null) {
+			electricClientInfo.setDelFlag(true);
+			electricClientInfo.setUpdateBy(roomInfo.getUpdateBy());
+			electricClientInfo.setUpdateTime(new Date());
+			return electricClientInfoDAO.update(electricClientInfo);
+		}else {
+			return 0;
+		}
+	}
+
 	@Override
 	public boolean exist(String id) {
 		// TODO Auto-generated method stub

+ 16 - 18
src/main/resources/mapper/base/ElectricClientInfo.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <!-- namespace必须指向DAO接口 -->
 <mapper namespace="com.jpsoft.epay.modules.base.dao.ElectricClientInfoDAO">
@@ -7,9 +7,8 @@
 		<id property="id" column="id_" />
 			<result property="customerNo" column="customer_no" />
 			<result property="roomId" column="room_id" />
-			<result property="meterId" column="meter_id" />
 			<result property="roomName" column="room_name" />
-			<result property="roomUseType" column="room_use_type" />
+			<result property="meterId" column="meter_id" />
 			<result property="meterName" column="meter_name" />
 			<result property="electricityTotal" column="electricity_total" />
 			<result property="amountTotal" column="amount_total" />
@@ -21,8 +20,6 @@
 			<result property="updateBy" column="update_by" />
 			<result property="updateTime" column="update_time" />
 			<result property="delFlag" column="del_flag" />
-			<association property="roomUseTypeN" column="room_use_type" select="com.jpsoft.epay.modules.sys.dao.DataDictionaryDAO.getName"/>
-			<association property="roomUseTypeV" column="room_use_type" select="com.jpsoft.epay.modules.sys.dao.DataDictionaryDAO.getValue"/>
 			</resultMap>
 	<insert id="insert" parameterType="ElectricClientInfo">
 	<!--
@@ -103,16 +100,6 @@
 	<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="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="exist" parameterType="string" resultType="int">
 		select count(*) from base_electric_client_info where id_=#{0} and del_flag = 0
 	</select>
@@ -135,12 +122,23 @@
 			<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>
-		<foreach item="sort" collection="sortList"  open="order by" separator=",">
-	        ${sort.name} ${sort.order}
-	 	</foreach>
+		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>
 </mapper>