|
|
|
@@ -2694,4 +2694,156 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
EventUtil.publistRentEvent(this, record); |
|
|
|
return new ResultData(Result.SUCCESS, "保存租赁合同信息成功", record); |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = {Exception.class}) |
|
|
|
@Override |
|
|
|
public ResultData extensionUpdate(WxRentContract record, Long userId, String userName, int from, Date oldRentStartDate) { |
|
|
|
//查询预账单用于展示 |
|
|
|
WxBillRent wxBillRent = new WxBillRent(); |
|
|
|
wxBillRent.setRentContractId(record.getId()); |
|
|
|
wxBillRent.setSortColumns(BaseEntity.SortField.Period_ASC); |
|
|
|
wxBillRent.setIsPreview(EnumIsPreview.YES.getCode()); |
|
|
|
List<WxBillRent> resultList = wxBillRentMapper.findList(wxBillRent); |
|
|
|
|
|
|
|
//更新 |
|
|
|
ResultData resultData = getResultDataForExtensionUpdate(record, userId,from,oldRentStartDate); |
|
|
|
if (resultData.code != Result.SUCCESS) { |
|
|
|
return resultData; |
|
|
|
} |
|
|
|
|
|
|
|
if(CollectionUtils.isEmpty(record.getPreviewBillRentList())) { |
|
|
|
if (record.getReceivePeriod() != null && record.getLease() != null |
|
|
|
&& !record.getReceivePeriod().equals(0) && !record.getLease().equals(0)) { |
|
|
|
//删除预账单,重新生成 |
|
|
|
wxBillRentMapper.deletePreviewBill(record); |
|
|
|
resultList = buildRent(new WxMerchant(), null, record, EnumIsPreview.YES.getCode(),true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//有模板,启动审批流,没有,直接生产账单 |
|
|
|
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.SUPPLE.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); |
|
|
|
} |
|
|
|
|
|
|
|
//保存调整金额(预账单调整) |
|
|
|
savePreviewBill(record); |
|
|
|
|
|
|
|
WxRentContract wxRentContract = (WxRentContract)resultData.data; |
|
|
|
wxRentContract.setPreviewBillRentList(resultList); |
|
|
|
return new ResultData(wxRentContract); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultData getResultDataForExtensionUpdate(WxRentContract record, Long userId,int from,Date oldRentStartDate) { |
|
|
|
//更新租赁合同信息 |
|
|
|
WxRentContract wxRentContract = wxRentContractMapper.selectById(record.getId()); |
|
|
|
if (wxRentContract == null) { |
|
|
|
return new ResultData(ErrorCode.RENT_CONTRACT_IS_NOT_FOUND); |
|
|
|
} |
|
|
|
wxRentContract.setBusDiscountTime(record.getBusDiscountTime()); |
|
|
|
wxRentContract.setBusDiscountRatio(record.getBusDiscountRatio()); |
|
|
|
wxRentContract.setPayRatio(record.getPayRatio()); |
|
|
|
|
|
|
|
int dayType = wxRentContract.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(!EnumFromType.SWITCH.getCode().equals(from)){ |
|
|
|
if (record.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) { |
|
|
|
if(record.getPayRatio()!=null && record.getPayRatio().intValue() > 0){ |
|
|
|
record.setPrice(countPrice(record.getPayRatio(),record.getRevenue(),EnumMissTimeType.OTHER.getCode(),record.getAdjustPeriod(),from)); |
|
|
|
}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); |
|
|
|
} |
|
|
|
|
|
|
|
record.setUpdatetime(new Date()); |
|
|
|
|
|
|
|
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.updateTenantInfo(record); |
|
|
|
Long shopId = rentInfoObject.getLong("shopId"); |
|
|
|
String shopNumber = rentInfoObject.getString("shopNumber"); |
|
|
|
if (shopId == null) { |
|
|
|
return new ResultData(ErrorCode.SHOP_IS_NOT_FOUND.getCode(), "店铺 " + shopNumber + " 已删除"); |
|
|
|
} |
|
|
|
WxShop wxShop = wxShopMapper.selectById(shopId); |
|
|
|
if (wxShop == null) { |
|
|
|
return new ResultData(ErrorCode.SHOP_IS_NOT_FOUND.getCode(), "店铺 " + shopNumber + " 已删除"); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
WxRentContract wxRentContractQuery = new WxRentContract(); |
|
|
|
wxRentContractQuery.updateTenantInfo(record); |
|
|
|
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 { |
|
|
|
Date tempDate = record.getRentalStartDate(); |
|
|
|
record.setRentalStartDate(oldRentStartDate); |
|
|
|
wxRentContractMapper.updateById(record); |
|
|
|
record.setRentalStartDate(tempDate); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("更新租赁合同信息失败,e:" + e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); |
|
|
|
} |
|
|
|
return new ResultData(Result.SUCCESS, "保存租赁合同信息成功", wxRentContract); |
|
|
|
} |
|
|
|
} |