PositionRequireItemServiceImpl.java 8.65 KB
package com.laowu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.laowu.dto.position.AddRequirementsDTO;
import com.laowu.dto.position.RequirementsDTO;
import com.laowu.mapper.*;
import com.laowu.model.*;
import com.laowu.service.PositionRequireItemService;
import com.laowu.util.ConstantUtils;
import com.laowu.vo.position.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 项目职位需求信息 服务实现类
 * </p>
 *
 * @author Tuyp
 * @since 2023-03-27
 */
@Service
public class PositionRequireItemServiceImpl extends ServiceImpl<PositionRequireItemMapper, PositionRequireItemDO> implements PositionRequireItemService {

    @Autowired
    private PositionItemInfoMapper positionItemInfoMapper;

    @Autowired
    private PositionItemJobMappingMapper positionItemJobMappingMapper;

    @Autowired
    private PositionRequireHistoryMapper positionRequireHistoryMapper;

    @Autowired
    private WorkstationRequireMappingMapper workstationRequireMappingMapper;

    @Autowired
    private CompanyDictMapper companyDictMapper;

    public IPage<RequirementsVO> requirements(RequirementsDTO requirementsDTO) {

        Page pager = new Page(requirementsDTO.getPageNum(), requirementsDTO.getPageSize());
        IPage<RequirementsVO> iPage = this.baseMapper.requirements(pager, requirementsDTO.getItemName(), requirementsDTO.getItemStatus(), requirementsDTO.getProvince(), requirementsDTO.getCity(), requirementsDTO.getCounty(), requirementsDTO.getPositionId());
        List<RequirementsVO> records = iPage.getRecords();
        for (RequirementsVO rv : records) {
            //预招人数
            List<PositionCountsVO> positionItemInfoDOS = positionItemInfoMapper.positionCounts(rv.getId());
            rv.setPositionItemInfoDOS(positionItemInfoDOS);
            //职位分类
            List<LibJobSortDO> libJobSortDOS = positionItemJobMappingMapper.positionSorts(rv.getId());
            rv.setLibJobSortDOS(libJobSortDOS);
        }
        return iPage;
    }

    public String deleteRequirements(AddRequirementsDTO addRequirementsDTO) {

        List<PositionItemInfoDO> itemInfoDOS = positionItemInfoMapper.selectList(new QueryWrapper<PositionItemInfoDO>()
                .lambda()
                .eq(PositionItemInfoDO::getPositionRequireId, addRequirementsDTO.getId()));

        for (PositionItemInfoDO piid : itemInfoDOS) {
            List<PositionItemJobMappingDO> positionItemJobMappingDOS = positionItemJobMappingMapper.selectList(new QueryWrapper<PositionItemJobMappingDO>()
                    .lambda()
                    .eq(PositionItemJobMappingDO::getItemInfoId, piid.getId()));

            positionItemJobMappingDOS.stream().forEach(x -> {
                positionItemJobMappingMapper.deleteById(x.getId());
            });
            positionItemInfoMapper.deleteById(piid.getId());
        }
        this.baseMapper.deleteById(addRequirementsDTO.getId());

        PositionRequireHistoryDO positionRequireHistoryDO = new PositionRequireHistoryDO();
        positionRequireHistoryDO.setRequireId(addRequirementsDTO.getId());
        positionRequireHistoryDO.setAdministerId(addRequirementsDTO.getUserId());
        positionRequireHistoryDO.setModule(addRequirementsDTO.getModule());
        positionRequireHistoryDO.setOpr("删除了项目职位需求信息");


        return ConstantUtils.DELETE_SUCCESS;
    }

