| | |
| | | import java.util.List; |
| | | |
| | | import com.ycl.system.entity.SysUser; |
| | | import com.ycl.system.mapper.SysDeptMapper; |
| | | import com.ycl.system.service.ISysDeptService; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | |
| | | @RequiredArgsConstructor |
| | | public class YwPointServiceImpl extends ServiceImpl<YwPointMapper, YwPoint> implements YwPointService { |
| | | |
| | | private final YwPointMapper ywPointMapper; |
| | | private final ISysDeptService deptService; |
| | | private final SysDeptMapper sysDeptMapper; |
| | | private final YwUnitService unitService; |
| | | private final YwUnitMapper ywUnitMapper; |
| | | private final RegionMapper regionMapper; |
| | | private final YwPeopleMapper ywPeopleMapper; |
| | | |
| | | /** |
| | |
| | | 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) |
| | |
| | | */ |
| | | @Override |
| | | public Result update(YwPointForm form) { |
| | | |
| | | YwPoint entity = baseMapper.selectById(form.getId()); |
| | | |
| | | // 为空抛IllegalArgumentException,做全局异常处理 |
| | | Assert.notNull(entity, "记录不存在"); |
| | | BeanUtils.copyProperties(form, entity); |
| | | if (baseMapper.updateById(entity) > 0) { |
| | | return Result.ok("修改成功"); |
| | | } |
| | | return Result.error("修改失败"); |
| | | entity.setPointTag(form.getPointTag().stream().collect(Collectors.joining(","))); |
| | | baseMapper.updateById(entity); |
| | | return Result.ok("修改成功"); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | 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()); |
| | | IPage<YwPointVO> page = PageUtil.getPage(query, YwPointVO.class); |
| | | baseMapper.page(page, query); |
| | | page.getRecords().stream().forEach(point -> { |
| | | if (StringUtils.hasText(point.getPointTagString())) { |
| | | point.setPointTags(point.getPointTagString().split(",")); |
| | | } |
| | | }); |
| | | return Result.ok().data(page.getRecords()).total(page.getTotal()); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public Result detail(String id) { |
| | | |
| | | YwPoint entity = baseMapper.selectById(id); |
| | | Assert.notNull(entity, "记录不存在"); |
| | | YwPointVO vo = YwPointVO.getVoByEntity(entity, null); |
| | | if (StringUtils.hasText(entity.getPointTag())) { |
| | | vo.setPointTags(entity.getPointTag().split(",")); |
| | | } |
| | | if (Objects.nonNull(entity.getDeptId())) { |
| | | vo.setDeptIds(sysDeptMapper.selectParents(entity.getDeptId())); |
| | | } |
| | | return Result.ok().data(vo); |
| | | } |
| | | |