package com.example.fms.service.impl; import com.example.fms.common.model.dto.SystemFileDTO; import com.example.fms.common.model.dto.SystemFileUpdateDTO; import com.example.fms.common.model.vo.PersonnelVO; import com.example.fms.common.model.vo.SystemFileVO; import com.example.fms.common.utils.CacheUtils; import com.example.fms.common.utils.SecurityUtils.LoginUtils; import com.example.fms.domain.SystemFile; import com.example.fms.exception.XiaoShiException; import com.example.fms.mapper.SystemFileMapper; import com.example.fms.service.ISystemFileService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import java.util.List; /** * 系统文件的Service层实现类 * * @Author xiexiang * @Date 2023/6/1 */ @Slf4j @Service @RequiredArgsConstructor public class SystemFileServiceImpl implements ISystemFileService { private final SystemFileMapper systemFileMapper; private final CacheUtils cacheUtils; private final LoginUtils loginUtils; /** * 新增系统文件(批量) * * @param systemFileDTOS */ @Override public void add(List systemFileDTOS){ //判断传入列表不为空 if(systemFileDTOS != null && systemFileDTOS.size() > 0){ SystemFile systemFile = new SystemFile(); //遍历传入列表 for(int i = 0; i < systemFileDTOS.size(); i++){ //取集合中的dto对象,并赋值给实体类 SystemFileDTO systemFileDTO = systemFileDTOS.get(i); BeanUtils.copyProperties(systemFileDTO, systemFile); //获取当前登陆人的信息 PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId()); //给实体类赋值登陆人id systemFile.setCreateId(personnelVO.getId()); //插入数据 int row = systemFileMapper.add(systemFile); //判断正确性 if(row != 1){ String mes = "新增系统文件第" + i + "条失败"; log.info("新增失败,{}", mes); throw new XiaoShiException(mes); } }log.info("新增系统文件成功"); } } /** * 更新系统文件(批量) * @param systemFiles */ @Override public void update(List systemFiles){ //判断传入对象不为空 if(systemFiles != null && systemFiles.size() > 0){ SystemFile systemFile = new SystemFile(); //遍历传入列表 for(int i = 0; i < systemFiles.size(); i++){ //取集合中的dto对象,并赋值给实体类 SystemFileUpdateDTO systemFileUpdateDTO = systemFiles.get(i); BeanUtils.copyProperties(systemFileUpdateDTO, systemFile); //数据入表 int row = systemFileMapper.update(systemFile); //判断正确性 if(row != 1){ String mes = "更新系统文件第" + i + "条失败"; log.info("更新失败,{}", mes); throw new XiaoShiException(mes); } }log.info("更新系统文件成功"); } } /** * 查询系统文件 * * @param id * @return */ @Override public SystemFileVO query(Integer id){ //id不为空且id不等于0 if(id != null && id != 0){ return systemFileMapper.query(id); } else { String mes = "传入id不可以为空"; throw new XiaoShiException(mes); } } /** * 删除 * * @param id */ @Override public void deleteById(Integer id){ if (id != null) { systemFileMapper.deleteById(id); } else { throw new XiaoShiException("需要删除的id不能为空"); } } /** * 批量删除 * * @param ids */ @Override public void deleteByIds(List ids) { if (ids != null) { systemFileMapper.deleteByIds(ids); } else { throw new XiaoShiException("需要删除的ids不能为空"); } } }