| @@ -416,9 +416,7 @@ public class WxEnergyController extends BaseController { | |||
| @ApiOperation("计费标准新增修改") | |||
| @PostMapping("calcuteFeesShopEndTime") | |||
| public ResultData calcuteFeesShopEndTime(@RequestBody WxEnergyFeesShop record) { | |||
| //TODO 待计算。 | |||
| Date endDate = new Date(); | |||
| return new ResultData(endDate); | |||
| return new ResultData(record.calcuteEndTime()); | |||
| } | |||
| @@ -3,17 +3,21 @@ package com.iformall.domain.po; | |||
| import com.baomidou.mybatisplus.annotation.TableField; | |||
| import com.baomidou.mybatisplus.annotation.TableName; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.EnumContractReceivePeriodUnit; | |||
| import com.iformall.enums.EnumEnergyMeterPhysicsType; | |||
| import com.iformall.enums.EnumEnergyMeterType; | |||
| import com.iformall.enums.EnumFeesShopTimeType; | |||
| import com.iformall.enums.EnumFeesShopTimeUnit; | |||
| import com.iformall.enums.EnumFeesStandardsTimeUnit; | |||
| import com.iformall.enums.EnumRentShopType; | |||
| import com.iformall.utils.DateUtils; | |||
| import cn.afterturn.easypoi.excel.annotation.Excel; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import lombok.ToString; | |||
| import java.util.Calendar; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| @@ -123,4 +127,47 @@ public class WxEnergyFeesShop extends TenantEntity { | |||
| @TableField(exist = false) | |||
| private String feesIdsStr; | |||
| private List<Long> feesIds; | |||
| public Date calcuteEndTime() { | |||
| Calendar instance = Calendar.getInstance(); | |||
| instance.setTime(this.beginTime); | |||
| if (this.timeUnit == EnumFeesShopTimeUnit.DAY.getCode()) { | |||
| //按天,则是到这个月底 | |||
| return DateUtils.getLastDayForMonth(this.beginTime); | |||
| }else if (this.timeUnit == EnumFeesShopTimeUnit.MONTH.getCode()) { | |||
| if (this.timeType == EnumFeesShopTimeType.PERIOD.getCode()) { | |||
| return EnumContractReceivePeriodUnit.getAfterCalendarDay(instance, 1, EnumContractReceivePeriodUnit.MONTH.getCode()).getTime(); | |||
| }else { | |||
| return DateUtils.getLastDayForMonth(this.beginTime); | |||
| } | |||
| }else if (this.timeUnit == EnumFeesShopTimeUnit.QUATOR.getCode()) { | |||
| return EnumContractReceivePeriodUnit.getAfterCalendarDay(instance, 1, EnumContractReceivePeriodUnit.QUARTER.getCode()).getTime(); | |||
| }else if (this.timeUnit == EnumFeesShopTimeUnit.HALF_YEAR.getCode()) { | |||
| if (this.timeType == EnumFeesShopTimeType.PERIOD.getCode()) { | |||
| return EnumContractReceivePeriodUnit.getAfterCalendarDay(instance, 6, EnumContractReceivePeriodUnit.MONTH.getCode()).getTime(); | |||
| }else { | |||
| Date end = EnumContractReceivePeriodUnit.getAfterCalendarNarDay(this.beginTime, 6, EnumContractReceivePeriodUnit.MONTH.getCode()); | |||
| //如果结束时间比本年最后一天要大,则取本年最后一天 | |||
| Date yearEnd = DateUtils.getLastDayForYear(this.beginTime); | |||
| if (end.after(yearEnd)) { | |||
| return yearEnd; | |||
| } | |||
| return end; | |||
| } | |||
| }else if (this.timeUnit == EnumFeesShopTimeUnit.YEAR.getCode()) { | |||
| if (this.timeType == EnumFeesShopTimeType.PERIOD.getCode()) { | |||
| return EnumContractReceivePeriodUnit.getAfterCalendarDay(instance, 12, EnumContractReceivePeriodUnit.MONTH.getCode()).getTime(); | |||
| }else { | |||
| Date end = EnumContractReceivePeriodUnit.getAfterCalendarNarDay(this.beginTime, 12, EnumContractReceivePeriodUnit.MONTH.getCode()); | |||
| //如果结束时间比本年最后一天要大,则取本年最后一天 | |||
| Date yearEnd = DateUtils.getLastDayForYear(this.beginTime); | |||
| if (end.after(yearEnd)) { | |||
| return yearEnd; | |||
| } | |||
| return end; | |||
| } | |||
| }else { | |||
| return DateUtils.getLastDayForMonth(this.beginTime); | |||
| } | |||
| } | |||
| } | |||
| @@ -16,4 +16,6 @@ public interface WxEnergyFeesShopMapper extends CommonMapper<WxEnergyFeesShop, L | |||
| WxEnergyFeesShop selectById(@Param("id")Long id,@Param("tenantId")String tenantId); | |||
| void updateTimes(@Param("tenantId")String tenantId, @Param("list")List<WxEnergyFeesShop> resultList); | |||
| } | |||
| @@ -1537,7 +1537,7 @@ public class WxEnergyServiceImpl implements WxEnergyService { | |||
| } | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| @Override | |||
| public void createBill(WxEnergyReadingCalcute record, MallUserInfo user) { | |||
| @@ -1556,10 +1556,12 @@ public class WxEnergyServiceImpl implements WxEnergyService { | |||
| merchantMap = wxMerchantService.getShopMerchantMap(sq); | |||
| } | |||
| WxEnergyFees fees = this.getFeesById(calcute.getFeesId(), record.getTenantId()); | |||
| List<WxEnergyReadingCalcuteResult> resultList = wxEnergyReadingCalcuteResultMapper.findList(crq); | |||
| if (null != resultList && resultList.size() > 0 ) { | |||
| List<WxAllBill> billList = new ArrayList<WxAllBill>(); | |||
| List<WxEnergyFeesShop> feesShopList = new ArrayList<WxEnergyFeesShop>(); | |||
| for (int i = 0 ; i < resultList.size(); i++) { | |||
| WxEnergyReadingCalcuteResult result = resultList.get(i); | |||
| WxShop shop = null; | |||
| @@ -1576,8 +1578,22 @@ public class WxEnergyServiceImpl implements WxEnergyService { | |||
| if (null == merchant) { | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"店铺"+shop.getShopNumber()+"未绑定商户,请先绑定商户"); | |||
| } | |||
| WxEnergyFeesShop feesShop = wxEnergyFeesShopMapper.selectById(result.getFeesShopId(), result.getTenantId()); | |||
| if (null == feesShop) { | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"店铺"+shop.getShopNumber()+"该科目费用标准未查询到"); | |||
| } | |||
| //非能耗费的费用标准更新开始日期和结束日期,能耗的是使用的抄表区间的时间。 | |||
| if (fees.getBillType() != EnumBillAllType.DAILY.getCode()) { | |||
| feesShop.setBeginTime(DateUtils.getSecondsTimeAfter(1, feesShop.getEndTime())); | |||
| feesShop.setEndTime(feesShop.calcuteEndTime()); | |||
| feesShopList.add(feesShop); | |||
| } | |||
| WxAllBill bill = result.generateBill(calcute, merchant, shop, user,result.getBeginTime(),result.getEndTime(), result.getMoney(), result.getMoneyDeail(), "能源计算自动生成"); | |||
| billList.add(bill); | |||
| } | |||
| try { | |||
| //先把之前的未付的账单全部删除掉,已支付的账单先不处理 | |||
| @@ -1586,6 +1602,10 @@ public class WxEnergyServiceImpl implements WxEnergyService { | |||
| delDaily.setEnergyReadingCalcuteId(record.getId()); | |||
| wxAllBillService.deleteEnergyReadingBills(delDaily); | |||
| wxAllBillService.insertBills(record.getTenantId(), billList); | |||
| //更新费用标准的开始日期和结束日期 | |||
| wxEnergyFeesShopMapper.updateTimes(record.getTenantId(), feesShopList); | |||
| }catch(Exception e) { | |||
| logger.error("insert bills error.",e); | |||
| } | |||
| @@ -1600,7 +1620,7 @@ public class WxEnergyServiceImpl implements WxEnergyService { | |||
| wxEnergyReadingCalcuteMapper.updateById(c); | |||
| } | |||
| } | |||
| @Override | |||
| public void setReadingCalcuteIsDel(WxEnergyReadingCalcute record) { | |||
| WxEnergyReadingCalcute calcute = wxEnergyReadingCalcuteMapper.selectById(record.getId(), record.getTenantId()); | |||
| @@ -1152,7 +1152,22 @@ public class DateUtils { | |||
| ca.set(Calendar.MILLISECOND, 0); //将毫秒至0 | |||
| return ca.getTime(); | |||
| } | |||
| public static Date getLastDayForYear(Date date) { | |||
| Calendar ca = Calendar.getInstance(); | |||
| ca.setTime(date); | |||
| int year = ca.get(Calendar.YEAR); | |||
| ca.clear(); | |||
| ca.set(Calendar.YEAR, year+1); | |||
| ca.set(Calendar.DAY_OF_YEAR, 0); | |||
| ca.set(Calendar.HOUR_OF_DAY, 23); | |||
| ca.set(Calendar.MINUTE, 59); | |||
| ca.set(Calendar.SECOND, 59); | |||
| ca.set(Calendar.MILLISECOND, 0); | |||
| Date currYearLast = ca.getTime(); | |||
| return currYearLast; | |||
| } | |||
| /** | |||
| * 取得指定月的天数 | |||
| * */ | |||
| @@ -1613,6 +1628,7 @@ public class DateUtils { | |||
| start.set(Calendar.HOUR_OF_DAY, 0); | |||
| start.set(Calendar.MINUTE, 0); | |||
| start.set(Calendar.SECOND, 0); | |||
| start.set(Calendar.MILLISECOND, 0); | |||
| switch(quater) { | |||
| case 1: | |||
| start.set(Calendar.MONTH, 0); | |||
| @@ -1670,4 +1686,8 @@ public class DateUtils { | |||
| } | |||
| return allDays; | |||
| } | |||
| public static void main(String[] args) { | |||
| System.out.println(DateUtils.getLastDayForYear(new Date())); | |||
| } | |||
| } | |||
| @@ -77,5 +77,11 @@ | |||
| <include refid="dynamicWhereConditions"/> | |||
| </select> | |||
| <insert id="updateTimes" parameterType="HashMap"> | |||
| <foreach collection="list" item="item" index="index" separator=";"> | |||
| update wx_energy_fees_shop set begin_time = #{item.beginTime}, end_time = #{item.endTime} where id = #{item.id} | |||
| </foreach> | |||
| </insert> | |||
| </mapper> | |||