package com.taoke.autopay.service.impl;
|
|
import com.taoke.autopay.dao.KeyOrderMapper;
|
import com.taoke.autopay.entity.KeyOrder;
|
import com.taoke.autopay.entity.OrderDistributeCountInfo;
|
import com.taoke.autopay.exception.KeyOrderException;
|
import com.taoke.autopay.factory.OrderFactory;
|
import com.taoke.autopay.service.KeyOrderService;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.util.Comparator;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* @author hxh
|
* @title: KeyOrderServiceImpl
|
* @description: TODO
|
* @date 2024/6/14 19:12
|
*/
|
@Service
|
public class KeyOrderServiceImpl implements KeyOrderService {
|
|
@Resource
|
private KeyOrderMapper keyOrderMapper;
|
|
|
@Override
|
public KeyOrder selectById(String id) {
|
return keyOrderMapper.selectById(id);
|
}
|
|
@Override
|
public KeyOrder addKeyOrder(String key) throws KeyOrderException {
|
String id = OrderFactory.createId(key);
|
KeyOrder order = keyOrderMapper.selectById(id);
|
if(order!=null){
|
throw new KeyOrderException("请勿重复提交口令");
|
}
|
order =new KeyOrder();
|
order.setId(id);
|
order.setKey(key);
|
order.setState(KeyOrder.STATE_NOT_PROCESS);
|
order.setStateDesc("尚未处理");
|
order.setCreateTime(new Date());
|
keyOrderMapper.insertSelective(order);
|
return order;
|
}
|
|
@Transactional(rollbackFor = Exception.class)
|
@Override
|
public void update(KeyOrder keyOrder) {
|
if (keyOrder.getId() == null) {
|
return;
|
}
|
KeyOrder old = keyOrderMapper.selectByPrimaryKeyForUpdate(keyOrder.getId());
|
if (old == null) {
|
return;
|
}
|
if (keyOrder.getUpdateTime() == null) {
|
keyOrder.setUpdateTime(new Date());
|
}
|
keyOrderMapper.updateByPrimaryKeySelective(keyOrder);
|
}
|
|
@Transactional(rollbackFor = Exception.class)
|
@Override
|
public void setOrderInfo(String id,String orderNo, int orderState) throws KeyOrderException{
|
KeyOrder old = keyOrderMapper.selectByPrimaryKeyForUpdate(id);
|
if (old == null) {
|
throw new KeyOrderException("口令不存在");
|
}
|
KeyOrder keyOrder=new KeyOrder();
|
keyOrder.setId(id);
|
// 默认1抖音
|
keyOrder.setOrderType(1);
|
keyOrder.setOrderNo(orderNo);
|
if (keyOrder.getUpdateTime() == null) {
|
keyOrder.setUpdateTime(new Date());
|
}
|
keyOrder.setOrderState(orderState);
|
keyOrderMapper.updateByPrimaryKeySelective(keyOrder);
|
}
|
|
@Override
|
public List<KeyOrder> list(KeyOrderMapper.DaoQuery query) {
|
return keyOrderMapper.list(query);
|
}
|
|
@Override
|
public long count(KeyOrderMapper.DaoQuery query) {
|
return keyOrderMapper.count(query);
|
}
|
|
@Override
|
public Long getCanDistributeUid() {
|
List<OrderDistributeCountInfo> list = keyOrderMapper.listDistributeUids();
|
if(list==null||list.size()==0){
|
return null;
|
}
|
Comparator<OrderDistributeCountInfo> cm = (OrderDistributeCountInfo o1, OrderDistributeCountInfo o2)-> o1.getCount()-o2.getCount();
|
list.sort(cm);
|
return list.get(0).getUid();
|
}
|
|
@Override
|
public List<KeyOrder> listNotDistributed(int page, int pageSize) {
|
return keyOrderMapper.listNotDistributed((page-1)*pageSize,pageSize);
|
}
|
}
|