| | |
| | | package com.ycl.platform.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; |
| | | import com.ycl.platform.base.BaseSelect; |
| | | import com.ycl.platform.domain.entity.Region; |
| | | import com.ycl.platform.domain.entity.YwPeople; |
| | | import com.ycl.platform.domain.entity.YwPoint; |
| | | import com.ycl.platform.domain.entity.YwUnit; |
| | | import com.ycl.platform.domain.form.BatchEditPointForm; |
| | | import com.ycl.platform.mapper.RegionMapper; |
| | | import com.ycl.platform.mapper.YwPeopleMapper; |
| | | import com.ycl.platform.mapper.YwPointMapper; |
| | | import com.ycl.platform.mapper.YwUnitMapper; |
| | | import com.ycl.platform.service.YwPointService; |
| | | import com.ycl.platform.service.YwUnitService; |
| | | import com.ycl.system.Result; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.platform.domain.form.YwPointForm; |
| | | import com.ycl.platform.domain.vo.YwPointVO; |
| | | import com.ycl.platform.domain.query.YwPointQuery; |
| | | import java.util.List; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | |
| | | import com.ycl.system.entity.SysUser; |
| | | import com.ycl.system.service.ISysDeptService; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.ycl.system.page.PageUtil; |
| | | import com.ycl.utils.SecurityUtils; |
| | | import enumeration.general.RegionLevelEnum; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | | import java.util.ArrayList; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | /** |
| | | * 运维点位 服务实现类 |
| | |
| | | public class YwPointServiceImpl extends ServiceImpl<YwPointMapper, YwPoint> implements YwPointService { |
| | | |
| | | private final YwPointMapper ywPointMapper; |
| | | private final ISysDeptService deptService; |
| | | private final YwUnitService unitService; |
| | | private final YwUnitMapper ywUnitMapper; |
| | | private final RegionMapper regionMapper; |
| | | private final YwPeopleMapper ywPeopleMapper; |
| | | |
| | | /** |
| | | * 添加 |
| | |
| | | return Result.ok("添加成功"); |
| | | } |
| | | return Result.error("添加失败"); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result batchAdd(List<YwPointForm> formList) { |
| | | formList.stream() |
| | | .forEach(form -> { |
| | | YwPoint entity = YwPointForm.getEntityByForm(form, null); |
| | | entity.setStatus("未开始"); |
| | | baseMapper.insert(entity); |
| | | }); |
| | | return Result.ok("添加成功"); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result batchEdit(BatchEditPointForm form) { |
| | | if (Objects.nonNull(form.getUnitId())) { |
| | | new LambdaUpdateChainWrapper<>(baseMapper) |
| | | .in(YwPoint::getId, form.getIds()) |
| | | .set(YwPoint::getUnitId, form.getUnitId()) |
| | | .set(YwPoint::getStartTime, form.getStartTime()) |
| | | .set(YwPoint::getEndTime, form.getEndTime()) |
| | | .update(); |
| | | } else { |
| | | new LambdaUpdateChainWrapper<>(baseMapper) |
| | | .in(YwPoint::getId, form.getIds()) |
| | | .set(YwPoint::getUnitId, form.getUnitId()) |
| | | .set(YwPoint::getStartTime, null) |
| | | .set(YwPoint::getEndTime, null) |
| | | .update(); |
| | | } |
| | | return Result.ok("修改成功"); |
| | | } |
| | | |
| | | /** |
| | |
| | | public Result page(YwPointQuery query) { |
| | | |
| | | IPage<YwPoint> page = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .like(StringUtils.hasText(query.getPointName()), YwPoint::getPointName, query.getPointName()) |
| | | .orderByDesc(YwPoint::getCreateTime) |
| | | .page(PageUtil.getPage(query, YwPoint.class)); |
| | | |
| | | List<YwPointVO> vos = page.getRecords().stream() |
| | | .map( |
| | | entity -> YwPointVO.getVoByEntity(entity, null) |
| | | .setDeptName(deptService.selectDeptById(entity.getDeptId()).getDeptName()) |
| | | .setUnitName(unitService.getById(entity.getUnitId()).getUnitName()) |
| | | ) |
| | | .collect(Collectors.toList()); |
| | | |
| | | return Result.ok().data(vos).total(page.getTotal()); |
| | | } |
| | | |
| | |
| | | .collect(Collectors.toList()); |
| | | return Result.ok().data(vos); |
| | | } |
| | | |
| | | @Override |
| | | public Result select(String keyword) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | // 获取当前运维人员的运维单位 |
| | | YwPeople people = new LambdaQueryChainWrapper<>(ywPeopleMapper) |
| | | .eq(YwPeople::getUserId, userId) |
| | | .one(); |
| | | Integer unitId = null; |
| | | if (Objects.nonNull(people)) { |
| | | unitId = people.getBelongUnit(); |
| | | } |
| | | |
| | | List<Region> list = new LambdaQueryChainWrapper<>(regionMapper) |
| | | .eq(Region::getRegionLevel, RegionLevelEnum.STREET) |
| | | .like(Region::getFullName, keyword) |
| | | .list(); |
| | | List<BaseSelect> data = list.stream().map(item -> { |
| | | BaseSelect baseSelect = new BaseSelect(); |
| | | baseSelect.setId(item.getId()); |
| | | baseSelect.setValue(item.getFullName()); |
| | | return baseSelect; |
| | | }).collect(Collectors.toList()); |
| | | return Result.ok().data(data); |
| | | } |
| | | } |