feat: 新增已有商品时,执行修改数量操作

This commit is contained in:
sdhkjh 2024-09-17 11:48:58 +08:00
parent 8f4866cc46
commit dceaafef1c
3 changed files with 63 additions and 22 deletions

View file

@ -43,13 +43,25 @@ public class ShopTradeCartController {
shopTradeCartService.queryList(inputObject, outputObject);
}
/**
* 新增购物车信息
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@ApiOperation(id = "insertShopTradeCart", value = "新增购物车信息", method = "POST", allUse = "2")
@ApiImplicitParams(classBean = ShopTradeCart.class)
@RequestMapping("/post/ShopTradeCartController/writeShopTradeCart")
@RequestMapping("/post/ShopTradeCartController/insertShopTradeCart")
public void insertShopTradeCart(InputObject inputObject, OutputObject outputObject) {
shopTradeCartService.createEntity(inputObject, outputObject);
}
/**
* 批量删除购物车信息
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@ApiOperation(id = "deleteShopTradCartByIds", value = "批量删除购物车信息", method = "DELETE", allUse = "2")
@ApiImplicitParams({
@ApiImplicitParam(id = "ids", name = "ids", value = "主键id列表多个id用逗号隔开", required = "required")})
@ -58,6 +70,12 @@ public class ShopTradeCartController {
shopTradeCartService.deleteById(inputObject, outputObject);
}
/**
* 更新购物车商品数量
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@ApiOperation(id = "changeCount", value = "更新购物车商品数量", method = "POST", allUse = "2")
@ApiImplicitParams({
@ApiImplicitParam(id = "id", name = "id", value = "主键id", required = "required"),
@ -67,6 +85,12 @@ public class ShopTradeCartController {
shopTradeCartService.changeCount(inputObject, outputObject);
}
/**
* 更新购物车商品选中
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@ApiOperation(id = "changeSelected", value = "更新购物车商品选中", method = "POST", allUse = "2")
@ApiImplicitParams({
@ApiImplicitParam(id = "id", name = "id", value = "主键id", required = "required")})
@ -75,16 +99,27 @@ public class ShopTradeCartController {
shopTradeCartService.changeSelected(inputObject, outputObject);
}
/**
* 重置购物车信息
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@ApiOperation(id = "resetShopTradeCart", value = "重置购物车信息", method = "POST", allUse = "2")
@RequestMapping("/post/ShopTradeCartController/resetShopTradeCart")
public void resetShopTradeCart(InputObject inputObject, OutputObject outputObject) {
shopTradeCartService.resetShopTradeCart(inputObject, outputObject);
}
/**
* 计算购物车总价
*
* @param inputObject 入参以及用户信息等获取对象
* @param outputObject 出参以及提示信息的返回值对象
*/
@ApiOperation(id = "calculateTotalPrices", value = "计算购物车总价", method = "POST", allUse = "2")
@RequestMapping("/post/ShopTradeCartController/calculateTotalPrices")
public void calculateTotalPrices(InputObject inputObject, OutputObject outputObject) {
shopTradeCartService.calculateTotalPrices(inputObject, outputObject);
}
}

View file

