Skip to content

Commit

Permalink
Merge branch 'wjh'
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffy5 committed Jun 26, 2018
2 parents bbb4f64 + aac90d8 commit 0af8cd6
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
1. 商家注册
2. 商家登陆
2. 修复上传接口 BUG
2. 修复商家密码会被查找出来

3. 修复商家密码会被查找出来
3. 修改秒杀接口返回的数据,封装好 Goods 返回,包含秒杀价格的 GoodsAttr (添加 Goods 接口:根据 GoodsAttrId 来查找商品)

4. 修改秒杀接口返回的数据,封装好 Goods 返回,包含秒杀价格的 GoodsAttr (添加 Goods 接口:根据 GoodsAttrId 来查找商品)
4. 部分商品没有套餐,在外层添加价格


4 changes: 4 additions & 0 deletions src/main/java/com/mall/Interceptor/postInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -18,6 +19,9 @@ public class postInterceptor extends AbstractInterceptor {
*/
@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
HttpServletResponse res = ServletActionContext.getResponse();
res.setHeader("Access-Control-Allow-Origin", "*");

String method = ServletActionContext.getRequest().getMethod();
if (method.equals("POST")) {
actionInvocation.invoke();
Expand Down
24 changes: 20 additions & 4 deletions src/main/java/com/mall/admin/action/GoodsAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,53 @@ public String list() {
orderKeys = "salesNum";
}

int count;

if (hasPageSetting()) {
int page = getPageSetting();
int pageSize = getPageSizeSetting();

// 根据参数判断用户是否要根据指定值查找
if (hasParam("goodsName")) {
goodses = goodsService.findByGoodsNameAndPage(getParam("goodsName"), page, pageSize, orderKeys);
String goodsName = getParam("goodsName");
goodses = goodsService.findByGoodsNameAndPage(goodsName, page, pageSize, orderKeys);
count = goodsService.getCountByGoodsName(goodsName);
} else if (hasParam("catId")) {
goodses = goodsService.findByCatIdAndPage(Integer.parseInt(getParam("catId")), page, pageSize, orderKeys);
int catId = Integer.parseInt(getParam("catId"));
goodses = goodsService.findByCatIdAndPage(catId, page, pageSize, orderKeys);
count = goodsService.getCountByCatId(catId);
} else if (hasParam("merchantId")) {
goodses = goodsService.findByMerchantIdAndPage(Integer.parseInt(getParam("merchantId")), page, pageSize, orderKeys);
int merchantId = Integer.parseInt(getParam("merchantId"));
goodses = goodsService.findByMerchantIdAndPage(merchantId, page, pageSize, orderKeys);
count = goodsService.getCountByMerchantId(merchantId);
} else {
goodses = goodsService.findByPage(page, pageSize, orderKeys);
count = goodsService.getCount();
}
} else {
if (hasParam("goodsName")) {
String goodsName = getParam("goodsName");
goodses = goodsService.findByGoodsName(getParam("goodsName"), orderKeys);
count = goodsService.getCountByGoodsName(goodsName);
} else if (hasParam("catId")) {
int catId = Integer.parseInt(getParam("catId"));
goodses = goodsService.findByCatId(Integer.parseInt(getParam("catId")), orderKeys);
count = goodsService.getCountByCatId(catId);
} else if (hasParam("merchantId")) {
int merchantId = Integer.parseInt("merchantId");
goodses = goodsService.findByMerchantId(Integer.parseInt(getParam("merchantId")), orderKeys);
count = goodsService.getCountByMerchantId(merchantId);
} else {
goodses = goodsService.findAll(orderKeys);
count = goodsService.getCount();
}
}

Map<String, Object> map = new HashMap<>();
map.put("data", goodses);

// 加上商品总数
map.put("goodsSum", goodses.size());
map.put("goodsSum", count);
jsonResult = ResponseTemplate.success(map);
return SUCCESS;
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/mall/admin/dao/GoodsDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public interface GoodsDao {

List<Goods> findByPage(int page, int pageSize, String orderKeys);

int getCount();

int getCountByGoodsName(String goodsName);

int getCountByMerchantId(int merchantId);

int getCountByCatId(int catId);

Goods findById(int id);

int save(Goods goods);
Expand Down
57 changes: 54 additions & 3 deletions src/main/java/com/mall/admin/dao/impl/GoodsDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import com.mall.model.GoodsCat;
import com.mall.model.Merchant;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.hibernate.criterion.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;
Expand Down Expand Up @@ -114,6 +112,59 @@ public List<Goods> findByPage(int page, int pageSize, String orderKeys) {
return resultList;
}

@Override
public int getCount() {
DetachedCriteria criteria = DetachedCriteria.forClass(Goods.class);
criteria.setProjection(Projections.rowCount());
Object obj = template.findByCriteria(criteria).get(0);
Long longObj = (Long) obj;
int count = longObj.intValue();
return count;
}

@Override
public int getCountByGoodsName(String goodsName) {
DetachedCriteria criteria = DetachedCriteria.forClass(Goods.class);

criteria.add(Restrictions.like("goodsName", "%"+goodsName+"%"));
criteria.setProjection(Projections.rowCount());

Object obj = template.findByCriteria(criteria).get(0);
Long longObj = (Long) obj;
int count = longObj.intValue();
return count;
}

@Override
public int getCountByMerchantId(int merchantId) {
DetachedCriteria criteria = DetachedCriteria.forClass(Goods.class);

Merchant merchant = new Merchant();
merchant.setId(merchantId);
criteria.add(Restrictions.eq("merchant", merchant));
criteria.setProjection(Projections.rowCount());

Object obj = template.findByCriteria(criteria).get(0);
Long longObj = (Long) obj;
int count = longObj.intValue();
return count;
}

@Override
public int getCountByCatId(int catId) {
DetachedCriteria criteria = DetachedCriteria.forClass(Goods.class);

GoodsCat goodsCat = new GoodsCat();
goodsCat.setId(catId);
criteria.add(Restrictions.eq("goodsCat", goodsCat));
criteria.setProjection(Projections.rowCount());

Object obj = template.findByCriteria(criteria).get(0);
Long longObj = (Long) obj;
int count = longObj.intValue();
return count;
}

@Override
public Goods findById(int id) {
DetachedCriteria criteria = DetachedCriteria.forClass(Goods.class);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/mall/admin/service/GoodsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ public interface GoodsService {

List<Goods> findByPage(int offset, int pageSize, String orderKeys);

int getCount();

int getCountByGoodsName(String goodsName);

int getCountByMerchantId(int merchantId);

int getCountByCatId(int catId);

Goods findById(int id);

int save(Goods adminUser);
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/mall/admin/service/impl/GoodsServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ public List<Goods> findByPage(int offset, int pageSize, String orderKeys) {
return goodss;
}

@Override
public int getCount() {
return goodsDao.getCount();
}

@Override
public int getCountByGoodsName(String goodsName) {
return goodsDao.getCountByGoodsName(goodsName);
}

@Override
public int getCountByMerchantId(int merchantId) {
return goodsDao.getCountByMerchantId(merchantId);
}

@Override
public int getCountByCatId(int catId) {
return goodsDao.getCountByCatId(catId);
}

@Override
public Goods findById(int id) {
Goods goods = goodsDao.findById(id);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/mall/common/UploadAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public class UploadAction extends ActionSupport {
public Map<String, Object> jsonResult;

public String upload() {
if (uploadFile == null) {
jsonResult = ResponseTemplate.error(-1, "No file!");
return SUCCESS;
}

System.out.println(this.uploadFileContentType);
System.out.println(this.uploadFileFileName);

Expand Down

0 comments on commit 0af8cd6

Please sign in to comment.