123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- 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<SystemFileDTO> 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());
- systemFile.setCreateId(1);
- //插入数据
- 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<SystemFileUpdateDTO> 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<Integer> ids) {
- if (ids != null) {
- systemFileMapper.deleteByIds(ids);
- } else {
- throw new XiaoShiException("需要删除的ids不能为空");
- }
- }
- }
|