| @@ -1,16 +1,23 @@ | |||
| package com.iformall.schedule; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.domain.po.WxBillRent; | |||
| import com.iformall.domain.po.WxMall; | |||
| import com.iformall.domain.po.WxPropertyContract; | |||
| import com.iformall.domain.po.WxRentContract; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.po.msg.WxMsgRecord; | |||
| import com.iformall.enums.EnumDelStatus; | |||
| import com.iformall.enums.EnumIsPreview; | |||
| import com.iformall.enums.EnumMsgMqKey; | |||
| import com.iformall.enums.EnumMsgMqTag; | |||
| import com.iformall.enums.EnumMsgMqTopic; | |||
| import com.iformall.enums.EnumMsgRecordType; | |||
| import com.iformall.enums.EnumRentContractStatus; | |||
| import com.iformall.enums.EnumRentContractType; | |||
| import com.iformall.mapper.WxMallMapper; | |||
| import com.iformall.mq.MqBaseProducer; | |||
| import com.iformall.service.WxBillRentService; | |||
| import com.iformall.service.WxPropertyContractService; | |||
| import com.iformall.service.WxRentContractService; | |||
| import com.iformall.utils.DateUtils; | |||
| @@ -23,6 +30,7 @@ import org.springframework.scheduling.annotation.Async; | |||
| import org.springframework.scheduling.annotation.Scheduled; | |||
| import org.springframework.stereotype.Component; | |||
| import java.util.ArrayList; | |||
| import java.util.Date; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| @@ -47,6 +55,7 @@ public class ContractSchedule { | |||
| @Autowired | |||
| private MqBaseProducer mqBaseProducer; | |||
| /** | |||
| * 凌晨5分 | |||
| */ | |||
| @@ -209,5 +218,36 @@ public class ContractSchedule { | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * 凌晨5分,联营扣点和面积联营取高的需要根据接单数据来更新账单,取高的那一个 | |||
| */ | |||
| @Async | |||
| @Scheduled(cron = "0 5 0 * * ?") | |||
| public void updateRentBill() { | |||
| //查询记租中的联营扣点或者取高的合同,每天更新账单截止时间为前一天的账单。 | |||
| List<WxMall> wxMalls = wxMallMapper.findList(null); | |||
| for (WxMall wxMall : wxMalls) { | |||
| WxRentContract rentContract = new WxRentContract(); | |||
| rentContract.updateTenantInfo(wxMall); | |||
| List<Integer> typeList = new ArrayList<Integer>(); | |||
| typeList.add(EnumRentContractType.RENT_BY_JOINT.getCode()); | |||
| typeList.add(EnumRentContractType.RENT_BY_AREA_AND_JOINT.getCode()); | |||
| rentContract.setTypeList(typeList); | |||
| rentContract.setStatus(EnumRentContractStatus.PAING.getCode()); | |||
| List<WxRentContract> contractList = wxRentContractService.findList(rentContract); | |||
| if (null != contractList && contractList.size() > 0 ) { | |||
| for (int i = 0 ; i < contractList.size(); i++ ) { | |||
| WxRentContract rc = contractList.get(i); | |||
| try { | |||
| wxRentContractService.calcuteByTradeDaily(rc); | |||
| }catch(Exception e) { | |||
| log.error("rentcontract updateRentBill error.",e); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -135,7 +135,6 @@ public class CouponOrderNoticeSchedule { | |||
| }); | |||
| } | |||
| } | |||
| } | |||
| @Async | |||
| @@ -143,7 +142,7 @@ public class CouponOrderNoticeSchedule { | |||
| public void couponOrderRefundSchedule() { | |||
| List<WxMall> malls = getMalls(); | |||
| for (WxMall mall: malls) { | |||
| Date oneDayBefore = DateUtils.getTimeAfterDays(1, new Date()); | |||
| Date oneDayBefore = DateUtils.getTimeAfterDays(2, new Date()); | |||
| List<WxCouponOrder> list = wxCouponOrderMapper.findExpiredCouponOrderByValidDate(mall.getTenantId(),oneDayBefore); | |||
| if (null != list && list.size() > 0 ) { | |||
| list.stream().forEach(co -> { | |||
| @@ -283,6 +283,8 @@ public class WxRentContract extends TenantEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value = "类型", name = "type") | |||
| private Integer type; | |||
| @TableField(exist = false) | |||
| private List<Integer> typeList; | |||
| @io.swagger.annotations.ApiModelProperty(value = "调整比例", name = "adjustRatio") | |||
| private String adjustRatio; | |||
| @@ -138,4 +138,6 @@ public interface WxRentContractService { | |||
| void setEndContractTime(WxRentContract wxRentContract); | |||
| List<WxRentContract> findToEndContractList(WxRentContract record); | |||
| void calcuteByTradeDaily(WxRentContract wxRentContract); | |||
| } | |||
| @@ -130,6 +130,9 @@ public class WxRentContractServiceImpl implements WxRentContractService { | |||
| @Autowired | |||
| WxBillRentManageMapper wxBillRentManageMapper; | |||
| @Autowired | |||
| WxMerchantTradeDailyMapper wxMerchantTradeDailyMapper; | |||
| // @Override | |||
| // public Map<String, Object> listAsPage(WxRentContract record, Integer pageIndex, Integer pageSize) { | |||
| // //Object rentContractStatusInfo = getRentContractStatusInfo(record); | |||
| @@ -3213,4 +3216,96 @@ public class WxRentContractServiceImpl implements WxRentContractService { | |||
| return wxRentContractMapper.findList(wrc); | |||
| } | |||
| @Override | |||
| public void calcuteByTradeDaily(WxRentContract wxRentContract) { | |||
| WxPayAccountBill wxPayAccountBill = wxPayAccountBillService.getByTenantInfo(wxRentContract); | |||
| //查询合同下截止时间为昨天的账单 | |||
| WxBillRent bq = new WxBillRent(); | |||
| bq.updateTenantInfo(wxRentContract); | |||
| bq.setRentContractId(wxRentContract.getId()); | |||
| bq.setIsPreview(EnumIsPreview.NO.getCode()); | |||
| bq.setEndtime(DateUtils.getDayBegin(DateUtils.getTimeAfterDays(-1, new Date()))); | |||
| bq.setIsDel(EnumDelStatus.NOT_DEL.getCode()); | |||
| List<WxBillRent> billList = wxBillRentMapper.findList(bq); | |||
| if (null != billList && billList.size() > 0 ) { | |||
| WxBillRent br = billList.get(0); | |||
| //判断账单是否跨月,如果跨月,需要按照每月来查询解单金额 | |||
| int needPay = 0 ; | |||
| int months = DateUtils.monthsBetween(br.getStarttime(), br.getEndtime()); | |||
| if ( months > 0 ) { | |||
| for (int i = 0 ; i < months ; i++ ) { | |||
| int _money = 0; | |||
| if (i == 0 ) { | |||
| _money = sumTradeDailyBySameMonthDay(bq, wxRentContract.getMerchantId(), br.getStarttime(), | |||
| DateUtils.getLastDayForMonth(br.getStarttime())); | |||
| }else if (i == (months-1)){ | |||
| _money = sumTradeDailyBySameMonthDay(bq, wxRentContract.getMerchantId(), | |||
| DateUtils.getFirstDayForCurrMonth(DateUtils.getTimeAfterMonths(i,br.getStarttime())), | |||
| DateUtils.getDayEnd(DateUtils.getTimeAfterDays(-1, br.getEndtime()))); | |||
| }else { | |||
| Date _date = DateUtils.getTimeAfterMonths(i,br.getStarttime()); | |||
| _money = sumTradeDailyBySameMonthDay(bq, wxRentContract.getMerchantId(), | |||
| DateUtils.getFirstDayForCurrMonth(_date), | |||
| DateUtils.getLastDayForMonth(_date)); | |||
| } | |||
| needPay = needPay + _money; | |||
| } | |||
| }else { | |||
| //同一个月 | |||
| //合同账单结束的时间是00:00:00,取日期要取前一天 | |||
| needPay = sumTradeDailyBySameMonthDay(bq, wxRentContract.getMerchantId(), | |||
| br.getStarttime(), DateUtils.getTimeAfterDays(-1, br.getEndtime())); | |||
| } | |||
| if (needPay > br.getNeedPay()) { | |||
| Long newPay = Long.parseLong(String.valueOf(needPay)); | |||
| br.setNeedPay(newPay); | |||
| br.setOwe(newPay); | |||
| br.setReceivePay(newPay); | |||
| br.setUpdatetime(new Date()); | |||
| BigDecimal servicePay = new BigDecimal(br.getReceivePay()).multiply(new BigDecimal(wxPayAccountBill.getServiceChargeRate())).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP); | |||
| br.setServiceChargePay(servicePay.intValue()); | |||
| br.setOwe(br.getReceivePay() + br.getServiceChargePay()); | |||
| br.setComments("解单金额["+newPay+"(分)]大于合同计算金额,系统自动更新"); | |||
| wxBillRentMapper.updateById(br); | |||
| } | |||
| } | |||
| } | |||
| private int sumTradeDailyBySameMonthDay(TenantEntity tenantEntity,Long merchantId,Date begin ,Date end) { | |||
| //如果有按月的,则取按月来算 | |||
| WxMerchantTradeDaily tdq = new WxMerchantTradeDaily(); | |||
| tdq.updateTenantInfo(tenantEntity); | |||
| tdq.setMerchantId(merchantId); | |||
| tdq.setDateType(EnumTradeDailyDateType.MONTH.getCode()); | |||
| tdq.setReportDate(DateUtils.date2String(begin, DateUtils.DATE_PATTERN_MONTH)); | |||
| List<WxMerchantTradeDaily> monthList = wxMerchantTradeDailyMapper.findList(tdq); | |||
| if (null != monthList && monthList.size() > 0 ){ | |||
| int monthSums = monthList.get(0).getTradeAmtInteger(); | |||
| Date _fistDay = DateUtils.getDayBegin(DateUtils.getFirstDayForCurrMonth(begin)); | |||
| Date _lastDay = DateUtils.getLastDayForMonth(begin); | |||
| if (begin.equals(_fistDay) && end.equals(_lastDay)) { | |||
| //满月 | |||
| return monthSums; | |||
| }else { | |||
| //根据天数计算 | |||
| int monthDays = DateUtils.daysBetween(_fistDay, _lastDay); | |||
| int _days = DateUtils.daysBetween(begin, end); | |||
| if (_days == 0) { | |||
| _days = 1;//当天 | |||
| } | |||
| BigDecimal servicePay = new BigDecimal(monthSums).multiply(new BigDecimal(_days)).divide(new BigDecimal(monthDays), 2, BigDecimal.ROUND_HALF_UP); | |||
| return servicePay.intValue(); | |||
| } | |||
| }else { | |||
| WxMerchantTradeDaily tdq1 = new WxMerchantTradeDaily(); | |||
| tdq1.updateTenantInfo(tenantEntity); | |||
| tdq1.setMerchantId(merchantId); | |||
| tdq1.setDateType(EnumTradeDailyDateType.DAY.getCode()); | |||
| tdq1.setStartTime(DateUtils.format(begin)); | |||
| tdq1.setEndTime(DateUtils.format(end)); | |||
| String sumMoney = wxMerchantTradeDailyMapper.findSumMoney(tdq1); | |||
| return Integer.parseInt(sumMoney); | |||
| } | |||
| } | |||
| } | |||
| @@ -24,6 +24,8 @@ public class DateUtils { | |||
| public final static String DATE_PATTERN = "yyyy-MM-dd"; | |||
| /** 时间格式(yyyy-MM-dd HH:mm:ss) */ | |||
| public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; | |||
| public final static String DATE_PATTERN_MONTH = "yyyy-MM"; | |||
| public final static String[] weekObj=new String[]{"日","一","二","三","四","五","六"}; | |||
| @@ -454,6 +456,20 @@ public class DateUtils { | |||
| now.set(Calendar.DATE, now.get(Calendar.DATE) + days); | |||
| return now.getTime(); | |||
| } | |||
| /** | |||
| * 获得当前时间后几个月的时间 | |||
| * | |||
| * @param days 后几天 | |||
| * | |||
| * @return | |||
| */ | |||
| public static Date getTimeAfterMonths(int months, Date myDate) { | |||
| Calendar now = Calendar.getInstance(); | |||
| now.setTime(myDate); | |||
| now.set(Calendar.MONTH, now.get(Calendar.MONTH) + months); | |||
| return now.getTime(); | |||
| } | |||
| /** | |||
| * 获得指定时间前几天,格式yyyy-MM-dd | |||
| @@ -1147,7 +1163,25 @@ public class DateUtils { | |||
| } | |||
| return 0; | |||
| } | |||
| public static int monthsBetween(Date begin,Date end) { | |||
| Calendar _bc = Calendar.getInstance(); | |||
| _bc.setTime(begin); | |||
| Calendar _ec = Calendar.getInstance(); | |||
| _ec.setTime(end); | |||
| int i = _ec.get(Calendar.YEAR) - _bc.get(Calendar.YEAR); | |||
| int month = 0; | |||
| if (i < 0) { | |||
| month = -i * 12; | |||
| }else { | |||
| month = i * 12; | |||
| } | |||
| int result = _ec.get(Calendar.MONTH) - _bc.get(Calendar.MONTH) + month; | |||
| return Math.abs(result); | |||
| } | |||
| /** | |||
| * 日期距离今天还有几天 | |||
| * @param date | |||
| @@ -1272,7 +1306,7 @@ public class DateUtils { | |||
| return calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR) && calendar1.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH); | |||
| } | |||
| /** | |||
| * 获取上个月的今天 | |||
| */ | |||
| @@ -95,6 +95,8 @@ | |||
| <if test=" null != isPreview ">and is_preview = #{isPreview}</if> | |||
| <if test=" null != payWay ">and `pay_way` = #{payWay}</if> | |||
| <if test=" null != latePayStatus ">and `late_pay_status` = #{latePayStatus}</if> | |||
| <if test=" null != starttime ">and `starttime` = #{starttime}</if> | |||
| <if test=" null != endtime ">and `endtime` = #{endtime}</if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| @@ -224,6 +224,12 @@ | |||
| #{statusItem} | |||
| </foreach> | |||
| </if> | |||
| <if test=" null != typeList "> | |||
| and type in | |||
| <foreach collection="typeList" index="index" item="typeItem" open="(" separator="," close=")"> | |||
| #{typeItem} | |||
| </foreach> | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||