ProductDao.java
3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package vion.dao;
import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import vion.model.File;
import vion.model.Product;
import vion.model.Store;
import java.util.Date;
import java.util.List;
@Repository
public class ProductDao {
@Autowired
private JdbcTemplate jdbcTemplate;
private static final String SELECT_PRODUCT_ALL = "SELECT * FROM tbl_product_info";
public List<Product> getProductAll() {
return jdbcTemplate.query(SELECT_PRODUCT_ALL, new BeanPropertyRowMapper<Product>(Product.class));
}
private static final String SELECT_PRODUCT_BY_ID = "SELECT * FROM tbl_product_info where id=?";
public Product getProductByID(Integer id) {
List<Product> products= jdbcTemplate.query(SELECT_PRODUCT_BY_ID,new Object[]{id},
new BeanPropertyRowMapper<Product>(Product.class));
if(products.size()>0){
return products.get(0);
}else{
return null;
}
}
private static final String SELECT_PRODUCT_BY_PARM= "SELECT * FROM tbl_product_info WHERE account_id=? and id=? ";
public List<Product> getProductByParm(Integer accountid, Integer id, String name, Integer brand, Integer functionary) {
StringBuffer getProductSb = new StringBuffer(SELECT_PRODUCT_BY_PARM);
if(!StrUtil.isBlank(name)){
getProductSb.append(" and name='"+name+"'");
}
if(brand!=null){
getProductSb.append(" and brand="+brand+"");
}
if(functionary!=null){
getProductSb.append(" and functionary="+functionary+"");
}
return jdbcTemplate.query(getProductSb.toString(),new Object[]{accountid,id}, new BeanPropertyRowMapper<Product>(Product.class));
}
private static final String SAVE_PRODUCT= "INSERT INTO tbl_product_info(\n" +
" material_no, store_id, name, functionary, brand, product_count, \n" +
" product_price, product_subtotal, product_total_price,remark,account_id)\n" +
" VALUES (?, ?, ?, ?, ?, ?, ?, \n" +
" ?, ?, ?,?);";
/*
public Integer addProduct(Product product) {
return jdbcTemplate.update(SAVE_PRODUCT,
new Object[]{product.getMaterial_no(),product.getStore_id(),product.getName(),
product.getFunctionary(),product.getBrand(),product.getProduct_count(),
product.getProduct_price(),product.getProduct_subtotal(),product.getProduct_total_price(),
product.getRemark(),product.getAccount_id()});
}
private static final String UPDATE_PRODUCT= "UPDATE tbl_product_info\n" +
" SET material_no=?, store_id=?, name=?, functionary=?, brand=?, \n" +
" product_count=?, product_price=?, product_subtotal=?, product_total_price=?, \n" +
" modify_time=?, remark=?,account_id=?\n" +
" WHERE id=?;";
public Integer updateProduct(Product product) {
return jdbcTemplate.update(UPDATE_PRODUCT,
new Object[]{product.getMaterial_no(),product.getStore_id(),product.getName(),
product.getFunctionary(),product.getBrand(),product.getProduct_count(),
product.getProduct_price(),product.getProduct_subtotal(),
product.getProduct_total_price(),product.getModify_time(),
product.getRemark(),product.getId(),product.getAccount_id()});
}*/
}