|
@@ -15,11 +15,13 @@ import com.ruoyi.dz.domain.DzCardsOpen;
|
|
|
import com.ruoyi.dz.mapper.DzAgentMapper;
|
|
import com.ruoyi.dz.mapper.DzAgentMapper;
|
|
|
import com.ruoyi.dz.mapper.DzCardsOpenMapper;
|
|
import com.ruoyi.dz.mapper.DzCardsOpenMapper;
|
|
|
import com.ruoyi.enums.*;
|
|
import com.ruoyi.enums.*;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
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.ruoyi.dz.mapper.DzCardsMapper;
|
|
import com.ruoyi.dz.mapper.DzCardsMapper;
|
|
|
import com.ruoyi.dz.domain.DzCards;
|
|
import com.ruoyi.dz.domain.DzCards;
|
|
|
import com.ruoyi.dz.service.IDzCardsService;
|
|
import com.ruoyi.dz.service.IDzCardsService;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import javax.validation.ValidationException;
|
|
import javax.validation.ValidationException;
|
|
|
|
|
|
|
@@ -125,12 +127,16 @@ public class DzCardsServiceImpl implements IDzCardsService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void issue(Long deptId, Integer type, Integer begin, Integer end) {
|
|
|
|
|
-
|
|
|
|
|
- for(Integer i = begin; i<= end; i++) {
|
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public void issueCard(Long deptId, CardType type, Integer count) {
|
|
|
|
|
+ Long maxNo = dzCardsMapper.selectMaxNo(type.getVal());
|
|
|
|
|
+ if(null == maxNo) {
|
|
|
|
|
+ maxNo = type.getVal() * 10000000L;
|
|
|
|
|
+ }
|
|
|
|
|
+ for(Integer i = 1; i <= count; i++) {
|
|
|
DzCards c = new DzCards();
|
|
DzCards c = new DzCards();
|
|
|
- c.setType(type);
|
|
|
|
|
- c.setCardNo(String.format(format, type, i));
|
|
|
|
|
|
|
+ c.setType(type.getVal());
|
|
|
|
|
+ c.setCardNo(String.valueOf(maxNo + i));
|
|
|
c.setPassword(RandomUtil.randomNumbers(6));
|
|
c.setPassword(RandomUtil.randomNumbers(6));
|
|
|
c.setDistributeStatus(CardDistributeStatus.Free.getVal());
|
|
c.setDistributeStatus(CardDistributeStatus.Free.getVal());
|
|
|
c.setStatus(CardStatus.Free.getVal());
|
|
c.setStatus(CardStatus.Free.getVal());
|
|
@@ -143,28 +149,27 @@ public class DzCardsServiceImpl implements IDzCardsService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void assign(Long agentId, String beginNo, String endNo) {
|
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public void assignCard(Long agentId, Long leafAgentId, String beginNo, String endNo) {
|
|
|
CardCriteria cond = new CardCriteria();
|
|
CardCriteria cond = new CardCriteria();
|
|
|
cond.setStartNo(beginNo);
|
|
cond.setStartNo(beginNo);
|
|
|
cond.setEndNo(endNo);
|
|
cond.setEndNo(endNo);
|
|
|
DzCards dzCards = new DzCards();
|
|
DzCards dzCards = new DzCards();
|
|
|
- DzAgent agent = dzAgentMapper.selectDzAgentByAgentId(agentId);
|
|
|
|
|
dzCardsMapper.selectListByCond(cond).stream().forEach(c -> {
|
|
dzCardsMapper.selectListByCond(cond).stream().forEach(c -> {
|
|
|
dzCards.setCardId(c.getCardId());
|
|
dzCards.setCardId(c.getCardId());
|
|
|
- if(null != agent.getParentId()) {
|
|
|
|
|
- dzCards.setAgentId(agent.getParentId());
|
|
|
|
|
- dzCards.setLeftAgentId(agent.getAgentId());
|
|
|
|
|
- } else {
|
|
|
|
|
- dzCards.setAgentId(agent.getAgentId());
|
|
|
|
|
- dzCards.setLeftAgentId(agent.getAgentId());
|
|
|
|
|
|
|
+ if(null != c.getAgentId() && !c.getAgentId().equals(agentId)) {
|
|
|
|
|
+ throw new ValidationException("卡分配错误");
|
|
|
}
|
|
}
|
|
|
|
|
+ dzCards.setAgentId(agentId);
|
|
|
|
|
+ dzCards.setLeftAgentId(leafAgentId);
|
|
|
dzCards.setDistributeTime(DateUtils.getNowDate());
|
|
dzCards.setDistributeTime(DateUtils.getNowDate());
|
|
|
dzCardsMapper.updateDzCards(dzCards);
|
|
dzCardsMapper.updateDzCards(dzCards);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public Boolean requestOpen(Long schoolId, Long agentId, String beginNo, String endNo) {
|
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public Boolean openCard(Long schoolId, Long agentId, String beginNo, String endNo) {
|
|
|
DzCardsOpen newOpen = new DzCardsOpen();
|
|
DzCardsOpen newOpen = new DzCardsOpen();
|
|
|
newOpen.setAgentId(agentId);
|
|
newOpen.setAgentId(agentId);
|
|
|
newOpen.setStartNo(beginNo);
|
|
newOpen.setStartNo(beginNo);
|
|
@@ -172,25 +177,59 @@ public class DzCardsServiceImpl implements IDzCardsService
|
|
|
newOpen.setEndDate(DateUtils.addDays(DateUtils.getNowDate(), 14)); // TODO MF 卡默认有效期
|
|
newOpen.setEndDate(DateUtils.addDays(DateUtils.getNowDate(), 14)); // TODO MF 卡默认有效期
|
|
|
newOpen.setSchoolId(schoolId);
|
|
newOpen.setSchoolId(schoolId);
|
|
|
newOpen.setIsReopen(0);
|
|
newOpen.setIsReopen(0);
|
|
|
- newOpen.setCardType(CardType.Test.getVal());
|
|
|
|
|
- newOpen.setStatus(RequestStatus.Wait.getVal());
|
|
|
|
|
|
|
+ newOpen.setStatus(RequestStatus.Pass.getVal());
|
|
|
dzCardsOpenMapper.insertDzCardsOpen(newOpen);
|
|
dzCardsOpenMapper.insertDzCardsOpen(newOpen);
|
|
|
// TODO MF 检查已经使用的或无效的
|
|
// TODO MF 检查已经使用的或无效的
|
|
|
|
|
+ CardCriteria cond = new CardCriteria();
|
|
|
|
|
+ cond.setStartNo(beginNo);
|
|
|
|
|
+ cond.setEndNo(endNo);
|
|
|
|
|
+ List<DzCards> cards = dzCardsMapper.selectListByCond(cond);
|
|
|
|
|
+ if(cards.stream().filter(t -> !t.getPayStatus().equals(PayStatus.UnPay.getVal())).count() > 0) {
|
|
|
|
|
+ throw new ValidationException("请求打开已开卡: " + beginNo + "-" + endNo);
|
|
|
|
|
+ }
|
|
|
|
|
+ DzCards dzCards = new DzCards();
|
|
|
|
|
+ cards.stream().forEach(c -> {
|
|
|
|
|
+ dzCards.setCardId(c.getCardId());
|
|
|
|
|
+ dzCards.setPayTime(DateUtils.getNowDate());
|
|
|
|
|
+ dzCards.setPayStatus(PayStatus.Paid.getVal());
|
|
|
|
|
+ dzCards.setStatus(CardStatus.Paid.getVal());
|
|
|
|
|
+ dzCardsMapper.updateDzCards(dzCards);
|
|
|
|
|
+ });
|
|
|
|
|
+ // TODO MF 检查已经使用的或无效的
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void confirmOpen(Long openId) {
|
|
|
|
|
|
|
+ public Boolean requestOpenCard(Long schoolId, Long agentId, String beginNo, String endNo) {
|
|
|
|
|
+
|
|
|
|
|
+ DzCardsOpen newOpen = new DzCardsOpen();
|
|
|
|
|
+ newOpen.setAgentId(agentId);
|
|
|
|
|
+ newOpen.setStartNo(beginNo);
|
|
|
|
|
+ newOpen.setEndNo(endNo);
|
|
|
|
|
+ newOpen.setEndDate(DateUtils.addDays(DateUtils.getNowDate(), 14)); // TODO MF 卡默认有效期
|
|
|
|
|
+ newOpen.setSchoolId(schoolId);
|
|
|
|
|
+ newOpen.setIsReopen(0);
|
|
|
|
|
+ newOpen.setStatus(RequestStatus.Wait.getVal());
|
|
|
|
|
+ dzCardsOpenMapper.insertDzCardsOpen(newOpen);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public void confirmOpenCard(Long openId, Long userId) {
|
|
|
DzCardsOpen open = dzCardsOpenMapper.selectDzCardsOpenById(openId);
|
|
DzCardsOpen open = dzCardsOpenMapper.selectDzCardsOpenById(openId);
|
|
|
if(!open.getStatus().equals(RequestStatus.Wait.getVal())) {
|
|
if(!open.getStatus().equals(RequestStatus.Wait.getVal())) {
|
|
|
throw new ValidationException("无效状态");
|
|
throw new ValidationException("无效状态");
|
|
|
}
|
|
}
|
|
|
CardCriteria cond = new CardCriteria();
|
|
CardCriteria cond = new CardCriteria();
|
|
|
- cond.setType(open.getCardType());
|
|
|
|
|
cond.setStartNo(open.getStartNo());
|
|
cond.setStartNo(open.getStartNo());
|
|
|
cond.setEndNo(open.getEndNo());
|
|
cond.setEndNo(open.getEndNo());
|
|
|
|
|
+ List<DzCards> cards = dzCardsMapper.selectListByCond(cond);
|
|
|
|
|
+ if(cards.stream().filter(t -> !t.getPayStatus().equals(PayStatus.UnPay.getVal())).count() > 0) {
|
|
|
|
|
+ throw new ValidationException("重复打开已开卡: " + open.getStartNo() + "-" + open.getEndNo());
|
|
|
|
|
+ }
|
|
|
DzCards dzCards = new DzCards();
|
|
DzCards dzCards = new DzCards();
|
|
|
- dzCardsMapper.selectListByCond(cond).stream().forEach(c -> {
|
|
|
|
|
|
|
+ cards.stream().forEach(c -> {
|
|
|
dzCards.setCardId(c.getCardId());
|
|
dzCards.setCardId(c.getCardId());
|
|
|
dzCards.setPayTime(DateUtils.getNowDate());
|
|
dzCards.setPayTime(DateUtils.getNowDate());
|
|
|
dzCards.setPayStatus(PayStatus.Paid.getVal());
|
|
dzCards.setPayStatus(PayStatus.Paid.getVal());
|
|
@@ -204,18 +243,39 @@ public class DzCardsServiceImpl implements IDzCardsService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void reOpen(Long[] cardIds) {
|
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public void changeCard(CardAction action, Long[] cardIds) {
|
|
|
|
|
+ List<DzCards> cards = dzCardsMapper.selectCardsByCardIds(cardIds);;
|
|
|
DzCards up = new DzCards();
|
|
DzCards up = new DzCards();
|
|
|
- for(Long cardId : cardIds) {
|
|
|
|
|
- DzCards old = dzCardsMapper.selectDzCardsByCardId(cardId);
|
|
|
|
|
- if(!old.getDistributeStatus().equals(CardDistributeStatus.Close.getVal())) {
|
|
|
|
|
- throw new ValidationException("非关闭卡");
|
|
|
|
|
|
|
+ if(CardAction.Pay.equals(action)) {
|
|
|
|
|
+ if(cards.stream().filter(t -> !t.getPayStatus().equals(PayStatus.UnPay.getVal())).count() > 0) {
|
|
|
|
|
+ throw new ValidationException("重复支付已支付卡: " + StringUtils.join(cardIds, ","));
|
|
|
|
|
+ }
|
|
|
|
|
+ up.setPayStatus(PayStatus.Paid.getVal());
|
|
|
|
|
+ up.setPayTime(DateUtils.getNowDate());
|
|
|
|
|
+ } else if(CardAction.Close.equals(action)) {
|
|
|
|
|
+ if(cards.stream().filter(t -> t.getDistributeStatus().equals(CardDistributeStatus.Close.getVal())).count() > 0) {
|
|
|
|
|
+ throw new ValidationException("重复关闭卡: " + StringUtils.join(cardIds, ","));
|
|
|
|
|
+ }
|
|
|
|
|
+ up.setDistributeStatus(CardDistributeStatus.Close.getVal());
|
|
|
|
|
+ up.setCloseTime(DateUtils.getNowDate());
|
|
|
|
|
+ } else if(CardAction.ReOpen.equals(action)) {
|
|
|
|
|
+ if(cards.stream().filter(t -> !t.getDistributeStatus().equals(CardDistributeStatus.Close.getVal())).count() > 0) {
|
|
|
|
|
+ throw new ValidationException("重开非关闭卡: " + StringUtils.join(cardIds, ","));
|
|
|
}
|
|
}
|
|
|
- up.setCardId(old.getCardId());
|
|
|
|
|
up.setDistributeStatus(CardDistributeStatus.Assign.getVal());
|
|
up.setDistributeStatus(CardDistributeStatus.Assign.getVal());
|
|
|
|
|
+ } else if(CardAction.Refund.equals(action)) {
|
|
|
|
|
+ if(cards.stream().filter(t -> t.getPayStatus().equals(PayStatus.Refund.getVal())).count() > 0) {
|
|
|
|
|
+ throw new ValidationException("重复退款: " + StringUtils.join(cardIds, ","));
|
|
|
|
|
+ }
|
|
|
|
|
+ up.setPayStatus(PayStatus.Refund.getVal());
|
|
|
|
|
+ up.setRefundTime(DateUtils.getNowDate());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new ValidationException("无效操作");
|
|
|
|
|
+ }
|
|
|
|
|
+ for(Long cardId : cardIds) {
|
|
|
|
|
+ up.setCardId(cardId);
|
|
|
dzCardsMapper.updateDzCards(up);
|
|
dzCardsMapper.updateDzCards(up);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|