Explorar o código

教材申请退书

大数据与最优化研究所 hai 7 meses
pai
achega
aaee46ba37

+ 15 - 0
src/main/java/com/xjrsoft/module/textbook/entity/WfTextbookRecede.java

@@ -77,6 +77,21 @@ public class WfTextbookRecede implements Serializable {
      */
     @ApiModelProperty("申请人")
     private Long applicantUserId;
+    /**
+     * 是否是学生
+     */
+    @ApiModelProperty("是否是学生")
+    private Integer isStuFlag;
+    /**
+     * 是否是班主任
+     */
+    @ApiModelProperty("是否是班主任")
+    private Integer isHeadTeaFlag;
+    /**
+     * 是否是班主任为班级退书
+     */
+    @ApiModelProperty("是否是班主任为班级退书")
+    private Integer isClassRecedeFlag;
     /**
      * 学期ID(base_semester)
      */

+ 51 - 8
src/main/java/com/xjrsoft/module/textbook/service/impl/WfTextbookRecedeServiceImpl.java

@@ -13,6 +13,7 @@ import com.xjrsoft.module.textbook.service.IWfTextbookRecedeService;
 import com.xjrsoft.module.workflow.entity.WorkflowFormRelation;
 import com.xjrsoft.module.workflow.mapper.WorkflowFormRelationMapper;
 import lombok.AllArgsConstructor;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.ObjectUtils;
 import org.camunda.bpm.engine.history.HistoricProcessInstance;
 import org.springframework.stereotype.Service;
@@ -21,10 +22,7 @@ import org.springframework.transaction.annotation.Transactional;
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -46,6 +44,8 @@ public class WfTextbookRecedeServiceImpl extends MPJBaseServiceImpl<WfTextbookRe
 
     private final TextbookIssueRecordMapper textbookIssueRecordMapper;
 
+    private final TextbookStudentClaimMapper textbookStudentClaimMapper;
+
     private final WorkflowFormRelationMapper workflowFormRelationMapper;
 
     @Override
@@ -123,6 +123,7 @@ public class WfTextbookRecedeServiceImpl extends MPJBaseServiceImpl<WfTextbookRe
                 && HistoricProcessInstance.STATE_COMPLETED.equals(workflowFormRelation.getCurrentState())
         ) {
             // 退书类型是到教务处
+            // 学生已经领取的教材退书的时候应该将领取状态改为退书
             if (RecedeTypeEnum.RecedeeDansOffice.getCode().equals(wfTextbookRecede.getRecedeType())) {
                 List<WfTextbookRecedeItem> wfTextbookRecedeItemList = wfTextbookRecede.getWfTextbookRecedeItemList();
                 if (ObjectUtils.isNotEmpty(wfTextbookRecedeItemList)) {
@@ -150,23 +151,54 @@ public class WfTextbookRecedeServiceImpl extends MPJBaseServiceImpl<WfTextbookRe
                     Map<Long, TextbookWarehouseRecord> textbookWarehouseRecordMap = textbookWarehouseRecords.stream()
                             .collect(Collectors.toMap(TextbookWarehouseRecord::getId, t -> t, (t1, t2) -> t1));
 
+                    // 获取当前退书班级所有的领取记录
+                    LambdaQueryWrapper<TextbookStudentClaim> textbookStudentClaimLambdaQueryWrapper = new LambdaQueryWrapper<>();
+                    textbookStudentClaimLambdaQueryWrapper
+                            .eq(TextbookStudentClaim::getDeleteMark, DeleteMark.NODELETE.getCode())
+                            ;
+
+                    if(wfTextbookRecede.getIsStuFlag() == 1){
+                        textbookStudentClaimLambdaQueryWrapper
+                                .eq(TextbookStudentClaim::getStudentUserId, wfTextbookRecede.getApplicantUserId())
+                                ;
+                    }
+
+                    // 如果是班主任帮班级退书
+                    if(wfTextbookRecede.getIsStuFlag() == 0){
+                        if(wfTextbookRecede.getIsHeadTeaFlag() == 1
+                                && wfTextbookRecede.getIsClassRecedeFlag() == 1){
+                            textbookStudentClaimLambdaQueryWrapper
+                                    .eq(TextbookStudentClaim::getClassId, wfTextbookRecede.getClassId())
+                            ;
+                        }else {
+                            textbookStudentClaimLambdaQueryWrapper
+                                    .eq(TextbookStudentClaim::getStudentUserId, wfTextbookRecede.getApplicantUserId())
+                            ;
+                        }
+                    }
+                    List<TextbookStudentClaim> textbookStudentClaims = textbookStudentClaimMapper.selectList(textbookStudentClaimLambdaQueryWrapper);
+                    Map<Long, List<TextbookStudentClaim>> groupByTextbookId = textbookStudentClaims.stream()
+                            .collect(Collectors.groupingBy(TextbookStudentClaim::getTextbookId));
+
                     //遍历每一个退书申请项
                     TextbookWarehouseRecord oldTextbookWarehouseRecord;
                     TextbookWarehouseRecordDetail textbookWarehouseRecordDetail;
                     TextbookWarehouseRecord updateTextbookWarehouseRecord;
                     TextbookIssueRecord oldTextbookIssueRecord;
-                    TextbookIssueRecord newTextbookIssueRecord;
                     TextbookIssueRecord updateTextbookIssueRecord;
                     for (WfTextbookRecedeItem wfTextbookRecedeItem : wfTextbookRecedeItemList) {
                         // 退书项对应的出库记录
                         oldTextbookIssueRecord = textbookIssueRecordMap.get(wfTextbookRecedeItem.getTextbookIssueRecordId());
+
+                        if(ObjectUtils.isEmpty(oldTextbookIssueRecord)){
+                            continue;
+                        }
+
                         // 退书项对应的出库记录对应的入库记录
                         oldTextbookWarehouseRecord = textbookWarehouseRecordMap.get(oldTextbookIssueRecord.getTextbookWarehouseRecordId());
 
                         // 退书类型是到教务处
-                        if (ObjectUtils.isNotEmpty(oldTextbookWarehouseRecord)
-                                && ObjectUtils.isNotEmpty(oldTextbookIssueRecord)
-                        ) {
+                        if (ObjectUtils.isNotEmpty(oldTextbookWarehouseRecord)) {
                             // 增加入库详情记录
                             textbookWarehouseRecordDetail = new TextbookWarehouseRecordDetail();
                             textbookWarehouseRecordDetail.setTextbookWarehouseRecordId(oldTextbookWarehouseRecord.getId());
@@ -205,6 +237,17 @@ public class WfTextbookRecedeServiceImpl extends MPJBaseServiceImpl<WfTextbookRe
                             updateTextbookIssueRecord.setModifyDate(nowDate);
                             textbookIssueRecordMapper.updateById(updateTextbookIssueRecord);
                         }
+
+                        List<TextbookStudentClaim> claimList = groupByTextbookId.get(wfTextbookRecedeItem.getTextbookId());
+                        if(CollectionUtils.isNotEmpty(claimList)){
+                            for (TextbookStudentClaim textbookStudentClaim : claimList){
+                                TextbookStudentClaim updateTextbookStudentClaim = new TextbookStudentClaim();
+                                updateTextbookStudentClaim.setId(textbookStudentClaim.getId());
+                                updateTextbookStudentClaim.setPrice(BigDecimal.ZERO);
+                                updateTextbookStudentClaim.setIsClaim(2);
+                                textbookStudentClaimMapper.updateById(updateTextbookStudentClaim);
+                            }
+                        }
                     }
                 }
             }