stock.list.jsp
StockMapper.xml

#추가
stock.create.jsp
WarehouseController.java
WarehouseDto.java
WarehouseMapper.java
WarehouseMapper.xml
WarehouseService.java
This commit is contained in:
sungsu
2024-01-08 18:46:09 +09:00
parent 2706c902c1
commit b6e967975b
8 changed files with 416 additions and 100 deletions

View File

@@ -0,0 +1,101 @@
package com.no1.wms.warehouse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Controller
@Slf4j
public class WarehouseController {
@Autowired
WarehouseService service;
// 재고 리스트 출력
@GetMapping("warehouse/list")
public String list(@RequestParam(name = "searchn", defaultValue = "0") int searchn,
@RequestParam(name = "search", defaultValue = "") String search,
@RequestParam(name = "p", defaultValue = "1") int page, Model m) {
int count = service.count(searchn, search);
int perPage = 10; // 한 페이지에 보일 글의 갯수
int startRow = (page - 1) * perPage;
//스톡서비스로 재고 리스트 출력 메서트 작성
List<Object> dto = service.list(searchn, search, perPage);
m.addAttribute("list", dto);
int pageNum = 4;//보여질 페이지 번호 수
int totalPages = count / perPage + (count % perPage > 0 ? 1 : 0); // 전체 페이지 수
int begin = (page - 1) / pageNum * pageNum + 1;
int end = begin + pageNum - 1;
if (end > totalPages) {
end = totalPages;
}
m.addAttribute("begin", begin);
m.addAttribute("end", end);
m.addAttribute("pageNum", pageNum);
m.addAttribute("totalPages", totalPages);
return "warehouse/list";
}
// 재고 상세페이지
@PostMapping("warehouse/read/{id}")
public String read(@PathVariable String id, Model m) {
//스톡서비스로 재고 상세페이지 출력 메서드 작성
WarehouseDto dto = service.warehouseOne(id);
m.addAttribute("dto", dto);
return "warehouse/read/";
}
// 수정 - 폼
@GetMapping("/warehouse/update/{id}")
public String update(@PathVariable String id, Model m) {
WarehouseDto dto = service.warehouseOne(id);
m.addAttribute("dto", dto);
return "warehouse/update";
}
// 수정 프로세스
@PutMapping("/warehouse/update_process")
@ResponseBody
public String updateProcess(WarehouseDto dto) {
service.updateWarehouse(dto);
return "redirect:list";
}
// 생성 폼
@GetMapping("/warehouse/create")
public String create()
{
return "stock/create";
}
// 생성 프로세스
@PostMapping("/warehouse/create_process")
@ResponseBody
public String createProcess(WarehouseDto dto) {
service.createWarehouse(dto);
return "redirect:list";// 글목록
}
// 삭제
@DeleteMapping("/warehouse/delete")
@ResponseBody
public int delete(String id) {
int i = service.deleteWarehouse(id);
return i;
}
}

View File

@@ -0,0 +1,15 @@
package com.no1.wms.warehouse;
import lombok.Data;
@Data
public class WarehouseDto {
private String id;
private String name;
private int capacity;
private int current_capacity;
private String manager_id;
private String address;
private boolean activation;
}

View File

@@ -0,0 +1,26 @@
package com.no1.wms.warehouse;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
import java.util.Map;
@Mapper
public interface WarehouseMapper {
int count(Map<String, Object> m);//검색 글 갯수
List<Object> list(Map<String, Object> m);
int updateWarehouse(WarehouseDto dto);
int createWarehouse(WarehouseDto dto);
WarehouseDto warehouseOne(String id);
int deleteWarehouse(String id);
}

View File

@@ -0,0 +1,61 @@
package com.no1.wms.warehouse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class WarehouseService {
@Autowired
WarehouseMapper mapper;
public int count(int searchn, String search) {
System.out.println(searchn+search);
Map<String,Object> m = new HashMap<String, Object>();
m.put("searchn",searchn);
m.put("search", search);
m.put("start", 0);
m.put("perPage", 10000);
return mapper.count(m);
}
public List<Object> list(int searchn, String search, int start){
System.out.println(searchn+search);
Map<String, Object> m = new HashMap<String, Object>();
m.put("searchn",searchn);
m.put("search", search);
m.put("start", start);
m.put("perPage", 10);
return mapper.list(m);
}
public WarehouseDto warehouseOne(String id) {
return mapper.warehouseOne(id);
}
public int createWarehouse(WarehouseDto dto) {
return mapper.createWarehouse(dto);
}
public int updateWarehouse(WarehouseDto dto) {
return mapper.updateWarehouse(dto);
}
public int deleteWarehouse(String id) {
return mapper.deleteWarehouse(id);
}
}

View File

