From 4fd246e32166938d7f86c7ab236ed554a2bc9fef Mon Sep 17 00:00:00 2001
From: wyu <kknd09321@nate.com>
Date: 월, 08 11월 2021 16:14:03 +0900
Subject: [PATCH] 업체 관리 백엔드 추가

---
 src/main/java/kr/wisestone/owl/service/impl/DepartmentManageServiceImpl.java |  118 +++++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 78 insertions(+), 40 deletions(-)

diff --git a/src/main/java/kr/wisestone/owl/service/impl/DepartmentManageServiceImpl.java b/src/main/java/kr/wisestone/owl/service/impl/DepartmentManageServiceImpl.java
index 5a51f55..ae93ef1 100644
--- a/src/main/java/kr/wisestone/owl/service/impl/DepartmentManageServiceImpl.java
+++ b/src/main/java/kr/wisestone/owl/service/impl/DepartmentManageServiceImpl.java
@@ -1,6 +1,6 @@
 package kr.wisestone.owl.service.impl;
 
-import kr.wisestone.owl.web.form.UserLevelForm;
+import kr.wisestone.owl.service.UserService;
 import org.springframework.ui.Model;
 import com.google.common.collect.Lists;
 import kr.wisestone.owl.common.ExcelConditionCheck;
@@ -38,6 +38,9 @@
     private DepartmentManageMapper departmentManageMapper;
 
     @Autowired
+    private UserService userService;
+
+    @Autowired
     private WorkspaceService workspaceService;
 
     @Autowired
@@ -61,9 +64,8 @@
 
     // 遺��꽌 紐⑸줉�쓣 媛��졇�삩�떎.
     @Override
