| | |
| | | package com.ycl.platform.service.impl; |
| | | |
| | | import com.ycl.platform.domain.entity.YwPeople; |
| | | import com.ycl.platform.domain.entity.YwUnit; |
| | | import com.ycl.platform.mapper.YwPeopleMapper; |
| | | import com.ycl.platform.mapper.YwUnitMapper; |
| | | import com.ycl.platform.service.YwPeopleService; |
| | | import com.ycl.system.Result; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.util.Assert; |
| | | |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | /** |
| | | * 运维人员 服务实现类 |
| | |
| | | public class YwPeopleServiceImpl extends ServiceImpl<YwPeopleMapper, YwPeople> implements YwPeopleService { |
| | | |
| | | private final YwPeopleMapper ywPeopleMapper; |
| | | private final YwUnitMapper ywUnitMapper; |
| | | |
| | | /** |
| | | * 添加 |
| | |
| | | @Override |
| | | public Result add(YwPeopleForm form) { |
| | | YwPeople entity = YwPeopleForm.getEntityByForm(form, null); |
| | | entity.setAddWay("manual"); |
| | | if(baseMapper.insert(entity) > 0) { |
| | | return Result.ok("添加成功"); |
| | | } |
| | |
| | | public Result page(YwPeopleQuery query) { |
| | | |
| | | IPage<YwPeople> page = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .eq(StringUtils.hasText(query.getYwPersonCode()), YwPeople::getYwPersonCode, query.getYwPersonCode()) |
| | | .like(StringUtils.hasText(query.getYwPersonName()), YwPeople::getYwPersonName, query.getYwPersonName()) |
| | | .eq(Objects.nonNull(query.getBelongUnit()), YwPeople::getBelongUnit, query.getBelongUnit()) |
| | | .orderByDesc(YwPeople::getCreateTime) |
| | | .page(PageUtil.getPage(query, YwPeople.class)); |
| | | |
| | | List<YwPeopleVO> vos = page.getRecords().stream() |
| | | .map( |
| | | entity -> YwPeopleVO.getVoByEntity(entity, null) |
| | | entity -> { |
| | | YwPeopleVO vo = YwPeopleVO.getVoByEntity(entity, null); |
| | | YwUnit unit = new LambdaQueryChainWrapper<>(ywUnitMapper) |
| | | .eq(YwUnit::getId, vo.getBelongUnit()) |
| | | .select(YwUnit::getUnitName) |
| | | .one(); |
| | | if (Objects.nonNull(unit)) { |
| | | vo.setBelongUnitName(unit.getUnitName()); |
| | | } |
| | | return vo; |
| | | } |
| | | ) |
| | | .collect(Collectors.toList()); |
| | | return Result.ok().data(vos).total(page.getTotal()); |