@@ -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<String, Object> 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<String,Object> resultMap = buildRent(lease, receivePeriod, price, rentalStartDate, Calendar.DAY_OF_MONTH, wxRentContract, userId, wxMerchant, 0,isPreview);
Map<String, Object> resultMap = buildRent(lease, receivePeriod, price, rentalStartDate, Calendar.DAY_OF_MONTH, wxRentContract, userId, wxMerchant, 0, isPreview, null );
rentList = ( List<WxBillRent>)resultMap.get("billList");
}
}
@@ -525,7 +535,10 @@ public class WxRentContractServiceImpl implements WxRentContractService {
}
public List<WxBillRent> buildRentMonth(WxMerchant wxMerchant, Long userId, WxRentContract wxRentContract, int receivePeriod, Integer lease, Date rentalStartDate, Integer price,Integer isPreview) {
List<int[]> priceList = computePrice(wxRentContract.getRentInfo());
String rentInfo = wxRentContract.getRentInfo();
JSONArray rentInfoArray = JSONArray.parseArray(rentInfo);
List<int[]> 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<Map<String, Object>> shopInfos = new ArrayList<>();
for (int i = 0; i < size; i++) {
Map<String, Object> 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<String, Object> resultMap = buildRent(leaseArr[i], receivePeriod, priceArrs[i], instance.getTime(), Calendar.MONTH, wxRentContract, userId, wxMerchant, billcount, isPreview);
Map<String, Object> resultMap = buildRent(leaseArr[i], receivePeriod, priceArrs[i], instance.getTime(), Calendar.MONTH, wxRentContract, userId, wxMerchant, billcount, isPreview, shopInfos.get(i) );
List<WxBillRent> billRentList = (List<WxBillRent>)resultMap.get("billList");
billcount = (Integer)resultMap.get("billcount");
resultList.addAll(billRentList);
@@ -563,7 +587,11 @@ public class WxRentContractServiceImpl implements WxRentContractService {
return resultList;
}
public Map<String,Object> buildRent(int lease, int receivePeriod, int price, Date startdate, int dayType, WxRentContract wxRentContract, Long userId, WxMerchant wxMerchant, int billcount,Integer isPreview) {
public Map<String, Object> buildRent(int lease, int receivePeriod, int price, Date startdate, int dayType, WxRentContract wxRentContract, Long userId, WxMerchant wxMerchant, int billcount, Integer isPreview, Map<String, Object> shopInfo) {
String shopInfoStr = null;
if (shopInfo != null) {
shopInfoStr = JSONObject.toJSONString(shopInfo);
}
Map<String,Object> resultMap = new HashedMap();
List<WxBillRent> 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<int[]> 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<Map<String, Object>> shopInfos = new ArrayList<>();
for (int i = 0; i < size; i++) {
Map<String, Object> 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));
}
}