refactor project

This commit is contained in:
Cauchy
2023-10-19 15:04:31 +08:00
parent 19a2ef58a9
commit 1994ba60ae
35 changed files with 274 additions and 226 deletions

View File

@@ -93,7 +93,7 @@ public class BookController {
wrapper.eq(ShopProductToLabelEntity::getDelFlag,0);
List<Integer> pIds = shopProductToLabelService.getBaseMapper().selectList(wrapper).stream().map(ShopProductToLabelEntity::getProductId).collect(Collectors.toList());
List<ShopProductEntity> shopProductEntities = shopProductService.getBaseMapper().selectList(new LambdaQueryWrapper<ShopProductEntity>().in(ShopProductEntity::getProductId, pIds));
List<ShopProduct> shopProductEntities = shopProductService.getBaseMapper().selectList(new LambdaQueryWrapper<ShopProduct>().in(ShopProduct::getProductId, pIds));
return R.ok().put("Products",shopProductEntities);
}
@@ -177,10 +177,10 @@ public class BookController {
String publisherId = book.getPublisherId();
String[] publisherIds = publisherId.split(",");
List<String> publisherList = Arrays.asList(publisherIds);
List<PublisherEntity> publisherEntities = publisherService.getBaseMapper().selectList(new QueryWrapper<PublisherEntity>().in("id", publisherList));
List<Publisher> publisherEntities = publisherService.getBaseMapper().selectList(new QueryWrapper<Publisher>().in("id", publisherList));
for (PublisherEntity publisherEntity : publisherEntities) {
publisherName += "," + publisherEntity.getPublisherName();
for (Publisher publisher : publisherEntities) {
publisherName += "," + publisher.getPublisherName();
}
publisherName = publisherName.startsWith(",") ? publisherName.substring(1) : publisherName;
@@ -553,10 +553,10 @@ public class BookController {
String publisherId = book.getPublisherId();
String[] publisherIds = publisherId.split(",");
List<String> publisherList = Arrays.asList(publisherIds);
List<PublisherEntity> publisherEntities = publisherService.getBaseMapper().selectList(new QueryWrapper<PublisherEntity>().in("id", publisherList));
List<Publisher> publisherEntities = publisherService.getBaseMapper().selectList(new QueryWrapper<Publisher>().in("id", publisherList));
for (PublisherEntity publisherEntity : publisherEntities) {
publisherName += "," + publisherEntity.getPublisherName();
for (Publisher publisher : publisherEntities) {
publisherName += "," + publisher.getPublisherName();
}
publisherName = publisherName.startsWith(",") ? publisherName.substring(1) : publisherName;
@@ -594,10 +594,10 @@ public class BookController {
String publisherId = book.getPublisherId();
String[] publisherIds = publisherId.split(",");
List<String> publisherList = Arrays.asList(publisherIds);
List<PublisherEntity> publisherEntities = publisherService.getBaseMapper().selectList(new QueryWrapper<PublisherEntity>().in("id", publisherList));
List<Publisher> publisherEntities = publisherService.getBaseMapper().selectList(new QueryWrapper<Publisher>().in("id", publisherList));
for (PublisherEntity publisherEntity : publisherEntities) {
publisherName += "," + publisherEntity.getPublisherName();
for (Publisher publisher : publisherEntities) {
publisherName += "," + publisher.getPublisherName();
}
publisherName = publisherName.startsWith(",") ? publisherName.substring(1) : publisherName;
@@ -634,10 +634,10 @@ public class BookController {
String publisherId = book.getPublisherId();
String[] publisherIds = publisherId.split(",");
List<String> publisherList = Arrays.asList(publisherIds);
List<PublisherEntity> publisherEntities = publisherService.getBaseMapper().selectList(new QueryWrapper<PublisherEntity>().in("id", publisherList));
List<Publisher> publisherEntities = publisherService.getBaseMapper().selectList(new QueryWrapper<Publisher>().in("id", publisherList));
for (PublisherEntity publisherEntity : publisherEntities) {
publisherName += "," + publisherEntity.getPublisherName();
for (Publisher publisher : publisherEntities) {
publisherName += "," + publisher.getPublisherName();
}
publisherName = publisherName.startsWith(",") ? publisherName.substring(1) : publisherName;

View File

@@ -377,10 +377,10 @@ public class BookForumArticlesServiceController {
String publisherId = bookentity.getPublisherId();
String[] publisherIds = publisherId.split(",");
List<String> publisherList = Arrays.asList(publisherIds);
List<PublisherEntity> publisherEntities = publisherService.getBaseMapper().selectList(new QueryWrapper<PublisherEntity>().in("id", publisherList));
List<Publisher> publisherEntities = publisherService.getBaseMapper().selectList(new QueryWrapper<Publisher>().in("id", publisherList));
for (PublisherEntity publisherEntity : publisherEntities) {
publisherName += "," + publisherEntity.getPublisherName();
for (Publisher publisher : publisherEntities) {
publisherName += "," + publisher.getPublisherName();
}
publisherName = publisherName.startsWith(",") ? publisherName.substring(1) : publisherName;
bookForumArticlesVO.setBookid(String.valueOf(bookid1));

View File

@@ -79,15 +79,15 @@ public class BuyOrderController {
private SysConfigService sysConfigService;
/**
* 列表
* 订单列表
*
* @param params
* @return
* @throws Exception
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params) throws Exception {
if ("all".equals(params.get("orderStatus"))) {
params.remove("orderStatus");
}
PageUtils page = buyOrderService.queryPage(params);
PageUtils page = buyOrderService.list(params);
return R.ok().put("page", page);
}
@@ -108,7 +108,7 @@ public class BuyOrderController {
for (BuyOrderDetail buyOrderDetail : buyOrderDetails) {
Integer productId = buyOrderDetail.getProductId();
int quantity = buyOrderDetail.getQuantity();
ShopProductEntity product = shopProductService.getById(productId);
ShopProduct product = shopProductService.getById(productId);
BigDecimal price = getRealPrice(product);
if (!handleStock(buyOrderDetail, product)) {
return R.error(500, "库存不足");
@@ -137,7 +137,8 @@ public class BuyOrderController {
vo = userAddressService.getAddressName(vo, userAddress.getRegionCode());
buyOrder.setProvince(vo.getProvince());
buyOrder.setCity(vo.getCity());
buyOrder.setDistrict(vo.getCity());
buyOrder.setDistrict(vo.getCounty());
buyOrder.setAddress(vo.getDetailAddress());
buyOrderService.save(buyOrder);
for (BuyOrderDetail buyOrderDetail : buyOrderDetails) {
@@ -187,7 +188,7 @@ public class BuyOrderController {
List<ProductRequestVo> products = vo.getProducts();
BigDecimal totalWeight = new BigDecimal(0);
for (ProductRequestVo product : products) {
ShopProductEntity shopProduct = shopProductService.getById(product.getProductId());
ShopProduct shopProduct = shopProductService.getById(product.getProductId());
BigDecimal weight = BigDecimal.valueOf(Double.valueOf(shopProduct.getWeight()) / 1000.0);
totalWeight = totalWeight.add(weight.multiply(new BigDecimal(product.getQuantity())));
}
@@ -204,7 +205,7 @@ public class BuyOrderController {
*/
@RequestMapping("/getMyOrderList")
public R getMyOrderList(@RequestParam Map<String, Object> params) {
PageUtils page = buyOrderService.queryPage1(params);
PageUtils page = buyOrderService.getMyOrderList(params);
return R.ok().put("page", page);
}
@@ -251,7 +252,7 @@ public class BuyOrderController {
.eq("order_id", byId.getOrderId()));
for (BuyOrderDetail buyOrderDetailEntity : buyOrderDetailEntities) {
Integer productId = buyOrderDetailEntity.getProductId();
ShopProductEntity product = shopProductService.getById(productId);
ShopProduct product = shopProductService.getById(productId);
product.setProductStock(product.getProductStock() + buyOrderDetailEntity.getQuantity());
shopProductService.updateById(product);
}
@@ -319,7 +320,7 @@ public class BuyOrderController {
List<BuyOrderDetail> buyOrderDetailList = buyOrderDetailService.list(queryWrapper);
for (BuyOrderDetail buyOrderDetail : buyOrderDetailList) {
ShopProductEntity prod = shopProductService.getById(buyOrderDetail.getProductId());
ShopProduct prod = shopProductService.getById(buyOrderDetail.getProductId());
if (prod != null) {
buyOrderDetail.setImage(prod.getProductImages());
}
@@ -392,10 +393,10 @@ public class BuyOrderController {
* @param buyOrderDetailId 订单详情列表
* @return R
*/
@RequestMapping(value = "/createSplitPackages", method = RequestMethod.POST)
public R createSplitPackageOrder(@RequestParam("expressCompanyCode") String expressCompanyCode,
@RequestBody List<Integer> buyOrderDetailId) throws Exception {
buyOrderService.createSplitPackageOrder(expressCompanyCode, buyOrderDetailId);
@RequestMapping(value = "/delivery", method = RequestMethod.POST)
public R delivery(@RequestParam("expressCompanyCode") String expressCompanyCode,
@RequestBody List<Integer> buyOrderDetailId) throws Exception {
buyOrderService.delivery(expressCompanyCode, buyOrderDetailId);
return R.ok();
}
@@ -406,7 +407,7 @@ public class BuyOrderController {
* @param product 商品信息
* @return 商品实际价格
*/
private BigDecimal getRealPrice(ShopProductEntity product) {
private BigDecimal getRealPrice(ShopProduct product) {
BigDecimal activityPrice = product.getActivityPrice();
return (activityPrice == null || activityPrice.equals(BigDecimal.ZERO)) ? product.getPrice() : activityPrice;
}
@@ -418,7 +419,7 @@ public class BuyOrderController {
* @param product
* @return
*/
private boolean handleStock(BuyOrderDetail buyOrderDetail, ShopProductEntity product) {
private boolean handleStock(BuyOrderDetail buyOrderDetail, ShopProduct product) {
int quantity = buyOrderDetail.getQuantity();
if (product.getProductStock() - quantity < 0) {
return false;

View File

@@ -3,7 +3,7 @@ package com.peanut.modules.book.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.R;
import com.peanut.modules.book.entity.PublisherEntity;
import com.peanut.modules.book.entity.Publisher;
import com.peanut.modules.book.service.BookService;
import com.peanut.modules.book.service.PublisherService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -40,9 +40,9 @@ public class PublisherController {
*/
@RequestMapping("/publisherList")
public R publisherList(){
List<PublisherEntity> publisherEntities = publisherService.getBaseMapper().selectList(new QueryWrapper<PublisherEntity>());
List<Publisher> publisherEntities = publisherService.getBaseMapper().selectList(new QueryWrapper<Publisher>());
ArrayList<Object> list = new ArrayList<>();
for (PublisherEntity publisherEntitie : publisherEntities) {
for (Publisher publisherEntitie : publisherEntities) {
HashMap<Object, Object> map = new HashMap<>();
map.put("id",publisherEntitie.getId());
map.put("value",publisherEntitie.getPublisherName());
@@ -56,7 +56,7 @@ public class PublisherController {
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Integer id){
PublisherEntity publisher = publisherService.getById(id);
Publisher publisher = publisherService.getById(id);
return R.ok().put("publisher", publisher);
}
@@ -68,13 +68,13 @@ public class PublisherController {
public R appGetInfo(@PathVariable("id") Integer id,
@PathVariable("limit") String limit,
@PathVariable("page") String page){
PublisherEntity publisherEntity = publisherService.getById(id);
Publisher publisher = publisherService.getById(id);
HashMap<String, Object> map = new HashMap<>();
map.put("publisherName",publisherEntity.getPublisherName());
map.put("publisherName", publisher.getPublisherName());
map.put("limit",limit);
map.put("page",page);
PageUtils pageUtils = bookService.queryPage(map);
return R.ok().put("publisherInfo", publisherEntity).put("publisherBooks",pageUtils);
return R.ok().put("publisherInfo", publisher).put("publisherBooks",pageUtils);
}
@@ -84,7 +84,7 @@ public class PublisherController {
*/
@RequestMapping("/save")
// @RequiresPermissions("book:publisher:save")
public R save(@RequestBody PublisherEntity publisher){
public R save(@RequestBody Publisher publisher){
publisher.setDelFlag(0);
publisherService.save(publisher);
return R.ok();
@@ -94,7 +94,7 @@ public class PublisherController {
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody PublisherEntity publisher){
public R update(@RequestBody Publisher publisher){
publisherService.updateById(publisher);
return R.ok();
}

View File

@@ -111,7 +111,7 @@ public class ShopProductController {
purchasedProductIds.add(String.valueOf(buyOrderDetail.getProductId()));
}
//查询商品表并过滤已购买商品id,根据时间倒叙展示
List<ShopProductEntity> allProductEntities = shopProductService.getBaseMapper().selectList(new QueryWrapper<ShopProductEntity>()
List<ShopProduct> allProductEntities = shopProductService.getBaseMapper().selectList(new QueryWrapper<ShopProduct>()
.notIn("product_id", purchasedProductIds)
.orderByDesc("create_time")
// .notLike("book_ids",",")
@@ -120,7 +120,7 @@ public class ShopProductController {
);
List lists = new ArrayList<>();
for (ShopProductEntity product : allProductEntities) {
for (ShopProduct product : allProductEntities) {
Map<String, Object> productMap = new HashMap<>();
productMap.put("product", product);
lists.add(productMap);
@@ -137,19 +137,19 @@ public class ShopProductController {
List<ShopProductBookEntity> bookEntityList = shopProductBookService.getBaseMapper().selectList(new QueryWrapper<ShopProductBookEntity>().eq("book_id", productId));
List<Object> list = new ArrayList<>();
ArrayList<String> booklist = new ArrayList<>();
ShopProductEntity shopProductEntity = null;
ShopProduct shopProduct = null;
for (ShopProductBookEntity shopProductBookEntity : bookEntityList) {
Integer proudictId = shopProductBookEntity.getProductId();
shopProductEntity = shopProductService.getBaseMapper().selectOne(new QueryWrapper<ShopProductEntity>().eq("product_id", proudictId));
shopProduct = shopProductService.getBaseMapper().selectOne(new QueryWrapper<ShopProduct>().eq("product_id", proudictId));
Integer bookId = shopProductBookEntity.getBookId();
BookEntity byId = bookService.getById(bookId);
booklist.add(String.valueOf(bookId));
list.add(byId);
shopProductEntity.setBookidsimages(list);
shopProductEntity.setBookids(booklist);
shopProduct.setBookidsimages(list);
shopProduct.setBookids(booklist);
}
return R.ok().put("shopProduct", shopProductEntity);
return R.ok().put("shopProduct", shopProduct);
}
@@ -157,17 +157,17 @@ public class ShopProductController {
@RequestMapping("/bookinfolists/{productId}")
public R bookinfolists(@PathVariable("productId") Integer productId) {
//查询商品
ShopProductEntity shopProductEntity = shopProductService.getBaseMapper().selectOne(new QueryWrapper<ShopProductEntity>().eq("product_id", productId));
ShopProduct shopProduct = shopProductService.getBaseMapper().selectOne(new QueryWrapper<ShopProduct>().eq("product_id", productId));
ArrayList<Map<String, String>> imagesUrl = new ArrayList<Map<String, String>>();
//分类
Integer poid = shopProductEntity.getProductPid();
Integer poid = shopProduct.getProductPid();
//商品id
Integer productId1 = shopProductEntity.getProductId();
Integer productId1 = shopProduct.getProductId();
//分类信息
List<Integer> poids = shopCategoryService.findPoid(poid);
List<ShopProductBookEntity> product = shopProductBookService.getBaseMapper().selectList(new QueryWrapper<ShopProductBookEntity>()
.eq("product_id", productId1));
List<ShopProductEntity> result = new ArrayList<>();
List<ShopProduct> result = new ArrayList<>();
//获取商品id
Set<Integer> productIds = new HashSet<>();
productIds.add(productId);
@@ -181,7 +181,7 @@ public class ShopProductController {
}
}
for (Integer pId : productIds) {
ShopProductEntity proEntity = null;
ShopProduct proEntity = null;
proEntity = shopProductService.getById(pId);
List<ShopProductBookEntity> pbookEntitys = shopProductBookService.getBaseMapper().selectList(new QueryWrapper<ShopProductBookEntity>()
.eq("product_id", pId));
@@ -224,13 +224,13 @@ public class ShopProductController {
.having("count(product_id) >=" + ids.size())
);
List<ShopProductEntity> frag = new ArrayList<>();
List<ShopProduct> frag = new ArrayList<>();
//如果绑定的书为空,直接返回空值
if (ids.size() == 0) {
return R.ok();
}
for (ShopProductBookEntity spbe : ss) {
ShopProductEntity ca_sp = shopProductService.getById(spbe.getProductId());
ShopProduct ca_sp = shopProductService.getById(spbe.getProductId());
frag.add(ca_sp);
}
@@ -246,16 +246,16 @@ public class ShopProductController {
*/
@RequestMapping("/info/{productId}")
public R info(@PathVariable("productId") Integer productId) {
ShopProductEntity shopProductEntity = shopProductService.getBaseMapper().selectOne(new QueryWrapper<ShopProductEntity>().eq("product_id", productId).eq("del_flag", 0));
if (shopProductEntity == null) {
ShopProduct shopProduct = shopProductService.getBaseMapper().selectOne(new QueryWrapper<ShopProduct>().eq("product_id", productId).eq("del_flag", 0));
if (shopProduct == null) {
return R.error("该商品已下架,看看其他商品吧");
}
ArrayList<Map<String, String>> imagesUrl = new ArrayList<Map<String, String>>();
Integer poid = shopProductEntity.getProductPid();
Integer productId1 = shopProductEntity.getProductId();
Integer poid = shopProduct.getProductPid();
Integer productId1 = shopProduct.getProductId();
List<Integer> poids = shopCategoryService.findPoid(poid);
shopProductEntity.setPoids(poids);
shopProduct.setPoids(poids);
List<Object> list = new ArrayList<>();
List<Object> bookIdlist = new ArrayList<>();
ArrayList<String> booklist = new ArrayList<>();
@@ -280,10 +280,10 @@ public class ShopProductController {
}
shopProductEntity.setBookidsimages(list);
shopProductEntity.setBookids(booklist);
shopProductEntity.setShoproudIds(bookIdlist);
return R.ok().put("shopProduct", shopProductEntity).put("labels", labelList);
shopProduct.setBookidsimages(list);
shopProduct.setBookids(booklist);
shopProduct.setShoproudIds(bookIdlist);
return R.ok().put("shopProduct", shopProduct).put("labels", labelList);
}
@@ -306,7 +306,7 @@ public class ShopProductController {
for (ShopProductBookEntity shopProduct : bookIds) {
Integer shopProductId = shopProduct.getProductId();
List<ShopProductEntity> shopProductEntities = shopProductService.getBaseMapper().selectList(new QueryWrapper<ShopProductEntity>()
List<ShopProduct> shopProductEntities = shopProductService.getBaseMapper().selectList(new QueryWrapper<ShopProduct>()
.eq("product_id", shopProductId));
list.add(shopProductEntities);
}
@@ -319,7 +319,7 @@ public class ShopProductController {
* 保存
*/
@RequestMapping("/save")
public R save(@RequestBody ShopProductEntity shopProduct) {
public R save(@RequestBody ShopProduct shopProduct) {
shopProduct.setCreateTime(new Date());
@@ -351,7 +351,7 @@ public class ShopProductController {
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody ShopProductEntity shopProduct) {
public R update(@RequestBody ShopProduct shopProduct) {
//商品id
Integer productId = shopProduct.getProductId();
@@ -458,7 +458,7 @@ public class ShopProductController {
if (catId == 0) {
catId = null;
}
List<ShopProductEntity> list = shopProductService.appGetCategoryList(catId);
List<ShopProduct> list = shopProductService.appGetCategoryList(catId);
return R.ok().put("list", list);
}
@@ -467,7 +467,7 @@ public class ShopProductController {
*/
@RequestMapping("/prodSearch")
public R prodSearch() {
List<ShopProductEntity> list = shopProductService.list(new QueryWrapper<ShopProductEntity>().select("product_id,product_name"));
List<ShopProduct> list = shopProductService.list(new QueryWrapper<ShopProduct>().select("product_id,product_name"));
List<ShopProductVo> collect = list.stream().map(shopProductEntity -> {
ShopProductVo shopProductVo = new ShopProductVo();
shopProductVo.setProductId(shopProductEntity.getProductId());
@@ -483,7 +483,7 @@ public class ShopProductController {
@RequestMapping("/backProdSearch")
public R backProdSearch(@RequestParam Map<String, Object> params) {
String productName = (String) params.get("productName");
List<ShopProductEntity> list = shopProductService.list(new QueryWrapper<ShopProductEntity>()
List<ShopProduct> list = shopProductService.list(new QueryWrapper<ShopProduct>()
.like("product_name", productName));
return R.ok().put("list", list);
}

View File

@@ -1,14 +1,13 @@
package com.peanut.modules.book.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.R;
import com.peanut.modules.book.dao.ShopProductLabelDao;
import com.peanut.modules.book.dao.ShopProductToLabelDao;
import com.peanut.modules.book.entity.ShopProductEntity;
import com.peanut.modules.book.entity.ShopProduct;
import com.peanut.modules.book.entity.ShopProductLabelEntity;
import com.peanut.modules.book.entity.ShopProductToLabelEntity;
import com.peanut.modules.book.service.ShopProductLabelService;
@@ -18,7 +17,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -106,12 +104,12 @@ public class ShopProductLabelController {
@RequestMapping("/getProductsByLabel")
public R getProductsByLabel(@RequestParam Integer splId,@RequestParam Integer limit,@RequestParam Integer page){
MPJLambdaWrapper<ShopProductToLabelEntity> shopProductEntityMPJLambdaWrapper = new MPJLambdaWrapper<ShopProductToLabelEntity>();
shopProductEntityMPJLambdaWrapper.selectAll(ShopProductEntity.class);
shopProductEntityMPJLambdaWrapper.leftJoin(ShopProductEntity.class,ShopProductEntity::getProductId,ShopProductToLabelEntity::getProductId);
shopProductEntityMPJLambdaWrapper.selectAll(ShopProduct.class);
shopProductEntityMPJLambdaWrapper.leftJoin(ShopProduct.class, ShopProduct::getProductId,ShopProductToLabelEntity::getProductId);
shopProductEntityMPJLambdaWrapper.eq(ShopProductToLabelEntity::getSplId,splId);
shopProductEntityMPJLambdaWrapper.eq(ShopProductToLabelEntity::getDelFlag,0);
shopProductEntityMPJLambdaWrapper.eq(ShopProductEntity::getDelFlag,0);
Page<ShopProductEntity> shopProductEntityPage = shopProductToLabelDao.selectJoinPage(new Page<ShopProductEntity>(page, limit), ShopProductEntity.class, shopProductEntityMPJLambdaWrapper);
shopProductEntityMPJLambdaWrapper.eq(ShopProduct::getDelFlag,0);
Page<ShopProduct> shopProductEntityPage = shopProductToLabelDao.selectJoinPage(new Page<ShopProduct>(page, limit), ShopProduct.class, shopProductEntityMPJLambdaWrapper);
return R.ok().put("page",shopProductEntityPage);
}