Skip to content

Commit

Permalink
优化:给sku菜单的列表增加一列“库存数量”
Browse files Browse the repository at this point in the history
  • Loading branch information
wukonggg committed Aug 22, 2016
1 parent 22a418e commit 5ca0a88
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 34 deletions.
2 changes: 1 addition & 1 deletion VERSION.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
2.设计最简单的菜单权限,去掉shiro。
3.修复bug:退货的价格不对,应该使用成交价,而不是零售价(原价)。
由此又调整了退货的业务逻辑,要退直接全退,不再调整退货数量。

4.优化:给sku菜单的列表增加一列“库存数量”

5.BUY菜单增加扫码枪加购物车的功能。
6.支持直接扫澳洲产品条码

Expand Down
43 changes: 27 additions & 16 deletions src/main/java/band/wukong/mz/g/sku/bean/Sku.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public class Sku {

private File gimg;

private int count; //sku list中用于显示库存数量

public long getId() {
return id;
}
Expand Down Expand Up @@ -198,24 +200,33 @@ public void setGimg(File gimg) {
this.gimg = gimg;
}

public int getCount() {
return count;
}

public void setCount(int count) {
this.count = count;
}

@Override
public String toString() {
return "Sku{" +
"id=" + id +
", sid='" + sid + '\'' +
", model='" + model + '\'' +
", type='" + type + '\'' +
", ptime=" + ptime +
", pprice=" + pprice +
", sprice=" + sprice +
", img='" + img + '\'' +
", ctime=" + ctime +
", utime=" + utime +
", state='" + state + '\'' +
", goodsId=" + goodsId +
", goods=" + goods +
", moreList=" + moreList +
", gimg=" + gimg +
'}';
"id=" + id +
", sid='" + sid + '\'' +
", model='" + model + '\'' +
", type='" + type + '\'' +
", ptime=" + ptime +
", pprice=" + pprice +
", sprice=" + sprice +
", img='" + img + '\'' +
", ctime=" + ctime +
", utime=" + utime +
", state='" + state + '\'' +
", goodsId=" + goodsId +
", goods=" + goods +
", moreList=" + moreList +
", gimg=" + gimg +
", count=" + count +
'}';
}
}
22 changes: 13 additions & 9 deletions src/main/java/band/wukong/mz/g/sku/dao/impl/SkuDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,30 +110,34 @@ public QueryResult list(String cateCode, String qcond, int pageNum, int pageSize
}

String exp =
"select t1.id as 'g.id', t1.cate_code as 'g.cate_code', t1.gname as 'g.gname'\n" +
" , t.id as 'sc.id', t.sid as 'sc.sid', t.model as 'sc.model', t.img as 'sc.img', t.pprice as 'sc.pprice', t1.id as 'sc.goods_id'\n" +
"from t_sku t\n" +
"inner join t_goods t1 on t1.id = t.goods_id\n" +
"where t.state = @t_state and t1.state = @t1_state\n" +
"and t1.cate_code like @cate_code\n" +
"and (t.sid like @qcond or t1.gname like @qcond)";
"select t1.id as 'g.id', t1.cate_code as 'g.cate_code', t1.gname as 'g.gname'\n" +
" , t.id as 'sc.id', t.sid as 'sc.sid', t.model as 'sc.model', t.img as 'sc.img', t.pprice as 'sc.pprice', t1.id as 'sc.goods_id'\n" +
" , sum(t2.count) as 'sc.count'\n" +
"from t_sku t\n" +
"inner join t_goods t1 on t1.id = t.goods_id\n" +
"inner join t_sku_more t2 on t2.sku_id = t.id\n" +
"where t.state = @t_state and t1.state = @t1_state\n" +
"and t1.cate_code like @cate_code\n" +
"and (t.sid like @qcond or t1.gname like @qcond)\n" +
"group by t.id";

Sql sql = Sqls.queryRecord(exp);

