| | |
| | | package com.yeshi.fanli.service.impl.order.dividents;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.Date;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.order.dividents.TeamDividentsSourceOrderMapper;
|
| | | import com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrder;
|
| | | import com.yeshi.fanli.exception.ParamsException;
|
| | | import com.yeshi.fanli.exception.order.dividents.TeamDividentsSourceOrderException;
|
| | | import com.yeshi.fanli.service.inter.order.dividents.TeamDividentsSourceOrderService;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | | @Service
|
| | | public class TeamDividentsSourceOrderServiceImpl implements TeamDividentsSourceOrderService {
|
| | |
|
| | | @Resource
|
| | | private TeamDividentsSourceOrderMapper teamDividentsSourceOrderMapper;
|
| | |
|
| | | @Override
|
| | | public TeamDividentsSourceOrder addTeamDividentsSourceOrder(TeamDividentsSourceOrder order)
|
| | | throws TeamDividentsSourceOrderException, ParamsException {
|
| | | if (order == null || order.getMoney() == null || StringUtil.isNullOrEmpty(order.getOrderNo())
|
| | | || order.getSourceType() == null || order.getState() == null || order.getUid() == null)
|
| | | throw new ParamsException(1, "参数不完整");
|
| | |
|
| | | TeamDividentsSourceOrder sourceOrder = selectByOrderNoSourceType(order.getOrderNo(), order.getSourceType());
|
| | | if (sourceOrder != null)
|
| | | throw new TeamDividentsSourceOrderException(TeamDividentsSourceOrderException.CODE_EXIST, "订单已存在");
|
| | |
|
| | | if (order.getCreateTime() == null)
|
| | | order.setCreateTime(new Date());
|
| | | teamDividentsSourceOrderMapper.insertSelective(order);
|
| | |
|
| | | return order;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public TeamDividentsSourceOrder selectByPrimaryKeyForUpdate(Long id) {
|
| | | return teamDividentsSourceOrderMapper.selectByPrimaryKeyForUpdate(id);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void invalidOrder(String orderNo, int sourceType, String beiZhu) {
|
| | | TeamDividentsSourceOrder order = selectByOrderNoSourceType(orderNo, sourceType);
|
| | | if (order == null)
|
| | | return;
|
| | | if (order.getState() != TeamDividentsSourceOrder.STATE_CAN_SEND)
|
| | | return;
|
| | | TeamDividentsSourceOrder update = new TeamDividentsSourceOrder();
|
| | | update.setId(order.getId());
|
| | | update.setState(TeamDividentsSourceOrder.STATE_INVALID);
|
| | | update.setUpdateTime(new Date());
|
| | | update.setBeiZhu(beiZhu);
|
| | | teamDividentsSourceOrderMapper.updateByPrimaryKeySelective(update);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void invalidOrderByUid(Long uid, String beiZhu) {
|
| | | teamDividentsSourceOrderMapper.setStateByUidAndState(uid, TeamDividentsSourceOrder.STATE_INVALID,
|
| | | TeamDividentsSourceOrder.STATE_CAN_SEND, beiZhu);
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public void send(Long id) {
|
| | | TeamDividentsSourceOrder order = teamDividentsSourceOrderMapper.selectByPrimaryKeyForUpdate(id);
|
| | | if (order == null)
|
| | | return;
|
| | | if (order.getState() != TeamDividentsSourceOrder.STATE_CAN_SEND)
|
| | | return;
|
| | | TeamDividentsSourceOrder update = new TeamDividentsSourceOrder();
|
| | | update.setId(order.getId());
|
| | | update.setState(TeamDividentsSourceOrder.STATE_ALREADY_SEND);
|
| | | update.setUpdateTime(new Date());
|
| | | update.setSendTime(new Date());
|
| | | teamDividentsSourceOrderMapper.updateByPrimaryKeySelective(update);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public TeamDividentsSourceOrder selectByOrderNoSourceType(String orderNo, int sourceType) {
|
| | |
|
| | | return teamDividentsSourceOrderMapper.selectByOrderNoAndSourceType(orderNo, sourceType);
|
| | |
|
| | | }
|
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void orderSettle(String orderNo, int sourceType, Date preSendTime, BigDecimal income) {
|
| | | TeamDividentsSourceOrder order = selectByOrderNoSourceType(orderNo, sourceType);
|
| | | if (order == null)
|
| | | return;
|
| | | if (order.getState() == TeamDividentsSourceOrder.STATE_UNKOWN) {
|
| | | TeamDividentsSourceOrder update = new TeamDividentsSourceOrder();
|
| | | update.setId(order.getId());
|
| | | update.setMoney(income);
|
| | | update.setState(TeamDividentsSourceOrder.STATE_CAN_SEND);
|
| | | update.setPreSendTime(preSendTime);
|
| | | update.setUpdateTime(new Date());
|
| | | teamDividentsSourceOrderMapper.updateByPrimaryKeySelective(update);
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void updateMoney(String orderNo, int sourceType, BigDecimal money) {
|
| | |
|
| | | TeamDividentsSourceOrder order = selectByOrderNoSourceType(orderNo, sourceType);
|
| | | if (order == null)
|
| | | return;
|
| | | if (order.getState() == TeamDividentsSourceOrder.STATE_UNKOWN) {
|
| | | TeamDividentsSourceOrder update = new TeamDividentsSourceOrder();
|
| | | update.setId(order.getId());
|
| | | update.setMoney(money);
|
| | | update.setUpdateTime(new Date());
|
| | | teamDividentsSourceOrderMapper.updateByPrimaryKeySelective(update);
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.service.impl.order.dividents; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.yeshi.fanli.dao.mybatis.order.dividents.TeamDividentsSourceOrderMapper; |
| | | import com.yeshi.fanli.entity.order.dividents.TeamDividentsSourceOrder; |
| | | import com.yeshi.fanli.exception.ParamsException; |
| | | import com.yeshi.fanli.exception.order.dividents.TeamDividentsSourceOrderException; |
| | | import com.yeshi.fanli.service.inter.order.dividents.TeamDividentsSourceOrderService; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | |
| | | @Service |
| | | public class TeamDividentsSourceOrderServiceImpl implements TeamDividentsSourceOrderService { |
| | | |
| | | @Resource |
| | | private TeamDividentsSourceOrderMapper teamDividentsSourceOrderMapper; |
| | | |
| | | @Override |
| | | public TeamDividentsSourceOrder addTeamDividentsSourceOrder(TeamDividentsSourceOrder order) |
| | | throws TeamDividentsSourceOrderException, ParamsException { |
| | | if (order == null || order.getMoney() == null || StringUtil.isNullOrEmpty(order.getOrderNo()) |
| | | || order.getSourceType() == null || order.getState() == null || order.getUid() == null) |
| | | throw new ParamsException(1, "参数不完整"); |
| | | |
| | | TeamDividentsSourceOrder sourceOrder = selectByOrderNoSourceType(order.getOrderNo(), order.getSourceType()); |
| | | if (sourceOrder != null) |
| | | throw new TeamDividentsSourceOrderException(TeamDividentsSourceOrderException.CODE_EXIST, "订单已存在"); |
| | | |
| | | if (order.getCreateTime() == null) |
| | | order.setCreateTime(new Date()); |
| | | teamDividentsSourceOrderMapper.insertSelective(order); |
| | | |
| | | return order; |
| | | } |
| | | |
| | | @Override |
| | | public TeamDividentsSourceOrder selectByPrimaryKeyForUpdate(Long id) { |
| | | return teamDividentsSourceOrderMapper.selectByPrimaryKeyForUpdate(id); |
| | | } |
| | | |
| | | @Override |
| | | public void invalidOrder(String orderNo, int sourceType, String beiZhu) { |
| | | TeamDividentsSourceOrder order = selectByOrderNoSourceType(orderNo, sourceType); |
| | | if (order == null) |
| | | return; |
| | | if (order.getState() != TeamDividentsSourceOrder.STATE_CAN_SEND) |
| | | return; |
| | | TeamDividentsSourceOrder update = new TeamDividentsSourceOrder(); |
| | | update.setId(order.getId()); |
| | | update.setState(TeamDividentsSourceOrder.STATE_INVALID); |
| | | update.setUpdateTime(new Date()); |
| | | update.setBeiZhu(beiZhu); |
| | | teamDividentsSourceOrderMapper.updateByPrimaryKeySelective(update); |
| | | } |
| | | |
| | | @Override |
| | | public void invalidOrderByUid(Long uid, String beiZhu) { |
| | | teamDividentsSourceOrderMapper.setStateByUidAndState(uid, TeamDividentsSourceOrder.STATE_INVALID, |
| | | TeamDividentsSourceOrder.STATE_CAN_SEND, beiZhu); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void send(Long id) { |
| | | TeamDividentsSourceOrder order = teamDividentsSourceOrderMapper.selectByPrimaryKeyForUpdate(id); |
| | | if (order == null) |
| | | return; |
| | | if (order.getState() != TeamDividentsSourceOrder.STATE_CAN_SEND) |
| | | return; |
| | | TeamDividentsSourceOrder update = new TeamDividentsSourceOrder(); |
| | | update.setId(order.getId()); |
| | | update.setState(TeamDividentsSourceOrder.STATE_ALREADY_SEND); |
| | | update.setUpdateTime(new Date()); |
| | | update.setSendTime(new Date()); |
| | | teamDividentsSourceOrderMapper.updateByPrimaryKeySelective(update); |
| | | } |
| | | |
| | | @Override |
| | | public TeamDividentsSourceOrder selectByOrderNoSourceType(String orderNo, int sourceType) { |
| | | |
| | | return teamDividentsSourceOrderMapper.selectByOrderNoAndSourceType(orderNo, sourceType); |
| | | |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void orderSettle(String orderNo, int sourceType, Date preSendTime, BigDecimal income) { |
| | | TeamDividentsSourceOrder order = selectByOrderNoSourceType(orderNo, sourceType); |
| | | if (order == null) |
| | | return; |
| | | if (order.getState() == TeamDividentsSourceOrder.STATE_UNKOWN) { |
| | | TeamDividentsSourceOrder update = new TeamDividentsSourceOrder(); |
| | | update.setId(order.getId()); |
| | | update.setMoney(income); |
| | | update.setState(TeamDividentsSourceOrder.STATE_CAN_SEND); |
| | | update.setPreSendTime(preSendTime); |
| | | update.setUpdateTime(new Date()); |
| | | teamDividentsSourceOrderMapper.updateByPrimaryKeySelective(update); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void updateMoney(String orderNo, int sourceType, BigDecimal money) { |
| | | |
| | | TeamDividentsSourceOrder order = selectByOrderNoSourceType(orderNo, sourceType); |
| | | if (order == null) |
| | | return; |
| | | if (order.getState() == TeamDividentsSourceOrder.STATE_UNKOWN) { |
| | | TeamDividentsSourceOrder update = new TeamDividentsSourceOrder(); |
| | | update.setId(order.getId()); |
| | | update.setMoney(money); |
| | | update.setUpdateTime(new Date()); |
| | | teamDividentsSourceOrderMapper.updateByPrimaryKeySelective(update); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public List<TeamDividentsSourceOrder> listByOrderNoOrUid(String orderNo, Long uid) { |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public List<TeamDividentsSourceOrder> listByOrderNo(String orderNo) { |
| | | return teamDividentsSourceOrderMapper.listByOrderNo(orderNo); |
| | | } |
| | | |
| | | } |