src/main/java/kr/wisestone/owl/domain/Department.java
File was renamed from src/main/java/kr/wisestone/owl/domain/DepartmentManage.java @@ -7,7 +7,7 @@ import java.io.Serializable; @Entity public class DepartmentManage extends BaseEntity implements Serializable { public class Department extends BaseEntity implements Serializable { private static final long serialVersionUID = 1L; @@ -17,7 +17,7 @@ private String departmentName; private String departmentDescription; public DepartmentManage() { public Department() { } public Long getId() { src/main/java/kr/wisestone/owl/domain/User.java
@@ -29,7 +29,6 @@ private String phone; private String profile; private String awsKey; // private Long departmentId; @Enumerated(EnumType.STRING) private SocialType socialType; private Long lastWorkspaceId; @@ -64,11 +63,6 @@ @JoinColumn(name="level_id") private UserLevel userLevel; @ManyToOne(targetEntity = DepartmentManage.class, fetch = FetchType.LAZY) @JoinColumn(name="department_id") private DepartmentManage departmentManage; public User() { } @@ -76,14 +70,6 @@ this.id = id; this.name = name; this.account = account; } public DepartmentManage getDepartmentManage() { return departmentManage; } public void setDepartmentManage(DepartmentManage departmentManage) { this.departmentManage = departmentManage; } public UserLevel getUserLevel() { src/main/java/kr/wisestone/owl/domain/UserDepartment.java
New file @@ -0,0 +1,33 @@ package kr.wisestone.owl.domain; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import java.io.Serializable; public class UserDepartment extends BaseEntity implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String departmentId; public UserDepartment(){} public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getDepartmentId() { return departmentId; } public void setDepartmentId(String departmentId) { this.departmentId = departmentId; } } src/main/java/kr/wisestone/owl/mapper/DepartmentManageMapper.java
File was deleted src/main/java/kr/wisestone/owl/mapper/DepartmentMapper.java
New file @@ -0,0 +1,21 @@ package kr.wisestone.owl.mapper; import kr.wisestone.owl.web.condition.DepartmentCondition; import org.springframework.stereotype.Repository; import java.util.List; import java.util.Map; /** * Created by wisestone on 2018-02-26. */ @Repository public interface DepartmentMapper { List<Map<String, Object>> find(DepartmentCondition departmentCondition); Long count(DepartmentCondition departmentCondition); List<Map<String, Object>> findEvent(); Long findBydepartmentId(Long Id); } src/main/java/kr/wisestone/owl/repository/DepartmentManageRepository.java
File was deleted src/main/java/kr/wisestone/owl/repository/DepartmentRepository.java
New file @@ -0,0 +1,8 @@ package kr.wisestone.owl.repository; import kr.wisestone.owl.domain.Department; import org.springframework.data.jpa.repository.JpaRepository; public interface DepartmentRepository extends JpaRepository<Department, Long> { } src/main/java/kr/wisestone/owl/service/DepartmentManageService.java
File was deleted src/main/java/kr/wisestone/owl/service/DepartmentService.java
New file @@ -0,0 +1,32 @@ package kr.wisestone.owl.service; import kr.wisestone.owl.domain.Department; import kr.wisestone.owl.vo.DepartmentVo; import kr.wisestone.owl.web.condition.DepartmentCondition; import kr.wisestone.owl.web.form.DepartmentForm; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.ui.Model; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import java.util.List; import java.util.Map; public interface DepartmentService extends AbstractService<Department, Long, JpaRepository<Department, Long>> { Department add(DepartmentForm departmentForm); List<DepartmentVo> find(Map<String, Object> resJsonData, DepartmentCondition make, Pageable pageable); Department getDepartment(Long id); void modify(DepartmentForm departmentForm); void remove(DepartmentForm departmentForm); void detail(Map<String, Object> resJsonData, DepartmentCondition make); ModelAndView downloadExcel(HttpServletRequest request, Model model); boolean department(Long id); } src/main/java/kr/wisestone/owl/service/impl/DepartmentManageServiceImpl.java
File was deleted src/main/java/kr/wisestone/owl/service/impl/DepartmentServiceImpl.java
New file @@ -0,0 +1,196 @@ package kr.wisestone.owl.service.impl; import kr.wisestone.owl.domain.Department; import kr.wisestone.owl.mapper.DepartmentMapper; import kr.wisestone.owl.service.UserService; import kr.wisestone.owl.web.condition.DepartmentCondition; import kr.wisestone.owl.web.form.DepartmentForm; import org.springframework.ui.Model; import com.google.common.collect.Lists; import kr.wisestone.owl.common.ExcelConditionCheck; import kr.wisestone.owl.constant.Constants; import kr.wisestone.owl.constant.MsgConstants; import kr.wisestone.owl.exception.OwlRuntimeException; import kr.wisestone.owl.repository.DepartmentRepository; import kr.wisestone.owl.service.DepartmentService; import kr.wisestone.owl.service.WorkspaceService; import kr.wisestone.owl.util.ConvertUtil; import kr.wisestone.owl.vo.*; import kr.wisestone.owl.web.view.ExcelView; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Service; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import java.util.HashMap; import java.util.List; import java.util.Map; @Service public class DepartmentServiceImpl extends AbstractServiceImpl<Department, Long, JpaRepository<Department, Long>> implements DepartmentService { @Autowired private DepartmentRepository departmentRepository; @Autowired private DepartmentMapper departmentMapper; @Autowired private UserService userService; @Autowired private WorkspaceService workspaceService; @Autowired private ExcelView excelView; @Autowired private ExcelConditionCheck excelConditionCheck; @Override protected JpaRepository<Department, Long> getRepository() { return this.departmentRepository; } // 부서 추가 @Override public Department add(DepartmentForm departmentForm) { Department department = ConvertUtil.copyProperties(departmentForm, Department.class); departmentRepository.saveAndFlush(department); return department; } // 부서 목록을 가져온다. @Override public List<DepartmentVo>find(Map<String, Object> resJsonData, DepartmentCondition condition, Pageable pageable) { condition.setPage(pageable.getPageNumber() * pageable.getPageSize()); condition.setPageSize(pageable.getPageSize()); List<Map<String, Object>> results = this.departmentMapper.find(condition); Long totalDepartmentCount = this.departmentMapper.count(condition); return this.convertDepartmentVoToMap(results, totalDepartmentCount, pageable, resJsonData); } // 부서 상세 조회한다. @Override public void detail(Map<String, Object> resJsonData, DepartmentCondition departmentCondition) { DepartmentVo departmentVo = new DepartmentVo(); Long departmentId = departmentCondition.getId(); if (departmentId != null) { Department department = this.getDepartment(departmentId); departmentVo = ConvertUtil.copyProperties(department, DepartmentVo.class); } resJsonData.put(Constants.RES_KEY_CONTENTS, departmentVo); } // 부서 정보를 수정한다. @Override public void modify(DepartmentForm departmentForm) { Department department = ConvertUtil.copyProperties(departmentForm, Department.class); departmentRepository.saveAndFlush(department); } // 부서를 삭제한다. @Override public void remove(DepartmentForm departmentForm) { if (departmentForm.getRemoveIds().size() < 1) { throw new OwlRuntimeException( this.messageAccessor.getMessage(MsgConstants.DEPARTMENT_REMOVE_NOT_SELECT)); } for (Long id : departmentForm.getRemoveIds()) { if (!this.userService.useUserLevel(id)) { this.departmentRepository.deleteById(id); } else { throw new OwlRuntimeException( this.messageAccessor.getMessage(MsgConstants.DEPARTMENT_ALREADY_IN_USE)); } } this.departmentRepository.flush(); } // 부서 목록을 엑셀로 다운로드 한다. @Override public ModelAndView downloadExcel(HttpServletRequest request, Model model) { ModelAndView modelAndView = this.workspaceService.checkUseExcelDownload(model); if (modelAndView != null) { return modelAndView; } Map<String, Object> conditions = new HashMap<>(); // 엑셀 다운로드에 필요한 검색 조건 정보를 추출하고 검색 조건 추출에 오류가 발생하면 경고를 표시해준다. modelAndView = this.excelConditionCheck.checkCondition(conditions, request, model); if (modelAndView != null) { return modelAndView; } DepartmentCondition departmentCondition = DepartmentCondition.make(conditions); List<Map<String, Object>> results = this.departmentMapper.find(departmentCondition); List<DepartmentVo> departmentVos = ConvertUtil.convertListToListClass(results, DepartmentVo.class); // code_ko_KR 에 code명 설정 ExportExcelVo excelInfo = new ExportExcelVo(); excelInfo.setFileName(this.messageAccessor.message("부서 목록")); excelInfo.addAttrInfos(new ExportExcelAttrVo("departmentName", this.messageAccessor.message("departmentManage.departmentName"), 6, ExportExcelAttrVo.ALIGN_CENTER)); excelInfo.addAttrInfos(new ExportExcelAttrVo("departmentDescription", this.messageAccessor.message("departmentManage.departmentDescription"), 20, ExportExcelAttrVo.ALIGN_CENTER)); excelInfo.addAttrInfos(new ExportExcelAttrVo("departmentCount", this.messageAccessor.message("departmentManage.departmentCount"), 3, ExportExcelAttrVo.ALIGN_CENTER)); excelInfo.setDatas(departmentVos); model.addAttribute(Constants.EXCEL, excelInfo); return new ModelAndView(this.excelView); } // 사용자 부서 ID로 조회한다. @Override public Department getDepartment(Long id) { if (id == null) { throw new OwlRuntimeException( this.messageAccessor.getMessage(MsgConstants.DEPARTMENT_NOT_EXIST)); } Department department = this.findOne(id); if (department == null) { throw new OwlRuntimeException( this.messageAccessor.getMessage(MsgConstants.DEPARTMENT_NOT_EXIST)); } return department; } // 삭제 할 부서 유저가 사용하고 있는지 확인 @Override public boolean department(Long Id) { return this.departmentMapper.findBydepartmentId(Id) > 0; } // 검색 결과를 DepartmentVo 로 변환한다. private List<DepartmentVo> convertDepartmentVoToMap(List<Map<String, Object>> results, Long totalDepartmentsCount, Pageable pageable, Map<String, Object> resJsonData) { List<DepartmentVo> departmentVos = Lists.newArrayList(); for (Map<String, Object> result : results) { DepartmentVo departmentVo = ConvertUtil.convertMapToClass(result, DepartmentVo.class); departmentVos.add(departmentVo); } int totalPage = (int) Math.ceil((totalDepartmentsCount - 1) / pageable.getPageSize()) + 1; resJsonData.put(Constants.RES_KEY_CONTENTS, departmentVos); resJsonData.put(Constants.REQ_KEY_PAGE_VO, new ResPage(pageable.getPageNumber(), pageable.getPageSize(), totalPage, totalDepartmentsCount)); return departmentVos; } } src/main/java/kr/wisestone/owl/service/impl/UserServiceImpl.java
@@ -17,7 +17,6 @@ import kr.wisestone.owl.util.*; import kr.wisestone.owl.vo.*; import kr.wisestone.owl.web.condition.UserCondition; import kr.wisestone.owl.web.form.DepartmentManageForm; import kr.wisestone.owl.web.form.UserForm; import kr.wisestone.owl.web.view.ExcelView; import org.apache.commons.validator.routines.EmailValidator; @@ -59,7 +58,7 @@ private UserLevelService userLevelService; @Autowired private DepartmentManageService departmentManageService; private DepartmentService departmentService; @Autowired private SystemRoleService systemRoleService; @@ -259,12 +258,12 @@ /*user.setPermission(MngPermission.makeSubAllPermission());*/ } } // 초기에 모든 사용자는 부서 없음 DepartmentManageForm departmentManageForm = new DepartmentManageForm(); departmentManageForm.setDepartmentName("부서 없음"); DepartmentManage departmentManage = this.departmentManageService.addDepartmentManage(departmentManageForm); user.setDepartmentManage(departmentManage); // DepartmentManageForm departmentManageForm = new DepartmentManageForm(); // // departmentManageForm.setDepartmentName("부서 없음"); // DepartmentManage departmentManage = this.departmentManageService.addDepartmentManage(departmentManageForm); // user.setDepartmentManage(departmentManage); this.userRepository.saveAndFlush(user); src/main/java/kr/wisestone/owl/service/impl/UserWorkspaceServiceImpl.java
@@ -40,7 +40,7 @@ private UserLevelService userLevelService; @Autowired private DepartmentManageService departmentManageService; private DepartmentService departmentService; @Autowired private UserWorkspaceMapper userWorkspaceMapper; @@ -117,13 +117,13 @@ } // 부서 변경 DepartmentManage currentDepartment = user.getDepartmentManage(); if (currentDepartment == null || (userWorkspaceForm.getDepartmentId() != null && currentDepartment.getId() != userWorkspaceForm.getDepartmentId())) { // 부서명 변경시 DepartmentManage departmentManage = this.departmentManageService.getDepartment(userWorkspaceForm.getDepartmentId()); user.setDepartmentManage(departmentManage); userWorkspace.setUser(user); } // DepartmentManage currentDepartment = user.getDepartmentManage(); // if (currentDepartment == null || (userWorkspaceForm.getDepartmentId() != null && currentDepartment.getId() != userWorkspaceForm.getDepartmentId())) { // // 부서명 변경시 // DepartmentManage departmentManage = this.departmentService.getDepartment(userWorkspaceForm.getDepartmentId()); // user.setDepartmentManage(departmentManage); // userWorkspace.setUser(user); // } // 참여로 상태를 변경하려고 할때 if (userWorkspace.getUseYn() != userWorkspaceForm.getUseYn()) { src/main/java/kr/wisestone/owl/vo/DepartmentVo.java
File was renamed from src/main/java/kr/wisestone/owl/vo/DepartmentManageVo.java @@ -3,17 +3,16 @@ /** * Created by wyu on 2021-11-05. */ public class DepartmentManageVo extends BaseVo{ public class DepartmentVo extends BaseVo{ private Long id; private String departmentName; private String departmentDescription; private String defaultYn; private Long departmentCount; public DepartmentManageVo() {} public DepartmentVo() {} public DepartmentManageVo(Long id, String departmentName, String departmentDescription) { public DepartmentVo(Long id, String departmentName, String departmentDescription) { this.id = id; this.departmentName = departmentName; this.departmentDescription = departmentDescription; src/main/java/kr/wisestone/owl/web/condition/DepartmentCondition.java
File was renamed from src/main/java/kr/wisestone/owl/web/condition/DepartmentManageCondition.java @@ -7,7 +7,7 @@ /** * Created by wyu on 2021-11-05. */ public class DepartmentManageCondition { public class DepartmentCondition { private Long id; private String departmentName; private String departmentDescription; @@ -16,8 +16,8 @@ private Integer Page; private Integer PageSize; public static DepartmentManageCondition make(Map<String, Object> departmentManageConditions) { return ConvertUtil.convertMapToClass(departmentManageConditions, DepartmentManageCondition.class); public static DepartmentCondition make(Map<String, Object> departmentManageConditions) { return ConvertUtil.convertMapToClass(departmentManageConditions, DepartmentCondition.class); } public Long getId() { src/main/java/kr/wisestone/owl/web/controller/DepartmentController.java
File was renamed from src/main/java/kr/wisestone/owl/web/controller/DepartmentManageController.java @@ -1,9 +1,9 @@ package kr.wisestone.owl.web.controller; import kr.wisestone.owl.constant.Constants; import kr.wisestone.owl.service.DepartmentManageService; import kr.wisestone.owl.web.condition.DepartmentManageCondition; import kr.wisestone.owl.web.form.DepartmentManageForm; import kr.wisestone.owl.service.DepartmentService; import kr.wisestone.owl.web.condition.DepartmentCondition; import kr.wisestone.owl.web.form.DepartmentForm; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Pageable; import org.springframework.http.MediaType; @@ -23,77 +23,77 @@ * Created by jeong on 2017-08-02. */ @Controller public class DepartmentManageController extends BaseController { public class DepartmentController extends BaseController { @Autowired private DepartmentManageService departmentManageService; private DepartmentService departmentService; // 부서 생성 @RequestMapping(value = "/departmentManage/add", method = RequestMethod.POST) @RequestMapping(value = "/department/add", method = RequestMethod.POST) public @ResponseBody Map<String, Object> add(@RequestBody Map<String, Map<String, Object>> params) { Map<String, Object> resJsonData = new HashMap<>(); Map<String, Object> content = params.get(Constants.REQ_KEY_CONTENT); this.departmentManageService.addDepartmentManage(DepartmentManageForm.make(content)); this.departmentService.add(DepartmentForm.make(content)); return this.setSuccessMessage(resJsonData); } // 부서 조회 @RequestMapping(value = "/departmentManage/find", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/department/find", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody Map<String, Object> find(@RequestBody Map<String, Map<String, Object>> params) { Map<String, Object> resJsonData = new HashMap<>(); Pageable pageable = this.pageUtil.convertPageable(this.getPageVo(params)); this.departmentManageService.findDepartment(resJsonData, DepartmentManageCondition.make(params.get(Constants.REQ_KEY_CONTENT)), pageable); this.departmentService.find(resJsonData, DepartmentCondition.make(params.get(Constants.REQ_KEY_CONTENT)), pageable); return this.setSuccessMessage(resJsonData); } // 부서 상세 조회 @RequestMapping(value = "/departmentManage/detail", produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/department/detail", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody Map<String, Object> detail(@RequestBody Map<String, Map<String, Object>> params) { Map<String, Object> resJsonData = new HashMap<>(); this.departmentManageService.detailDepartment(resJsonData, DepartmentManageCondition.make(params.get(Constants.REQ_KEY_CONTENT))); this.departmentService.detail(resJsonData, DepartmentCondition.make(params.get(Constants.REQ_KEY_CONTENT))); return this.setSuccessMessage(resJsonData); } // 부서 수정 @RequestMapping(value = "/departmentManage/modify", produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/department/modify", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody Map<String, Object> modify(@RequestBody Map<String, Map<String, Object>> params) { Map<String, Object> resJsonData = new HashMap<>(); this.departmentManageService.modifyDepartment(DepartmentManageForm.make(params.get(Constants.REQ_KEY_CONTENT))); this.departmentService.modify(DepartmentForm.make(params.get(Constants.REQ_KEY_CONTENT))); return this.setSuccessMessage(resJsonData); } // 부서 삭제 @RequestMapping(value = "/departmentManage/remove", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/department/remove", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody Map<String, Object> remove(@RequestBody Map<String, Map<String, Object>> params) { Map<String, Object> resJsonData = new HashMap<>(); Map<String, Object> content = params.get(Constants.REQ_KEY_CONTENT); this.departmentManageService.removeDepartment(DepartmentManageForm.make(content)); this.departmentService.remove(DepartmentForm.make(content)); return this.setSuccessMessage(resJsonData); } // 부서 엑셀 다운로드 @RequestMapping(value = "/departmentManage/downloadExcel", method = RequestMethod.POST) @RequestMapping(value = "/department/downloadExcel", method = RequestMethod.POST) public ModelAndView downloadExcel(HttpServletRequest request, Model model) { return this.departmentManageService.downloadExcel(request, model); return this.departmentService.downloadExcel(request, model); } } src/main/java/kr/wisestone/owl/web/form/DepartmentForm.java
File was renamed from src/main/java/kr/wisestone/owl/web/form/DepartmentManageForm.java @@ -10,17 +10,17 @@ /** * Created by jeong on 2017-12-30. */ public class DepartmentManageForm { public class DepartmentForm { private Long id; private String departmentName; private String departmentDescription; private List<Long> removeIds = Lists.newArrayList(); public DepartmentManageForm() { public DepartmentForm() { } public static DepartmentManageForm make(Map<String, Object> params) { DepartmentManageForm form = ConvertUtil.convertMapToClass(params, DepartmentManageForm.class); public static DepartmentForm make(Map<String, Object> params) { DepartmentForm form = ConvertUtil.convertMapToClass(params, DepartmentForm.class); if (MapUtil.getLongs(params,"removeIds") != null) { form.setRemoveIds(MapUtil.getLongs(params, "removeIds")); src/main/resources/migration/V1_10__Alter_Table.sql
@@ -1,8 +1,7 @@ ALTER TABLE `user` DROP COLUMN `permission`; ALTER TABLE `user` ADD COLUMN `level_id` BIGINT(11) NULL; ALTER TABLE `user` ADD COLUMN `department_id` BIGINT(11) NULL; CREATE TABLE `department_manage`( CREATE TABLE `department`( `id` BIGINT(11) AUTO_INCREMENT, `department_name` VARCHAR(50) NULL, `department_description` VARCHAR(255) NULL, src/main/resources/migration/V1_11__Alter_Table.sql
@@ -30,7 +30,7 @@ CREATE TABLE `hosting_field`( `id` BIGINT(11) AUTO_INCREMENT, `code` varchar (50) NOT NULL, `code` VARCHAR(50) NOT NULL, `name` VARCHAR(50) NOT NULL, `manager` VARCHAR(50) NULL, `tel` VARCHAR (50) NULL, @@ -43,3 +43,12 @@ PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; CREATE TABLE `user_department`( `id` BIGINT(11) AUTO_INCREMENT, `department_id` VARCHAR(50) NOT NULL, `register_id` BIGINT(20) NOT NULL, `register_date` TIMESTAMP NULL, `modify_id` BIGINT(20) NOT NULL, `modify_date` TIMESTAMP NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; src/main/resources/mybatis/query-template/department-template.xml
New file @@ -0,0 +1,39 @@ <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="kr.wisestone.owl.mapper.DepartmentMapper"> <select id="find" resultType="java.util.HashMap" parameterType="kr.wisestone.owl.web.condition.DepartmentCondition"> SELECT d.id as id, d.department_name as departmentName, d.department_description as departmentDescription, (SELECT COUNT(u.id) FROM user u WHERE d.id = u.department_id) AS departmentCount FROM department d WHERE 1=1 <if test="departmentName != '' and departmentName != null"> AND d.department_name like CONCAT('%',#{departmentName},'%') </if> <if test="id != '' and id != null"> AND d.id like CONCAT('%',#{id},'%') </if> <if test="pageSize != '' and pageSize != null"> limit #{pageSize} offset #{page}; </if> </select> <select id="count" resultType="java.lang.Long" parameterType="kr.wisestone.owl.web.condition.DepartmentCondition"> SELECT count(d.id) FROM department d WHERE 1=1 <if test="departmentName != '' and departmentName != null"> AND d.department_name like CONCAT('%',#{departmentName},'%') </if> <if test="id != '' and id != null"> AND d.id like CONCAT('%',#{id},'%') </if> </select> </mapper> src/main/resources/mybatis/query-template/departmentManage-template.xml
File was deleted