sql.params().set("t_state", Sku.STATE_ON);
sql.params().set("t1_state", Goods.STATE_OK);
sql.params().set("cate_code", cateCode + "%");
sql.params().set("qcond", "%" + qcond + "%");

int count = count4List(exp, cateCode, qcond);
int count = count4List(sql.getSourceSql(), cateCode, qcond);
Pager pager = NutzDaoHelper.createPager(pageNum, pageSize, count);
sql.setPager(pager);


dao.execute(sql);
List<Record> list = sql.getList(Record.class);
List<Sku> scList = new ArrayList<Sku>();
for (Record re : list) {
Sku sc = re.toEntity(dao.getEntity(Sku.class), "sc.");
sc.setCount(re.getInt("sc.count"));
Goods g = re.toEntity(dao.getEntity(Goods.class), "g.");
sc.setGoods(g);
scList.add(sc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ public QueryResult list(String cateCode, String qcond, int pageNum, int pageSize
if (Strings.isBlank(cateCode)) {
throw new IllegalParameterException();
}

return skuDao.list(cateCode, qcond, pageNum, pageSize);
}

Expand Down
11 changes: 9 additions & 2 deletions src/main/webapp/WEB-INF/view/sku/sku_list.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@
<%
Map retMap = (Map) request.getAttribute("obj");
QueryResult qr = (QueryResult) retMap.get("result");
List<Sku> scList = qr.getList(Sku.class);
Pager pager = qr.getPager();
List<Sku> scList = null;
Pager pager = null;
if (qr != null) {
scList = qr.getList(Sku.class);
pager = qr.getPager();
}
request.setAttribute("scList", scList);
request.setAttribute("pager", pager);
request.setAttribute("cateCode", retMap.get("cateCode"));
Expand Down Expand Up @@ -96,6 +101,7 @@
<th>品类</th>
<th>名称</th>
<th>款型</th>
<th>库存量</th>
<th>SKU编码</th>
<th style="width: 250px;">操作</th>
</tr>
Expand All @@ -108,6 +114,7 @@
<td>${cate:title(sc.goods.cateCode, applicationScope["APP_CATE_FLAT_MAP"])}</td> <!-- TODO -OPT 这里如何能做到不用字面字符串?-->
<td class="mz-tooltip " title="${sc.goods.gname}">${one:string4short(sc.goods.gname, 16)}</td>
<td>${sc.model}</td>
<td>${sc.count}</td>
<td>${sc.sid}</td>
<td>
<div class="am-btn-toolbar">
Expand Down
12 changes: 7 additions & 5 deletions src/test/java/band/wukong/mz/g/sku/dao/impl/SkuDaoImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ public void list() {
Assert.assertTrue(qr1.getList(Sku.class).size() > 0);
System.out.println("qr1.getPager() = " + qr1.getPager());
System.out.println("qr1.getList(Sku.class).size() = " + qr1.getList(Sku.class).size());
System.out.println("qr1.getList().get(0) = " + qr1.getList(Sku.class).get(0));

// QueryResult qr2 = skuDao.list(SimpleCateConst.CATE_CODE_A_SYTZ, "junit", 0, 100);
// Assert.assertNotNull(qr2.getPager());
// Assert.assertTrue(qr2.getList(Sku.class).size() > 0);
// System.out.println("qr2.getPager() = " + qr2.getPager());
// System.out.println("qr2.getList(Sku.class).size() = " + qr2.getList(Sku.class).size());

QueryResult qr2 = skuDao.list(SimpleCateConst.CATE_CODE_A_SYTZ, "junit", 0, 100);
Assert.assertNotNull(qr2.getPager());
Assert.assertTrue(qr2.getList(Sku.class).size() > 0);
System.out.println("qr2.getPager() = " + qr2.getPager());
System.out.println("qr2.getList(Sku.class).size() = " + qr2.getList(Sku.class).size());
}


Expand Down

0 comments on commit 5ca0a88

Please sign in to comment.