|
|
|
@@ -455,6 +455,203 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService |
|
|
|
return new ResultData(Result.SUCCESS, message, record); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = {Exception.class}) |
|
|
|
public ResultData saveOrUpdate2(WxPropertyContract record, Long userId, String userName) { |
|
|
|
// 保存调整金额(预账单调整) |
|
|
|
boolean haspreview = false; |
|
|
|
if(!CollectionUtils.isEmpty(record.getPreviewBillRentList())){ |
|
|
|
savePreviewBill(record); |
|
|
|
haspreview = true; |
|
|
|
} |
|
|
|
|
|
|
|
if (record.getRentShopType().equals(EnumRentShopType.POINT.getCode()) && null == record.getShopId()) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "shopId不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
WxRentContract wxRentContract = wxRentContractMapper.selectById(record.getRentContractId()); |
|
|
|
if (wxRentContract != null) { |
|
|
|
if (wxRentContract.getStatus().equals(EnumRentContractStatus.CONTRACT_END.getCode()) || |
|
|
|
wxRentContract.getStatus().equals(EnumRentContractStatus.CONTRACT_TERMINATE.getCode()) || |
|
|
|
wxRentContract.getStatus().equals(EnumRentContractStatus.INVALID.getCode())) { |
|
|
|
return new ResultData(ErrorCode.RENT_CONTRACT_IS_TERMINATED); |
|
|
|
} |
|
|
|
} else { |
|
|
|
return new ResultData(ErrorCode.RENT_CONTRACT_IS_NOT_FOUND); |
|
|
|
} |
|
|
|
if (null == record.getMerchantId() && record.getOperationType().equals(EnumContractOperationType.PART.getCode())) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "merchantId不能为空"); |
|
|
|
} |
|
|
|
if (record.getOperationType().equals(EnumContractOperationType.PART.getCode())) { |
|
|
|
WxMerchant merchant = wxMerchantMapper.selectById(record.getMerchantId()); |
|
|
|
if (merchant == null) { |
|
|
|
return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND); |
|
|
|
} |
|
|
|
} |
|
|
|
if (null == record.getReceivePeriod()) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "付款周期不能为空"); |
|
|
|
} |
|
|
|
if (null == record.getLease()) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "租期不能为空"); |
|
|
|
} |
|
|
|
if (null == record.getPrice()) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "物业费不能为空"); |
|
|
|
} |
|
|
|
if (null == record.getDeposit()) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "押金不能为空"); |
|
|
|
} |
|
|
|
if (record.getPrice().longValue() <= 0) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "物业费要大于0"); |
|
|
|
} |
|
|
|
|
|
|
|
WxPropertyContract propertyContract = new WxPropertyContract(); |
|
|
|
propertyContract.updateTenantInfo(wxRentContract); |
|
|
|
propertyContract.setRentContractId(record.getRentContractId()); |
|
|
|
long count = wxPropertyContractMapper.findList(propertyContract) |
|
|
|
.stream().filter(p -> p.getStatus().equals(EnumRentContractStatus.SIGNED_RENT_UNPAID.getCode()) || |
|
|
|
p.getStatus().equals(EnumRentContractStatus.RENT_PAID.getCode()) || |
|
|
|
p.getStatus().equals(EnumRentContractStatus.CONTRACT_END_SOON.getCode())).count(); |
|
|
|
if (count > 1) { |
|
|
|
return new ResultData(ErrorCode.RENT_CONTRACT_WITH_SHOP_IS_FOUND); |
|
|
|
} |
|
|
|
//保存物业合同信息 |
|
|
|
String message; |
|
|
|
boolean hasFlow = true; |
|
|
|
if (record.getId() == null) { |
|
|
|
if (record.getOperationType().equals(EnumContractOperationType.WHOLE.getCode())) { |
|
|
|
WxPropertyContract propertyContractQuery = new WxPropertyContract(); |
|
|
|
propertyContractQuery.setRentContractId(record.getRentContractId()); |
|
|
|
int propertyContractCount = wxPropertyContractMapper.selectCount(new QueryWrapper(propertyContractQuery)); |
|
|
|
if (propertyContractCount > 0) { |
|
|
|
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|
hasFlow = false; |
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
record.setId(idWorker.nextId()); |
|
|
|
record.setRentalStartDate(wxRentContract.getRentalStartDate()); |
|
|
|
record.setRentalEndDate(wxRentContract.getRentalEndDate()); |
|
|
|
record.setStartDate(wxRentContract.getStartDate()); |
|
|
|
record.setEndDate(wxRentContract.getEndDate()); |
|
|
|
Date date = new Date(); |
|
|
|
record.setCreatetime(date); |
|
|
|
record.setUpdatetime(date); |
|
|
|
record.setStatus(EnumRentContractStatus.EXTENSION.getCode()); |
|
|
|
record.setApplyStatus(EnumRentContractAppStatus.DEFAULT.getCode()); |
|
|
|
try { |
|
|
|
wxPropertyContractMapper.insert(record); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("保存物业合同信息失败,e:" + e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
//生成预览账单 |
|
|
|
wxBillPropertyMapper.deletePreviewBill(record); |
|
|
|
//重新生成 |
|
|
|
List<WxBillProperty> billList = buildProperty(new WxMerchant(),userId,record,EnumIsPreview.YES.getCode(),true); |
|
|
|
record.setPreviewBillRentList(billList); |
|
|
|
|
|
|
|
message = "保存物业合同信息成功"; |
|
|
|
} else {//更新物业合同信息 |
|
|
|
//查询预账单用于展示 |
|
|
|
WxBillProperty wxBillRent = new WxBillProperty(); |
|
|
|
wxBillRent.setPropertyContractId(record.getId()); |
|
|
|
wxBillRent.setSortColumns(BaseEntity.SortField.Period_ASC); |
|
|
|
wxBillRent.setIsPreview(EnumIsPreview.YES.getCode()); |
|
|
|
List<WxBillProperty> billList = wxBillPropertyMapper.findList(wxBillRent); |
|
|
|
record.setPreviewBillRentList(billList); |
|
|
|
|
|
|
|
if(!haspreview){ |
|
|
|
if (record.getReceivePeriod() != null && record.getLease() != null && record.getPrice() != null |
|
|
|
&& !record.getReceivePeriod().equals(0) && !record.getLease().equals(0) && !record.getPrice().equals(0l)) { |
|
|
|
//删除预账单,重新生成 |
|
|
|
wxBillPropertyMapper.deletePreviewBill(record); |
|
|
|
//重新生成 |
|
|
|
billList = buildProperty(new WxMerchant(),userId,record,EnumIsPreview.YES.getCode(),true); |
|
|
|
record.setPreviewBillRentList(billList); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
WxPropertyContract wxPropertyContract = wxPropertyContractMapper.selectById(record.getId()); |
|
|
|
if (wxPropertyContract == null) { |
|
|
|
return new ResultData(ErrorCode.PROPERTY_CONTRACT_IS_NOT_FOUND); |
|
|
|
} |
|
|
|
|
|
|
|
record.setRentalStartDate(wxRentContract.getRentalStartDate()); |
|
|
|
record.setRentalEndDate(wxRentContract.getRentalEndDate()); |
|
|
|
record.setStartDate(wxRentContract.getStartDate()); |
|
|
|
record.setEndDate(wxRentContract.getEndDate()); |
|
|
|
record.setPrice(record.getPrice() != null ? record.getPrice() : 0); |
|
|
|
record.setDeposit(record.getDeposit() != null ? record.getDeposit() : 0); |
|
|
|
record.setUpdatetime(new Date()); |
|
|
|
|
|
|
|
//如果是合并合同 物业合同的状态为 意向 |
|
|
|
if (record.getOperationType().equals(EnumContractOperationType.WHOLE.getCode())) { |
|
|
|
record.setStatus(EnumRentContractStatus.EXTENSION.getCode()); |
|
|
|
} |
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(record.getFlowParams())) { |
|
|
|
hasFlow = false; |
|
|
|
record.setApplyStatus(EnumRentContractAppStatus.DEFAULT.getCode()); |
|
|
|
} |
|
|
|
try { |
|
|
|
wxPropertyContractMapper.updateById(record); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("更新物业合同信息失败,e:" + e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
message = "更新物业合同信息成功"; |
|
|
|
} |
|
|
|
|
|
|
|
if (hasFlow) { |
|
|
|
if (record.getOperationType().equals(EnumContractOperationType.PART.getCode())) { |
|
|
|
if (wxFlowService.getModelByType((Integer) record.getFlowParams().get("businessType"), record) == null) { |
|
|
|
updatePropertyContractStatus(record.getId()); |
|
|
|
} else { |
|
|
|
record.getFlowParams().put("businessId", record.getId().toString()); |
|
|
|
wxFlowService.start(record.getFlowParams(), userId, userName, record); |
|
|
|
|
|
|
|
// 合同状态改成待签约 |
|
|
|
WxPropertyContract updateRentContract = new WxPropertyContract(); |
|
|
|
updateRentContract.setId(record.getId()); |
|
|
|
updateRentContract.setStatus(EnumRentContractStatus.EXTENSION.getCode()); |
|
|
|
wxPropertyContractMapper.updateStatus(updateRentContract); |
|
|
|
logger.info("id:{},启动审批流成功", record.getId().toString()); |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (wxFlowService.getModelByType((Integer) record.getFlowParams().get("businessType"), record) == null |
|
|
|
&& record.getMerchantId() != null) { |
|
|
|
wxRentContractService.updateRentContractStatus(record.getId()); |
|
|
|
} else { |
|
|
|
record.getFlowParams().put("businessId", record.getRentContractId().toString()); |
|
|
|
if (record.getMerchantId() != null) { |
|
|
|
record.getFlowParams().put("supplement", true); //设置补录 |
|
|
|
} |
|
|
|
wxFlowService.start(record.getFlowParams(), userId, userName, record); |
|
|
|
|
|
|
|
// 合同状态改成待签约 |
|
|
|
WxRentContract updateRentContract = new WxRentContract(); |
|
|
|
updateRentContract.setId(record.getRentContractId()); |
|
|
|
updateRentContract.setStatus(EnumRentContractStatus.EXTENSION.getCode()); |
|
|
|
if(wxRentContract.getStatus().equals(EnumRentContractStatus.SUPPLE.getCode())){ |
|
|
|
updateRentContract.setStatus(EnumRentContractStatus.EXTENSION.getCode()); |
|
|
|
} |
|
|
|
wxRentContractMapper.updateStatus(updateRentContract); |
|
|
|
logger.info("id:{},启动审批流成功,是否补录:{}", record.getRentContractId().toString(), record.getMerchantId() != null); |
|
|
|
} |
|
|
|
} |
|
|
|
}else{ |
|
|
|
//审批状态重置 |
|
|
|
WxPropertyContract updateRentContract = new WxPropertyContract(); |
|
|
|
updateRentContract.setId(record.getId()); |
|
|
|
updateRentContract.setApplyStatus(EnumRentContractAppStatus.DEFAULT.getCode()); |
|
|
|
wxPropertyContractMapper.updateById(updateRentContract); |
|
|
|
} |
|
|
|
|
|
|
|
return new ResultData(Result.SUCCESS, message, record); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultData updatePropertyContractStatus(Long id) { |
|
|
|
if (id == null) { |
|
|
|
|