diff --git a/soss-admin/src/main/java/com/soss/web/controller/coffee/AppController.java b/soss-admin/src/main/java/com/soss/web/controller/coffee/AppController.java index 564861b..a7bbfbf 100644 --- a/soss-admin/src/main/java/com/soss/web/controller/coffee/AppController.java +++ b/soss-admin/src/main/java/com/soss/web/controller/coffee/AppController.java @@ -50,13 +50,13 @@ public class AppController extends BaseController { } @RequestMapping("/getHomeOrder") - public AjaxResult getHomeOrder(HttpServletRequest request){ + public AjaxResult getHomeOrder(HttpServletRequest request,String shopId){ LoginUser loginUser = tokenService.getLoginUser(request); if(loginUser ==null){ return AjaxResult.success(); } String openId = loginUser.getOpenId(); - Map<String,String> info = orderService.getMyFristOrder(openId); + Map<String,String> info = orderService.getMyFristOrder(openId,shopId); return AjaxResult.success("操作成功",info); } @RequestMapping("/getWaitTine") diff --git a/soss-admin/src/main/java/com/soss/web/controller/coffee/GoodsController.java b/soss-admin/src/main/java/com/soss/web/controller/coffee/GoodsController.java index dcc7a83..1de6ed5 100644 --- a/soss-admin/src/main/java/com/soss/web/controller/coffee/GoodsController.java +++ b/soss-admin/src/main/java/com/soss/web/controller/coffee/GoodsController.java @@ -2,6 +2,7 @@ package com.soss.web.controller.coffee; import java.util.List; +import com.soss.common.exception.ServiceException; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -46,7 +47,12 @@ public class GoodsController extends BaseController */ @GetMapping("/putShop") public AjaxResult putShop(@RequestParam("goodsId") Long goodsId, @RequestParam("boo") boolean boo){ - return AjaxResult.success(goodsService.putShop(goodsId,boo)); + try{ + return AjaxResult.success(goodsService.putShop(goodsId,boo)); + }catch (ServiceException serviceException){ + return AjaxResult.error(99,serviceException.getMessage()); + } + } /** diff --git a/soss-admin/src/main/resources/application.yml b/soss-admin/src/main/resources/application.yml index d18e02b..b4366cd 100644 --- a/soss-admin/src/main/resources/application.yml +++ b/soss-admin/src/main/resources/application.yml @@ -101,9 +101,9 @@ weixin: # REFLC7NYqwUo9KpvvmWv sms: aliyun: - accessKeyId: - accessKeySecret: - signName: + accessKeyId: LTAI5tEBoPGkpG6qy39h9dWj + accessKeySecret: B9c9aTIG5pmHWnlaRl4gGB12qmBtB4 + signName: 深圳好饮 push: appkey: 59c9290134b359212290c075 secret: 026756e7d5688089898db088 diff --git a/soss-system/src/main/java/com/soss/system/domain/Spec.java b/soss-system/src/main/java/com/soss/system/domain/Spec.java index 22f00f9..3155d13 100644 --- a/soss-system/src/main/java/com/soss/system/domain/Spec.java +++ b/soss-system/src/main/java/com/soss/system/domain/Spec.java @@ -57,6 +57,18 @@ public class Spec extends BaseEntity @Excel(name = "规格编码") private String code; + @Override + public String getRemark() { + return remark; + } + + @Override + public void setRemark(String remark) { + this.remark = remark; + } + + private String remark; + private List<SpecRule> specRules; public List<SpecRule> getSpecRules() { diff --git a/soss-system/src/main/java/com/soss/system/mapper/GoodsMapper.java b/soss-system/src/main/java/com/soss/system/mapper/GoodsMapper.java index ced70d3..2c74352 100644 --- a/soss-system/src/main/java/com/soss/system/mapper/GoodsMapper.java +++ b/soss-system/src/main/java/com/soss/system/mapper/GoodsMapper.java @@ -2,6 +2,8 @@ package com.soss.system.mapper; import java.util.List; import com.soss.system.domain.Goods; +import com.soss.system.domain.GoodsSku; +import org.apache.ibatis.annotations.Param; /** * 商品Mapper接口 @@ -60,4 +62,10 @@ public interface GoodsMapper public int deleteGoodsByIds(String[] ids); Integer selectCount(String id); + + List<Goods> selectSpec(String query); + + List<Goods> selectSpecNoState(@Param("query") String query, @Param("state") String s); + + void updateGoodsSpec(long id); } diff --git a/soss-system/src/main/java/com/soss/system/mapper/OrderMapper.java b/soss-system/src/main/java/com/soss/system/mapper/OrderMapper.java index 047fc83..6d2f42c 100644 --- a/soss-system/src/main/java/com/soss/system/mapper/OrderMapper.java +++ b/soss-system/src/main/java/com/soss/system/mapper/OrderMapper.java @@ -74,9 +74,13 @@ public interface OrderMapper List<Order> selectOrderByShopId(@Param("status") List<String> status,@Param("shopId") String shopId); - Order selectHomeByUserId(@Param("userId") String openId,@Param("status") List<String> status); + Order selectHomeByUserId(@Param("userId") String openId, @Param("status") List<String> status, @Param("shopId") String shopId); void updateTimeOut(@Param("status") String productionCompleted,@Param("timeout") String timeout); List<Order> selectOrderByUserId(@Param("userId") String openId,@Param("status") List<String> status); + + void updateCancel(@Param("status") String unpaid, @Param("timeout") int i); + + List<Order> selectOrderByTime(@Param("status")String unpaid, @Param("timeout")int i); } diff --git a/soss-system/src/main/java/com/soss/system/schedule/OrderSchedule.java b/soss-system/src/main/java/com/soss/system/schedule/OrderSchedule.java index 8e39838..c736904 100644 --- a/soss-system/src/main/java/com/soss/system/schedule/OrderSchedule.java +++ b/soss-system/src/main/java/com/soss/system/schedule/OrderSchedule.java @@ -2,21 +2,46 @@ package com.soss.system.schedule; import com.soss.system.constants.OrderStatusConstant; import com.soss.system.domain.Order; +import com.soss.system.domain.OrderOperationLog; import com.soss.system.mapper.OrderMapper; +import com.soss.system.mapper.OrderOperationLogMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import java.util.Date; +import java.util.List; + @Component public class OrderSchedule { @Autowired private OrderMapper orderMapper; @Value("${timeout}") private String timeout; + @Autowired + private OrderOperationLogMapper operationLogMapper; @Scheduled(fixedDelay = 60*1000) private void process() { orderMapper.updateTimeOut(OrderStatusConstant.productionCompleted,timeout); + //orderMapper.updateCancel(OrderStatusConstant.Unpaid,15); + List<Order> orders = orderMapper.selectOrderByTime(OrderStatusConstant.Unpaid, 15); + if(orders!=null &&orders.size()>0){ + for (Order order : orders) { + order.setState(OrderStatusConstant.UnpaidCancel); + order.setUpdatedAt(new Date()); + orderMapper.updateOrder(order); + OrderOperationLog operationLog =new OrderOperationLog(); + operationLog.setOperationUser("系统"); + operationLog.setStatus("已取消"); + operationLog.setOrderId(String.valueOf(order.getId())); + operationLog.setContent("超时自动取消"); + operationLog.setCreateAt(new Date()); + operationLog.setOperation("取消订单"); + operationLogMapper.insertOrderOperationLog(operationLog); + } + } } + } diff --git a/soss-system/src/main/java/com/soss/system/service/impl/GoodsServiceImpl.java b/soss-system/src/main/java/com/soss/system/service/impl/GoodsServiceImpl.java index 01b1390..e33d2b2 100644 --- a/soss-system/src/main/java/com/soss/system/service/impl/GoodsServiceImpl.java +++ b/soss-system/src/main/java/com/soss/system/service/impl/GoodsServiceImpl.java @@ -98,7 +98,7 @@ public class GoodsServiceImpl implements IGoodsService @Transactional public int insertGoods(Goods goods) { - if(goods.getDiscount().compareTo(goods.getPrice())>0){ + if(goods.getDiscount().compareTo(goods.getPrice())>=0){ throw new ServiceException("折扣价不能大于等于原价"); } goods.setCode(GenerateCode.getCode("G")); @@ -261,6 +261,12 @@ public class GoodsServiceImpl implements IGoodsService @Override public String putShop(Long goodsId, boolean boo) { + GoodsSku goodsSku =new GoodsSku(); + goodsSku.setGoodsId(goodsId); + List<GoodsSku> goodsSkus = goodsSkuMapper.selectGoodsSkuList(goodsSku); + if(goodsSkus.isEmpty()){ + throw new ServiceException("商品信息不全,请修改商品"); + } Goods goods = new Goods(); goods.setId(goodsId); goods.setState("3"); diff --git a/soss-system/src/main/java/com/soss/system/service/impl/MachineApiServiceImpl.java b/soss-system/src/main/java/com/soss/system/service/impl/MachineApiServiceImpl.java index 4c37c21..208ea5d 100644 --- a/soss-system/src/main/java/com/soss/system/service/impl/MachineApiServiceImpl.java +++ b/soss-system/src/main/java/com/soss/system/service/impl/MachineApiServiceImpl.java @@ -72,7 +72,8 @@ public class MachineApiServiceImpl { shopGoodsSku.setSkuId(Long.parseLong(skuId)); List<ShopGoodsSku> shopGoodsSkus = shopGoodsSkuMapper.selectShopGoodsSkuList(shopGoodsSku); if(shopGoodsSkus.isEmpty()){ - throw new ServiceException(skuId+"不存在"); + log.info("当前sku【{}】不存在",skuId); + //throw new ServiceException(skuId+"不存在"); } for (ShopGoodsSku goodsSkus : shopGoodsSkus) { Long goodsId = goodsSkus.getGoodsId(); diff --git a/soss-system/src/main/java/com/soss/system/service/impl/OrderRefundServiceImpl.java b/soss-system/src/main/java/com/soss/system/service/impl/OrderRefundServiceImpl.java index 9bf4fe1..0c355e8 100644 --- a/soss-system/src/main/java/com/soss/system/service/impl/OrderRefundServiceImpl.java +++ b/soss-system/src/main/java/com/soss/system/service/impl/OrderRefundServiceImpl.java @@ -100,7 +100,7 @@ public class OrderRefundServiceImpl implements IOrderRefundService } // 制作中、制作完成、聚餐中、已完成 String state = order.getState(); - List<String> status = Arrays.asList(OrderStatusConstant.production,OrderStatusConstant.productionCompleted,OrderStatusConstant.Taking,OrderStatusConstant.completed); + List<String> status = Arrays.asList(OrderStatusConstant.production,OrderStatusConstant.productionCompleted,OrderStatusConstant.Taking,OrderStatusConstant.completed,OrderStatusConstant.timeout); if(OrderStatusConstant.Paid.equals(state)){ orderRefund.setRefundAmount(order.getAmount()); // 4 支付制作中 5 制作完成未取 6 取餐中 7 取餐完成 diff --git a/soss-system/src/main/java/com/soss/system/service/impl/OrderServiceImpl.java b/soss-system/src/main/java/com/soss/system/service/impl/OrderServiceImpl.java index a93b5b7..84515f7 100644 --- a/soss-system/src/main/java/com/soss/system/service/impl/OrderServiceImpl.java +++ b/soss-system/src/main/java/com/soss/system/service/impl/OrderServiceImpl.java @@ -69,6 +69,8 @@ public class OrderServiceImpl implements IOrderService private SendMessageUtils sendMessageUtils; @Autowired private OrderTakingServiceImpl orderTakingService; + @Autowired + private CustomerMapper customerMapper; @@ -243,6 +245,11 @@ public class OrderServiceImpl implements IOrderService order.setFinishTime(new Date()); orderOperationLogService.insertOrderOperationLog(order); jiGuangPushService.pushOrderState(order); + Customer customer = customerMapper.selectCustomerById(order.getUserId()); + if(!"1".equals(customer.getAllow())){ + + } + } /** @@ -426,10 +433,10 @@ public class OrderServiceImpl implements IOrderService String redisKey = "shopId"+format+shopId; RedisAtomicInteger redisAtomicInteger = new RedisAtomicInteger(redisKey,SpringUtils.getBean(StringRedisTemplate.class).getConnectionFactory()); if(0 == redisAtomicInteger.get()){ - redisAtomicInteger.set(30); + redisAtomicInteger.set((int)(1000*Math.random())); } redisAtomicInteger.expire(1, TimeUnit.DAYS); - int andIncrement = redisAtomicInteger.getAndIncrement(); + int andIncrement = redisAtomicInteger.getAndAdd(3); return key+String.format("%03d",andIncrement); } //获取订单号 @@ -495,9 +502,9 @@ public class OrderServiceImpl implements IOrderService return null; } - public Map<String,String> getMyFristOrder(String openId) { + public Map<String,String> getMyFristOrder(String openId,String shopId) { List<String> status = Arrays.asList("2","3","4","7"); - Order order = orderMapper.selectHomeByUserId(openId,status); + Order order = orderMapper.selectHomeByUserId(openId,status,shopId); if(order ==null){ return null; } diff --git a/soss-system/src/main/java/com/soss/system/service/impl/ShopRecommendServiceImpl.java b/soss-system/src/main/java/com/soss/system/service/impl/ShopRecommendServiceImpl.java index bca3820..1b46955 100644 --- a/soss-system/src/main/java/com/soss/system/service/impl/ShopRecommendServiceImpl.java +++ b/soss-system/src/main/java/com/soss/system/service/impl/ShopRecommendServiceImpl.java @@ -4,9 +4,11 @@ import java.util.Date; import java.util.List; import java.util.stream.Collectors; +import com.alibaba.fastjson.JSONObject; import com.soss.system.domain.Goods; import com.soss.system.domain.Machine; import com.soss.system.domain.ShopGoods; +import com.soss.system.jiguang.impl.JiGuangPushServiceImpl; import com.soss.system.mapper.GoodsCategoryMapper; import com.soss.system.mapper.MachineMapper; import com.soss.system.mapper.OrderMapper; @@ -33,6 +35,8 @@ public class ShopRecommendServiceImpl implements IShopRecommendService private OrderMapper orderMapper; @Autowired private GoodsCategoryMapper goodsCategoryMapper; + @Autowired + private JiGuangPushServiceImpl jiGuangPushService; /** * 查询推荐和今日特惠 @@ -78,10 +82,24 @@ public class ShopRecommendServiceImpl implements IShopRecommendService shopRecommend.setCreatedAt(new Date()); shopRecommend.setRecDate(new Date()); shopRecommendMapper.insertShopRecommend(shopRecommend); + updateApplication(Long.parseLong(shopRecommend.getShopId())); shopRecommend.setTurn(shopRecommend.getId()); return shopRecommendMapper.updateShopRecommend(shopRecommend); } + public void updateApplication(long shopId){ + Machine machine = new Machine(); + machine.setShopId(shopId); + List<Machine> machines = machineMapper.selectMachineList(machine); + if(!machines.isEmpty()){ + JSONObject jsonObject = new JSONObject(); + jsonObject.put("action","GOODS_CHANGED"); + jsonObject.put("timestamp",System.currentTimeMillis()); + jiGuangPushService.push(machines.get(0).getCode(),jsonObject); + } + + + } /** * 修改推荐和今日特惠 * @@ -166,6 +184,7 @@ public class ShopRecommendServiceImpl implements IShopRecommendService shopRecommend.setType(type); shopRecommend.setGoodsId(goodsId); ShopRecommend frist = shopRecommendMapper.selectShopRecommendList(shopRecommend).get(0); + updateApplication(Long.parseLong(shopRecommend.getShopId())); return shopRecommendMapper.deleteShopRecommendById(frist.getId()); } diff --git a/soss-system/src/main/java/com/soss/system/service/impl/ShopServiceImpl.java b/soss-system/src/main/java/com/soss/system/service/impl/ShopServiceImpl.java index 98281d1..a0a2bf2 100644 --- a/soss-system/src/main/java/com/soss/system/service/impl/ShopServiceImpl.java +++ b/soss-system/src/main/java/com/soss/system/service/impl/ShopServiceImpl.java @@ -1,22 +1,26 @@ package com.soss.system.service.impl; +import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.List; import java.util.stream.Collectors; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.soss.common.core.domain.AjaxResult; import com.soss.common.exception.ServiceException; import com.soss.common.utils.StringUtils; import com.soss.system.domain.*; +import com.soss.system.domain.vo.orderTaking.*; +import com.soss.system.jiguang.impl.JiGuangPushServiceImpl; import com.soss.system.service.IShopService; import com.soss.system.mapper.*; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cglib.core.CollectionUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; /** * 店铺Service业务层处理 @@ -48,6 +52,10 @@ public class ShopServiceImpl implements IShopService @Autowired private ShopRecommendMapper shopRecommendMapper; + @Autowired + private JiGuangPushServiceImpl jiGuangPushService; + @Autowired + private GoodsTagMapper goodsTagMapper; @@ -191,10 +199,16 @@ public class ShopServiceImpl implements IShopService shopGoodsSku.setUpdatedAt(new Date()); shopGoodsSkuMapper.insertShopGoodsSku(shopGoodsSku); } + updateApplication(machine1.getCode()); } return null; } - + public void updateApplication(String code){ + JSONObject jsonObject = new JSONObject(); + jsonObject.put("action","GOODS_CHANGED"); + jsonObject.put("timestamp",System.currentTimeMillis()); + jiGuangPushService.push(code,jsonObject); + } @Override public List<GoodsCategory> getCategoryGoods(long shopId) { @@ -312,6 +326,13 @@ public class ShopServiceImpl implements IShopService shopGoodsSkuMapper.deleteByGoodsIds(shopId,goodsIds); shopGoodsMapper.deleteByShopIdGoods(shopId,goodsIds); shopRecommendMapper.deleteByShopIdGoods(shopId,goodsIds); + Machine machine = new Machine(); + machine.setShopId(shopId); + List<Machine> machines = machineMapper.selectMachineList(machine); + if(!machines.isEmpty()){ + Machine machine1 =machines .get(0); + updateApplication(machine1.getCode()); + } return null; } @@ -356,13 +377,92 @@ public class ShopServiceImpl implements IShopService return AjaxResult.error("该产品已经不存在"); }else{ ShopGoodsSku shopGoodsSku1 = shopGoodsSkus.get(0); - if(!"1".equals(shopGoodsSku1.getState())){ - return AjaxResult.error("该产品已经告罄"); - } + JSONObject jsonObject = new JSONObject(); + jsonObject.put("state",shopGoodsSku1.getState()); + Goods goods = goodsMapper.selectGoodsById(String.valueOf(shopGoodsSku1.getGoodsId())); + jsonObject.put("goods",getGoodsVo(goods,shopGoodsSku1.getShopId())); + AjaxResult.success(jsonObject); } return AjaxResult.success(); } + + public GoodsVo getGoodsVo(Goods good,Long shopId){ + GoodsVo goodsVo =new GoodsVo(); + goodsVo.setGoodsId(String.valueOf(good.getId())); + goodsVo.setName(good.getName()); + goodsVo.setDesc(good.getDesc()); + goodsVo.setDiscount(good.getDiscount().stripTrailingZeros().toPlainString()); + goodsVo.setPrice(good.getPrice().stripTrailingZeros().toPlainString()); + goodsVo.setPics(JSONObject.parseObject(good.getPics())); + goodsVo.setRemarks(good.getRemarks()); + goodsVo.setSpecs(buildGoodsSpec(good.getSpec())); + goodsVo.setSpecString(null); + + GoodsTag goodsTag = new GoodsTag(); + goodsTag.setState("1"); + goodsTag.setGoodsId(Long.parseLong(goodsVo.getGoodsId())); + List<GoodsTag> goodsTags = goodsTagMapper.selectGoodsTagList(goodsTag); + List<String> tags = goodsTags.stream().map(GoodsTag::getTag).collect(Collectors.toList()); + goodsVo.setTags(tags); + //获取产品信息 + List<SkuVo> skuVos = shopGoodsSkuMapper.selectSkuByGoodAndShop(shopId, goodsVo.getGoodsId()); + buildSkuRules(skuVos); + goodsVo.setSkus(skuVos); + return goodsVo; + } + private JSONArray buildGoodsSpec(String specs) { + List<Spec> specList = JSONObject.parseArray(specs,Spec.class); + List<SpecVo> specVos = new ArrayList<>(); + for (Spec spec : specList) { + SpecVo specVo = new SpecVo(); + specVos.add(specVo); + specVo.setSpecId(String.valueOf(spec.getId())); + specVo.setSpecName(spec.getName()); + List<SpecRuleVo> specRuleVos = new ArrayList<>(); + specVo.setRules(specRuleVos); + for (SpecRule specRule : spec.getSpecRules()) { + SpecRuleVo specRuleVo = new SpecRuleVo(); + specRuleVos.add(specRuleVo); + specRuleVo.setRuleId(String.valueOf(specRule.getId())); + specRuleVo.setPrice(specRule.getAmount().stripTrailingZeros().toPlainString()); + specRuleVo.setRuleName(specRule.getName()); + specRuleVo.setIsDefault(String.valueOf(specRule.getIsDefault())); + specRuleVo.setIsRecommend(specRule.getIsRecommend()); + } + + } + return JSONArray.parseArray(JSONObject.toJSONString(specVos)); + + } + private void buildSkuRules(List<SkuVo> skuVos) { + if(CollectionUtils.isEmpty(skuVos)){ + return; + } + for (SkuVo skuVo : skuVos) { + String rules = skuVo.getRulesString(); + List<SpecRule> specRuleList = JSONObject.parseArray(rules, SpecRule.class); + boolean boo =true; + List<SkuRuleVo> skuRuleVos = new ArrayList<>(); + for (SpecRule specRule : specRuleList) { + SkuRuleVo skuRuleVo = new SkuRuleVo(); + skuRuleVos.add(skuRuleVo); + skuRuleVo.setPrice(specRule.getAmount().stripTrailingZeros().toPlainString()); + skuRuleVo.setRuleId(String.valueOf(specRule.getId())); + skuRuleVo.setSpecId(String.valueOf(specRule.getSpecId())); + skuRuleVo.setRuleName(specRule.getName()); + if(0L == specRule.getIsDefault()){ + boo =false; + } + } + skuVo.setIsDefault("0"); + if(boo){ + skuVo.setIsDefault("1"); + } + skuVo.setRules(JSONObject.parseArray(JSONObject.toJSONString(skuRuleVos))); + skuVo.setRulesString(null); + } + } } diff --git a/soss-system/src/main/java/com/soss/system/service/impl/SpecServiceImpl.java b/soss-system/src/main/java/com/soss/system/service/impl/SpecServiceImpl.java index 0155297..4f0a9c3 100644 --- a/soss-system/src/main/java/com/soss/system/service/impl/SpecServiceImpl.java +++ b/soss-system/src/main/java/com/soss/system/service/impl/SpecServiceImpl.java @@ -5,17 +5,11 @@ import java.util.List; import com.soss.common.exception.ServiceException; import com.soss.common.utils.GenerateCode; -import com.soss.system.domain.GoodsSku; -import com.soss.system.domain.SpecRule; -import com.soss.system.domain.SpecRuleMaterial; -import com.soss.system.mapper.GoodsSkuMapper; +import com.soss.system.domain.*; +import com.soss.system.mapper.*; import com.soss.system.service.ISpecService; -import com.soss.system.mapper.SpecRuleMapper; -import com.soss.system.mapper.SpecRuleMaterialMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.soss.system.mapper.SpecMapper; -import com.soss.system.domain.Spec; import org.springframework.transaction.annotation.Transactional; /** @@ -35,6 +29,8 @@ public class SpecServiceImpl implements ISpecService private SpecRuleMaterialMapper specRuleMaterialMapper; @Autowired private GoodsSkuMapper goodsSkuMapper; + @Autowired + private GoodsMapper goodsMapper; /** * 查询规格 @@ -139,12 +135,16 @@ public class SpecServiceImpl implements ISpecService @Override public int updateSpec(Spec spec) { - if(2 == spec.getState()){ - String query ="\"specId\": "+spec.getId(); - List<GoodsSku> goodsSkus = goodsSkuMapper.selectSpec(query); - if(!goodsSkus.isEmpty()){ - throw new ServiceException("当前还有商品使用,请先删除商品"); - } + /** + * where + * is_deleted ='0' and + * rule_list like concat('%',#{query},'%') + */ + + String query ="\"specId\": "+spec.getId(); + List<Goods> goods = goodsMapper.selectSpec(query); + if(!goods.isEmpty()){ + throw new ServiceException("当前还有商品使用,请先删除商品"); } spec.setIsDeleted(0); spec.setUpdatedAt(new Date()); @@ -160,7 +160,7 @@ public class SpecServiceImpl implements ISpecService }else{ spec.setIsShow(0L); } - + deleteGoodsSku(String.valueOf(spec.getId())); long specId = spec.getId(); if(spec.getIsShow()==1L){ for (SpecRule specRule : specRules) { @@ -208,7 +208,8 @@ public class SpecServiceImpl implements ISpecService { String query ="\"specId\": "+id; List<GoodsSku> goodsSkus = goodsSkuMapper.selectSpec(query); - if(!goodsSkus.isEmpty()){ + List<Goods> goods = goodsMapper.selectSpec(query); + if(!goods.isEmpty()){ throw new ServiceException("当前还有商品使用,请先删除商品"); } long specId = Long.parseLong(id); @@ -217,6 +218,23 @@ public class SpecServiceImpl implements ISpecService Spec spec = specMapper.selectSpecById(id); spec.setIsDeleted(1); spec.setUpdatedAt(new Date()); + deleteGoodsSku(id); return specMapper.updateSpec(spec); } + + public void deleteGoodsSku(String specId){ + String query ="\"specId\": "+specId; + List<Goods> goods = goodsMapper.selectSpecNoState(query,"3"); + for (Goods good : goods) { + goodsMapper.updateGoodsSpec(good.getId()); + GoodsSku goodsSku = new GoodsSku(); + goodsSku.setGoodsId(good.getId()); + List<GoodsSku> goodsSkus = goodsSkuMapper.selectGoodsSkuList(goodsSku); + for (GoodsSku skus : goodsSkus) { + goodsSkuMapper.deleteGoodsSkuById(String.valueOf(skus.getId())); + } + + + } + } } diff --git a/soss-system/src/main/resources/mapper/system/GoodsMapper.xml b/soss-system/src/main/resources/mapper/system/GoodsMapper.xml index 22fa123..78b79a0 100644 --- a/soss-system/src/main/resources/mapper/system/GoodsMapper.xml +++ b/soss-system/src/main/resources/mapper/system/GoodsMapper.xml @@ -147,4 +147,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <select id="selectCount" resultType="integer"> select count(*) from goods where category=#{id} </select> + <select id="selectSpec" resultMap="GoodsResult"> + <include refid="selectGoodsVo"/> + <where> + spec like concat('%',#{query},'%') + and state ='3' + </where> + </select> + <select id="selectSpecNoState" resultMap="GoodsResult"> + <include refid="selectGoodsVo"/> + <where> + spec like concat('%',#{query},'%') + and state !=#{state} + </where> + </select> + <update id="updateGoodsSpec"> + update goods set spec =null where id = #{id} + </update> </mapper> \ No newline at end of file diff --git a/soss-system/src/main/resources/mapper/system/OrderMapper.xml b/soss-system/src/main/resources/mapper/system/OrderMapper.xml index bef056c..6c52304 100644 --- a/soss-system/src/main/resources/mapper/system/OrderMapper.xml +++ b/soss-system/src/main/resources/mapper/system/OrderMapper.xml @@ -211,8 +211,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{item} </foreach> and user_id = #{userId} + and shop_id =#{shopId} </where> - order by created_at desc limit 1 + order by created_at limit 1 </select> <update id="updateTimeOut"> update `order` set state='7' where state =#{status} and updated_at < DATE_SUB(NOW() ,interval #{timeout} SECOND) @@ -240,4 +241,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and shop_id = #{shopId} </where> </select> + <select id="selectOrderByTime" resultType="com.soss.system.domain.Order"> + <include refid="selectOrderVo"/> + where state =#{status} and updated_at < DATE_SUB(NOW() ,interval #{timeout} SECOND) + </select> + <update id="updateCancel"> + update `order` set state='8' where state =#{status} and updated_at < DATE_SUB(NOW() ,interval #{timeout} SECOND) + </update> </mapper> \ No newline at end of file diff --git a/soss-system/src/main/resources/mapper/system/SpecMapper.xml b/soss-system/src/main/resources/mapper/system/SpecMapper.xml index 1df17a1..478548e 100644 --- a/soss-system/src/main/resources/mapper/system/SpecMapper.xml +++ b/soss-system/src/main/resources/mapper/system/SpecMapper.xml @@ -14,10 +14,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <result property="createdAt" column="created_at" /> <result property="updatedAt" column="updated_at" /> <result property="code" column="code" /> + <result property="remark" column="remark" /> </resultMap> <sql id="selectSpecVo"> - select id, name, state, is_show, is_deleted, is_neccessary, created_at, updated_at, code from spec + select id, name, state, is_show, is_deleted, is_neccessary, created_at, updated_at, code,remark from spec </sql> <select id="selectSpecList" parameterType="Spec" resultMap="SpecResult"> @@ -52,6 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <if test="createdAt != null">created_at,</if> <if test="updatedAt != null">updated_at,</if> <if test="code != null">code,</if> + <if test="remark != null">remark,</if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="name != null and name != ''">#{name},</if> @@ -62,6 +64,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <if test="createdAt != null">#{createdAt},</if> <if test="updatedAt != null">#{updatedAt},</if> <if test="code != null">#{code},</if> + <if test="remark != null">#{remark},</if> </trim> </insert> @@ -75,6 +78,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <if test="isNeccessary != null and isNeccessary != ''">is_neccessary = #{isNeccessary},</if> <if test="updatedAt != null">updated_at = #{updatedAt},</if> <if test="code != null">code = #{code},</if> + <if test="remark != null">code = #{remark},</if> </trim> where id = #{id} </update>