|
|
|
@@ -7,7 +7,9 @@ import com.iformall.domain.po.WxFlowModel; |
|
|
|
import com.iformall.domain.po.WxMerchant; |
|
|
|
import com.iformall.domain.po.WxPropertyContract; |
|
|
|
import com.iformall.domain.po.WxRentContract; |
|
|
|
import com.iformall.domain.po.WxShop; |
|
|
|
import com.iformall.domain.po.base.TenantEntity; |
|
|
|
import com.iformall.domain.vo.ShopValidAreaVo; |
|
|
|
import com.iformall.domain.vo.WxRentPropertyContractVo; |
|
|
|
import com.iformall.enums.EnumContractOperationType; |
|
|
|
import com.iformall.enums.EnumFlowContractType; |
|
|
|
@@ -22,6 +24,7 @@ import com.iformall.service.WxPropertyContractService; |
|
|
|
import com.iformall.service.WxRentContractService; |
|
|
|
import com.iformall.service.WxShopService; |
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
@@ -31,6 +34,7 @@ import java.text.SimpleDateFormat; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Iterator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@@ -148,79 +152,114 @@ public class WxContractBaseController extends BaseController{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void contractValidShop(TenantEntity tenantEntity,Long contractId,Date contractStartDate,Date contractEndDate, |
|
|
|
List<Long> rentShopIdList,Map<Long, BigDecimal> rentAreaMap,Map<Long, String> shopNumberMap,boolean isRent) throws Exception { |
|
|
|
protected Map<Long,ShopValidAreaVo> calcuteShopValidArea(TenantEntity tenantEntity,Long contractId,Date contractStartDate,Date contractEndDate, |
|
|
|
List<Long> shopIdList,Map<Long, BigDecimal> rentAreaMap,boolean isRent) { |
|
|
|
//判断店铺是否还有有效的面积 |
|
|
|
for (int i = 0 ; i < rentShopIdList.size(); i++) { |
|
|
|
Long shopId = rentShopIdList.get(i); |
|
|
|
Map<Long,ShopValidAreaVo> shopValidAreaMap = new HashMap<Long,ShopValidAreaVo>(); |
|
|
|
for (int i = 0 ; i < shopIdList.size(); i++) { |
|
|
|
Long shopId = shopIdList.get(i); |
|
|
|
|
|
|
|
BigDecimal shopRentArea = rentAreaMap.get(shopId); |
|
|
|
String shopNumber = shopNumberMap.get(shopId); |
|
|
|
if (shopRentArea.compareTo(new BigDecimal(0)) <= 0 ) { |
|
|
|
throw new MallinkException(Result.ERROR, "房间["+shopNumber+"]面积不足。"); |
|
|
|
BigDecimal shopArea = new BigDecimal(0); |
|
|
|
WxShop shop = wxShopService.getById(shopId); |
|
|
|
if (StringUtils.isNotBlank(shop.getOperationArea())){ |
|
|
|
shopArea = new BigDecimal(shop.getOperationArea()); |
|
|
|
} |
|
|
|
|
|
|
|
ShopValidAreaVo vo = new ShopValidAreaVo(); |
|
|
|
vo.setShopNumber(shop.getShopNumber()); |
|
|
|
; |
|
|
|
|
|
|
|
List<Long> sidlist = new ArrayList<Long>(); |
|
|
|
sidlist.add(shopId); |
|
|
|
List<Long> contractIds = wxAgileContractService.findShopContractIds(tenantEntity, sidlist); |
|
|
|
//查询是否有跟当前合同时间有冲突的合同 |
|
|
|
if (null != contractIds) { |
|
|
|
if (null != contractId) { |
|
|
|
contractIds.remove(contractId); |
|
|
|
} |
|
|
|
if (contractIds.size() > 0) { |
|
|
|
List<Long> usedContractIds = null; |
|
|
|
List<Integer> statusList = new ArrayList<Integer>(); |
|
|
|
statusList.add(EnumRentContractStatus.DRAFT.getCode()); |
|
|
|
statusList.add(EnumRentContractStatus.PAING.getCode()); |
|
|
|
statusList.add(EnumRentContractStatus.READY_FOR_PAING.getCode()); |
|
|
|
statusList.add(EnumRentContractStatus.PERFORMANCE.getCode()); |
|
|
|
statusList.add(EnumRentContractStatus.UNWRITE.getCode()); |
|
|
|
if (isRent) { |
|
|
|
WxRentContract rc = new WxRentContract(); |
|
|
|
rc.updateTenantInfo(tenantEntity); |
|
|
|
rc.setIds(contractIds); |
|
|
|
rc.setStatuss(statusList); |
|
|
|
/**满足下面条件的都算 |
|
|
|
* 1. 合同开始日期<=当前合同开始日期 && 合同结束日期 > 当前合同开始日期 |
|
|
|
* 2. 合同开始日期 >= 当前合同开始日期 && 合同开始日期 <= 当前结束日期 |
|
|
|
*/ |
|
|
|
rc.setUseStartTime(contractStartDate); |
|
|
|
rc.setUseEndTime(contractEndDate); |
|
|
|
usedContractIds = wxRentContractService.findIdList(rc); |
|
|
|
}else { |
|
|
|
WxPropertyContract rc = new WxPropertyContract(); |
|
|
|
rc.updateTenantInfo(tenantEntity); |
|
|
|
rc.setIds(contractIds); |
|
|
|
rc.setStatuss(statusList); |
|
|
|
rc.setUseStartTime(contractStartDate); |
|
|
|
rc.setUseEndTime(contractEndDate); |
|
|
|
usedContractIds = wxPropertyContractService.findIdList(rc); |
|
|
|
} |
|
|
|
if (null != usedContractIds && usedContractIds.size() > 0 ) { |
|
|
|
BigDecimal usedArea = wxAgileContractService.sumShopContractAreas(tenantEntity, shopId,usedContractIds); |
|
|
|
BigDecimal totalUsedArea = usedArea.add(shopRentArea); |
|
|
|
BigDecimal remianArea = wxShopService.calcuteUsedShopArea(tenantEntity, shopId, totalUsedArea); |
|
|
|
if (remianArea.compareTo(new BigDecimal(0)) < 0 ) { |
|
|
|
throw new MallinkException(Result.ERROR, "房间["+shopNumber+"]面积不足。"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (shopArea.compareTo(new BigDecimal(0)) <= 0 ) { |
|
|
|
vo.setValidArea(new BigDecimal(0)); |
|
|
|
}else { |
|
|
|
BigDecimal contractShopArea = new BigDecimal(0); |
|
|
|
if (null != rentAreaMap) { |
|
|
|
contractShopArea = rentAreaMap.get(shopId); |
|
|
|
if (null == contractShopArea) { |
|
|
|
contractShopArea = new BigDecimal(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
List<Long> sidlist = new ArrayList<Long>(); |
|
|
|
sidlist.add(shopId); |
|
|
|
List<Long> contractIds = wxAgileContractService.findShopContractIds(tenantEntity, sidlist); |
|
|
|
//查询是否有跟当前合同时间有冲突的合同 |
|
|
|
if (null != contractIds) { |
|
|
|
if (null != contractId) { |
|
|
|
contractIds.remove(contractId); |
|
|
|
} |
|
|
|
if (contractIds.size() > 0) { |
|
|
|
List<Long> usedContractIds = null; |
|
|
|
List<Integer> statusList = new ArrayList<Integer>(); |
|
|
|
statusList.add(EnumRentContractStatus.DRAFT.getCode()); |
|
|
|
statusList.add(EnumRentContractStatus.PAING.getCode()); |
|
|
|
statusList.add(EnumRentContractStatus.READY_FOR_PAING.getCode()); |
|
|
|
statusList.add(EnumRentContractStatus.PERFORMANCE.getCode()); |
|
|
|
statusList.add(EnumRentContractStatus.UNWRITE.getCode()); |
|
|
|
if (isRent) { |
|
|
|
WxRentContract rc = new WxRentContract(); |
|
|
|
rc.updateTenantInfo(tenantEntity); |
|
|
|
rc.setIds(contractIds); |
|
|
|
rc.setStatuss(statusList); |
|
|
|
/**满足下面条件的都算 |
|
|
|
* 1. 合同开始日期<=当前合同开始日期 && 合同结束日期 > 当前合同开始日期 |
|
|
|
* 2. 合同开始日期 >= 当前合同开始日期 && 合同开始日期 <= 当前结束日期 |
|
|
|
*/ |
|
|
|
rc.setUseStartTime(contractStartDate); |
|
|
|
rc.setUseEndTime(contractEndDate); |
|
|
|
usedContractIds = wxRentContractService.findIdList(rc); |
|
|
|
}else { |
|
|
|
WxPropertyContract rc = new WxPropertyContract(); |
|
|
|
rc.updateTenantInfo(tenantEntity); |
|
|
|
rc.setIds(contractIds); |
|
|
|
rc.setStatuss(statusList); |
|
|
|
rc.setUseStartTime(contractStartDate); |
|
|
|
rc.setUseEndTime(contractEndDate); |
|
|
|
usedContractIds = wxPropertyContractService.findIdList(rc); |
|
|
|
} |
|
|
|
if (null != usedContractIds && usedContractIds.size() > 0 ) { |
|
|
|
BigDecimal usedArea = wxAgileContractService.sumShopContractAreas(tenantEntity, shopId,usedContractIds); |
|
|
|
BigDecimal totalUsedArea = usedArea.add(contractShopArea); |
|
|
|
BigDecimal remianArea = wxShopService.calcuteUsedShopArea(tenantEntity, shopId, totalUsedArea); |
|
|
|
if (remianArea.compareTo(new BigDecimal(0)) < 0 ) { |
|
|
|
vo.setValidArea(new BigDecimal(0)); |
|
|
|
}else { |
|
|
|
vo.setValidArea(remianArea); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
shopValidAreaMap.put(shopId, vo); |
|
|
|
} |
|
|
|
return shopValidAreaMap; |
|
|
|
} |
|
|
|
|
|
|
|
private void contractValidShop(TenantEntity tenantEntity,Long contractId,Date contractStartDate,Date contractEndDate, |
|
|
|
List<Long> rentShopIdList,Map<Long, BigDecimal> rentAreaMap,boolean isRent) throws Exception { |
|
|
|
//判断店铺是否还有有效的面积 |
|
|
|
Map<Long,ShopValidAreaVo> shopVliadAreaMap = calcuteShopValidArea(tenantEntity, contractId, contractStartDate, contractEndDate, rentShopIdList, rentAreaMap, isRent); |
|
|
|
if (null != shopVliadAreaMap) { |
|
|
|
for (Iterator<Long> it = shopVliadAreaMap.keySet().iterator(); it.hasNext();) { |
|
|
|
Long shopId = it.next(); |
|
|
|
ShopValidAreaVo vo = shopVliadAreaMap.get(shopId); |
|
|
|
if ( null != vo && null != vo.getValidArea()) { |
|
|
|
if (vo.getValidArea().compareTo(new BigDecimal(0)) <= 0 ) { |
|
|
|
throw new MallinkException(Result.ERROR, "房间["+vo.getShopNumber()+"]面积不足。"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected void rentContractValidShop(WxRentContract rentContract) throws Exception { |
|
|
|
contractValidShop(rentContract,rentContract.getId(),rentContract.getRentalStartDate(),rentContract.getRentalEndDate(),rentContract.shopIdsByRentInfo(), |
|
|
|
rentContract.getRentShopArea(),rentContract.getRentInfoShopNumberMap(),true); |
|
|
|
rentContract.getRentShopArea(),true); |
|
|
|
} |
|
|
|
|
|
|
|
protected void propertyContractValidShop(WxPropertyContract propertyContract) throws Exception { |
|
|
|
contractValidShop(propertyContract,propertyContract.getId(),propertyContract.getRentalStartDate(),propertyContract.getRentalEndDate(),propertyContract.shopIdsByShop(), |
|
|
|
propertyContract.getRentShopArea(),propertyContract.getRentInfoShopNumberMap(),false); |
|
|
|
propertyContract.getRentShopArea(),false); |
|
|
|
} |
|
|
|
|
|
|
|
} |