Commit 1a707599 by weijiguang

恢复部分代码

parent 3f058b83
......@@ -210,15 +210,13 @@ public class ShopController extends BaseController {
return getDataTable(list);
}
@GetMapping("/getShopGoodsSpecs")
public AjaxResult getShopGoodsSpecs(Long shopId, Long goodsId) {
return AjaxResult.success(shopGoodsService.getShopGoodsSpecs(shopId, goodsId));
@GetMapping(value = "/selectSkuByShopGoods")
public AjaxResult selectSkuByShopGoods(long shopId, long goodsId) {
return AjaxResult.success(shopGoodsService.selectSkuByShopGoods(shopId, goodsId));
}
@GetMapping("/updateShopGoodsSpecState")
public AjaxResult getShopGoodsSpecs(Long shopId, Long goodsId, Long ruleId, Integer state) {
return AjaxResult.success(shopGoodsService.updateShopGoodsSpecState(shopId, goodsId, ruleId, state));
@GetMapping("/updateShopGoodsSkuState")
public AjaxResult updateShopGoodsSkuState(@RequestParam("id") Long shopGoodsSkuId, @RequestParam("state") Integer state) {
return AjaxResult.success(shopGoodsService.updateShopGoodsSkuState(shopGoodsSkuId, state));
}
}
......@@ -11,12 +11,11 @@ import java.util.Date;
/**
* 从店铺到sku关联对象 shop_goods_sku
*
*
* @author zxq
* @date 2022-04-28
*/
public class ShopGoodsSku extends BaseEntity
{
public class ShopGoodsSku extends BaseEntity {
private static final long serialVersionUID = 1L;
/** 主键 */
......@@ -66,6 +65,16 @@ public class ShopGoodsSku extends BaseEntity
*/
private BigDecimal discount;
private String ruleList;
public String getRuleList() {
return ruleList;
}
public void setRuleList(String ruleList) {
this.ruleList = ruleList;
}
public BigDecimal getOrigDiscount() {
return origDiscount;
}
......@@ -82,100 +91,90 @@ public class ShopGoodsSku extends BaseEntity
this.discount = discount;
}
public void setId(String id)
{
public void setId(String id) {
this.id = id;
}
public String getId()
{
public String getId() {
return id;
}
public void setShopId(Long shopId)
{
public void setShopId(Long shopId) {
this.shopId = shopId;
}
public Long getShopId()
{
public Long getShopId() {
return shopId;
}
public void setMachineId(String machineId)
{
public void setMachineId(String machineId) {
this.machineId = machineId;
}
public String getMachineId()
{
public String getMachineId() {
return machineId;
}
public void setGoodsId(Long goodsId)
{
public void setGoodsId(Long goodsId) {
this.goodsId = goodsId;
}
public Long getGoodsId()
{
public Long getGoodsId() {
return goodsId;
}
public void setSkuId(Long skuId)
{
public void setSkuId(Long skuId) {
this.skuId = skuId;
}
public Long getSkuId()
{
public Long getSkuId() {
return skuId;
}
public void setState(String state)
{
public void setState(String state) {
this.state = state;
}
public String getState()
{
public String getState() {
return state;
}
public void setIsDeleted(String isDeleted)
{
public void setIsDeleted(String isDeleted) {
this.isDeleted = isDeleted;
}
public String getIsDeleted()
{
public String getIsDeleted() {
return isDeleted;
}
public void setCreatedAt(Date createdAt)
{
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getCreatedAt()
{
public Date getCreatedAt() {
return createdAt;
}
public void setUpdatedAt(Date updatedAt)
{
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public Date getUpdatedAt()
{
public Date getUpdatedAt() {
return updatedAt;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("shopId", getShopId())
.append("machineId", getMachineId())
.append("goodsId", getGoodsId())
.append("skuId", getSkuId())
.append("state", getState())
.append("isDeleted", getIsDeleted())
.append("createdAt", getCreatedAt())
.append("updatedAt", getUpdatedAt())
.toString();
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("shopId", getShopId())
.append("machineId", getMachineId())
.append("goodsId", getGoodsId())
.append("skuId", getSkuId())
.append("state", getState())
.append("isDeleted", getIsDeleted())
.append("createdAt", getCreatedAt())
.append("updatedAt", getUpdatedAt())
.toString();
}
}
package com.soss.system.domain.vo;
import lombok.Data;
@Data
public class SkuCountVo {
private Integer sellin;
private Integer sellout;
}
......@@ -2,6 +2,7 @@ package com.soss.system.mapper;
import com.soss.system.domain.GoodsSku;
import com.soss.system.domain.ShopGoodsSku;
import com.soss.system.domain.vo.SkuCountVo;
import com.soss.system.domain.vo.orderTaking.SkuVo;
import org.apache.ibatis.annotations.Param;
......@@ -47,6 +48,8 @@ public interface ShopGoodsSkuMapper {
*/
public int updateShopGoodsSku(ShopGoodsSku shopGoodsSku);
int updateShopGoodsSkuState(@Param("id") Long shopGoodsSkuId, @Param("state") Integer state);
/**
* 删除从店铺到sku关联
*
......@@ -65,6 +68,8 @@ public interface ShopGoodsSkuMapper {
List<GoodsSku> selectSkuByShopAndGoods(@Param("shopId") long shopId, @Param("goodsId") long goodsId);
List<ShopGoodsSku> selectSkuByShopGoods(@Param("shopId") long shopId, @Param("goodsId") long goodsId);
List<SkuVo> selectSkuByGoodAndShop(@Param("shopId") Long shopId, @Param("goodsId") String goodId);
void deleteShopGoodsSkuByGoodsId(@Param("goodsId") Long goodsId);
......@@ -76,4 +81,6 @@ public interface ShopGoodsSkuMapper {
void updateSkuDiscount(@Param("id") Long id, @Param("discount") BigDecimal discount);
void restoreSkuDiscount(@Param("shopId") Long shopId, @Param("goodsId") Long goodsId);
SkuCountVo getSkuCount(@Param("shopId") long shopId, @Param("goodsId") long goodsId);
}
package com.soss.system.service;
import com.soss.system.domain.ShopGoods;
import com.soss.system.domain.Spec;
import com.soss.system.domain.ShopGoodsSku;
import java.util.List;
......@@ -60,7 +60,6 @@ public interface IShopGoodsService {
*/
public int deleteShopGoodsById(String id);
List<Spec> getShopGoodsSpecs(Long shopId, Long goodsId);
Boolean updateShopGoodsSpecState(Long shopId, Long goodsId, Long ruleId, Integer state);
List<ShopGoodsSku> selectSkuByShopGoods(Long shopId, Long goodsId);
Boolean updateShopGoodsSkuState(Long shopGoodsSkuId, Integer state);
}
package com.soss.system.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.soss.common.exception.ServiceException;
import com.soss.system.domain.*;
import com.soss.system.domain.vo.orderTaking.SkuVo;
import com.soss.system.domain.ShopGoods;
import com.soss.system.domain.ShopGoodsSku;
import com.soss.system.mapper.*;
import com.soss.system.service.IShopGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.stream.Collectors;
import java.util.List;
/**
* 店铺和商品关联Service业务层处理
......@@ -102,186 +97,17 @@ public class ShopGoodsServiceImpl implements IShopGoodsService {
}
@Override
public List<Spec> getShopGoodsSpecs(Long shopId, Long goodsId) {
List<SkuVo> skuVos = shopGoodsSkuMapper.selectSkuByGoodAndShop(shopId, goodsId.toString());
if (CollectionUtils.isEmpty(skuVos)) {
return null;
}
Map<String, List<SkuVo>> skuMap = skuVos.stream().collect(Collectors.groupingBy(SkuVo::getState));
if (CollectionUtils.isEmpty(skuMap)) {
return null;
}
Set<Long> selloutRules = new HashSet<>();
Set<Long> sellinRules = new HashSet<>();
List<SkuVo> selloutSkus = skuMap.get("2");
if (!CollectionUtils.isEmpty(selloutSkus)) {
selloutSkus.forEach(skuVo -> {
List<SpecRule> rules = JSON.parseArray(skuVo.getRulesString(), SpecRule.class);
if (!CollectionUtils.isEmpty(rules)) {
rules.forEach(rule -> selloutRules.add(rule.getId()));
}
});
}
List<SkuVo> sellinSkus = skuMap.get("1");
if (!CollectionUtils.isEmpty(sellinSkus)) {
sellinSkus.forEach(skuVo -> {
List<SpecRule> rules = JSON.parseArray(skuVo.getRulesString(), SpecRule.class);
if (!CollectionUtils.isEmpty(rules)) {
rules.forEach(rule -> sellinRules.add(rule.getId()));
}
});
}
// 从售罄sku选项列表中删除 未售罄sku选项
sellinRules.forEach(sellinId -> selloutRules.remove(sellinId));
Goods goods = goodsMapper.selectGoodsById(goodsId);
if (goods == null) {
return null;
}
List<Spec> specs = JSONArray.parseArray(goods.getSpec(), Spec.class);
if (CollectionUtils.isEmpty(specs)) {
return specs;
}
specs.forEach(spec -> {
List<SpecRule> rules = spec.getSpecRules();
if (CollectionUtils.isEmpty(rules)) {
return;
}
rules.forEach(rule -> {
if (sellinRules.contains(rule.getId())) {
rule.setState(1);
} else {
rule.setState(0);
}
});
});
// Map<Long, List<SpecRule>> selloutRulesBySpec = selloutRules.values().stream().collect(Collectors.groupingBy(SpecRule::getSpecId));
// Map<Long, List<SpecRule>> sellinRulesBySpec = sellinRules.values().stream().collect(Collectors.groupingBy(SpecRule::getSpecId));
//
// List<Long> specIds = new ArrayList<>();
// specIds.addAll(sellinRules.values().stream().map(SpecRule::getSpecId).collect(Collectors.toList()));
// specIds.addAll(selloutRules.values().stream().map(SpecRule::getSpecId).collect(Collectors.toList()));
//
// // 构建返回数据
// List<Spec> specVos = specMapper.selectSpecByIds(specIds);
// if (CollectionUtils.isEmpty(specVos)) {
// return null;
// }
// specVos.forEach(spec -> {
// if (CollectionUtils.isEmpty(spec.getSpecRules())) {
// spec.setSpecRules(new ArrayList<>());
// }
// if (!CollectionUtils.isEmpty(sellinRulesBySpec.get(spec.getId()))) {
// spec.getSpecRules().addAll(sellinRulesBySpec.get(spec.getId()));
// }
// if (!CollectionUtils.isEmpty(selloutRulesBySpec.get(spec.getId()))) {
// spec.getSpecRules().addAll(selloutRulesBySpec.get(spec.getId()));
// }
// });
return specs;
public List<ShopGoodsSku> selectSkuByShopGoods(Long shopId, Long goodsId) {
List<ShopGoodsSku> skus = shopGoodsSkuMapper.selectSkuByShopGoods(shopId, goodsId);
return skus;
}
public Boolean updateShopGoodsSpecState(Long shopId, Long goodsId, Long ruleId, Integer state) {
if (shopId == null || shopId <= 0) {
throw new ServiceException("店铺id错误");
}
if (goodsId == null || goodsId <= 0) {
throw new ServiceException("商品id错误");
}
if (ruleId == null || ruleId <= 0) {
throw new ServiceException("选项id错误");
}
if (state == null) {
throw new ServiceException("状态不能为空");
}
if (state != 1 && state != 2) {
throw new ServiceException("状态错误,1-2");
}
List<SkuVo> skuVos = shopGoodsSkuMapper.selectSkuByGoodAndShop(shopId, goodsId.toString());
if (CollectionUtils.isEmpty(skuVos)) {
return false;
}
// 本店铺本商品 所有规格,选项状态
List<Spec> specs = getShopGoodsSpecs(shopId, goodsId);
if (CollectionUtils.isEmpty(specs)) {
return false;
}
// 包含本次修改选项的sku列表
List<String> skuIds = new ArrayList<>();
skuVos.forEach(skuVo -> {
List<SpecRule> rules = JSON.parseArray(skuVo.getRulesString(), SpecRule.class);
if (CollectionUtils.isEmpty(rules)) {
return;
}
rules.forEach(rule -> {
// 判断本sku是否包含本次修改的选项
if (rule.getId() == ruleId) {
if (existsOtherSellout(skuVo, specs, ruleId)) {
// 除本次修改选项外,本商品还有其它售罄选项
return;
}
skuIds.add(skuVo.getSkuId().toString());
}
});
});
if (CollectionUtils.isEmpty(skuIds)) {
return true;
}
int i = shopGoodsSkuMapper.updateSkuStatus(skuIds, "0", String.valueOf(shopId), String.valueOf(state));
//推送给极光
List<Machine> machines = machineMapper.selectMachineByShopId(shopId);
if (CollectionUtils.isEmpty(machines)) {
@Override
public Boolean updateShopGoodsSkuState(Long shopGoodsSkuId, Integer state) {
int i = shopGoodsSkuMapper.updateShopGoodsSkuState(shopGoodsSkuId, state);
if (i > 0) {
return true;
}
List<Long> longSkuIds = skuIds.stream().map(x -> Long.parseLong(x)).collect(Collectors.toList());
Machine machine = machines.get(0);
Map<Long, List<Long>> map = new HashMap<>();
map.put(goodsId, longSkuIds);
machineApiService.push(machine, String.valueOf(state), map);
return true;
}
/** 判断除本次修改选项外,本商品还有其它售罄选项 */
private boolean existsOtherSellout(SkuVo skuVo, List<Spec> specs, long ruleId) {
List<Long> selloutRuleIds = new ArrayList<>();
for (Spec spec : specs) {
for (SpecRule rule : spec.getSpecRules()) {
if (rule.getState() == 1) {
continue;
}
if (rule.getId() == ruleId) {
continue;
}
selloutRuleIds.add(rule.getId());
}
}
// 没有其它售罄选项
if (CollectionUtils.isEmpty(selloutRuleIds)) {
return false;
}
// 有其它售罄选项,判断本商品是否包含其它售罄选项
List<SpecRule> rules = JSON.parseArray(skuVo.getRulesString(), SpecRule.class);
for (SpecRule rule : rules) {
if (selloutRuleIds.contains(rule.getId())) {
return true;
}
}
return false;
}
}
......@@ -10,6 +10,7 @@ import com.soss.common.enums.SkuDeleteState;
import com.soss.common.exception.ServiceException;
import com.soss.common.utils.StringUtils;
import com.soss.system.domain.*;
import com.soss.system.domain.vo.SkuCountVo;
import com.soss.system.domain.vo.orderTaking.*;
import com.soss.system.jiguang.impl.JiGuangPushServiceImpl;
import com.soss.system.mapper.*;
......@@ -281,22 +282,11 @@ public class ShopServiceImpl implements IShopService {
}
}
List<Spec> specs = shopGoodsService.getShopGoodsSpecs(shopId, goods.getId());
if (CollectionUtils.isEmpty(specs)) {
goods.setSelloutCount(0);
goods.setSkuCount(0);
SkuCountVo skuCountVo = shopGoodsSkuMapper.getSkuCount(shopId, goods.getId());
if (skuCountVo != null) {
goods.setSelloutCount(skuCountVo.getSellout());
goods.setSkuCount(skuCountVo.getSellout() + skuCountVo.getSellin());
}
specs.forEach(spec -> {
if (CollectionUtils.isEmpty(spec.getSpecRules())) {
return;
}
spec.getSpecRules().forEach(rule -> {
goods.setSkuCount(goods.getSkuCount() + 1);
if (rule.getState() == 0) {
goods.setSelloutCount(goods.getSelloutCount() + 1);
}
});
});
ShopRecommend shopRecommend = new ShopRecommend();
shopRecommend.setShopId(String.valueOf(shopId));
......
......@@ -81,6 +81,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where id = #{id}
</update>
<update id="updateShopGoodsSkuState" >
update shop_goods_sku set `state`= #{state} where id = #{id}
</update>
<delete id="deleteShopGoodsSkuById" parameterType="String">
delete from shop_goods_sku where id = #{id}
</delete>
......@@ -98,6 +102,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select gs.* from shop_goods_sku sgs ,goods_sku gs where gs.id =sgs.sku_id and gs.is_deleted ='0'
and sgs.goods_id =#{goodsId} and shop_id =#{shopId}
</select>
<select id="selectSkuByShopGoods" resultType="ShopGoodsSku">
select sgs.*,gs.rule_list from shop_goods_sku sgs
left join goods_sku gs on sgs.sku_id = gs.id
where sgs.goods_id =#{goodsId} and shop_id =#{shopId}
</select>
<select id="selectSkuByGoodAndShop" resultType="com.soss.system.domain.vo.orderTaking.SkuVo">
select
sgs.id as id,
......@@ -145,4 +154,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
</delete>
<select id="getSkuCount" resultType="SkuCountVo">
select
sum(case when `state`=1 then 1 else 0 end) sellin,
sum(case when `state`=2 then 1 else 0 end) sellout
from shop_goods_sku where shop_id=#{shopId} and goods_id=#{goodsId}
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment