|
@@ -0,0 +1,119 @@
|
|
|
|
|
+package com.its.op.service.database;
|
|
|
|
|
+
|
|
|
|
|
+import com.its.op.model.dto.GropMenuAthrDto;
|
|
|
|
|
+import com.its.op.model.entity.GropMenuAthr;
|
|
|
|
|
+import com.its.op.model.entity.GropMenuAthrKey;
|
|
|
|
|
+import com.its.op.model.entity.OperSystMenu;
|
|
|
|
|
+import com.its.op.model.entity.UserGropInfr;
|
|
|
|
|
+import com.its.op.repository.GropMenuAthrRepository;
|
|
|
|
|
+import com.its.op.repository.OperSystMenuRepository;
|
|
|
|
|
+import com.its.op.repository.UserGropInfrRepository;
|
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Optional;
|
|
|
|
|
+
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
|
+@Service
|
|
|
|
|
+public class TbGropMenuAthrService {
|
|
|
|
|
+
|
|
|
|
|
+ private final GropMenuAthrRepository menuAuthRepo;
|
|
|
|
|
+ private final UserGropInfrRepository userGropRepo;
|
|
|
|
|
+ private final OperSystMenuRepository systMenuRepo;
|
|
|
|
|
+
|
|
|
|
|
+ public List<GropMenuAthrDto.GropMenuAthrInfo> findAll() {
|
|
|
|
|
+ List<GropMenuAthrDto.GropMenuAthrInfo> result = new ArrayList<>();
|
|
|
|
|
+ try {
|
|
|
|
|
+ List<UserGropInfr> userGrops = this.userGropRepo.findAll();
|
|
|
|
|
+ List<OperSystMenu> systMenus = this.systMenuRepo.findAll();
|
|
|
|
|
+ List<GropMenuAthr> menuAuths = this.menuAuthRepo.findAll();
|
|
|
|
|
+ HashMap<String, GropMenuAthr> authMap = new HashMap<>();
|
|
|
|
|
+ for (GropMenuAthr menuAthr : menuAuths) {
|
|
|
|
|
+ authMap.put(menuAthr.getGROP_ID() + "*" + menuAthr.getOPERSYST_MENU_ID(), menuAthr);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (UserGropInfr userGrop : userGrops) {
|
|
|
|
|
+ if (userGrop.getDEL_YN().equals("N")) {
|
|
|
|
|
+ for (OperSystMenu systMenu : systMenus) {
|
|
|
|
|
+ if (systMenu.getDEL_YN().equals("N")) {
|
|
|
|
|
+ GropMenuAthrDto.GropMenuAthrInfo menuAthr = new GropMenuAthrDto.GropMenuAthrInfo(userGrop, systMenu);
|
|
|
|
|
+ GropMenuAthr auth = authMap.get(userGrop.getGROP_ID() + "*" + systMenu.getOPERSYST_MENU_ID());
|
|
|
|
|
+ if (auth != null) {
|
|
|
|
|
+ menuAthr.updateMenuAuth(auth);
|
|
|
|
|
+ }
|
|
|
|
|
+ result.add(menuAthr);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception e) {
|
|
|
|
|
+ log.error("{}.findAll: Exception: {}", getClass().getSimpleName(), e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<GropMenuAthrDto.GropMenuAthrInfo> findById(String id) {
|
|
|
|
|
+ List<GropMenuAthrDto.GropMenuAthrInfo> result = new ArrayList<>();
|
|
|
|
|
+ try {
|
|
|
|
|
+ Optional<UserGropInfr> userGrops = this.userGropRepo.findById(id);
|
|
|
|
|
+ List<OperSystMenu> systMenus = this.systMenuRepo.findAll();
|
|
|
|
|
+ List<GropMenuAthr> menuAuths = this.menuAuthRepo.findAll();
|
|
|
|
|
+ HashMap<String, GropMenuAthr> authMap = new HashMap<>();
|
|
|
|
|
+ for (GropMenuAthr menuAthr : menuAuths) {
|
|
|
|
|
+ authMap.put(menuAthr.getGROP_ID() + "*" + menuAthr.getOPERSYST_MENU_ID(), menuAthr);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (userGrops.isPresent()) {
|
|
|
|
|
+ UserGropInfr userGrop = userGrops.get();
|
|
|
|
|
+ if (userGrop.getDEL_YN().equals("N")) {
|
|
|
|
|
+ for (OperSystMenu systMenu : systMenus) {
|
|
|
|
|
+ if (systMenu.getDEL_YN().equals("N")) {
|
|
|
|
|
+ GropMenuAthrDto.GropMenuAthrInfo menuAthr = new GropMenuAthrDto.GropMenuAthrInfo(userGrop, systMenu);
|
|
|
|
|
+ GropMenuAthr auth = authMap.get(userGrop.getGROP_ID() + "*" + systMenu.getOPERSYST_MENU_ID());
|
|
|
|
|
+ if (auth != null) {
|
|
|
|
|
+ menuAthr.updateMenuAuth(auth);
|
|
|
|
|
+ }
|
|
|
|
|
+ result.add(menuAthr);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception e) {
|
|
|
|
|
+ log.error("{}.findById: Exception: {}", getClass().getSimpleName(), e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<GropMenuAthr> mergeInfo(List<GropMenuAthrDto.GropMenuAthrUpdateReq> reqList) {
|
|
|
|
|
+ List<GropMenuAthr> result = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ for (GropMenuAthrDto.GropMenuAthrUpdateReq req: reqList) {
|
|
|
|
|
+ GropMenuAthrKey key = new GropMenuAthrKey(req.getGROP_ID(), req.getOPERSYST_MENU_ID());
|
|
|
|
|
+ Optional<GropMenuAthr> data = this.menuAuthRepo.findById(key);
|
|
|
|
|
+ GropMenuAthr obj;
|
|
|
|
|
+ if (data.isPresent()) {
|
|
|
|
|
+ obj = data.get();
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ obj = new GropMenuAthr(req.getGROP_ID(), req.getOPERSYST_MENU_ID());
|
|
|
|
|
+ }
|
|
|
|
|
+ obj.updateInfo(req);
|
|
|
|
|
+ this.menuAuthRepo.save(obj);
|
|
|
|
|
+ result.add(obj);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception e) {
|
|
|
|
|
+ log.error("{}.mergeInfo: Object: {}, Exception: {}", getClass().getSimpleName(), reqList, e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|