developrelease_toaliyun_real
| @@ -3,23 +3,21 @@ package com.iformall.controller.app; | |||
| import cn.binarywang.wx.miniapp.api.WxMaService; | |||
| import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor; | |||
| import com.amazonaws.services.s3.model.ObjectMetadata; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.controller.sys.UploadController; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxCouponChannel; | |||
| import com.iformall.domain.po.WxMerchant; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.WxCouponChannelMapper; | |||
| import com.iformall.mapper.WxMerchantMapper; | |||
| import com.iformall.service.WxAppinfoService; | |||
| import com.iformall.service.wechat.FmOpenService; | |||
| import com.iformall.utils.Constant; | |||
| import com.iformall.utils.MaUtil; | |||
| import com.iformall.utils.QRCodeUtils; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| @@ -28,8 +26,6 @@ import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.core.task.AsyncTaskExecutor; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| import javax.servlet.ServletException; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| @@ -37,8 +33,6 @@ import java.io.*; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import java.util.UUID; | |||
| import java.util.concurrent.ExecutorService; | |||
| import java.util.concurrent.Executors; | |||
| @RestController | |||
| @RequestMapping("wxAppinfo") | |||
| @@ -66,6 +60,9 @@ public class WxAppinfoController extends BaseController { | |||
| @Autowired | |||
| private AsyncTaskExecutor asyncTaskExecutor; | |||
| @Autowired | |||
| private WxCouponChannelMapper wxCouponChannelMapper; | |||
| @ApiOperation("加载老数据二维码") | |||
| @GetMapping("/updateQrCode") | |||
| public void updateQrCode(String p)throws ServletException, IOException { | |||
| @@ -89,6 +86,29 @@ public class WxAppinfoController extends BaseController { | |||
| } | |||
| } | |||
| @ApiOperation("加载卷二维码") | |||
| @GetMapping("/updateCouponQrCode") | |||
| public void updateCouponQrCode(String p)throws ServletException, IOException { | |||
| if("xlldxx".equals(p)){ | |||
| String pageUrl = "pages/index/index"; | |||
| List<WxCouponChannel> list = wxCouponChannelMapper.findQrcodeEmptyList(); | |||
| for (WxCouponChannel couponChannel:list) { | |||
| asyncTaskExecutor.execute(new Runnable() { | |||
| @Override | |||
| public void run() { | |||
| String param = couponChannel.getWeappScene(); | |||
| ResultData resultData = exportQrcode(null,null,couponChannel.getTenantId(),1,pageUrl,param,0,"","","店铺详情",true); | |||
| Map<String,String> map = (Map)resultData.data; | |||
| String url = map.get("url"); | |||
| couponChannel.setQrCode(url); | |||
| wxCouponChannelMapper.updateByPrimaryKeySelective(couponChannel); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| } | |||
| @ApiOperation(value = "下载二维码", produces="application/json;charset=UTF-8", notes = "参数{\"name\":\"String\",\"pageUrl\":\"String\", \"sceneParam\":\"二维码参数\", \"type\":0:有限二维码,1:无限二维码,\"withText\":int(0:不带字, 1:加一行字,2:加两行字),\"text1\":\"String\",\"text2\":\"String\"}") | |||
| @PostMapping("/downQrCode") | |||
| public void downQrCode(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> params) throws MallinkException { | |||
| @@ -8,6 +8,7 @@ import com.iformall.common.ResultData; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.vo.WxCouponStatisVo; | |||
| import com.iformall.enums.EnumCouponType; | |||
| import com.iformall.enums.EnumCouponValidType; | |||
| import com.iformall.service.WxCouponService; | |||
| import com.iformall.utils.DateUtils; | |||
| @@ -70,26 +71,37 @@ public class WxCouponController extends BaseController { | |||
| public ResultData updateStokeAndValidDate(@RequestBody WxCoupon wxCoupon) { | |||
| logger.debug("[" + getIpAddr() + "] WxCouponController::updateStokeAndValidDate"); | |||
| if (wxCoupon.getId() == null) { | |||
| logger.error("缺少id"); | |||
| return new ResultData(ResultData.ERROR, "缺少id"); | |||
| } | |||
| if(wxCoupon.getRemainInventory() == null || wxCoupon.getInventory() == null) { | |||
| logger.error("库存错误1"); | |||
| return new ResultData(ErrorCode.COUPON_STOCK_ERR); | |||
| } | |||
| if(wxCoupon.getRemainInventory() > wxCoupon.getInventory()) { | |||
| logger.error("库存错误2"); | |||
| return new ResultData(ErrorCode.COUPON_STOCK_ERR); | |||
| } | |||
| if(wxCoupon.getValidType() == null) { | |||
| logger.error("库存错误3"); | |||
| return new ResultData(ErrorCode.COUPON_VALID_DATE_ERR); | |||
| } | |||
| if(wxCoupon.getValidType().equals(EnumCouponValidType.BETWEEN_TWO_TIME.getCode())) { | |||
| if(wxCoupon.getValidEndDate() == null) { | |||
| logger.error("有效期错误1"); | |||
| return new ResultData(ErrorCode.COUPON_VALID_DATE_ERR); | |||
| } | |||
| } else { | |||
| if(wxCoupon.getValidDays() == null) { | |||
| logger.error("有效期错误2"); | |||
| return new ResultData(ErrorCode.COUPON_VALID_DATE_ERR); | |||
| } | |||
| } | |||
| if(wxCoupon.getType().equals(EnumCouponType.COUPON_TINGCHE.getCode()) || | |||
| wxCoupon.getType().equals(EnumCouponType.COUPON_CREDIT_PARK.getCode())) { | |||
| logger.error("券库存有效期不支持停车券"); | |||
| return new ResultData(ErrorCode.COUPON_STOCK_DATE_NO_CAR); | |||
| } | |||
| wxCoupon.setTenantId(getTenantId()); | |||
| return wxCouponService.updateCouponStockAndEndTime(wxCoupon); | |||
| } | |||
| @@ -33,6 +33,9 @@ public class WxTopicController extends BaseController { | |||
| wxTopic.setTenantId(tenantId); | |||
| PageInfo<WxTopic> page = wxTopicService.listAsPage(wxTopic, pageNum, pageSize); | |||
| //可投放、已上线,时间区间查的是活动开始时间 | |||
| //已下线、已作为,时间区间查的是活动结束时间 | |||
| //设置正在上架的专题 | |||
| Date now = new Date(); | |||
| page.getList().stream().forEach(cc->{ | |||
| @@ -65,9 +65,9 @@ public class BillDailyAsyncTask { | |||
| public void importExcelData(File file, MallUserInfo user, String importKey, String tenantId) { | |||
| ImportParams params = new ImportParams(); | |||
| // 需要验证 | |||
| params.setImportFields(new String[]{"商铺号", "费用类型", "实际应收金额(元)", "实收金额(元)", "缴款截止日期", "逾期天数"}); | |||
| params.setImportFields(new String[]{"商铺号", "费用类型", "实际应收金额(元)", "实收金额(元)", "缴款截止日期"}); | |||
| IExcelDataHandler<WxBillDailyVo> handler = new BillDailyAsyncTask.BillDailyExcelHandler(); | |||
| handler.setNeedHandlerFields(new String[]{"商铺号", "费用类型", "实际应收金额(元)", "实收金额(元)", "缴款截止日期", "逾期天数"}); | |||
| handler.setNeedHandlerFields(new String[]{"商铺号", "费用类型", "实际应收金额(元)", "实收金额(元)", "缴款截止日期"}); | |||
| params.setNeedVerify(true); | |||
| ExcelImportResult<WxBillDailyVo> datalist = null; | |||
| @@ -0,0 +1,2 @@ | |||
| ALTER TABLE wx_coupon_channel | |||
| ADD COLUMN qr_code VARCHAR(500) DEFAULT NULL COMMENT '二维码'; | |||
| @@ -109,6 +109,7 @@ public enum ErrorCode{ | |||
| COUPON_STOCK_ERR(2034, "券库存设置错误"), | |||
| COUPON_VALID_DATE_ERR(2035, "券有效期设置错误"), | |||
| COUPON_STOCK_VALID_DATE_SETTING_ERR(2036, "券库存有效期未修改"), | |||
| COUPON_STOCK_DATE_NO_CAR(2037, "券库存不支持停车券"), | |||
| PUSH_LIMIT_UP_TO_1DAYLIMIT(2040, "此用户一天内发券到达疲劳度限制"), | |||
| PUSH_LIMIT_UP_TO_COUPONLIMIT(2041, "此用户发此券到达疲劳度限制"), | |||
| @@ -62,8 +62,6 @@ public class WxBillDaily extends BaseEntity{ | |||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createtime") | |||
| private Date createtime; | |||
| @Excel(name = "逾期天数", orderNum = "6", width = 20, numFormat = "#") | |||
| @NotNull | |||
| @SortColumn(column = "expiredDay") | |||
| @io.swagger.annotations.ApiModelProperty(value="逾期天数",name="expiredDay") | |||
| private Long expiredDay; | |||
| @@ -71,6 +71,8 @@ public class WxCouponChannel extends BaseEntity { | |||
| private Date updateDate; | |||
| @io.swagger.annotations.ApiModelProperty(value="子频道ID",name="subTargetId") | |||
| private Long subTargetId; | |||
| @io.swagger.annotations.ApiModelProperty(value="二维码",name="qrCode") | |||
| private String qrCode; | |||
| @Transient | |||
| @io.swagger.annotations.ApiModelProperty(value="积分售价(适用于类型10,11)",name="creditPrice") | |||
| @@ -0,0 +1,17 @@ | |||
| package com.iformall.domain.vo; | |||
| import lombok.Data; | |||
| import java.io.Serializable; | |||
| import java.util.Date; | |||
| @Data | |||
| public class BillTimeVo implements Serializable{ | |||
| private static final long serialVersionUID = 1L; | |||
| private Date startDate; | |||
| private Date endDate; | |||
| private Date ReceiveDate; | |||
| } | |||
| @@ -32,10 +32,12 @@ public class WxCouponCVo extends WxCoupon implements Serializable { | |||
| @Transient | |||
| private String priceStr; | |||
| @Transient | |||
| private Integer activityStatus; | |||
| @Transient | |||
| private String qrCode; | |||
| @io.swagger.annotations.ApiModelProperty(value="券ID",name="couponId") | |||
| private Long couponId; | |||
| @@ -36,4 +36,6 @@ public interface WxCouponChannelMapper extends CommonMapper<WxCouponChannel, Str | |||
| void offExpiriedCouponChannel2ByEndTime(); | |||
| void delByTopic(WxTopic wxTopic); | |||
| List<WxCouponChannel> findQrcodeEmptyList(); | |||
| } | |||
| @@ -259,12 +259,10 @@ public class WxBillDailyServiceImpl implements WxBillDailyService { | |||
| wxBillDaily.setPayDate(date); | |||
| } | |||
| int expiredDay = DateUtils.daysBetween(receiveDate, date); | |||
| wxBillDaily.setExpiredDay(billDaily.getExpiredDay()); | |||
| wxBillDaily.setExpiredDay(0L); | |||
| if (expiredDay > 0) { | |||
| wxBillDaily.setStatus(EnumBillRentStatus.NOT_PAID.getCode()); | |||
| if (billDaily.getExpiredDay().equals(0L)) { | |||
| wxBillDaily.setExpiredDay((long) expiredDay); | |||
| } | |||
| wxBillDaily.setExpiredDay((long) expiredDay); | |||
| } else { | |||
| wxBillDaily.setStatus(EnumBillRentStatus.WAIT_PAY.getCode()); | |||
| } | |||
| @@ -541,34 +541,6 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| // 5. get app info | |||
| // WxAppinfo appInfo = wxAppinfoService.getByAppId(user.getAppId()); | |||
| // 6. get payOrder info | |||
| if(StringUtils.isBlank(order.getFormId())) { | |||
| // formId为空,获取prepayId | |||
| WxPayOrder payOrder = null; | |||
| WxPayOrder payOrderQ = new WxPayOrder(); | |||
| payOrderQ.setTenantId(couponOrder.getTenantId()); | |||
| payOrderQ.setOrderId(order.getId()); | |||
| payOrderQ.setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); | |||
| List<WxPayOrder> payList = wxPayOrderMapper.select(payOrderQ); | |||
| if (payList.size() > 0) { | |||
| payOrder = payList.get(0); | |||
| } | |||
| if (payOrder == null) { | |||
| logger.error("找不到payOrder信息"); | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_NOT_FOUND); | |||
| } | |||
| if (payOrder.getPrepayId() == null) { | |||
| logger.error("payOrder信息中,prepay_id为空"); | |||
| throw new MallinkException(ErrorCode.PREPAY_ID_IS_EMPTY); | |||
| } | |||
| formId = payOrder.getPrepayId(); | |||
| } | |||
| if(StringUtils.isBlank(formId)) { | |||
| logger.error("formId为空"); | |||
| throw new MallinkException(ErrorCode.TEMPLATE_FORMID_NOT_FOUND); | |||
| } | |||
| SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); | |||
| String couponDetail = ""; | |||
| if (coupon.getType() == EnumCouponType.COUPON_MANJIAN.getCode()) { | |||
| @@ -598,6 +570,34 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| doVerifyAppUniformMsg(couponOrder, coupon, merchant, user, dateFormat, gotopage); | |||
| } | |||
| // 6. get payOrder info | |||
| if(StringUtils.isBlank(order.getFormId())) { | |||
| // formId为空,获取prepayId | |||
| WxPayOrder payOrder = null; | |||
| WxPayOrder payOrderQ = new WxPayOrder(); | |||
| payOrderQ.setTenantId(couponOrder.getTenantId()); | |||
| payOrderQ.setOrderId(order.getId()); | |||
| payOrderQ.setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); | |||
| List<WxPayOrder> payList = wxPayOrderMapper.select(payOrderQ); | |||
| if (payList.size() > 0) { | |||
| payOrder = payList.get(0); | |||
| } | |||
| if (payOrder == null) { | |||
| logger.error("找不到payOrder信息"); | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_NOT_FOUND); | |||
| } | |||
| if (payOrder.getPrepayId() == null) { | |||
| logger.error("payOrder信息中,prepay_id为空"); | |||
| throw new MallinkException(ErrorCode.PREPAY_ID_IS_EMPTY); | |||
| } | |||
| formId = payOrder.getPrepayId(); | |||
| } | |||
| if(StringUtils.isBlank(formId)) { | |||
| logger.error("formId为空"); | |||
| throw new MallinkException(ErrorCode.TEMPLATE_FORMID_NOT_FOUND); | |||
| } | |||
| // 9. 微信小程序-模板消息 | |||
| SmartAppMsg smartAppMsg; | |||
| if (bUsed) { | |||
| @@ -9,6 +9,7 @@ import com.iformall.common.IdWorker; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.vo.BillTimeVo; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| @@ -247,9 +248,6 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService | |||
| if (record.getPrice().longValue() <= 0) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "物业费要大于0"); | |||
| } | |||
| if (record.getDeposit().longValue() <= 0) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "押金要大于0"); | |||
| } | |||
| WxPropertyContract propertyContract = new WxPropertyContract(); | |||
| propertyContract.setTenantId(record.getTenantId()); | |||
| @@ -508,6 +506,8 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService | |||
| int billcount = 0; | |||
| List<WxBillProperty> resultList = new ArrayList<>(); | |||
| List<Date> yearList = new ArrayList<>(); | |||
| for (int i = 0; i < size; i++) { | |||
| Calendar instance = Calendar.getInstance(); | |||
| Date startDate; | |||
| @@ -525,241 +525,79 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService | |||
| instance.add(Calendar.MONTH, month * i); | |||
| startDate = instance.getTime(); | |||
| } | |||
| Map<String, Object> resultMap = buildRent(leaseArr[i], receivePeriod, priceArr[i], startDate, Calendar.MONTH, wxPropertyContract, userId, wxMerchant, billcount, isPreview, shopInfo,i==size-1?true:false); | |||
| List<WxBillProperty> billRentList = (List<WxBillProperty>)resultMap.get("billList"); | |||
| billcount = (Integer)resultMap.get("billcount"); | |||
| resultList.addAll(billRentList); | |||
| yearList.add(startDate); | |||
| } | |||
| Map<String, Object> resultMap = buildRent(receivePeriod, priceArr, yearList, Calendar.MONTH, wxPropertyContract, userId, wxMerchant, billcount, isPreview, shopInfo); | |||
| List<WxBillProperty> billRentList = (List<WxBillProperty>)resultMap.get("billList"); | |||
| resultList.addAll(billRentList); | |||
| return resultList; | |||
| } | |||
| public boolean isFirstDay(Date date){ | |||
| int dateInt = Integer.parseInt(new SimpleDateFormat("d").format(date)); | |||
| if(dateInt == 1){ | |||
| return true; | |||
| } | |||
| return false; | |||
| } | |||
| public boolean isCrossMonth(Date start,Date end){ | |||
| int startInt = Integer.parseInt(new SimpleDateFormat("M").format(start)); | |||
| int endInt = Integer.parseInt(new SimpleDateFormat("M").format(end)); | |||
| if(startInt != endInt){ | |||
| return true; | |||
| } | |||
| return false; | |||
| } | |||
| public Map<String, Object> buildRent(int lease, int receivePeriod, long price, Date startdate, int dayType, WxPropertyContract wxPropertyContract, Long userId, WxMerchant wxMerchant, int billcount, Integer isPreview, Map<String, Object> shopInfo, boolean isLastYesr) { | |||
| public Map<String, Object> buildRent(int receivePeriod,long[] priceArrs, List<Date> yearList,int dayType, WxPropertyContract wxPropertyContract, Long userId, WxMerchant wxMerchant, int billcount, Integer isPreview,Map<String, Object> shopInfo) { | |||
| SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); | |||
| Map<String,Object> resultMap = new HashedMap(); | |||
| List<WxBillProperty> resultList = new ArrayList<>(); | |||
| int extralease = lease % receivePeriod; | |||
| int extracount = extralease > 0 ? 1 : 0; | |||
| int paycount = lease / receivePeriod + extracount; | |||
| int index = paycount - 1; | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| //自然月,而且残月,周期整除,n+1,最后一个周期作为残月 | |||
| if(wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode()) | |||
| && !isFirstDay(wxPropertyContract.getRentalStartDate()) | |||
| && (wxPropertyContract.getLease() % wxPropertyContract.getReceivePeriod() == 0) | |||
| && isLastYesr | |||
| && isCrossMonth(wxPropertyContract.getRentalStartDate(),wxPropertyContract.getRentalEndDate()) | |||
| ){ | |||
| paycount ++; | |||
| } | |||
| for(int i = 0; i < paycount; i++){ | |||
| WxBillProperty wxBillProperty = new WxBillProperty(); | |||
| wxBillProperty.setIsPreview(isPreview); | |||
| wxBillProperty.setId(idWorker.nextId()); | |||
| wxBillProperty.setPropertyContractId(wxPropertyContract.getId()); | |||
| wxBillProperty.setPay(0L); | |||
| long needpay = new BigDecimal(price).multiply(new BigDecimal(receivePeriod)).longValue(); | |||
| Date date = new Date(); | |||
| Calendar instance = Calendar.getInstance(); | |||
| instance.setTime(startdate); | |||
| instance.add(dayType, receivePeriod * i); | |||
| if(!wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) { | |||
| instance.add(Calendar.DAY_OF_MONTH, -1); | |||
| } | |||
| Date time = instance.getTime(); | |||
| wxBillProperty.setReceiveDate(time); | |||
| //账单开始时间 | |||
| instance.clear(); | |||
| instance.setTime(wxBillProperty.getReceiveDate()); | |||
| if(!wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) { | |||
| instance.add(Calendar.DAY_OF_MONTH, 1); | |||
| } | |||
| wxBillProperty.setStarttime(instance.getTime()); | |||
| //账单结束时间 | |||
| instance.clear(); | |||
| instance.setTime(wxBillProperty.getStarttime()); | |||
| instance.add(dayType, receivePeriod); | |||
| instance.add(Calendar.DAY_OF_MONTH, -1); | |||
| wxBillProperty.setEndtime(instance.getTime()); | |||
| Date endDate = null; | |||
| if(yearList.size() > 1){ | |||
| endDate = yearList.get(1); | |||
| } | |||
| if (extracount > 0 && i == index) { | |||
| //账单开始时间 | |||
| instance.clear(); | |||
| instance.setTime(wxBillProperty.getReceiveDate()); | |||
| if(!wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) { | |||
| instance.add(Calendar.DAY_OF_MONTH, 1); | |||
| } | |||
| wxBillProperty.setStarttime(instance.getTime()); | |||
| //账单结束时间 | |||
| instance.clear(); | |||
| instance.setTime(wxBillProperty.getStarttime()); | |||
| instance.add(dayType, extralease); | |||
| instance.add(Calendar.DAY_OF_MONTH, -1); | |||
| wxBillProperty.setEndtime(instance.getTime()); | |||
| needpay = new BigDecimal(price).multiply(new BigDecimal(extralease)).longValue(); | |||
| } | |||
| List<BillTimeVo> billTimeVoList = WxRentContractServiceImpl.initBillTimeList(wxPropertyContract.getRentalStartDate(),wxPropertyContract.getRentalEndDate(),wxPropertyContract.getAdjustPeriod(),dayType,receivePeriod); | |||
| //自然月,开始日期、缴款日,结束日期 | |||
| if(wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ | |||
| int rentStartDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxPropertyContract.getRentalStartDate())); | |||
| int startDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxBillProperty.getStarttime())); | |||
| int endDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxPropertyContract.getRentalEndDate())); | |||
| if(i == 0){//第一周期 | |||
| double oneDayProce = (double) price / DateUtils.getMonthDayCount(wxBillProperty.getStarttime()); | |||
| double needPayDouble; | |||
| if(receivePeriod <= 1) {//周期为一个月 | |||
| wxBillProperty.setEndtime(DateUtils.getLastDayForMonth(wxBillProperty.getStarttime())); | |||
| needPayDouble = oneDayProce * (DateUtils.getMonthDayCount(wxBillProperty.getStarttime())-startDateInt+1); | |||
| }else{ //周期大于一个月 | |||
| Date firstDay = DateUtils.getFirstDayForCurrMonth(wxBillProperty.getStarttime()); | |||
| instance.clear(); | |||
| instance.setTime(firstDay); | |||
| //最后一个期有余,加上残月,不整除时,最后一个月有余,否则为0 | |||
| if(extralease > 0 && (i == paycount - 1)){ | |||
| instance.add(dayType, extralease); | |||
| instance.add(Calendar.DAY_OF_MONTH, rentStartDateInt-1); | |||
| }else{ | |||
| instance.add(dayType, receivePeriod); | |||
| } | |||
| instance.add(Calendar.DAY_OF_MONTH, -1); | |||
| wxBillProperty.setEndtime(instance.getTime()); | |||
| if(isLastYesr && (i == paycount - 1)){ //最后一年 最后一期 | |||
| needPayDouble = 0; | |||
| oneDayProce = (double) price/DateUtils.getMonthDayCount(wxBillProperty.getEndtime()); | |||
| if(receivePeriod > 1) { | |||
| needPayDouble += price * extralease; | |||
| } | |||
| if(!isFirstDay(wxPropertyContract.getRentalStartDate())) { //残月才加 | |||
| needPayDouble += oneDayProce * endDateInt; | |||
| } | |||
| }else{ | |||
| //[A/31 *(31-12+1)]+A+A | |||
| needPayDouble = oneDayProce * (DateUtils.getMonthDayCount(wxBillProperty.getStarttime())-startDateInt+1); | |||
| needPayDouble += price * (receivePeriod - 1); | |||
| } | |||
| } | |||
| DecimalFormat format = new DecimalFormat("0"); | |||
| needpay = Long.parseLong(format.format(needPayDouble)); //分做四舍五入 | |||
| }else if(i < paycount - 1){//中间周期 | |||
| Date receiveDate = DateUtils.getFirstDayOfNextMonth(startdate,receivePeriod * i); | |||
| wxBillProperty.setReceiveDate(receiveDate); | |||
| wxBillProperty.setStarttime(receiveDate); | |||
| wxBillProperty.setEndtime(DateUtils.getLastDayForMonth(wxBillProperty.getStarttime(),receivePeriod * i)); | |||
| instance.clear(); | |||
| instance.setTime(receiveDate); | |||
| instance.add(dayType, receivePeriod); | |||
| instance.add(Calendar.DAY_OF_MONTH, -1); | |||
| wxBillProperty.setEndtime(instance.getTime()); | |||
| }else if(i == paycount - 1) {//最后周期 | |||
| //receivePeriod * i 得到开始日期 | |||
| Date receiveDate = DateUtils.getFirstDayOfNextMonth(startdate,receivePeriod * i); | |||
| wxBillProperty.setReceiveDate(receiveDate); | |||
| wxBillProperty.setStarttime(receiveDate); | |||
| //得到开始日期第一天 | |||
| Date firstDay = DateUtils.getFirstDayForCurrMonth(wxBillProperty.getStarttime()); | |||
| instance.clear(); | |||
| instance.setTime(firstDay); | |||
| //若最后一期有余,带上残月,(不整除时,最后一个月有余,否则extralease=0) | |||
| if(isFirstDay(wxPropertyContract.getRentalStartDate())){ //月第一天起租 | |||
| if(receivePeriod > 1){ | |||
| if(isLastYesr && extralease > 0){ | |||
| instance.add(dayType, extralease); | |||
| }else{ | |||
| instance.add(dayType, receivePeriod); | |||
| } | |||
| }else{ | |||
| instance.add(dayType, receivePeriod); | |||
| } | |||
| }else{ | |||
| if(isLastYesr) { | |||
| instance.add(dayType, extralease); | |||
| instance.add(Calendar.DAY_OF_MONTH, rentStartDateInt - 1); | |||
| }else{ | |||
| instance.add(dayType, receivePeriod); | |||
| } | |||
| } | |||
| int index = 0; | |||
| for (BillTimeVo billTimeVo : billTimeVoList){ | |||
| if(yearList.size() > 1) { | |||
| if (sd.format(billTimeVo.getStartDate()).equals(sd.format(endDate)) || billTimeVo.getStartDate().after(endDate)) { | |||
| logger.info("=====billTimeVo.getStartDate():"+sd.format(billTimeVo.getStartDate())+" endDate:"+sd.format(endDate)); | |||
| //先减一个月 后加上残月 | |||
| instance.add(Calendar.DAY_OF_MONTH, -1); | |||
| wxBillProperty.setEndtime(instance.getTime()); | |||
| //逻辑同计算endtime | |||
| double needPayDouble = 0; | |||
| double oneDayProce = (double) price/DateUtils.getMonthDayCount(wxBillProperty.getEndtime()); | |||
| if(isFirstDay(wxPropertyContract.getRentalStartDate())){ | |||
| if(receivePeriod > 1) { | |||
| if(isLastYesr && extralease > 0) { | |||
| needPayDouble += price * extralease; | |||
| }else{ | |||
| needPayDouble += price * receivePeriod; | |||
| } | |||
| }else { | |||
| needPayDouble += price * receivePeriod; | |||
| } | |||
| }else{ | |||
| if(isLastYesr) { | |||
| needPayDouble += price * extralease; | |||
| needPayDouble += oneDayProce * endDateInt; | |||
| }else{ | |||
| needPayDouble += price * receivePeriod; | |||
| } | |||
| index++; | |||
| if(index >= yearList.size()-1){ | |||
| endDate = wxPropertyContract.getRentalEndDate(); | |||
| }else { | |||
| endDate = yearList.get(index); | |||
| } | |||
| DecimalFormat format = new DecimalFormat("0"); | |||
| needpay = Long.parseLong(format.format(needPayDouble)); //分做四舍五入 | |||
| logger.info("==========cross:"+sd.format(endDate)); | |||
| } | |||
| } | |||
| //最后一期截止到结束日期 | |||
| if(i == paycount - 1 && isLastYesr){ | |||
| wxBillProperty.setEndtime(wxPropertyContract.getRentalEndDate()); | |||
| //当天也算,加1天 | |||
| Date newEndDate = DateUtils.getDaySet(wxBillProperty.getEndtime(),Calendar.DATE,1); | |||
| //按日 | |||
| if(wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode())){ | |||
| int dayCount = DateUtils.daysBetween(wxBillProperty.getStarttime(),newEndDate); | |||
| needpay = dayCount*price; | |||
| }else{ | |||
| //按月 | |||
| int[] diff = DateUtils.getDiff(wxBillProperty.getStarttime(),newEndDate); | |||
| needpay = diff[0]*price; | |||
| //获取price 、shopInfo | |||
| long price = priceArrs[index]; | |||
| double oneDayProce = (double) price/DateUtils.getMonthDayCount(wxPropertyContract.getRentalEndDate()); | |||
| needpay += diff[1] * oneDayProce; | |||
| } | |||
| } | |||
| WxBillProperty wxBillProperty = new WxBillProperty(); | |||
| wxBillProperty.setIsPreview(isPreview); | |||
| wxBillProperty.setId(idWorker.nextId()); | |||
| wxBillProperty.setPropertyContractId(wxPropertyContract.getId()); | |||
| wxBillProperty.setPay(0L); | |||
| wxBillProperty.setStarttime(billTimeVo.getStartDate()); | |||
| wxBillProperty.setEndtime(billTimeVo.getEndDate()); | |||
| wxBillProperty.setReceiveDate(billTimeVo.getReceiveDate()); | |||
| long needpay; | |||
| //当天也算,加1天 | |||
| Date newEndDate = DateUtils.getDaySet(wxBillProperty.getEndtime(),Calendar.DATE,1); | |||
| //按日 | |||
| if(wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode())){ | |||
| int dayCount = DateUtils.daysBetween(wxBillProperty.getStarttime(),newEndDate); | |||
| needpay = dayCount*price; | |||
| }else{ | |||
| //按月 | |||
| int[] diff = DateUtils.getDiff(wxBillProperty.getStarttime(),newEndDate); | |||
| needpay = diff[0]*price; | |||
| double oneDayProce = (double) price/DateUtils.getMonthDayCount(wxPropertyContract.getRentalEndDate()); | |||
| needpay += diff[1] * oneDayProce; | |||
| } | |||
| wxBillProperty.setNeedPay(needpay); | |||
| wxBillProperty.setOwe(needpay); | |||
| wxBillProperty.setReceivePay(needpay); | |||
| //截止收租日在当前时间之前 | |||
| Date date = new Date(); | |||
| if (wxBillProperty.getReceiveDate().before(date)) { | |||
| long day = (time.getTime() - date.getTime()) / (24 * 60 * 60 * 1000); | |||
| long day = (wxBillProperty.getReceiveDate().getTime() - date.getTime()) / (24 * 60 * 60 * 1000); | |||
| wxBillProperty.setStatus(EnumBillRentStatus.NOT_PAID.getCode()); | |||
| wxBillProperty.setExpiredDay(day); | |||
| } else {//截止收租日在当前时间之后 | |||
| @@ -775,7 +613,6 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService | |||
| wxBillProperty.setExpiredDay(0L); | |||
| } | |||
| } | |||
| wxBillProperty.setTenantId(wxMerchant.getTenantId()); | |||
| wxBillProperty.setIsDel(0); | |||
| wxBillProperty.setMerchantId(wxMerchant.getId()); | |||
| @@ -789,14 +626,10 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService | |||
| if (shopInfo != null) { | |||
| wxBillProperty.setShopInfo(JSONObject.toJSONString(shopInfo)); | |||
| } | |||
| try { | |||
| wxBillPropertyMapper.insertSelective(wxBillProperty); | |||
| resultList.add(wxBillProperty); | |||
| } catch (Exception e) { | |||
| logger.error("添加租赁账单失败,e:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); | |||
| } | |||
| wxBillPropertyMapper.insertSelective(wxBillProperty); | |||
| resultList.add(wxBillProperty); | |||
| } | |||
| resultMap.put("billcount",billcount); | |||
| resultMap.put("billList",resultList); | |||
| return resultMap; | |||
| @@ -840,9 +673,9 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService | |||
| result = buildRentMonth(wxMerchant, userId, propertyContract, receivePeriod, lease, rentalStartDate, price,isPreview); | |||
| } else { | |||
| //如果按日 | |||
| //处理lease | |||
| lease = DateUtils.daysBetween(propertyContract.getRentalStartDate(),propertyContract.getRentalEndDate()); | |||
| Map<String, Object> resultMap = buildRent(lease, receivePeriod, price, rentalStartDate, Calendar.DAY_OF_MONTH, propertyContract, userId, wxMerchant, 0, isPreview, null,false); | |||
| List<Date> yearList = new ArrayList<>(); | |||
| yearList.add(rentalStartDate); | |||
| Map<String, Object> resultMap = buildRent(receivePeriod,new long[]{price}, yearList, Calendar.DAY_OF_MONTH, propertyContract, userId, wxMerchant, 0, isPreview, null); | |||
| result = (List<WxBillProperty>)resultMap.get("billList"); | |||
| } | |||
| } | |||
| @@ -9,6 +9,7 @@ import com.iformall.common.IdWorker; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.vo.BillTimeVo; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| @@ -722,10 +723,9 @@ public class WxRentContractServiceImpl implements WxRentContractService { | |||
| rentList = buildRentMonth(wxMerchant, userId, wxRentContract, receivePeriod, lease, rentalStartDate, price,isPreview); | |||
| } else { | |||
| //如果按日 | |||
| //处理lease | |||
| lease = DateUtils.daysBetween(wxRentContract.getRentalStartDate(),wxRentContract.getRentalEndDate()); | |||
| Map<String, Object> resultMap = buildRent(lease, receivePeriod, price, rentalStartDate, Calendar.DAY_OF_MONTH, wxRentContract, userId, wxMerchant, 0, isPreview, null,false); | |||
| List<Date> yearList = new ArrayList<>(); | |||
| yearList.add(rentalStartDate); | |||
| Map<String, Object> resultMap = buildRent(receivePeriod, new long[]{price}, yearList, Calendar.DAY_OF_MONTH, wxRentContract, userId, wxMerchant, 0, isPreview,null); | |||
| rentList = ( List<WxBillRent>)resultMap.get("billList"); | |||
| } | |||
| } | |||
| @@ -831,6 +831,8 @@ public class WxRentContractServiceImpl implements WxRentContractService { | |||
| int billcount = 0; | |||
| List<WxBillRent> resultList = new ArrayList<>(); | |||
| List<Date> yearList = new ArrayList<>(); | |||
| for (int i = 0; i < size; i++) { | |||
| Calendar instance = Calendar.getInstance(); | |||
| Date startDate; | |||
| @@ -848,263 +850,102 @@ public class WxRentContractServiceImpl implements WxRentContractService { | |||
| instance.add(Calendar.MONTH, month * i); | |||
| startDate = instance.getTime(); | |||
| } | |||
| Map<String, Object> resultMap = buildRent(leaseArr[i], receivePeriod, priceArrs[i], startDate, Calendar.MONTH, wxRentContract, userId, wxMerchant, billcount, isPreview, shopInfos.isEmpty() ? null : shopInfos.get(i),i==size-1?true:false); | |||
| List<WxBillRent> billRentList = (List<WxBillRent>)resultMap.get("billList"); | |||
| billcount = (Integer)resultMap.get("billcount"); | |||
| resultList.addAll(billRentList); | |||
| } | |||
| return resultList; | |||
| } | |||
| public boolean isFirstDay(Date date){ | |||
| int dateInt = Integer.parseInt(new SimpleDateFormat("d").format(date)); | |||
| if(dateInt == 1){ | |||
| return true; | |||
| yearList.add(startDate); | |||
| } | |||
| return false; | |||
| } | |||
| public boolean isCrossMonth(Date start,Date end){ | |||
| int startInt = Integer.parseInt(new SimpleDateFormat("M").format(start)); | |||
| int endInt = Integer.parseInt(new SimpleDateFormat("M").format(end)); | |||
| if(startInt != endInt){ | |||
| return true; | |||
| } | |||
| return false; | |||
| Map<String, Object> resultMap = buildRent(receivePeriod, priceArrs, yearList, Calendar.MONTH, wxRentContract, userId, wxMerchant, billcount, isPreview, shopInfos); | |||
| List<WxBillRent> billRentList = (List<WxBillRent>)resultMap.get("billList"); | |||
| resultList.addAll(billRentList); | |||
| return resultList; | |||
| } | |||
| public Map<String, Object> buildRent(int lease, int receivePeriod, long price, Date startdate, int dayType, WxRentContract wxRentContract, Long userId, WxMerchant wxMerchant, int billcount, Integer isPreview, Map<String, Object> shopInfo, boolean isLastYesr) { | |||
| System.out.println("------lease:"+lease+"receivePeriod:"+receivePeriod+"price:"+price+"start:"+DateUtils.date2String(startdate,"yyyy-MM-dd") | |||
| +"dayType:"+dayType+"billcount:"+billcount); | |||
| String shopInfoStr = null; | |||
| if (shopInfo != null) { | |||
| shopInfoStr = JSONObject.toJSONString(shopInfo); | |||
| } else { | |||
| if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode()) && | |||
| wxRentContract.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) { | |||
| String rentInfo = wxRentContract.getRentInfo(); | |||
| JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); | |||
| int rentSize = rentInfoArray.size(); | |||
| Map<String, Object> shopInfoMap = new HashMap<>(); | |||
| for (int i = 0; i < rentSize; i++) { | |||
| JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); | |||
| shopInfoMap.put(rentInfoObject.getString("shopNumber"), 0); | |||
| } | |||
| shopInfoStr = JSONObject.toJSONString(shopInfoMap); | |||
| } | |||
| } | |||
| public Map<String, Object> buildRent(int receivePeriod,long[] priceArrs, List<Date> yearList,int dayType, WxRentContract wxRentContract, Long userId, WxMerchant wxMerchant, int billcount, Integer isPreview,List<Map<String, Object>> shopInfoList) { | |||
| SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); | |||
| Map<String,Object> resultMap = new HashedMap(); | |||
| List<WxBillRent> resultList = new ArrayList<>(); | |||
| int extralease = lease % receivePeriod; //余 | |||
| int extracount = extralease > 0 ? 1 : 0; | |||
| int paycount = lease / receivePeriod + extracount; | |||
| int index = paycount - 1; | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| //自然月计租,而且残月,周期整除,n+1,最后一个周期作为残月 | |||
| if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode()) | |||
| && !isFirstDay(wxRentContract.getRentalStartDate()) | |||
| && (wxRentContract.getLease() % wxRentContract.getReceivePeriod() == 0) | |||
| && isLastYesr | |||
| && isCrossMonth(wxRentContract.getRentalStartDate(),wxRentContract.getRentalEndDate()) | |||
| ){ | |||
| paycount ++; | |||
| Date endDate = null; | |||
| if(yearList.size() > 1){ | |||
| endDate = yearList.get(1); | |||
| } | |||
| for(int i = 0; i < paycount; i++){ | |||
| WxBillRent wxBillRent = new WxBillRent(); | |||
| wxBillRent.setIsPreview(isPreview); | |||
| wxBillRent.setId(idWorker.nextId()); | |||
| wxBillRent.setRentContractId(wxRentContract.getId()); | |||
| wxBillRent.setPay(0L); | |||
| long needpay = new BigDecimal(price).multiply(new BigDecimal(receivePeriod)).longValue(); | |||
| List<BillTimeVo> billTimeVoList = initBillTimeList(wxRentContract.getRentalStartDate(),wxRentContract.getRentalEndDate(),wxRentContract.getAdjustPeriod(),dayType,receivePeriod); | |||
| Calendar instance = Calendar.getInstance(); | |||
| Date date = new Date(); | |||
| instance.setTime(startdate); | |||
| instance.add(dayType, receivePeriod * i); | |||
| if(!wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ | |||
| instance.add(Calendar.DAY_OF_MONTH, -1); | |||
| } | |||
| Date time = instance.getTime(); | |||
| wxBillRent.setReceiveDate(time); | |||
| //账单开始时间 | |||
| instance.clear(); | |||
| instance.setTime(wxBillRent.getReceiveDate()); | |||
| if(!wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ | |||
| instance.add(Calendar.DAY_OF_MONTH, 1); | |||
| } | |||
| wxBillRent.setStarttime(instance.getTime()); | |||
| //账单结束时间 | |||
| instance.clear(); | |||
| instance.setTime(wxBillRent.getStarttime()); | |||
| instance.add(dayType, receivePeriod); | |||
| instance.add(Calendar.DAY_OF_MONTH, -1); | |||
| wxBillRent.setEndtime(instance.getTime()); | |||
| //最后一个周期 | |||
| if (extracount > 0 && i == index) { | |||
| //账单开始时间 | |||
| instance.clear(); | |||
| instance.setTime(wxBillRent.getReceiveDate()); | |||
| if(!wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ | |||
| instance.add(Calendar.DAY_OF_MONTH, 1); | |||
| int index = 0; | |||
| for (BillTimeVo billTimeVo : billTimeVoList){ | |||
| if(yearList.size() > 1) { | |||
| if (sd.format(billTimeVo.getStartDate()).equals(sd.format(endDate)) || billTimeVo.getStartDate().after(endDate)) { | |||
| logger.info("=====billTimeVo.getStartDate():"+sd.format(billTimeVo.getStartDate())+" endDate:"+sd.format(endDate)); | |||
| index++; | |||
| if(index >= yearList.size()-1){ | |||
| endDate = wxRentContract.getRentalEndDate(); | |||
| }else { | |||
| endDate = yearList.get(index); | |||
| } | |||
| logger.info("==========cross:"+sd.format(endDate)); | |||
| } | |||
| wxBillRent.setStarttime(instance.getTime()); | |||
| //账单结束时间 | |||
| instance.clear(); | |||
| instance.setTime(wxBillRent.getStarttime()); | |||
| instance.add(dayType, extralease); | |||
| instance.add(Calendar.DAY_OF_MONTH, -1); | |||
| wxBillRent.setEndtime(instance.getTime()); | |||
| needpay = new BigDecimal(price).multiply(new BigDecimal(extralease)).longValue(); | |||
| } | |||
| //自然月,开始日期、缴款日,结束日期 | |||
| if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ | |||
| int rentStartDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxRentContract.getRentalStartDate())); | |||
| int startDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxBillRent.getStarttime())); | |||
| int endDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxRentContract.getRentalEndDate())); | |||
| if(i == 0){//第一周期 | |||
| double oneDayProce = (double) price / DateUtils.getMonthDayCount(wxBillRent.getStarttime()); | |||
| double needPayDouble; | |||
| if(receivePeriod <= 1) {//周期为一个月 | |||
| wxBillRent.setEndtime(DateUtils.getLastDayForMonth(wxBillRent.getStarttime())); | |||
| needPayDouble = oneDayProce * (DateUtils.getMonthDayCount(wxBillRent.getStarttime())-startDateInt+1); | |||
| }else{ //周期大于一个月 | |||
| Date firstDay = DateUtils.getFirstDayForCurrMonth(wxBillRent.getStarttime()); | |||
| instance.clear(); | |||
| instance.setTime(firstDay); | |||
| //最后一个期有余,加上残月,不整除时,最后一个月有余,否则为0 | |||
| if(extralease > 0 && (i == paycount - 1)){ | |||
| instance.add(dayType, extralease); | |||
| instance.add(Calendar.DAY_OF_MONTH, rentStartDateInt-1); | |||
| }else{ | |||
| instance.add(dayType, receivePeriod); | |||
| } | |||
| instance.add(Calendar.DAY_OF_MONTH, -1); | |||
| wxBillRent.setEndtime(instance.getTime()); | |||
| if(isLastYesr && (i == paycount - 1)){ //最后一年 最后一期 | |||
| needPayDouble = 0; | |||
| oneDayProce = (double) price/DateUtils.getMonthDayCount(wxBillRent.getEndtime()); | |||
| if(receivePeriod > 1) { | |||
| needPayDouble += price * extralease; | |||
| } | |||
| if(!isFirstDay(wxRentContract.getRentalStartDate())) { //残月才加 | |||
| needPayDouble += oneDayProce * endDateInt; | |||
| } | |||
| }else{ | |||
| //[A/31 *(31-12+1)]+A+A | |||
| needPayDouble = oneDayProce * (DateUtils.getMonthDayCount(wxBillRent.getStarttime())-startDateInt+1); | |||
| needPayDouble += price * (receivePeriod - 1); | |||
| } | |||
| } | |||
| DecimalFormat format = new DecimalFormat("0"); | |||
| needpay = Long.parseLong(format.format(needPayDouble)); //分做四舍五入 | |||
| }else if(i < paycount - 1){//中间周期 | |||
| Date receiveDate = DateUtils.getFirstDayOfNextMonth(startdate,receivePeriod * i); | |||
| wxBillRent.setReceiveDate(receiveDate); | |||
| wxBillRent.setStarttime(receiveDate); | |||
| wxBillRent.setEndtime(DateUtils.getLastDayForMonth(wxBillRent.getStarttime(),receivePeriod * i)); | |||
| instance.clear(); | |||
| instance.setTime(receiveDate); | |||
| instance.add(dayType, receivePeriod); | |||
| instance.add(Calendar.DAY_OF_MONTH, -1); | |||
| wxBillRent.setEndtime(instance.getTime()); | |||
| }else if(i == paycount - 1) {//最后周期 | |||
| //receivePeriod * i 得到开始日期 | |||
| Date receiveDate = DateUtils.getFirstDayOfNextMonth(startdate,receivePeriod * i); | |||
| wxBillRent.setReceiveDate(receiveDate); | |||
| wxBillRent.setStarttime(receiveDate); | |||
| //得到开始日期第一天 | |||
| Date firstDay = DateUtils.getFirstDayForCurrMonth(wxBillRent.getStarttime()); | |||
| instance.clear(); | |||
| instance.setTime(firstDay); | |||
| //若最后一期有余,带上残月,(不整除时,最后一个月有余,否则extralease=0) | |||
| if(isFirstDay(wxRentContract.getRentalStartDate())){ //月第一天起租 | |||
| if(receivePeriod > 1){ | |||
| if(isLastYesr && extralease > 0){ | |||
| instance.add(dayType, extralease); | |||
| }else{ | |||
| instance.add(dayType, receivePeriod); | |||
| } | |||
| }else{ | |||
| instance.add(dayType, receivePeriod); | |||
| } | |||
| }else{ | |||
| if(isLastYesr) { | |||
| instance.add(dayType, extralease); | |||
| instance.add(Calendar.DAY_OF_MONTH, rentStartDateInt - 1); | |||
| }else{ | |||
| instance.add(dayType, receivePeriod); | |||
| } | |||
| } | |||
| //获取price 、shopInfo | |||
| long price = priceArrs[index]; | |||
| Map<String, Object> shopInfo = null; | |||
| if(shopInfoList != null){ | |||
| shopInfo = shopInfoList.get(index); | |||
| } | |||
| //先减一个月 后加上残月 | |||
| instance.add(Calendar.DAY_OF_MONTH, -1); | |||
| wxBillRent.setEndtime(instance.getTime()); | |||
| //逻辑同计算endtime | |||
| double needPayDouble = 0; | |||
| double oneDayProce = (double) price/DateUtils.getMonthDayCount(wxBillRent.getEndtime()); | |||
| if(isFirstDay(wxRentContract.getRentalStartDate())){ | |||
| if(receivePeriod > 1) { | |||
| if(isLastYesr && extralease > 0) { | |||
| needPayDouble += price * extralease; | |||
| }else{ | |||
| needPayDouble += price * receivePeriod; | |||
| } | |||
| }else { | |||
| needPayDouble += price * receivePeriod; | |||
| } | |||
| }else{ | |||
| if(isLastYesr) { | |||
| needPayDouble += price * extralease; | |||
| needPayDouble += oneDayProce * endDateInt; | |||
| }else{ | |||
| needPayDouble += price * receivePeriod; | |||
| } | |||
| String shopInfoStr = null; | |||
| if (shopInfo != null) { | |||
| shopInfoStr = JSONObject.toJSONString(shopInfo); | |||
| } else { | |||
| if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode()) && | |||
| wxRentContract.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) { | |||
| String rentInfo = wxRentContract.getRentInfo(); | |||
| JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); | |||
| int rentSize = rentInfoArray.size(); | |||
| Map<String, Object> shopInfoMap = new HashMap<>(); | |||
| for (int i = 0; i < rentSize; i++) { | |||
| JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); | |||
| shopInfoMap.put(rentInfoObject.getString("shopNumber"), 0); | |||
| } | |||
| DecimalFormat format = new DecimalFormat("0"); | |||
| needpay = Long.parseLong(format.format(needPayDouble)); //分做四舍五入 | |||
| shopInfoStr = JSONObject.toJSONString(shopInfoMap); | |||
| } | |||
| } | |||
| //最后一期截止到结束日期 | |||
| if(i == paycount - 1 && isLastYesr){ | |||
| wxBillRent.setEndtime(wxRentContract.getRentalEndDate()); | |||
| //当天也算,加1天 | |||
| Date newEndDate = DateUtils.getDaySet(wxBillRent.getEndtime(),Calendar.DATE,1); | |||
| //按日 | |||
| if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode())){ | |||
| int dayCount = DateUtils.daysBetween(wxBillRent.getStarttime(),newEndDate); | |||
| needpay = dayCount*price; | |||
| }else{ | |||
| //按月 | |||
| int[] diff = DateUtils.getDiff(wxBillRent.getStarttime(),newEndDate); | |||
| needpay = diff[0]*price; | |||
| WxBillRent wxBillRent = new WxBillRent(); | |||
| wxBillRent.setIsPreview(isPreview); | |||
| wxBillRent.setId(idWorker.nextId()); | |||
| wxBillRent.setRentContractId(wxRentContract.getId()); | |||
| wxBillRent.setPay(0L); | |||
| wxBillRent.setStarttime(billTimeVo.getStartDate()); | |||
| wxBillRent.setEndtime(billTimeVo.getEndDate()); | |||
| wxBillRent.setReceiveDate(billTimeVo.getReceiveDate()); | |||
| long needpay; | |||
| //当天也算,加1天 | |||
| Date newEndDate = DateUtils.getDaySet(wxBillRent.getEndtime(),Calendar.DATE,1); | |||
| //按日 | |||
| if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode())){ | |||
| int dayCount = DateUtils.daysBetween(wxBillRent.getStarttime(),newEndDate); | |||
| needpay = dayCount*price; | |||
| }else{ | |||
| //按月 | |||
| int[] diff = DateUtils.getDiff(wxBillRent.getStarttime(),newEndDate); | |||
| needpay = diff[0]*price; | |||
| double oneDayProce = (double) price/DateUtils.getMonthDayCount(wxRentContract.getRentalEndDate()); | |||
| needpay += diff[1] * oneDayProce; | |||
| } | |||
| double oneDayProce = (double) price/DateUtils.getMonthDayCount(wxRentContract.getRentalEndDate()); | |||
| needpay += diff[1] * oneDayProce; | |||
| } | |||
| wxBillRent.setNeedPay(needpay); | |||
| wxBillRent.setOwe(needpay); | |||
| wxBillRent.setReceivePay(needpay); | |||
| //截止收租日在当前时间之前 | |||
| Date date = new Date(); | |||
| if (wxBillRent.getReceiveDate().before(date)) { | |||
| long day = (time.getTime() - date.getTime()) / (24 * 60 * 60 * 1000); | |||
| long day = (wxBillRent.getReceiveDate().getTime() - date.getTime()) / (24 * 60 * 60 * 1000); | |||
| wxBillRent.setStatus(EnumBillRentStatus.NOT_PAID.getCode()); | |||
| wxBillRent.setExpiredDay(day); | |||
| } else {//截止收租日在当前时间之后 | |||
| @@ -1132,14 +973,10 @@ public class WxRentContractServiceImpl implements WxRentContractService { | |||
| wxBillRent.setRentShopType(wxRentContract.getRentShopType()); | |||
| wxBillRent.setPeriod(++billcount); | |||
| wxBillRent.setShopInfo(shopInfoStr); | |||
| try { | |||
| wxBillRentMapper.insertSelective(wxBillRent); | |||
| resultList.add(wxBillRent); | |||
| } catch (Exception e) { | |||
| logger.error("添加租赁账单失败,e:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); | |||
| } | |||
| wxBillRentMapper.insertSelective(wxBillRent); | |||
| resultList.add(wxBillRent); | |||
| } | |||
| resultMap.put("billcount",billcount); | |||
| resultMap.put("billList",resultList); | |||
| return resultMap; | |||
| @@ -1891,6 +1728,80 @@ public class WxRentContractServiceImpl implements WxRentContractService { | |||
| public Integer getShopType(WxRentContract wxRentContract) { | |||
| return wxRentContractMapper.getShopType(wxRentContract); | |||
| } | |||
| public static void main(String[] args) throws Exception{ | |||
| SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); | |||
| // Date start = sd.parse("2019-05-24"); | |||
| // Date end = sd.parse("2020-06-24"); | |||
| Date start = sd.parse("2019-05-24"); | |||
| Date end = sd.parse("2019-08-10"); | |||
| Integer adjustPeriod = EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode(); | |||
| Integer dayType = Calendar.MONTH; | |||
| int receivePeriod = 2; | |||
| List<BillTimeVo> list = initBillTimeList(start,end,adjustPeriod,dayType,receivePeriod); | |||
| for (BillTimeVo b:list) { | |||
| System.out.print(sd.format(b.getStartDate())); | |||
| System.out.print(" "+sd.format(b.getEndDate())); | |||
| System.out.print(" "+sd.format(b.getReceiveDate())); | |||
| System.out.println(); | |||
| } | |||
| } | |||
| public static List<BillTimeVo> initBillTimeList(Date start,Date end,Integer adjustPeriod,Integer dayType,int receivePeriod){ | |||
| List<BillTimeVo> list = new ArrayList<>(); | |||
| int count = 0; | |||
| while (true){ | |||
| BillTimeVo timeVo = new BillTimeVo(); | |||
| //开始时间 | |||
| timeVo.setStartDate(start); | |||
| //账单日 | |||
| Calendar instance = Calendar.getInstance(); | |||
| instance.setTime(start); | |||
| if(!adjustPeriod.equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ | |||
| instance.add(Calendar.DATE, -1); | |||
| } | |||
| timeVo.setReceiveDate(instance.getTime()); | |||
| //结束时间 | |||
| SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); | |||
| System.out.println(sd.format(start)); | |||
| instance.clear(); | |||
| instance.setTime(start); | |||
| instance.add(dayType, receivePeriod); | |||
| instance.add(Calendar.DATE, -1); | |||
| timeVo.setEndDate(instance.getTime()); | |||
| System.out.println(sd.format(instance.getTime())); | |||
| //自然月 | |||
| if(adjustPeriod.equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ | |||
| if(count == 0){ | |||
| timeVo.setEndDate(DateUtils.getLastDayForMonth(timeVo.getStartDate())); | |||
| } | |||
| } | |||
| if(timeVo.getEndDate().after(end)){ | |||
| timeVo.setEndDate(end); | |||
| } | |||
| list.add(timeVo); | |||
| //next | |||
| start = DateUtils.getDaySet(timeVo.getEndDate(),Calendar.DATE,1); | |||
| if(start.after(end)) { | |||
| break; | |||
| } | |||
| count ++; | |||
| } | |||
| return list; | |||
| } | |||
| } | |||
| @@ -292,5 +292,9 @@ | |||
| delete from wx_coupon_channel where sub_target_id = #{id} | |||
| </delete> | |||
| <select id="findQrcodeEmptyList" resultType="com.iformall.domain.po.WxCouponChannel"> | |||
| select * from wx_coupon_channel where qr_code is null | |||
| </select> | |||
| </mapper> | |||
| @@ -37,6 +37,7 @@ | |||
| <result column="auto_refund" jdbcType="INTEGER" property="autoRefund"/> | |||
| <result column="credit_price" jdbcType="INTEGER" property="creditPrice"/> | |||
| <result column="credit_refund" jdbcType="INTEGER" property="creditRefund"/> | |||
| <result column="qr_code" property="qrCode"/> | |||
| </resultMap> | |||
| <resultMap id="statisMap" type="com.iformall.domain.vo.WxCouponStatisVo"> | |||
| @@ -90,7 +91,7 @@ | |||
| `id`,`tenant_id`,`type`,`cover_img`,`cover_picture`,`detail_picture`,`title`,`sub_title`,`sale_price`,`use_price`,`use_limit_quantity`,`send_type`, | |||
| `valid_type`,`valid_start_date`,`valid_end_date`,`valid_days`,`detail`,`price`,`unit`,`remain_inventory`,`inventory`, | |||
| `remark`,`status`,`create_date`,`update_date`,`business`,`sub_business`,`support_transfer`,`subsidy_num`,`subsidy_type`, | |||
| `press_limit_num`, `press_limit_hours`, `auto_refund`,`credit_price`,`credit_refund` | |||
| `press_limit_num`, `press_limit_hours`, `auto_refund`,`credit_price`,`credit_refund`,qr_code | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -574,7 +574,7 @@ | |||
| ,count(distinct w.shop_id) xCount | |||
| from wx_merchant_shop w | |||
| where w.is_del=0 | |||
| and w.tenant_id = 456 | |||
| and w.tenant_id = #{tenantId} | |||
| group by xTime | |||
| order by xTime | |||
| </select> | |||
| @@ -33,12 +33,24 @@ | |||
| <if test=" null != tenantId "> | |||
| and `tenant_id` = #{tenantId} | |||
| </if> | |||
| <if test=" null != beginTime "> | |||
| and `begin_time` >= #{beginTime} | |||
| <if test='statusStr =="0,2" or status==1'> | |||
| <if test=" null != beginTime "> | |||
| and `begin_time` >= #{beginTime} | |||
| </if> | |||
| <if test=" null != endTime "> | |||
| and `begin_time` <= #{endTime} | |||
| </if> | |||
| </if> | |||
| <if test=" null != endTime "> | |||
| and `end_time` <= #{endTime} | |||
| <if test='status ==2 or status==3'> | |||
| <if test=" null != beginTime "> | |||
| and `end_time` >= #{beginTime} | |||
| </if> | |||
| <if test=" null != endTime "> | |||
| and `end_time` <= #{endTime} | |||
| </if> | |||
| </if> | |||
| <if test=" null != status "> | |||
| and `status` = #{status} | |||
| </if> | |||