提交
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
package com.chaozhanggui.system.cashierservice.task;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbMerchantThirdApply;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbOrderPayment;
|
||||
import com.chaozhanggui.system.cashierservice.model.TradeQueryReq;
|
||||
import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
|
||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import com.chaozhanggui.system.cashierservice.util.BeanUtil;
|
||||
import com.chaozhanggui.system.cashierservice.util.MD5Util;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class OrderTask {
|
||||
|
||||
|
||||
@Autowired
|
||||
TbOrderInfoMapper tbOrderInfoMapper;
|
||||
@Autowired
|
||||
TbCashierCartMapper tbCashierCartMapper;
|
||||
|
||||
@Autowired
|
||||
TbMerchantThirdApplyMapper tbMerchantThirdApplyMapper;
|
||||
|
||||
@Autowired
|
||||
TbOrderPaymentMapper tbOrderPaymentMapper;
|
||||
|
||||
|
||||
@Autowired
|
||||
TbOrderDetailMapper tbOrderDetailMapper;
|
||||
|
||||
@Autowired
|
||||
RabbitProducer producer;
|
||||
|
||||
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
|
||||
|
||||
@Value("${gateway.url}")
|
||||
private String gateWayUrl;
|
||||
|
||||
// @Scheduled(initialDelay = 1000,fixedDelay = 1000)
|
||||
public void orderQuery(){
|
||||
|
||||
List<TbOrderInfo> list= tbOrderInfoMapper.selectAllByStatus("paying");
|
||||
if(ObjectUtil.isNotEmpty(list)&&list.size()>0){
|
||||
for (TbOrderInfo orderInfo : list) {
|
||||
deal(orderInfo);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deal(TbOrderInfo orderInfo){
|
||||
|
||||
|
||||
TbMerchantThirdApply thirdApply= tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMerchantId()));
|
||||
if(ObjectUtil.isEmpty(thirdApply)||ObjectUtil.isNull(thirdApply)){
|
||||
log.info(CodeEnum.NOCUSTOMER.getMsg());
|
||||
return ;
|
||||
}
|
||||
|
||||
TbOrderPayment tbOrderPayment=tbOrderPaymentMapper.selectByOrderId(orderInfo.getId().toString());
|
||||
if(ObjectUtil.isNotEmpty(tbOrderPayment)){
|
||||
TradeQueryReq tradeQueryReq=new TradeQueryReq();
|
||||
tradeQueryReq.setAppId(thirdApply.getAppId());
|
||||
tradeQueryReq.setTimestamp(System.currentTimeMillis());
|
||||
tradeQueryReq.setOrderNumber(tbOrderPayment.getTradeNumber());
|
||||
|
||||
Map<String,Object> map= BeanUtil.transBean2Map(tradeQueryReq);
|
||||
tradeQueryReq.setSign(MD5Util.encrypt(map,thirdApply.getAppToken(),true));
|
||||
ResponseEntity<String> response= restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/tradeQuery"),tradeQueryReq,String.class);
|
||||
if(response.getStatusCodeValue()==200&&ObjectUtil.isNotEmpty(response.getBody())){
|
||||
JSONObject object=JSONObject.parseObject(response.getBody());
|
||||
if(object.get("code").equals("0")){
|
||||
|
||||
JSONObject data=object.getJSONObject("data");
|
||||
if("1".equals(data.getString("status"))){
|
||||
|
||||
orderInfo.setStatus("closed");
|
||||
orderInfo.setPayOrderNo(tbOrderPayment.getTradeNumber());
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
//更新购物车状态
|
||||
int cartCount= tbCashierCartMapper.updateByOrderId(orderInfo.getId().toString(),"final");
|
||||
log.info("更新购物车:{}",cartCount);
|
||||
|
||||
tbOrderDetailMapper.updateStatusByOrderIdAndStatus(orderInfo.getId(),"closed");
|
||||
|
||||
|
||||
// JSONObject jsonObject=new JSONObject();
|
||||
// jsonObject.put("token",token);
|
||||
// jsonObject.put("type","create");
|
||||
// jsonObject.put("orderId",orderId);
|
||||
//
|
||||
// producer.putOrderCollect(jsonObject.toJSONString());
|
||||
//
|
||||
// producer.printMechine(orderId);
|
||||
|
||||
|
||||
|
||||
|
||||
}else if ("0".equals(data.getString("status"))){
|
||||
orderInfo.setStatus("fail");
|
||||
orderInfo.setPayOrderNo(tbOrderPayment.getTradeNumber());
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
//更新购物车状态
|
||||
int cartCount= tbCashierCartMapper.updateByOrderId(orderInfo.getId().toString(),"fail");
|
||||
log.info("更新购物车:{}",cartCount);
|
||||
}
|
||||
}else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.chaozhanggui.system.cashierservice.task;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.chaozhanggui.system.cashierservice.cache.DataCache;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbShopInfoMapper;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbShopOnlineMapper;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbShopInfo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbShopOnline;
|
||||
import com.chaozhanggui.system.cashierservice.util.DateUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ShopInfoStatusTask {
|
||||
|
||||
|
||||
@Autowired
|
||||
TbShopInfoMapper tbShopInfoMapper;
|
||||
|
||||
|
||||
@Autowired
|
||||
TbShopOnlineMapper tbShopOnlineMapper;
|
||||
|
||||
|
||||
// @Scheduled(initialDelay = 2000,fixedDelay = 500)
|
||||
public void modifyShopStatus(){
|
||||
ConcurrentHashMap<String, TbShopInfo> concurrentHashMap= DataCache.concurrentHashMap;
|
||||
|
||||
Enumeration<String> keys= concurrentHashMap.keys();
|
||||
while (keys.hasMoreElements()) {
|
||||
String key = keys.nextElement();
|
||||
TbShopInfo shopInfo = concurrentHashMap.get(key);
|
||||
if (shopInfo.getBusinessTime() == null || ObjectUtil.isEmpty(shopInfo.getBusinessTime())) {
|
||||
shopInfo.setOnSale(Byte.parseByte("0"));
|
||||
shopInfo.setStatus(Byte.parseByte("0"));
|
||||
shopInfo.setUpdatedAt(System.currentTimeMillis());
|
||||
tbShopInfoMapper.updateByPrimaryKeyWithBLOBs(shopInfo);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
deal(shopInfo);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deal(TbShopInfo shopInfo) throws Exception{
|
||||
TbShopOnline online= tbShopOnlineMapper.selectByPrimaryKey(shopInfo.getId());
|
||||
if(Objects.isNull(online)||ObjectUtil.isEmpty(online)){
|
||||
log.error("店铺信息不存在:{}",shopInfo.getId());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
switch (shopInfo.getOnSale().toString()){
|
||||
case "0":
|
||||
if(new Date().compareTo(online.getStartTime())>0&&online.getEndTime().compareTo(new Date())>0){
|
||||
shopInfo.setOnSale(Byte.parseByte("1"));
|
||||
shopInfo.setStatus(Byte.parseByte("1"));
|
||||
shopInfo.setCreatedAt(System.currentTimeMillis());
|
||||
tbShopInfoMapper.updateByPrimaryKey(shopInfo);
|
||||
|
||||
|
||||
online.setStatus("1");
|
||||
online.setUpdateTime(new Date());
|
||||
tbShopOnlineMapper.updateByPrimaryKey(online);
|
||||
DataCache.concurrentHashMap.put(shopInfo.getId().toString(),shopInfo);
|
||||
}
|
||||
break;
|
||||
case "1":
|
||||
if(online.getStartTime().compareTo(new Date())>0||new Date().compareTo(online.getEndTime())>0){
|
||||
shopInfo.setOnSale(Byte.parseByte("1"));
|
||||
shopInfo.setStatus(Byte.parseByte("1"));
|
||||
shopInfo.setCreatedAt(System.currentTimeMillis());
|
||||
tbShopInfoMapper.updateByPrimaryKey(shopInfo);
|
||||
|
||||
online.setStartTime(DateUtils.getNewDate(online.getStartTime(),3,1));
|
||||
online.setEndTime(DateUtils.getNewDate(online.getEndTime(),3,1));
|
||||
online.setStatus("0");
|
||||
online.setUpdateTime(new Date());
|
||||
tbShopOnlineMapper.updateByPrimaryKey(online);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user