diff options
| author | zhanghongqing <[email protected]> | 2022-08-09 16:54:16 +0800 |
|---|---|---|
| committer | zhanghongqing <[email protected]> | 2022-08-09 16:54:16 +0800 |
| commit | b3fa11d4b1b5a68d7b04fde5eb6cfbda557927eb (patch) | |
| tree | a49d344e49fc427fbf4cf00aa4963c4d04cd98a4 /src/main/java/com/mesasoft/cn/service/impl/AuthServiceImpl.java | |
| parent | d8a2be0d094ac9ba2d47c81ebf03b3fe6e34a078 (diff) | |
Diffstat (limited to 'src/main/java/com/mesasoft/cn/service/impl/AuthServiceImpl.java')
| -rw-r--r-- | src/main/java/com/mesasoft/cn/service/impl/AuthServiceImpl.java | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/main/java/com/mesasoft/cn/service/impl/AuthServiceImpl.java b/src/main/java/com/mesasoft/cn/service/impl/AuthServiceImpl.java new file mode 100644 index 0000000..d4d0e53 --- /dev/null +++ b/src/main/java/com/mesasoft/cn/service/impl/AuthServiceImpl.java @@ -0,0 +1,96 @@ +package com.mesasoft.cn.service.impl; + +import com.mesasoft.cn.dao.AuthDAO; +import com.mesasoft.cn.util.BeanUtils; +import com.mesasoft.cn.config.SettingConfig; +import com.mesasoft.cn.entity.Auth; +import com.mesasoft.cn.model.AuthRecord; +import com.mesasoft.cn.modules.constant.ConfigConsts; +import com.mesasoft.cn.service.IAuthService; +import com.mesasoft.cn.util.ServiceUtils; +import com.zhazhapan.modules.constant.ValueConsts; +import com.zhazhapan.util.Checker; +import com.zhazhapan.util.Formatter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author pantao + * @since 2018/2/1 + */ +@Service +public class AuthServiceImpl implements IAuthService { + + private final AuthDAO authDAO; + + @Autowired + public AuthServiceImpl(AuthDAO authDAO) {this.authDAO = authDAO;} + + @Override + public boolean addAuth(String files, String users, String auths) { + if (Checker.isNotEmpty(files) && Checker.isNotEmpty(users) && Checker.isNotEmpty(auths)) { + String[] file = files.split(ValueConsts.COMMA_SIGN); + String[] user = users.split(ValueConsts.COMMA_SIGN); + for (String f : file) { + long fileId = Formatter.stringToLong(f); + for (String u : user) { + int userId = Formatter.stringToInt(u); + if (Checker.isNull(authDAO.exists(userId, fileId))) { + Auth auth = new Auth(userId, fileId); + auth.setAuth(BeanUtils.getAuth(auths)); + authDAO.insertAuth(auth); + } + } + } + } + return true; + } + + @Override + public boolean batchDelete(String ids) { + return Checker.isNotEmpty(ids) && authDAO.batchDelete(ids); + } + + @Override + public boolean updateAuth(long id, String auths) { + int[] auth = BeanUtils.getAuth(auths); + return authDAO.updateAuthById(id, auth[0], auth[1], auth[2], auth[3], auth[4]); + } + + @Override + public List<AuthRecord> listAuth(String usernameOrEmail, String fileName, int offset) { + long fileId = ServiceUtils.getFileId(fileName); + int userId = ServiceUtils.getUserId(usernameOrEmail); + return authDAO.listAuthBy(ValueConsts.ZERO_INT, userId, fileId, fileName, offset); + } + + @Override + public AuthRecord getByFileIdAndUserId(long fileId, int userId) { + List<AuthRecord> authRecords = authDAO.listAuthBy(ValueConsts.ZERO_INT, userId, fileId, ValueConsts + .EMPTY_STRING, ValueConsts.ZERO_INT); + if (Checker.isNotEmpty(authRecords)) { + return authRecords.get(0); + } + return null; + } + + @Override + public boolean insertDefaultAuth(int userId, long fileId) { + int[] defaultAuth = SettingConfig.getAuth(ConfigConsts.AUTH_DEFAULT_OF_SETTING); + Auth auth = new Auth(userId, fileId); + auth.setAuth(defaultAuth[0], defaultAuth[1], defaultAuth[2], defaultAuth[3], defaultAuth[4]); + return insertAuth(auth); + } + + @Override + public boolean insertAuth(Auth auth) { + return authDAO.insertAuth(auth); + } + + @Override + public boolean removeByFileId(long fileId) { + return authDAO.removeAuthByFileId(fileId); + } +} |
