This commit is contained in:
Suh
2024-01-16 12:04:48 +09:00
parent f21300a991
commit 88806ccde6
5 changed files with 95 additions and 10 deletions

View File

@@ -1,8 +1,6 @@
package com.no1.wms.account; package com.no1.wms.account;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.stream.JsonReader;
import com.no1.wms.authority.AuthorityDto; import com.no1.wms.authority.AuthorityDto;
import com.no1.wms.authority.AuthorityService; import com.no1.wms.authority.AuthorityService;
import com.no1.wms.utils.ConstantValues; import com.no1.wms.utils.ConstantValues;
@@ -11,7 +9,6 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import java.io.StringReader;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@@ -27,11 +24,32 @@ public class AccountController {
AuthorityService authorityService; AuthorityService authorityService;
@GetMapping("/list") @GetMapping("/list")
public ModelAndView list(ModelAndView mav, @RequestParam(defaultValue = "") String search, @RequestParam(defaultValue = "0") int start){ public ModelAndView list(ModelAndView mav,@RequestParam(defaultValue = "0") int searchn, @RequestParam(defaultValue = "") String search, @RequestParam(defaultValue = "1") int page){
int perPage = 10;
int startRow = (page - 1) * perPage;
int count = accountService.count(searchn, search, startRow, perPage);
List<AccountDto> list = accountService.selectAll(search, start, ConstantValues.PER_PAGE);
int pageNum = 4;//보여질 페이지 번호 수
int totalPages = count / perPage + (count % perPage > 0 ? 1 : 0); // 전체 페이지 수
//스톡서비스로 재고 리스트 출력 메서트 작성
List<AccountDto> list = accountService.selectAll(searchn, search, searchn, perPage);
int begin = (page - 1) / pageNum * pageNum + 1;
int end = begin + pageNum - 1;
if (end > totalPages) {
end = totalPages;
}
mav.addObject("list", list); mav.addObject("list", list);
mav.addObject("end", end);
mav.addObject("searchn", searchn);
mav.addObject("search", search);
mav.addObject("page", startRow);
mav.addObject("begin", begin);
mav.setViewName("account/list"); mav.setViewName("account/list");
return mav; return mav;
} }
@@ -120,7 +138,7 @@ public class AccountController {
}else if(name.equals("dept")){ }else if(name.equals("dept")){
list = accountService.selectDeptAll(search, start, ConstantValues.PER_PAGE); list = accountService.selectDeptAll(search, start, ConstantValues.PER_PAGE);
}else if(name.equals("pos")){ }else if(name.equals("pos")){
list = accountService.selectPosAll(search, start, ConstantValues.PER_PAGE); list = accountService.selectPosAll(10, search, start);
} }
// //
mav.addObject("list", list); mav.addObject("list", list);

View File

@@ -31,4 +31,6 @@ public interface AccountMapper {
int delete(AccountDto dto); int delete(AccountDto dto);
AccountDto selectByLogin(AccountDto dto); AccountDto selectByLogin(AccountDto dto);
int count(Map<String, Object> m);
} }

View File

@@ -29,11 +29,12 @@ public class AccountService {
return mapper.selectById(dto); return mapper.selectById(dto);
} }
public List<AccountDto> selectAll(String search, int start, int perPage){ public List<AccountDto> selectAll(int searchn, String search, int start, int perPage){
HashMap<String, Object> map = new HashMap<String, Object>(); HashMap<String, Object> map = new HashMap<String, Object>();
map.put("search", search); map.put("search", search);
map.put("start", start); map.put("start", start);
map.put("perPage", perPage); map.put("perPage", perPage);
map.put("searchn", searchn);
@@ -49,7 +50,7 @@ public class AccountService {
return mapper.selectDeptAll(map); return mapper.selectDeptAll(map);
} }
List<PositionDto> selectPosAll(String search, int start, int perPage){ List<PositionDto> selectPosAll(int perPage, String search, int start){
HashMap<String, Object> map = new HashMap<String, Object>(); HashMap<String, Object> map = new HashMap<String, Object>();
map.put("search", search); map.put("search", search);
map.put("start", start); map.put("start", start);
@@ -69,4 +70,13 @@ public class AccountService {
return mapper.selectByLogin(dto); return mapper.selectByLogin(dto);
} }
int count(int searchn, String search, int start, int perPage){
HashMap<String, Object> m = new HashMap<>();
m.put("searchn", searchn);
m.put("search", search);
m.put("start", start);
m.put("perPage", perPage);
return mapper.count(m);
}
} }

