Parcourir la source

调整卡管理相关接口

mingfu il y a 1 mois
Parent
commit
67034d5bd0
21 fichiers modifiés avec 264 ajouts et 85 suppressions
  1. 49 16
      ie-admin/src/main/java/com/ruoyi/web/controller/dz/DzCardsController.java
  2. 12 0
      ie-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java
  3. 1 1
      ie-common/src/main/java/com/ruoyi/common/core/domain/entity/SysUser.java
  4. 23 2
      ie-system/src/main/java/com/ruoyi/dz/domain/DzAgent.java
  5. 0 15
      ie-system/src/main/java/com/ruoyi/dz/domain/DzCardsOpen.java
  6. 24 1
      ie-system/src/main/java/com/ruoyi/dz/domain/DzTeacher.java
  7. 4 0
      ie-system/src/main/java/com/ruoyi/dz/mapper/DzCardsMapper.java
  8. 22 8
      ie-system/src/main/java/com/ruoyi/dz/service/IDzCardsService.java
  9. 1 1
      ie-system/src/main/java/com/ruoyi/dz/service/impl/DzAgentServiceImpl.java
  10. 87 27
      ie-system/src/main/java/com/ruoyi/dz/service/impl/DzCardsServiceImpl.java
  11. 1 1
      ie-system/src/main/java/com/ruoyi/dz/service/impl/DzTeacherServiceImpl.java
  12. 10 0
      ie-system/src/main/java/com/ruoyi/enums/CardAction.java
  13. 1 1
      ie-system/src/main/java/com/ruoyi/enums/CardType.java
  14. 1 1
      ie-system/src/main/java/com/ruoyi/enums/UserTypeEnum.java
  15. 1 1
      ie-system/src/main/java/com/ruoyi/system/service/ISysUserService.java
  16. 1 1
      ie-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
  17. 5 2
      ie-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java
  18. 6 1
      ie-system/src/main/resources/mapper/dz/DzAgentMapper.xml
  19. 9 0
      ie-system/src/main/resources/mapper/dz/DzCardsMapper.xml
  20. 1 6
      ie-system/src/main/resources/mapper/dz/DzCardsOpenMapper.xml
  21. 5 0
      ie-system/src/main/resources/mapper/dz/DzTeacherMapper.xml

+ 49 - 16
ie-admin/src/main/java/com/ruoyi/web/controller/dz/DzCardsController.java

@@ -2,8 +2,15 @@ package com.ruoyi.web.controller.dz;
 
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
+import javax.validation.ValidationException;
 
