123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- package com.diagbot.facade;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.diagbot.entity.IntroduceDetail;
- import com.diagbot.entity.IntroduceInfo;
- import com.diagbot.service.impl.IntroduceDetailServiceImpl;
- import com.diagbot.service.impl.IntroduceInfoServiceImpl;
- import com.diagbot.util.UserUtils;
- import com.diagbot.vo.IntroduceDetailVO;
- 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.stereotype.Component;
- import java.util.Arrays;
- import java.util.Date;
- import java.util.List;
- import java.util.Map;
- /**
- * @Description:
- * @Author:zhaops
- * @time: 2018/11/16 14:30
- */
- @Component
- public class IntroduceInfoFacade extends IntroduceInfoServiceImpl {
- @Autowired
- IntroduceMapFacade introduceMapFacade;
- @Autowired
- IntroduceDetailFacade introduceDetailFacade;
- @Autowired
- IntroduceDetailServiceImpl introduceDetailServiceImpl;
- /**
- * 保存提示信息(新增or修改)
- *
- * @param introduceVO
- * @return
- */
- public Boolean saveIntroduce(IntroduceVO introduceVO) {
- IntroduceInfo introduceInfo = new IntroduceInfo();
- if (!(introduceVO.getId() == null)) {
- introduceInfo = this.getById(introduceVO.getId());
- //introduceInfo.setModifier(UserUtils.getCurrentPrincipleID());
- introduceInfo.setGmtModified(new Date());
- } else {
- //introduceInfo.setCreator(UserUtils.getCurrentPrincipleID());
- introduceInfo.setGmtCreate(new Date());
- }
- introduceInfo.setName(introduceVO.getName());
- introduceInfo.setRemark(introduceVO.getRemark());
- //更新提示信息
- this.saveOrUpdate(introduceInfo);
- //明细信息不更新,每次都删除重新插入
- //删除已有明细,物理删除
- if (!(introduceInfo.getId() == null)) {
- QueryWrapper<IntroduceDetail> detailQueryWrapper = new QueryWrapper<>();
- detailQueryWrapper.eq("introduce_id", introduceInfo.getId());
- introduceDetailFacade.remove(detailQueryWrapper);
- }
- List<IntroduceDetail> introduceDetailList = Lists.newArrayList();
- for (IntroduceDetailVO detailVO : introduceVO.getDetailVOList()) {
- IntroduceDetail detail = new IntroduceDetail();
- detail.setIntroduceId(introduceInfo.getId());
- //detail.setCreator(UserUtils.getCurrentPrincipleID());
- detail.setGmtCreate(new Date());
- detail.setContent(detailVO.getContent());
- detail.setText(detailVO.getText());
- detail.setTitle(detailVO.getTitle());
- detail.setOrderNo(detailVO.getOrderNo());
- detail.setPosition(detailVO.getPosition());
- introduceDetailList.add(detail);
- }
- //插入新的明细记录
- introduceDetailServiceImpl.saveBatch(introduceDetailList);
- return true;
- }
- /**
- * 单条删除提示信息 物理删除
- *
- * @param id
- * @return
- */
- public Boolean deleteRecord(Long id) {
- //删除明细
- QueryWrapper<IntroduceDetail> introduceDetailQueryWrapper = new QueryWrapper<>();
- introduceDetailQueryWrapper.eq("introduce_id", id);
- introduceDetailFacade.remove(introduceDetailQueryWrapper);
- //删除提示信息
- this.removeById(id);
- return true;
- }
- /**
- * 批量删除提示信息 物理删除
- *
- * @param ids
- * @return
- */
- public Boolean deleteRecords(Long[] ids) {
- //删除明细
- QueryWrapper<IntroduceDetail> introduceDetailQueryWrapper = new QueryWrapper<>();
- introduceDetailQueryWrapper.in("introduce_id", ids);
- introduceDetailFacade.remove(introduceDetailQueryWrapper);
- //删除提示信息
- this.removeByIds(Arrays.asList(ids));
- return true;
- }
- /**
- * 分页查询提示信息,可带等于条件
- *
- * @param introducePageVO
- * @return
- */
- public IPage<IntroduceInfo> getPageByMap(IntroducePageVO introducePageVO) {
- QueryWrapper<IntroduceInfo> introduceInfoQueryWrapper = new QueryWrapper<>();
- for (Map.Entry<String, Object> entry : introducePageVO.getMap().entrySet()) {
- introduceInfoQueryWrapper.eq(entry.getKey(), entry.getValue());
- }
- IPage<IntroduceInfo> introduceInfoIPage = this.page(introducePageVO, introduceInfoQueryWrapper);
- return introduceInfoIPage;
- }
- /**
- * 带条件查询
- *
- * @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);
- }
- }
|