    public String updateRequirements(AddRequirementsDTO addRequirementsDTO) {

        PositionRequireItemDO positionRequireItemDO1 = this.baseMapper.selectById(addRequirementsDTO.getId());

        PositionRequireItemDO positionRequireItemDO = new PositionRequireItemDO();
        BeanUtils.copyProperties(addRequirementsDTO,positionRequireItemDO);
        this.baseMapper.updateById(positionRequireItemDO);

        //修改内容
        PositionRequireHistoryDO positionRequireHistoryDO = new PositionRequireHistoryDO();
        positionRequireHistoryDO.setAdministerId(addRequirementsDTO.getUserId());
        positionRequireHistoryDO.setModule(addRequirementsDTO.getModule());
        positionRequireHistoryDO.setRequireId(positionRequireItemDO.getId());

        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("变更了“");

        //id  itemName  itemStatus  companyId  jobId  infoOrigin  province city county
        if (null != positionRequireItemDO1.getItemName() && !positionRequireItemDO1.getItemName().equals(addRequirementsDTO.getItemName())){
            stringBuffer.append("项目名称、");
        }

        if (null != positionRequireItemDO1.getCompanyId() && !positionRequireItemDO1.getCompanyId().equals(addRequirementsDTO.getCompanyId())){
            stringBuffer.append("企业名称、");
        }

        if (null != positionRequireItemDO1.getItemStatus() && !positionRequireItemDO1.getItemStatus().equals(addRequirementsDTO.getItemStatus())){
            stringBuffer.append("招聘状态、");
        }

        if (null != positionRequireItemDO1.getInfoOrigin() && !positionRequireItemDO1.getInfoOrigin().equals(addRequirementsDTO.getInfoOrigin())){
            stringBuffer.append("关联信息、");
        }

        if (null != positionRequireItemDO1.getProvince() && !positionRequireItemDO1.getProvince().equals(addRequirementsDTO.getProvince())||!positionRequireItemDO1.getCity().equals(addRequirementsDTO.getCity())||!positionRequireItemDO1.getCounty().equals(addRequirementsDTO.getCounty())){
            stringBuffer.append("就业地区");
        }

        String opr = stringBuffer.substring(0, stringBuffer.length() - 1) + "”";
        positionRequireHistoryDO.setOpr(opr);
        positionRequireHistoryMapper.insert(positionRequireHistoryDO);

        return ConstantUtils.SUCCESS_UPDATE;
    }

    @Transactional(rollbackFor = Exception.class)
    public String addRequirements(AddRequirementsDTO addRequirementsDTO) {

        PositionRequireItemDO positionRequireItemDO = new PositionRequireItemDO();
        BeanUtils.copyProperties(addRequirementsDTO,positionRequireItemDO);
        this.baseMapper.insert(positionRequireItemDO);

        WorkstationRequireMappingDO workstationRequireMappingDO = new WorkstationRequireMappingDO();
        workstationRequireMappingDO.setStationId(addRequirementsDTO.getStationId());
        workstationRequireMappingDO.setRequireId(positionRequireItemDO.getId());
        workstationRequireMappingMapper.insert(workstationRequireMappingDO);

        PositionRequireHistoryDO positionRequireHistoryDO = new PositionRequireHistoryDO();
        positionRequireHistoryDO.setRequireId(positionRequireHistoryDO.getId());
        positionRequireHistoryDO.setAdministerId(addRequirementsDTO.getUserId());
        positionRequireHistoryDO.setModule(addRequirementsDTO.getModule());
        positionRequireHistoryDO.setOpr("创建了项目职位需求信息");
        positionRequireHistoryMapper.insert(positionRequireHistoryDO);
        return ConstantUtils.ADD_SUCCESS;
    }

    public OneRequirementVO oneRequirement(PositionRequireItemDO positionRequireItemDO) {

        OneRequirementVO oneRequirementVO = new OneRequirementVO();
        PositionRequireItemDO positionRequireItemDO1 = this.baseMapper.selectById(positionRequireItemDO.getId());
        BeanUtils.copyProperties(positionRequireItemDO1,oneRequirementVO);

        CompanyDictDO companyDictDO = companyDictMapper.selectById(positionRequireItemDO1.getCompanyId());
        oneRequirementVO.setCompanyName(companyDictDO.getCompanyName());

        //预招人数
        List<PositionCountsVO> positionItemInfoDOS = positionItemInfoMapper.positionCounts(positionRequireItemDO.getId());
        oneRequirementVO.setPositionItemInfoDOS(positionItemInfoDOS);

        //职位分类
        List<LibJobSortDO> libJobSortDOS = positionItemJobMappingMapper.positionSorts(positionRequireItemDO.getId());
        oneRequirementVO.setLibJobSortDOS(libJobSortDOS);

        //关联业务
        List<RequireWorkstationsVO> requireWorkstationsVOS = workstationRequireMappingMapper.requireWorkstations(positionRequireItemDO.getId());
        oneRequirementVO.setRequireWorkstationsVOS(requireWorkstationsVOS);

        //更新日志
        List<RequireHistoryVO> requireHistoryVOS = positionRequireHistoryMapper.requireHistory(positionRequireItemDO.getId());
        oneRequirementVO.setRequireHistoryVOS(requireHistoryVOS);

        return oneRequirementVO;
    }

}