Browse Source

更行商品排行

master
xyiege 4 years ago
parent
commit
a2d0755d26
  1. 10
      src/main/java/cn/chjyj/szwh/bean/Goods.java
  2. 6
      src/main/java/cn/chjyj/szwh/controller/admin/AdminGoodsController.java
  3. 2
      src/main/java/cn/chjyj/szwh/service/GoodsService.java
  4. 43
      src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java
  5. 2
      src/main/java/cn/chjyj/szwh/service/impl/ShopCarServiceImpl.java
  6. 9
      src/test/java/cn/chjyj/szwh/mapper/GoodsMapperTest.java
  7. 41
      src/test/java/cn/chjyj/szwh/service/GoodsServiceTest.java

10
src/main/java/cn/chjyj/szwh/bean/Goods.java

@ -13,7 +13,7 @@ public class Goods {
private Integer userId;//用户编号
private String userIslicode;//委托方isli标识码
private String username;//委托方名称
private Integer goodsDetailsId;//商品明细id
private Integer goodsDetailId;//商品明细id
private String goodsIslicode; //商品isli标识码
private String isLicode;//sliCode
private Integer saleCount;//销售量
@ -67,12 +67,12 @@ public class Goods {
this.username = username;
}
public Integer getGoodsDetailsId() {
return goodsDetailsId;
public Integer getGoodsDetailId() {
return goodsDetailId;
}
public void setGoodsDetailsId(Integer goodsDetailsId) {
this.goodsDetailsId = goodsDetailsId;
public void setGoodsDetailId(Integer goodsDetailId) {
this.goodsDetailId = goodsDetailId;
}
public String getGoodsIslicode() {

6
src/main/java/cn/chjyj/szwh/controller/admin/AdminGoodsController.java

@ -60,7 +60,7 @@ public class AdminGoodsController extends BaseController {
// 查找用户信息
User user = userService.getApiUser(goods.getUserIslicode(),token);
result.put("userinfo",user);
GoodsDetail goodsDetail = goodsDetailService.getGoodsDetailBygid(goods.getGoodsDetailsId());
GoodsDetail goodsDetail = goodsDetailService.getGoodsDetailBygid(goods.getGoodsDetailId());
}else{
throw new ChException("未查询到该标的");
@ -79,8 +79,8 @@ public class AdminGoodsController extends BaseController {
@PostMapping("/rankingList")
public JSONObject rankingList(@RequestParam(value = "type",defaultValue = "1") String type){
int itype = Integer.valueOf(type);
Map retmap = goodsService.getMapDataByTyep(itype);
jsonObject.put("data",retmap);
List retlist = goodsService.getMapDataByTyep(itype);
jsonObject.put("data",retlist);
jsonObject.put("code",200);
jsonObject.put("msg","成功");
return jsonObject;

2
src/main/java/cn/chjyj/szwh/service/GoodsService.java

@ -33,5 +33,5 @@ public interface GoodsService {
* @param type
* @return
*/
Map<String,Object> getMapDataByTyep(int type);
List getMapDataByTyep(int type);
}

43
src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java

@ -1,7 +1,9 @@
package cn.chjyj.szwh.service.impl;
import cn.chjyj.szwh.bean.Goods;
import cn.chjyj.szwh.bean.GoodsDetail;
import cn.chjyj.szwh.constant.ChConstant;
import cn.chjyj.szwh.mapper.GoodsDetailMapper;
import cn.chjyj.szwh.mapper.GoodsMapper;
import cn.chjyj.szwh.service.GoodsService;
import cn.chjyj.szwh.utils.ProperUtils;
@ -14,6 +16,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -23,6 +26,8 @@ public class GoodsServiceImpl implements GoodsService {
private static Log log = LogFactory.getLog(GoodsServiceImpl.class);
@Autowired
private GoodsMapper goodsMapper;
@Autowired
private GoodsDetailMapper goodsDetailMapper;
@Override
public List<Goods> getGoodsList(int page) {
@ -69,28 +74,52 @@ public class GoodsServiceImpl implements GoodsService {
}
@Override
public Map<String, Object> getMapDataByTyep(int type) {
public List getMapDataByTyep(int type) {
Map retmap = new HashMap();
String order="";//排序条件
String where="goods.is_deleted=0 ";//排序
String where="is_deleted=0 ";//排序
int limit=10;
// 点击量倒序
if (type==1){
where+="goods.click_count desc";
order="click_count";
}
// 销售量
if(type==2){
where+="goods.sale_count desc";
order="sale_count";
}
//推荐,just 8
if(type==3){
limit=8;
where+="goods.recommend_sort desc";
order="recommend_sort ";
where+= "and is_recommend=1";
}
return null;
// 商品结果列表
List nglist = new ArrayList();
// 排序索引
int index=0;
List<Goods> glist = goodsMapper.getGoodsByCondition(where,limit,order,"DESC");
if(glist!=null){
for(Goods g:glist){
Map<String,Object> ngmap = new HashMap<>();
GoodsDetail goodsDetail = goodsDetailMapper.getGoodsDetailBygid(g.getGoodsDetailId());
//添加内容
ngmap.put("createtime",g.getCreateTime());
ngmap.put("goods_islicode",g.getGoodsIslicode());
ngmap.put("goods_name",goodsDetail.getGoodsName());
ngmap.put("goods_status",g.getGoodsStatus());
ngmap.put("goods_type",goodsDetail.getGoodsType());
ngmap.put("id",index+1);
ngmap.put("key",g.getGoodsIslicode());
ngmap.put("recommend_sort",g.getRecommendSort());
ngmap.put("username",g.getUsername());
nglist.add(ngmap);
index++;
}
}
return nglist;
}
}

2
src/main/java/cn/chjyj/szwh/service/impl/ShopCarServiceImpl.java

@ -58,7 +58,7 @@ public class ShopCarServiceImpl implements ShopCarService {
// 检查订单是否存在
long curtimestamp= System.currentTimeMillis()/1000l;
// 检查商品库存
GoodsDetail goodsDetail = goodsDetailMapper.getGoodsDetailBygid(goods.getGoodsDetailsId());
GoodsDetail goodsDetail = goodsDetailMapper.getGoodsDetailBygid(goods.getGoodsDetailId());
if (goodsDetail!=null) {
if(goodsDetail.getStock()<0 && goodsDetail.getGoodsEntrust()==1){
// 标的库存为0,不可添加

9
src/test/java/cn/chjyj/szwh/mapper/GoodsMapperTest.java

@ -57,8 +57,11 @@ public class GoodsMapperTest {
@Test
public void getGoodsByCon(){
String wcon="is_deleted=0 order by click_count desc";
List glist = goodsMapper.getGoodsByCondition(wcon);
System.out.println(glist.size());
String wcon="is_deleted=0";
List<Goods> glist = goodsMapper.getGoodsByCondition(wcon,12,"click_count", "DESC");
for(Goods g:glist){
System.out.println(g.getId());
}
// System.out.println(glist.size());
}
}

41
src/test/java/cn/chjyj/szwh/service/GoodsServiceTest.java

@ -0,0 +1,41 @@
package cn.chjyj.szwh.service;
import cn.chjyj.szwh.bean.Goods;
import cn.chjyj.szwh.mapper.GoodsMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
import static org.junit.Assert.*;
@SpringBootTest
@RunWith(SpringRunner.class)
public class GoodsServiceTest {
@Autowired
private GoodsService goodsService;
@Test
public void getGoodsList() {
}
@Test
public void getGoodsByIsli() {
}
@Test
public void getApiGoods() {
}
@Test
public void getMapDataByTyep() {
int type=1;
List<Goods> glist = goodsService.getMapDataByTyep(type);
for(Goods g:glist){
System.out.println(g.getGoodsDetailId());
}
}
}
Loading…
Cancel
Save