修改定时计费模型

This commit is contained in:
yuyang 2022-02-23 14:28:22 +08:00
parent 172ce9fb0a
commit bf8f19df85
7 changed files with 415 additions and 9 deletions

View File

@ -8,6 +8,7 @@ import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.common.log.annotation.Log;
import com.xhpc.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;
import com.xhpc.common.core.domain.R;
@ -62,6 +63,39 @@ public class XhpcTimingChargingModelController extends BaseController {
return xhpcTimingChargingModelService.updateXhpcTimingChargingModel(timingChargingModelId);
}
/**
* 详情
*
* @return
*/
@GetMapping(value = "/getXhpcTimingChargingModelMessage")
public R getXhpcTimingChargingModelMessage(Long timingChargingModelId) {
return xhpcTimingChargingModelService.getXhpcTimingChargingModelMessage(timingChargingModelId);
}
/**
* 编辑定时计费模型
* @param xhpcTimingChargingModelDto
* @return
*/
@Log(title = "编辑定时计费模型", businessType = BusinessType.INSERT)
@PostMapping(value = "/updateXhpcTimingChargingModel")
public R updateXhpcTimingChargingModel(HttpServletRequest request, @RequestBody XhpcTimingChargingModelDto xhpcTimingChargingModelDto) {
if(xhpcTimingChargingModelDto.getTimingChargingModelId()==null){
return R.fail("定时计费模型id比传");
}
return xhpcTimingChargingModelService.addXhpcTimingChargingModel(request,xhpcTimingChargingModelDto);
}
/**
* 每5分钟执行一次
*/
@Scheduled(cron = "0 0/5 * * * ?")
public void getXhpcTimingChargingModelCron(){
xhpcTimingChargingModelService.getXhpcTimingChargingModelCron();
}
}

View File