+import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.dz.domain.DzAgent;
+import com.ruoyi.dz.service.IDzAgentService;
+import com.ruoyi.enums.CardAction;
+import com.ruoyi.enums.CardType;
+import com.ruoyi.enums.UserTypeEnum;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
@@ -32,6 +39,8 @@ public class DzCardsController extends BaseController
 {
     @Autowired
     private IDzCardsService dzCardsService;
+    @Autowired
+    private IDzAgentService agentService;
 
     /**
      * 查询学习卡列表
@@ -102,46 +111,70 @@ public class DzCardsController extends BaseController
     }
 
     @Log(title = "制卡", businessType = BusinessType.INSERT)
-    @PostMapping("/issue")
+    @PostMapping("/issueCard")
     @ApiOperation("制卡")
-    public AjaxResult issue(@ApiParam("机构") Long deptId, @ApiParam("卡类型") Integer type, @ApiParam("开始号") Integer begin, @ApiParam("结束号") Integer end)
+    public AjaxResult issueCard(@ApiParam("机构") Long institutionId, @ApiParam("卡类型") CardType type, @ApiParam("数量") Integer count)
     {
-        dzCardsService.issue(deptId, type, begin, end);
+        dzCardsService.issueCard(institutionId, type, count);
         return AjaxResult.success();
     }
 
     @Log(title = "分配卡", businessType = BusinessType.INSERT)
-    @PostMapping("/assign")
+    @PostMapping("/assignCard")
     @ApiOperation("分配卡")
-    public AjaxResult assign(@ApiParam("代理商") Long agentId, @ApiParam("开始号") String begin, @ApiParam("结束号") String end)
+    public AjaxResult assignCard(@ApiParam("代理商") Long agentId, @ApiParam("开始号") String begin, @ApiParam("结束号") String end)
     {
-        dzCardsService.assign(agentId, begin, end);
+        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
+        DzAgent agent = agentService.selectDzAgentByAgentId(agentId);
+        if(UserTypeEnum.Agent.equals(sysUser.getUserType())) { // 代理商分配
+            if (!sysUser.getUserTypeId().equals(agent.getParentId())) {
+                throw new ValidationException("只能分配给下级代理");
+            }
+            dzCardsService.assignCard(sysUser.getUserTypeId(), agentId, begin, end);
+        } else if(UserTypeEnum.Institution.equals(sysUser.getUserType())) { // 机构分配卡给自己的下级
+            if (!sysUser.getDeptId().equals(agent.getDeptId())) {
+                throw new ValidationException("只能分配给下级代理");
+            }
+            dzCardsService.assignCard(agentId, agentId, begin, end);
+        } else { // 平台指定, TODO 暂只支持二级代理
+            dzCardsService.assignCard(agent.getParentId(), agentId, begin, end);
+        }
         return AjaxResult.success();
     }
 
+    @Log(title = "直接开卡", businessType = BusinessType.INSERT)
+    @PostMapping("/openCard")
+    @ApiOperation("分配卡")
+    public AjaxResult openCard(@ApiParam("学校") Long schoolId, @ApiParam("开始号") String begin, @ApiParam("结束号") String end)
+    {
+        Long agentId = 0L;
+        return AjaxResult.success(dzCardsService.openCard(schoolId, agentId, begin, end));
+    }
+
     @Log(title = "申请开卡", businessType = BusinessType.INSERT)
-    @PostMapping("/requestOpen")
+    @PostMapping("/requestOpenCard")
     @ApiOperation("分配卡")
-    public AjaxResult requestOpen(@ApiParam("学校") Long schoolId, @ApiParam("开始号") String begin, @ApiParam("结束号") String end)
+    public AjaxResult requestOpenCard(@ApiParam("学校") Long schoolId, @ApiParam("开始号") String begin, @ApiParam("结束号") String end)
     {
         Long agentId = SecurityUtils.getLoginUser().getUser().getUserTypeId();
-        return AjaxResult.success(dzCardsService.requestOpen(schoolId, agentId, begin, end));
+        return AjaxResult.success(dzCardsService.requestOpenCard(schoolId, agentId, begin, end));
     }
 
     @Log(title = "确认开卡", businessType = BusinessType.INSERT)
-    @PostMapping("/confirmOpen")
+    @PostMapping("/confirmOpenCard")
     @ApiOperation("确认开卡")
-    public AjaxResult confirmOpen(@ApiParam("开卡申请ID") Long openId)
+    public AjaxResult confirmOpenCard(@ApiParam("开卡申请ID") Long openId)
     {
-        dzCardsService.confirmOpen(openId);
+        dzCardsService.confirmOpenCard(openId, SecurityUtils.getLoginUser().getUser().getUserId());
         return AjaxResult.success();
     }
 
-    @PostMapping("/reOpen")
-    @ApiOperation("重开卡")
-    public AjaxResult reOpen(@ApiParam("卡ID") Long[] cardIds)
+    @Log(title = "修改卡", businessType = BusinessType.UPDATE)
+    @PostMapping("/changeCard")
+    @ApiOperation("修改卡 重卡/关卡/支付")
+    public AjaxResult changeCard(@ApiParam("操作") CardAction action, @ApiParam("卡ID") Long[] cardIds)
     {
-        dzCardsService.reOpen(cardIds);
+        dzCardsService.changeCard(action, cardIds);
         return AjaxResult.success();
     }
 }

+ 12 - 0
ie-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java

@@ -55,6 +55,18 @@ public class SysDept extends BaseEntity
     /** 子部门 */
     private List<SysDept> children = new ArrayList<SysDept>();
 
+
+
+    private String username;
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
     public Long getDeptId()
     {
         return deptId;

+ 1 - 1
ie-common/src/main/java/com/ruoyi/common/core/domain/entity/SysUser.java

@@ -451,7 +451,7 @@ public class SysUser extends BaseEntity
 
 
     public String getCode() {
-        return userId.toString();
+        return String.valueOf(userId);
     }
 
     @Override

+ 23 - 2
ie-system/src/main/java/com/ruoyi/dz/domain/DzAgent.java

@@ -20,6 +20,9 @@ public class DzAgent extends TreeEntity
 
     /** 上级代理商ID */
     private Long parentId;
+    /** 机构ID */
+    @Excel(name = "机构ID")
+    private Long deptId;
 
     /** 用户ID */
     @Excel(name = "用户ID")
@@ -37,7 +40,17 @@ public class DzAgent extends TreeEntity
     @Excel(name = "负责校区列表")
     private String schools;
 
-    public void setAgentId(Long agentId) 
+    private String username;
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public void setAgentId(Long agentId)
     {
         this.agentId = agentId;
     }
@@ -47,7 +60,15 @@ public class DzAgent extends TreeEntity
         return agentId;
     }
 
-    public void setUserId(Long userId) 
+    public Long getDeptId() {
+        return deptId;
+    }
+
+    public void setDeptId(Long deptId) {
+        this.deptId = deptId;
+    }
+
+    public void setUserId(Long userId)
     {
         this.userId = userId;
     }

+ 0 - 15
ie-system/src/main/java/com/ruoyi/dz/domain/DzCardsOpen.java

@@ -49,10 +49,6 @@ public class DzCardsOpen extends BaseEntity
     @Excel(name = "重新开卡:0否,1是")
     private Integer isReopen;
 
-    /** 卡类型,对应card_type */
-    @Excel(name = "卡类型,对应card_type")
-    private Integer cardType;
-
     /** 状态(0:无效,1:审核结束,2:审核中) */
     @Excel(name = "状态(0:无效,1:审核结束,2:审核中)")
     private Integer status;
@@ -137,16 +133,6 @@ public class DzCardsOpen extends BaseEntity
         return isReopen;
     }
 
