|
@@ -0,0 +1,99 @@
|
|
|
+package com.fd.server.impl;
|
|
|
+
|
|
|
+import com.fd.constant.TypeCode;
|
|
|
+import com.fd.constant.UserCode;
|
|
|
+import com.fd.dto.PageDto;
|
|
|
+import com.fd.entity.FileEntity;
|
|
|
+import com.fd.entity.OutputFileEntity;
|
|
|
+import com.fd.entity.User;
|
|
|
+import com.fd.repository.FileRepository;
|
|
|
+import com.fd.repository.OutputFileRepository;
|
|
|
+import com.fd.repository.StyleRepository;
|
|
|
+import com.fd.repository.UserRepository;
|
|
|
+import com.fd.server.BaseServer;
|
|
|
+import com.fd.shiro.JWTUtil;
|
|
|
+import com.fd.util.R;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Optional;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by Owen on 2019/12/19 0019 10:17
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class BaseServerImpl implements BaseServer {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OutputFileRepository outputFileRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StyleRepository styleRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserRepository userRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FileRepository fileRepository;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<OutputFileEntity> findByList(String type, PageDto param, String token) {
|
|
|
+
|
|
|
+ String username = JWTUtil.getUsername(token);
|
|
|
+
|
|
|
+ // 根据用户名查找用户
|
|
|
+ User user = userRepository.findByUsername(username);
|
|
|
+
|
|
|
+ // 判断用户角色
|
|
|
+
|
|
|
+ Page<OutputFileEntity> page = null;
|
|
|
+
|
|
|
+ // 部门经理
|
|
|
+ if (UserCode.USER_ROLE_ROOT.equals(user.getRole())) {
|
|
|
+ page = outputFileRepository.findByTypeAndUserGroup(type, user.getUserGroup(), PageRequest.of(param.getPageNum(), param.getPageSize(), Sort.by("createTime").descending()));
|
|
|
+
|
|
|
+ //普通用户
|
|
|
+ } else if (UserCode.USER_ROLE_USER.equals(user.getRole())) {
|
|
|
+ page = outputFileRepository.findByTypeAndUserId(type, user.getId(), PageRequest.of(param.getPageNum(), param.getPageSize(), Sort.by("createTime").descending()));
|
|
|
+
|
|
|
+ // 管理员用户
|
|
|
+ } else {
|
|
|
+ page = outputFileRepository.findByTypeAndResStatus(type, 0, PageRequest.of(param.getPageNum(), param.getPageSize(), Sort.by("createTime").descending()));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public OutputFileEntity findById(Long fileId) {
|
|
|
+ Optional<OutputFileEntity> o = outputFileRepository.findById(fileId);
|
|
|
+ if (o.isPresent()) {
|
|
|
+ return o.get();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public FileEntity findByInputFileId(Long fileId) {
|
|
|
+ Optional<FileEntity> o = fileRepository.findById(fileId);
|
|
|
+ if (o.isPresent()) {
|
|
|
+ return o.get();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public FileEntity saveInputFile(FileEntity fileEntity) {
|
|
|
+ return fileRepository.save(fileEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R findByType(String type, PageDto pageDto) {
|
|
|
+ Page<OutputFileEntity> page = outputFileRepository.findByTypeAndResStatus(type, 0,PageRequest.of(pageDto.getPageNum(), pageDto.getPageSize(), Sort.by("createTime").descending()));
|
|
|
+ return new R(200, page);
|
|
|
+ }
|
|
|
+}
|