@ -1,5 +1,6 @@
package com.xhpc.charging.station.mapper;
import com.xhpc.common.domain.XhpcTimingChargingCacheRateModel;
import com.xhpc.common.domain.XhpcTimingChargingModel;
import com.xhpc.common.domain.XhpcTimingChargingTime;
import com.xhpc.common.domain.XhpcTtimingChargingRate;
@ -14,7 +15,7 @@ import java.util.Map;
*/
public interface XhpcTimingChargingModelMapper {
List<Map<String, Object>> list(@Param("reason") String reason,@Param("status") Integer status,@Param("startTime") String startTime,@Param("endTime") String endTime,@Param("chargingStationId") Long chargingStationId,@Param("tenantId")String tenantId);
List<Map<String, Object>> list(@Param("status") Integer status,@Param("startTime") String startTime,@Param("endTime") String endTime,@Param("chargingStationId") Long chargingStationId,@Param("tenantId")String tenantId);
int insertXhpcTimingChargingModel(XhpcTimingChargingModel xhpcTimingChargingModel);
@ -23,7 +24,21 @@ public interface XhpcTimingChargingModelMapper {
int insertXhpcTimingChargingTime(XhpcTimingChargingTime xhpcTimingChargingTime);
XhpcTimingChargingModel getXhpcTimingChargingModelById(@Param("timingChargingModelId")Long timingChargingModelId);
int insertXhpcTimingChargingCacheRateModel(XhpcTimingChargingCacheRateModel xhpcTimingChargingCacheRateModel);
XhpcTimingChargingModel getXhpcTimingChargingModelById(@Param("timingChargingModelId")Long timingChargingModelId,@Param("tenantId")String tenantId);
int updateXhpcTimingChargingModel(XhpcTimingChargingModel xhpcTimingChargingModel);
int updateXhpcTtimingChargingRate(@Param("timingChargingModelId")Long timingChargingModelId);
int updateXhpcTimingChargingTime(@Param("timingChargingModelId")Long timingChargingModelId);
int updateXhpcTimingChargingCacheRateModel(@Param("timingChargingModelId")Long timingChargingModelId);
List<Map<String, Object>> getXhpcTimingChargingRateList(@Param("timingChargingModelId") Long timingChargingModelId);
List<Map<String, Object>> getXhpcTimingChargingTimeTypeList(@Param("timingChargingModelId") Long timingChargingModelId);
Map<String, Object> getXhpcTimingChargingModelMapById(@Param("timingChargingModelId")Long timingChargingModelId,@Param("tenantId")String tenantId);
}

View File

@ -2,6 +2,8 @@ package com.xhpc.charging.station.service;
import com.xhpc.common.api.dto.XhpcTimingChargingModelDto;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.domain.XhpcTimingChargingModel;
import org.apache.ibatis.annotations.Param;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@ -19,4 +21,11 @@ public interface IXhpcTimingChargingModelService {
R updateXhpcTimingChargingModel(Long timingChargingModelId);
R getXhpcTimingChargingModelMessage(Long timingChargingModelId);
XhpcTimingChargingModel getXhpcTimingChargingModelById(Long timingChargingModelId);
int updateXhpcTimingChargingModel(XhpcTimingChargingModel xhpcTimingChargingModel);
void getXhpcTimingChargingModelCron();
}

View File

@ -8,6 +8,7 @@ import com.xhpc.common.api.dto.XhpcTimingChargingModelDto;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.service.BaseService;
import com.xhpc.common.data.redis.CacheRateModel;
import com.xhpc.common.domain.*;
import com.xhpc.common.security.service.TokenService;
import com.xhpc.system.api.model.LoginUser;
@ -18,6 +19,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -40,7 +42,7 @@ public class XhpcTimingChargingModelServiceImpl extends BaseService implements I
LoginUser loginUser = tokenService.getLoginUser(request);
if(loginUser !=null){
startPage();
return xhpcTimingChargingModelMapper.list(reason,status,startTime,endTime,chargingStationId,loginUser.getTenantId());
return xhpcTimingChargingModelMapper.list(status,startTime,endTime,chargingStationId,loginUser.getTenantId());
}
return new ArrayList<>();
}
@ -132,11 +134,24 @@ public class XhpcTimingChargingModelServiceImpl extends BaseService implements I
xhpcTimingChargingModel.setTenantId(loginUser.getTenantId());
xhpcTimingChargingModel.setCreateTime(new Date());
xhpcTimingChargingModel.setChargingStationId(chargingStationId);
int i = xhpcTimingChargingModelMapper.insertXhpcTimingChargingModel(xhpcTimingChargingModel);
if (i == 0) {
return R.fail("1006", "定时计费模型添加失败");
if(xhpcTimingChargingModelDto.getTimingChargingModelId() !=null){
xhpcTimingChargingModel.setTimingChargingModelId(xhpcTimingChargingModelDto.getTimingChargingModelId());
xhpcTimingChargingModelMapper.updateXhpcTimingChargingModel(xhpcTimingChargingModel);
//删除之前添加的费率和费率时段
xhpcTimingChargingModelMapper.updateXhpcTtimingChargingRate(xhpcTimingChargingModel.getTimingChargingModelId());
xhpcTimingChargingModelMapper.updateXhpcTimingChargingTime(xhpcTimingChargingModel.getTimingChargingModelId());
xhpcTimingChargingModelMapper.updateXhpcTimingChargingCacheRateModel(xhpcTimingChargingModel.getTimingChargingModelId());
}else{
int i = xhpcTimingChargingModelMapper.insertXhpcTimingChargingModel(xhpcTimingChargingModel);
if (i == 0) {
return R.fail("1006", "定时计费模型添加失败");
}
}
Long timingChargingModelId = xhpcTimingChargingModel.getTimingChargingModelId();
//添加费率
Map<String, Long> map = new HashMap<>();
List<XhpcRateDto> xhpcRateList = xhpcTimingChargingModelDto.getXhpcRateList();
@ -172,6 +187,8 @@ public class XhpcTimingChargingModelServiceImpl extends BaseService implements I
//存费率时段从Map中获取费率id
//每个时间段都要存
//返回计费模型 24:00 转成 00:00
XhpcRateTimeDto[] xhpcRateTimeDtosArr = new XhpcRateTimeDto[xhpcRateTimeList.size()];
xhpcRateTimeList.toArray(xhpcRateTimeDtosArr);
XhpcRateTimeDto[] xhpcRateTimeDtos = bubbleSort(xhpcRateTimeDtosArr);
@ -184,7 +201,10 @@ public class XhpcTimingChargingModelServiceImpl extends BaseService implements I
}
//默认费率类型值
String rateValue = xhpcTimingChargingModelDto.getDefaultPeriodId();
String[] tfPricesSeq = new String[48];
for (int k = 0; k <48 ; k++) {
tfPricesSeq[k]=rateValue;
}
for (int k = 0; k < list.size(); k++) {
XhpcRateTimeDto xhpcRateTimeDto = list.get(k);
String startTime = xhpcRateTimeDto.getStartTime();
@ -195,6 +215,9 @@ public class XhpcTimingChargingModelServiceImpl extends BaseService implements I
int st= Integer.valueOf(str);
String endT = endTime.split(":")[0];
int end= Integer.valueOf(endT);
for (int l = st*2; l <end*2 ; l++) {
tfPricesSeq[l]=rateValues;
}
if(list.size() == 1){
if(!"00:00:00".equals(xhpcRateTimeDto.getStartTime())){
if(rateValue ==null || "".equals(rateValue)){
@ -255,13 +278,76 @@ public class XhpcTimingChargingModelServiceImpl extends BaseService implements I
}
}
}
XhpcTimingChargingCacheRateModel xhpcTimingChargingCacheRateModel=new XhpcTimingChargingCacheRateModel();
xhpcTimingChargingCacheRateModel.setLossRate(0);
xhpcTimingChargingCacheRateModel.setTenantId(xhpcTimingChargingModel.getTenantId());
xhpcTimingChargingCacheRateModel.setTimingChargingModelId(timingChargingModelId);
BigDecimal valueSec = new BigDecimal(100000);
boolean t1 = true;
boolean t2 = true;
boolean t3 = true;
boolean t4 = true;
for (XhpcRateDto xhpcRateDto : xhpcRateList) {
BigDecimal powerFee = xhpcRateDto.getPowerFee();
BigDecimal serviceFee = xhpcRateDto.getServiceFee();
String id = xhpcRateDto.getId();
int i1 = powerFee.multiply(valueSec).intValue();
int i2 = serviceFee.multiply(valueSec).intValue();
if ("00".equals(id)) {
xhpcTimingChargingCacheRateModel.setOnePrice(i1);
xhpcTimingChargingCacheRateModel.setOneSvcPrice(i2);
t1 = false;
} else if ("01".equals(id)) {
xhpcTimingChargingCacheRateModel.setTwoPrice(i1);
xhpcTimingChargingCacheRateModel.setTwoSvcPrice(i2);
t2 = false;
} else if ("02".equals(id)) {
xhpcTimingChargingCacheRateModel.setThreePrice(i1);
xhpcTimingChargingCacheRateModel.setThreeSvcPrice(i2);
t3 = false;
} else if ("03".equals(id)) {
xhpcTimingChargingCacheRateModel.setFourPrice(i1);
xhpcTimingChargingCacheRateModel.setFourSvcPrice(i2);
t4 = false;
}
}
if (t1) {
xhpcTimingChargingCacheRateModel.setOneSvcPrice(0);
xhpcTimingChargingCacheRateModel.setOnePrice(0);
}
if (t2) {
xhpcTimingChargingCacheRateModel.setTwoSvcPrice(0);
xhpcTimingChargingCacheRateModel.setTwoPrice(0);
}
if (t3) {
xhpcTimingChargingCacheRateModel.setThreeSvcPrice(0);
xhpcTimingChargingCacheRateModel.setThreePrice(0);
}
if (t4) {
xhpcTimingChargingCacheRateModel.setFourSvcPrice(0);
xhpcTimingChargingCacheRateModel.setFourPrice(0);
}
StringBuilder st = new StringBuilder();
for (int i = 0; i < tfPricesSeq.length; i++) {
if(i==0){
st = new StringBuilder(tfPricesSeq[i]);
}else{
st.append(",").append(tfPricesSeq[i]);
}
}
xhpcTimingChargingCacheRateModel.setTfPricesSeq(st.toString());
xhpcTimingChargingModelMapper.insertXhpcTimingChargingCacheRateModel(xhpcTimingChargingCacheRateModel);
return R.ok();
}
@Override
public R updateXhpcTimingChargingModel(Long timingChargingModelId) {
LoginUser loginUser = tokenService.getLoginUser();
if(loginUser ==null){
return R.ok();
}
//查询是否是未执行状态
XhpcTimingChargingModel xhpcTimingChargingModel = xhpcTimingChargingModelMapper.getXhpcTimingChargingModelById(timingChargingModelId);
XhpcTimingChargingModel xhpcTimingChargingModel = xhpcTimingChargingModelMapper.getXhpcTimingChargingModelById(timingChargingModelId,loginUser.getTenantId());
if(xhpcTimingChargingModel ==null){
return R.fail("数据不存在");
}else if (xhpcTimingChargingModel.getStatus()==0){
@ -275,6 +361,40 @@ public class XhpcTimingChargingModelServiceImpl extends BaseService implements I
}
}
@Override
public R getXhpcTimingChargingModelMessage(Long timingChargingModelId) {
Map<String, Object> map =new HashMap<>();
LoginUser loginUser = tokenService.getLoginUser();
if(loginUser ==null){
return R.ok(map);
}
//查询是否是未执行状态
map = xhpcTimingChargingModelMapper.getXhpcTimingChargingModelMapById(timingChargingModelId,loginUser.getTenantId());
//费率
List<Map<String, Object>> xhpcRateList = xhpcTimingChargingModelMapper.getXhpcTimingChargingRateList(timingChargingModelId);
map.put("xhpcRateList", xhpcRateList);
//费率时段,先反设置时段在反默认时段
List<Map<String, Object>> xhpcRateTimeTypeList = xhpcTimingChargingModelMapper.getXhpcTimingChargingTimeTypeList(timingChargingModelId);
map.put("xhpcRateTimeList", xhpcRateTimeTypeList);
return R.ok(map);
}
@Override
public XhpcTimingChargingModel getXhpcTimingChargingModelById(Long timingChargingModelId) {
return xhpcTimingChargingModelMapper.getXhpcTimingChargingModelById(timingChargingModelId,null);
}
@Override
public int updateXhpcTimingChargingModel(XhpcTimingChargingModel xhpcTimingChargingModel) {
return xhpcTimingChargingModelMapper.updateXhpcTimingChargingModel(xhpcTimingChargingModel);
}
@Override
public void getXhpcTimingChargingModelCron() {
}
public static XhpcRateTimeDto[] bubbleSort(XhpcRateTimeDto[] args) {
//冒泡排序算法
for (int i = 0; i < args.length - 1; i++) {

View File

@ -307,8 +307,139 @@
</trim>
</insert>
<insert id="insertXhpcTimingChargingCacheRateModel">
insert into xhpc_timing_charging_cache_rate_model
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="null != timingChargingModelId">
timing_charging_model_id,
</if>
<if test="null != onePrice ">
one_price,
</if>
<if test="null != oneSvcPrice">
one_svc_price,
</if>
<if test="null != twoPrice">
two_price,
</if>
<if test="null != twoSvcPrice ">
two_svc_price,
</if>
<if test="null != threePrice ">
three_price,
</if>
<if test="null != threeSvcPrice ">
three_svc_price,
</if>
<if test="null != fourPrice ">
four_price,
</if>
<if test="null != fourSvcPrice ">
four_svc_price,
</if>
<if test="null != lossRate ">
loss_rate,
</if>
<if test="null != tfPricesSeq and ''!=tfPricesSeq">
tf_prices_seq,
</if>
<if test="null != pp and ''!=pp">
pp,
</if>
<if test="null != tenantId ">
tenant_id,
</if>
<if test="null != status ">
status,
</if>
<if test="null != delFlag ">
del_flag,
</if>
<if test="null != createTime ">
create_time,
</if>
<if test="null != createBy and '' != createBy">
create_by,
</if>
<if test="null != updateTime ">
update_time,
</if>
<if test="null != updateBy and '' != updateBy">
update_by,
</if>
<if test="null != remark and '' != remark">
remark
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="null != timingChargingModelId">
#{timingChargingModelId},
</if>
<if test="null != onePrice ">
#{onePrice},
</if>
<if test="null != oneSvcPrice">
#{oneSvcPrice},
</if>
<if test="null != twoPrice">
#{twoPrice},
</if>
<if test="null != twoSvcPrice ">
#{twoSvcPrice},
</if>
<if test="null != threePrice ">
#{threePrice},
</if>
<if test="null != threeSvcPrice ">
#{threeSvcPrice},
</if>
<if test="null != fourPrice ">
#{fourPrice},
</if>
<if test="null != fourSvcPrice ">
#{fourSvcPrice},
</if>
<if test="null != lossRate ">
#{lossRate},
</if>
<if test="null != tfPricesSeq and ''!=tfPricesSeq">
#{tfPricesSeq},
</if>
<if test="null != pp and ''!=pp">
#{pp},
</if>
<if test="null != tenantId ">
#{tenantId},
</if>
<if test="null != status ">
#{status},
</if>
<if test="null != delFlag ">
#{delFlag},
</if>
<if test="null != createTime ">
#{createTime},
</if>
<if test="null != createBy and '' != createBy">
#{createBy},
</if>
<if test="null != updateTime ">
#{updateTime},
</if>
<if test="null != updateBy and '' != updateBy">
#{updateBy},
</if>
<if test="null != remark and '' != remark">
#{remark}
</if>
</trim>
</insert>
<select id="getXhpcTimingChargingModelById" resultMap="BaseResultMap">
select * from xhpc_timing_charging_model where timing_charging_model_id =#{timingChargingModelId} and del_flag=0
<if test="tenantId !=null and ''!=tenantId">
and tenant_id=#{tenantId}
</if>
</select>
<update id="updateXhpcTimingChargingModel" parameterType="Integer">
@ -330,4 +461,57 @@
where timing_charging_model_id =#{timingChargingModelId}
</update>
<update id="updateXhpcTtimingChargingRate">
update xhpc_timing_charging_rate set del_flag=2 where timing_charging_model_id =#{timingChargingModelId}
</update>
<update id="updateXhpcTimingChargingTime">
update xhpc_timing_charging_time set del_flag=2 where timing_charging_model_id =#{timingChargingModelId}
</update>
<update id="updateXhpcTimingChargingCacheRateModel">
update xhpc_timing_charging_cache_rate_model set del_flag=2 where timing_charging_model_id =#{timingChargingModelId}
</update>
<select id="getXhpcTimingChargingRateList" resultType="map">
select power_fee as powerFee,
service_fee as serviceFee,
name as name,
rate_value as id
from xhpc_timing_charging_rate
where timing_charging_model_id = #{timingChargingModelId}
and del_flag = 0
GROUP BY rate_value
</select>
<select id="getXhpcTimingChargingTimeTypeList" resultType="java.util.Map">
select rt.start_time as startTime,
replace(rt.end_time, '00:00:00', '24:00:00') AS endTime,
rt.timing_charging_time_id as timingChargingTimeId,
rt.rate_value as id,
ra.name as rateName,
ra.power_fee as powerFee,
ra.service_fee as serviceFee
from xhpc_timing_charging_time as rt
left join xhpc_timing_charging_rate as ra on ra.timing_charging_rate_id = rt.timing_charging_rate_id
where rt.timing_charging_model_id = #{timingChargingModelId}
and rt.del_flag = 0
</select>
<select id="getXhpcTimingChargingModelMapById" resultType="map">
select
tcm.timing_charging_model_id as timingChargingModelId,
tcm.reason as reason,
cs.name as chargingStationName,
tcm.timing_time as timingTime,
tcm.status as status,
tcm.create_time as createTime
from xhpc_timing_charging_model as tcm
left join xhpc_charging_station as cs on cs.charging_station_id = tcm.charging_station_id
where tcm.timing_charging_model_id =#{timingChargingModelId}
and tcm.del_flag=0
<if test="tenantId !=null and ''!=tenantId">
and tcm.tenant_id=#{tenantId}
</if>
</select>
</mapper>

View File

@ -0,0 +1,45 @@
package com.xhpc.common.domain;
import com.xhpc.common.core.web.domain.BaseEntity;
import lombok.Data;
/**
* @author yuyang
* @date 2022/2/23 13:34
*/
@Data
public class XhpcTimingChargingCacheRateModel extends BaseEntity {
private Long timingChargingCacheRateModelId;
private Long timingChargingModelId;
private Integer onePrice;
private Integer oneSvcPrice;
private Integer twoPrice;
private Integer twoSvcPrice;
private Integer threePrice;
private Integer threeSvcPrice;
private Integer fourPrice;
private Integer fourSvcPrice;
private Integer lossRate;
private String tfPricesSeq;
private String pp;
private Integer status;
private Integer delFlag;
private String tenantId;
}

View File

@ -1,6 +1,5 @@
package com.xhpc.pp.mapper;
import com.xhpc.mapper.XhpcMessageMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;