SystemFileServiceImpl.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. systemFile.setCreateId(1);
  50. //插入数据
  51. int row = systemFileMapper.add(systemFile);
  52. //判断正确性
  53. if(row != 1){
  54. String mes = "新增系统文件第" + i + "条失败";
  55. log.info("新增失败,{}", mes);
  56. throw new XiaoShiException(mes);
  57. }
  58. }log.info("新增系统文件成功");
  59. }
  60. }
  61. /**
  62. * 更新系统文件(批量)
  63. * @param systemFiles
  64. */
  65. @Override
  66. public void update(List<SystemFileUpdateDTO> systemFiles){
  67. //判断传入对象不为空
  68. if(systemFiles != null && systemFiles.size() > 0){
  69. SystemFile systemFile = new SystemFile();
  70. //遍历传入列表
  71. for(int i = 0; i < systemFiles.size(); i++){
  72. //取集合中的dto对象,并赋值给实体类
  73. SystemFileUpdateDTO systemFileUpdateDTO = systemFiles.get(i);
  74. BeanUtils.copyProperties(systemFileUpdateDTO, systemFile);
  75. //数据入表
  76. int row = systemFileMapper.update(systemFile);
  77. //判断正确性
  78. if(row != 1){
  79. String mes = "更新系统文件第" + i + "条失败";
  80. log.info("更新失败,{}", mes);
  81. throw new XiaoShiException(mes);
  82. }
  83. }log.info("更新系统文件成功");
  84. }
  85. }
  86. /**
  87. * 查询系统文件
  88. *
  89. * @param id
  90. * @return
  91. */
  92. @Override
  93. public SystemFileVO query(Integer id){
  94. //id不为空且id不等于0
  95. if(id != null && id != 0){
  96. return systemFileMapper.query(id);
  97. } else {
  98. String mes = "传入id不可以为空";
  99. throw new XiaoShiException(mes);
  100. }
  101. }
  102. /**
  103. * 删除
  104. *
  105. * @param id
  106. */
  107. @Override
  108. public void deleteById(Integer id){
  109. if (id != null) {
  110. systemFileMapper.deleteById(id);
  111. } else {
  112. throw new XiaoShiException("需要删除的id不能为空");
  113. }
  114. }
  115. /**
  116. * 批量删除
  117. *
  118. * @param ids
  119. */
  120. @Override
  121. public void deleteByIds(List<Integer> ids) {
  122. if (ids != null) {
  123. systemFileMapper.deleteByIds(ids);
  124. } else {
  125. throw new XiaoShiException("需要删除的ids不能为空");
  126. }
  127. }
  128. }