商品详情界面

pull/1/head
feijinping 3 years ago
parent 6bd7a99a83
commit 5fab6f7b6c

@ -1,12 +1,22 @@
package com.fjp.lc.test.service;
import com.cyl.ums.service.MemberCartService;
import com.ruoyi.RuoYiApplication;
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.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = RuoYiApplication.class)
@ActiveProfiles("dev")
public class ServiceTest {
@Autowired
private MemberCartService memberCartService;
@Test
public void test1() {
memberCartService.mineCartNum();
}
}

@ -0,0 +1,28 @@
package com.cyl.h5.controller;
import com.cyl.pms.domain.ProductCategory;
import com.cyl.ums.service.MemberCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/h5/cart")
public class CartController {
@Autowired
private MemberCartService memberCartService;
/**
*
*
* @return
*/
@GetMapping("goodscount")
public ResponseEntity<Integer> allCategories() {
return ResponseEntity.ok(memberCartService.mineCartNum());
}
}

@ -1,6 +1,7 @@
package com.cyl.h5.controller;
import com.cyl.h5.pojo.dto.ProductDTO;
import com.cyl.h5.pojo.vo.ProductDetail;
import com.cyl.pms.convert.ProductConvert;
import com.cyl.pms.domain.Product;
import com.cyl.pms.pojo.query.ProductQuery;
@ -10,10 +11,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -30,4 +28,9 @@ public class GoodController {
List<Product> pageRes = productService.selectList(query, page);
return ResponseEntity.ok(new PageImpl<>(productConvert.dos2dtos(pageRes), page, ((com.github.pagehelper.Page) pageRes).getTotal()));
}
@GetMapping("/detail")
public ResponseEntity<ProductDetail> queryDetail(@RequestParam Long id) {
ProductDetail detail = productService.queryDetail(id);
return ResponseEntity.ok(detail);
}
}

@ -0,0 +1,15 @@
package com.cyl.h5.pojo.vo;
import com.cyl.pms.domain.Brand;
import com.cyl.pms.domain.Product;
import com.cyl.pms.domain.Sku;
import lombok.Data;
import java.util.List;
@Data
public class ProductDetail {
private Product product;
private List<Sku> skus;
private Brand brand;
}

@ -5,16 +5,21 @@ import java.util.*;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.cyl.h5.pojo.vo.ProductDetail;
import com.cyl.pms.convert.ProductConvert;
import com.cyl.pms.domain.Brand;
import com.cyl.pms.domain.Sku;
import com.cyl.pms.mapper.BrandMapper;
import com.cyl.pms.mapper.SkuMapper;
import com.cyl.pms.pojo.vo.ProductVO;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import com.cyl.pms.mapper.ProductMapper;
import com.cyl.pms.domain.Product;
@ -35,6 +40,8 @@ public class ProductService {
@Autowired
private SkuMapper skuMapper;
@Autowired
private BrandMapper brandMapper;
@Autowired
private ProductConvert convert;
/**
@ -186,4 +193,17 @@ public class ProductService {
public int deleteById(Long id) {
return productMapper.deleteById(id);
}
public ProductDetail queryDetail(Long id) {
ProductDetail res = new ProductDetail();
Product d = productMapper.selectById(id);
res.setProduct(d);
LambdaQueryWrapper<Sku> qw = new LambdaQueryWrapper<>();
qw.eq(Sku::getProductId, id);
res.setSkus(skuMapper.selectList(qw));
if (d.getBrandId() != null) {
res.setBrand(brandMapper.selectById(d.getBrandId()));
}
return res;
}
}

@ -3,8 +3,12 @@ package com.cyl.ums.service;
import java.util.Arrays;
import java.util.List;
import java.time.LocalDateTime;
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.apache.commons.lang3.StringUtils;
@ -16,7 +20,6 @@ import com.cyl.ums.pojo.query.MemberCartQuery;
/**
* Service
*
*
* @author zcc
*/
@Service
@ -111,4 +114,17 @@ public class MemberCartService {
public int deleteById(Long id) {
return memberCartMapper.deleteById(id);
}
public Integer mineCartNum() {
Long userId = SecurityUtils.getUserId();
QueryWrapper<MemberCart> qw = new QueryWrapper<>();
qw.eq("member_id", userId);
qw.eq("status", 1);
qw.select("sum(quantity) quantity");
MemberCart c = memberCartMapper.selectOne(qw);
if (c == null) {
return 0;
}
return c.getQuantity();
}
}

Loading…
Cancel
Save