@@ -9,19 +9,19 @@
select count(*) from stock left join warehouse on stock.warehouse_id = warehouse.id left join product on stock.product_id = product.id left join product_category on product.kan_code = product_category.kan_code select count(*) from stock left join warehouse on stock.warehouse_id = warehouse.id left join product on stock.product_id = product.id left join product_category on product.kan_code = product_category.kan_code
<where> <where>
<choose> <choose>
<when test="searchn == 0"> stock.activation = 1 and warehouse.name like concat('%',#{search},'%')</when> <when test="searchn == 0"> stock.activation = 1 and product.name like concat('%',#{search},'%')</when>
<when test="searchn == 1"> stock.activation = 1 and product.name like concat('%',#{search},'%') </when> <when test="searchn == 1"> stock.activation = 1 and product_category.cls_Nm_4 like concat('%',#{search},'%') </when>
</choose> </choose>
</where> </where>
order by stock.id desc limit #{start}, #{perPage} order by stock.id desc limit #{start}, #{perPage}
</select> </select>
<select id="list" parameterType="map" resultType="com.no1.wms.stock.StockDto"> <select id="count" parameterType="map" resultType="java.lang.Integer">
select * from stock left join warehouse on stock.warehouse_id = warehouse.id left join product on stock.product_id = product.id left join product_category on product.kan_code = product_category.kan_code select * from stock left join warehouse on stock.warehouse_id = warehouse.id left join product on stock.product_id = product.id left join product_category on product.kan_code = product_category.kan_code
<where> <where>
<choose> <choose>
<when test="searchn == 0"> stock.activation = 1 and warehouse.name like concat('%',#{search},'%')</when> <when test="searchn == 0"> stock.activation = 1 and product.name like concat('%',#{search},'%')</when>
<when test="searchn == 1"> stock.activation = 1 and product.name like concat('%',#{search},'%') </when> <when test="searchn == 1"> stock.activation = 1 and product_category.cls_Nm_4 like concat('%',#{search},'%') </when>
</choose> </choose>
</where> </where>
order by stock.id desc limit #{start}, #{perPage} order by stock.id desc limit #{start}, #{perPage}

View File

@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTO Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.no1.wms.warehouse.WarehouseMapper">
<!-- select -->
<select id="count" parameterType="map" resultType="java.lang.Integer">
select count(*) from warehouse left join account on warehouse.manager_id = account.id
<where>
<choose>
<when test="searchn == 0"> warehouse.activation = 1 and warehouse.name like concat('%',#{search},'%')</when>
<when test="searchn == 1"> warehouse.activation = 1 and warehouse.capacity like concat('%',#{search},'%') </when>
<when test="searchn == 3"> warehouse.activation = 1 and warehouse.current_capacity like concat('%',#{search},'%')</when>
</choose>
</where>
order by stock.id desc limit #{start}, #{perPage}
</select>
<select id="list" parameterType="map" resultType="com.no1.wms.warehouse.WarehouseDto">
select * from warehouse left join account on warehouse.manager_id = account.id
<where>
<choose>
<when test="searchn == 0"> warehouse.activation = 1 and warehouse.name like concat('%',#{search},'%')</when>
<when test="searchn == 1"> warehouse.activation = 1 and warehouse.capacity like concat('%',#{search},'%') </when>
<when test="searchn == 3"> warehouse.activation = 1 and warehouse.current_capacity like concat('%',#{search},'%')</when>
</choose>
</where>
order by stock.id desc limit #{start}, #{perPage}
</select>
<select id="warehouseOne" parameterType="String" resultType="com.no1.wms.warehouse.WarehouseDto">
selct * from warehouse where id = #{id}
</select>
<!-- select -->
<!-- update -->
<update id="updateWarehouse" parameterType="com.no1.wms.warehouse.WarehouseDto">
update warehouse
set capacity = #{dto.capacity}, name = #{dto.name}
where id = #{dto.id}
</update>
<!-- update -->
<!-- insert -->
<insert id="createWarehouse" parameterType="com.no1.wms.warehouse.WarehouseDto">
insert into warehouse (id, warehouse_id, product_id, quantity, activation)
values ((UUID), #{dto.warehouse_id}, #{dto.product_id}, #{dto.quantity}, 1)
</insert>
<!-- insert -->
<!-- delete -->
<delete id="deleteWarehouse" parameterType="String">
delete from warehouse where no = #{id}
</delete>
<!-- delete -->
</mapper>

View File

@@ -0,0 +1,60 @@
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>재고 생성</title>
<style type="text/css">
.header {
text-align: center;
}
</style>
</head>
<body>
<div class = "container" >
<div class="header">
<h1>재고 관리 생성</h1>
</div>
<hr>
<div class = "row">
<div class = "col-6">
<form>
<input type="text" name="search" maxlength="50" readonly/>
<input type="submit" class="btn btn-primary" id = "search_modal_show_button" value="검색" />
</form>
</div>
</div>
<div class="modal fade" id="search_modal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-xl" >
<div class="modal-content align: center" id="search_modal_content">
<div class="modal-header">
<h1 class="modal-title fs-5 col-" id="searchModalLabel">재고명 검색</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
</div>
</div>
</div>
</div>
</body>
<script src="../../utils.js" type="text/javascript"></script>
<script>
//검색 팝업 모달 관련
const searchModalBootStrap = new bootstrap.Modal("#search_modal");
$("#search_modal_show_button").on("click", function(){
searchModalBootStrap.show();
});
/*
* 검색 팝업 모달 닫는 함수
*/
function hideSearchModal(){
searchModalBootStrap.hide();
}
</script>
</html>

View File

@@ -1,5 +1,6 @@
<%@ page contentType="text/html; charset=UTF-8"%> <%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
@@ -13,66 +14,32 @@
</head> </head>
<body> <body>
<div class="header"> <div class="header">
<h1>재고 리스트</h1> <h1>재고 리스트</h1>
</div> </div>
<hr> <hr>
<<script src="../../utils.js" type="text/javascript"></script>
<script>
/*
yes no 모달의 확인 버튼을 누를때 재정의할 function
yesNoModal.yesFunction = myYesFunction; <div class="body">
function myYesFunction(){
alert("재정의 됨");
}
*/
$(function(){
$('.tabcontent > div').hide();
$('.tabnav a').click(function () {
$('.tabcontent > div').hide().filter(this.hash).fadeIn();
$('.tabnav a').removeClass('active');
$(this).addClass('active');
return false;
}).filter(':eq(0)').click();
});
/*엑셀 다운로드 클릭 펑션 */
$("#excelButton").click(function(){
const columns = [
{name: '번호', key: 'id'},
{name: '제품명', key: 'product_name'},
{name: '창고명', key: 'warehouse_name'},
{name: '재고수', key: 'quantity'},
{name: '카테고리', key: 'cls_Nm_4'}
];
exportExcel(e, 'sheet', columns, list, 'stock');
})
</script>
여기다가 화면 만들기
<!--탭키명 --> <!--탭키명 -->
<div class="tab"> <ul class="nav nav-tabs" id="myTab" role="tablist">
<ul class="tabnav"> <li class="nav-item" role="presentation">
<li><a href="#tab01">재고</a></li> <button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home" type="button" role="tab" aria-controls="home" aria-selected="true">
<li><a href="#tab02">부족한재고</a></li> 재고
</ul> </button>
</li>
<!--탭키 내용--> <li class="nav-item" role="presentation">
<div class="tabcontent"> <button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#profile" type="button" role="tab" aria-controls="profile" aria-selected="false">
부족한 재고
<!--재고 탭 내용--> </button>
<div id="tab01"> </li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
<div id="search" align="center"> <div id="search" align="center">
<form action="search"> <form action="search">
<select name="searchn"> <select name="searchn">
<option value="0">창고명</option> <option value="0">제품명</option>
<option value="1">제품명</option> <option value="1">카테고리</option>
</select> </select>
<input type="text" name="search" maxlength="50"/> <input type="text" name="search" maxlength="50"/>
<input type="submit" class="btn btn-primary" value="검색" /> <input type="submit" class="btn btn-primary" value="검색" />
@@ -97,10 +64,10 @@
</table> </table>
<!-- 엑셀 다운로드--> <!-- 엑셀 다운로드-->
<div class="excelButton"> <div class="excelButton" align="left">
<button id="excelButton" value="생성">생성</button> <button id="excelButton" value="excelButton">다운로드</button>
</div> </div>
<div id="page"> <div id="page" align="center">
<c:if test="${begin > pageNum }"> <c:if test="${begin > pageNum }">
<a href="list?p=${begin-1 }">[<]</a> <a href="list?p=${begin-1 }">[<]</a>
</c:if> </c:if>
@@ -112,16 +79,43 @@
</c:if> </c:if>
</div> </div>
<div class="createButton" align="right">
<button id="createButton" href="create">생성</button>
</div>
</div>
</c:if> </c:if>
</div>
<!--부족한재고 탭 내용-->
<div id="tab02">
tab2 content
</div> </div>
<div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">
탭2 내용
</div> </div>
</div> </div>
</div>
</body> </body>
<script src="../../utils.js" type="text/javascript"></script>
<script>
/*엑셀 다운로드 클릭 펑션 */
$("#excelButton").click(function(){
const columns = [
{name: '번호', key: 'id'},
{name: '제품명', key: 'product_name'},
{name: '창고명', key: 'warehouse_name'},
{name: '재고수', key: 'quantity'},
{name: '카테고리', key: 'cls_Nm_4'}
];
exportExcel(e, 'sheet', columns, list, 'stock');
})
</script>
</html> </html>