package com.newfiber.api.pc.service.impl; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.newfiber.api.core.commons.CustomException; import com.newfiber.api.core.commons.PageRequestObject; import com.newfiber.api.core.commons.PageResultObject; import com.newfiber.api.core.commons.ResultCode; import com.newfiber.api.pc.dao.PeopleMapper; import com.newfiber.api.pc.dto.PeopleSerchDTO; import com.newfiber.api.pc.model.meet.People; import com.newfiber.api.pc.service.PeopleSerivce; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import java.util.List; /** * @Author:zhz * @CreateDate:2020/11/24 14:08 * @Description: */ @Service @Transactional(rollbackFor = Exception.class) public class PeopleSerivceImpl extends ServiceImpl<PeopleMapper,People> implements PeopleSerivce { @Override public PageResultObject<People> queryPage(PageRequestObject<PeopleSerchDTO> peopleDTO) { Page<People> page = new Page<>(peopleDTO.getCurrent(), peopleDTO.getSize()); EntityWrapper<People> wrapper = new EntityWrapper<>(); PeopleSerchDTO dto = peopleDTO.getObject(); if(!StringUtils.isEmpty(dto.getPeopleName())){ wrapper.like("people_name",dto.getPeopleName()); } if(!StringUtils.isEmpty(dto.getDId())){ wrapper.eq("duty_type",dto.getDId()); } Page<People> peoplePage = this.selectPage(page, wrapper); int count = this.selectCount(wrapper); return new PageResultObject<>(peopleDTO.getCurrent(), peopleDTO.getSize(),(long)count,peoplePage.getRecords()); } @Override public void addPeople(People people) { if(StringUtils.isEmpty(people)){ throw new CustomException(ResultCode.PARAM_NULL); } boolean repeatJob = isRepeatJob(people.getPeopleNo(), people.getJob()); if(repeatJob){ throw new CustomException(500,"不能添加相同职务"); } boolean insert = this.insert(people); if(!insert){ throw new CustomException(ResultCode.SAVE_ERROR); } } @Override public boolean isRepeatJob(String userNo,String job){ if(StringUtils.isEmpty(userNo) || StringUtils.isEmpty(job)){ throw new CustomException(500,"用户编号与职业不能为空!"); } EntityWrapper<People> wrapper = new EntityWrapper<>(); wrapper.eq("people_no",userNo); List<People> people = this.selectList(wrapper); for(People p : people){ if(p.getJob().equalsIgnoreCase(job)){ return true; } } return false; } }