com.github.rexsheng.springboot.faster.system.post.application.PostServiceImpl Maven / Gradle / Ivy
The newest version!
package com.github.rexsheng.springboot.faster.system.post.application;
import com.github.rexsheng.springboot.faster.common.constant.CommonConstant;
import com.github.rexsheng.springboot.faster.common.domain.PagedList;
import com.github.rexsheng.springboot.faster.spring.SpringContext;
import com.github.rexsheng.springboot.faster.system.post.application.dto.AddPostRequest;
import com.github.rexsheng.springboot.faster.system.post.application.dto.PostDetailResponse;
import com.github.rexsheng.springboot.faster.system.post.application.dto.QueryPostRequest;
import com.github.rexsheng.springboot.faster.system.post.application.dto.UpdatePostRequest;
import com.github.rexsheng.springboot.faster.system.post.domain.PostStateChangedEvent;
import com.github.rexsheng.springboot.faster.system.post.domain.SysPost;
import com.github.rexsheng.springboot.faster.system.post.domain.gateway.PostGateway;
import com.github.rexsheng.springboot.faster.system.post.domain.gateway.QueryPostDO;
import jakarta.annotation.Resource;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import java.util.List;
import java.util.stream.Collectors;
@Service
@ConditionalOnClass({SqlSessionFactoryBean.class})
public class PostServiceImpl implements PostService{
@Resource
private PostGateway postGateway;
@Override
public void add(AddPostRequest request) {
postGateway.insertPost(request.toPost());
SpringContext.getApplicationContext().publishEvent(new PostStateChangedEvent(PostStateChangedEvent.PostState.ADD));
}
@Override
public List queryList(QueryPostRequest request) {
QueryPostDO query=new QueryPostDO();
query.setName(request.getPostName());
query.setStatus(CommonConstant.STATUS_RUNNING);
List dataList=postGateway.queryPosts(query);
return dataList.stream().map(PostDetailResponse::of).collect(Collectors.toList());
}
@Override
public PagedList pagedList(QueryPostRequest request) {
QueryPostDO query=new QueryPostDO();
query.setName(request.getPostName());
query.setPageIndex(request.getPageIndex());
query.setPageSize(request.getPageSize());
PagedList dataList=postGateway.paginatePosts(query);
return PagedList.of(dataList, PostDetailResponse::of);
}
@Override
public PostDetailResponse get(Integer id) {
SysPost data= postGateway.getPost(id);
Assert.notNull(data,"岗位不存在");
return PostDetailResponse.of(data);
}
@Override
public void update(UpdatePostRequest request) {
SysPost data=request.toPost();
postGateway.updatePostById(data);
}
@Override
public void updateStatus(List request) {
List dataList=request.stream().map(UpdatePostRequest::toPost).collect(Collectors.toList());
postGateway.updatePostStatus(dataList);
SpringContext.getApplicationContext().publishEvent(new PostStateChangedEvent(PostStateChangedEvent.PostState.STATUS_CHANGED));
}
@Override
public void delete(List ids) {
postGateway.deletePosts(SysPost.of(ids,true));
SpringContext.getApplicationContext().publishEvent(new PostStateChangedEvent(PostStateChangedEvent.PostState.DELETE));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy