heheng
22 小时以前 6faa8da685a95b1fce5f432f5bd41a870ccb5ade
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package com.gkhy.exam.system.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.gkhy.exam.common.api.CommonPage;
import com.gkhy.exam.common.api.CommonResult;
import com.gkhy.exam.common.constant.UserConstant;
import com.gkhy.exam.common.utils.PageUtils;
import com.gkhy.exam.common.utils.SecurityUtils;
import com.gkhy.exam.system.domain.AnnualVerificationPlan;
import com.gkhy.exam.system.domain.DocumentBorrowCopy;
import com.gkhy.exam.system.domain.DocumentBorrowCopyRecord;
import com.gkhy.exam.system.mapper.DocumentBorrowCopyMapper;
import com.gkhy.exam.system.mapper.DocumentBorrowCopyRecordMapper;
import com.gkhy.exam.system.service.DocumentBorrowCopyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.time.LocalDateTime;
import java.util.List;
 
/**
 * <p>
 * 文件借阅复制申请主表 服务实现类
 * </p>
 *
 * @author hh
 * @since 2025-08-25 15:01:44
 */
@Service
public class DocumentBorrowCopyServiceImpl extends ServiceImpl<DocumentBorrowCopyMapper, DocumentBorrowCopy> implements DocumentBorrowCopyService {
 
    @Autowired
    private DocumentBorrowCopyMapper documentBorrowCopyMapper;
 
    @Autowired
    private DocumentBorrowCopyRecordMapper documentBorrowCopyRecordMapper;
 
    @Override
    public CommonPage selectDocumentBorrowCopyList(DocumentBorrowCopy documentBorrowCopy) {
        PageUtils.startPage();
        List<DocumentBorrowCopy> documentBorrowCopies = documentBorrowCopyMapper.selectDocumentBorrowCopyList(documentBorrowCopy);
        return CommonPage.restPage(documentBorrowCopies);
    }
 
    @Override
    @Transactional
    public CommonResult saveDocumentBorrowCopy(DocumentBorrowCopy documentBorrowCopy) {
        List<DocumentBorrowCopyRecord> documentBorrowCopyRecordList = documentBorrowCopy.getDocumentBorrowCopyRecordList();
        if (ObjectUtils.isEmpty(documentBorrowCopyRecordList)){
            return CommonResult.failed("保存参数不能为空");
        }
        int i = 0;
        if (documentBorrowCopy.getId() == null){
            documentBorrowCopy.setCreateBy(SecurityUtils.getUsername());
            documentBorrowCopy.setCreateTime(LocalDateTime.now());
             i = documentBorrowCopyMapper.insert(documentBorrowCopy);
        }else {
            documentBorrowCopy.setUpdateBy(SecurityUtils.getUsername());
            documentBorrowCopy.setUpdateTime(LocalDateTime.now());
            i = documentBorrowCopyMapper.updateById(documentBorrowCopy);
        }
        if (i > 0){
            batchSave(documentBorrowCopy.getId(), documentBorrowCopyRecordList,documentBorrowCopy.getDeleteIds());
        }
        return i > 0 ? CommonResult.success() : CommonResult.failed();
    }
 
    private void batchSave(Long id, List<DocumentBorrowCopyRecord> documentBorrowCopyRecordList,List<Long> delIds) {
        if (ObjectUtils.isNotEmpty(delIds)) {
            int update = documentBorrowCopyRecordMapper.update(new DocumentBorrowCopyRecord(),
                    new LambdaUpdateWrapper<DocumentBorrowCopyRecord>().set(DocumentBorrowCopyRecord::getDelFlag, UserConstant.DISENABLE)
                            .set(DocumentBorrowCopyRecord::getUpdateTime, LocalDateTime.now())
                            .set(DocumentBorrowCopyRecord::getUpdateBy, SecurityUtils.getUsername()).in(DocumentBorrowCopyRecord::getId, delIds)
            );
        }
        if (ObjectUtils.isNotEmpty(documentBorrowCopyRecordList)) {
          documentBorrowCopyRecordList.forEach(documentBorrowCopyRecord -> {
              if (documentBorrowCopyRecord.getId() == null){
                  documentBorrowCopyRecord.setDocumentBorrowId(id);
                  documentBorrowCopyRecord.setCreateTime(LocalDateTime.now());
                  documentBorrowCopyRecord.setCreateBy(SecurityUtils.getUsername());
                  documentBorrowCopyRecordMapper.insert(documentBorrowCopyRecord);
              }else {
                  documentBorrowCopyRecord.setUpdateTime(LocalDateTime.now());
                  documentBorrowCopyRecord.setUpdateBy(SecurityUtils.getUsername());
                  documentBorrowCopyRecordMapper.updateById(documentBorrowCopyRecord);
              }
 
          });
        }
    }
 
    @Override
    public CommonResult getDocumentBorrowCopy(Long id) {
        DocumentBorrowCopy documentBorrowCopy = documentBorrowCopyMapper.selectById(id);
        if (documentBorrowCopy != null){
            List<DocumentBorrowCopyRecord> documentBorrowCopyRecordList = documentBorrowCopyRecordMapper.selectList(
                    new LambdaQueryWrapper<>(DocumentBorrowCopyRecord.class).eq(DocumentBorrowCopyRecord::getDocumentBorrowId, id)
                            .eq(DocumentBorrowCopyRecord::getDelFlag, UserConstant.ENABLE).orderByAsc(DocumentBorrowCopyRecord::getSort)
            );
            documentBorrowCopy.setDocumentBorrowCopyRecordList(documentBorrowCopyRecordList);
        }
        return CommonResult.success(documentBorrowCopy);
    }
 
    @Override
    @Transactional
    public CommonResult deletedDocumentBorrowCopy(Long id) {
        int i = documentBorrowCopyMapper.update(new DocumentBorrowCopy(),
                new LambdaUpdateWrapper<DocumentBorrowCopy>().set(DocumentBorrowCopy::getDelFlag, UserConstant.DISENABLE)
                        .set(DocumentBorrowCopy::getUpdateTime, LocalDateTime.now())
                        .set(DocumentBorrowCopy::getUpdateBy, SecurityUtils.getUsername()).eq(DocumentBorrowCopy::getId, id)
        );
        if (i > 0){
            documentBorrowCopyRecordMapper.update(new DocumentBorrowCopyRecord(),
                    new LambdaUpdateWrapper<DocumentBorrowCopyRecord>().set(DocumentBorrowCopyRecord::getDelFlag, UserConstant.DISENABLE)
                            .set(DocumentBorrowCopyRecord::getUpdateTime, LocalDateTime.now()).set(DocumentBorrowCopyRecord::getUpdateBy, SecurityUtils.getUsername())
                            .eq(DocumentBorrowCopyRecord::getDocumentBorrowId, id));
        }
        return CommonResult.success();
    }
}