-    public List<DepartmentManageVo> findDepartment(Map<String, Object> resJsonData,
+    public List<DepartmentManageVo>findDepartment(Map<String, Object> resJsonData,
                                                    DepartmentManageCondition condition, Pageable pageable) {
-
         condition.setPage(pageable.getPageNumber() * pageable.getPageSize());
         condition.setPageSize(pageable.getPageSize());
 
@@ -73,55 +75,47 @@
         return this.convertDepartmentManageVoToMap(results, totalDepartmentCount, pageable, resJsonData);
     }
 
-
-
-    // �궗�슜�옄 遺��꽌 ID濡� 議고쉶�븳�떎.
+    // 遺��꽌 �긽�꽭 議고쉶�븳�떎.
     @Override
-    public DepartmentManage getDepartment(Long id) {
-        if (id == null) {
-            throw new OwlRuntimeException(
-                    this.messageAccessor.getMessage(MsgConstants.USER_LEVEL_NOT_EXIST));
+    public void detailDepartment(Map<String, Object> resJsonData, DepartmentManageCondition departmentManageCondition) {
+        DepartmentManageVo departmentManageVo = new DepartmentManageVo();
+
+        Long departmentId = departmentManageCondition.getId();
+        if (departmentId != null) {
+            DepartmentManage departmentManage = this.getDepartment(departmentId);
+            departmentManageVo = ConvertUtil.copyProperties(departmentManage, DepartmentManageVo.class);
         }
+        resJsonData.put(Constants.RES_KEY_CONTENTS, departmentManageVo);
+    }
 
-        DepartmentManage departmentManage = this.findOne(id);
-
-        if (departmentManage == null) {
-            throw new OwlRuntimeException(
-                    this.messageAccessor.getMessage(MsgConstants.USER_LEVEL_NOT_EXIST));
-        }
-
-        return departmentManage;
+    // 遺��꽌 �젙蹂대�� �닔�젙�븳�떎.
+    @Override
+    public void modifyDepartment(DepartmentManageForm departmentManageForm) {
+        DepartmentManage departmentManage = ConvertUtil.copyProperties(departmentManageForm, DepartmentManage.class);
+        departmentManageRepository.saveAndFlush(departmentManage);
     }
 
     // 遺��꽌瑜� �궘�젣�븳�떎.
     @Override
-    public void removeUserLevel(DepartmentManageForm departmentManageForm) {
+    public void removeDepartment(DepartmentManageForm departmentManageForm) {
         if (departmentManageForm.getRemoveIds().size() < 1) {
             throw new OwlRuntimeException(
-                    this.messageAccessor.getMessage(MsgConstants.PROJECT_REMOVE_NOT_SELECT));
+                    this.messageAccessor.getMessage(MsgConstants.DEPARTMENT_REMOVE_NOT_SELECT));
+        }
+
+        for (Long id : departmentManageForm.getRemoveIds()) {
+            if (!this.userService.useUserLevel(id)) {
+                this.departmentManageRepository.deleteById(id);
+            } else {
+                throw new OwlRuntimeException(
+                        this.messageAccessor.getMessage(MsgConstants.DEPARTMENT_ALREADY_IN_USE));
+            }
+
         }
         this.departmentManageRepository.flush();
     }
 
-
-    //  寃��깋 寃곌낵瑜� DepartmentManageVo 濡� 蹂��솚�븳�떎.
-    private List<DepartmentManageVo> convertDepartmentManageVoToMap(List<Map<String, Object>> results, Long totalDepartmentsCount, Pageable pageable, Map<String, Object> resJsonData) {
-        List<DepartmentManageVo> departmentManageVos = Lists.newArrayList();
-
-        for (Map<String, Object> result : results) {
-            DepartmentManageVo departmentManageVo = ConvertUtil.convertMapToClass(result, DepartmentManageVo.class);
-            departmentManageVos.add(departmentManageVo);
-        }
-
-        int totalPage = (int) Math.ceil((totalDepartmentsCount - 1) / pageable.getPageSize()) + 1;
-
-        resJsonData.put(Constants.RES_KEY_CONTENTS, departmentManageVos);
-        resJsonData.put(Constants.REQ_KEY_PAGE_VO, new ResPage(pageable.getPageNumber(), pageable.getPageSize(),
-                totalPage, totalDepartmentsCount));
-
-        return departmentManageVos;
-    }
-
+    // 遺��꽌 紐⑸줉�쓣 �뿊��濡� �떎�슫濡쒕뱶 �븳�떎.
     @Override
     public ModelAndView downloadExcel(HttpServletRequest request, Model model) {
 
@@ -142,17 +136,61 @@
 
         List<Map<String, Object>> results = this.departmentManageMapper.find(departmentManageCondition);
         List<DepartmentManageVo> departmentManageVos = ConvertUtil.convertListToListClass(results, DepartmentManageVo.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(departmentManageVos);
 
         model.addAttribute(Constants.EXCEL, excelInfo);
         return new ModelAndView(this.excelView);
+
     }
 
+    // �궗�슜�옄 遺��꽌 ID濡� 議고쉶�븳�떎.
+    @Override
+    public DepartmentManage getDepartment(Long id) {
+        if (id == null) {
+            throw new OwlRuntimeException(
+                    this.messageAccessor.getMessage(MsgConstants.DEPARTMENT_NOT_EXIST));
+        }
+
+        DepartmentManage departmentManage = this.findOne(id);
+
+        if (departmentManage == null) {
+            throw new OwlRuntimeException(
+                    this.messageAccessor.getMessage(MsgConstants.DEPARTMENT_NOT_EXIST));
+        }
+
+        return departmentManage;
+    }
+
+
+    //  �궘�젣 �븷 遺��꽌 �쑀��媛� �궗�슜�븯怨� �엳�뒗吏� �솗�씤
+    @Override
+    public boolean department(Long Id) {
+        return this.departmentManageMapper.findBydepartmentId(Id) > 0;
+    }
+
+
+    //  寃��깋 寃곌낵瑜� DepartmentManageVo 濡� 蹂��솚�븳�떎.
+    private List<DepartmentManageVo> convertDepartmentManageVoToMap(List<Map<String, Object>> results, Long totalDepartmentsCount, Pageable pageable, Map<String, Object> resJsonData) {
+        List<DepartmentManageVo> departmentManageVos = Lists.newArrayList();
+
+        for (Map<String, Object> result : results) {
+            DepartmentManageVo departmentManageVo = ConvertUtil.convertMapToClass(result, DepartmentManageVo.class);
+            departmentManageVos.add(departmentManageVo);
+        }
+
+        int totalPage = (int) Math.ceil((totalDepartmentsCount - 1) / pageable.getPageSize()) + 1;
+
+        resJsonData.put(Constants.RES_KEY_CONTENTS, departmentManageVos);
+        resJsonData.put(Constants.REQ_KEY_PAGE_VO, new ResPage(pageable.getPageNumber(), pageable.getPageSize(),
+                totalPage, totalDepartmentsCount));
+
+        return departmentManageVos;
+    }
 }

--
Gitblit v1.8.0