@ -38,7 +38,7 @@ public class ShopTradeCart extends OperatorUserInfo {
@TableField(exist = false)
@ApiModelProperty(value = "商品信息")
private Map<String, Object> materialMaton;
private Map<String, Object> materialMation;
@TableField("norms_id")
@ApiModelProperty(value = "规格id", required = "required")
@ -46,7 +46,7 @@ public class ShopTradeCart extends OperatorUserInfo {
@TableField(exist = false)
@ApiModelProperty(value = "規格信息")
private Map<String, Object> normsMaton;
private Map<String, Object> normsMation;
@TableField("count")
@ApiModelProperty(value = "数量", required = "required")

View file

@ -5,6 +5,7 @@
package com.skyeye.store.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@ -18,6 +19,7 @@ import com.skyeye.common.enumeration.WhetherEnum;
import com.skyeye.common.object.InputObject;
import com.skyeye.common.object.OutputObject;
import com.skyeye.common.util.CalculationUtil;
import com.skyeye.common.util.StringUtil;
import com.skyeye.common.util.mybatisplus.MybatisPlusUtil;
import com.skyeye.erp.service.IMaterialNormsService;
import com.skyeye.erp.service.IMaterialService;
@ -26,6 +28,7 @@ import com.skyeye.rest.shopmaterialnorms.sevice.IShopMaterialNormsService;
import com.skyeye.store.dao.ShopTradeCartDao;
import com.skyeye.store.entity.ShopTradeCart;
import com.skyeye.store.service.ShopTradeCartService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -55,6 +58,7 @@ public class ShopTradeCartServiceImpl extends SkyeyeBusinessServiceImpl<ShopTrad
@Override
public void validatorEntity(ShopTradeCart shopTradeCart) {
super.validatorEntity(shopTradeCart);
if (shopTradeCart.getCount() <= CommonNumConstants.NUM_ZERO) {
throw new CustomException("商品数量不能小于1");
}
@ -66,15 +70,29 @@ public class ShopTradeCartServiceImpl extends SkyeyeBusinessServiceImpl<ShopTrad
QueryWrapper<ShopTradeCart> wrapper = new QueryWrapper<>();
wrapper.eq(MybatisPlusUtil.toColumns(ShopTradeCart::getCreateId), userId);
List<ShopTradeCart> beans = list(wrapper);
iMaterialNormsService.setDataMation(beans, ShopTradeCart::getMaterialId);
iMaterialNormsService.setDataMation(beans, ShopTradeCart::getNormsId);
iMaterialService.setDataMation(beans, ShopTradeCart::getMaterialId);
return JSONUtil.toList(JSONUtil.toJsonStr(beans), null);
}
@Override
public String createEntity(ShopTradeCart shopTradeCart, String userId){
QueryWrapper<ShopTradeCart> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(MybatisPlusUtil.toColumns(ShopTradeCart::getMaterialId), shopTradeCart.getMaterialId());
queryWrapper.eq(MybatisPlusUtil.toColumns(ShopTradeCart::getNormsId), shopTradeCart.getNormsId());
ShopTradeCart one = getOne(queryWrapper);
if (ObjectUtil.isNotEmpty(one)) {
shopTradeCart.setId(one.getId());
shopTradeCart.setCount(one.getCount() + shopTradeCart.getCount());
return super.updateEntity(shopTradeCart, userId);
}
return super.createEntity(shopTradeCart, userId);
}
@Override
public void deleteById(InputObject inputObject, OutputObject outputObject) {
String ids = inputObject.getParams().get("ids").toString();
List<String> idList = Arrays.asList(ids.split(","));
List<String> idList = Arrays.asList(ids.split(CommonCharConstants.COMMA_MARK));
super.deleteById(idList);
}
@ -88,14 +106,10 @@ public class ShopTradeCartServiceImpl extends SkyeyeBusinessServiceImpl<ShopTrad
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());
}
updateWrapper.set(MybatisPlusUtil.toColumns(ShopTradeCart::getSelected),
Objects.equals(one.getSelected(), WhetherEnum.ENABLE_USING.getKey())
? WhetherEnum.DISABLE_USING.getKey() : WhetherEnum.ENABLE_USING.getKey());
update(updateWrapper);
outputObject.setBean(getOne(updateWrapper));
outputObject.settotal(CommonNumConstants.NUM_ONE);
}
@Override
@ -116,8 +130,6 @@ public class ShopTradeCartServiceImpl extends SkyeyeBusinessServiceImpl<ShopTrad
updateWrapper.set(MybatisPlusUtil.toColumns(ShopTradeCart::getCount), count - CommonNumConstants.NUM_ONE);
}
update(updateWrapper);
outputObject.setBean(getOne(updateWrapper));
outputObject.settotal(CommonNumConstants.NUM_ONE);
}
@Override
@ -125,12 +137,7 @@ public class ShopTradeCartServiceImpl extends SkyeyeBusinessServiceImpl<ShopTrad
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
@ -160,9 +167,8 @@ public class ShopTradeCartServiceImpl extends SkyeyeBusinessServiceImpl<ShopTrad
allPrice[0] = CalculationUtil.add(allPrice[0], flagPrice);
});
}
result.put("allPrice", Joiner.on(CommonCharConstants.COMMA_MARK).join(allPrice));
outputObject.setBean(result);
outputObject.settotal(CommonNumConstants.NUM_ONE);
}
}
}