|
|
|
@@ -2555,4 +2555,143 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
public List<WxRentContract> getAllContractByMerchantId(WxRentContract wxRentContract) { |
|
|
|
return wxRentContractMapper.getAllContractBymerchantId(wxRentContract); |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = {Exception.class}) |
|
|
|
@Override |
|
|
|
public ResultData extension(WxRentContract record, Long userId, String userName, Date oldRentStartDate) { |
|
|
|
//保存租赁合同信息 |
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
record.setId(idWorker.nextId()); |
|
|
|
int dayType = record.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode()) ? Calendar.DAY_OF_MONTH : Calendar.MONTH; |
|
|
|
//计租开始时间 |
|
|
|
Calendar instance = Calendar.getInstance(); |
|
|
|
instance.setTime(record.getRentalStartDate()); |
|
|
|
instance.add(dayType, record.getLease()); |
|
|
|
instance.add(Calendar.DAY_OF_MONTH, -1); |
|
|
|
//起租结束时间 |
|
|
|
if (!record.getStartDate().equals(record.getRentalStartDate())) { |
|
|
|
instance.clear(); |
|
|
|
instance.setTime(record.getRentalStartDate()); |
|
|
|
instance.add(Calendar.DAY_OF_MONTH, -1); |
|
|
|
record.setEndDate(instance.getTime()); |
|
|
|
} else { |
|
|
|
record.setEndDate(record.getStartDate()); |
|
|
|
} |
|
|
|
|
|
|
|
if (record.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) { |
|
|
|
if(record.getRevenue() == null || record.getRevenue().longValue() <= 0){ |
|
|
|
record.setPrice(0l); |
|
|
|
}else{ |
|
|
|
if(record.getPayRatio()!=null && record.getPayRatio().intValue() > 0){ |
|
|
|
record.setPrice(countPrice(record.getPayRatio(),record.getRevenue(),EnumMissTimeType.OTHER.getCode(),record.getAdjustPeriod(),EnumGetRatioFrom.RENT.getCode())); |
|
|
|
}else{ |
|
|
|
int dayCount = record.getReceivePeriod() * 30; |
|
|
|
RatioVo ratioVo = getPayRatio(EnumGetRatioFrom.RENT.getCode(),record.getRevenue(),record.getBusDiscountRatio(),record.getBusDiscountTime(),dayCount,record.getReceivePeriod()); |
|
|
|
//record.setPayRatio(ratioVo.getRatio()); |
|
|
|
record.setPrice(ratioVo.getPrice()); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (StringUtils.isNotEmpty(record.getPriceStr())) { |
|
|
|
record.setPrice(new BigDecimal(record.getPriceStr()).multiply(new BigDecimal(100)).longValue()); |
|
|
|
} else { |
|
|
|
record.setPrice(0L); |
|
|
|
} |
|
|
|
} |
|
|
|
if (StringUtils.isNotEmpty(record.getDepositStr())) { |
|
|
|
record.setDeposit(new BigDecimal(record.getDepositStr()).multiply(new BigDecimal(100)).longValue()); |
|
|
|
} else { |
|
|
|
record.setDeposit(0L); |
|
|
|
} |
|
|
|
|
|
|
|
Date date = new Date(); |
|
|
|
record.setCreatetime(date); |
|
|
|
record.setUpdatetime(date); |
|
|
|
|
|
|
|
List<Long> shopList = Lists.newArrayList(); |
|
|
|
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.updateTenantInfo(record); |
|
|
|
Long shopId = rentInfoObject.getLong("shopId"); |
|
|
|
String shopNumber = rentInfoObject.getString("shopNumber"); |
|
|
|
WxShop wxShop = wxShopMapper.selectById(shopId); |
|
|
|
if (wxShop == null) { |
|
|
|
return new ResultData(ErrorCode.SHOP_IS_NOT_FOUND.getCode(), "店铺 " + shopNumber + " 已删除"); |
|
|
|
} |
|
|
|
shopList.add(shopId); |
|
|
|
} |
|
|
|
} else { |
|
|
|
WxRentContract wxRentContract = new WxRentContract(); |
|
|
|
wxRentContract.updateTenantInfo(record); |
|
|
|
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) { |
|
|
|
return new ResultData(ErrorCode.RENT_CONTRACT_WITH_SHOP_IS_FOUND); |
|
|
|
} |
|
|
|
shopList.add(record.getShopId()); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
record.setApplyStatus(EnumRentContractAppStatus.DEFAULT.getCode()); |
|
|
|
|
|
|
|
Date tempDate = record.getRentalStartDate(); |
|
|
|
record.setRentalStartDate(oldRentStartDate); |
|
|
|
wxRentContractMapper.insert(record); |
|
|
|
record.setRentalStartDate(tempDate); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("保存租赁合同信息失败,e:" + e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
//有模板,启动审批流,没有,直接生产账单 |
|
|
|
if (!CollectionUtils.isEmpty(record.getFlowParams())){ |
|
|
|
if (wxFlowService.getModelByType((Integer) record.getFlowParams().get("businessType"), record) == null |
|
|
|
&& record.getMerchantId() != null) { |
|
|
|
updateRentContractStatus(record.getId()); |
|
|
|
}else{ |
|
|
|
record.getFlowParams().put("businessId", record.getId().toString()); |
|
|
|
if (record.getMerchantId() != null) { |
|
|
|
record.getFlowParams().put("supplement", true); //设置补录 |
|
|
|
} |
|
|
|
wxFlowService.start(record.getFlowParams(), userId, userName, record); |
|
|
|
|
|
|
|
// 合同状态改成续签合同状态 |
|
|
|
WxRentContract updateRentContract = new WxRentContract(); |
|
|
|
updateRentContract.setId(record.getId()); |
|
|
|
updateRentContract.setStatus(EnumRentContractStatus.EXTENSION.getCode()); |
|
|
|
wxRentContractMapper.updateStatus(updateRentContract); |
|
|
|
logger.info("id:{},启动审批流成功, 是否补录:{}", record.getId().toString(), record.getMerchantId() != null); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
//审批状态重置 |
|
|
|
WxRentContract updateRentContract = new WxRentContract(); |
|
|
|
updateRentContract.setId(record.getId()); |
|
|
|
updateRentContract.setApplyStatus(EnumRentContractAppStatus.DEFAULT.getCode()); |
|
|
|
updateApplyStatus(updateRentContract); |
|
|
|
} |
|
|
|
|
|
|
|
//生成预览账单(补录第二步,第三步走编辑) |
|
|
|
if (record.getReceivePeriod() != null && record.getLease() != null && record.getPrice() != null |
|
|
|
&& !record.getReceivePeriod().equals(0) && !record.getLease().equals(0) && !record.getPrice().equals(0l)) { |
|
|
|
wxBillRentMapper.deletePreviewBill(record); |
|
|
|
//重新生成 |
|
|
|
List<WxBillRent> resultList = buildRent(new WxMerchant(), null, record, EnumIsPreview.YES.getCode(),true); |
|
|
|
record.setPreviewBillRentList(resultList); |
|
|
|
} |
|
|
|
|
|
|
|
EventUtil.publistRentEvent(this, record); |
|
|
|
return new ResultData(Result.SUCCESS, "保存租赁合同信息成功", record); |
|
|
|
} |
|
|
|
} |