Przeglądaj źródła

update edits

tags/Baseline_30082024_BACKEND_UAT
MSI\derek 1 rok temu
rodzic
commit
1204e963c6
6 zmienionych plików z 80 dodań i 53 usunięć
  1. +11
    -1
      src/main/java/com/ffii/tsms/modules/data/service/SkillService.kt
  2. +6
    -2
      src/main/java/com/ffii/tsms/modules/user/service/GroupService.java
  3. +42
    -41
      src/main/java/com/ffii/tsms/modules/user/service/UserService.java
  4. +3
    -0
      src/main/java/com/ffii/tsms/modules/user/service/res/LoadUserRes.java
  5. +10
    -4
      src/main/java/com/ffii/tsms/modules/user/web/GroupController.java
  6. +8
    -5
      src/main/java/com/ffii/tsms/modules/user/web/UserController.java

+ 11
- 1
src/main/java/com/ffii/tsms/modules/data/service/SkillService.kt Wyświetl plik

@@ -24,10 +24,20 @@ open class SkillService(
return skill return skill
} }


open fun updateSkill(req: NewSkillRequest, skill: Skill): Skill {
skill.apply {
name = req.name
code = req.code
description = req.description
}
skillRepository.save(skill)
return skill
}

open fun saveOrUpdate(req: NewSkillRequest): Skill { open fun saveOrUpdate(req: NewSkillRequest): Skill {
val skill = if(req.id != null) find(req.id).get() else Skill() val skill = if(req.id != null) find(req.id).get() else Skill()
if (req.id != null) { if (req.id != null) {
// updateSkill(req, skill)
updateSkill(req, skill)
} else { } else {
saveSkill(req) saveSkill(req)
} }


+ 6
- 2
src/main/java/com/ffii/tsms/modules/user/service/GroupService.java Wyświetl plik

@@ -175,7 +175,7 @@ public class GroupService extends AbstractBaseEntityService<Group, Long, GroupRe




@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public List<Map<String, Object>> listGroupAuth(Map<String, Object> args) {
public List<Map<String, Object>> listAuth(Map<String, Object> args) {


StringBuilder sql = new StringBuilder("SELECT" StringBuilder sql = new StringBuilder("SELECT"
+ " a.id, " + " a.id, "
@@ -183,8 +183,12 @@ public class GroupService extends AbstractBaseEntityService<Group, Long, GroupRe
+ " a.authority," + " a.authority,"
+ " a.name," + " a.name,"
+ " a.description, "); + " a.description, ");
if (args.containsKey("groupId"))
if (args.containsKey("groupId")) {
sql.append(" EXISTS(SELECT 1 FROM group_authority ga WHERE a.id = ga.authId AND groupId = :groupId) AS v"); sql.append(" EXISTS(SELECT 1 FROM group_authority ga WHERE a.id = ga.authId AND groupId = :groupId) AS v");
}
else if (args.containsKey("userId")) {
sql.append(" EXISTS(SELECT 1 FROM user_authority ua WHERE a.id = ua.authId AND userId = :userId) AS v");
}
else else
sql.append(" 0 AS v"); sql.append(" 0 AS v");
sql.append(" FROM authority a" sql.append(" FROM authority a"


+ 42
- 41
src/main/java/com/ffii/tsms/modules/user/service/UserService.java Wyświetl plik

@@ -7,6 +7,7 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.Date; import java.util.Date;
import java.util.stream.Collectors;


import com.ffii.tsms.modules.common.service.AuditLogService; import com.ffii.tsms.modules.common.service.AuditLogService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -184,6 +185,25 @@ public class UserService extends AbstractBaseEntityService<User, Long, UserRepos
Map.of(Params.ID, id)); Map.of(Params.ID, id));
} }


@Transactional(rollbackFor = Exception.class)
public List<Map<String, Object>> listUserAuth(Map<String, Object> args) {

StringBuilder sql = new StringBuilder("SELECT"
+ " a.id, "
+ " a.module,"
+ " a.authority,"
+ " a.name,"
+ " a.description, ");
if (args.containsKey("userId"))
sql.append(" EXISTS(SELECT 1 FROM user_authority ua WHERE a.id = ua.authId AND userId = :userId) AS v");
else
sql.append(" 0 AS v");
sql.append(" FROM authority a"
+ " ORDER BY a.module, a.name");

return jdbcDao.queryForList(sql.toString(), args);
}

public List<Integer> listUserGroupId(long id) { public List<Integer> listUserGroupId(long id) {
return jdbcDao.queryForInts( return jdbcDao.queryForInts(
"SELECT" "SELECT"
@@ -201,47 +221,28 @@ public class UserService extends AbstractBaseEntityService<User, Long, UserRepos
} }
BeanUtils.copyProperties(req,instance); BeanUtils.copyProperties(req,instance);
instance = save(instance); instance = save(instance);
// long id = instance.getId();

// List<Map<String, Integer>> groupBatchInsertValues = req.getAddGroupIds().stream()
// .map(groupId -> Map.of("userId", (int) id, "groupId", groupId))
// .collect(Collectors.toList());
// List<Map<String, Integer>> groupBatchDeleteValues = req.getRemoveGroupIds().stream()
// .map(groupId -> Map.of("userId", (int) id, "groupId", groupId))
// .collect(Collectors.toList());

// if (!groupBatchInsertValues.isEmpty()) {
// jdbcDao.batchUpdate(
// "INSERT IGNORE INTO user_group (groupId,userId)"
// + " VALUES (:groupId, :userId)",
// groupBatchInsertValues);
// }
// if (!groupBatchDeleteValues.isEmpty()) {
// jdbcDao.batchUpdate(
// "DELETE FROM user_group"
// + " WHERE groupId = :groupId AND userId = :userId",
// groupBatchDeleteValues);
// }

// List<Map<String, Integer>> authBatchInsertValues = req.getAddAuthIds().stream()
// .map(authId -> Map.of("userId", (int)id, "authId", authId))
// .collect(Collectors.toList());
// List<Map<String, Integer>> authBatchDeleteValues = req.getRemoveAuthIds().stream()
// .map(authId -> Map.of("userId", (int)id, "authId", authId))
// .collect(Collectors.toList());
// if (!authBatchInsertValues.isEmpty()) {
// jdbcDao.batchUpdate(
// "INSERT IGNORE INTO user_authority (userId, authId)"
// + " VALUES (:userId, :authId)",
// authBatchInsertValues);
// }

// if (!authBatchDeleteValues.isEmpty()) {
// jdbcDao.batchUpdate(
// "DELETE FROM user_authority"
// + " WHERE userId = :userId AND authId = :authId",
// authBatchDeleteValues);
// }
long id = instance.getId();

List<Map<String, Integer>> authBatchInsertValues = req.getAddAuthIds().stream()
.map(authId -> Map.of("userId", (int)id, "authId", authId))
.collect(Collectors.toList());
List<Map<String, Integer>> authBatchDeleteValues = req.getRemoveAuthIds().stream()
.map(authId -> Map.of("userId", (int)id, "authId", authId))
.collect(Collectors.toList());
if (!authBatchInsertValues.isEmpty()) {
jdbcDao.batchUpdate(
"INSERT IGNORE INTO user_authority (userId, authId)"
+ " VALUES (:userId, :authId)",
authBatchInsertValues);
}

if (!authBatchDeleteValues.isEmpty()) {
jdbcDao.batchUpdate(
"DELETE FROM user_authority"
+ " WHERE userId = :userId ",
// + "AND authId = :authId",
authBatchDeleteValues);
}
return instance; return instance;
} }




+ 3
- 0
src/main/java/com/ffii/tsms/modules/user/service/res/LoadUserRes.java Wyświetl plik

@@ -1,6 +1,7 @@
package com.ffii.tsms.modules.user.service.res; package com.ffii.tsms.modules.user.service.res;


import java.util.List; import java.util.List;
import java.util.Map;


import com.ffii.tsms.modules.user.entity.User; import com.ffii.tsms.modules.user.entity.User;


@@ -16,6 +17,7 @@ public class LoadUserRes {
this.data = data; this.data = data;
this.authIds = authIds; this.authIds = authIds;
this.groupIds = groupIds; this.groupIds = groupIds;
// this.auths = auths;
} }


public User getData() { public User getData() {
@@ -42,4 +44,5 @@ public class LoadUserRes {
this.groupIds = groupIds; this.groupIds = groupIds;
} }



} }