-    public void setCardType(Integer cardType)
-    {
-        this.cardType = cardType;
-    }
-
-    public Integer getCardType()
-    {
-        return cardType;
-    }
-
     public void setStatus(Integer status)
     {
         this.status = status;
@@ -169,7 +155,6 @@ public class DzCardsOpen extends BaseEntity
             .append("sender", getSender())
             .append("createTime", getCreateTime())
             .append("isReopen", getIsReopen())
-            .append("cardType", getCardType())
             .append("status", getStatus())
             .toString();
     }

+ 24 - 1
ie-system/src/main/java/com/ruoyi/dz/domain/DzTeacher.java

@@ -22,6 +22,10 @@ public class DzTeacher extends BaseEntity
     @Excel(name = "用户ID")
     private Long userId;
 
+    /** 机构ID */
+    @Excel(name = "机构ID")
+    private Long deptId;
+
     /** 所在校区 */
     @Excel(name = "所在校区")
     private Long schoolId;
@@ -30,6 +34,17 @@ public class DzTeacher extends BaseEntity
     @Excel(name = "教师姓名")
     private String name;
 
+
+    private String username;
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
     public void setTeacherId(Long teacherId) 
     {
         this.teacherId = teacherId;
@@ -50,7 +65,15 @@ public class DzTeacher extends BaseEntity
         return userId;
     }
 
-    public void setSchoolId(Long schoolId) 
+    public Long getDeptId() {
+        return deptId;
+    }
+
+    public void setDeptId(Long deptId) {
+        this.deptId = deptId;
+    }
+
+    public void setSchoolId(Long schoolId)
     {
         this.schoolId = schoolId;
     }

+ 4 - 0
ie-system/src/main/java/com/ruoyi/dz/mapper/DzCardsMapper.java

@@ -63,4 +63,8 @@ public interface DzCardsMapper
     public int deleteDzCardsByCardIds(Long[] cardIds);
 
     public List<DzCards> selectListByCond(CardCriteria cond);
+
+    public List<DzCards> selectCardsByCardIds(Long[] cardIds);
+
+    public Long selectMaxNo(@Param("type") Integer type);
 }

