mq增加事务
This commit is contained in:
parent
f206777914
commit
9c90074614
|
|
@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||||
import com.chaozhanggui.system.cashierservice.dao.*;
|
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.*;
|
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||||
|
import com.chaozhanggui.system.cashierservice.service.DutyService;
|
||||||
import com.chaozhanggui.system.cashierservice.util.DateUtils;
|
import com.chaozhanggui.system.cashierservice.util.DateUtils;
|
||||||
import com.chaozhanggui.system.cashierservice.util.TokenUtil;
|
import com.chaozhanggui.system.cashierservice.util.TokenUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
@ -14,6 +15,7 @@ import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
@ -25,249 +27,13 @@ import java.util.*;
|
||||||
public class DutyConsumer {
|
public class DutyConsumer {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TbTokenMapper tbTokenMapper;
|
private DutyService dutyService;
|
||||||
@Autowired
|
|
||||||
private TbOrderDetailMapper orderDetailMapper;
|
|
||||||
@Autowired
|
|
||||||
private TbOrderInfoMapper orderInfoMapper;
|
|
||||||
@Autowired
|
|
||||||
private ShopUserDutyDetailMapper shopUserDutyDetailMapper;
|
|
||||||
@Autowired
|
|
||||||
private ShopUserDutyMapper shopUserDutyMapper;
|
|
||||||
@Autowired
|
|
||||||
private TbShopInfoMapper shopInfoMapper;
|
|
||||||
@Autowired
|
|
||||||
private ShopUserDutyPayMapper shopUserDutyPayMapper;
|
|
||||||
@RabbitHandler
|
@RabbitHandler
|
||||||
public void listener(String message) {
|
public void listener(String message) {
|
||||||
try {
|
dutyService.exect(message);
|
||||||
System.out.println("数据落地开始");
|
|
||||||
JSONObject jsonObject = JSON.parseObject(message);
|
|
||||||
String token = jsonObject.getString("token");
|
|
||||||
String type = jsonObject.getString("type");
|
|
||||||
TbToken tbToken = tbTokenMapper.selectByToken(token);
|
|
||||||
if (type.equals("return") || type.equals("create")) {
|
|
||||||
if (Objects.isNull(tbToken)) {
|
|
||||||
throw new MsgException("当前用户不存在");
|
|
||||||
}
|
|
||||||
Integer tokenId = tbToken.getId();
|
|
||||||
|
|
||||||
Integer orderId = jsonObject.getInteger("orderId");
|
|
||||||
JSONObject tokenJson = TokenUtil.parseParamFromToken(tbToken.getToken());
|
|
||||||
Integer shopId = tokenJson.getInteger("shopId");
|
|
||||||
Integer userId = tokenJson.getInteger("staffId");
|
|
||||||
String loginName = tokenJson.getString("loginName");
|
|
||||||
TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId);
|
|
||||||
if (Objects.isNull(orderInfo) && orderId > 0) {
|
|
||||||
throw new MsgException("订单不存在");
|
|
||||||
}
|
|
||||||
List<TbOrderDetail> list = orderDetailMapper.selectAllByOrderId(orderId);
|
|
||||||
ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByTokenId(tokenId);
|
|
||||||
BigDecimal cashAmount = BigDecimal.ZERO;
|
|
||||||
if (orderInfo.getPayType().equals("cash")) {
|
|
||||||
cashAmount = orderInfo.getPayAmount();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type.equals("create")) {
|
|
||||||
if (Objects.isNull(shopUserDuty)) {
|
|
||||||
shopUserDuty = new ShopUserDuty(userId, tbToken.getCreateTime(), 1, orderInfo.getOrderAmount(), loginName, "0",
|
|
||||||
orderInfo.getOrderAmount(), shopId, BigDecimal.ZERO, cashAmount, BigDecimal.ZERO, "");
|
|
||||||
shopUserDuty.setTokenId(tokenId);
|
|
||||||
shopUserDuty.setReturnAmount(BigDecimal.ZERO);
|
|
||||||
shopUserDuty.setTradeDay(DateUtils.getDay());
|
|
||||||
shopUserDutyMapper.insert(shopUserDuty);
|
|
||||||
List<ShopUserDutyDetail> detaiList = new ArrayList<>();
|
|
||||||
for (TbOrderDetail orderDetail : list) {
|
|
||||||
ShopUserDutyDetail shopUserDutyDetail = new ShopUserDutyDetail();
|
|
||||||
shopUserDutyDetail.setDutyId(shopUserDuty.getId());
|
|
||||||
shopUserDutyDetail.setAmount(orderDetail.getPriceAmount());
|
|
||||||
shopUserDutyDetail.setNum(orderDetail.getNum());
|
|
||||||
shopUserDutyDetail.setSkuId(orderDetail.getProductSkuId());
|
|
||||||
shopUserDutyDetail.setSkuName(orderDetail.getProductSkuName());
|
|
||||||
shopUserDutyDetail.setProductId(orderDetail.getProductId());
|
|
||||||
shopUserDutyDetail.setProductName(orderDetail.getProductName());
|
|
||||||
detaiList.add(shopUserDutyDetail);
|
|
||||||
}
|
|
||||||
if (detaiList.size() > 0) {
|
|
||||||
shopUserDutyDetailMapper.batchInsert(detaiList);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
shopUserDuty.setAmount(shopUserDuty.getAmount().add(orderInfo.getPayAmount()));
|
|
||||||
shopUserDuty.setCashAmount(shopUserDuty.getCashAmount().add(cashAmount));
|
|
||||||
shopUserDuty.setIncomeAmount(shopUserDuty.getIncomeAmount().add(orderInfo.getPayAmount()));
|
|
||||||
shopUserDuty.setOrderNum(shopUserDuty.getOrderNum() + 1);
|
|
||||||
shopUserDutyMapper.updateByPrimaryKeySelective(shopUserDuty);
|
|
||||||
List<Integer> skuIds = new ArrayList<>();
|
|
||||||
for (TbOrderDetail orderDetail : list) {
|
|
||||||
skuIds.add(orderDetail.getProductSkuId());
|
|
||||||
}
|
|
||||||
List<ShopUserDutyDetail> details = shopUserDutyDetailMapper.selectByDuctId(shopUserDuty.getId(), skuIds);
|
|
||||||
|
|
||||||
Map<Integer, ShopUserDutyDetail> map = new HashMap<>();
|
|
||||||
for (ShopUserDutyDetail shopUserDutyDetail : details) {
|
|
||||||
map.put(shopUserDutyDetail.getSkuId(), shopUserDutyDetail);
|
|
||||||
}
|
|
||||||
List<ShopUserDutyDetail> detaiList = new ArrayList<>();
|
|
||||||
for (TbOrderDetail orderDetail : list) {
|
|
||||||
if (map.containsKey(orderDetail.getProductSkuId())) {
|
|
||||||
ShopUserDutyDetail shopUserDutyDetail = map.get(orderDetail.getProductSkuId());
|
|
||||||
shopUserDutyDetail.setNum(shopUserDutyDetail.getNum() + orderDetail.getNum());
|
|
||||||
shopUserDutyDetail.setAmount(shopUserDutyDetail.getAmount().add(orderDetail.getPriceAmount().add(orderDetail.getPackAmount())));
|
|
||||||
shopUserDutyDetailMapper.updateByPrimaryKeySelective(shopUserDutyDetail);
|
|
||||||
} else {
|
|
||||||
ShopUserDutyDetail shopUserDutyDetail = new ShopUserDutyDetail();
|
|
||||||
shopUserDutyDetail.setDutyId(shopUserDuty.getId());
|
|
||||||
shopUserDutyDetail.setAmount(orderDetail.getPriceAmount());
|
|
||||||
shopUserDutyDetail.setNum(orderDetail.getNum());
|
|
||||||
shopUserDutyDetail.setSkuId(orderDetail.getProductSkuId());
|
|
||||||
shopUserDutyDetail.setSkuName(orderDetail.getProductSkuName());
|
|
||||||
shopUserDutyDetail.setProductId(orderDetail.getProductId());
|
|
||||||
shopUserDutyDetail.setProductName(orderDetail.getProductName());
|
|
||||||
detaiList.add(shopUserDutyDetail);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (detaiList.size() > 0) {
|
|
||||||
shopUserDutyDetailMapper.batchInsert(detaiList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ShopUserDutyPay shopUserDutyPay = shopUserDutyPayMapper.selectByDuctIdAndType(shopUserDuty.getId(),orderInfo.getPayType());
|
|
||||||
if (Objects.nonNull(shopUserDutyPay)){
|
|
||||||
shopUserDutyPay.setAmount(orderInfo.getOrderAmount().add(shopUserDutyPay.getAmount()));
|
|
||||||
shopUserDutyPayMapper.updateByPrimaryKeySelective(shopUserDutyPay);
|
|
||||||
}else {
|
|
||||||
shopUserDutyPay=new ShopUserDutyPay();
|
|
||||||
shopUserDutyPay.setDutyId(shopUserDuty.getId());
|
|
||||||
shopUserDutyPay.setType(orderInfo.getPayType());
|
|
||||||
shopUserDutyPay.setAmount(orderInfo.getOrderAmount());
|
|
||||||
shopUserDutyPayMapper.insert(shopUserDutyPay);
|
|
||||||
}
|
|
||||||
} else if (type.equals("return")) {
|
|
||||||
BigDecimal amount = jsonObject.getBigDecimal("amount");
|
|
||||||
if (Objects.isNull(shopUserDuty)) {
|
|
||||||
shopUserDuty = new ShopUserDuty(userId, tbToken.getCreateTime(), 1, BigDecimal.ZERO, loginName, "0",
|
|
||||||
BigDecimal.ZERO, shopId, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, "");
|
|
||||||
shopUserDuty.setReturnAmount(amount);
|
|
||||||
shopUserDuty.setTokenId(tokenId);
|
|
||||||
shopUserDuty.setTradeDay(DateUtils.getDay());
|
|
||||||
shopUserDutyMapper.insert(shopUserDuty);
|
|
||||||
} else {
|
|
||||||
shopUserDuty.setReturnAmount(shopUserDuty.getReturnAmount().add(amount));
|
|
||||||
shopUserDutyMapper.updateByPrimaryKeySelective(shopUserDuty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (type.equals("wxcreate")) {
|
|
||||||
String day = DateUtils.getDay();
|
|
||||||
Integer orderId = jsonObject.getInteger("orderId");
|
|
||||||
TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId);
|
|
||||||
if (Objects.isNull(orderInfo)) {
|
|
||||||
throw new MsgException("订单不存在");
|
|
||||||
}
|
|
||||||
List<TbOrderDetail> list = orderDetailMapper.selectAllByOrderId(orderId);
|
|
||||||
BigDecimal cashAmount = BigDecimal.ZERO;
|
|
||||||
if (orderInfo.getPayType().equals("cash")) {
|
|
||||||
cashAmount = orderInfo.getPayAmount();
|
|
||||||
}
|
|
||||||
ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByTokenIdAndTradeDay(0, day, orderInfo.getShopId());
|
|
||||||
TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getShopId()));
|
|
||||||
if (Objects.isNull(shopUserDuty)) {
|
|
||||||
shopUserDuty = new ShopUserDuty(Integer.valueOf(orderInfo.getShopId()), new Date(), 1, orderInfo.getOrderAmount(), "", "0",
|
|
||||||
orderInfo.getOrderAmount(), Integer.valueOf(orderInfo.getShopId()), BigDecimal.ZERO, cashAmount, BigDecimal.ZERO, "");
|
|
||||||
shopUserDuty.setTokenId(0);
|
|
||||||
shopUserDuty.setType("wx");
|
|
||||||
if (Objects.nonNull(shopInfo)) {
|
|
||||||
shopUserDuty.setUserName(shopInfo.getShopName());
|
|
||||||
}
|
|
||||||
shopUserDuty.setTradeDay(DateUtils.getDay());
|
|
||||||
shopUserDutyMapper.insert(shopUserDuty);
|
|
||||||
List<ShopUserDutyDetail> detaiList = new ArrayList<>();
|
|
||||||
for (TbOrderDetail orderDetail : list) {
|
|
||||||
ShopUserDutyDetail shopUserDutyDetail = new ShopUserDutyDetail();
|
|
||||||
shopUserDutyDetail.setDutyId(shopUserDuty.getId());
|
|
||||||
shopUserDutyDetail.setAmount(orderDetail.getPriceAmount());
|
|
||||||
shopUserDutyDetail.setNum(orderDetail.getNum());
|
|
||||||
shopUserDutyDetail.setSkuId(orderDetail.getProductSkuId());
|
|
||||||
shopUserDutyDetail.setSkuName(orderDetail.getProductSkuName());
|
|
||||||
shopUserDutyDetail.setProductId(orderDetail.getProductId());
|
|
||||||
shopUserDutyDetail.setProductName(orderDetail.getProductName());
|
|
||||||
detaiList.add(shopUserDutyDetail);
|
|
||||||
}
|
|
||||||
if (detaiList.size() > 0) {
|
|
||||||
shopUserDutyDetailMapper.batchInsert(detaiList);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
shopUserDuty.setAmount(shopUserDuty.getAmount().add(orderInfo.getPayAmount()));
|
|
||||||
shopUserDuty.setCashAmount(shopUserDuty.getCashAmount().add(cashAmount));
|
|
||||||
shopUserDuty.setIncomeAmount(shopUserDuty.getIncomeAmount().add(orderInfo.getPayAmount()));
|
|
||||||
shopUserDuty.setOrderNum(shopUserDuty.getOrderNum() + 1);
|
|
||||||
shopUserDutyMapper.updateByPrimaryKeySelective(shopUserDuty);
|
|
||||||
List<Integer> skuIds = new ArrayList<>();
|
|
||||||
for (TbOrderDetail orderDetail : list) {
|
|
||||||
skuIds.add(orderDetail.getProductSkuId());
|
|
||||||
}
|
|
||||||
List<ShopUserDutyDetail> details = shopUserDutyDetailMapper.selectByDuctId(shopUserDuty.getId(), skuIds);
|
|
||||||
|
|
||||||
Map<Integer, ShopUserDutyDetail> map = new HashMap<>();
|
|
||||||
for (ShopUserDutyDetail shopUserDutyDetail : details) {
|
|
||||||
map.put(shopUserDutyDetail.getSkuId(), shopUserDutyDetail);
|
|
||||||
}
|
|
||||||
List<ShopUserDutyDetail> detaiList = new ArrayList<>();
|
|
||||||
for (TbOrderDetail orderDetail : list) {
|
|
||||||
if (map.containsKey(orderDetail.getProductSkuId())) {
|
|
||||||
ShopUserDutyDetail shopUserDutyDetail = map.get(orderDetail.getProductSkuId());
|
|
||||||
shopUserDutyDetail.setNum(shopUserDutyDetail.getNum() + orderDetail.getNum());
|
|
||||||
shopUserDutyDetail.setAmount(shopUserDutyDetail.getAmount().add(orderDetail.getPriceAmount().add(orderDetail.getPackAmount())));
|
|
||||||
shopUserDutyDetailMapper.updateByPrimaryKeySelective(shopUserDutyDetail);
|
|
||||||
} else {
|
|
||||||
ShopUserDutyDetail shopUserDutyDetail = new ShopUserDutyDetail();
|
|
||||||
shopUserDutyDetail.setDutyId(shopUserDuty.getId());
|
|
||||||
shopUserDutyDetail.setAmount(orderDetail.getPriceAmount());
|
|
||||||
shopUserDutyDetail.setNum(orderDetail.getNum());
|
|
||||||
shopUserDutyDetail.setSkuId(orderDetail.getProductSkuId());
|
|
||||||
shopUserDutyDetail.setSkuName(orderDetail.getProductSkuName());
|
|
||||||
shopUserDutyDetail.setProductId(orderDetail.getProductId());
|
|
||||||
shopUserDutyDetail.setProductName(orderDetail.getProductName());
|
|
||||||
detaiList.add(shopUserDutyDetail);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (detaiList.size() > 0) {
|
|
||||||
shopUserDutyDetailMapper.batchInsert(detaiList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ShopUserDutyPay shopUserDutyPay = shopUserDutyPayMapper.selectByDuctIdAndType(shopUserDuty.getId(),orderInfo.getPayType());
|
|
||||||
if (Objects.nonNull(shopUserDutyPay)){
|
|
||||||
shopUserDutyPay.setAmount(orderInfo.getOrderAmount().add(shopUserDutyPay.getAmount()));
|
|
||||||
shopUserDutyPayMapper.updateByPrimaryKeySelective(shopUserDutyPay);
|
|
||||||
}else {
|
|
||||||
shopUserDutyPay=new ShopUserDutyPay();
|
|
||||||
shopUserDutyPay.setDutyId(shopUserDuty.getId());
|
|
||||||
shopUserDutyPay.setType(orderInfo.getPayType());
|
|
||||||
shopUserDutyPay.setAmount(orderInfo.getOrderAmount());
|
|
||||||
shopUserDutyPayMapper.insert(shopUserDutyPay);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
if (type.equals("close")){
|
|
||||||
shopUserDutyMapper.updateStatusByTokenId(tbToken.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.getMessage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
String sss = "{\"data\":{\"orderId\":\"1\",\"payAmount\":3.60,\"returnDetails\":[{\"cetyId\":\"2\",\"id\":\"1\",\"number\":\"5\"},{\"cetyId\":\"3\",\"id\":\"2\",\"number\":\"9\"}]},\"type\":\"return\",\"token\":\"黑龙江省王大秃子屯\"}";
|
|
||||||
JSONObject jsonObject = JSON.parseObject(sss);
|
|
||||||
JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("returnDetails");
|
|
||||||
for (int i = 0;i<jsonArray.size();i++){
|
|
||||||
JSONObject object = jsonArray.getJSONObject(i);
|
|
||||||
System.out.println(object.getInteger("cetyId"));
|
|
||||||
System.out.println(object.getInteger("number"));
|
|
||||||
}
|
|
||||||
System.out.println(jsonArray);
|
|
||||||
System.out.println(jsonObject.getJSONObject("data").getBigDecimal("payAmount"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,260 @@
|
||||||
|
package com.chaozhanggui.system.cashierservice.service;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||||
|
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||||
|
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||||
|
import com.chaozhanggui.system.cashierservice.model.CategoryInfo;
|
||||||
|
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
|
||||||
|
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||||
|
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||||
|
import com.chaozhanggui.system.cashierservice.util.*;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class DutyService {
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TbTokenMapper tbTokenMapper;
|
||||||
|
@Autowired
|
||||||
|
private TbOrderDetailMapper orderDetailMapper;
|
||||||
|
@Autowired
|
||||||
|
private TbOrderInfoMapper orderInfoMapper;
|
||||||
|
@Autowired
|
||||||
|
private ShopUserDutyDetailMapper shopUserDutyDetailMapper;
|
||||||
|
@Autowired
|
||||||
|
private ShopUserDutyMapper shopUserDutyMapper;
|
||||||
|
@Autowired
|
||||||
|
private TbShopInfoMapper shopInfoMapper;
|
||||||
|
@Autowired
|
||||||
|
private ShopUserDutyPayMapper shopUserDutyPayMapper;
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void exect(String message) {
|
||||||
|
try {
|
||||||
|
System.out.println("数据落地开始");
|
||||||
|
JSONObject jsonObject = JSON.parseObject(message);
|
||||||
|
String token = jsonObject.getString("token");
|
||||||
|
String type = jsonObject.getString("type");
|
||||||
|
TbToken tbToken = tbTokenMapper.selectByToken(token);
|
||||||
|
if (type.equals("return") || type.equals("create")) {
|
||||||
|
if (Objects.isNull(tbToken)) {
|
||||||
|
throw new MsgException("当前用户不存在");
|
||||||
|
}
|
||||||
|
Integer tokenId = tbToken.getId();
|
||||||
|
Integer orderId = jsonObject.getInteger("orderId");
|
||||||
|
JSONObject tokenJson = TokenUtil.parseParamFromToken(tbToken.getToken());
|
||||||
|
Integer shopId = tokenJson.getInteger("shopId");
|
||||||
|
Integer userId = tokenJson.getInteger("staffId");
|
||||||
|
String loginName = tokenJson.getString("loginName");
|
||||||
|
TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId);
|
||||||
|
if (Objects.isNull(orderInfo) && orderId > 0) {
|
||||||
|
throw new MsgException("订单不存在");
|
||||||
|
}
|
||||||
|
List<TbOrderDetail> list = orderDetailMapper.selectAllByOrderId(orderId);
|
||||||
|
ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByTokenId(tokenId);
|
||||||
|
BigDecimal cashAmount = BigDecimal.ZERO;
|
||||||
|
if (orderInfo.getPayType().equals("cash")) {
|
||||||
|
cashAmount = orderInfo.getPayAmount();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type.equals("create")) {
|
||||||
|
if (Objects.isNull(shopUserDuty)) {
|
||||||
|
shopUserDuty = new ShopUserDuty(userId, tbToken.getCreateTime(), 1, orderInfo.getOrderAmount(), loginName, "0",
|
||||||
|
orderInfo.getOrderAmount(), shopId, BigDecimal.ZERO, cashAmount, BigDecimal.ZERO, "");
|
||||||
|
shopUserDuty.setTokenId(tokenId);
|
||||||
|
shopUserDuty.setReturnAmount(BigDecimal.ZERO);
|
||||||
|
shopUserDuty.setTradeDay(DateUtils.getDay());
|
||||||
|
shopUserDutyMapper.insert(shopUserDuty);
|
||||||
|
List<ShopUserDutyDetail> detaiList = new ArrayList<>();
|
||||||
|
for (TbOrderDetail orderDetail : list) {
|
||||||
|
ShopUserDutyDetail shopUserDutyDetail = new ShopUserDutyDetail();
|
||||||
|
shopUserDutyDetail.setDutyId(shopUserDuty.getId());
|
||||||
|
shopUserDutyDetail.setAmount(orderDetail.getPriceAmount());
|
||||||
|
shopUserDutyDetail.setNum(orderDetail.getNum());
|
||||||
|
shopUserDutyDetail.setSkuId(orderDetail.getProductSkuId());
|
||||||
|
shopUserDutyDetail.setSkuName(orderDetail.getProductSkuName());
|
||||||
|
shopUserDutyDetail.setProductId(orderDetail.getProductId());
|
||||||
|
shopUserDutyDetail.setProductName(orderDetail.getProductName());
|
||||||
|
detaiList.add(shopUserDutyDetail);
|
||||||
|
}
|
||||||
|
if (detaiList.size() > 0) {
|
||||||
|
shopUserDutyDetailMapper.batchInsert(detaiList);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
shopUserDuty.setAmount(shopUserDuty.getAmount().add(orderInfo.getPayAmount()));
|
||||||
|
shopUserDuty.setCashAmount(shopUserDuty.getCashAmount().add(cashAmount));
|
||||||
|
shopUserDuty.setIncomeAmount(shopUserDuty.getIncomeAmount().add(orderInfo.getPayAmount()));
|
||||||
|
shopUserDuty.setOrderNum(shopUserDuty.getOrderNum() + 1);
|
||||||
|
shopUserDutyMapper.updateByPrimaryKeySelective(shopUserDuty);
|
||||||
|
List<Integer> skuIds = new ArrayList<>();
|
||||||
|
for (TbOrderDetail orderDetail : list) {
|
||||||
|
skuIds.add(orderDetail.getProductSkuId());
|
||||||
|
}
|
||||||
|
List<ShopUserDutyDetail> details = shopUserDutyDetailMapper.selectByDuctId(shopUserDuty.getId(), skuIds);
|
||||||
|
|
||||||
|
Map<Integer, ShopUserDutyDetail> map = new HashMap<>();
|
||||||
|
for (ShopUserDutyDetail shopUserDutyDetail : details) {
|
||||||
|
map.put(shopUserDutyDetail.getSkuId(), shopUserDutyDetail);
|
||||||
|
}
|
||||||
|
List<ShopUserDutyDetail> detaiList = new ArrayList<>();
|
||||||
|
for (TbOrderDetail orderDetail : list) {
|
||||||
|
if (map.containsKey(orderDetail.getProductSkuId())) {
|
||||||
|
ShopUserDutyDetail shopUserDutyDetail = map.get(orderDetail.getProductSkuId());
|
||||||
|
shopUserDutyDetail.setNum(shopUserDutyDetail.getNum() + orderDetail.getNum());
|
||||||
|
shopUserDutyDetail.setAmount(shopUserDutyDetail.getAmount().add(orderDetail.getPriceAmount().add(orderDetail.getPackAmount())));
|
||||||
|
shopUserDutyDetailMapper.updateByPrimaryKeySelective(shopUserDutyDetail);
|
||||||
|
} else {
|
||||||
|
ShopUserDutyDetail shopUserDutyDetail = new ShopUserDutyDetail();
|
||||||
|
shopUserDutyDetail.setDutyId(shopUserDuty.getId());
|
||||||
|
shopUserDutyDetail.setAmount(orderDetail.getPriceAmount());
|
||||||
|
shopUserDutyDetail.setNum(orderDetail.getNum());
|
||||||
|
shopUserDutyDetail.setSkuId(orderDetail.getProductSkuId());
|
||||||
|
shopUserDutyDetail.setSkuName(orderDetail.getProductSkuName());
|
||||||
|
shopUserDutyDetail.setProductId(orderDetail.getProductId());
|
||||||
|
shopUserDutyDetail.setProductName(orderDetail.getProductName());
|
||||||
|
detaiList.add(shopUserDutyDetail);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (detaiList.size() > 0) {
|
||||||
|
shopUserDutyDetailMapper.batchInsert(detaiList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ShopUserDutyPay shopUserDutyPay = shopUserDutyPayMapper.selectByDuctIdAndType(shopUserDuty.getId(),orderInfo.getPayType());
|
||||||
|
if (Objects.nonNull(shopUserDutyPay)){
|
||||||
|
shopUserDutyPay.setAmount(orderInfo.getOrderAmount().add(shopUserDutyPay.getAmount()));
|
||||||
|
shopUserDutyPayMapper.updateByPrimaryKeySelective(shopUserDutyPay);
|
||||||
|
}else {
|
||||||
|
shopUserDutyPay=new ShopUserDutyPay();
|
||||||
|
shopUserDutyPay.setDutyId(shopUserDuty.getId());
|
||||||
|
shopUserDutyPay.setType(orderInfo.getPayType());
|
||||||
|
shopUserDutyPay.setAmount(orderInfo.getOrderAmount());
|
||||||
|
shopUserDutyPayMapper.insert(shopUserDutyPay);
|
||||||
|
}
|
||||||
|
} else if (type.equals("return")) {
|
||||||
|
BigDecimal amount = jsonObject.getBigDecimal("amount");
|
||||||
|
if (Objects.isNull(shopUserDuty)) {
|
||||||
|
shopUserDuty = new ShopUserDuty(userId, tbToken.getCreateTime(), 1, BigDecimal.ZERO, loginName, "0",
|
||||||
|
BigDecimal.ZERO, shopId, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, "");
|
||||||
|
shopUserDuty.setReturnAmount(amount);
|
||||||
|
shopUserDuty.setTokenId(tokenId);
|
||||||
|
shopUserDuty.setTradeDay(DateUtils.getDay());
|
||||||
|
shopUserDutyMapper.insert(shopUserDuty);
|
||||||
|
} else {
|
||||||
|
shopUserDuty.setReturnAmount(shopUserDuty.getReturnAmount().add(amount));
|
||||||
|
shopUserDutyMapper.updateByPrimaryKeySelective(shopUserDuty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (type.equals("wxcreate")) {
|
||||||
|
String day = DateUtils.getDay();
|
||||||
|
Integer orderId = jsonObject.getInteger("orderId");
|
||||||
|
TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId);
|
||||||
|
if (Objects.isNull(orderInfo)) {
|
||||||
|
throw new MsgException("订单不存在");
|
||||||
|
}
|
||||||
|
List<TbOrderDetail> list = orderDetailMapper.selectAllByOrderId(orderId);
|
||||||
|
BigDecimal cashAmount = BigDecimal.ZERO;
|
||||||
|
if (orderInfo.getPayType().equals("cash")) {
|
||||||
|
cashAmount = orderInfo.getPayAmount();
|
||||||
|
}
|
||||||
|
ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByTokenIdAndTradeDay(0, day, orderInfo.getShopId());
|
||||||
|
TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getShopId()));
|
||||||
|
if (Objects.isNull(shopUserDuty)) {
|
||||||
|
shopUserDuty = new ShopUserDuty(Integer.valueOf(orderInfo.getShopId()), new Date(), 1, orderInfo.getOrderAmount(), "", "0",
|
||||||
|
orderInfo.getOrderAmount(), Integer.valueOf(orderInfo.getShopId()), BigDecimal.ZERO, cashAmount, BigDecimal.ZERO, "");
|
||||||
|
shopUserDuty.setTokenId(0);
|
||||||
|
shopUserDuty.setType("wx");
|
||||||
|
if (Objects.nonNull(shopInfo)) {
|
||||||
|
shopUserDuty.setUserName(shopInfo.getShopName());
|
||||||
|
}
|
||||||
|
shopUserDuty.setTradeDay(DateUtils.getDay());
|
||||||
|
shopUserDutyMapper.insert(shopUserDuty);
|
||||||
|
List<ShopUserDutyDetail> detaiList = new ArrayList<>();
|
||||||
|
for (TbOrderDetail orderDetail : list) {
|
||||||
|
ShopUserDutyDetail shopUserDutyDetail = new ShopUserDutyDetail();
|
||||||
|
shopUserDutyDetail.setDutyId(shopUserDuty.getId());
|
||||||
|
shopUserDutyDetail.setAmount(orderDetail.getPriceAmount());
|
||||||
|
shopUserDutyDetail.setNum(orderDetail.getNum());
|
||||||
|
shopUserDutyDetail.setSkuId(orderDetail.getProductSkuId());
|
||||||
|
shopUserDutyDetail.setSkuName(orderDetail.getProductSkuName());
|
||||||
|
shopUserDutyDetail.setProductId(orderDetail.getProductId());
|
||||||
|
shopUserDutyDetail.setProductName(orderDetail.getProductName());
|
||||||
|
detaiList.add(shopUserDutyDetail);
|
||||||
|
}
|
||||||
|
if (detaiList.size() > 0) {
|
||||||
|
shopUserDutyDetailMapper.batchInsert(detaiList);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
shopUserDuty.setAmount(shopUserDuty.getAmount().add(orderInfo.getPayAmount()));
|
||||||
|
shopUserDuty.setCashAmount(shopUserDuty.getCashAmount().add(cashAmount));
|
||||||
|
shopUserDuty.setIncomeAmount(shopUserDuty.getIncomeAmount().add(orderInfo.getPayAmount()));
|
||||||
|
shopUserDuty.setOrderNum(shopUserDuty.getOrderNum() + 1);
|
||||||
|
shopUserDutyMapper.updateByPrimaryKeySelective(shopUserDuty);
|
||||||
|
List<Integer> skuIds = new ArrayList<>();
|
||||||
|
for (TbOrderDetail orderDetail : list) {
|
||||||
|
skuIds.add(orderDetail.getProductSkuId());
|
||||||
|
}
|
||||||
|
List<ShopUserDutyDetail> details = shopUserDutyDetailMapper.selectByDuctId(shopUserDuty.getId(), skuIds);
|
||||||
|
|
||||||
|
Map<Integer, ShopUserDutyDetail> map = new HashMap<>();
|
||||||
|
for (ShopUserDutyDetail shopUserDutyDetail : details) {
|
||||||
|
map.put(shopUserDutyDetail.getSkuId(), shopUserDutyDetail);
|
||||||
|
}
|
||||||
|
List<ShopUserDutyDetail> detaiList = new ArrayList<>();
|
||||||
|
for (TbOrderDetail orderDetail : list) {
|
||||||
|
if (map.containsKey(orderDetail.getProductSkuId())) {
|
||||||
|
ShopUserDutyDetail shopUserDutyDetail = map.get(orderDetail.getProductSkuId());
|
||||||
|
shopUserDutyDetail.setNum(shopUserDutyDetail.getNum() + orderDetail.getNum());
|
||||||
|
shopUserDutyDetail.setAmount(shopUserDutyDetail.getAmount().add(orderDetail.getPriceAmount().add(orderDetail.getPackAmount())));
|
||||||
|
shopUserDutyDetailMapper.updateByPrimaryKeySelective(shopUserDutyDetail);
|
||||||
|
} else {
|
||||||
|
ShopUserDutyDetail shopUserDutyDetail = new ShopUserDutyDetail();
|
||||||
|
shopUserDutyDetail.setDutyId(shopUserDuty.getId());
|
||||||
|
shopUserDutyDetail.setAmount(orderDetail.getPriceAmount());
|
||||||
|
shopUserDutyDetail.setNum(orderDetail.getNum());
|
||||||
|
shopUserDutyDetail.setSkuId(orderDetail.getProductSkuId());
|
||||||
|
shopUserDutyDetail.setSkuName(orderDetail.getProductSkuName());
|
||||||
|
shopUserDutyDetail.setProductId(orderDetail.getProductId());
|
||||||
|
shopUserDutyDetail.setProductName(orderDetail.getProductName());
|
||||||
|
detaiList.add(shopUserDutyDetail);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (detaiList.size() > 0) {
|
||||||
|
shopUserDutyDetailMapper.batchInsert(detaiList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ShopUserDutyPay shopUserDutyPay = shopUserDutyPayMapper.selectByDuctIdAndType(shopUserDuty.getId(),orderInfo.getPayType());
|
||||||
|
if (Objects.nonNull(shopUserDutyPay)){
|
||||||
|
shopUserDutyPay.setAmount(orderInfo.getOrderAmount().add(shopUserDutyPay.getAmount()));
|
||||||
|
shopUserDutyPayMapper.updateByPrimaryKeySelective(shopUserDutyPay);
|
||||||
|
}else {
|
||||||
|
shopUserDutyPay=new ShopUserDutyPay();
|
||||||
|
shopUserDutyPay.setDutyId(shopUserDuty.getId());
|
||||||
|
shopUserDutyPay.setType(orderInfo.getPayType());
|
||||||
|
shopUserDutyPay.setAmount(orderInfo.getOrderAmount());
|
||||||
|
shopUserDutyPayMapper.insert(shopUserDutyPay);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if (type.equals("close")){
|
||||||
|
shopUserDutyMapper.updateStatusByTokenId(tbToken.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue