feat: 简化wall的点赞代码,shop增加shop_reande_cart表

This commit is contained in:
sdhkjh 2024-09-08 20:33:07 +08:00
parent aabaae1090
commit 50e5ebb2cf
6 changed files with 312 additions and 3 deletions

View file

@ -0,0 +1,81 @@
package com.skyeye.store.controller;
import com.skyeye.annotation.api.Api;
import com.skyeye.annotation.api.ApiImplicitParam;
import com.skyeye.annotation.api.ApiImplicitParams;
import com.skyeye.annotation.api.ApiOperation;
import com.skyeye.common.object.InputObject;
import com.skyeye.common.object.OutputObject;
import com.skyeye.store.entity.ShopTradeCart;
import com.skyeye.store.service.ShopTradeCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @ClassName: ShopAreaController
* @Description: 购物车管理控制类
* @author: skyeye云系列--卫志强
* @date: 2022/2/4 10:06
* @Copyright: 2021 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
* 注意本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
*/
@RestController
@Api(value = "购物车管理", tags = "购物车管理", modelName = "购物车管理")
public class ShopTradeCartController {
@Autowired
private ShopTradeCartService shopTradeCartService;
/**
* 获取购物车信息
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@ApiOperation(id = "queryMyShopTradeCartList", value = "获取购物车信息", method = "POST", allUse = "2")
@RequestMapping("/post/ShopTradeCartController/queryMyShopTradeCartList")
public void queryShopTradeCartList(InputObject inputObject, OutputObject outputObject) {
shopTradeCartService.queryMyShopTradeCartList(inputObject, outputObject);
}
@ApiOperation(id = "writeShopTradeCart", value = "新增/修改购物车信息", method = "POST", allUse = "2")
@ApiImplicitParams(classBean = ShopTradeCart.class)
@RequestMapping("/post/ShopTradeCartController/writeShopTradeCart")
public void insertShopTradeCart(InputObject inputObject, OutputObject outputObject) {
shopTradeCartService.saveOrUpdateEntity(inputObject, outputObject);
}
@ApiOperation(id = "deleteShopTradCartByIds", value = "批量删除购物车信息", method = "DELETE", allUse = "2")
@ApiImplicitParams({
@ApiImplicitParam(id = "ids", name = "ids", value = "主键id列表", required = "required")})
@RequestMapping("/post/ShopTradeCartController/deleteShopTradCartByIds")
public void deleteShopTradCartByIds(InputObject inputObject, OutputObject outputObject) {
shopTradeCartService.deleteByIds(inputObject, outputObject);
}
@ApiOperation(id = "changeCount", value = "更新购物车商品数量", method = "POST", allUse = "2")
@ApiImplicitParams({
@ApiImplicitParam(id = "id", name = "id", value = "主键id", required = "required"),
@ApiImplicitParam(id = "sign", name = "sign", value = "修改标志0为减少1为增加", required = "required")})
@RequestMapping("/post/ShopTradeCartController/changeCount")
public void changeCount(InputObject inputObject, OutputObject outputObject) {
shopTradeCartService.changeCount(inputObject, outputObject);
}
@ApiOperation(id = "changeSelected", value = "更新购物车商品选中", method = "POST", allUse = "2")
@ApiImplicitParams({
@ApiImplicitParam(id = "id", name = "id", value = "主键id", required = "required")})
@RequestMapping("/post/ShopTradeCartController/changeSelected")
public void changeSelected(InputObject inputObject, OutputObject outputObject) {
shopTradeCartService.changeSelected(inputObject, outputObject);
}
@ApiOperation(id = "resetShopTradeCart", value = "重置购物车信息", method = "POST", allUse = "2")
@RequestMapping("/post/ShopTradeCartController/resetShopTradeCart")
public void resetShopTradeCart(InputObject inputObject, OutputObject outputObject) {
shopTradeCartService.resetShopTradeCart(inputObject, outputObject);
}
}

View file

@ -0,0 +1,15 @@
package com.skyeye.store.dao;
import com.skyeye.eve.dao.SkyeyeBaseMapper;
import com.skyeye.store.entity.ShopTradeCart;
/**
* @ClassName: ShopTradeCartDao
* @Description: 购物车管理数据接口层
* @author: skyeye云系列--卫志强
* @date: 2022/2/4 10:07
* @Copyright: 2021 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
* 注意本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
*/
public interface ShopTradeCartDao extends SkyeyeBaseMapper<ShopTradeCart> {
}

View file

@ -0,0 +1,44 @@
package com.skyeye.store.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.skyeye.annotation.api.ApiModel;
import com.skyeye.annotation.api.ApiModelProperty;
import com.skyeye.common.entity.features.OperatorUserInfo;
import lombok.Data;
/**
* @ClassName: ShopTradeCart
* @Description: 品牌管理实体类
* @author: skyeye云系列--卫志强
* @date: 2022/2/4 10:12
* @Copyright: 2021 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
* 注意本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
*/
@Data
@TableName(value = "Shop_trade_cart")
@ApiModel("购物车管理实体类")
public class ShopTradeCart extends OperatorUserInfo {
@TableId("id")
@ApiModelProperty("主键id。为空时新增不为空时编辑")
private String id;
@TableField("material_id")
@ApiModelProperty(value = "商品id", required = "required")
private String materialId;
@TableField("norms_id")
@ApiModelProperty(value = "规格id", required = "required")
private String normsId;
@TableField("count")
@ApiModelProperty(value = "数量", required = "required")
private Integer count;
@TableField("selected")
@ApiModelProperty(value = "是否选中", required = "required")
private Integer selected;
}

View file

@ -0,0 +1,26 @@
package com.skyeye.store.service;
import com.skyeye.base.business.service.SkyeyeBusinessService;
import com.skyeye.common.object.InputObject;
import com.skyeye.common.object.OutputObject;
import com.skyeye.store.entity.ShopTradeCart;
/**
* @ClassName: ShopTradeCartService
* @Description: 购物车管理服务接口层
* @author: skyeye云系列--卫志强
* @date: 2022/2/4 10:07
* @Copyright: 2021 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
* 注意本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
*/
public interface ShopTradeCartService extends SkyeyeBusinessService<ShopTradeCart> {
void queryMyShopTradeCartList(InputObject inputObject, OutputObject outputObject);
void changeSelected(InputObject inputObject, OutputObject outputObject);
void changeCount(InputObject inputObject, OutputObject outputObject);
void resetShopTradeCart(InputObject inputObject, OutputObject outputObject);
void deleteByIds(InputObject inputObject, OutputObject outputObject);
}

View file

@ -0,0 +1,142 @@
package com.skyeye.store.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.skyeye.annotation.service.SkyeyeService;
import com.skyeye.base.business.service.impl.SkyeyeBusinessServiceImpl;
import com.skyeye.common.constans.CommonConstants;
import com.skyeye.common.constans.CommonNumConstants;
import com.skyeye.common.enumeration.WhetherEnum;
import com.skyeye.common.object.InputObject;
import com.skyeye.common.object.OutputObject;
import com.skyeye.common.util.mybatisplus.MybatisPlusUtil;
import com.skyeye.exception.CustomException;
import com.skyeye.store.dao.ShopTradeCartDao;
import com.skyeye.store.entity.ShopTradeCart;
import com.skyeye.store.service.ShopTradeCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
/**
* @ClassName: ShopTradeCartServiceImpl
* @Description: 购物车管理服务层
* @author: skyeye云系列--卫志强
* @date: 2022/2/4 10:07
* @Copyright: 2021 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
* 注意本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
*/
@Service
@SkyeyeService(name = "购物车管理", groupName = "购物车管理")
public class ShopTradeCartServiceImpl extends SkyeyeBusinessServiceImpl<ShopTradeCartDao, ShopTradeCart> implements ShopTradeCartService {
@Autowired
private ShopTradeCartService shopTradeCartService;
@Override
public void validatorEntity(ShopTradeCart shopTradeCart) {
if (shopTradeCart.getCount() <= CommonNumConstants.NUM_ZERO) {
throw new CustomException("商品数量不能小于1");
}
}
@Override
public void queryMyShopTradeCartList(InputObject inputObject, OutputObject outputObject) {
String userId = InputObject.getLogParamsStatic().get("id").toString();
QueryWrapper<ShopTradeCart> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(MybatisPlusUtil.toColumns(ShopTradeCart::getCreateId), userId);
List<Map<String, Object>> mapList = listMaps(queryWrapper);
Map<String, Object> priceAndNum = new HashMap<>();
final Long[] sum = {0L};
final int[] allCount = {0};
mapList.forEach(map -> {
String normsId = map.get("norms_id").toString();
int count = (int) map.get("count");
//通过normsId获得单个商品的价格
Long flag = 10L;
//--------------------
sum[0] = sum[0] + flag;
allCount[0] = allCount[0] + count;
});
priceAndNum.put("price", sum[0]);
priceAndNum.put("allCount", allCount[0]);
mapList.add(priceAndNum);
outputObject.setBeans(mapList);
outputObject.settotal(mapList.size());
}
@Override
public void changeSelected(InputObject inputObject, OutputObject outputObject) {
String userId = InputObject.getLogParamsStatic().get("id").toString();
String id = inputObject.getParams().get("id").toString();
UpdateWrapper<ShopTradeCart> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq(CommonConstants.ID, id);
ShopTradeCart one = getOne(updateWrapper);
if (!userId.equals(one.getCreateId())) {
throw new CustomException("无权限!");
}
if (Objects.equals(one.getSelected(), WhetherEnum.ENABLE_USING.getKey())) {
updateWrapper.set(MybatisPlusUtil.toColumns(ShopTradeCart::getSelected), WhetherEnum.DISABLE_USING.getKey());
} else {
updateWrapper.set(MybatisPlusUtil.toColumns(ShopTradeCart::getSelected), WhetherEnum.ENABLE_USING.getKey());
}
update(updateWrapper);
outputObject.setBean(getOne(updateWrapper));
outputObject.settotal(CommonNumConstants.NUM_ONE);
}
@Override
public void changeCount(InputObject inputObject, OutputObject outputObject) {
Map<String, Object> params = inputObject.getParams();
String id = params.get("id").toString();
Integer sign = Integer.parseInt(params.get("sign").toString());
UpdateWrapper<ShopTradeCart> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq(CommonConstants.ID, id);
ShopTradeCart one = getOne(updateWrapper);
Integer count = one.getCount();
if (Objects.equals(sign, CommonNumConstants.NUM_ONE)) {
updateWrapper.set(MybatisPlusUtil.toColumns(ShopTradeCart::getCount), count + CommonNumConstants.NUM_ONE);
} else {
if (count <= CommonNumConstants.NUM_ONE) {
throw new CustomException("商品数量不能小于1");
}
updateWrapper.set(MybatisPlusUtil.toColumns(ShopTradeCart::getCount), count - CommonNumConstants.NUM_ONE);
}
update(updateWrapper);
outputObject.setBean(getOne(updateWrapper));
outputObject.settotal(CommonNumConstants.NUM_ONE);
}
@Override
public void resetShopTradeCart(InputObject inputObject, OutputObject outputObject) {
String userId = InputObject.getLogParamsStatic().get("id").toString();
QueryWrapper<ShopTradeCart> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(MybatisPlusUtil.toColumns(ShopTradeCart::getCreateId), userId);
List<ShopTradeCart> list = list(queryWrapper);
remove(queryWrapper);
List<String> idCollect = list.stream()
.map(ShopTradeCart::getId).collect(Collectors.toList());
outputObject.setBeans(idCollect);
outputObject.settotal(idCollect.size());
}
@Override
public void deleteByIds(InputObject inputObject, OutputObject outputObject) {
String userId = InputObject.getLogParamsStatic().get("id").toString();
String ids = inputObject.getParams().get("ids").toString();
List<String> idList = Arrays.asList(ids.split(","));
QueryWrapper<ShopTradeCart> queryWrapper = new QueryWrapper<>();
queryWrapper.in(CommonConstants.ID, idList);
List<ShopTradeCart> list = list(queryWrapper);
List<ShopTradeCart> MyCartIds = list.stream().filter(
shopTradeCart -> shopTradeCart.getCreateId().equals(userId)
).collect(Collectors.toList());
if (MyCartIds.size() == list.size()) {
shopTradeCartService.deleteById(idList);
} else {
throw new CustomException("存在无权限信息");
}
}
}

View file

@ -58,7 +58,7 @@ public class UpvoteServiceImpl extends SkyeyeBusinessServiceImpl<UpvoteDao, Upvo
}
} else {
if (estimateAddOrCancel(upvote)) {
addUpvotePost(upvote, userId);
addUpvotePost(upvote);
} else {
updateUpvotePost(upvote);
}
@ -78,8 +78,9 @@ public class UpvoteServiceImpl extends SkyeyeBusinessServiceImpl<UpvoteDao, Upvo
return false;
}
public void addUpvotePost(Upvote upvote, String userId) {
upvoteService.createEntity(upvote, userId);
public void addUpvotePost(Upvote upvote) {
upvote.setCreateTime(DateUtil.getYmdTimeAndToString());
upvoteService.createEntity(upvote, StrUtil.EMPTY);
postService.updateUpvoteCount(upvote.getObjectId(), String.valueOf(getUpvoteNum(upvote.getObjectId())));
}