diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxShop.java b/mallinkService/src/main/java/com/iformall/domain/po/WxShop.java index 45459b3fd..e3138dad8 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxShop.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxShop.java @@ -123,9 +123,6 @@ public class WxShop implements Serializable { @io.swagger.annotations.ApiModelProperty(value = "备注", name = "comments") private String comments; - @io.swagger.annotations.ApiModelProperty(value = "邮箱", name = "email") - private String email; - @io.swagger.annotations.ApiModelProperty(value = "是否删除1是0否", name = " ") private Integer isDel; @@ -137,14 +134,6 @@ public class WxShop implements Serializable { this.isDel = isDel; } - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - public String getTenantId() { return tenantId; } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java index 86e8bf982..2a7281e24 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java @@ -16,6 +16,7 @@ import com.iformall.service.WxFlowRecordService; import com.iformall.service.WxFlowService; import com.iformall.service.WxPropertyContractService; import com.iformall.utils.Constant; +import com.iformall.utils.DateUtils; import org.apache.commons.collections.map.HashedMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,6 +31,8 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.net.HttpURLConnection; import java.net.URL; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; import java.util.*; /** @@ -508,6 +511,63 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService wxBillProperty.setEndtime(instance.getTime()); needpay = price * extralease; } + + //自然月,开始日期、缴款日,结束日期 + if(wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ + if(i == 0){//第一周期 + wxBillProperty.setReceiveDate(wxPropertyContract.getStartDate()); + wxBillProperty.setStarttime(wxPropertyContract.getStartDate()); + double oneDayProce = (double) price / DateUtils.getMonthDayCount(wxPropertyContract.getStartDate()); + int startDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxPropertyContract.getStartDate())); + double needPayDouble; + + if(receivePeriod <= 1) {//周期为一个月 + wxBillProperty.setEndtime(DateUtils.getLastDayForMonth(wxPropertyContract.getStartDate())); + needPayDouble = oneDayProce * (DateUtils.getMonthDayCount(wxPropertyContract.getStartDate())-startDateInt+1); + }else{ //周期大于一个月 + wxBillProperty.setEndtime(DateUtils.getLastDayForMonth(wxPropertyContract.getStartDate(),receivePeriod - 1)); + // [A/31 *(31-12+1)]+A+A + needPayDouble = oneDayProce * (DateUtils.getMonthDayCount(wxPropertyContract.getStartDate())-startDateInt+1); + needPayDouble += price * (receivePeriod - 1); + } + DecimalFormat format = new DecimalFormat("0"); + needpay = Integer.parseInt(format.format(needPayDouble)); //分做四舍五入 + }else if(i < paycount - 1){//中间周期 + Date receiveDate = DateUtils.getFirstDayOfNextMonth(wxPropertyContract.getStartDate(),receivePeriod * i); + wxBillProperty.setReceiveDate(receiveDate); + wxBillProperty.setStarttime(receiveDate); + wxBillProperty.setEndtime(DateUtils.getLastDayForMonth(receiveDate,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) {//最后周期 + Date receiveDate = DateUtils.getFirstDayOfNextMonth(wxPropertyContract.getStartDate(),receivePeriod * i); + wxBillProperty.setReceiveDate(receiveDate); + wxBillProperty.setStarttime(receiveDate); + instance.clear(); + instance.setTime(receiveDate); + instance.add(dayType, extracount>0?extralease:receivePeriod);//最后一期不足,一个完整周期 + instance.add(Calendar.DAY_OF_MONTH, -1); + int endDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxPropertyContract.getEndDate())); + String endDateStr = DateUtils.date2String(instance.getTime(),"yyyy-MM")+ "-" +endDateInt; + wxBillProperty.setEndtime(DateUtils.stringToDate(endDateStr,"yyyy-MM-dd")); + + double needPayDouble; + double oneDayProce = (double) price/DateUtils.getMonthDayCount(wxBillProperty.getEndtime()); + if(receivePeriod <= 1) {//周期为一个月 + needPayDouble = oneDayProce * endDateInt; + }else{ + needPayDouble = price * (extralease-1); + needPayDouble += oneDayProce * endDateInt; + } + DecimalFormat format = new DecimalFormat("0"); + needpay = Integer.parseInt(format.format(needPayDouble)); //分做四舍五入 + } + } + wxBillProperty.setNeedPay(needpay); wxBillProperty.setOwe(needpay); wxBillProperty.setReceivePay(needpay); @@ -587,7 +647,8 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService Integer price = propertyContract.getPrice(); //按月计租 - if (propertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_MONTH.getCode())) { + if (propertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_MONTH.getCode()) + ||propertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) { result = buildRentMonth(wxMerchant, userId, propertyContract, receivePeriod, lease, rentalStartDate, price,isPreview); } else { //按日计租 diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java index 73a32287e..49928084f 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java @@ -562,7 +562,8 @@ public class WxRentContractServiceImpl implements WxRentContractService { Date rentalStartDate = wxRentContract.getRentalStartDate(); Integer price = wxRentContract.getPrice(); //按月计租 - if (wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_MONTH.getCode())) { + if (wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_MONTH.getCode()) + ||wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) { rentList = buildRentMonth(wxMerchant, userId, wxRentContract, receivePeriod, lease, rentalStartDate, price,isPreview); } else { //按日计租 @@ -678,22 +679,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { return resultList; } - /** - * 是否是残月 - * @param date - * @return - */ - public boolean incompleteMonth(Date date){ - if("01".equals(new SimpleDateFormat("dd").format(date))){ - return false; - } - return true; - } - public Map buildRent(int lease, int receivePeriod, int price, Date startdate, int dayType, WxRentContract wxRentContract, Long userId, WxMerchant wxMerchant, int billcount, Integer isPreview, Map shopInfo) { - //todo:test - wxRentContract.setAdjustPeriod(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode()); - String shopInfoStr = null; if (shopInfo != null) { shopInfoStr = JSONObject.toJSONString(shopInfo); @@ -754,40 +740,56 @@ public class WxRentContractServiceImpl implements WxRentContractService { //自然月,开始日期、缴款日,结束日期 if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){ if(i == 0){//第一周期 + wxBillRent.setReceiveDate(wxRentContract.getStartDate()); + wxBillRent.setStarttime(wxRentContract.getStartDate()); + double oneDayProce = (double) price / DateUtils.getMonthDayCount(wxRentContract.getStartDate()); + int startDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxRentContract.getStartDate())); + double needPayDouble; + if(receivePeriod <= 1) {//周期为一个月 - wxBillRent.setReceiveDate(wxRentContract.getStartDate()); - wxBillRent.setStarttime(wxRentContract.getStartDate()); - wxBillRent.setEndtime(DateUtils.getLastDayForCurrMonth()); - - double needPayDouble = (double) price / DateUtils.getCurrMonthDayCount(); - int startDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxRentContract.getStartDate())); - // 5月12日 周期:3 [A/31 *(31-12+1)]+A+A - needPayDouble = (needPayDouble * (DateUtils.getCurrMonthDayCount()-startDateInt+1)) + (price * (receivePeriod-1)); - DecimalFormat format = new DecimalFormat("0"); - needpay = Integer.parseInt(format.format(needPayDouble)); //分做四舍五入 - }else{ - wxBillRent.setReceiveDate(wxRentContract.getStartDate()); - wxBillRent.setStarttime(wxRentContract.getStartDate()); - wxBillRent.setEndtime(DateUtils.getFirstDayOfNextMonth(wxRentContract.getStartDate(),receivePeriod - 1)); - - double needPayDouble = (double) price / DateUtils.getCurrMonthDayCount(); - needPayDouble = needPayDouble * DateUtils.daysBetween(DateUtils.getFirstDayForCurrMonth(), wxRentContract.getStartDate()); - DecimalFormat format = new DecimalFormat("0"); - needpay = Integer.parseInt(format.format(needPayDouble)); //分做四舍五入 + wxBillRent.setEndtime(DateUtils.getLastDayForMonth(wxRentContract.getStartDate())); + needPayDouble = oneDayProce * (DateUtils.getMonthDayCount(wxRentContract.getStartDate())-startDateInt+1); + }else{ //周期大于一个月 + wxBillRent.setEndtime(DateUtils.getLastDayForMonth(wxRentContract.getStartDate(),receivePeriod - 1)); + // [A/31 *(31-12+1)]+A+A + needPayDouble = oneDayProce * (DateUtils.getMonthDayCount(wxRentContract.getStartDate())-startDateInt+1); + needPayDouble += price * (receivePeriod - 1); } + DecimalFormat format = new DecimalFormat("0"); + needpay = Integer.parseInt(format.format(needPayDouble)); //分做四舍五入 + }else if(i < paycount - 1){//中间周期 + Date receiveDate = DateUtils.getFirstDayOfNextMonth(wxRentContract.getStartDate(),receivePeriod * i); + wxBillRent.setReceiveDate(receiveDate); + wxBillRent.setStarttime(receiveDate); + wxBillRent.setEndtime(DateUtils.getLastDayForMonth(receiveDate,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) {//最后周期 - wxBillRent.setReceiveDate(DateUtils.getFirstDayForCurrMonth()); - wxBillRent.setStarttime(DateUtils.getFirstDayForCurrMonth()); - wxBillRent.setEndtime(wxRentContract.getStartDate()); - - double needPayDouble = (double) price/DateUtils.getCurrMonthDayCount(); - needPayDouble = needPayDouble * DateUtils.daysBetween(DateUtils.getFirstDayForCurrMonth(),wxRentContract.getStartDate()); + Date receiveDate = DateUtils.getFirstDayOfNextMonth(wxRentContract.getStartDate(),receivePeriod * i); + wxBillRent.setReceiveDate(receiveDate); + wxBillRent.setStarttime(receiveDate); + instance.clear(); + instance.setTime(receiveDate); + instance.add(dayType, extracount>0?extralease:receivePeriod);//最后一期不足,一个完整周期 + instance.add(Calendar.DAY_OF_MONTH, -1); + int endDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxRentContract.getEndDate())); + String endDateStr = DateUtils.date2String(instance.getTime(),"yyyy-MM")+ "-" +endDateInt; + wxBillRent.setEndtime(DateUtils.stringToDate(endDateStr,"yyyy-MM-dd")); + + double needPayDouble; + double oneDayProce = (double) price/DateUtils.getMonthDayCount(wxBillRent.getEndtime()); + if(receivePeriod <= 1) {//周期为一个月 + needPayDouble = oneDayProce * endDateInt; + }else{ + needPayDouble = price * (extralease-1); + needPayDouble += oneDayProce * endDateInt; + } DecimalFormat format = new DecimalFormat("0"); needpay = Integer.parseInt(format.format(needPayDouble)); //分做四舍五入 - }else{//中间周期 - wxBillRent.setReceiveDate(DateUtils.getFirstDayForCurrMonth()); - wxBillRent.setStarttime(DateUtils.getFirstDayForCurrMonth()); - wxBillRent.setEndtime(DateUtils.getLastDayForCurrMonth()); } } @@ -839,7 +841,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { } public static void main(String[] args) { - System.out.println(new SimpleDateFormat("d").format(DateUtils.getLastDayForCurrMonth())); + System.out.println(new SimpleDateFormat("d").format(DateUtils.getLastDayForMonth(new Date()))); } diff --git a/mallinkService/src/main/java/com/iformall/utils/DateUtils.java b/mallinkService/src/main/java/com/iformall/utils/DateUtils.java index eb669f7fc..77cee4dc8 100755 --- a/mallinkService/src/main/java/com/iformall/utils/DateUtils.java +++ b/mallinkService/src/main/java/com/iformall/utils/DateUtils.java @@ -948,22 +948,45 @@ public class DateUtils { cale.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 return cale.getTime(); } + /** + * 获取当前月的第一天 + * @return + */ + public static Date getFirstDayForCurrMonth(Date date){ + Calendar cale = Calendar.getInstance(); + cale.setTime(date); + cale.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 + return cale.getTime(); + } /** - * 获取当前月的最后一天 + * 获取指定月的最后一天 + * @return + */ + public static Date getLastDayForMonth(Date date){ + Calendar ca = Calendar.getInstance(); + ca.setTime(date); + ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH)); + return ca.getTime(); + } + /** + * 获取指定日期n个月后的最后一天 * @return */ - public static Date getLastDayForCurrMonth(){ + public static Date getLastDayForMonth(Date date, int amount){ Calendar ca = Calendar.getInstance(); + ca.setTime(date); ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH)); + ca.add(Calendar.MONTH, amount); return ca.getTime(); } /** - * 取得当月天数 + * 取得指定月的天数 * */ - public static int getCurrMonthDayCount() { + public static int getMonthDayCount(Date date) { Calendar a = Calendar.getInstance(); + a.setTime(date); a.set(Calendar.DATE, 1);//把日期设置为当月第一天 a.roll(Calendar.DATE, -1);//日期回滚一天,也就是最后一天 int maxDate = a.get(Calendar.DATE); @@ -1007,4 +1030,17 @@ public class DateUtils { return calendar.getTime(); } + /** + * 获取指定日期n个月后的最后一天 + * @return + */ + public static Date getLastDayOfNextMonth(Date date,int amount){ + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + calendar.set(Calendar.DAY_OF_MONTH,1); + calendar.add(Calendar.MONTH, amount); + Date d = calendar.getTime(); + return getFirstDayForCurrMonth(d); + } + } diff --git a/mallinkService/src/main/resources/mapper/WxShopMapper.xml b/mallinkService/src/main/resources/mapper/WxShopMapper.xml index aba684f35..278fbdc23 100644 --- a/mallinkService/src/main/resources/mapper/WxShopMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxShopMapper.xml @@ -24,7 +24,6 @@ - @@ -32,7 +31,7 @@ `id`,`tenant_id`,`shop_number`,`build_area`,`operation_area`,`building`, `floor`,`status`,`x`,`y`,`addr`,`baidu_poi`,`longitude`,`latitude`,`create_date`, - `update_date`,`img_url`,`manager`,`manager_phone`,`type`,`point_type`,`comments`,email,`is_del` + `update_date`,`img_url`,`manager`,`manager_phone`,`type`,`point_type`,`comments`,`is_del` @@ -131,10 +130,7 @@ and `point_type` = #{pointType} - - and `email` = #{email} - - + and id in @@ -158,7 +154,7 @@ s.img_url imgUrl,s.operation_area operationArea, s.status,b.building_name building,f.floor_name floor,m.`name` merchantName,m.id merchantId, m.link_person linkPerson,m.link_phone linkPhone,s.manager,s.manager_phone managerPhone, - s.type,s.point_type pointType,s.addr,s.email + s.type,s.point_type pointType,s.addr from wx_shop s left join wx_merchant_shop ms on ms.shop_id=s.id and ms.is_del=0 left join wx_merchant m on ms.merchant_id=m.id left join wx_mall_building b on s.building=b.id @@ -253,13 +249,9 @@ and s.`type` = #{type} - and s.`point_type` = #{pointType} - - and s.`email`= #{email} - and s.id in @@ -294,8 +286,6 @@ - - @@ -314,7 +304,7 @@ select m.`name` merchantName,s.build_area buildArea,s.operation_area operationArea, c.price,c.receive_period receivePeriod,s.shop_number shopNumber,m.link_person linkPerson, - m.link_phone linkPhone,s.email + m.link_phone linkPhone from wx_merchant_shop ms inner join wx_merchant m on ms.merchant_id=m.id inner join wx_shop s on ms.shop_id=s.id inner join wx_rent_contract c on ms.merchant_id=c.merchant_id @@ -458,7 +445,7 @@ s.img_url imgUrl,s.operation_area operationArea, s.status,b.building_name building,f.floor_name floor,m.`name` merchantName,m.id merchantId, m.link_person linkPerson,m.link_phone linkPhone,s.manager,s.manager_phone managerPhone, - m.brand,m.business_id businessId,m.shop_type shopType,s.email + m.brand,m.business_id businessId,m.shop_type shopType from wx_shop s left join wx_merchant_shop ms on ms.shop_id=s.id left join wx_merchant m on ms.merchant_id=m.id left join wx_mall_building b on s.building=b.id