package com.fdkankan.fusion.service.impl; import java.util.Date; import cn.dev33.satoken.stp.StpUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.fdkankan.fusion.common.PageInfo; import com.fdkankan.fusion.common.ResultCode; import com.fdkankan.fusion.common.enums.IdPreEnum; import com.fdkankan.fusion.common.util.IdUtils; import com.fdkankan.fusion.entity.TmMessage; import com.fdkankan.fusion.entity.TmProject; import com.fdkankan.fusion.exception.BusinessException; import com.fdkankan.fusion.mapper.ITmMessageMapper; import com.fdkankan.fusion.request.MessageReqDto; import com.fdkankan.fusion.service.ITmMessageService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.fdkankan.fusion.service.ITmProjectService; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** *

* 留言信息表 服务实现类 *

* * @author * @since 2023-07-28 */ @Service public class TmMessageServiceImpl extends ServiceImpl implements ITmMessageService { @Autowired ITmProjectService tmProjectService; @Override public void addNew(MessageReqDto body) { if(StringUtils.isBlank(body.getProjectId()) || StringUtils.isBlank(body.getContent())){ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS); } TmProject tmProject = tmProjectService.getById(body.getProjectId()); if(null == tmProject){ throw new BusinessException(ResultCode.PROJECT_NOT_EXITS); } TmMessage tmMessage = new TmMessage(); tmMessage.setId(IdUtils.genId(IdPreEnum.MESSAGE_PRE.getPre())); tmMessage.setContent(body.getContent()); tmMessage.setProjectId(body.getProjectId()); tmMessage.setUserId((String) StpUtil.getLoginId()); tmMessage.setCreatorId((String) StpUtil.getLoginId()); this.save(tmMessage); } @Override public Object pageList(MessageReqDto messageReqDto) { if( StringUtils.isBlank(messageReqDto.getContent())){ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS); } LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(TmMessage::getProjectId,messageReqDto.getProjectId()); Page page = this.page(new Page<>(messageReqDto.getPageNum(), messageReqDto.getPageSize()), wrapper); return PageInfo.PageInfo(page); } }