| | |
| | | package com.ruoyi.service.impl; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.utils.MapUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.common.utils.uuid.IdUtils; |
| | | import com.ruoyi.domain.ZTravelBase; |
| | | import com.ruoyi.domain.ZTravelPrice; |
| | | import com.ruoyi.domain.ZTravelPrice; |
| | | import com.ruoyi.domain.ZTravelPriceDetail; |
| | | import com.ruoyi.domain.dto.PriceDto; |
| | | import com.ruoyi.mapper.ZTravelPriceMapper; |
| | | import com.ruoyi.service.ZTravelBaseService; |
| | | import com.ruoyi.service.ZTravelPriceDetailService; |
| | | import com.ruoyi.service.ZTravelPriceService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | | * 服务实现类 |
| | | * 服务实现类 |
| | | * </p> |
| | | * |
| | | * @author ojq |
| | |
| | | @Service |
| | | public class ZTravelPriceServiceImpl extends ServiceImpl<ZTravelPriceMapper, ZTravelPrice> implements ZTravelPriceService { |
| | | |
| | | @Autowired |
| | | ZTravelPriceServiceImpl zTravelPriceService; |
| | | |
| | | @Autowired |
| | | ZTravelPriceDetailService zTravelPriceDetailService; |
| | | |
| | | @Autowired |
| | | ZTravelBaseService zTravelBaseService; |
| | | |
| | | // private LambdaQueryWrapper<ZTravelPrice> uniqueCondition(ZTravelPrice zTravelPrice){ |
| | | // LambdaQueryWrapper<ZTravelPrice> lqw = new LambdaQueryWrapper<>(); |
| | | // lqw.eq(zTravelPrice.getMyId()!=null,ZTravelPrice::getMyId,zTravelPrice.getMyId()) |
| | | // .eq(zTravelPrice.getStartTime()!=null,ZTravelPrice::getStartTime,zTravelPrice.getStartTime()) |
| | | // .eq(zTravelPrice.getEndTime()!=null,ZTravelPrice::getEndTime,zTravelPrice.getEndTime()) |
| | | // .eq(zTravelPrice.getTotalDay()!=null,ZTravelPrice::getTotalDay,zTravelPrice.getTotalDay()) |
| | | // .eq(StringUtils.isNotEmpty(zTravelPrice.getTitle()),ZTravelPrice::getTitle,zTravelPrice.getTitle()); |
| | | //// .eq(zTravelPrice.getEat()!=null,ZTravelPrice::getEat,zTravelPrice.getEat()) |
| | | //// .eq(zTravelPrice.getStay()!=null,ZTravelPrice::getStay,zTravelPrice.getStay()) |
| | | //// .eq(zTravelPrice.getTraffic()!=null,ZTravelPrice::getTraffic,zTravelPrice.getTraffic()) |
| | | //// .eq(zTravelPrice.getShopping()!=null,ZTravelPrice::getShopping,zTravelPrice.getShopping()); |
| | | // return lqw; |
| | | // } |
| | | |
| | | private LambdaQueryWrapper<ZTravelPrice> buildCondition(ZTravelPrice zTravelPrice, Long userId) { |
| | | LambdaQueryWrapper<ZTravelPrice> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.eq(ZTravelPrice::getMyId, userId) |
| | | .eq(zTravelPrice.getTotalDay() != null, ZTravelPrice::getTotalDay, zTravelPrice.getTotalDay()) |
| | | .le(zTravelPrice.getEnd() != null, ZTravelPrice::getEndTime, zTravelPrice.getEnd()) |
| | | .ge(zTravelPrice.getStart() != null, ZTravelPrice::getStartTime, zTravelPrice.getStart()); |
| | | |
| | | lqw.orderBy(true, true, ZTravelPrice::getStartTime); |
| | | return lqw; |
| | | } |
| | | |
| | | /** |
| | | * 分页查找 |
| | | */ |
| | | @Override |
| | | public AjaxResult selectDataList(ZTravelPrice zTravelPrice, Integer pageNum, Integer pageSize) { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | LambdaQueryWrapper<ZTravelPrice> lqw = buildCondition(zTravelPrice, userId); |
| | | |
| | | Page<ZTravelPrice> pageBean = new Page<>(pageNum, pageSize); |
| | | Page<ZTravelPrice> pageResult = page(pageBean, lqw); |
| | | |
| | | List<ZTravelPrice> priceList = pageResult.getRecords();//得到查询出来的数据 |
| | | |
| | | //查询费用详情 |
| | | for (ZTravelPrice price : priceList) { |
| | | LambdaQueryWrapper<ZTravelPriceDetail> detailLqw = new LambdaQueryWrapper<>(); |
| | | detailLqw.eq(ZTravelPriceDetail::getFeeId,price.getId()); |
| | | List<ZTravelPriceDetail> detailList = zTravelPriceDetailService.list(detailLqw); |
| | | price.setDetailList(detailList); |
| | | } |
| | | |
| | | HashMap<String, Object> data = MapUtils.getResult(pageResult, priceList); |
| | | return AjaxResult.success(data); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public List<ZTravelPrice> selectCondition(ZTravelPrice zTravelPrice) { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | LambdaQueryWrapper<ZTravelPrice> lqw = buildCondition(zTravelPrice, userId); |
| | | return list(lqw); |
| | | } |
| | | |
| | | @Override |
| | | public List<ZTravelPrice> selectByIds(Long[] ids) { |
| | | List<ZTravelPrice> list = new ArrayList<>(); |
| | | if (ids.length != 0) |
| | | list = listByIds(Arrays.asList(ids)); |
| | | else |
| | | list = list(); |
| | | return list; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public AjaxResult mySave(PriceDto priceDto) { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | |
| | | List<ZTravelPriceDetail> detailList = priceDto.getDetailList(); |
| | | |
| | | //生成费用表id |
| | | String priceId = IdUtils.fastSimpleUUID(); |
| | | |
| | | //得到总天数 |
| | | long count = detailList.stream().map(ZTravelPriceDetail::getHappenTime).distinct().count(); |
| | | Integer totalDay = Math.toIntExact(count); |
| | | |
| | | |
| | | //先插入明细表 |
| | | |
| | | //collectList还没有添加每日金额字段 |
| | | List<ZTravelPriceDetail> collectList = detailList.stream().peek((priceDetail) -> |
| | | { |
| | | priceDetail.setFeeId(priceId); |
| | | if (priceDetail.getEat() == null || priceDetail.getStay() == null || priceDetail.getTraffic() == null || priceDetail.getEntrance() == null || priceDetail.getShopping() == null) { |
| | | throw new RuntimeException("如果没有对应的费用,前端要传个0过来"); |
| | | } |
| | | Double totalCost = priceDetail.getEat() + priceDetail.getStay() + priceDetail.getTraffic() + priceDetail.getEntrance() + priceDetail.getShopping(); |
| | | priceDetail.setTotalCost(totalCost); |
| | | }).collect(Collectors.toList()); |
| | | |
| | | |
| | | //按日期分组 |
| | | Map<String, List<ZTravelPriceDetail>> groupByTimeMap = collectList.stream().collect(Collectors.groupingBy(ZTravelPriceDetail::getHappenTime)); |
| | | |
| | | //将每日金额字段的值也添加上 |
| | | for (String key : groupByTimeMap.keySet()) { |
| | | List<ZTravelPriceDetail> groupByTimeList = groupByTimeMap.get(key); |
| | | Double dayTotalCost = 0d; |
| | | for (ZTravelPriceDetail detail : groupByTimeList) { |
| | | dayTotalCost += detail.getTotalCost(); |
| | | } |
| | | |
| | | for (ZTravelPriceDetail detail : groupByTimeList){ |
| | | detail.setDayCost(dayTotalCost); |
| | | } |
| | | } |
| | | |
| | | //开始插入费用详情数据 |
| | | for (String key : groupByTimeMap.keySet()) { |
| | | List<ZTravelPriceDetail> dataList = groupByTimeMap.get(key); |
| | | for (ZTravelPriceDetail detail : dataList) { |
| | | zTravelPriceDetailService.save(detail); |
| | | } |
| | | } |
| | | |
| | | |
| | | //再插入费用记录统计表 |
| | | |
| | | //先得到各个详情费用的总和 |
| | | Double eatTotal = 0d; |
| | | Double stayTotal = 0d; |
| | | Double trafficTotal = 0d; |
| | | Double entranceTotal = 0d; |
| | | Double shoppingTotal = 0d; |
| | | Double totalFee = 0d; |
| | | |
| | | for (String key : groupByTimeMap.keySet()) { |
| | | List<ZTravelPriceDetail> dataList = groupByTimeMap.get(key); |
| | | for (ZTravelPriceDetail priceDetail : dataList) { |
| | | if (priceDetail.getEat() == null || priceDetail.getStay() == null || priceDetail.getTraffic() == null || priceDetail.getEntrance() == null || priceDetail.getShopping() == null) { |
| | | throw new RuntimeException("如果没有对应的费用,前端要传个0过来"); |
| | | } |
| | | eatTotal+=priceDetail.getEat(); |
| | | stayTotal+=priceDetail.getStay(); |
| | | trafficTotal+=priceDetail.getTraffic(); |
| | | entranceTotal+=priceDetail.getEntrance(); |
| | | shoppingTotal+=priceDetail.getShopping(); |
| | | totalFee+=priceDetail.getTotalCost(); |
| | | } |
| | | } |
| | | |
| | | ZTravelPrice zTravelPrice = new ZTravelPrice(); |
| | | zTravelPrice.setId(priceId); |
| | | zTravelPrice.setStartTime(priceDto.getStartTime()); |
| | | zTravelPrice.setEndTime(priceDto.getEndTime()); |
| | | zTravelPrice.setTotalDay(totalDay); |
| | | zTravelPrice.setTitle(priceDto.getTitle()); |
| | | zTravelPrice.setEat(eatTotal); |
| | | zTravelPrice.setStay(stayTotal); |
| | | zTravelPrice.setTraffic(trafficTotal); |
| | | zTravelPrice.setEntrance(entranceTotal); |
| | | zTravelPrice.setShopping(shoppingTotal); |
| | | zTravelPrice.setTotalCost(totalFee); |
| | | zTravelPrice.setMyId(userId); |
| | | |
| | | //插入费用记录统计 |
| | | zTravelPriceService.save(zTravelPrice); |
| | | |
| | | return AjaxResult.success(); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult myUpdate(PriceDto priceDto) { |
| | | |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | |
| | | List<ZTravelPriceDetail> detailList = priceDto.getDetailList(); |
| | | |
| | | //得到总天数 |
| | | long count = detailList.stream().map(ZTravelPriceDetail::getHappenTime).distinct().count(); |
| | | Integer totalDay = Math.toIntExact(count); |
| | | |
| | | List<ZTravelPriceDetail> collectList = detailList.stream().peek((priceDetail) -> |
| | | { |
| | | if (priceDetail.getEat() == null || priceDetail.getStay() == null || priceDetail.getTraffic() == null || priceDetail.getEntrance() == null || priceDetail.getShopping() == null) { |
| | | throw new RuntimeException("如果没有对应的费用,前端要传个0过来"); |
| | | } |
| | | Double totalCost = priceDetail.getEat() + priceDetail.getStay() + priceDetail.getTraffic() + priceDetail.getEntrance() + priceDetail.getShopping(); |
| | | priceDetail.setTotalCost(totalCost); |
| | | }).collect(Collectors.toList()); |
| | | |
| | | //按日期分组 |
| | | Map<String, List<ZTravelPriceDetail>> groupByTimeMap = collectList.stream().collect(Collectors.groupingBy(ZTravelPriceDetail::getHappenTime)); |
| | | |
| | | //将每日金额字段的值也添加上 |
| | | for (String key : groupByTimeMap.keySet()) { |
| | | List<ZTravelPriceDetail> groupByTimeList = groupByTimeMap.get(key); |
| | | Double dayTotalCost = 0d; |
| | | for (ZTravelPriceDetail detail : groupByTimeList) { |
| | | dayTotalCost += detail.getTotalCost(); |
| | | } |
| | | |
| | | for (ZTravelPriceDetail detail : groupByTimeList){ |
| | | detail.setDayCost(dayTotalCost); |
| | | } |
| | | } |
| | | |
| | | //开始修改费用详情数据 |
| | | for (String key : groupByTimeMap.keySet()) { |
| | | List<ZTravelPriceDetail> dataList = groupByTimeMap.get(key); |
| | | for (ZTravelPriceDetail detail : dataList) { |
| | | zTravelPriceDetailService.updateById(detail); |
| | | } |
| | | } |
| | | |
| | | //再修改费用记录统计表 |
| | | |
| | | //先得到各个详情费用的总和 |
| | | Double eatTotal = 0d; |
| | | Double stayTotal = 0d; |
| | | Double trafficTotal = 0d; |
| | | Double entranceTotal = 0d; |
| | | Double shoppingTotal = 0d; |
| | | Double totalFee = 0d; |
| | | |
| | | for (String key : groupByTimeMap.keySet()) { |
| | | List<ZTravelPriceDetail> dataList = groupByTimeMap.get(key); |
| | | for (ZTravelPriceDetail priceDetail : dataList) { |
| | | if (priceDetail.getEat() == null || priceDetail.getStay() == null || priceDetail.getTraffic() == null || priceDetail.getEntrance() == null || priceDetail.getShopping() == null) { |
| | | throw new RuntimeException("如果没有对应的费用,前端要传个0过来"); |
| | | } |
| | | eatTotal+=priceDetail.getEat(); |
| | | stayTotal+=priceDetail.getStay(); |
| | | trafficTotal+=priceDetail.getTraffic(); |
| | | entranceTotal+=priceDetail.getEntrance(); |
| | | shoppingTotal+=priceDetail.getShopping(); |
| | | totalFee+=priceDetail.getTotalCost(); |
| | | } |
| | | } |
| | | |
| | | ZTravelPrice zTravelPrice = new ZTravelPrice(); |
| | | zTravelPrice.setId(priceDto.getId()); |
| | | zTravelPrice.setStartTime(priceDto.getStartTime()); |
| | | zTravelPrice.setEndTime(priceDto.getEndTime()); |
| | | zTravelPrice.setTotalDay(totalDay); |
| | | zTravelPrice.setTitle(priceDto.getTitle()); |
| | | zTravelPrice.setEat(eatTotal); |
| | | zTravelPrice.setStay(stayTotal); |
| | | zTravelPrice.setTraffic(trafficTotal); |
| | | zTravelPrice.setEntrance(entranceTotal); |
| | | zTravelPrice.setShopping(shoppingTotal); |
| | | zTravelPrice.setTotalCost(totalFee); |
| | | zTravelPrice.setMyId(userId); |
| | | |
| | | //修改统计表 |
| | | zTravelPriceService.updateById(zTravelPrice); |
| | | |
| | | return AjaxResult.success(); |
| | | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public AjaxResult myRemove(String[] ids) { |
| | | |
| | | for (String feeId : ids) { |
| | | //删除旅游经历 |
| | | zTravelBaseService.remove(new LambdaQueryWrapper<ZTravelBase>().eq(ZTravelBase::getFeeId,feeId)); |
| | | |
| | | //删除费用详情 |
| | | zTravelPriceDetailService.remove(new LambdaQueryWrapper<ZTravelPriceDetail>().eq(ZTravelPriceDetail::getFeeId,feeId)); |
| | | |
| | | //删除费用记录 |
| | | zTravelPriceService.remove(new LambdaQueryWrapper<ZTravelPrice>().eq(ZTravelPrice::getId,feeId)); |
| | | } |
| | | |
| | | return AjaxResult.success(); |
| | | |
| | | } |
| | | |
| | | // @Override |
| | | // public AjaxResult importExcel(MultipartFile file) { |
| | | // |
| | | // } |
| | | |
| | | |
| | | // @Override |
| | | // @Transactional |
| | | // public AjaxResult importExcel(MultipartFile file) { |
| | | // |
| | | // ExcelUtil<ZTravelPrice> util = new ExcelUtil<>(ZTravelPrice.class); |
| | | // List<ZTravelPrice> dataList = null; |
| | | // try { |
| | | // dataList = util.importExcel(file.getInputStream()); |
| | | // } catch (Exception e) { |
| | | // throw new RuntimeException("没有按照规则导入数据"); |
| | | // } |
| | | // |
| | | // assert dataList != null; |
| | | // |
| | | // for (ZTravelPrice zTravelPrice : dataList) { |
| | | // zTravelPriceService.mySave(zTravelPrice); |
| | | // } |
| | | // |
| | | // return AjaxResult.success(); |
| | | // |
| | | // } |
| | | } |