+ 22 - 8
ie-system/src/main/java/com/ruoyi/dz/service/IDzCardsService.java

@@ -2,6 +2,8 @@ package com.ruoyi.dz.service;
 
 import java.util.List;
 import com.ruoyi.dz.domain.DzCards;
+import com.ruoyi.enums.CardAction;
+import com.ruoyi.enums.CardType;
 
 /**
  * 学习卡Service接口
@@ -65,18 +67,28 @@ public interface IDzCardsService
      * 制卡
      * @param deptId
      * @param type
-     * @param begin
-     * @param end
+     * @param count
      */
-    public void issue(Long deptId, Integer type, Integer begin, Integer end);
+    public void issueCard(Long deptId, CardType type, Integer count);
 
     /**
      * 分配卡
      * @param agentId
+     * @param leafAgentId
      * @param beginNo
      * @param endNo
      */
-    public void assign(Long agentId, String beginNo, String endNo);
+    public void assignCard(Long agentId, Long leafAgentId, String beginNo, String endNo);
+
+    /**
+     * 开卡
+     * @param schoolId
+     * @param agentId
+     * @param beginNo
+     * @param endNo
+     * @return
+     */
+    public Boolean openCard(Long schoolId, Long agentId, String beginNo, String endNo);
 
     /**
      * 申请开卡
@@ -85,17 +97,19 @@ public interface IDzCardsService
      * @param beginNo
      * @param endNo
      */
-    public Boolean requestOpen(Long schoolId, Long agentId, String beginNo, String endNo);
+    public Boolean requestOpenCard(Long schoolId, Long agentId, String beginNo, String endNo);
 
     /**
      * 审核开卡
      * @param openId
+     * @param userId
      */
-    public void confirmOpen(Long openId);
+    public void confirmOpenCard(Long openId, Long userId);
 
     /**
-     * 重开卡
+     * 修改卡
+     * @param action
      * @param cardIds
      */
-    public void reOpen(Long[] cardIds);
+    public void changeCard(CardAction action, Long[] cardIds);
 }

+ 1 - 1
ie-system/src/main/java/com/ruoyi/dz/service/impl/DzAgentServiceImpl.java

@@ -60,7 +60,7 @@ public class DzAgentServiceImpl implements IDzAgentService
     public int insertDzAgent(DzAgent dzAgent)
     {
         int iRet = dzAgentMapper.insertDzAgent(dzAgent);
-        userService.insertRelateUser(UserTypeEnum.Agent, dzAgent.getAgentId(),dzAgent.getName());
+        userService.insertRelateUser(UserTypeEnum.Agent, dzAgent.getAgentId(), dzAgent.getDeptId(), dzAgent.getUsername(), dzAgent.getName());
         return iRet;
     }
 

+ 87 - 27
ie-system/src/main/java/com/ruoyi/dz/service/impl/DzCardsServiceImpl.java

@@ -15,11 +15,13 @@ import com.ruoyi.dz.domain.DzCardsOpen;
 import com.ruoyi.dz.mapper.DzAgentMapper;
 import com.ruoyi.dz.mapper.DzCardsOpenMapper;
 import com.ruoyi.enums.*;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.ruoyi.dz.mapper.DzCardsMapper;
 import com.ruoyi.dz.domain.DzCards;
 import com.ruoyi.dz.service.IDzCardsService;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.validation.ValidationException;
 
@@ -125,12 +127,16 @@ public class DzCardsServiceImpl implements IDzCardsService
     }
 
     @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();
-            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.setDistributeStatus(CardDistributeStatus.Free.getVal());
             c.setStatus(CardStatus.Free.getVal());
@@ -143,28 +149,27 @@ public class DzCardsServiceImpl implements IDzCardsService
     }
 
     @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();
         cond.setStartNo(beginNo);
         cond.setEndNo(endNo);
         DzCards dzCards = new DzCards();
-        DzAgent agent = dzAgentMapper.selectDzAgentByAgentId(agentId);
         dzCardsMapper.selectListByCond(cond).stream().forEach(c -> {
             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());
             dzCardsMapper.updateDzCards(dzCards);
         });
     }
 
     @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();
         newOpen.setAgentId(agentId);
         newOpen.setStartNo(beginNo);
