package cn.stylefeng.rest.modular.home.controller;
|
|
import cn.hutool.core.util.StrUtil;
|
import cn.stylefeng.guns.modular.business.entity.PsychologicalColumn;
|
import cn.stylefeng.guns.modular.business.entity.PsychologicalRead;
|
import cn.stylefeng.guns.modular.business.service.IPsychologicalColumnService;
|
import cn.stylefeng.guns.modular.business.service.IPsychologicalReadService;
|
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
|
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
import cn.stylefeng.roses.kernel.rule.enums.DeleteEnum;
|
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
|
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.annotation.Resource;
|
import java.util.List;
|
|
/**
|
* 主页接口-心理专栏
|
*
|
* @author goupan
|
* @date 2024/01/02
|
*/
|
@RestController
|
@Api(tags = "主页接口")
|
@ApiResource(name = "主页接口")
|
@RequestMapping("/home/psychologicalColumn")
|
public class HomePsychologicalColumnController {
|
|
@Resource
|
private IPsychologicalColumnService psychologicalColumnService;
|
|
@Resource
|
private IPsychologicalReadService psychologicalReadService;
|
|
@ApiOperation("心理专栏(分页)")
|
@GetResource(name = "心理专栏(分页)", path = "/page")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "pageNo", value = "当前页数", dataTypeClass = Integer.class, defaultValue = "1"),
|
@ApiImplicitParam(name = "pageSize", value = "分页条数", dataTypeClass = Integer.class, defaultValue = "20"),
|
@ApiImplicitParam(name = "title", value = "标题")
|
})
|
public ResponseData<PageResult<PsychologicalColumn>> page(Integer pageNo, Integer pageSize, String title) {
|
Page<PsychologicalColumn> page = this.psychologicalColumnService.page(
|
PageFactory.page(pageNo, pageSize),
|
Wrappers.<PsychologicalColumn>lambdaQuery()
|
.eq(PsychologicalColumn::getIsDelete,DeleteEnum.NOT_DELETE.getCode())
|
.like(StrUtil.isNotBlank(title), PsychologicalColumn::getArticleTitle,DeleteEnum.NOT_DELETE.getCode())
|
.orderByDesc(PsychologicalColumn::getReleaseTime)
|
);
|
return new SuccessResponseData<>(PageResultFactory.createPageResult(page));
|
}
|
|
@ApiOperation("心理专栏")
|
@GetResource(name = "心理专栏", path = "/list")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "title", value = "标题")
|
})
|
public ResponseData<List<PsychologicalColumn>> list(String title) {
|
// 查询列表
|
List<PsychologicalColumn> list = psychologicalColumnService.list(
|
Wrappers.<PsychologicalColumn>lambdaQuery()
|
.eq(PsychologicalColumn::getIsDelete, DeleteEnum.NOT_DELETE.getCode())
|
.like(StrUtil.isNotBlank(title), PsychologicalColumn::getArticleTitle, title)
|
.orderByDesc(PsychologicalColumn::getCreateTime)
|
);
|
return new SuccessResponseData(list);
|
}
|
|
@ApiOperation(value = "心理专栏详情", notes = "心理专栏详情,增加阅读量")
|
@GetResource(name = "心理专栏", path = "/detail/{id}")
|
public ResponseData<PsychologicalColumn> detail(@PathVariable("id") Long id) {
|
// 查询详情
|
PsychologicalColumn obj = psychologicalColumnService.getById(id);
|
|
// 获取当前登录用户信息
|
LoginUser loginUser = LoginContext.me().getLoginUser();
|
if (loginUser != null) {
|
// 获取当前用户的用户Id
|
Long userId = loginUser.getUserId();
|
|
// // 是否阅读过
|
// long count = psychologicalReadService.count(
|
// Wrappers.<PsychologicalRead>lambdaQuery()
|
// .eq(PsychologicalRead::getPsychologicalColumnId, id)
|
// .eq(PsychologicalRead::getUserId, userId)
|
// );
|
//
|
// if (count == 0) {
|
// 阅读量+1
|
psychologicalColumnService.update(
|
Wrappers.<PsychologicalColumn>lambdaUpdate()
|
.set(PsychologicalColumn::getReadNum, obj.getReadNum() + 1)
|
.eq(PsychologicalColumn::getId, id)
|
);
|
|
// 保存阅读记录
|
PsychologicalRead read = new PsychologicalRead();
|
read.setPsychologicalColumnId(id);
|
read.setUserId(userId);
|
psychologicalReadService.save(read);
|
// }
|
}
|
|
return new SuccessResponseData(obj);
|
}
|
|
}
|