Commit 828745b3 by 张新旗

代码永远在路上

parent 5a6d6601
...@@ -50,13 +50,13 @@ public class AppController extends BaseController { ...@@ -50,13 +50,13 @@ public class AppController extends BaseController {
} }
@RequestMapping("/getHomeOrder") @RequestMapping("/getHomeOrder")
public AjaxResult getHomeOrder(HttpServletRequest request){ public AjaxResult getHomeOrder(HttpServletRequest request,String shopId){
LoginUser loginUser = tokenService.getLoginUser(request); LoginUser loginUser = tokenService.getLoginUser(request);
if(loginUser ==null){ if(loginUser ==null){
return AjaxResult.success(); return AjaxResult.success();
} }
String openId = loginUser.getOpenId(); String openId = loginUser.getOpenId();
Map<String,String> info = orderService.getMyFristOrder(openId); Map<String,String> info = orderService.getMyFristOrder(openId,shopId);
return AjaxResult.success("操作成功",info); return AjaxResult.success("操作成功",info);
} }
@RequestMapping("/getWaitTine") @RequestMapping("/getWaitTine")
......
...@@ -2,6 +2,7 @@ package com.soss.web.controller.coffee; ...@@ -2,6 +2,7 @@ package com.soss.web.controller.coffee;
import java.util.List; import java.util.List;
import com.soss.common.exception.ServiceException;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -46,7 +47,12 @@ public class GoodsController extends BaseController ...@@ -46,7 +47,12 @@ public class GoodsController extends BaseController
*/ */
@GetMapping("/putShop") @GetMapping("/putShop")
public AjaxResult putShop(@RequestParam("goodsId") Long goodsId, @RequestParam("boo") boolean boo){ 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());
}
} }
/** /**
......
...@@ -101,9 +101,9 @@ weixin: ...@@ -101,9 +101,9 @@ weixin:
# REFLC7NYqwUo9KpvvmWv # REFLC7NYqwUo9KpvvmWv
sms: sms:
aliyun: aliyun:
accessKeyId: accessKeyId: LTAI5tEBoPGkpG6qy39h9dWj
accessKeySecret: accessKeySecret: B9c9aTIG5pmHWnlaRl4gGB12qmBtB4
signName: signName: 深圳好饮
push: push:
appkey: 59c9290134b359212290c075 appkey: 59c9290134b359212290c075
secret: 026756e7d5688089898db088 secret: 026756e7d5688089898db088
......
...@@ -57,6 +57,18 @@ public class Spec extends BaseEntity ...@@ -57,6 +57,18 @@ public class Spec extends BaseEntity
@Excel(name = "规格编码") @Excel(name = "规格编码")
private String code; 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; private List<SpecRule> specRules;
public List<SpecRule> getSpecRules() { public List<SpecRule> getSpecRules() {
......
...@@ -2,6 +2,8 @@ package com.soss.system.mapper; ...@@ -2,6 +2,8 @@ package com.soss.system.mapper;
import java.util.List; import java.util.List;
import com.soss.system.domain.Goods; import com.soss.system.domain.Goods;
import com.soss.system.domain.GoodsSku;
import org.apache.ibatis.annotations.Param;
/** /**
* 商品Mapper接口 * 商品Mapper接口
...@@ -60,4 +62,10 @@ public interface GoodsMapper ...@@ -60,4 +62,10 @@ public interface GoodsMapper
public int deleteGoodsByIds(String[] ids); public int deleteGoodsByIds(String[] ids);
Integer selectCount(String id); Integer selectCount(String id);
List<Goods> selectSpec(String query);
List<Goods> selectSpecNoState(@Param("query") String query, @Param("state") String s);
void updateGoodsSpec(long id);
} }
...@@ -74,9 +74,13 @@ public interface OrderMapper ...@@ -74,9 +74,13 @@ public interface OrderMapper
List<Order> selectOrderByShopId(@Param("status") List<String> status,@Param("shopId") String shopId); 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); void updateTimeOut(@Param("status") String productionCompleted,@Param("timeout") String timeout);
List<Order> selectOrderByUserId(@Param("userId") String openId,@Param("status") List<String> status); 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);
} }
...@@ -2,21 +2,46 @@ package com.soss.system.schedule; ...@@ -2,21 +2,46 @@ package com.soss.system.schedule;
import com.soss.system.constants.OrderStatusConstant; import com.soss.system.constants.OrderStatusConstant;
import com.soss.system.domain.Order; import com.soss.system.domain.Order;
import com.soss.system.domain.OrderOperationLog;
import com.soss.system.mapper.OrderMapper; 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.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
@Component @Component
public class OrderSchedule { public class OrderSchedule {
@Autowired @Autowired
private OrderMapper orderMapper; private OrderMapper orderMapper;
@Value("${timeout}") @Value("${timeout}")
private String timeout; private String timeout;
@Autowired
private OrderOperationLogMapper operationLogMapper;
@Scheduled(fixedDelay = 60*1000) @Scheduled(fixedDelay = 60*1000)
private void process() { private void process() {
orderMapper.updateTimeOut(OrderStatusConstant.productionCompleted,timeout); 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);
}
}
} }
} }
...@@ -98,7 +98,7 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -98,7 +98,7 @@ public class GoodsServiceImpl implements IGoodsService
@Transactional @Transactional
public int insertGoods(Goods goods) public int insertGoods(Goods goods)
{ {
if(goods.getDiscount().compareTo(goods.getPrice())>0){ if(goods.getDiscount().compareTo(goods.getPrice())>=0){
throw new ServiceException("折扣价不能大于等于原价"); throw new ServiceException("折扣价不能大于等于原价");
} }
goods.setCode(GenerateCode.getCode("G")); goods.setCode(GenerateCode.getCode("G"));
...@@ -261,6 +261,12 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -261,6 +261,12 @@ public class GoodsServiceImpl implements IGoodsService
@Override @Override
public String putShop(Long goodsId, boolean boo) { 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 goods = new Goods();
goods.setId(goodsId); goods.setId(goodsId);
goods.setState("3"); goods.setState("3");
......
...@@ -72,7 +72,8 @@ public class MachineApiServiceImpl { ...@@ -72,7 +72,8 @@ public class MachineApiServiceImpl {
shopGoodsSku.setSkuId(Long.parseLong(skuId)); shopGoodsSku.setSkuId(Long.parseLong(skuId));
List<ShopGoodsSku> shopGoodsSkus = shopGoodsSkuMapper.selectShopGoodsSkuList(shopGoodsSku); List<ShopGoodsSku> shopGoodsSkus = shopGoodsSkuMapper.selectShopGoodsSkuList(shopGoodsSku);
if(shopGoodsSkus.isEmpty()){ if(shopGoodsSkus.isEmpty()){
throw new ServiceException(skuId+"不存在"); log.info("当前sku【{}】不存在",skuId);
//throw new ServiceException(skuId+"不存在");
} }
for (ShopGoodsSku goodsSkus : shopGoodsSkus) { for (ShopGoodsSku goodsSkus : shopGoodsSkus) {
Long goodsId = goodsSkus.getGoodsId(); Long goodsId = goodsSkus.getGoodsId();
......
...@@ -100,7 +100,7 @@ public class OrderRefundServiceImpl implements IOrderRefundService ...@@ -100,7 +100,7 @@ public class OrderRefundServiceImpl implements IOrderRefundService
} }
// 制作中、制作完成、聚餐中、已完成 // 制作中、制作完成、聚餐中、已完成
String state = order.getState(); 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)){ if(OrderStatusConstant.Paid.equals(state)){
orderRefund.setRefundAmount(order.getAmount()); orderRefund.setRefundAmount(order.getAmount());
// 4 支付制作中 5 制作完成未取 6 取餐中 7 取餐完成 // 4 支付制作中 5 制作完成未取 6 取餐中 7 取餐完成
......
...@@ -69,6 +69,8 @@ public class OrderServiceImpl implements IOrderService ...@@ -69,6 +69,8 @@ public class OrderServiceImpl implements IOrderService
private SendMessageUtils sendMessageUtils; private SendMessageUtils sendMessageUtils;
@Autowired @Autowired
private OrderTakingServiceImpl orderTakingService; private OrderTakingServiceImpl orderTakingService;
@Autowired
private CustomerMapper customerMapper;
...@@ -243,6 +245,11 @@ public class OrderServiceImpl implements IOrderService ...@@ -243,6 +245,11 @@ public class OrderServiceImpl implements IOrderService
order.setFinishTime(new Date()); order.setFinishTime(new Date());
orderOperationLogService.insertOrderOperationLog(order); orderOperationLogService.insertOrderOperationLog(order);
jiGuangPushService.pushOrderState(order); jiGuangPushService.pushOrderState(order);
Customer customer = customerMapper.selectCustomerById(order.getUserId());
if(!"1".equals(customer.getAllow())){
}
} }
/** /**
...@@ -426,10 +433,10 @@ public class OrderServiceImpl implements IOrderService ...@@ -426,10 +433,10 @@ public class OrderServiceImpl implements IOrderService
String redisKey = "shopId"+format+shopId; String redisKey = "shopId"+format+shopId;
RedisAtomicInteger redisAtomicInteger = new RedisAtomicInteger(redisKey,SpringUtils.getBean(StringRedisTemplate.class).getConnectionFactory()); RedisAtomicInteger redisAtomicInteger = new RedisAtomicInteger(redisKey,SpringUtils.getBean(StringRedisTemplate.class).getConnectionFactory());
if(0 == redisAtomicInteger.get()){ if(0 == redisAtomicInteger.get()){
redisAtomicInteger.set(30); redisAtomicInteger.set((int)(1000*Math.random()));
} }
redisAtomicInteger.expire(1, TimeUnit.DAYS); redisAtomicInteger.expire(1, TimeUnit.DAYS);
int andIncrement = redisAtomicInteger.getAndIncrement(); int andIncrement = redisAtomicInteger.getAndAdd(3);
return key+String.format("%03d",andIncrement); return key+String.format("%03d",andIncrement);
} }
//获取订单号 //获取订单号
...@@ -495,9 +502,9 @@ public class OrderServiceImpl implements IOrderService ...@@ -495,9 +502,9 @@ public class OrderServiceImpl implements IOrderService
return null; 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"); 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){ if(order ==null){
return null; return null;
} }
......
...@@ -4,9 +4,11 @@ import java.util.Date; ...@@ -4,9 +4,11 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject;
import com.soss.system.domain.Goods; import com.soss.system.domain.Goods;
import com.soss.system.domain.Machine; import com.soss.system.domain.Machine;
import com.soss.system.domain.ShopGoods; import com.soss.system.domain.ShopGoods;
import com.soss.system.jiguang.impl.JiGuangPushServiceImpl;
import com.soss.system.mapper.GoodsCategoryMapper; import com.soss.system.mapper.GoodsCategoryMapper;
import com.soss.system.mapper.MachineMapper; import com.soss.system.mapper.MachineMapper;
import com.soss.system.mapper.OrderMapper; import com.soss.system.mapper.OrderMapper;
...@@ -33,6 +35,8 @@ public class ShopRecommendServiceImpl implements IShopRecommendService ...@@ -33,6 +35,8 @@ public class ShopRecommendServiceImpl implements IShopRecommendService
private OrderMapper orderMapper; private OrderMapper orderMapper;
@Autowired @Autowired
private GoodsCategoryMapper goodsCategoryMapper; private GoodsCategoryMapper goodsCategoryMapper;
@Autowired
private JiGuangPushServiceImpl jiGuangPushService;
/** /**
* 查询推荐和今日特惠 * 查询推荐和今日特惠
...@@ -78,10 +82,24 @@ public class ShopRecommendServiceImpl implements IShopRecommendService ...@@ -78,10 +82,24 @@ public class ShopRecommendServiceImpl implements IShopRecommendService
shopRecommend.setCreatedAt(new Date()); shopRecommend.setCreatedAt(new Date());
shopRecommend.setRecDate(new Date()); shopRecommend.setRecDate(new Date());
shopRecommendMapper.insertShopRecommend(shopRecommend); shopRecommendMapper.insertShopRecommend(shopRecommend);
updateApplication(Long.parseLong(shopRecommend.getShopId()));
shopRecommend.setTurn(shopRecommend.getId()); shopRecommend.setTurn(shopRecommend.getId());
return shopRecommendMapper.updateShopRecommend(shopRecommend); 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 ...@@ -166,6 +184,7 @@ public class ShopRecommendServiceImpl implements IShopRecommendService
shopRecommend.setType(type); shopRecommend.setType(type);
shopRecommend.setGoodsId(goodsId); shopRecommend.setGoodsId(goodsId);
ShopRecommend frist = shopRecommendMapper.selectShopRecommendList(shopRecommend).get(0); ShopRecommend frist = shopRecommendMapper.selectShopRecommendList(shopRecommend).get(0);
updateApplication(Long.parseLong(shopRecommend.getShopId()));
return shopRecommendMapper.deleteShopRecommendById(frist.getId()); return shopRecommendMapper.deleteShopRecommendById(frist.getId());
} }
......
package com.soss.system.service.impl; package com.soss.system.service.impl;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.soss.common.core.domain.AjaxResult; import com.soss.common.core.domain.AjaxResult;
import com.soss.common.exception.ServiceException; import com.soss.common.exception.ServiceException;
import com.soss.common.utils.StringUtils; import com.soss.common.utils.StringUtils;
import com.soss.system.domain.*; 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.service.IShopService;
import com.soss.system.mapper.*; import com.soss.system.mapper.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.core.CollectionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
/** /**
* 店铺Service业务层处理 * 店铺Service业务层处理
...@@ -48,6 +52,10 @@ public class ShopServiceImpl implements IShopService ...@@ -48,6 +52,10 @@ public class ShopServiceImpl implements IShopService
@Autowired @Autowired
private ShopRecommendMapper shopRecommendMapper; private ShopRecommendMapper shopRecommendMapper;
@Autowired
private JiGuangPushServiceImpl jiGuangPushService;
@Autowired
private GoodsTagMapper goodsTagMapper;
...@@ -191,10 +199,16 @@ public class ShopServiceImpl implements IShopService ...@@ -191,10 +199,16 @@ public class ShopServiceImpl implements IShopService
shopGoodsSku.setUpdatedAt(new Date()); shopGoodsSku.setUpdatedAt(new Date());
shopGoodsSkuMapper.insertShopGoodsSku(shopGoodsSku); shopGoodsSkuMapper.insertShopGoodsSku(shopGoodsSku);
} }
updateApplication(machine1.getCode());
} }
return null; 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 @Override
public List<GoodsCategory> getCategoryGoods(long shopId) { public List<GoodsCategory> getCategoryGoods(long shopId) {
...@@ -312,6 +326,13 @@ public class ShopServiceImpl implements IShopService ...@@ -312,6 +326,13 @@ public class ShopServiceImpl implements IShopService
shopGoodsSkuMapper.deleteByGoodsIds(shopId,goodsIds); shopGoodsSkuMapper.deleteByGoodsIds(shopId,goodsIds);
shopGoodsMapper.deleteByShopIdGoods(shopId,goodsIds); shopGoodsMapper.deleteByShopIdGoods(shopId,goodsIds);
shopRecommendMapper.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; return null;
} }
...@@ -356,13 +377,92 @@ public class ShopServiceImpl implements IShopService ...@@ -356,13 +377,92 @@ public class ShopServiceImpl implements IShopService
return AjaxResult.error("该产品已经不存在"); return AjaxResult.error("该产品已经不存在");
}else{ }else{
ShopGoodsSku shopGoodsSku1 = shopGoodsSkus.get(0); ShopGoodsSku shopGoodsSku1 = shopGoodsSkus.get(0);
if(!"1".equals(shopGoodsSku1.getState())){ JSONObject jsonObject = new JSONObject();
return AjaxResult.error("该产品已经告罄"); 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(); 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);
}
}
} }
...@@ -5,17 +5,11 @@ import java.util.List; ...@@ -5,17 +5,11 @@ import java.util.List;
import com.soss.common.exception.ServiceException; import com.soss.common.exception.ServiceException;
import com.soss.common.utils.GenerateCode; import com.soss.common.utils.GenerateCode;
import com.soss.system.domain.GoodsSku; import com.soss.system.domain.*;
import com.soss.system.domain.SpecRule; import com.soss.system.mapper.*;
import com.soss.system.domain.SpecRuleMaterial;
import com.soss.system.mapper.GoodsSkuMapper;
import com.soss.system.service.ISpecService; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.soss.system.mapper.SpecMapper;
import com.soss.system.domain.Spec;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
/** /**
...@@ -35,6 +29,8 @@ public class SpecServiceImpl implements ISpecService ...@@ -35,6 +29,8 @@ public class SpecServiceImpl implements ISpecService
private SpecRuleMaterialMapper specRuleMaterialMapper; private SpecRuleMaterialMapper specRuleMaterialMapper;
@Autowired @Autowired
private GoodsSkuMapper goodsSkuMapper; private GoodsSkuMapper goodsSkuMapper;
@Autowired
private GoodsMapper goodsMapper;
/** /**
* 查询规格 * 查询规格
...@@ -139,12 +135,16 @@ public class SpecServiceImpl implements ISpecService ...@@ -139,12 +135,16 @@ public class SpecServiceImpl implements ISpecService
@Override @Override
public int updateSpec(Spec spec) public int updateSpec(Spec spec)
{ {
if(2 == spec.getState()){ /**
String query ="\"specId\": "+spec.getId(); * where
List<GoodsSku> goodsSkus = goodsSkuMapper.selectSpec(query); * is_deleted ='0' and
if(!goodsSkus.isEmpty()){ * rule_list like concat('%',#{query},'%')
throw new ServiceException("当前还有商品使用,请先删除商品"); */
}
String query ="\"specId\": "+spec.getId();
List<Goods> goods = goodsMapper.selectSpec(query);
if(!goods.isEmpty()){
throw new ServiceException("当前还有商品使用,请先删除商品");
} }
spec.setIsDeleted(0); spec.setIsDeleted(0);
spec.setUpdatedAt(new Date()); spec.setUpdatedAt(new Date());
...@@ -160,7 +160,7 @@ public class SpecServiceImpl implements ISpecService ...@@ -160,7 +160,7 @@ public class SpecServiceImpl implements ISpecService
}else{ }else{
spec.setIsShow(0L); spec.setIsShow(0L);
} }
deleteGoodsSku(String.valueOf(spec.getId()));
long specId = spec.getId(); long specId = spec.getId();
if(spec.getIsShow()==1L){ if(spec.getIsShow()==1L){
for (SpecRule specRule : specRules) { for (SpecRule specRule : specRules) {
...@@ -208,7 +208,8 @@ public class SpecServiceImpl implements ISpecService ...@@ -208,7 +208,8 @@ public class SpecServiceImpl implements ISpecService
{ {
String query ="\"specId\": "+id; String query ="\"specId\": "+id;
List<GoodsSku> goodsSkus = goodsSkuMapper.selectSpec(query); List<GoodsSku> goodsSkus = goodsSkuMapper.selectSpec(query);
if(!goodsSkus.isEmpty()){ List<Goods> goods = goodsMapper.selectSpec(query);
if(!goods.isEmpty()){
throw new ServiceException("当前还有商品使用,请先删除商品"); throw new ServiceException("当前还有商品使用,请先删除商品");
} }
long specId = Long.parseLong(id); long specId = Long.parseLong(id);
...@@ -217,6 +218,23 @@ public class SpecServiceImpl implements ISpecService ...@@ -217,6 +218,23 @@ public class SpecServiceImpl implements ISpecService
Spec spec = specMapper.selectSpecById(id); Spec spec = specMapper.selectSpecById(id);
spec.setIsDeleted(1); spec.setIsDeleted(1);
spec.setUpdatedAt(new Date()); spec.setUpdatedAt(new Date());
deleteGoodsSku(id);
return specMapper.updateSpec(spec); 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()));
}
}
}
} }
...@@ -147,4 +147,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -147,4 +147,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectCount" resultType="integer"> <select id="selectCount" resultType="integer">
select count(*) from goods where category=#{id} select count(*) from goods where category=#{id}
</select> </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> </mapper>
\ No newline at end of file
...@@ -211,8 +211,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -211,8 +211,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{item} #{item}
</foreach> </foreach>
and user_id = #{userId} and user_id = #{userId}
and shop_id =#{shopId}
</where> </where>
order by created_at desc limit 1 order by created_at limit 1
</select> </select>
<update id="updateTimeOut"> <update id="updateTimeOut">
update `order` set state='7' where state =#{status} and updated_at &lt; DATE_SUB(NOW() ,interval #{timeout} SECOND) update `order` set state='7' where state =#{status} and updated_at &lt; DATE_SUB(NOW() ,interval #{timeout} SECOND)
...@@ -240,4 +241,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -240,4 +241,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and shop_id = #{shopId} and shop_id = #{shopId}
</where> </where>
</select> </select>
<select id="selectOrderByTime" resultType="com.soss.system.domain.Order">
<include refid="selectOrderVo"/>
where state =#{status} and updated_at &lt; DATE_SUB(NOW() ,interval #{timeout} SECOND)
</select>
<update id="updateCancel">
update `order` set state='8' where state =#{status} and updated_at &lt; DATE_SUB(NOW() ,interval #{timeout} SECOND)
</update>
</mapper> </mapper>
\ No newline at end of file
...@@ -14,10 +14,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -14,10 +14,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="createdAt" column="created_at" /> <result property="createdAt" column="created_at" />
<result property="updatedAt" column="updated_at" /> <result property="updatedAt" column="updated_at" />
<result property="code" column="code" /> <result property="code" column="code" />
<result property="remark" column="remark" />
</resultMap> </resultMap>
<sql id="selectSpecVo"> <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> </sql>
<select id="selectSpecList" parameterType="Spec" resultMap="SpecResult"> <select id="selectSpecList" parameterType="Spec" resultMap="SpecResult">
...@@ -52,6 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -52,6 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createdAt != null">created_at,</if> <if test="createdAt != null">created_at,</if>
<if test="updatedAt != null">updated_at,</if> <if test="updatedAt != null">updated_at,</if>
<if test="code != null">code,</if> <if test="code != null">code,</if>
<if test="remark != null">remark,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null and name != ''">#{name},</if> <if test="name != null and name != ''">#{name},</if>
...@@ -62,6 +64,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -62,6 +64,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createdAt != null">#{createdAt},</if> <if test="createdAt != null">#{createdAt},</if>
<if test="updatedAt != null">#{updatedAt},</if> <if test="updatedAt != null">#{updatedAt},</if>
<if test="code != null">#{code},</if> <if test="code != null">#{code},</if>
<if test="remark != null">#{remark},</if>
</trim> </trim>
</insert> </insert>
...@@ -75,6 +78,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -75,6 +78,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="isNeccessary != null and isNeccessary != ''">is_neccessary = #{isNeccessary},</if> <if test="isNeccessary != null and isNeccessary != ''">is_neccessary = #{isNeccessary},</if>
<if test="updatedAt != null">updated_at = #{updatedAt},</if> <if test="updatedAt != null">updated_at = #{updatedAt},</if>
<if test="code != null">code = #{code},</if> <if test="code != null">code = #{code},</if>
<if test="remark != null">code = #{remark},</if>
</trim> </trim>
where id = #{id} where id = #{id}
</update> </update>
......
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