mirror of
https://github.com/suhf/No1WMS.git
synced 2026-02-04 12:13:24 +09:00
add stockController
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.no1.wms.stock;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -8,9 +9,12 @@ import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.no1.wms.stock.StockDto;
|
||||
|
||||
@Controller
|
||||
public class StockController {
|
||||
|
||||
@@ -19,24 +23,52 @@ public class StockController {
|
||||
|
||||
// 재고 리스트 출력
|
||||
@GetMapping("stock/list")
|
||||
public String list(@RequestParam(name = "p", defaultValue = "1")int p, Model m) {
|
||||
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<StockDto> dto = service.stockList(p);
|
||||
List<StockDto> dto = service.stockList(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 "stock/list";
|
||||
}
|
||||
|
||||
|
||||
// 재고 상세페이지
|
||||
@PostMapping("stock/read/{id}")
|
||||
@ResponseBody
|
||||
public String read(@PathVariable String id, Model m) {
|
||||
public String read(@PathVariable UUID id, Model m) {
|
||||
|
||||
//스톡서비스로 재고 상세페이지 출력 메서드 작성
|
||||
|
||||
return "stock/read/{id}";
|
||||
StockDto dto = service.stockOne(id);
|
||||
m.addAttribute("dto", dto);
|
||||
return "stock/read/";
|
||||
}
|
||||
|
||||
|
||||
// 수정 - 폼
|
||||
// @GetMapping("/stock/update/{id}")
|
||||
// public String update(@PathVariable UUID id, Model m) {
|
||||
// StockDto dto = service.updateStock(id);
|
||||
// m.addAttribute("dto", dto);
|
||||
// return "stock/update";
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.no1.wms.stock;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class StockDto {
|
||||
|
||||
private int id;
|
||||
private UUID id;
|
||||
private int warehouse_id;
|
||||
private int product_id;
|
||||
private int quantity;
|
||||
|
||||
@@ -2,12 +2,23 @@ package com.no1.wms.stock;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
|
||||
@Mapper
|
||||
public interface StockMapper {
|
||||
|
||||
int count(Map<String, Object> m);//검색 글 갯수
|
||||
|
||||
List<StockDto> stockList(Map<String, Object> m);
|
||||
|
||||
int updateStock(StockDto dto);
|
||||
|
||||
int createStock(StockDto dto);
|
||||
|
||||
StockDto stockOne(UUID id);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.io.Console;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -13,18 +14,43 @@ public class StockService {
|
||||
@Autowired
|
||||
StockMapper mapper;
|
||||
|
||||
public List<StockDto> stockList(int p){
|
||||
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);
|
||||
return mapper.count(m);
|
||||
}
|
||||
|
||||
|
||||
public List<StockDto> stockList(int searchn, String search, int start){
|
||||
|
||||
int start = 0;
|
||||
int end = 0;
|
||||
System.out.println(searchn+search);
|
||||
|
||||
Map m = new HashMap<String, Object>();
|
||||
Map<String, Object> m = new HashMap<String, Object>();
|
||||
m.put("searchn",searchn);
|
||||
m.put("search", search);
|
||||
m.put("start", start);
|
||||
m.put("end", end);
|
||||
m.put("count", 10);
|
||||
|
||||
return mapper.stockList(m);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public StockDto stockOne(UUID id) {
|
||||
return mapper.stockOne(id);
|
||||
}
|
||||
|
||||
|
||||
public int createStock(StockDto dto) {
|
||||
return mapper.createStock(dto);
|
||||
}
|
||||
|
||||
|
||||
public int updateStock(StockDto dto) {
|
||||
return mapper.updateStock(dto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,18 +5,47 @@
|
||||
<mapper namespace="com.no1.wms.authority.AuthorityMapper">
|
||||
|
||||
<!-- select -->
|
||||
<select id="stockList" parameterType="map" resultType="com.no1.wms.stock.StockDto">
|
||||
select * from stock product warehouse
|
||||
<select id="count" parameterType="map" resultType="com.no1.wms.stock.StockDto">
|
||||
select count(*) from wms.stock left join wms.warehouse on wms.stock.warehouse_id = wms.warehouse.id left join wms.product on wms.stock.product_id = wms.product.id
|
||||
<where>
|
||||
<choose>
|
||||
<when test="searchn == 0"> name like ('%',#{search},'%')</when>
|
||||
<when test="searchn == 1"> content like concat('%',#{search},'%') </when>
|
||||
<when test="searchn == 0"> activation = 1 and warehouse.name like concat('%',#{search},'%')</when>
|
||||
<when test="searchn == 1"> activation = 1 and product.name like concat('%',#{search},'%') </when>
|
||||
</choose>
|
||||
</where>
|
||||
order by id desc limit #{start}, #{count}
|
||||
order by id desc limit #{start}, #{perPage}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="stockList" parameterType="map" resultType="com.no1.wms.stock.StockDto">
|
||||
select * from wms.stock left join wms.warehouse on wms.stock.warehouse_id = wms.warehouse.id left join wms.product on wms.stock.product_id = wms.product.id
|
||||
<where>
|
||||
<choose>
|
||||
<when test="searchn == 0"> activation = 1 and warehouse.name like concat('%',#{search},'%')</when>
|
||||
<when test="searchn == 1"> activation = 1 and product.name like concat('%',#{search},'%') </when>
|
||||
</choose>
|
||||
</where>
|
||||
order by id desc limit #{start}, #{perPage}
|
||||
</select>
|
||||
|
||||
<select id="stockOne" parameterType="UUID" resultType="com.no1.wms.stock.StockDto">
|
||||
selct * from stock where id = #{id}
|
||||
</select>
|
||||
<!-- select -->
|
||||
|
||||
|
||||
<!-- update -->
|
||||
<update id="updateStock" parameterType="com.no1.wms.stock.StockDto">
|
||||
update stock
|
||||
set quantity = #{dto.quantity}
|
||||
where id = #{dto.id}
|
||||
</update>
|
||||
<!-- update -->
|
||||
|
||||
|
||||
<!-- insert -->
|
||||
<insert id="createStock" parameterType="com.no1.wms.stock.StockDto">
|
||||
insert into stock (id, quantity, activation)
|
||||
values (#{dto.id}, #{dto.quantity}, 1)
|
||||
</insert>
|
||||
<!-- insert -->
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user