heheng
2025-11-17 df77511b027636bd2202983d7ac4cdc636eac94b
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
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.gkhy.exam.common.api.CommonPage;
import com.gkhy.exam.common.api.CommonResult;
import com.gkhy.exam.common.utils.PageUtils;
import com.gkhy.exam.common.utils.SecurityUtils;
import com.gkhy.exam.system.domain.Memo;
import com.gkhy.exam.system.domain.vo.IndexDataRep;
import com.gkhy.exam.system.domain.vo.IndexSearch;
import com.gkhy.exam.system.mapper.MemoMapper;
import com.gkhy.exam.system.service.MemoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
 
/**
 * <p>
 * 备忘录 服务实现类
 * </p>
 *
 * @author hh
 * @since 2025-11-10 13:58:42
 */
@Service
public class MemoServiceImpl extends ServiceImpl<MemoMapper, Memo> implements MemoService {
 
    @Autowired
    private MemoMapper memoMapper;
    @Override
    public CommonResult saveMemo(Memo memo) {
        if (memo.getId() != null){
 
            LambdaUpdateWrapper<Memo> updateWrapper = new LambdaUpdateWrapper<>();
            updateWrapper.eq(Memo::getCreateById, SecurityUtils.getUserId());
            updateWrapper.set(Memo::getContent, memo.getContent())
                    .set(Memo::getUpdateById, memo.getUpdateById())
                    .set(Memo::getUpdateTime, LocalDateTime.now());
            memoMapper.update(new Memo(), updateWrapper);
        }else {
            LambdaQueryWrapper<Memo> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(Memo::getCreateById, SecurityUtils.getUserId());
            if (memoMapper.selectCount(queryWrapper) >= 1){
                return CommonResult.failed("只能保存一个");
            }
            memo.setCreateById(SecurityUtils.getUserId());
            memo.setCompanyId(SecurityUtils.getCompanyId() == null ? 0 : SecurityUtils.getCompanyId());
            memo.setCreateTime(LocalDateTime.now());
            memoMapper.insert(memo);
        }
        return CommonResult.success(memo);
    }
 
    @Override
    public CommonResult getMemo() {
        LambdaQueryWrapper<Memo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Memo::getCreateById, SecurityUtils.getUserId());
        return CommonResult.success(memoMapper.selectOne(queryWrapper));
    }
 
    @Override
    public CommonPage getIndexTitle() {
 
        Long userId = SecurityUtils.getUserId();
        Long deptId = SecurityUtils.getLoginUser().getUser().getDeptId();
        Long companyId = SecurityUtils.getCompanyId();
        IndexSearch indexSearch = new IndexSearch();
        indexSearch.setUserId(userId);
        indexSearch.setCompanyId(companyId);
        if (deptId != null && deptId == 20){
            indexSearch.setKeyword(deptId.toString());
        }
        if (deptId != null && deptId == 22){
            indexSearch.setKeyword1(deptId.toString());
        }
        PageUtils.startPage();
        List<IndexDataRep> indexTitle = memoMapper.getIndexTitle(indexSearch);
        return CommonPage.restPage(indexTitle);
    }
}