package com.ruoyi.postCheck.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.ruoyi.common.constant.PostPlanEnum;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.postCheck.mapper.PostPlanInfoMapper;
import com.ruoyi.postCheck.domain.PostPlanInfo;
import com.ruoyi.postCheck.service.IPostPlanInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

/**
 * 岗检计划明细表Service业务层处理
 *
 * @author csg
 * @date 2023-12-19
 */
@Service
public class PostPlanInfoServiceImpl extends ServiceImpl<PostPlanInfoMapper, PostPlanInfo> implements IPostPlanInfoService {
    @Autowired
    private PostPlanInfoMapper postPlanInfoMapper;

    /**
     * 查询岗检计划明细表
     *
     * @param id 岗检计划明细表主键
     * @return 岗检计划明细表
     */
    @Override
    public PostPlanInfo selectPostPlanInfoById(Long id) {
        return postPlanInfoMapper.selectPostPlanInfoById(id);
    }

    /**
     * 查询岗检计划明细表列表
     *
     * @param postPlanInfo 岗检计划明细表
     * @return 岗检计划明细表
     */
    @Override
    public List<PostPlanInfo> selectPostPlanInfoList(PostPlanInfo postPlanInfo) {
        return postPlanInfoMapper.selectPostPlanInfoList(postPlanInfo);
    }

    /**
     * 新增岗检计划明细表：涉及部门和岗位是必选参数
     *
     * @param postPlanInfo 岗检计划明细表
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertPostPlanInfo(PostPlanInfo postPlanInfo) {

        //            checkedDeptId
//            checkedPostId
        if (postPlanInfo.getCheckedDeptId() == null || postPlanInfo.getCheckedPostId() == null) {
            throw new BaseException("涉及部门和涉及岗位的值为空，请重新选择！");
        }


        //TODO 自增主键修改为-MyBatis-Plus雪花算法(截取5位解决VUE精度丢失BUG)-系统登录日志
        if (postPlanInfo.getId() == null)
            postPlanInfo.setId(Long.parseLong(IdWorker.getIdStr().substring(4)));
        postPlanInfo.setCreateDefault();
        postPlanInfo.setStatus(PostPlanEnum.INFO_STATUS_NO.getValue());
        postPlanInfo.setCreateUserId(SecurityUtils.getUserId());

        return postPlanInfoMapper.insertPostPlanInfo(postPlanInfo);
    }

    /**
     * 修改岗检计划明细表
     *
     * @param postPlanInfo 岗检计划明细表
     * @return 结果
     */
    @Override
    public int updatePostPlanInfo(PostPlanInfo postPlanInfo) {
        postPlanInfo.setUpdateDefault();
//        postPlanInfo.setUpdateTime(DateUtils.getNowDate());
        return postPlanInfoMapper.updatePostPlanInfo(postPlanInfo);
    }

    /**
     * 批量删除岗检计划明细表
     *
     * @param ids 需要删除的岗检计划明细表主键
     * @return 结果
     */
    @Override
    public int deletePostPlanInfoByIds(Long[] ids) {
        return postPlanInfoMapper.deletePostPlanInfoByIds(ids);
    }

    /**
     * 删除岗检计划明细表信息
     *
     * @param id 岗检计划明细表主键
     * @return 结果
     */
    @Override
    public int deletePostPlanInfoById(Long id) {
        return postPlanInfoMapper.deletePostPlanInfoById(id);
    }
}