@@ -172,25 +177,59 @@ public class DzCardsServiceImpl implements IDzCardsService
         newOpen.setEndDate(DateUtils.addDays(DateUtils.getNowDate(), 14)); // TODO MF 卡默认有效期
         newOpen.setSchoolId(schoolId);
         newOpen.setIsReopen(0);
-        newOpen.setCardType(CardType.Test.getVal());
-        newOpen.setStatus(RequestStatus.Wait.getVal());
+        newOpen.setStatus(RequestStatus.Pass.getVal());
         dzCardsOpenMapper.insertDzCardsOpen(newOpen);
         // 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;
     }
 
     @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);
         if(!open.getStatus().equals(RequestStatus.Wait.getVal())) {
             throw new ValidationException("无效状态");
         }
         CardCriteria cond = new CardCriteria();
-        cond.setType(open.getCardType());
         cond.setStartNo(open.getStartNo());
         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();
-        dzCardsMapper.selectListByCond(cond).stream().forEach(c -> {
+        cards.stream().forEach(c -> {
             dzCards.setCardId(c.getCardId());
             dzCards.setPayTime(DateUtils.getNowDate());
             dzCards.setPayStatus(PayStatus.Paid.getVal());
@@ -204,18 +243,39 @@ public class DzCardsServiceImpl implements IDzCardsService
     }
 
     @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();
-        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());
+        } 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);
         }
     }
-
-
 }

+ 1 - 1
ie-system/src/main/java/com/ruoyi/dz/service/impl/DzTeacherServiceImpl.java

@@ -58,7 +58,7 @@ public class DzTeacherServiceImpl implements IDzTeacherService
     public int insertDzTeacher(DzTeacher dzTeacher)
     {
         int id = dzTeacherMapper.insertDzTeacher(dzTeacher);
-        userService.insertRelateUser(UserTypeEnum.Teacher, dzTeacher.getTeacherId(),dzTeacher.getName());
+        userService.insertRelateUser(UserTypeEnum.Teacher, dzTeacher.getTeacherId(), dzTeacher.getDeptId(), dzTeacher.getUsername(), dzTeacher.getName());
         return id;
     }
 

+ 10 - 0
ie-system/src/main/java/com/ruoyi/enums/CardAction.java

@@ -0,0 +1,10 @@
+package com.ruoyi.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+@Getter
+@AllArgsConstructor
+public enum CardAction {
+    Pay, Open, Close, ReOpen, Refund;
+}

+ 1 - 1
ie-system/src/main/java/com/ruoyi/enums/CardType.java

@@ -6,7 +6,7 @@ import lombok.Getter;
 @Getter
 @AllArgsConstructor
 public enum CardType {
-    Test(0); // 未用/申请开卡/开卡成功且支付/激活
+    Platform(6), Dept(2), ECard(7), Test(8); // 代理商 5, 教师 9
 
     private final Integer val;
 }

+ 1 - 1
ie-system/src/main/java/com/ruoyi/enums/UserTypeEnum.java

@@ -6,7 +6,7 @@ import lombok.Getter;
 @Getter
 @AllArgsConstructor
 public enum UserTypeEnum {
-    Sys("00"), Card("01"), Agent("10"), Teacher("11"), Dept("12"); // 用户类型(00系统01卡10代理11老师12机构)
+    Sys("00"), Card("01"), Agent("10"), Teacher("11"), Institution("12"); // 用户类型(00系统01卡10代理11老师12机构)
 
     private final String val;
 }

+ 1 - 1
ie-system/src/main/java/com/ruoyi/system/service/ISysUserService.java

@@ -224,5 +224,5 @@ public interface ISysUserService
      */
     public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName);
 
-    public int insertRelateUser(UserTypeEnum userType, Long userTypeId, String userName);
+    public int insertRelateUser(UserTypeEnum userType, Long userTypeId, Long deptId, String userName, String nickName);
 }

+ 1 - 1
ie-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java

