作者 shenhailong

统计剩余水费电费的余额

package com.sunyo.energy.location.controller;
import com.github.pagehelper.PageInfo;
import com.google.gson.internal.$Gson$Preconditions;
import com.sunyo.energy.location.controller.response.ResultJson;
import com.sunyo.energy.location.dao.LocationMapper;
import com.sunyo.energy.location.dao.PayRecordsMapper;
import com.sunyo.energy.location.dao.WaterEleCountMoneyMapper;
import com.sunyo.energy.location.model.Location;
import com.sunyo.energy.location.model.PayRecords;
import com.sunyo.energy.location.model.WaterEleCountMoney;
import com.sunyo.energy.location.service.ElectricityMeterService;
import com.sunyo.energy.location.service.PayOrderService;
import com.sunyo.energy.location.service.WaterMeterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* Created by XYH on 2019/12/16.
* 订单查询,新增,更新,删除
... ... @@ -41,10 +43,13 @@ public class PayOrderController {
@Autowired
private LocationMapper locationMapper;
@Autowired
WaterEleCountMoneyMapper waterEleCountMoneyMapperl;
@ApiOperation(value = "查询缴费订单")
@RequestMapping("/list")
public PageInfo<PayRecords> getOrder(@RequestParam(value = "pageSize", required = false, defaultValue = "1") int pageSize,
@RequestParam(value = "pageNum", required = false, defaultValue = "5") int pageNum,
public PageInfo<PayRecords> getOrder(@RequestParam(value = "pageSize", required = false, defaultValue = "100000") int pageSize,
@RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
@RequestParam(value = "orderNumber", required = false) String orderNumber,
@RequestParam(value = "payTime", required = false) String payTime,
@RequestParam(value = "username", required = false) String username,
... ... @@ -133,4 +138,13 @@ public class PayOrderController {
}
}
@ApiOperation(value = "水电剩余余额统计")
@GetMapping("/waterEleCount")
public ResultJson waterEleCount() throws Exception {
List<WaterEleCountMoney> waterEleCountMonies = waterEleCountMoneyMapperl.selectByPrimaryKey();
return new ResultJson("200", "success", waterEleCountMonies);
}
}
... ...
... ... @@ -14,7 +14,7 @@ public interface LocationMapper {
int insertSelective(Location record);
List<Location> selectByPrimaryKey(Integer id);
List<Location> selectByPrimaryKey();
List<Location> selectAll(Integer id);
... ...
package com.sunyo.energy.location.dao;
import com.sunyo.energy.location.model.WaterEleCountMoney;
import java.util.List;
public interface WaterEleCountMoneyMapper {
int deleteByPrimaryKey(Integer id);
int insert(WaterEleCountMoney record);
int insertSelective(WaterEleCountMoney record);
List<WaterEleCountMoney> selectByPrimaryKey();
int updateByPrimaryKeySelective(WaterEleCountMoney record);
int updateByPrimaryKey(WaterEleCountMoney record);
}
\ No newline at end of file
... ...
package com.sunyo.energy.location.model;
import java.math.BigDecimal;
import java.util.Date;
public class WaterEleCountMoney {
private Integer id;
private BigDecimal wmMoney;
private BigDecimal emMoney;
private Date createDate;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public BigDecimal getWmMoney() {
return wmMoney;
}
public void setWmMoney(BigDecimal wmMoney) {
this.wmMoney = wmMoney;
}
public BigDecimal getEmMoney() {
return emMoney;
}
public void setEmMoney(BigDecimal emMoney) {
this.emMoney = emMoney;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
}
\ No newline at end of file
... ...
... ... @@ -3,6 +3,8 @@ package com.sunyo.energy.location.service;
import com.github.pagehelper.PageInfo;
import com.sunyo.energy.location.model.PayRecords;
import java.util.Map;
/**
* Created by XYH on 2019/12/16.
*/
... ... @@ -15,4 +17,6 @@ public interface PayOrderService {
int ediOrder(PayRecords payRecords);
int delOrder(PayRecords payRecords);
void waterEleCount() throws Exception;
}
... ...
... ... @@ -3,15 +3,21 @@ package com.sunyo.energy.location.service.imp;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sunyo.energy.location.dao.LocationMapper;
import com.sunyo.energy.location.dao.PayRecordsMapper;
import com.sunyo.energy.location.model.PayRecords;
import com.sunyo.energy.location.dao.WaterEleCountMoneyMapper;
import com.sunyo.energy.location.model.*;
import com.sunyo.energy.location.service.ElectricityMeterService;
import com.sunyo.energy.location.service.PayOrderService;
import com.sunyo.energy.location.service.WaterMeterService;
import com.sunyo.energy.location.utils.AllUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.math.BigDecimal;
import java.util.*;
/**
* Created by XYH on 2019/12/16.
... ... @@ -21,6 +27,18 @@ public class PayOrderImpl implements PayOrderService {
@Autowired
PayRecordsMapper recordsMapper;
@Autowired
LocationMapper locationMapper;
@Autowired
WaterMeterService waterMeterService;
@Autowired
ElectricityMeterService electricityMeterService;
@Autowired
WaterEleCountMoneyMapper waterEleCountMoneyMapper;
@Override
public PageInfo<PayRecords> getOrder(int pageSize, int pageNum, String orderNumber, String payTime,
... ... @@ -65,4 +83,42 @@ public class PayOrderImpl implements PayOrderService {
public int delOrder(PayRecords payRecords) {
return recordsMapper.deleteByPrimaryKey(payRecords.getId());
}
/**
* 剩余水电费统计
* @throws Exception
*/
@Override
@Scheduled(cron = "0 0 * * * ?")
public void waterEleCount() throws Exception {
Map<String, Object> map = new HashMap<>();
// 水量
Double wmMoney = 0.00;
// 电费
Double eeMoney = 0.00;
// 查询 公寓所有水电编号
List<Location> locations = locationMapper.selectByPrimaryKey();
for (Location location: locations){
// 剩余水量 查询累加
WaterMeter realTime = waterMeterService.findRealTime(location.getWmid());
String subtraction = AllUtils.nubmerSubtraction(realTime.getWmSacc(), realTime.getWmLacc());
BigDecimal wmBigDecimal = new BigDecimal(subtraction);
wmMoney += wmBigDecimal.doubleValue();
// 剩余电费 累加
ElectricityMeter energyInfoForRealTime = electricityMeterService.getEnergyInfoForRealTime(location.getEeid());
if (energyInfoForRealTime != null) {
// 电费累加
eeMoney+=energyInfoForRealTime.getBalance().doubleValue();
}
}
BigDecimal moneyWm = new BigDecimal(wmMoney);
BigDecimal bigDecimal = new BigDecimal(4.5);
WaterEleCountMoney waterEleCountMoney = new WaterEleCountMoney();
waterEleCountMoney.setCreateDate(new Date());
waterEleCountMoney.setEmMoney(new BigDecimal(eeMoney).setScale(2,BigDecimal.ROUND_HALF_UP));
waterEleCountMoney.setWmMoney(moneyWm.multiply(bigDecimal).setScale(2,BigDecimal.ROUND_HALF_UP));
waterEleCountMoney.setId(2);
waterEleCountMoneyMapper.updateByPrimaryKeySelective(waterEleCountMoney);
}
}
... ...
... ... @@ -13,11 +13,11 @@
<sql id="Base_Column_List">
id, adrName, parent, type, wm_id, ee_id
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
<select id="selectByPrimaryKey" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from location
where id = #{id,jdbcType=INTEGER}
where wm_id != '' and wm_id is not null and ee_id is not null and ee_id != ''
</select>
<select id="selectAll" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.sunyo.energy.location.dao.WaterEleCountMoneyMapper" >
<resultMap id="BaseResultMap" type="com.sunyo.energy.location.model.WaterEleCountMoney" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="wm_money" property="wmMoney" jdbcType="DECIMAL" />
<result column="em_money" property="emMoney" jdbcType="DECIMAL" />
<result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Base_Column_List" >
id, wm_money, em_money, create_date
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from water_ele_count_money
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from water_ele_count_money
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.sunyo.energy.location.model.WaterEleCountMoney" >
insert into water_ele_count_money (id, wm_money, em_money,
create_date)
values (#{id,jdbcType=INTEGER}, #{wmMoney,jdbcType=DECIMAL}, #{emMoney,jdbcType=DECIMAL},
#{createDate,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.sunyo.energy.location.model.WaterEleCountMoney" >
insert into water_ele_count_money
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="wmMoney != null" >
wm_money,
</if>
<if test="emMoney != null" >
em_money,
</if>
<if test="createDate != null" >
create_date,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="wmMoney != null" >
#{wmMoney,jdbcType=DECIMAL},
</if>
<if test="emMoney != null" >
#{emMoney,jdbcType=DECIMAL},
</if>
<if test="createDate != null" >
#{createDate,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.sunyo.energy.location.model.WaterEleCountMoney" >
update water_ele_count_money
<set >
<if test="wmMoney != null" >
wm_money = #{wmMoney,jdbcType=DECIMAL},
</if>
<if test="emMoney != null" >
em_money = #{emMoney,jdbcType=DECIMAL},
</if>
<if test="createDate != null" >
create_date = #{createDate,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.sunyo.energy.location.model.WaterEleCountMoney" >
update water_ele_count_money
set wm_money = #{wmMoney,jdbcType=DECIMAL},
em_money = #{emMoney,jdbcType=DECIMAL},
create_date = #{createDate,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...