| @@ -206,23 +206,35 @@ public class WxRentContractServiceImpl implements WxRentContractService { | |||
| record.setCreatetime(date); | |||
| record.setUpdatetime(date); | |||
| String rentInfo = record.getRentInfo(); | |||
| JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); | |||
| int size = rentInfoArray.size(); | |||
| if (size == 0) { | |||
| return new ResultData(ErrorCode.SHOP_NOT_SELECTED); | |||
| } | |||
| //查询rent_info 包括 shopId | |||
| for (int i = 0; i < size; i++) { | |||
| JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); | |||
| if (record.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { | |||
| String rentInfo = record.getRentInfo(); | |||
| JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); | |||
| int size = rentInfoArray.size(); | |||
| if (size == 0) { | |||
| return new ResultData(ErrorCode.SHOP_NOT_SELECTED); | |||
| } | |||
| //查询rent_info 包括 shopId | |||
| for (int i = 0; i < size; i++) { | |||
| JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); | |||
| WxRentContract wxRentContract = new WxRentContract(); | |||
| wxRentContract.setTenantId(record.getTenantId()); | |||
| wxRentContract.setShopId(rentInfoObject.getLong("shopId")); | |||
| int count = wxRentContractMapper.selectRentContractCountByShopId(wxRentContract); | |||
| if (count > 0) { | |||
| String shopNumber = rentInfoObject.getString("shopNumber"); | |||
| return new ResultData(ErrorCode.SHOP_IS_RENT.getCode(), "店铺 " + shopNumber + " 已出租"); | |||
| } | |||
| } | |||
| } else { | |||
| WxRentContract wxRentContract = new WxRentContract(); | |||
| wxRentContract.setTenantId(record.getTenantId()); | |||
| wxRentContract.setShopId(rentInfoObject.getLong("shopId")); | |||
| int count = wxRentContractMapper.selectRentContractCountByShopId(wxRentContract); | |||
| wxRentContract.setShopId(record.getShopId()); | |||
| long count = wxRentContractMapper.queryRentContractData(wxRentContract).stream(). | |||
| filter(rc -> rc.get("status").equals(EnumRentContractStatus.SIGNED_RENT_UNPAID.getCode()) | |||
| || rc.get("status").equals(EnumRentContractStatus.RENT_PAID.getCode()) | |||
| || rc.get("status").equals(EnumRentContractStatus.CONTRACT_END_SOON.getCode())).count(); | |||
| if (count > 0) { | |||
| String shopNumber = rentInfoObject.getString("shopNumber"); | |||
| return new ResultData(ErrorCode.SHOP_IS_RENT.getCode(), "店铺 " + shopNumber + " 已出租"); | |||
| return new ResultData(ErrorCode.RENT_CONTRACT_WITH_SHOP_IS_FOUND); | |||
| } | |||
| } | |||
| @@ -382,20 +394,40 @@ public class WxRentContractServiceImpl implements WxRentContractService { | |||
| record.setDeposit(record.getDeposit() == null ? 0 : record.getDeposit()); | |||
| record.setUpdatetime(new Date()); | |||
| try { | |||
| WxRentContract wxRentContractParams = new WxRentContract(); | |||
| wxRentContractParams.setTenantId(record.getTenantId()); | |||
| wxRentContractParams.setShopId(record.getShopId()); | |||
| long count = wxRentContractMapper.queryRentContractData(wxRentContractParams).stream(). | |||
| filter(rc -> !rc.get("status").equals(EnumRentContractStatus.CONTRACT_TERMINATE.getCode()) | |||
| && !rc.get("status").equals(EnumRentContractStatus.WAIT_SIGN.getCode()) | |||
| && !rc.get("status").equals(EnumRentContractStatus.INVALID.getCode()) | |||
| && !rc.get("status").equals(EnumRentContractStatus.CONTRACT_END.getCode()) | |||
| && !rc.get("status").equals(EnumRentContractStatus.INTENTION.getCode()) | |||
| && !rc.get("id").equals(wxRentContract.getId())).count(); | |||
| if (record.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { | |||
| String rentInfo = record.getRentInfo(); | |||
| JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); | |||
| int size = rentInfoArray.size(); | |||
| if (size == 0) { | |||
| return new ResultData(ErrorCode.SHOP_NOT_SELECTED); | |||
| } | |||
| //查询rent_info 包括 shopId | |||
| for (int i = 0; i < size; i++) { | |||
| JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); | |||
| WxRentContract wxRentContractQuery = new WxRentContract(); | |||
| wxRentContractQuery.setTenantId(record.getTenantId()); | |||
| wxRentContractQuery.setShopId(rentInfoObject.getLong("shopId")); | |||
| int count = wxRentContractMapper.selectRentContractCountByShopId(wxRentContract); | |||
| if (count > 0) { | |||
| String shopNumber = rentInfoObject.getString("shopNumber"); | |||
| return new ResultData(ErrorCode.SHOP_IS_RENT.getCode(), "店铺 " + shopNumber + " 已出租"); | |||
| } | |||
| } | |||
| } else { | |||
| WxRentContract wxRentContractQuery = new WxRentContract(); | |||
| wxRentContractQuery.setTenantId(record.getTenantId()); | |||
| wxRentContractQuery.setShopId(record.getShopId()); | |||
| long count = wxRentContractMapper.queryRentContractData(wxRentContract).stream(). | |||
| filter(rc -> rc.get("status").equals(EnumRentContractStatus.SIGNED_RENT_UNPAID.getCode()) | |||
| || rc.get("status").equals(EnumRentContractStatus.RENT_PAID.getCode()) | |||
| || rc.get("status").equals(EnumRentContractStatus.CONTRACT_END_SOON.getCode())).count(); | |||
| if (count > 0) { | |||
| return new ResultData(ErrorCode.RENT_CONTRACT_WITH_SHOP_IS_FOUND); | |||
| } | |||
| } | |||
| try { | |||
| wxRentContractMapper.updateByPrimaryKeySelective(record); | |||
| } catch (Exception e) { | |||
| logger.error("更新租赁合同信息失败,e:" + e.getMessage()); | |||
| @@ -451,15 +483,17 @@ 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")); | |||
| if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { | |||
| 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")); | |||
| } | |||
| wxBillDeposit.setShopInfo(JSONObject.toJSONString(shopInfo)); | |||
| } | |||
| wxBillDeposit.setShopInfo(JSONObject.toJSONString(shopInfo)); | |||
| } | |||
| try { | |||
| wxBillDepositMapper.insertSelective(wxBillDeposit); | |||
| @@ -544,32 +578,50 @@ 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) { | |||
| 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++) { | |||
| int[] priceInt = priceList.get(i); | |||
| int sum = 0; | |||
| for (int p : priceInt) { | |||
| sum += p; | |||
| int size = 0; | |||
| int[] priceArrs = null; | |||
| List<Map<String, Object>> shopInfos = new ArrayList<>(); | |||
| if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { | |||
| String rentInfo = wxRentContract.getRentInfo(); | |||
| JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); | |||
| List<int[]> priceList = computePrice(rentInfo); | |||
| size = priceList.size(); | |||
| priceArrs = new int[size]; | |||
| for (int i = 0; i < size; i++) { | |||
| int[] priceInt = priceList.get(i); | |||
| int sum = 0; | |||
| for (int p : priceInt) { | |||
| sum += p; | |||
| } | |||
| priceArrs[i] = sum; | |||
| } | |||
| 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]); | |||
| 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); | |||
| } | |||
| } else { | |||
| String adjustRatio = wxRentContract.getAdjustRatio(); | |||
| List<Integer> integers = JSONArray.parseArray(adjustRatio, Integer.class); | |||
| integers.add(0, 0); | |||
| size = integers.size(); | |||
| priceArrs = new int[size]; | |||
| priceArrs[0] = price; | |||
| double priceD = price; | |||
| for (int i = 1; i < size; i++) { | |||
| priceD = priceD + priceD * integers.get(i) / 10000.0; | |||
| priceArrs[i] = new BigDecimal(priceD).setScale(0, RoundingMode.HALF_EVEN).intValue(); | |||
| } | |||
| shopInfos.add(shopInfo); | |||
| } | |||
| int month = 12; | |||
| int divide = lease / month; | |||
| int mod = lease % month; | |||
| @@ -588,7 +640,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, shopInfos.get(i)); | |||
| Map<String, Object> resultMap = buildRent(leaseArr[i], receivePeriod, priceArrs[i], instance.getTime(), Calendar.MONTH, wxRentContract, userId, wxMerchant, billcount, isPreview, shopInfos.isEmpty() ? null : shopInfos.get(i)); | |||
| List<WxBillRent> billRentList = (List<WxBillRent>)resultMap.get("billList"); | |||
| billcount = (Integer)resultMap.get("billcount"); | |||
| resultList.addAll(billRentList); | |||