package com.doumee.service.business.impl; import com.doumee.biz.system.SystemDictDataBiz; import com.doumee.core.constants.Constants; import com.doumee.core.constants.ResponseStatus; import com.doumee.core.exception.BusinessException; import com.doumee.core.model.LoginUserInfo; import com.doumee.core.model.PageData; import com.doumee.core.model.PageWrap; import com.doumee.core.utils.Utils; import com.doumee.dao.business.InformationMapper; import com.doumee.dao.business.model.Carousel; import com.doumee.dao.business.model.Information; import com.doumee.service.business.InformationService; 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.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.apache.shiro.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import java.util.Date; import java.util.List; import java.util.Objects; /** * 动态咨询Service实现 * @author 江蹄蹄 * @since 2025/06/18 09:30 */ @Service public class InformationServiceImpl implements InformationService { @Autowired private InformationMapper informationMapper; @Autowired private SystemDictDataBiz systemDictDataBiz; @Override public Integer create(Information information) { LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); if(Objects.isNull(information) // || Objects.isNull(information.getSortnum()) // || Objects.isNull(information.getReleaseDate()) || StringUtils.isEmpty(information.getTitle()) // || StringUtils.isEmpty(information.getContent()) // || StringUtils.isEmpty(information.getDetail()) // || StringUtils.isEmpty(information.getImgurl()) ){ throw new BusinessException(ResponseStatus.BAD_REQUEST); } information.setType(Constants.formatIntegerNum(information.getType())); information.setIsdeleted(Constants.ZERO); information.setCreateDate(new Date()); information.setCreator(user.getId()); informationMapper.insert(information); return information.getId(); } @Override public void deleteById(Integer id) { informationMapper.update(new UpdateWrapper().lambda().set(Information::getIsdeleted,Constants.ONE).eq(Information::getId,id)); } @Override public void delete(Information information) { UpdateWrapper deleteWrapper = new UpdateWrapper<>(information); informationMapper.delete(deleteWrapper); } @Override public void deleteByIdInBatch(List ids) { if (CollectionUtils.isEmpty(ids)) { return; } for (Integer id : ids) { this.deleteById(id); } } @Override public void updateById(Information information) { LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); if(Objects.isNull(information) || Objects.isNull(information.getId()) // || Objects.isNull(information.getSortnum()) // || Objects.isNull(information.getReleaseDate()) || StringUtils.isEmpty(information.getTitle()) // || StringUtils.isEmpty(information.getContent()) // || StringUtils.isEmpty(information.getDetail()) // || StringUtils.isEmpty(information.getImgurl()) ){ throw new BusinessException(ResponseStatus.BAD_REQUEST); } information.setIsdeleted(Constants.ZERO); information.setEditDate(new Date()); information.setEditor(user.getId()); informationMapper.updateById(information); } @Override public void updateByIdInBatch(List informations) { if (CollectionUtils.isEmpty(informations)) { return; } for (Information information: informations) { this.updateById(information); } } @Override public Information findById(Integer id) { Information information = informationMapper.selectById(id); if(Objects.isNull(information)&& org.apache.commons.lang3.StringUtils.isNotBlank(information.getImgurl())){ String fileDir = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FILE_DIR).getCode(); information.setFullImgurl(fileDir + information.getImgurl()); } return information; } @Override public Information findOne(Information information) { QueryWrapper wrapper = new QueryWrapper<>(information); return informationMapper.selectOne(wrapper); } @Override public List findList(Information information) { QueryWrapper wrapper = new QueryWrapper<>(information); return informationMapper.selectList(wrapper); } @Override public PageData findPage(PageWrap pageWrap) { IPage page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); QueryWrapper queryWrapper = new QueryWrapper<>(); Utils.MP.blankToNull(pageWrap.getModel()); queryWrapper.lambda() .eq(Information::getIsdeleted,Constants.ZERO) .eq(pageWrap.getModel().getId() != null, Information::getId, pageWrap.getModel().getId()) .eq(pageWrap.getModel().getModule() != null, Information::getModule, pageWrap.getModel().getModule()) .eq(pageWrap.getModel().getType() != null, Information::getType, pageWrap.getModel().getType()) .eq(pageWrap.getModel().getStatus() != null, Information::getStatus, pageWrap.getModel().getStatus()) .eq(pageWrap.getModel().getRemark() != null, Information::getRemark, pageWrap.getModel().getRemark()) .like(pageWrap.getModel().getTitle() != null, Information::getTitle, pageWrap.getModel().getTitle()) .like(pageWrap.getModel().getDetail() != null, Information::getDetail, pageWrap.getModel().getDetail()) .like(pageWrap.getModel().getContent() != null, Information::getContent, pageWrap.getModel().getContent()) .ge(pageWrap.getModel().getReleaseDate() != null, Information::getReleaseDate, Utils.Date.getStart(pageWrap.getModel().getReleaseDate())) .le(pageWrap.getModel().getReleaseDate() != null, Information::getReleaseDate, Utils.Date.getEnd(pageWrap.getModel().getReleaseDate())) .orderByDesc(Information::getSortnum) ; for(PageWrap.SortData sortData: pageWrap.getSorts()) { if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { queryWrapper.orderByDesc(sortData.getProperty()); } else { queryWrapper.orderByAsc(sortData.getProperty()); } } IPage iPage = informationMapper.selectPage(page, queryWrapper); String fileDir = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FILE_DIR).getCode(); for (Information information:iPage.getRecords()) { if(!Objects.isNull(information)&& org.apache.commons.lang3.StringUtils.isNotBlank(information.getImgurl())){ information.setFullImgurl(fileDir + information.getImgurl()); } } return PageData.from(iPage); } @Override public long count(Information information) { QueryWrapper wrapper = new QueryWrapper<>(information); return informationMapper.selectCount(wrapper); } @Override public void updateStatus(Information information){ if(Objects.isNull(information) || Objects.isNull(information.getStatus()) || Objects.isNull(information.getId()) || !(Constants.equalsInteger(information.getStatus(),Constants.ZERO) || Constants.equalsInteger(information.getStatus(),Constants.ONE))){ throw new BusinessException(ResponseStatus.DATA_EMPTY); } informationMapper.update(new UpdateWrapper().lambda().set(Information::getStatus,information.getStatus()).eq(Information::getId,information.getId())); } }