SystemFileServiceImpl.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package com.example.fms.service.impl;
  2. import com.example.fms.common.model.dto.SystemFileDTO;
  3. import com.example.fms.common.model.dto.SystemFileUpdateDTO;
  4. import com.example.fms.common.model.vo.PersonnelVO;
  5. import com.example.fms.common.model.vo.SystemFileVO;
  6. import com.example.fms.common.utils.CacheUtils;
  7. import com.example.fms.common.utils.SecurityUtils.LoginUtils;
  8. import com.example.fms.domain.SystemFile;
  9. import com.example.fms.exception.XiaoShiException;
  10. import com.example.fms.mapper.SystemFileMapper;
  11. import com.example.fms.service.ISystemFileService;
  12. import lombok.RequiredArgsConstructor;
  13. import lombok.extern.slf4j.Slf4j;
  14. import org.springframework.beans.BeanUtils;
  15. import org.springframework.stereotype.Service;
  16. import java.util.List;
  17. /**
  18. * 系统文件的Service层实现类
  19. *
  20. * @Author xiexiang
  21. * @Date 2023/6/1
  22. */
  23. @Slf4j
  24. @Service
  25. @RequiredArgsConstructor
  26. public class SystemFileServiceImpl implements ISystemFileService {
  27. private final SystemFileMapper systemFileMapper;
  28. private final CacheUtils cacheUtils;
  29. private final LoginUtils loginUtils;
  30. /**
  31. * 新增系统文件(批量)
  32. *
  33. * @param systemFileDTOS
  34. */
  35. @Override
  36. public void add(List<SystemFileDTO> systemFileDTOS){
  37. //判断传入列表不为空
  38. if(systemFileDTOS != null && systemFileDTOS.size() > 0){
  39. SystemFile systemFile = new SystemFile();
  40. //遍历传入列表
  41. for(int i = 0; i < systemFileDTOS.size(); i++){
  42. //取集合中的dto对象,并赋值给实体类
  43. SystemFileDTO systemFileDTO = systemFileDTOS.get(i);
  44. BeanUtils.copyProperties(systemFileDTO, systemFile);
  45. //获取当前登陆人的信息
  46. PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  47. //给实体类赋值登陆人id
  48. systemFile.setCreateId(personnelVO.getId());
  49. //插入数据
  50. int row = systemFileMapper.add(systemFile);
  51. //判断正确性
  52. if(row != 1){
  53. String mes = "新增系统文件第" + i + "条失败";
  54. log.info("新增失败,{}", mes);
  55. throw new XiaoShiException(mes);
  56. }
  57. }log.info("新增系统文件成功");
  58. }
  59. }
  60. /**
  61. * 更新系统文件(批量)
  62. * @param systemFiles
  63. */
  64. @Override
  65. public void update(List<SystemFileUpdateDTO> systemFiles){
  66. //判断传入对象不为空
  67. if(systemFiles != null && systemFiles.size() > 0){
  68. SystemFile systemFile = new SystemFile();
  69. //遍历传入列表
  70. for(int i = 0; i < systemFiles.size(); i++){
  71. //取集合中的dto对象,并赋值给实体类
  72. SystemFileUpdateDTO systemFileUpdateDTO = systemFiles.get(i);
  73. BeanUtils.copyProperties(systemFileUpdateDTO, systemFile);
  74. //数据入表
  75. int row = systemFileMapper.update(systemFile);
  76. //判断正确性
  77. if(row != 1){
  78. String mes = "更新系统文件第" + i + "条失败";
  79. log.info("更新失败,{}", mes);
  80. throw new XiaoShiException(mes);
  81. }
  82. }log.info("更新系统文件成功");
  83. }
  84. }
  85. /**
  86. * 查询系统文件
  87. *
  88. * @param id
  89. * @return
  90. */
  91. @Override
  92. public SystemFileVO query(Integer id){
  93. //id不为空且id不等于0
  94. if(id != null && id != 0){
  95. return systemFileMapper.query(id);
  96. } else {
  97. String mes = "传入id不可以为空";
  98. throw new XiaoShiException(mes);
  99. }
  100. }
  101. /**
  102. * 删除
  103. *
  104. * @param id
  105. */
  106. @Override
  107. public void deleteById(Integer id){
  108. if (id != null) {
  109. systemFileMapper.deleteById(id);
  110. } else {
  111. throw new XiaoShiException("需要删除的id不能为空");
  112. }
  113. }
  114. /**
  115. * 批量删除
  116. *
  117. * @param ids
  118. */
  119. @Override
  120. public void deleteByIds(List<Integer> ids) {
  121. if (ids != null) {
  122. systemFileMapper.deleteByIds(ids);
  123. } else {
  124. throw new XiaoShiException("需要删除的ids不能为空");
  125. }
  126. }
  127. }