diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxBillRent.java b/mallinkService/src/main/java/com/iformall/domain/po/WxBillRent.java index 995a56f85..3f60e4eca 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxBillRent.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillRent.java @@ -121,6 +121,17 @@ public class WxBillRent implements Serializable { @io.swagger.annotations.ApiModelProperty(value = "预览账单0否1是", name = "isPreview") private Integer isPreview; + @io.swagger.annotations.ApiModelProperty(value = "商铺信息", name = "shopInfo") + private String shopInfo; + + public String getShopInfo() { + return shopInfo; + } + + public void setShopInfo(String shopInfo) { + this.shopInfo = shopInfo; + } + public Integer getIsPreview() { return isPreview; } 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 948dea750..c80e08712 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java @@ -442,6 +442,16 @@ public class WxRentContractServiceImpl implements WxRentContractService { wxBillDeposit.setUpdatetime(date); wxBillDeposit.setIsDel(EnumDelStatus.NOT_DEL.getCode()); wxBillDeposit.setRentShopType(wxRentContract.getRentShopType()); + String rentInfo = wxRentContract.getRentInfo(); + if (rentInfo != null) { + JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); + Map shopInfo = new HashMap<>(); + for (int i = 0, size = rentInfoArray.size(); i < size; i++) { + JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); + shopInfo.put(rentInfoObject.getString("shopNumber"), rentInfoObject.get("deposit")); + } + + } try { wxBillDepositMapper.insertSelective(wxBillDeposit); } catch (Exception e) { @@ -483,7 +493,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { rentList = buildRentMonth(wxMerchant, userId, wxRentContract, receivePeriod, lease, rentalStartDate, price,isPreview); } else { //按日计租 - Map resultMap = buildRent(lease, receivePeriod, price, rentalStartDate, Calendar.DAY_OF_MONTH, wxRentContract, userId, wxMerchant, 0,isPreview); + Map resultMap = buildRent(lease, receivePeriod, price, rentalStartDate, Calendar.DAY_OF_MONTH, wxRentContract, userId, wxMerchant, 0, isPreview, null); rentList = ( List)resultMap.get("billList"); } } @@ -525,7 +535,10 @@ public class WxRentContractServiceImpl implements WxRentContractService { } public List buildRentMonth(WxMerchant wxMerchant, Long userId, WxRentContract wxRentContract, int receivePeriod, Integer lease, Date rentalStartDate, Integer price,Integer isPreview) { - List priceList = computePrice(wxRentContract.getRentInfo()); + String rentInfo = wxRentContract.getRentInfo(); + JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); + + List priceList = computePrice(rentInfo); int size = priceList.size(); int[] priceArrs = new int[size]; for (int i = 0; i < size; i++) { @@ -537,6 +550,17 @@ public class WxRentContractServiceImpl implements WxRentContractService { priceArrs[i] = sum; } + List> shopInfos = new ArrayList<>(); + for (int i = 0; i < size; i++) { + Map shopInfo = new HashMap<>(); + int[] ints = priceList.get(i); + for (int j = 0; j < ints.length; j++) { + JSONObject rentInfoObject = rentInfoArray.getJSONObject(j); + shopInfo.put(rentInfoObject.getString("shopNumber"), ints[j]); + } + shopInfos.add(shopInfo); + } + int month = 12; int divide = lease / month; int mod = lease % month; @@ -555,7 +579,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { instance.setTime(rentalStartDate); //开始时间 instance.add(Calendar.MONTH, month * i); - Map resultMap = buildRent(leaseArr[i], receivePeriod, priceArrs[i], instance.getTime(), Calendar.MONTH, wxRentContract, userId, wxMerchant, billcount, isPreview); + Map resultMap = buildRent(leaseArr[i], receivePeriod, priceArrs[i], instance.getTime(), Calendar.MONTH, wxRentContract, userId, wxMerchant, billcount, isPreview, shopInfos.get(i)); List billRentList = (List)resultMap.get("billList"); billcount = (Integer)resultMap.get("billcount"); resultList.addAll(billRentList); @@ -563,7 +587,11 @@ public class WxRentContractServiceImpl implements WxRentContractService { return resultList; } - public Map buildRent(int lease, int receivePeriod, int price, Date startdate, int dayType, WxRentContract wxRentContract, Long userId, WxMerchant wxMerchant, int billcount,Integer isPreview) { + 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) { + String shopInfoStr = null; + if (shopInfo != null) { + shopInfoStr = JSONObject.toJSONString(shopInfo); + } Map resultMap = new HashedMap(); List resultList = new ArrayList<>(); int extralease = lease % receivePeriod; @@ -650,6 +678,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { wxBillRent.setIsDel(EnumDelStatus.NOT_DEL.getCode()); wxBillRent.setRentShopType(wxRentContract.getRentShopType()); wxBillRent.setPeriod(++billcount); + wxBillRent.setShopInfo(shopInfoStr); try { wxBillRentMapper.insertSelective(wxBillRent); resultList.add(wxBillRent); @@ -1509,4 +1538,67 @@ public class WxRentContractServiceImpl implements WxRentContractService { wxRentContractMapper.updateApplyStatus(wxRentContract); } + + public static void main(String[] args) { + JSONArray rentInfoArray = JSONArray.parseArray("[{shopId:0,shopNumber:0,price:1000,adjustRatio:[1100,1100]},{shopId:1,shopNumber:1,price:2000,adjustRatio:[1200,1200]},{shopId:2,shopNumber:2,price:3000,adjustRatio:[1300,1300]}]"); + int arraySize = rentInfoArray.size(); + List priceList = new ArrayList<>(); + //第一年 + int[] priceArr = new int[arraySize]; + for (int i = 0; i < arraySize; i++) { + JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); + priceArr[i] = rentInfoObject.getIntValue("price"); + } + priceList.add(priceArr); + //大于一年 + JSONObject rentInfoObject = rentInfoArray.getJSONObject(0); + JSONArray adjustRatio = rentInfoObject.getJSONArray("adjustRatio"); + int adjustRatioSize = adjustRatio.size(); + + for (int i = 0; i < adjustRatioSize; i++) { + int[] priceArrs = new int[arraySize]; + for (int j = 0; j < arraySize; j++) { + rentInfoObject = rentInfoArray.getJSONObject(j); + adjustRatio = rentInfoObject.getJSONArray("adjustRatio");// + double price = priceList.get(i)[j] + priceList.get(i)[j] * adjustRatio.getIntValue(i) / 10000.0; + priceArrs[j] = new BigDecimal(price).setScale(0, RoundingMode.HALF_EVEN).intValue(); + } + priceList.add(priceArrs); + } + int size = priceList.size(); + int[] priceArrs = new int[size]; + for (int i = 0; i < size; i++) { + int[] price = priceList.get(i); + int sum = 0; + for (int p : price) { + sum += p; + } + priceArrs[i] = sum; + } + + + List> shopInfos = new ArrayList<>(); + for (int i = 0; i < size; i++) { + Map shopInfo = new HashMap<>(); + int[] ints = priceList.get(i); + for (int j = 0; j < ints.length; j++) { + rentInfoObject = rentInfoArray.getJSONObject(j); + shopInfo.put(rentInfoObject.getString("shopNumber"), ints[j]); + } + shopInfos.add(shopInfo); + } + + System.out.println(shopInfos); + //System.out.println(Arrays.toString(priceArr)); +// Calendar a = Calendar.getInstance(); +// a.set(Calendar.DATE, 1); +// a.roll(Calendar.DATE, -1); +// int maxDate = a.get(Calendar.DATE); +// System.out.println(maxDate); +// a.clear(); +// a.setTime(new Date()); +// System.out.println(a.get(Calendar.DAY_OF_MONTH)); + + } + } diff --git a/mallinkService/src/main/resources/mapper/WxBillRentMapper.xml b/mallinkService/src/main/resources/mapper/WxBillRentMapper.xml index e7a026ab6..088ddcc72 100644 --- a/mallinkService/src/main/resources/mapper/WxBillRentMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxBillRentMapper.xml @@ -26,14 +26,15 @@ - + + `id`,`rent_contract_id`,`receive_pay`,`pay`,`receive_date`,`pay_date`, `createtime`,`expired_day`,`tenant_id`,`owe`,`status`,`is_del`,`need_pay`, `merchant_id`,`user_id`,`shop_id`,`updatetime`,`rent_shop_type`, - `revenue`,`late_pay_ratio`,`late_pay_time`,`late_pay_price`,`period`,`is_preview` + `revenue`,`late_pay_ratio`,`late_pay_time`,`late_pay_price`,`period`,`is_preview`,`shop_info` @@ -85,7 +86,7 @@ br.`rent_contract_id` rentContractId,d.receive_pay deposit,case when br.late_pay_time is null then 0 else FLOOR(DATEDIFF(now(),br.late_pay_time)*br.late_pay_ratio/10000*br.owe) end latePayPrice, (select max(period) from wx_bill_rent where rent_contract_id=br.rent_contract_id) allPeriod,d.`status` - depositStatus + depositStatus,br.shop_info shopInfo from wx_bill_rent br left join wx_merchant m on br.merchant_id=m.id left join wx_shop s on br.shop_id=s.id left join wx_rent_contract r on br.rent_contract_id=r.id