|
|
|
@@ -145,9 +145,6 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
@Autowired
|
|
|
|
WxMallService wxMallService;
|
|
|
|
|
|
|
|
//@Autowired
|
|
|
|
//WxBrandMapper WxBrandMapper;
|
|
|
|
|
|
|
|
@Lazy
|
|
|
|
@Autowired
|
|
|
|
WxFlowRecordService wxFlowRecordService;
|
|
|
|
@@ -196,19 +193,6 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
@Autowired
|
|
|
|
WxEnergyService wxEnergyService;
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
// public Map<String, Object> listAsPage(WxRentContract record, Integer pageIndex, Integer pageSize) {
|
|
|
|
// //Object rentContractStatusInfo = getRentContractStatusInfo(record);
|
|
|
|
// PageHelper.startPage(pageIndex, pageSize);
|
|
|
|
// //List<Map<String, Object>> rentContractData = wxRentContractMapper.queryRentContractData(record);
|
|
|
|
// //PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(rentContractData);
|
|
|
|
// //Map<String, Object> result = new HashMap<>();
|
|
|
|
// //result.put("rentContractStatusInfo", rentContractStatusInfo);
|
|
|
|
// result.put("pageInfo", pageInfo);
|
|
|
|
// this.
|
|
|
|
// return result;
|
|
|
|
// }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<WxRentContract> findList(WxRentContract record){
|
|
|
|
return wxRentContractMapper.findList(record);
|
|
|
|
@@ -367,142 +351,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
public WxRentContract selectById(Long id) {
|
|
|
|
return wxRentContractMapper.selectById(id);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 计算金额
|
|
|
|
* @param ratio
|
|
|
|
* @param revenueLong
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static BigDecimal countPrice(Integer decimalSize,String ratio,String revenueLong,int timeType,int period,int from){
|
|
|
|
if (StringUtils.isBlank(revenueLong)) {
|
|
|
|
revenueLong = "0";
|
|
|
|
}
|
|
|
|
BigDecimal revenue = new BigDecimal(revenueLong);
|
|
|
|
BigDecimal payRatio = null;
|
|
|
|
if (StringUtils.isBlank(ratio)) {
|
|
|
|
payRatio = new BigDecimal(0);
|
|
|
|
}else {
|
|
|
|
payRatio = new BigDecimal(ratio);
|
|
|
|
}
|
|
|
|
BigDecimal price;
|
|
|
|
if(EnumMissTimeType.YEAR.getCode().equals(timeType) && EnumGetRatioFrom.RENT.getCode().equals(from)){
|
|
|
|
price = revenue.multiply(new BigDecimal(12)).multiply(payRatio).setScale(decimalSize, RoundingMode.HALF_EVEN);
|
|
|
|
}else if(EnumMissTimeType.PERIOD.getCode().equals(timeType) && EnumGetRatioFrom.RENT.getCode().equals(from)){
|
|
|
|
price = revenue.multiply(new BigDecimal(period)).multiply(payRatio).setScale(decimalSize, RoundingMode.HALF_EVEN);;
|
|
|
|
}else{
|
|
|
|
price = revenue.multiply(payRatio).setScale(decimalSize, RoundingMode.HALF_EVEN);
|
|
|
|
}
|
|
|
|
return price;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取设置的跳点率
|
|
|
|
* ["1000-1200:10",">3000:20"]
|
|
|
|
*/
|
|
|
|
public static RatioVo getPayRatio(Integer decimalSize,int from,String revenueLong,String busDiscountRatio,int timeType,long dayCount,int period,Integer periodUnit){
|
|
|
|
RatioVo ratioVo = new RatioVo();
|
|
|
|
if(StringUtils.isBlank(busDiscountRatio)){
|
|
|
|
return ratioVo;
|
|
|
|
}
|
|
|
|
List<String> ratioList = JSONArray.parseArray(busDiscountRatio, String.class);
|
|
|
|
ratioVo.setUseRatio(busDiscountRatio);
|
|
|
|
|
|
|
|
for (int i = 0; i < ratioList.size(); i++) {
|
|
|
|
//BigDecimal revenue = new BigDecimal(revenueLong).divide(new BigDecimal(1000000)).setScale(8, RoundingMode.HALF_EVEN);
|
|
|
|
BigDecimal revenue = new BigDecimal(revenueLong);
|
|
|
|
String e = ratioList.get(i);
|
|
|
|
String[] array = e.split(":");
|
|
|
|
//Integer ratio = Integer.parseInt(array[1]);
|
|
|
|
String ratio = array[1];
|
|
|
|
|
|
|
|
if(e.indexOf("-") >= 0){
|
|
|
|
String[] revenueArray = array[0].split("-");
|
|
|
|
BigDecimal start = new BigDecimal(revenueArray[0]);
|
|
|
|
BigDecimal end = new BigDecimal(revenueArray[1]);
|
|
|
|
|
|
|
|
//残年 (小金额 / 365 * 账单周期天数 )--(大金额 / 365 * 账单周期天数)
|
|
|
|
if(EnumMissTimeType.YEAR.getCode().equals(timeType)){
|
|
|
|
if(EnumGetRatioFrom.BILL.getCode().equals(from)) {
|
|
|
|
start = new BigDecimal(revenueArray[0]).divide(new BigDecimal(365), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount));
|
|
|
|
end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(365), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount));
|
|
|
|
}
|
|
|
|
if(EnumGetRatioFrom.RENT.getCode().equals(from)) {
|
|
|
|
revenue = revenue.multiply(new BigDecimal(12));
|
|
|
|
}
|
|
|
|
}else if(EnumMissTimeType.MONTH.getCode().equals(timeType)){
|
|
|
|
if(EnumGetRatioFrom.BILL.getCode().equals(from)) {
|
|
|
|
start = new BigDecimal(revenueArray[0]).divide(new BigDecimal(30), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount));
|
|
|
|
end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(30), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount));
|
|
|
|
}
|
|
|
|
}else if(EnumMissTimeType.PERIOD.getCode().equals(timeType)){
|
|
|
|
if(EnumGetRatioFrom.RENT.getCode().equals(from)) {
|
|
|
|
revenue = revenue.multiply(new BigDecimal(period));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (revenue.compareTo(start) >= 0 && revenue.compareTo(end)<= 0){
|
|
|
|
ratioVo.setRatio(ratio);
|
|
|
|
ratioVo.setPrice(countPrice(decimalSize,ratioVo.getRatio(),revenueLong,timeType,period,from).toPlainString());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}else if(e.indexOf(">") >= 0){
|
|
|
|
String[] revenueArray = array[0].split(">");
|
|
|
|
BigDecimal end = new BigDecimal(revenueArray[1]);
|
|
|
|
|
|
|
|
//残年 (小金额 / 365 * 账单周期天数 )--(大金额 / 365 * 账单周期天数)
|
|
|
|
if(EnumMissTimeType.YEAR.getCode().equals(timeType)){
|
|
|
|
if(EnumGetRatioFrom.BILL.getCode().equals(from)) {
|
|
|
|
end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(365), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount));
|
|
|
|
}
|
|
|
|
if(EnumGetRatioFrom.RENT.getCode().equals(from)) {
|
|
|
|
revenue = revenue.multiply(new BigDecimal(12));
|
|
|
|
}
|
|
|
|
}else if(EnumMissTimeType.MONTH.getCode().equals(timeType)){
|
|
|
|
if(EnumGetRatioFrom.BILL.getCode().equals(from)) {
|
|
|
|
end = new BigDecimal(revenueArray[1]).divide(new BigDecimal(30), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount));
|
|
|
|
}
|
|
|
|
}else if(EnumMissTimeType.PERIOD.getCode().equals(timeType)){
|
|
|
|
if(EnumGetRatioFrom.RENT.getCode().equals(from)) {
|
|
|
|
revenue = revenue.multiply(new BigDecimal(period));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (revenue.compareTo(end) >= 0){
|
|
|
|
ratioVo.setRatio(ratio);
|
|
|
|
|
|
|
|
//计算超出部分
|
|
|
|
BigDecimal payRatio = new BigDecimal(ratio).divide(new BigDecimal(10000));
|
|
|
|
BigDecimal balance = revenue.subtract(end).multiply(new BigDecimal(1000000));
|
|
|
|
BigDecimal price = balance.multiply(payRatio).setScale(decimalSize, RoundingMode.HALF_EVEN);
|
|
|
|
|
|
|
|
array = ratioList.get(i-1).split(":");
|
|
|
|
Integer frontatio = Integer.parseInt(array[1]);
|
|
|
|
revenueArray = array[0].split("-");
|
|
|
|
|
|
|
|
BigDecimal frontEnd;
|
|
|
|
if(EnumGetRatioFrom.BILL.getCode().equals(from)){
|
|
|
|
if(EnumMissTimeType.YEAR.getCode().equals(timeType)){
|
|
|
|
frontEnd = new BigDecimal(revenueArray[1]).divide(new BigDecimal(365), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount));
|
|
|
|
}else if(EnumMissTimeType.MONTH.getCode().equals(timeType)){
|
|
|
|
frontEnd = new BigDecimal(revenueArray[1]).divide(new BigDecimal(30), 10, BigDecimal.ROUND_HALF_DOWN).multiply(new BigDecimal(dayCount));
|
|
|
|
}else{
|
|
|
|
frontEnd = new BigDecimal(revenueArray[1]);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
frontEnd = new BigDecimal(revenueArray[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
BigDecimal frontRatio = new BigDecimal(frontatio).divide(new BigDecimal(10000));
|
|
|
|
BigDecimal frontPrice = frontEnd.multiply(new BigDecimal(1000000).multiply(frontRatio).setScale(decimalSize, RoundingMode.HALF_EVEN));
|
|
|
|
|
|
|
|
ratioVo.setPrice(price.add(frontPrice).toPlainString());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ratioVo;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = {Exception.class})
|
|
|
|
@Override
|
|
|
|
public ResultData save(WxRentContract record,MallUserInfo user,String userName,Date oldRentStartDate) {
|
|
|
|
@@ -525,31 +374,11 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
record.setEndDate(record.getStartDate());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (null != record.getType() && record.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) {
|
|
|
|
if(StringUtils.isBlank(record.getRevenue())){
|
|
|
|
record.setPrice("0");
|
|
|
|
}else{
|
|
|
|
if(StringUtils.isNotBlank(record.getPayRatio())){
|
|
|
|
record.setPrice(countPrice(Constant.default_long_decimal_size,record.getPayRatio(),record.getRevenue(),EnumMissTimeType.OTHER.getCode(),record.getAdjustPeriod(),EnumGetRatioFrom.RENT.getCode()).toPlainString());
|
|
|
|
}else{
|
|
|
|
int dayCount = record.getReceivePeriod() * 30;
|
|
|
|
RatioVo ratioVo = getPayRatio(Constant.default_long_decimal_size,EnumGetRatioFrom.RENT.getCode(),record.getRevenue(),record.getBusDiscountRatio(),
|
|
|
|
0,dayCount,record.getReceivePeriod(),record.getReceivePeriodUnit()); |
|
|
|
//record.setPayRatio(ratioVo.getRatio());
|
|
|
|
record.setPrice(ratioVo.getPrice());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (StringUtils.isNotEmpty(record.getPrice())) {
|
|
|
|
//record.setPrice(new BigDecimal(record.getPriceStr()).multiply(new BigDecimal(100)).longValue());
|
|
|
|
} else {
|
|
|
|
record.setPrice("0");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils.isNotEmpty(record.getDeposit())) {
|
|
|
|
//record.setDeposit(new BigDecimal(record.getDepositStr()).multiply(new BigDecimal(100)).longValue());
|
|
|
|
} else {
|
|
|
|
record.setDeposit("0");
|
|
|
|
if (StringUtils.isEmpty(record.getPrice())) {
|
|
|
|
record.setPrice("0");
|
|
|
|
}
|
|
|
|
if (StringUtils.isEmpty(record.getDeposit())) {
|
|
|
|
record.setDeposit("0");
|
|
|
|
}
|
|
|
|
|
|
|
|
Date date = new Date();
|
|
|
|
@@ -842,7 +671,6 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
if (wxRentContract == null) {
|
|
|
|
return new ResultData(ErrorCode.RENT_CONTRACT_IS_NOT_FOUND);
|
|
|
|
}
|
|
|
|
wxRentContract.setBusDiscountRatio(record.getBusDiscountRatio());
|
|
|
|
wxRentContract.setPayRatio(record.getPayRatio());
|
|
|
|
|
|
|
|
int dayType = wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode()) ? Calendar.DAY_OF_MONTH : Calendar.MONTH;
|
|
|
|
@@ -853,57 +681,56 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
instance.add(Calendar.DAY_OF_MONTH, -1);
|
|
|
|
|
|
|
|
if(!EnumFromType.SWITCH.getCode().equals(from)){
|
|
|
|
if (record.getType() != null && record.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) {
|
|
|
|
if(StringUtils.isNotBlank(record.getPayRatio())){
|
|
|
|
record.setPrice(countPrice(Constant.default_long_decimal_size,record.getPayRatio(),record.getRevenue(),EnumMissTimeType.OTHER.getCode(),record.getAdjustPeriod(),from).toPlainString());
|
|
|
|
}else{
|
|
|
|
int dayCount = record.getReceivePeriod() * 30;
|
|
|
|
RatioVo ratioVo = getPayRatio(Constant.default_long_decimal_size,EnumGetRatioFrom.RENT.getCode(),record.getRevenue(),
|
|
|
|
record.getBusDiscountRatio(),0,dayCount,record.getReceivePeriod(),record.getReceivePeriodUnit());
|
|
|
|
//record.setPayRatio(ratioVo.getRatio());
|
|
|
|
record.setPrice(ratioVo.getPrice());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (StringUtils.isNotEmpty(record.getPrice())) {
|
|
|
|
//record.setPrice(new BigDecimal(record.getPriceStr()).multiply(new BigDecimal(100)).longValue());
|
|
|
|
} else {
|
|
|
|
record.setPrice("0");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//如果是联营扣点,或者联营取高,需要根据保底营业额来计算
|
|
|
|
if (record.getType() != null) {
|
|
|
|
//联营扣点
|
|
|
|
if (record.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) {
|
|
|
|
String revenue = record.getRevenue();
|
|
|
|
if (StringUtils.isBlank(revenue)) {
|
|
|
|
revenue = "0";
|
|
|
|
}
|
|
|
|
record.setPrice(new BigDecimal(record.getPayRatio()).multiply(new BigDecimal(revenue)).setScale(Constant.default_long_decimal_size,RoundingMode.HALF_UP).toPlainString());
|
|
|
|
}else if (record.getType().equals(EnumRentContractType.RENT_BY_AREA_AND_JOINT.getCode())) {
|
|
|
|
//联营取高,如果是固定金额的话,取固定金额. 不固定的金额,会传price.
|
|
|
|
if (null != record.getRevenueFixedRentPrice() && record.getRevenueFixedRentPrice().intValue() == EnumYesOrNo.YES.getCode()){
|
|
|
|
record.setPrice(record.getRevenueRentPrice());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(record.getDeposit())) {
|
|
|
|
//record.setDeposit(new BigDecimal(record.getDepositStr()).multiply(new BigDecimal(100)).longValue());
|
|
|
|
} else {
|
|
|
|
record.setDeposit("0");
|
|
|
|
}
|
|
|
|
if (StringUtils.isEmpty(record.getPrice())) {
|
|
|
|
record.setPrice("0");
|
|
|
|
}
|
|
|
|
if (StringUtils.isEmpty(record.getDeposit())) {
|
|
|
|
record.setDeposit("0");
|
|
|
|
}
|
|
|
|
List<Long> shopList = Lists.newArrayList();
|
|
|
|
record.setUpdatetime(new Date());
|
|
|
|
record.setUpdateBy(user.getId());; |
|
|
|
// 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);
|
|
|
|
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
|
|
|
|
String shopName = "";
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
JSONObject rentInfoObject = rentInfoArray.getJSONObject(i);
|
|
|
|
WxRentContract wxRentContractQuery = new WxRentContract();
|
|
|
|
wxRentContractQuery.updateTenantInfo(record);
|
|
|
|
Long shopId = rentInfoObject.getLong("id");
|
|
|
|
String shopNumber = rentInfoObject.getString("shopNumber");
|
|
|
|
if (shopId == null) {
|
|
|
|
return new ResultData(ErrorCode.SHOP_IS_NOT_FOUND.getCode(), "店铺 " + shopNumber + " 已删除");
|
|
|
|
}
|
|
|
|
//查询rent_info 包括 shopId
|
|
|
|
String shopName = "";
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
JSONObject rentInfoObject = rentInfoArray.getJSONObject(i);
|
|
|
|
WxRentContract wxRentContractQuery = new WxRentContract();
|
|
|
|
wxRentContractQuery.updateTenantInfo(record);
|
|
|
|
Long shopId = rentInfoObject.getLong("id");
|
|
|
|
String shopNumber = rentInfoObject.getString("shopNumber");
|
|
|
|
if (shopId == null) {
|
|
|
|
return new ResultData(ErrorCode.SHOP_IS_NOT_FOUND.getCode(), "店铺 " + shopNumber + " 已删除");
|
|
|
|
}
|
|
|
|
wxRentContractQuery.setId(record.getId());
|
|
|
|
if (!shopList.contains(shopId)) {
|
|
|
|
shopList.add(shopId);
|
|
|
|
shopName = shopName +","+shopNumber;
|
|
|
|
}
|
|
|
|
wxRentContractQuery.setId(record.getId());
|
|
|
|
if (!shopList.contains(shopId)) {
|
|
|
|
shopList.add(shopId);
|
|
|
|
shopName = shopName +","+shopNumber;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
Date tempDate = record.getRentalStartDate();
|
|
|
|
|