View File

@@ -63,8 +63,14 @@
acc.birth, acc.telephone, acc.address, acc.activation, acc.birth, acc.telephone, acc.address, acc.activation,
auth2.name group_auth_name, auth.name personal_auth_name auth2.name group_auth_name, auth.name personal_auth_name
from account acc join authority auth join authority auth2 on acc.personal_authority_id = auth.id and acc.group_authority_id = auth2.id from account acc join authority auth join authority auth2 on acc.personal_authority_id = auth.id and acc.group_authority_id = auth2.id
where acc.name like concat('%',#{search},'%') <where>
order by acc.activation desc, acc.id desc limit #{start}, #{perPage} <choose>
<when test="searchn == 0"> acc.activation = 1 and acc.name like concat('%',#{search},'%')</when>
<when test="searchn == 1"> acc.activation = 1 and acc.employee_number like concat('%',#{search},'%') </when>
</choose>
</where>
order by acc.id desc limit #{start}, #{perPage}
</select> </select>
<insert id="insert" parameterType="accountDto"> <insert id="insert" parameterType="accountDto">
insert into account insert into account
@@ -134,4 +140,15 @@
<update id="delete" parameterType="accountDto"> <update id="delete" parameterType="accountDto">
update account SET activation = false WHERE id = #{id} update account SET activation = false WHERE id = #{id}
</update> </update>
<select id="count" parameterType="map" resultType="java.lang.Integer">
select count(*) from ( SELECT 1 from account
<where>
<choose>
<when test="searchn == 1"> activation = 1 and name like concat('%',#{search},'%')</when>
<when test="searchn == 0"> activation = 1 and employee_number like concat('%',#{search},'%') </when>
</choose>
</where>
order by id desc limit #{start}, #{perPage} ) t
</select>
</mapper> </mapper>

View File

@@ -49,6 +49,14 @@
} }
function onPaging(target){
const p = $(target).data("p");
$("#pPage").val(p);
const $form = $("#search_form");
$form.attr("action", "/account/list");
$form.trigger("submit");
}
</script> </script>
@@ -66,6 +74,21 @@
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<div class="container"> <div class="container">
<div class="row">
<div class="col-12">
<div id="search" align="center">
<form id="search_form">
<select name="searchn">
<option <c:if test="${searchn == 0}">selected="selected"</c:if> value="0">사번</option>
<option <c:if test="${searchn == 1}">selected="selected"</c:if> value="1">사원명</option>
</select>
<input type="text" name="search" maxlength="50" value="${search}"/>
<button type="submit" class="btn btn-primary" >검색</button>
<input id="pPage" hidden type="text" name="page">
</form>
</div>
</div>
</div>
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<table class="table" > <table class="table" >
@@ -89,6 +112,21 @@
</table> </table>
</div> </div>
</div> </div>
<div class="row">
<div class="col-12">
<div id="page" align="center">
<c:if test="${begin > pageNum }">
<a data-p='${begin-1 }' href="#" onclick="onPaging(this)">[<]</a>
</c:if>
<c:forEach begin="${begin }" end="${end}" var="i">
<a data-p='${i}' href="#" onclick="onPaging(this)" >${i}</a>
</c:forEach>
<c:if test="${end < totalPages }">
<a data-p='${end+1}' href="#" onclick="onPaging(this)">[>]</a>
</c:if>
</div>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>