| @@ -10,6 +10,7 @@ import com.ffii.core.support.AbstractBaseEntityService; | |||
| import com.ffii.core.support.JdbcDao; | |||
| import com.ffii.core.utils.BeanUtils; | |||
| import com.ffii.core.utils.Params; | |||
| import com.ffii.lioner.modules.common.SecurityUtils; | |||
| import com.ffii.lioner.modules.common.service.AuditLogService; | |||
| import com.ffii.lioner.modules.lioner.client.entity.Client; | |||
| import com.ffii.lioner.modules.lioner.client.entity.ClientRepository; | |||
| @@ -194,6 +195,9 @@ public class ClientService extends AbstractBaseEntityService<Client, Long, Clien | |||
| // } | |||
| public List<Map<String,Object>> list(Map<String, Object> args){ | |||
| long currentUserId = SecurityUtils.getUser().get().getId(); | |||
| args.put("currentUserId", currentUserId); | |||
| StringBuilder sql = new StringBuilder("SELECT" | |||
| + " (select fullname from user where id = client.createdBy) as createdByName, " | |||
| + " id, " | |||
| @@ -213,6 +217,11 @@ public class ClientService extends AbstractBaseEntityService<Client, Long, Clien | |||
| + " FROM client " | |||
| + " WHERE deleted = FALSE " | |||
| + " AND ( " | |||
| + " NOT EXISTS (SELECT 1 FROM user_consultant WHERE userId = :currentUserId) " | |||
| + " OR client.consultantId IN (SELECT consultantId FROM user_consultant WHERE userId = :currentUserId) " | |||
| + " ) " | |||
| ); | |||
| if (args != null) { | |||
| @@ -231,6 +240,9 @@ public class ClientService extends AbstractBaseEntityService<Client, Long, Clien | |||
| if (args.containsKey("remarks")) | |||
| sql.append(" AND remarks LIKE :remarks "); | |||
| } | |||
| if (args.containsKey("consultantId") && args.get("consultantId") != null) { | |||
| sql.append(" AND consultantId = :consultantId "); | |||
| } | |||
| return jdbcDao.queryForList(sql.toString(), args); | |||
| } | |||
| @@ -136,6 +136,7 @@ public class ClientController{ | |||
| .addStringLike("email") | |||
| .addStringLike("phone1") | |||
| .addStringLike("phone2") | |||
| .addLong("consultantId") | |||
| // .addDate("dobFrom") | |||
| // .addDate("dobTo") | |||
| .addStringLike("remarks") | |||
| @@ -1004,6 +1004,7 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito | |||
| setValueIfPresent(form2, "toggle_1", commonField.getEduPri()); | |||
| setValueIfPresent(form2, "toggle_2", commonField.getEduSec()); | |||
| setValueIfPresent(form2, "toggle_3", commonField.getEduPostSec()); | |||
| setValueIfPresent(form2, "Financial Protection", commonField.getFna_b1_a()); | |||
| setValueIfPresent(form2, "Preparation", commonField.getFna_b1_b()); | |||
| setValueIfPresent(form2, "Providing", commonField.getFna_b1_c()); | |||
| @@ -1930,7 +1931,7 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito | |||
| if("Yes".equals(commonField.getGenderMale())){ | |||
| setValueIfPresent(form2, "Check Box2", "Yes"); | |||
| }else if("Yes".equals(commonField.getGenderMale())){ | |||
| }else if("Yes".equals(commonField.getGenderFemale())){ | |||
| if("Yes".equals(commonField.getOthers().get("maritalStatusMarried"))){ | |||
| setValueIfPresent(form2, "Check Box3", "Yes"); | |||
| }else{ | |||
| @@ -2168,7 +2169,11 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito | |||
| setValueIfPresent(form2, "Checkbox_EudcationPri", commonField.getEduPri()); | |||
| setValueIfPresent(form2, "Checkbox_EudcationSec", commonField.getEduSec()); | |||
| setValueIfPresent(form2, "Checkbox_EudcationPostSec", commonField.getEduPostSec()); | |||
| setValueIfPresent(form2, "Checkbox_EudcationTer", commonField.getEduUni()); | |||
| if("Yes".equals(commonField.getEduUni())){ | |||
| setValueIfPresent(form2, "Checkbox_EudcationPostSec", "Off"); | |||
| setValueIfPresent(form2, "Checkbox_EudcationTer", commonField.getEduUni()); | |||
| } | |||
| /* Page3 End */ | |||
| @@ -3204,9 +3209,9 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito | |||
| case "fna_a_life_less_5" -> commonField.setFna_a_life_less_5(fieldValue); | |||
| case "fna_a_life_above_5" -> commonField.setFna_a_life_above_5(fieldValue); | |||
| case "fna_a_primary" -> commonField.setEduPri(fieldValue); | |||
| case "fna_a_secondary" -> commonField.setEduSec(fieldValue); | |||
| case "fna_a_tertiary" -> commonField.setEduPostSec(fieldValue); | |||
| //case "fna_a_primary" -> commonField.setEduPri(fieldValue); | |||
| //case "fna_a_secondary" -> commonField.setEduSec(fieldValue); | |||
| // case "fna_a_tertiary" -> commonField.setEduPostSec(fieldValue); | |||
| case "fna_a_marital" -> commonField.setMaritalStatus(fieldValue); | |||
| case "fna_a_contact" -> commonField.setContactNo(fieldValue); | |||
| @@ -3339,9 +3344,9 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito | |||
| case "fill_9" -> commonField.setOccupationTitle(fieldValue); | |||
| case "fill_10" -> commonField.setContactNo(fieldValue); | |||
| case "toggle_1" -> commonField.setEduPri(fieldValue); | |||
| case "toggle_2" -> commonField.setEduSec(fieldValue); | |||
| case "toggle_3" -> commonField.setEduPostSec(fieldValue); | |||
| // case "toggle_1" -> commonField.setEduPri(fieldValue); | |||
| //case "toggle_2" -> commonField.setEduSec(fieldValue); | |||
| // case "toggle_3" -> commonField.setEduPostSec(fieldValue); | |||
| case "fill_11" -> { | |||
| if(fieldValue != null){ | |||
| @@ -3499,10 +3504,10 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito | |||
| case "Checkbox_Wealth4" -> commonField.getOthers().put("sourceOther", fieldValue); | |||
| case "Field_Wealth4" -> commonField.getOthers().put("sourceOtherDesc", fieldValue); | |||
| case "Checkbox_EudcationPri" -> commonField.setEduPri(fieldValue); | |||
| case "Checkbox_EudcationSec" -> commonField.setEduSec(fieldValue); | |||
| case "Checkbox_EudcationPostSec" -> commonField.setEduPostSec(fieldValue); | |||
| case "Checkbox_EudcationTer" -> commonField.setEduUni(fieldValue); | |||
| //case "Checkbox_EudcationPri" -> commonField.setEduPri(fieldValue); | |||
| //case "Checkbox_EudcationSec" -> commonField.setEduSec(fieldValue); | |||
| //case "Checkbox_EudcationPostSec" -> commonField.setEduPostSec(fieldValue); | |||
| //case "Checkbox_EudcationTer" -> commonField.setEduUni(fieldValue); | |||
| /* Page3 End */ | |||
| /* Page7 Start */ | |||
| @@ -3808,10 +3813,10 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito | |||
| */ | |||
| case "ch2_5_1p" -> commonField.setEduPri(fieldValue); | |||
| case "ch2_5_1s" -> commonField.setEduSec(fieldValue); | |||
| case "ch2_5_1m" -> commonField.setEduPostSec(fieldValue); | |||
| case "ch2_5_1u" -> commonField.setEduUni(fieldValue); | |||
| //case "ch2_5_1p" -> commonField.setEduPri(fieldValue); | |||
| //case "ch2_5_1s" -> commonField.setEduSec(fieldValue); | |||
| //case "ch2_5_1m" -> commonField.setEduPostSec(fieldValue); | |||
| //case "ch2_5_1u" -> commonField.setEduUni(fieldValue); | |||
| case "ch2_5_2w" -> commonField.setFna_a_life_0(fieldValue); | |||
| case "ch2_5_2_less5" -> commonField.setFna_a_life_less_5(fieldValue); | |||
| @@ -20,6 +20,8 @@ public class NewLionerUserReq { | |||
| @NotNull | |||
| private Boolean twoFactorEnabled; | |||
| private List<Long> consultantIds; | |||
| @Size(max = 30) | |||
| @NotBlank | |||
| @Pattern(regexp = "^[A-Za-z0-9]+$") | |||
| @@ -251,5 +253,12 @@ public class NewLionerUserReq { | |||
| this.name = name; | |||
| } | |||
| public List<Long> getConsultantIds() { | |||
| return consultantIds; | |||
| } | |||
| public void setConsultantIds(List<Long> consultantIds) { | |||
| this.consultantIds = consultantIds; | |||
| } | |||
| } | |||
| @@ -17,6 +17,8 @@ public class UpdateUserReq { | |||
| @NotNull | |||
| private Boolean twoFactorEnabled; | |||
| private List<Long> consultantIds; | |||
| @Size(max = 90) | |||
| @NotBlank | |||
| private String name; | |||
| @@ -168,4 +170,11 @@ public class UpdateUserReq { | |||
| this.twoFactorEnabled = twoFactorEnabled; | |||
| } | |||
| public List<Long> getConsultantIds() { | |||
| return consultantIds; | |||
| } | |||
| public void setConsultantIds(List<Long> consultantIds) { | |||
| this.consultantIds = consultantIds; | |||
| } | |||
| } | |||
| @@ -370,6 +370,9 @@ public class UserService extends AbstractBaseEntityService<User, Long, UserRepos | |||
| } | |||
| BeanUtils.copyProperties(req, instance); | |||
| instance = saveAndFlush(instance); | |||
| logger.info("##### updating updateRecord " + req.getConsultantIds()); | |||
| updateConsultantAssignments(instance.getId(), req.getConsultantIds()); | |||
| return instance; | |||
| } | |||
| @@ -765,4 +768,34 @@ public class UserService extends AbstractBaseEntityService<User, Long, UserRepos | |||
| .orElseThrow(() -> new NotFoundException()); | |||
| } | |||
| @Transactional | |||
| public void updateConsultantAssignments(Long userId, List<Long> consultantIds) { | |||
| // 1. Remove old assignments | |||
| Map<String, Object> args = Map.of( | |||
| "userId", userId); | |||
| jdbcDao.executeUpdate("DELETE FROM user_consultant WHERE userId = :userId", args); | |||
| // 2. Add new assignments | |||
| if (consultantIds != null) { | |||
| for (Long cId : consultantIds) { | |||
| args = Map.of( | |||
| "userId", userId, | |||
| "cId", cId); | |||
| jdbcDao.executeUpdate("INSERT INTO user_consultant (userId, consultantId) VALUES (:userId, :cId)", | |||
| args); | |||
| } | |||
| } | |||
| } | |||
| public List<Long> listUserConsultantId(long userId) { | |||
| String sql = "SELECT consultantId FROM user_consultant WHERE userId = :userId"; | |||
| List<Map<String, Object>> rows = jdbcDao.queryForList(sql, Map.of("userId", userId)); | |||
| return rows.stream() | |||
| .map(row -> (Long) row.get("consultantId")) | |||
| .collect(Collectors.toList()); | |||
| } | |||
| } | |||
| @@ -9,15 +9,17 @@ public class LoadUserRes { | |||
| private Integer groupId; | |||
| private List<Integer> authIds; | |||
| private List<Integer> groupIds; | |||
| private List<Long> consultantIds; | |||
| public LoadUserRes() { | |||
| } | |||
| public LoadUserRes(User data, Integer groupId, List<Integer> authIds, List<Integer> groupIds) { | |||
| public LoadUserRes(User data, Integer groupId, List<Integer> authIds, List<Integer> groupIds, List<Long> consultantIds) { | |||
| this.data = data; | |||
| this.groupId = groupId; | |||
| this.authIds = authIds; | |||
| this.groupIds = groupIds; | |||
| this.consultantIds = consultantIds; | |||
| } | |||
| public User getData() { | |||
| @@ -52,4 +54,8 @@ public class LoadUserRes { | |||
| this.groupId = groupId; | |||
| } | |||
| public List<Long> getConsultantIds() { return consultantIds; } | |||
| public void setConsultantIds(List<Long> consultantIds) { this.consultantIds = consultantIds; } | |||
| } | |||
| @@ -107,7 +107,8 @@ public class UserController { | |||
| userService.find(id).orElseThrow(NotFoundException::new), | |||
| userService.getUserGroupId(id), | |||
| userService.listUserAuthId(id), | |||
| userService.listUserGroupId(id)); | |||
| userService.listUserGroupId(id), | |||
| userService.listUserConsultantId(id)); | |||
| return userRes; | |||
| } | |||
| @@ -0,0 +1,9 @@ | |||
| --liquibase formatted sql | |||
| --changeset vin:add user consultant | |||
| CREATE TABLE user_consultant ( | |||
| userId BIGINT NOT NULL, | |||
| consultantId BIGINT NOT NULL, | |||
| PRIMARY KEY (userId, consultantId) | |||
| ); | |||