123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- package com.diagbot.facade;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.diagbot.client.UserServiceClient;
- import com.diagbot.dto.IntroducePageDTO;
- import com.diagbot.dto.QuestionShortDTO;
- import com.diagbot.dto.RespDTO;
- import com.diagbot.entity.IntroduceDetail;
- import com.diagbot.entity.IntroduceInfo;
- import com.diagbot.entity.IntroduceMap;
- import com.diagbot.entity.QuestionInfo;
- import com.diagbot.enums.IsDeleteEnum;
- import com.diagbot.service.IntroduceDetailService;
- import com.diagbot.service.IntroduceMapService;
- import com.diagbot.service.impl.IntroduceInfoServiceImpl;
- import com.diagbot.util.BeanUtil;
- import com.diagbot.util.DateUtil;
- import com.diagbot.util.UserUtils;
- import com.diagbot.vo.IntroduceDetailVO;
- import com.diagbot.vo.IntroduceMapVO;
- import com.diagbot.vo.IntroducePageVO;
- import com.diagbot.vo.IntroduceVO;
- import com.google.common.collect.Lists;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Qualifier;
- import org.springframework.stereotype.Component;
- import java.util.Date;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- /**
- * @Description:
- * @Author:zhaops
- * @time: 2018/11/16 14:30
- */
- @Component
- public class IntroduceInfoFacade extends IntroduceInfoServiceImpl {
- @Autowired
- IntroduceMapFacade introduceMapFacade;
- @Autowired
- IntroduceDetailFacade introduceDetailFacade;
- @Autowired
- @Qualifier("introduceDetailServiceImpl")
- IntroduceDetailService introduceDetailService;
- @Autowired
- @Qualifier("introduceMapServiceImpl")
- IntroduceMapService introduceMapService;
- @Autowired
- UserServiceClient userServiceClient;
- @Autowired
- QuestionInfoFacade questionInfoFacade;
- /**
- * 保存提示信息(新增or修改)
- *
- * @param introduceVO
- * @return
- */
- public Boolean saveIntroduce(IntroduceVO introduceVO) {
- IntroduceInfo introduceInfo = new IntroduceInfo();
- if (!(introduceVO.getId() == null||introduceInfo.getId().equals(0))) {
- introduceInfo = this.getById(introduceVO.getId());
- introduceInfo.setModifier(UserUtils.getCurrentPrincipleID());
- introduceInfo.setGmtModified(DateUtil.now());
- }
- Date now = DateUtil.now();
- String userId = UserUtils.getCurrentPrincipleID();
- introduceInfo.setCreator(userId);
- introduceInfo.setGmtCreate(now);
- introduceInfo.setModifier(userId);
- introduceInfo.setGmtModified(now);
- introduceInfo.setName(introduceVO.getName());
- introduceInfo.setRemark(introduceVO.getRemark());
- //更新提示信息
- this.saveOrUpdate(introduceInfo);
- //明细信息不更新,每次都删除重新插入
- //删除已有明细,逻辑删除
- if (!(introduceInfo.getId() == null)) {
- UpdateWrapper<IntroduceDetail> detailUpdateWrapper = new UpdateWrapper<>();
- detailUpdateWrapper.eq("introduce_id", introduceInfo.getId()).
- eq("is_deleted", IsDeleteEnum.N.getKey()).
- set("is_deleted", IsDeleteEnum.Y.getKey()).
- set("modifier", UserUtils.getCurrentPrincipleID()).
- set("gmt_modified", DateUtil.now());
- introduceDetailFacade.update(new IntroduceDetail(), detailUpdateWrapper);
- }
- List<IntroduceDetail> introduceDetailList = Lists.newArrayList();
- for (IntroduceDetailVO detailVO : introduceVO.getDetailVOList()) {
- IntroduceDetail detail = new IntroduceDetail();
- detail.setIntroduceId(introduceInfo.getId());
- detail.setCreator(UserUtils.getCurrentPrincipleID());
- detail.setGmtCreate(DateUtil.now());
- detail.setContent(detailVO.getContent());
- detail.setText(detailVO.getText());
- detail.setTitle(detailVO.getTitle());
- detail.setOrderNo(detailVO.getOrderNo());
- detail.setPosition(detailVO.getPosition());
- detail.setIsReason(detailVO.getIsReason());
- introduceDetailList.add(detail);
- }
- //插入新的明细记录
- introduceDetailService.saveBatch(introduceDetailList);
- //更新映射关系
- //删除已有映射关系
- UpdateWrapper<IntroduceMap> introduceMapUpdateWrapper = new UpdateWrapper<>();
- introduceMapUpdateWrapper.eq("introduce_id", introduceInfo.getId()).
- eq("is_deleted", IsDeleteEnum.N.getKey()).
- set("is_deleted", IsDeleteEnum.Y.getKey()).
- set("modifier", UserUtils.getCurrentPrincipleID()).
- set("gmt_modified", DateUtil.now());
- introduceMapFacade.update(new IntroduceMap(), introduceMapUpdateWrapper);
- //插入新的映射关系
- List<IntroduceMap> introduceMapList = Lists.newLinkedList();
- for (IntroduceMapVO introduceMapVO : introduceVO.getMapVOList()) {
- IntroduceMap introduceMap = new IntroduceMap();
- BeanUtil.copyProperties(introduceMapVO, introduceMap);
- introduceMap.setIntroduceId(introduceInfo.getId());
- introduceMapList.add(introduceMap);
- }
- introduceMapService.saveBatch(introduceMapList);
- return true;
- }
- /**
- * 单条删除提示信息 逻辑删除
- *
- * @param id
- * @return
- */
- public Boolean deleteRecord(Long id) {
- //删除已有映射关系
- UpdateWrapper<IntroduceMap> introduceMapUpdateWrapper = new UpdateWrapper<>();
- introduceMapUpdateWrapper.eq("introduce_id", id).
- eq("is_deleted", IsDeleteEnum.N.getKey()).
- set("is_deleted", IsDeleteEnum.Y.getKey()).
- set("modifier", UserUtils.getCurrentPrincipleID()).
- set("gmt_modified", DateUtil.now());
- introduceMapFacade.update(new IntroduceMap(), introduceMapUpdateWrapper);
- //删除明细
- UpdateWrapper<IntroduceDetail> introduceDetailUpdateWrapper = new UpdateWrapper<>();
- introduceDetailUpdateWrapper.eq("introduce_id", id).
- eq("is_deleted", IsDeleteEnum.N.getKey()).
- set("is_deleted", IsDeleteEnum.Y.getKey()).
- set("modifier", UserUtils.getCurrentPrincipleID()).
- set("gmt_modified", DateUtil.now());
- introduceDetailFacade.update(new IntroduceDetail(), introduceDetailUpdateWrapper);
- //删除提示信息
- UpdateWrapper<IntroduceInfo> introduceInfoUpdateWrapper = new UpdateWrapper<>();
- introduceInfoUpdateWrapper.eq("id", id).
- eq("is_deleted", IsDeleteEnum.N.getKey()).
- set("is_deleted", IsDeleteEnum.Y.getKey()).
- set("modifier", UserUtils.getCurrentPrincipleID()).
- set("gmt_modified", DateUtil.now());
- this.update(new IntroduceInfo(), introduceInfoUpdateWrapper);
- return true;
- }
- /**
- * 批量删除提示信息 逻辑删除
- *
- * @param ids
- * @return
- */
- public Boolean deleteRecords(Long[] ids) {
- //删除已有映射关系
- UpdateWrapper<IntroduceMap> introduceMapUpdateWrapper = new UpdateWrapper<>();
- introduceMapUpdateWrapper.in("introduce_id", ids).
- eq("is_deleted", IsDeleteEnum.N.getKey()).
- set("is_deleted", IsDeleteEnum.Y.getKey()).
- set("modifier", UserUtils.getCurrentPrincipleID()).
- set("gmt_modified", DateUtil.now());
- introduceMapFacade.update(new IntroduceMap(), introduceMapUpdateWrapper);
- //删除明细
- UpdateWrapper<IntroduceDetail> introduceDetailUpdateWrapper = new UpdateWrapper<>();
- introduceDetailUpdateWrapper.in("introduce_id", ids).
- eq("is_deleted", IsDeleteEnum.N.getKey()).
- set("is_deleted", IsDeleteEnum.Y.getKey()).
- set("modifier", UserUtils.getCurrentPrincipleID()).
- set("gmt_modified", DateUtil.now());
- introduceDetailFacade.update(new IntroduceDetail(), introduceDetailUpdateWrapper);
- //删除提示信息
- UpdateWrapper<IntroduceInfo> introduceInfoUpdateWrapper = new UpdateWrapper<>();
- introduceInfoUpdateWrapper.in("id", ids).
- eq("is_deleted", IsDeleteEnum.N.getKey()).
- set("is_deleted", IsDeleteEnum.Y.getKey()).
- set("modifier", UserUtils.getCurrentPrincipleID()).
- set("gmt_modified", DateUtil.now());
- this.update(new IntroduceInfo(), introduceInfoUpdateWrapper);
- return true;
- }
- /**
- * 获取提示信息分页信息,带条件
- *
- * @param introducePageVO
- * @return
- */
- public IPage<IntroducePageDTO> getIntroducePageByMap(IntroducePageVO introducePageVO) {
- IPage<IntroducePageDTO> introducePageDTOIPage = this.getIntroducePage(introducePageVO);
- List<IntroducePageDTO> records = introducePageDTOIPage.getRecords();
- for (IntroducePageDTO introducePageDTO : records) {
- introducePageDTO.setOperator(introducePageDTO.getModifier());
- introducePageDTO.setGmtOperate(introducePageDTO.getGmtModified());
- }
- List<String> userIds = records.stream().map(introduceList -> introduceList.getOperator()).collect(Collectors.toList());
- RespDTO<Map<String, String>> userInfos = userServiceClient.getUserInfoByIds(userIds);
- if (userInfos != null) {
- Map<String, String> userInfoMap = userInfos.data;
- for (IntroducePageDTO introducePageDTO : records) {
- if (userInfoMap.containsKey(introducePageDTO.getOperator())) {
- introducePageDTO.setOperatorName(userInfoMap.get(introducePageDTO.getOperator()));
- }
- }
- }
- introducePageDTOIPage.setRecords(records);
- return introducePageDTOIPage;
- }
- /**
- * 带条件查询
- *
- * @param map
- * @return
- */
- public List<IntroduceInfo> getByMap(Map<String, Object> map) {
- QueryWrapper<IntroduceInfo> introduceInfoQueryWrapper = new QueryWrapper<>();
- for (Map.Entry<String, Object> entry : map.entrySet()) {
- introduceInfoQueryWrapper.eq(entry.getKey(), entry.getValue());
- }
- return this.list(introduceInfoQueryWrapper);
- }
- /**
- * 根据id获取提示信息
- *
- * @param id
- * @return
- */
- public IntroducePageDTO getIntroduceById(Long id) {
- IntroducePageDTO introducePageDTO = new IntroducePageDTO();
- IntroduceInfo introduceInfo = this.getById(id);
- BeanUtil.copyProperties(introduceInfo, introducePageDTO);
- QueryWrapper<IntroduceMap> introduceMapQueryWrapper = new QueryWrapper<>();
- introduceMapQueryWrapper.eq("introduce_id", id).eq("is_deleted", IsDeleteEnum.N.getKey());
- List<IntroduceMap> introduceMapList = introduceMapFacade.list(introduceMapQueryWrapper);
- List<Long> questionIds = introduceMapList.stream().map(introduceMap -> introduceMap.getQuestionId()).collect(Collectors.toList());
- QueryWrapper<QuestionInfo> questionInfoQueryWrapper = new QueryWrapper<>();
- questionInfoQueryWrapper.in("id", questionIds).eq("is_deleted", IsDeleteEnum.N.getKey());
- List<QuestionInfo> questionInfoList = questionInfoFacade.list(questionInfoQueryWrapper);
- List<QuestionShortDTO> questionShortDTOList = Lists.newLinkedList();
- String tagName = "";
- for (QuestionInfo questionInfo : questionInfoList) {
- QuestionShortDTO questionShortDTO = new QuestionShortDTO();
- BeanUtil.copyProperties(questionInfo, questionShortDTO);
- questionShortDTOList.add(questionShortDTO);
- tagName += questionInfo.getTagName() + ",";
- }
- if (tagName.endsWith(",")) {
- tagName = tagName.substring(0, tagName.length() - 1);
- }
- introducePageDTO.setTagName(tagName);
- introducePageDTO.setQuestionList(questionShortDTOList);
- //未关联的标签
- QueryWrapper<QuestionInfo> unRelatedQuestionWrapper = new QueryWrapper<>();
- unRelatedQuestionWrapper.eq("is_deleted", IsDeleteEnum.N.getKey()).notIn("id", questionIds);
- List<QuestionInfo> unRelatedQuestionList = questionInfoFacade.list(unRelatedQuestionWrapper);
- List<QuestionShortDTO> unRelatedQuestionDTOList = Lists.newLinkedList();
- for (QuestionInfo questionInfo : unRelatedQuestionList) {
- QuestionShortDTO questionShortDTO = new QuestionShortDTO();
- BeanUtil.copyProperties(questionInfo, questionShortDTO);
- unRelatedQuestionDTOList.add(questionShortDTO);
- }
- introducePageDTO.setUnRelatedQuestionList(unRelatedQuestionDTOList);
- return introducePageDTO;
- }
- /**
- * 获取未关联标签列表
- *
- * @return
- */
- public List<QuestionShortDTO> getAllQuestionList() {
- QueryWrapper<QuestionInfo> unRelatedQuestionWrapper = new QueryWrapper<>();
- unRelatedQuestionWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
- List<QuestionInfo> unRelatedQuestionList = questionInfoFacade.list(unRelatedQuestionWrapper);
- List<QuestionShortDTO> unRelatedQuestionDTOList = Lists.newLinkedList();
- for (QuestionInfo questionInfo : unRelatedQuestionList) {
- QuestionShortDTO questionShortDTO = new QuestionShortDTO();
- BeanUtil.copyProperties(questionInfo, questionShortDTO);
- unRelatedQuestionDTOList.add(questionShortDTO);
- }
- return unRelatedQuestionDTOList;
- }
- }
|