| | |
| | | package org.dromara.demo.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.dromara.common.core.utils.MapstructUtils; |
| | | import org.dromara.common.core.utils.StringUtils; |
| | | import org.dromara.common.mybatis.core.page.TableDataInfo; |
| | | import org.dromara.common.mybatis.core.page.PageQuery; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.dromara.common.mybatis.core.page.TableDataInfo; |
| | | import org.dromara.demo.domain.RsSceneryInfo; |
| | | import org.dromara.demo.domain.RsSceneryOperationData; |
| | | import org.dromara.demo.domain.bo.RsSceneryOperationDataBo; |
| | | import org.dromara.demo.domain.vo.RsSceneryOperationDataVo; |
| | | import org.dromara.demo.domain.RsSceneryOperationData; |
| | | import org.dromara.demo.mapper.RsSceneryInfoMapper; |
| | | import org.dromara.demo.mapper.RsSceneryOperationDataMapper; |
| | | import org.dromara.demo.service.IRsSceneryOperationDataService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Collection; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 景区运行数据Service业务层处理 |
| | | * |
| | | * @author Lion Li |
| | | * @date 2024-02-27 |
| | | * @author gonghl |
| | | * @date 2024-03-05 |
| | | */ |
| | | @RequiredArgsConstructor |
| | | @Service |
| | | public class RsSceneryOperationDataServiceImpl implements IRsSceneryOperationDataService { |
| | | |
| | | private final RsSceneryOperationDataMapper baseMapper; |
| | | private final RsSceneryInfoMapper sceneryInfoMapper; |
| | | |
| | | /** |
| | | * 查询景区运行数据 |
| | | */ |
| | | @Override |
| | | public RsSceneryOperationDataVo queryById(Long id){ |
| | | public RsSceneryOperationDataVo queryById(String id){ |
| | | return baseMapper.selectVoById(id); |
| | | } |
| | | |
| | |
| | | private LambdaQueryWrapper<RsSceneryOperationData> buildQueryWrapper(RsSceneryOperationDataBo bo) { |
| | | Map<String, Object> params = bo.getParams(); |
| | | LambdaQueryWrapper<RsSceneryOperationData> lqw = Wrappers.lambdaQuery(); |
| | | lqw.eq(bo.getPeriodYear() != null, RsSceneryOperationData::getPeriodYear, bo.getPeriodYear()); |
| | | lqw.eq(bo.getPeriodMonth() != null, RsSceneryOperationData::getPeriodMonth, bo.getPeriodMonth()); |
| | | lqw.eq(bo.getCarFlowNum() != null, RsSceneryOperationData::getCarFlowNum, bo.getCarFlowNum()); |
| | | lqw.eq(bo.getPersonFlowNum() != null, RsSceneryOperationData::getPersonFlowNum, bo.getPersonFlowNum()); |
| | | lqw.eq(bo.getVisitorSubNum() != null, RsSceneryOperationData::getVisitorSubNum, bo.getVisitorSubNum()); |
| | | lqw.eq(bo.getEnterGardenNum() != null, RsSceneryOperationData::getEnterGardenNum, bo.getEnterGardenNum()); |
| | | lqw.eq(bo.getOnPolice() != null, RsSceneryOperationData::getOnPolice, bo.getOnPolice()); |
| | | lqw.eq(bo.getOnPaddyWagon() != null, RsSceneryOperationData::getOnPaddyWagon, bo.getOnPaddyWagon()); |
| | | lqw.eq(bo.getStandbyPolice() != null, RsSceneryOperationData::getStandbyPolice, bo.getStandbyPolice()); |
| | | lqw.like(StringUtils.isNotBlank(bo.getSceneryInfoName()), RsSceneryOperationData::getSceneryInfoName, bo.getSceneryInfoName()); |
| | | lqw.eq(StringUtils.isNotBlank(bo.getPeriodDate()), RsSceneryOperationData::getPeriodDate, bo.getPeriodDate()); |
| | | lqw.eq(bo.getStatus() != null, RsSceneryOperationData::getStatus, bo.getStatus()); |
| | | lqw.eq(bo.getScId() != null, RsSceneryOperationData::getScId, bo.getScId()); |
| | | lqw.orderByDesc(RsSceneryOperationData::getCreateTime); |
| | | return lqw; |
| | | } |
| | | |
| | |
| | | if (flag) { |
| | | bo.setId(add.getId()); |
| | | } |
| | | // 启用新数据将其余同类型数据改为禁用 |
| | | if (bo.getStatus().equals(1L)) { |
| | | LambdaUpdateWrapper<RsSceneryOperationData> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | updateWrapper.ne(RsSceneryOperationData::getId, bo.getId()).eq(RsSceneryOperationData::getSceneryInfoId, bo.getSceneryInfoId()).set(RsSceneryOperationData::getStatus, 2); |
| | | baseMapper.update(updateWrapper); |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | |
| | | @Override |
| | | public Boolean updateByBo(RsSceneryOperationDataBo bo) { |
| | | RsSceneryOperationData update = MapstructUtils.convert(bo, RsSceneryOperationData.class); |
| | | validEntityBeforeSave(update); |
| | | // 启用新数据将其余同类型数据改为禁用 |
| | | if (bo.getStatus().equals(1L)) { |
| | | LambdaUpdateWrapper<RsSceneryOperationData> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | updateWrapper.ne(RsSceneryOperationData::getId, bo.getId()).eq(RsSceneryOperationData::getSceneryInfoId, bo.getSceneryInfoId()).set(RsSceneryOperationData::getStatus, 2); |
| | | baseMapper.update(updateWrapper); |
| | | } |
| | | return baseMapper.updateById(update) > 0; |
| | | } |
| | | |
| | |
| | | * 保存前的数据校验 |
| | | */ |
| | | private void validEntityBeforeSave(RsSceneryOperationData entity){ |
| | | //TODO 做一些数据校验,如唯一约束 |
| | | entity.setCreateTime(new Date()); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除景区运行数据 |
| | | */ |
| | | @Override |
| | | public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) { |
| | | public Boolean deleteWithValidByIds(Collection<String> ids, Boolean isValid) { |
| | | if(isValid){ |
| | | //TODO 做一些业务上的校验,判断是否需要校验 |
| | | } |
| | | return baseMapper.deleteBatchIds(ids) > 0; |
| | | } |
| | | |
| | | @Override |
| | | public String importExcel(List<RsSceneryOperationData> list) { |
| | | Set<String> sceneryInfoNames = new HashSet<>(); |
| | | // 查询数据库是否存在导入的景区 |
| | | Map<String, RsSceneryInfo> sceneryInfoMap = sceneryInfoMapper.selectList().stream() |
| | | .collect(Collectors.toMap(RsSceneryInfo::getSceneryName, Function.identity())); |
| | | for (RsSceneryOperationData operationData : list) { |
| | | String sceneryName = operationData.getSceneryInfoName(); |
| | | RsSceneryInfo sceneryInfo = sceneryInfoMap.get(sceneryName); |
| | | // 景区已存在,正常导入,默认禁用 |
| | | if (sceneryInfo != null) { |
| | | operationData.setSceneryInfoId(sceneryInfo.getId()); |
| | | operationData.setPeriod(operationData.getPeriodDate().length() > 4 ? 1L : 2L); |
| | | operationData.setCreateTime(new Date()); |
| | | operationData.setStatus(2L); |
| | | } else { |
| | | sceneryInfoNames.add(operationData.getSceneryInfoName()); |
| | | } |
| | | } |
| | | if (!sceneryInfoNames.isEmpty()) { |
| | | return "很抱歉,导入失败!" + String.join("、", "<" + sceneryInfoNames + ">") + "景区不存在,请前往【景区配置】添加后重试!"; |
| | | } |
| | | baseMapper.insertBatch(list); |
| | | return "恭喜您,数据已全部导入成功!共" + list.size() + "条!"; |
| | | } |
| | | } |