From 96b9dbcd8a43cf8aff61ac9d56fcfc7171fc8e06 Mon Sep 17 00:00:00 2001 From: Suh Date: Fri, 12 Jan 2024 12:37:56 +0900 Subject: [PATCH] =?UTF-8?q?account=20read=20update=20=EA=B4=80=EB=A0=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../no1/wms/account/AccountController.java | 69 ++++++++- .../java/com/no1/wms/account/AccountDto.java | 2 + .../com/no1/wms/account/AccountMapper.java | 11 +- .../com/no1/wms/account/AccountService.java | 26 +++- .../no1/wms/account/DeptAndPositionDto.java | 17 --- src/main/resources/mappers/AccountMapper.xml | 62 +++++++- .../webapp/WEB-INF/views/account/create.jsp | 59 ++++++-- .../webapp/WEB-INF/views/account/list.jsp | 2 +- .../webapp/WEB-INF/views/account/read.jsp | 80 +++++++++++ .../webapp/WEB-INF/views/account/update.jsp | 136 ++++++++++++++++++ src/main/webapp/WEB-INF/views/modal/auth.jsp | 15 +- src/main/webapp/WEB-INF/views/modal/dept.jsp | 48 +++++++ src/main/webapp/WEB-INF/views/modal/pos.jsp | 47 ++++++ src/main/webapp/WEB-INF/views/test/kkk.jsp | 4 +- 14 files changed, 522 insertions(+), 56 deletions(-) delete mode 100644 src/main/java/com/no1/wms/account/DeptAndPositionDto.java create mode 100644 src/main/webapp/WEB-INF/views/account/read.jsp create mode 100644 src/main/webapp/WEB-INF/views/account/update.jsp create mode 100644 src/main/webapp/WEB-INF/views/modal/dept.jsp create mode 100644 src/main/webapp/WEB-INF/views/modal/pos.jsp diff --git a/src/main/java/com/no1/wms/account/AccountController.java b/src/main/java/com/no1/wms/account/AccountController.java index 196cb1c..7c413d0 100644 --- a/src/main/java/com/no1/wms/account/AccountController.java +++ b/src/main/java/com/no1/wms/account/AccountController.java @@ -1,15 +1,16 @@ package com.no1.wms.account; +import com.google.gson.Gson; +import com.no1.wms.authority.AuthorityDto; +import com.no1.wms.authority.AuthorityService; import com.no1.wms.utils.ConstantValues; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; import java.util.List; +import java.util.UUID; @Controller @RequestMapping("/account") @@ -17,6 +18,8 @@ public class AccountController { @Autowired AccountService accountService; + @Autowired + AuthorityService authorityService; @GetMapping("/list") public ModelAndView list(ModelAndView mav, @RequestParam(defaultValue = "") String search, @RequestParam(defaultValue = "0") int start){ @@ -34,11 +37,63 @@ public class AccountController { return mav; } - @PostMapping("/show_modal") - public ModelAndView showModal(ModelAndView mav, @RequestParam String name){ - //db에서 데이터 가져오는거 필요 + @PostMapping("/create_process") + @ResponseBody + public String createProcess(AccountDto dto, Gson gson){ + String uuid = UUID.randomUUID().toString(); + AuthorityDto authorityDto = new AuthorityDto(); + authorityDto.setId(dto.getGroupAuthorityId()); + authorityDto = authorityService.selectById(authorityDto); + authorityDto.setId(uuid); + authorityDto.setIsGroupAuthority(false); + authorityDto.setName(dto.getEmployeeNumber()); + accountService.insertToAuthority(authorityDto); + dto.setPersonalAuthorityId(uuid); + accountService.insert(dto); + + return gson.toJson("s"); + } + + @PostMapping("/read") + public ModelAndView read(AccountDto dto, ModelAndView mav){ + dto = accountService.selectById(dto); + mav.addObject("dto", dto); + mav.setViewName("/account/read"); + return mav; + } + + @PostMapping("/update") + public ModelAndView update(AccountDto dto, ModelAndView mav){ + dto = accountService.selectById(dto); + mav.addObject("dto", dto); + mav.setViewName("/account/update"); + return mav; + } + + @PostMapping("/update_process") + @ResponseBody + public String updateProcess(AccountDto dto, Gson gson){ + + accountService.update(dto); + + return gson.toJson("s"); + } + + @PostMapping("/show_modal") + public ModelAndView showModal(ModelAndView mav, @RequestParam(defaultValue = "") String search, + @RequestParam(defaultValue = "0") int start, @RequestParam String name){ + //db에서 데이터 가져오는거 필요 + List list = null; + if(name.equals("auth")){ + list = authorityService.selectAll(search, start, ConstantValues.PER_PAGE); + }else if(name.equals("dept")){ + list = accountService.selectDeptAll(search, start, ConstantValues.PER_PAGE); + }else if(name.equals("pos")){ + list = accountService.selectPosAll(search, start, ConstantValues.PER_PAGE); + } // + mav.addObject("list", list); mav.setViewName(name); return mav; } diff --git a/src/main/java/com/no1/wms/account/AccountDto.java b/src/main/java/com/no1/wms/account/AccountDto.java index 33ef0aa..cfa3859 100644 --- a/src/main/java/com/no1/wms/account/AccountDto.java +++ b/src/main/java/com/no1/wms/account/AccountDto.java @@ -8,6 +8,7 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import org.apache.ibatis.type.Alias; +import org.springframework.format.annotation.DateTimeFormat; import java.util.Date; @@ -25,6 +26,7 @@ public class AccountDto { private String personalAuthorityId; private String name; private String gender; + @DateTimeFormat(pattern = "yyyy-MM-dd") private Date birth; private String telephone; private String address; diff --git a/src/main/java/com/no1/wms/account/AccountMapper.java b/src/main/java/com/no1/wms/account/AccountMapper.java index 079dcf6..1ffaa27 100644 --- a/src/main/java/com/no1/wms/account/AccountMapper.java +++ b/src/main/java/com/no1/wms/account/AccountMapper.java @@ -1,5 +1,8 @@ package com.no1.wms.account; +import com.no1.wms.authority.AuthorityDto; +import com.no1.wms.department.DepartmentDto; +import com.no1.wms.position.PositionDto; import org.apache.ibatis.annotations.Mapper; import org.springframework.stereotype.Repository; @@ -11,9 +14,15 @@ import java.util.Map; public interface AccountMapper { int insert(AccountDto dto); + + int insertToAuthority(AuthorityDto dto); int update(AccountDto dto); - int selectById(AccountDto dto); + AccountDto selectById(AccountDto dto); List selectAll(Map m); + + List selectDeptAll(Map m); + + List selectPosAll(Map m); } diff --git a/src/main/java/com/no1/wms/account/AccountService.java b/src/main/java/com/no1/wms/account/AccountService.java index 8ee5c24..26ebfc7 100644 --- a/src/main/java/com/no1/wms/account/AccountService.java +++ b/src/main/java/com/no1/wms/account/AccountService.java @@ -1,5 +1,8 @@ package com.no1.wms.account; +import com.no1.wms.authority.AuthorityDto; +import com.no1.wms.department.DepartmentDto; +import com.no1.wms.position.PositionDto; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -15,11 +18,14 @@ public class AccountService { public int insert(AccountDto dto){ return mapper.insert(dto); } + int insertToAuthority(AuthorityDto dto){ + return mapper.insertToAuthority(dto); + } public int update(AccountDto dto){ return mapper.update(dto); } - public int selectById(AccountDto dto){ + public AccountDto selectById(AccountDto dto){ return mapper.selectById(dto); } @@ -34,4 +40,22 @@ public class AccountService { return mapper.selectAll(map); } + List selectDeptAll(String search, int start, int perPage){ + HashMap map = new HashMap(); + map.put("search", search); + map.put("start", start); + map.put("perPage", perPage); + + return mapper.selectDeptAll(map); + } + + List selectPosAll(String search, int start, int perPage){ + HashMap map = new HashMap(); + map.put("search", search); + map.put("start", start); + map.put("perPage", perPage); + + return mapper.selectPosAll(map); + } + } diff --git a/src/main/java/com/no1/wms/account/DeptAndPositionDto.java b/src/main/java/com/no1/wms/account/DeptAndPositionDto.java deleted file mode 100644 index 7f9a328..0000000 --- a/src/main/java/com/no1/wms/account/DeptAndPositionDto.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.no1.wms.account; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.apache.ibatis.type.Alias; - -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@Alias("DeptPositionDto") -public class DeptAndPositionDto { - private String id; - private String name; -} diff --git a/src/main/resources/mappers/AccountMapper.xml b/src/main/resources/mappers/AccountMapper.xml index 77da4d4..eb37bd3 100644 --- a/src/main/resources/mappers/AccountMapper.xml +++ b/src/main/resources/mappers/AccountMapper.xml @@ -13,6 +13,8 @@ + + @@ -21,12 +23,12 @@ - - + + - - + + @@ -35,12 +37,14 @@ acc.id, acc.name, acc.employee_number, acc.password, acc.email, acc.gender, acc.birth, acc.telephone, acc.address, acc.activation, + acc.personal_authority_id , acc.group_authority_id, + acc.department_id, acc.position_id, auth2.name group_auth_name, auth.name personal_auth_name, dept.name dept_name, pos.name pos_name from account acc join authority auth join authority auth2 join department dept join position pos on acc.personal_authority_id = auth.id and acc.group_authority_id = auth2.id and dept.id = acc.department_id and acc.position_id = pos.id - where acc.name like concat('%',#{search},'%') + where acc.id = #{id} + select * from department + where name like concat('%',#{search},'%') + order by name limit #{start}, #{perPage} + + + + + + update account SET + name = #{name}, + employee_number = #{employeeNumber}, + email = #{email}, + personal_authority_id = #{personalAuthorityId}, + gender = #{gender}, + birth = #{birth}, + telephone = #{telephone}, + address = #{address}, + department_id = #{departmentId}, + position_id = #{positionId}, + activation = #{activation} + WHERE id = #{id} + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/account/create.jsp b/src/main/webapp/WEB-INF/views/account/create.jsp index 8d67b42..96dcca1 100644 --- a/src/main/webapp/WEB-INF/views/account/create.jsp +++ b/src/main/webapp/WEB-INF/views/account/create.jsp @@ -27,6 +27,33 @@ } }); } + + function createProcess(){ + let data = {}; + const $dataInputList = $("input.create_data"); + $dataInputList.each(function(index, element){ + const $element = $(element); + const name = $element.attr("name"); + const val = $element.val(); + data[name] = val; + }); + + $.ajax({ + type : 'post', // 타입 (get, post, put 등등) + url : '/account/create_process', // 요청할 서버url + dataType : 'json', // 데이터 타입 (html, xml, json, text 등등) + data : data, + success : function(result) { // 결과 성공 콜백함수 + alert("성공"); + }, + error : function(request, status, error) { + alert(error) + } + }); + + + + }
@@ -43,46 +70,52 @@
사용자 명 - + 사번 - +
부서 명 - - + + + 직책 - - + + +
권한 - +
이메일 - + 전화번호 - +
성별 - + 생일 - + +
+
+ 주소 +
- - + +
diff --git a/src/main/webapp/WEB-INF/views/account/list.jsp b/src/main/webapp/WEB-INF/views/account/list.jsp index 2b727c5..6c38b62 100644 --- a/src/main/webapp/WEB-INF/views/account/list.jsp +++ b/src/main/webapp/WEB-INF/views/account/list.jsp @@ -76,7 +76,7 @@ 사번사용자 명활성 여부 - + ${dto.employeeNumber} ${dto.name} diff --git a/src/main/webapp/WEB-INF/views/account/read.jsp b/src/main/webapp/WEB-INF/views/account/read.jsp new file mode 100644 index 0000000..c21c58f --- /dev/null +++ b/src/main/webapp/WEB-INF/views/account/read.jsp @@ -0,0 +1,80 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> + + +
+
+
+
+

사용자 추가

+
+
+
+
+
+
+
+
+
+ 이름 : ${dto.name} + + + 사번 : ${dto.employeeNumber} +
+
+ 부서 : ${dto.departmentDto.name} + + 직책 : ${dto.positionDto.name} +
+
+ 권한 : ${dto.personalAuthorityDto.name} +
+
+ 이메일 : ${dto.email} + + 전화번호 : ${dto.telephone} +
+
+ 성별 : ${dto.gender} + + 생일 : + +
+
+ 주소 : ${dto.address} +
+
+
+
+
+ + +
+
+
+ \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/account/update.jsp b/src/main/webapp/WEB-INF/views/account/update.jsp new file mode 100644 index 0000000..dbc5fce --- /dev/null +++ b/src/main/webapp/WEB-INF/views/account/update.jsp @@ -0,0 +1,136 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> + + +
+
+
+
+

사용자 추가

+
+
+
+
+
+
+
+
+
+ 활성화 +
+ checked class="form-check-input" type="radio" name="activation" id="inlineRadio1" value="true"> + +
+
+ checked class="form-check-input" type="radio" name="activation" id="inlineRadio2" value="false"> + +
+
+
+ 이름 + + + 사번 + +
+
+ 부서 + + + + + 직책 + + + +
+
+ 권한 + + + +
+
+ 이메일 + + + 전화번호 + +
+
+ 성별 + + + 생일 + +
+
+ 주소 + +
+
+
+
+
+ + +
+
+
+ \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/modal/auth.jsp b/src/main/webapp/WEB-INF/views/modal/auth.jsp index f6c767f..a462455 100644 --- a/src/main/webapp/WEB-INF/views/modal/auth.jsp +++ b/src/main/webapp/WEB-INF/views/modal/auth.jsp @@ -1,7 +1,8 @@ <%@ page contentType="text/html; charset=UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> +
+
+
+ +
+
+ + + + + + + + + + + + +
부서 명
${dto.name}
+
+
+
\ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/modal/pos.jsp b/src/main/webapp/WEB-INF/views/modal/pos.jsp new file mode 100644 index 0000000..db62cfe --- /dev/null +++ b/src/main/webapp/WEB-INF/views/modal/pos.jsp @@ -0,0 +1,47 @@ +<%@ page contentType="text/html; charset=UTF-8"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> + +
+
+
+ +
+
+ + + + + + + + + + + + +
권한명
${dto.name}
+
+
+
\ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/test/kkk.jsp b/src/main/webapp/WEB-INF/views/test/kkk.jsp index 25ee7f3..5b08948 100644 --- a/src/main/webapp/WEB-INF/views/test/kkk.jsp +++ b/src/main/webapp/WEB-INF/views/test/kkk.jsp @@ -4,8 +4,10 @@ Title + -kkkkk 성공 + + \ No newline at end of file