+ 10
- 4
src/main/java/com/ffii/tsms/modules/user/web/GroupController.java Wyświetl plik

@@ -78,14 +78,20 @@ public class GroupController{
.build())); .build()));
} }


@GetMapping("/auth/combo/{id}")
public RecordsRes<Map<String, Object>> authComboJson(HttpServletRequest request, @PathVariable("id") int id) throws ServletRequestBindingException {
@GetMapping("/auth/{target}/{id}")
public RecordsRes<Map<String, Object>> authComboJson(HttpServletRequest request, @PathVariable("id") int id, @PathVariable("target") String target) throws ServletRequestBindingException {
System.out.println(request); System.out.println(request);
Map<String, Object> args = new HashMap<>(); Map<String, Object> args = new HashMap<>();
if (id != 0)
if (id != 0){
if (target.equals("group")){
args.put("groupId", id); args.put("groupId", id);
} else {
args.put("userId", id);


return new RecordsRes<>(groupService.listGroupAuth(args));
}
}

return new RecordsRes<>(groupService.listAuth(args));
} }


} }

+ 8
- 5
src/main/java/com/ffii/tsms/modules/user/web/UserController.java Wyświetl plik

@@ -1,6 +1,7 @@
package com.ffii.tsms.modules.user.web; package com.ffii.tsms.modules.user.web;


import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.Map;


import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@@ -73,11 +74,13 @@ public class UserController{
@PreAuthorize("hasAuthority('VIEW_USER')") @PreAuthorize("hasAuthority('VIEW_USER')")
public LoadUserRes load(@PathVariable long id) { public LoadUserRes load(@PathVariable long id) {
LoadUserRes test = new LoadUserRes( LoadUserRes test = new LoadUserRes(
userService.find(id).orElseThrow(NotFoundException::new),
userService.listUserAuthId(id),
userService.listUserGroupId(id));
logger.info("Test List user2");
logger.info(test);
userService.find(id).orElseThrow(NotFoundException::new),
userService.listUserAuthId(id),
userService.listUserGroupId(id)
// userService.listUserAuth(Map.of("userId", id))
);
logger.info("printing test LoadUserRes");
logger.info(test);
return test; return test;
} }




Ładowanie…
Anuluj
Zapisz