|
@@ -0,0 +1,304 @@
|
|
|
+package com.persagy.fm.person.service.impl;
|
|
|
+
|
|
|
+import com.persagy.fm.common.model.RequiredParamsStorage;
|
|
|
+import com.persagy.fm.person.dao.PersonMapper;
|
|
|
+import com.persagy.fm.person.model.vo.ResponsePersonListItemVO;
|
|
|
+import com.persagy.fm.person.service.IPersonService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.persagy.fm.workresume.model.WorkResume;
|
|
|
+import com.persagy.fm.workresume.model.dto.PageQueryWorkResumeDTO;
|
|
|
+import com.persagy.fm.workresume.service.IWorkResumeService;
|
|
|
+import org.assertj.core.util.Lists;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import com.persagy.fm.common.constant.enums.ValidEnum;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.persagy.fm.person.model.*;
|
|
|
+import com.persagy.fm.person.model.dto.*;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.google.common.base.CaseFormat;
|
|
|
+import com.persagy.fm.common.model.dto.Sort;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 人员(Person) service层
|
|
|
+ *
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-03-15 17:20:31
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class PersonServiceImpl extends ServiceImpl<PersonMapper, Person>
|
|
|
+ implements IPersonService {
|
|
|
+ @Autowired
|
|
|
+ private IWorkResumeService workResumeService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建人员
|
|
|
+ *
|
|
|
+ * @return Long 人员主键
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-03-15 17:20:31
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Long createPerson(AddPersonDTO addPersonDTO) {
|
|
|
+ Person person = ConvertPersonTool.INSTANCE.convertAddDto2Entity(addPersonDTO);
|
|
|
+ // 设置默认值
|
|
|
+ setDefaultValue(person);
|
|
|
+ save(person);
|
|
|
+ return person.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 如果某些字段没有赋值,使用默认的值
|
|
|
+ *
|
|
|
+ * @param person 人员实体
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/3/12 12:29 下午
|
|
|
+ */
|
|
|
+ private void setDefaultValue(Person person) {
|
|
|
+ person.setCreator(RequiredParamsStorage.getUserId());
|
|
|
+ // todo 其他默认的属性
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 人员详情
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return 部门do类
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-03-15 17:20:31
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Person queryPersonDetail(Long id) {
|
|
|
+ Person person = getById(id);
|
|
|
+ if (person == null) {
|
|
|
+ throw new IllegalArgumentException("查看Person详情时发生异常,找不到要查看的记录,id=" + id);
|
|
|
+ }
|
|
|
+ return person;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新人员
|
|
|
+ *
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-03-15 17:20:31
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void updatePerson(UpdatePersonDTO updatePersonDTO) {
|
|
|
+ Person person = getById(updatePersonDTO.getId());
|
|
|
+ person = ConvertPersonTool.INSTANCE.convertUpdateDto2Entity(person, updatePersonDTO);
|
|
|
+ person.setModifier(RequiredParamsStorage.getUserId());
|
|
|
+ updateById(person);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验人员是否可删除
|
|
|
+ *
|
|
|
+ * @param id 人员主键
|
|
|
+ * @return 人员do类
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-03-15 17:20:31
|
|
|
+ */
|
|
|
+ public Person checkDeletable(Long id) {
|
|
|
+ if (id == null) {
|
|
|
+ throw new IllegalArgumentException("删除Person时发生异常,主键为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ Person person = getById(id);
|
|
|
+
|
|
|
+ if (person == null) {
|
|
|
+ throw new IllegalArgumentException("删除Person时发生异常,找不到要删除的数据,id:" + id);
|
|
|
+ }
|
|
|
+
|
|
|
+ return person;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除人员
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-03-15 17:20:31
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void deletePerson(Long id) {
|
|
|
+ // 校验是否可删除
|
|
|
+ Person person = checkDeletable(id);
|
|
|
+
|
|
|
+ person.setValid(ValidEnum.FALSE.getType());
|
|
|
+ updateById(person);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询人员
|
|
|
+ *
|
|
|
+ * @return List<Person>
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-03-15 17:20:31
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Person> queryPersonList(QueryPersonDTO queryPersonDTO) {
|
|
|
+ QueryWrapper<Person> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq(Person.PROP_VALID, ValidEnum.TRUE.getType());
|
|
|
+ // 默认按创建时间倒序排序
|
|
|
+ queryWrapper.orderBy(true, false, Person.PROP_CREATIONTIME);
|
|
|
+
|
|
|
+ if (queryPersonDTO != null) {
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(queryPersonDTO.getName())) {
|
|
|
+ queryWrapper.like(Person.PROP_NAME, queryPersonDTO.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(queryPersonDTO.getUsername())) {
|
|
|
+ queryWrapper.like(Person.PROP_USERNAME, queryPersonDTO.getUsername());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(queryPersonDTO.getIdNumber())) {
|
|
|
+ queryWrapper.like(Person.PROP_ID_NUMBER, queryPersonDTO.getIdNumber());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (queryPersonDTO.getGender() != null) {
|
|
|
+ queryWrapper.eq(Person.PROP_GENDER, queryPersonDTO.getGender());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (queryPersonDTO.getBirthday() != null) {
|
|
|
+ queryWrapper.eq(Person.PROP_BIRTHDAY, queryPersonDTO.getBirthday());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(queryPersonDTO.getOtherAccount())) {
|
|
|
+ queryWrapper.like(Person.PROP_OTHER_ACCOUNT, queryPersonDTO.getOtherAccount());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(queryPersonDTO.getUserFrom())) {
|
|
|
+ queryWrapper.like(Person.PROP_USER_FROM, queryPersonDTO.getUserFrom());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(queryPersonDTO.getRemark())) {
|
|
|
+ queryWrapper.like(Person.PROP_REMARK, queryPersonDTO.getRemark());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(queryPersonDTO.getProfession())) {
|
|
|
+ queryWrapper.like(Person.PROP_PROFESSION, queryPersonDTO.getProfession());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return list(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<ResponsePersonListItemVO> pageQueryPersonListByDepId(PageQueryPersonByDepDTO pageQueryPersonByDepDTO) {
|
|
|
+ // 根据工作信息获取部门下的人员
|
|
|
+ PageQueryWorkResumeDTO pageQueryWorkResumeDTO = ConvertPersonTool.INSTANCE.
|
|
|
+ convert2PageQueryWorkResumeDTO(pageQueryPersonByDepDTO);
|
|
|
+ IPage<WorkResume> workResumePagedList = workResumeService.pageQueryWorkResume(pageQueryWorkResumeDTO);
|
|
|
+ List<WorkResume> workResumeList = workResumePagedList.getRecords();
|
|
|
+
|
|
|
+ /* 将工作信息转换为人员信息 */
|
|
|
+ if (CollectionUtils.isEmpty(workResumeList)) {
|
|
|
+ IPage<ResponsePersonListItemVO> result = new Page<>();
|
|
|
+ result.setRecords(Lists.newArrayList());
|
|
|
+ result.setTotal(0);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取人员的基本信息
|
|
|
+ List<Long> personIdList = workResumeList.stream().map(WorkResume::getPersonId).collect(Collectors.toList());
|
|
|
+ List<Person> people = listByIds(personIdList);
|
|
|
+
|
|
|
+ // TODO: 2021/3/15 获取账号的信息
|
|
|
+
|
|
|
+ // 数据转换
|
|
|
+ List<ResponsePersonListItemVO> responsePersonListItems = ConvertPersonTool.INSTANCE.convert2List(people);
|
|
|
+ IPage<ResponsePersonListItemVO> result = new Page<>();
|
|
|
+ result.setRecords(responsePersonListItems);
|
|
|
+ result.setTotal(workResumePagedList.getTotal());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询人员
|
|
|
+ *
|
|
|
+ * @return IPage<Person>
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-03-15 17:20:31
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<Person> pageQueryPerson(PageQueryPersonDTO pageQueryPersonDTO) {
|
|
|
+ QueryWrapper<Person> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq(Person.PROP_VALID, ValidEnum.TRUE.getType());
|
|
|
+ // 这里认为pageQueryDTO是经过校验的,肯定包含分页信息
|
|
|
+ IPage<Person> pageParam = new Page<>(pageQueryPersonDTO.getPage(), pageQueryPersonDTO.getSize(), true);
|
|
|
+ // 排序信息
|
|
|
+ if (CollectionUtils.isEmpty(pageQueryPersonDTO.getOrders())) {
|
|
|
+ // 默认按创建时间倒序排序
|
|
|
+ queryWrapper.orderBy(true, false, Person.PROP_CREATIONTIME);
|
|
|
+ } else {
|
|
|
+ List<Sort> orders = pageQueryPersonDTO.getOrders();
|
|
|
+ for (Sort sort : orders) {
|
|
|
+ // 将驼峰转换为下划线格式
|
|
|
+ sort.setColumn(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, sort.getColumn()));
|
|
|
+ queryWrapper.orderBy(true, sort.isAsc(), sort.getColumn());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(pageQueryPersonDTO.getName())) {
|
|
|
+ queryWrapper.like(Person.PROP_NAME, pageQueryPersonDTO.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(pageQueryPersonDTO.getUsername())) {
|
|
|
+ queryWrapper.like(Person.PROP_USERNAME, pageQueryPersonDTO.getUsername());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(pageQueryPersonDTO.getIdNumber())) {
|
|
|
+ queryWrapper.like(Person.PROP_ID_NUMBER, pageQueryPersonDTO.getIdNumber());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (pageQueryPersonDTO.getGender() != null) {
|
|
|
+ queryWrapper.eq(Person.PROP_GENDER, pageQueryPersonDTO.getGender());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (pageQueryPersonDTO.getBirthday() != null) {
|
|
|
+ queryWrapper.eq(Person.PROP_BIRTHDAY, pageQueryPersonDTO.getBirthday());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(pageQueryPersonDTO.getOtherAccount())) {
|
|
|
+ queryWrapper.like(Person.PROP_OTHER_ACCOUNT, pageQueryPersonDTO.getOtherAccount());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(pageQueryPersonDTO.getUserFrom())) {
|
|
|
+ queryWrapper.like(Person.PROP_USER_FROM, pageQueryPersonDTO.getUserFrom());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(pageQueryPersonDTO.getRemark())) {
|
|
|
+ queryWrapper.like(Person.PROP_REMARK, pageQueryPersonDTO.getRemark());
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 需判断使用like还是eq
|
|
|
+ if (StringUtils.isNotEmpty(pageQueryPersonDTO.getProfession())) {
|
|
|
+ queryWrapper.like(Person.PROP_PROFESSION, pageQueryPersonDTO.getProfession());
|
|
|
+ }
|
|
|
+
|
|
|
+ return getBaseMapper().selectPage(pageParam, queryWrapper);
|
|
|
+ }
|
|
|
+}
|