package com.ruoyi.tool.service.impl; import java.util.List; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.bean.BeanValidators; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.tool.mapper.TPostMapper; import com.ruoyi.tool.domain.TPost; import com.ruoyi.tool.service.ITPostService; /** * 职位信息Service业务层处理 * * @author ruoyi * @date 2024-06-13 */ @Service @Slf4j public class TPostServiceImpl implements ITPostService { @Autowired private TPostMapper tPostMapper; /** * 查询职位信息 * * @param postId 职位信息主键 * @return 职位信息 */ @Override public TPost selectTPostByPostId(Long postId) { return tPostMapper.selectTPostByPostId(postId); } /** * 查询职位信息列表 * * @param tPost 职位信息 * @return 职位信息 */ @Override public List selectTPostList(TPost tPost) { return tPostMapper.selectTPostList(tPost); } /** * 新增职位信息 * * @param tPost 职位信息 * @return 结果 */ @Override public int insertTPost(TPost tPost) { tPost.setCreateTime(DateUtils.getNowDate()); return tPostMapper.insertTPost(tPost); } /** * 修改职位信息 * * @param tPost 职位信息 * @return 结果 */ @Override public int updateTPost(TPost tPost) { tPost.setUpdateTime(DateUtils.getNowDate()); return tPostMapper.updateTPost(tPost); } /** * 批量删除职位信息 * * @param postIds 需要删除的职位信息主键 * @return 结果 */ @Override public int deleteTPostByPostIds(Long[] postIds) { return tPostMapper.deleteTPostByPostIds(postIds); } /** * 删除职位信息信息 * * @param postId 职位信息主键 * @return 结果 */ @Override public int deleteTPostByPostId(Long postId) { return tPostMapper.deleteTPostByPostId(postId); } @Override public String importPost(List postList, String operName) { if (StringUtils.isNull(postList) || postList.size() == 0) { throw new ServiceException("导入职位数据数据不能为空!"); } int successNum = 0; int failureNum = 0; StringBuilder successMsg = new StringBuilder(); StringBuilder failureMsg = new StringBuilder(); for (TPost post : postList) { try { tPostMapper.insertTPost(post); successMsg.append("
" + successNum + "、职位 " + post.getPostName() + " 导入成功"); } catch (Exception e) { failureNum++; String msg = "
" + failureNum + "、职位 " + post.getPostName() + " 导入失败:"; failureMsg.append(msg + e.getMessage()); log.error(msg, e); } } if (failureNum > 0) { failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); throw new ServiceException(failureMsg.toString()); } else { successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); } return successMsg.toString(); } }