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;
/**
*
* 备忘录 服务实现类
*
*
* @author hh
* @since 2025-11-10 13:58:42
*/
@Service
public class MemoServiceImpl extends ServiceImpl implements MemoService {
@Autowired
private MemoMapper memoMapper;
@Override
public CommonResult saveMemo(Memo memo) {
if (memo.getId() != null){
LambdaUpdateWrapper 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 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 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 indexTitle = memoMapper.getIndexTitle(indexSearch);
return CommonPage.restPage(indexTitle);
}
}