| @@ -4,7 +4,11 @@ import com.ffii.core.support.AbstractRepository; | |||
| import com.ffii.tsms.modules.data.entity.projections.DepartmentSearchInfo; | |||
| import java.util.List; | |||
| import java.util.Optional; | |||
| public interface DepartmentRepository extends AbstractRepository<Department, Long> { | |||
| List<DepartmentSearchInfo> findDepartmentSearchInfoBy(); | |||
| List<DepartmentSearchInfo> findDepartmentSearchInfoByAndDeletedFalse(); | |||
| Optional<DepartmentSearchInfo> findDepartmentSearchInfoById(Long departmentId); | |||
| } | |||
| @@ -6,7 +6,10 @@ import com.ffii.tsms.modules.data.entity.Department | |||
| import com.ffii.tsms.modules.data.entity.DepartmentRepository | |||
| import com.ffii.tsms.modules.data.entity.projections.DepartmentSearchInfo | |||
| import com.ffii.tsms.modules.data.web.models.NewDepartmentRequest | |||
| import com.ffii.tsms.modules.project.web.models.EditProjectDetails | |||
| import org.springframework.beans.BeanUtils | |||
| import org.springframework.stereotype.Service | |||
| import kotlin.jvm.optionals.getOrNull | |||
| @Service | |||
| open class DepartmentService( | |||
| @@ -14,20 +17,32 @@ open class DepartmentService( | |||
| private val jdbcDao: JdbcDao, | |||
| ) : AbstractBaseEntityService<Department, Long, DepartmentRepository>(jdbcDao, departmentRepository) { | |||
| open fun allDepartments(): List<DepartmentSearchInfo>{ | |||
| return departmentRepository.findDepartmentSearchInfoBy() | |||
| return departmentRepository.findDepartmentSearchInfoByAndDeletedFalse() | |||
| } | |||
| open fun saveDepartment(request: NewDepartmentRequest): Department { | |||
| val department = | |||
| Department().apply { | |||
| name = request.departmentName | |||
| code = request.departmentCode | |||
| description = request.description | |||
| } | |||
| var department = Department() | |||
| if (request.id != null && request.id > 0) { | |||
| department = departmentRepository.findById(request.id).orElseThrow() | |||
| BeanUtils.copyProperties(request, department) | |||
| }else{ | |||
| department.name = request.name | |||
| department.code = request.code | |||
| department.description = request.description | |||
| } | |||
| return departmentRepository.save(department) | |||
| } | |||
| open fun getDepartmentDetails(departmentId: Long): DepartmentSearchInfo? { | |||
| val department = departmentRepository.findDepartmentSearchInfoById(departmentId).orElseThrow() | |||
| return department | |||
| } | |||
| open fun combo(args: Map<String, Any>): List<Map<String, Any>> { | |||
| val sql = StringBuilder("select" | |||
| + " d.id as id," | |||
| @@ -12,6 +12,7 @@ import com.ffii.tsms.modules.data.entity.projections.DepartmentSearchInfo | |||
| import com.ffii.tsms.modules.data.entity.projections.PositionSearchInfo | |||
| import com.ffii.tsms.modules.data.web.models.NewDepartmentRequest | |||
| import com.ffii.tsms.modules.data.web.models.NewPositionRequest | |||
| import org.springframework.beans.BeanUtils | |||
| import org.springframework.stereotype.Service | |||
| @Service | |||
| open class PositionService( | |||
| @@ -27,12 +28,19 @@ open class PositionService( | |||
| } | |||
| open fun savePosition(request: NewPositionRequest): Position { | |||
| val position = | |||
| Position().apply { | |||
| name = request.positionName | |||
| code = request.positionCode | |||
| description = request.description | |||
| } | |||
| var position = Position() | |||
| if (request.id != null && request.id > 0 ){ | |||
| position = positionRepository.findById(request.id).orElseThrow() | |||
| BeanUtils.copyProperties(request, position) | |||
| }else{ | |||
| position.name = request.name | |||
| position.code = request.code | |||
| position.description = request.description | |||
| } | |||
| return positionRepository.save(position) | |||
| } | |||
| @@ -1,5 +1,6 @@ | |||
| package com.ffii.tsms.modules.data.web | |||
| import com.ffii.core.exception.NotFoundException | |||
| import com.ffii.core.response.RecordsRes | |||
| import com.ffii.core.utils.CriteriaArgsBuilder | |||
| import com.ffii.tsms.modules.data.entity.Department | |||
| @@ -7,9 +8,11 @@ import com.ffii.tsms.modules.data.entity.projections.DepartmentSearchInfo | |||
| import com.ffii.tsms.modules.data.service.DepartmentService | |||
| import com.ffii.tsms.modules.data.web.models.NewDepartmentRequest | |||
| import com.ffii.tsms.modules.project.entity.Project | |||
| import com.ffii.tsms.modules.project.web.models.EditProjectDetails | |||
| import com.ffii.tsms.modules.project.web.models.NewProjectRequest | |||
| import jakarta.servlet.http.HttpServletRequest | |||
| import jakarta.validation.Valid | |||
| import org.springframework.http.HttpStatus | |||
| import org.springframework.web.bind.ServletRequestBindingException | |||
| import org.springframework.web.bind.annotation.* | |||
| @@ -22,11 +25,22 @@ class DepartmentController(private val departmentService: DepartmentService | |||
| return departmentService.allDepartments() | |||
| } | |||
| @GetMapping("/departmentDetails/{id}") | |||
| fun departmentDetails(@PathVariable id: Long): DepartmentSearchInfo { | |||
| return departmentService.getDepartmentDetails(id) ?: throw NotFoundException() | |||
| } | |||
| @PostMapping("/new") | |||
| fun saveProject(@Valid @RequestBody newDepartment: NewDepartmentRequest): Department { | |||
| return departmentService.saveDepartment(newDepartment) | |||
| } | |||
| @DeleteMapping("/{id}") | |||
| @ResponseStatus(HttpStatus.NO_CONTENT) | |||
| fun deleteDepartment(@PathVariable id: Long) { | |||
| departmentService.markDelete(id) | |||
| } | |||
| @GetMapping("/combo") | |||
| @Throws(ServletRequestBindingException::class) | |||
| fun combo(request: HttpServletRequest?): RecordsRes<Map<String, Any>> { | |||
| @@ -14,6 +14,7 @@ import com.ffii.tsms.modules.project.entity.Project | |||
| import com.ffii.tsms.modules.project.web.models.NewProjectRequest | |||
| import jakarta.servlet.http.HttpServletRequest | |||
| import jakarta.validation.Valid | |||
| import org.springframework.http.HttpStatus | |||
| import org.springframework.web.bind.ServletRequestBindingException | |||
| import org.springframework.web.bind.annotation.* | |||
| @@ -36,6 +37,12 @@ class PositionController(private val positionService: PositionService | |||
| return positionService.savePosition(newPosition) | |||
| } | |||
| @DeleteMapping("/{id}") | |||
| @ResponseStatus(HttpStatus.NO_CONTENT) | |||
| fun deletePosition(@PathVariable id: Long) { | |||
| positionService.markDelete(id) | |||
| } | |||
| @GetMapping("/combo") | |||
| @Throws(ServletRequestBindingException::class) | |||
| fun combo(request: HttpServletRequest?): RecordsRes<Map<String, Any>> { | |||
| @@ -3,10 +3,11 @@ package com.ffii.tsms.modules.data.web.models | |||
| import jakarta.validation.constraints.NotBlank | |||
| data class NewDepartmentRequest ( | |||
| val id: Long?, | |||
| @field: NotBlank(message = "Department code cannot be empty") | |||
| val departmentCode: String, | |||
| val code: String, | |||
| @field:NotBlank(message = "Department name cannot be empty") | |||
| val departmentName: String, | |||
| val name: String, | |||
| val description: String | |||
| ) | |||
| @@ -4,12 +4,12 @@ import jakarta.validation.constraints.NotBlank | |||
| data class NewPositionRequest ( | |||
| val id: Long, | |||
| val id: Long?, | |||
| @field: NotBlank(message = "Position code cannot be empty") | |||
| val positionCode: String, | |||
| val code: String, | |||
| @field:NotBlank(message = "Position name cannot be empty") | |||
| val positionName: String, | |||
| val name: String, | |||
| val description: String | |||
| ) | |||
| @@ -27,8 +27,8 @@ public class UpdateUserReq { | |||
| @NotBlank | |||
| private String email; | |||
| @NotBlank | |||
| private String department; | |||
| // @NotBlank | |||
| // private String department; | |||
| // @NotNull | |||
| private List<Integer> addGroupIds; | |||
| @@ -140,12 +140,12 @@ public class UpdateUserReq { | |||
| this.email = email; | |||
| } | |||
| public String getDepartment() { | |||
| return department; | |||
| } | |||
| public void setDepartment(String department) { | |||
| this.department = department; | |||
| } | |||
| // public String getDepartment() { | |||
| // return department; | |||
| // } | |||
| // | |||
| // public void setDepartment(String department) { | |||
| // this.department = department; | |||
| // } | |||
| } | |||
| @@ -173,4 +173,23 @@ public class GroupService extends AbstractBaseEntityService<Group, Long, GroupRe | |||
| Map.of(Params.ID, id)); | |||
| } | |||
| @Transactional(rollbackFor = Exception.class) | |||
| public List<Map<String, Object>> listGroupAuth(Map<String, Object> args) { | |||
| StringBuilder sql = new StringBuilder("SELECT" | |||
| + " a.id, " | |||
| + " a.module," | |||
| + " a.authority," | |||
| + " a.name," | |||
| + " a.description, "); | |||
| if (args.containsKey("groupId")) | |||
| sql.append(" EXISTS(SELECT 1 FROM group_authority ga WHERE a.id = ga.authId AND groupId = :groupId) 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); | |||
| } | |||
| } | |||
| @@ -3,15 +3,12 @@ package com.ffii.tsms.modules.user.service; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.util.LinkedHashSet; | |||
| import java.util.List; | |||
| import java.util.Locale; | |||
| import java.util.Map; | |||
| import java.util.Optional; | |||
| import java.util.Set; | |||
| import java.util.Date; | |||
| import java.util.stream.Collectors; | |||
| import com.ffii.tsms.modules.common.service.AuditLogService; | |||
| import org.apache.commons.lang3.LocaleUtils; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.beans.BeanUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| @@ -41,8 +38,6 @@ import jakarta.persistence.Table; | |||
| import com.ffii.core.utils.JsonUtils; | |||
| import com.ffii.tsms.modules.common.SecurityUtils; | |||
| import jakarta.mail.internet.InternetAddress; | |||
| @Service | |||
| public class UserService extends AbstractBaseEntityService<User, Long, UserRepository> { | |||
| private static final String USER_AUTH_SQL = "SELECT a.authority" | |||
| @@ -91,9 +86,9 @@ public class UserService extends AbstractBaseEntityService<User, Long, UserRepos | |||
| return userRepository.findByUsernameAndDeletedFalse(username); | |||
| } | |||
| public Map<String, Object> softDelete(User user) { | |||
| public void softDelete(User user) { | |||
| // =====GET OLD AUDIT LOG=====// | |||
| // =====GET OLD AUDIT LOG=====// | |||
| String tableName = user.getClass().getAnnotation(Table.class).name(); | |||
| StringBuilder sql = new StringBuilder("SELECT * FROM " + tableName + " WHERE id = :id"); | |||
| String oldValueJson = null; | |||
| @@ -124,8 +119,6 @@ public class UserService extends AbstractBaseEntityService<User, Long, UserRepos | |||
| newValueJson); | |||
| // =====GET NEW AUDIT LOG=====// | |||
| return Map.of( | |||
| "id", user.getId()); | |||
| } | |||
| // @Transactional(rollbackFor = Exception.class) | |||
| @@ -148,7 +141,8 @@ public class UserService extends AbstractBaseEntityService<User, Long, UserRepos | |||
| + " u.email," | |||
| + " u.phone1," | |||
| + " u.phone2," | |||
| + " u.remarks " | |||
| + " u.remarks, " | |||
| + " ug.groupId " | |||
| + " FROM `user` u" | |||
| + " left join user_group ug on u.id = ug.userId" | |||
| + " where u.deleted = false"); | |||
| @@ -201,7 +195,7 @@ public class UserService extends AbstractBaseEntityService<User, Long, UserRepos | |||
| } | |||
| private User saveOrUpdate(User instance, UpdateUserReq req) { | |||
| if (instance.getId() == null){ | |||
| req.setLocked(false); | |||
| } | |||
| @@ -263,7 +257,7 @@ public class UserService extends AbstractBaseEntityService<User, Long, UserRepos | |||
| User instance = new User(); | |||
| instance.setPassword(pwdHash); | |||
| instance = saveOrUpdate(instance, req); | |||
| // Locale locale = instance.getLocale() != null ? LocaleUtils.from(instance.getLocale()) : Locale.ENGLISH; | |||
| // mailService.send( | |||
| // MailRequest.builder() | |||
| @@ -25,6 +25,8 @@ public class UserRecord { | |||
| private String phone2; | |||
| private String remarks; | |||
| private Long groupId; | |||
| public Integer getId() { | |||
| return id; | |||
| } | |||
| @@ -152,4 +154,10 @@ public class UserRecord { | |||
| this.remarks = remarks; | |||
| } | |||
| public Long getGroupId() { | |||
| return groupId; | |||
| } | |||
| public void setGroupId(Long groupId) { this.groupId = groupId; } | |||
| } | |||
| @@ -1,5 +1,6 @@ | |||
| package com.ffii.tsms.modules.user.web; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| import org.apache.commons.logging.Log; | |||
| @@ -77,4 +78,14 @@ public class GroupController{ | |||
| .build())); | |||
| } | |||
| @GetMapping("/auth/combo/{id}") | |||
| public RecordsRes<Map<String, Object>> authComboJson(HttpServletRequest request, @PathVariable("id") int id) throws ServletRequestBindingException { | |||
| System.out.println(request); | |||
| Map<String, Object> args = new HashMap<>(); | |||
| if (id != 0) | |||
| args.put("groupId", id); | |||
| return new RecordsRes<>(groupService.listGroupAuth(args)); | |||
| } | |||
| } | |||