|
|
|
@ -1,77 +1,79 @@ |
|
|
|
|
package com.cjy.reservation.service.impl; |
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.math.RoundingMode; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
import com.cjy.marketingdata.domain.Region; |
|
|
|
|
import com.cjy.marketingdata.service.IRegionService; |
|
|
|
|
import com.cjy.reservation.domain.ReservationSource; |
|
|
|
|
import com.cjy.reservation.domain.vo.ReservationSourceVO; |
|
|
|
|
import com.cjy.reservation.domain.vo.ResultVO; |
|
|
|
|
import com.cjy.reservation.mapper.ReservationSourceMapper; |
|
|
|
|
import com.cjy.reservation.service.IReservationSourceService; |
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult; |
|
|
|
|
import com.ruoyi.common.utils.DateUtils; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import com.cjy.reservation.mapper.ReservationSourceMapper; |
|
|
|
|
import com.cjy.reservation.domain.ReservationSource; |
|
|
|
|
import com.cjy.reservation.service.IReservationSourceService; |
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.math.RoundingMode; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Random; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 分时预约客源 Service业务层处理 |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @author ms |
|
|
|
|
* @date 2023-03-21 |
|
|
|
|
*/ |
|
|
|
|
@Service |
|
|
|
|
public class ReservationSourceServiceImpl implements IReservationSourceService |
|
|
|
|
{ |
|
|
|
|
public class ReservationSourceServiceImpl implements IReservationSourceService { |
|
|
|
|
@Autowired |
|
|
|
|
private ReservationSourceMapper reservationSourceMapper; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private IRegionService regionService; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 查询分时预约客源 |
|
|
|
|
* |
|
|
|
|
* 查询分时预约客源 |
|
|
|
|
* |
|
|
|
|
* @param id 分时预约客源 主键 |
|
|
|
|
* @return 分时预约客源 |
|
|
|
|
* @return 分时预约客源 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public ReservationSource selectReservationSourceById(Long id) |
|
|
|
|
{ |
|
|
|
|
public ReservationSource selectReservationSourceById(Long id) { |
|
|
|
|
return reservationSourceMapper.selectReservationSourceById(id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 查询分时预约客源 列表 |
|
|
|
|
* |
|
|
|
|
* @param reservationSource 分时预约客源 |
|
|
|
|
* @return 分时预约客源 |
|
|
|
|
* |
|
|
|
|
* @param reservationSource 分时预约客源 |
|
|
|
|
* @return 分时预约客源 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public List<ReservationSource> selectReservationSourceList(ReservationSource reservationSource) |
|
|
|
|
{ |
|
|
|
|
public List<ReservationSource> selectReservationSourceList(ReservationSource reservationSource) { |
|
|
|
|
return reservationSourceMapper.selectReservationSourceList(reservationSource); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<ReservationSourceVO> selectReservationSourceVOList(ReservationSource reservationSource) { |
|
|
|
|
return reservationSourceMapper.selectReservationSourceVOList(reservationSource); |
|
|
|
|
return reservationSourceMapper.selectReservationSourceVOList(reservationSource); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 新增分时预约客源 |
|
|
|
|
* |
|
|
|
|
* @param reservationSource 分时预约客源 |
|
|
|
|
* 新增分时预约客源 |
|
|
|
|
* |
|
|
|
|
* @param reservationSource 分时预约客源 |
|
|
|
|
* @return 结果 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public AjaxResult insertReservationSource(ReservationSource reservationSource) |
|
|
|
|
{ |
|
|
|
|
public AjaxResult insertReservationSource(ReservationSource reservationSource) { |
|
|
|
|
ReservationSource selectSource = new ReservationSource(); |
|
|
|
|
selectSource.setProvinceSource(reservationSource.getProvinceSource()); |
|
|
|
|
selectSource.setCitySource(reservationSource.getCitySource()); |
|
|
|
|
selectSource.setResourceCode(reservationSource.getResourceCode()); |
|
|
|
|
List<ReservationSource> list =reservationSourceMapper.selectReservationSourceList(selectSource); |
|
|
|
|
if(!list.isEmpty()){ |
|
|
|
|
return AjaxResult.error("数据已存在,请勿重复添加"); |
|
|
|
|
}else{ |
|
|
|
|
List<ReservationSource> list = reservationSourceMapper.selectReservationSourceList(selectSource); |
|
|
|
|
if (!list.isEmpty()) { |
|
|
|
|
return AjaxResult.error("数据已存在,请勿重复添加"); |
|
|
|
|
} else { |
|
|
|
|
reservationSourceMapper.insertReservationSource(reservationSource); |
|
|
|
|
return AjaxResult.success(); |
|
|
|
|
} |
|
|
|
@ -79,78 +81,101 @@ public class ReservationSourceServiceImpl implements IReservationSourceService |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 修改分时预约客源 |
|
|
|
|
* |
|
|
|
|
* @param reservationSource 分时预约客源 |
|
|
|
|
* 修改分时预约客源 |
|
|
|
|
* |
|
|
|
|
* @param reservationSource 分时预约客源 |
|
|
|
|
* @return 结果 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public int updateReservationSource(ReservationSource reservationSource) |
|
|
|
|
{ |
|
|
|
|
public int updateReservationSource(ReservationSource reservationSource) { |
|
|
|
|
reservationSource.setUpdateTime(DateUtils.getNowDate()); |
|
|
|
|
return reservationSourceMapper.updateReservationSource(reservationSource); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 批量删除分时预约客源 |
|
|
|
|
* |
|
|
|
|
* 批量删除分时预约客源 |
|
|
|
|
* |
|
|
|
|
* @param ids 需要删除的分时预约客源 主键 |
|
|
|
|
* @return 结果 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public int deleteReservationSourceByIds(Long[] ids) |
|
|
|
|
{ |
|
|
|
|
public int deleteReservationSourceByIds(Long[] ids) { |
|
|
|
|
return reservationSourceMapper.deleteReservationSourceByIds(ids); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 删除分时预约客源 信息 |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param id 分时预约客源 主键 |
|
|
|
|
* @return 结果 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public int deleteReservationSourceById(Long id) |
|
|
|
|
{ |
|
|
|
|
public int deleteReservationSourceById(Long id) { |
|
|
|
|
return reservationSourceMapper.deleteReservationSourceById(id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 批量假删除分时预约客源 |
|
|
|
|
* 批量假删除分时预约客源 |
|
|
|
|
* |
|
|
|
|
* @param ids 需要删除的分时预约客源 主键集合 |
|
|
|
|
* @return 结果 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public int updateDelFlagByIds(Long[] ids){ |
|
|
|
|
public int updateDelFlagByIds(Long[] ids) { |
|
|
|
|
return reservationSourceMapper.updateDelFlagByIds(ids); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<ResultVO> selectProvinceTop10(Long organCode) { |
|
|
|
|
List<ResultVO> list = reservationSourceMapper.selectProvinceTop10(organCode); |
|
|
|
|
if (list.size() < 10) { |
|
|
|
|
Random rand = new Random(); |
|
|
|
|
Region regions = new Region(); |
|
|
|
|
regions.setRegionLevel(1); |
|
|
|
|
List<Region> regionList = regionService.selectRegionList(regions); |
|
|
|
|
int total = list.size(); |
|
|
|
|
for (int i = 0; i < (10 - total); i++) { |
|
|
|
|
//获取随机数省份
|
|
|
|
|
Region region = regionList.get(rand.nextInt(regionList.size())); |
|
|
|
|
boolean result = list.stream().filter(m -> m.getName().equals(region.getRegionName())).findAny().isPresent(); |
|
|
|
|
if (!result) { |
|
|
|
|
ResultVO resultVO = new ResultVO(); |
|
|
|
|
resultVO.setPercentage("0.0"); |
|
|
|
|
resultVO.setName(region.getRegionName()); |
|
|
|
|
resultVO.setRatio("0.0"); |
|
|
|
|
resultVO.setNum(0); |
|
|
|
|
list.add(resultVO); |
|
|
|
|
}else{ |
|
|
|
|
total= total -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Integer total = list.stream().mapToInt(ResultVO::getNum).sum(); |
|
|
|
|
list.forEach(x ->{ |
|
|
|
|
Integer num =x.getNum(); |
|
|
|
|
if(total>0){ |
|
|
|
|
BigDecimal ratio = new BigDecimal(num).divide(new BigDecimal(total),2, RoundingMode.DOWN).multiply( new BigDecimal("100")); |
|
|
|
|
list.forEach(x -> { |
|
|
|
|
Integer num = x.getNum(); |
|
|
|
|
if (total > 0) { |
|
|
|
|
BigDecimal ratio = new BigDecimal(num).divide(new BigDecimal(total), 2, RoundingMode.DOWN).multiply(new BigDecimal("100")); |
|
|
|
|
x.setPercentage(ratio.toString()); |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
x.setPercentage("0.0"); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
return list; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<ResultVO> selectCityTop10(Long organCode) { |
|
|
|
|
List<ResultVO> list = reservationSourceMapper.selectCityTop10(organCode); |
|
|
|
|
|
|
|
|
|
Integer total = list.stream().mapToInt(ResultVO::getNum).sum(); |
|
|
|
|
list.forEach(x ->{ |
|
|
|
|
Integer num =x.getNum(); |
|
|
|
|
if(total>0){ |
|
|
|
|
BigDecimal ratio = new BigDecimal(num).multiply(new BigDecimal("100").divide(new BigDecimal(total),2, RoundingMode.DOWN)); |
|
|
|
|
list.forEach(x -> { |
|
|
|
|
Integer num = x.getNum(); |
|
|
|
|
if (total > 0) { |
|
|
|
|
BigDecimal ratio = new BigDecimal(num).multiply(new BigDecimal("100").divide(new BigDecimal(total), 2, RoundingMode.DOWN)); |
|
|
|
|
x.setPercentage(ratio.toString()); |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
x.setPercentage("0.0"); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|