@@ -224,7 +224,7 @@ public class SysDeptServiceImpl implements ISysDeptService
             throw new ServiceException("部门停用,不允许新增");
         }
         dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
-        userService.insertRelateUser(UserTypeEnum.Dept, dept.getDeptId(), dept.getDeptName());
+        userService.insertRelateUser(UserTypeEnum.Institution, dept.getDeptId(), dept.getDeptId(), dept.getUsername(), dept.getDeptName());
         return deptMapper.insertDept(dept);
     }
 

+ 5 - 2
ie-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java

@@ -6,6 +6,7 @@ import java.util.List;
 import java.util.stream.Collectors;
 import javax.validation.Validator;
 
+import cn.hutool.core.util.RandomUtil;
 import com.ruoyi.enums.UserTypeEnum;
 import com.ruoyi.system.service.ISysRoleService;
 import org.slf4j.Logger;
@@ -582,12 +583,14 @@ public class SysUserServiceImpl implements ISysUserService
     }
 
     @Override
-    public int insertRelateUser(UserTypeEnum userType, Long userTypeId, String userName) {
+    public int insertRelateUser(UserTypeEnum userType, Long userTypeId, Long deptId, String userName, String nickName) {
         SysUser user = new SysUser();
+        user.setDeptId(deptId);
         user.setUserName(userName);
+        user.setNickName(nickName);
         user.setUserType(userType.getVal());
         user.setUserTypeId(userTypeId);
-        user.setPassword2("123456");
+        user.setPassword2(RandomUtil.randomNumbers(6));
         user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
         user.setRoleIds(new Long[] {roleService.selectRoleByUserType(userType).getRoleId()});
         return insertUser(user);

+ 6 - 1
ie-system/src/main/resources/mapper/dz/DzAgentMapper.xml

@@ -6,6 +6,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     
     <resultMap type="DzAgent" id="DzAgentResult">
         <result property="agentId"    column="agentId"    />
+        <result property="deptId"    column="deptId"    />
         <result property="userId"    column="userId"    />
         <result property="name"    column="name"    />
         <result property="phonenumber"    column="phonenumber"    />
@@ -15,13 +16,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectDzAgentVo">
-        select agentId, userId, name, phonenumber, parentId, schools, remark from dz_agent
+        select agentId, deptId, userId, name, phonenumber, parentId, schools, remark from dz_agent
     </sql>
 
     <select id="selectDzAgentList" parameterType="DzAgent" resultMap="DzAgentResult">
         <include refid="selectDzAgentVo"/>
         <where>  
             <if test="userId != null "> and userId = #{userId}</if>
+            <if test="deptId != null "> and deptId = #{deptId}</if>
             <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
             <if test="phonenumber != null  and phonenumber != ''"> and phonenumber = #{phonenumber}</if>
             <if test="parentId != null "> and parentId = #{parentId}</if>
@@ -37,6 +39,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <insert id="insertDzAgent" parameterType="DzAgent" useGeneratedKeys="true" keyProperty="agentId">
         insert into dz_agent
         <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="deptId != null">deptId,</if>
             <if test="userId != null">userId,</if>
             <if test="name != null">name,</if>
             <if test="phonenumber != null">phonenumber,</if>
@@ -45,6 +48,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="remark != null">remark,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="deptId != null">#{deptId},</if>
             <if test="userId != null">#{userId},</if>
             <if test="name != null">#{name},</if>
             <if test="phonenumber != null">#{phonenumber},</if>
@@ -58,6 +62,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         update dz_agent
         <trim prefix="SET" suffixOverrides=",">
             <if test="userId != null">userId = #{userId},</if>
+            <if test="deptId != null">deptId = #{deptId},</if>
             <if test="name != null">name = #{name},</if>
             <if test="phonenumber != null">phonenumber = #{phonenumber},</if>
             <if test="parentId != null">parentId = #{parentId},</if>

+ 9 - 0
ie-system/src/main/resources/mapper/dz/DzCardsMapper.xml

@@ -225,4 +225,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="closeTime != null "> and close_time = #{closeTime}</if>
         </where>
     </select>
+
+    <select id="selectCardsByCardIds" parameterType="String" resultMap="DzCardsResult">
+        <include refid="selectDzCardsVo"/>
+        where card_id in <foreach item="cardId" collection="array" open="(" separator="," close=")">#{cardId}</foreach>
+    </select>
+
+    <select id="selectMaxNo" parameterType="Integer" resultType="Long">
+        select max(card_no) from dz_cards where type = #{type}
+    </select>
 </mapper>

+ 1 - 6
ie-system/src/main/resources/mapper/dz/DzCardsOpenMapper.xml

@@ -14,12 +14,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="sender"    column="sender"    />
         <result property="createTime"    column="create_time"    />
         <result property="isReopen"    column="is_reopen"    />
-        <result property="cardType"    column="card_type"    />
         <result property="status"    column="status"    />
     </resultMap>
 
     <sql id="selectDzCardsOpenVo">
-        select id, agent_id, start_no, end_no, end_date, school_id, sender, create_time, is_reopen, card_type, status from dz_cards_open
+        select id, agent_id, start_no, end_no, end_date, school_id, sender, create_time, is_reopen, status from dz_cards_open
     </sql>
 
     <select id="selectDzCardsOpenList" parameterType="DzCardsOpen" resultMap="DzCardsOpenResult">
@@ -32,7 +31,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="schoolId != null "> and school_id = #{schoolId}</if>
             <if test="sender != null  and sender != ''"> and sender = #{sender}</if>
             <if test="isReopen != null "> and is_reopen = #{isReopen}</if>
-            <if test="cardType != null "> and card_type = #{cardType}</if>
             <if test="status != null "> and status = #{status}</if>
         </where>
     </select>
@@ -53,7 +51,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="sender != null">sender,</if>
             <if test="createTime != null">create_time,</if>
             <if test="isReopen != null">is_reopen,</if>
-            <if test="cardType != null">card_type,</if>
             <if test="status != null">status,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
@@ -65,7 +62,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="sender != null">#{sender},</if>
             <if test="createTime != null">#{createTime},</if>
             <if test="isReopen != null">#{isReopen},</if>
-            <if test="cardType != null">#{cardType},</if>
             <if test="status != null">#{status},</if>
          </trim>
     </insert>
@@ -81,7 +77,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="sender != null">sender = #{sender},</if>
             <if test="createTime != null">create_time = #{createTime},</if>
             <if test="isReopen != null">is_reopen = #{isReopen},</if>
-            <if test="cardType != null">card_type = #{cardType},</if>
             <if test="status != null">status = #{status},</if>
         </trim>
         where id = #{id}

+ 5 - 0
ie-system/src/main/resources/mapper/dz/DzTeacherMapper.xml

@@ -7,6 +7,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <resultMap type="DzTeacher" id="DzTeacherResult">
         <result property="teacherId"    column="teacher_id"    />
         <result property="userId"    column="user_id"    />
+        <result property="deptId"    column="dept_id"    />
         <result property="schoolId"    column="school_id"    />
         <result property="name"    column="name"    />
     </resultMap>
@@ -19,6 +20,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <include refid="selectDzTeacherVo"/>
         <where>  
             <if test="userId != null "> and user_id = #{userId}</if>
+            <if test="deptId != null "> and dept_id = #{deptId}</if>
             <if test="schoolId != null "> and school_id = #{schoolId}</if>
             <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
         </where>
@@ -33,11 +35,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         insert into dz_teacher
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="userId != null">user_id,</if>
+            <if test="deptId != null">dept_id,</if>
             <if test="schoolId != null">school_id,</if>
             <if test="name != null">name,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="userId != null">#{userId},</if>
+            <if test="deptId != null">#{deptId},</if>
             <if test="schoolId != null">#{schoolId},</if>
             <if test="name != null">#{name},</if>
          </trim>
@@ -47,6 +51,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         update dz_teacher
         <trim prefix="SET" suffixOverrides=",">
             <if test="userId != null">user_id = #{userId},</if>
+            <if test="deptId != null">dept_id = #{deptId},</if>
             <if test="schoolId != null">school_id = #{schoolId},</if>
             <if test="name != null">name = #{name},</if>
         </trim>