| | |
| | | package com.finance.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.finance.common.basic.PageDTO; |
| | | import com.finance.common.core.domain.entity.SysUser; |
| | | import com.finance.common.utils.BeanUtils; |
| | | import com.finance.common.utils.CollUtils; |
| | | import com.finance.common.utils.DateUtils; |
| | | import com.finance.common.utils.StringUtils; |
| | | import com.finance.system.constants.QuarterConstant; |
| | | import com.finance.system.domain.TbQuestion; |
| | | import com.finance.system.dto.QuestionDTO; |
| | | import com.finance.system.dto.update.QuestionUpdDTO; |
| | | import com.finance.system.mapper.TbQuestionMapper; |
| | | import com.finance.system.query.QuestionQuery; |
| | | import com.finance.system.service.AsyncService; |
| | | import com.finance.system.service.ISysUserService; |
| | | import com.finance.system.service.TbQuestionService; |
| | | import com.finance.system.vo.QuestionVO; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @since 2024-03-13 |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class TbQuestionServiceImpl extends ServiceImpl<TbQuestionMapper, TbQuestion> implements |
| | | TbQuestionService { |
| | | |
| | | private final ISysUserService sysUserService; |
| | | private final AsyncService asyncService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void addQuestion(QuestionDTO dto) throws Exception { |
| | | TbQuestion tbQuestion = BeanUtils.copyBean(dto, TbQuestion.class); |
| | | tbQuestion.setQuarter(DateUtils.getNowQuarter()); |
| | | tbQuestion.setType(dto.getType()); |
| | | String previousQuarter = DateUtils.getPreviousQuarter(); |
| | | previousQuarter = QuarterConstant.CURRENT_QUARTER; |
| | | tbQuestion.setQuarter(previousQuarter); |
| | | this.save(tbQuestion); |
| | | asyncService.subtractScoreWithFixedRules(dto.getDeptAreaCode()); |
| | | } |
| | | |
| | | @Override |
| | | public void editQuestion(QuestionUpdDTO dto) { |
| | | public void editQuestion(QuestionUpdDTO dto) throws Exception { |
| | | TbQuestion tbQuestion = BeanUtils.copyBean(dto, TbQuestion.class); |
| | | tbQuestion.setType(dto.getType()); |
| | | this.updateById(tbQuestion); |
| | | asyncService.subtractScoreWithFixedRules(dto.getDeptAreaCode()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | .like(StringUtils.isNotBlank(dto.getTitle()), TbQuestion::getTitle, dto.getTitle()) |
| | | .orderByDesc(TbQuestion::getCreateTime) |
| | | .page(new Page<>(dto.getPageNum(), dto.getPageSize())); |
| | | return PageDTO.of(page, QuestionVO.class); |
| | | if (StringUtils.isEmpty(page.getRecords())) { |
| | | return PageDTO.empty(page.getTotal(), page.getPages()); |
| | | } |
| | | PageDTO<QuestionVO> questionVOPageDTO = PageDTO.of(page, QuestionVO.class); |
| | | Set<String> areaCodeSet = questionVOPageDTO.getList().stream() |
| | | .map(QuestionVO::getDeptAreaCode) |
| | | .collect(Collectors.toSet()); |
| | | if (CollUtils.isNotEmpty(areaCodeSet)) { |
| | | List<SysUser> sysUsers = sysUserService.list( |
| | | Wrappers.lambdaQuery(SysUser.class).in(SysUser::getAreaCode, areaCodeSet)); |
| | | Map<String, String> deptNameMap = sysUsers.stream() |
| | | .collect(Collectors.toMap(SysUser::getAreaCode, SysUser::getAreaName)); |
| | | if (CollUtils.isNotEmpty(deptNameMap)) { |
| | | for (QuestionVO questionVO : questionVOPageDTO.getList()) { |
| | | String deptName = deptNameMap.get(questionVO.getDeptAreaCode()); |
| | | questionVO.setDeptName(StringUtils.isNotBlank(deptName) ? deptName : ""); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return questionVOPageDTO; |
| | | } |
| | | |
| | | @Override |
| | | public void delete(Long id) { |
| | | TbQuestion question = this.getById(id); |
| | | try { |
| | | asyncService.subtractScoreWithFixedRules(question.getDeptAreaCode()); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | this.removeById(id); |
| | | } |
| | | } |