package com.ruoyi.web.controller.api;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.model.TGuide;
import com.ruoyi.system.query.TGuideQuery;
import com.ruoyi.system.service.TGuideService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import java.util.Objects;
/**
*
* 景区攻略信息表 前端控制器
*
*
* @author L
* @since 2025-12-30
*/
@RestController
@RequestMapping("/t-guide")
@Api(tags = "(青都)景区攻略管理")
public class TGuideController {
private final TGuideService tGuideService;
private final TokenService tokenService;
public TGuideController(TGuideService tGuideService, TokenService tokenService) {
this.tGuideService = tGuideService;
this.tokenService = tokenService;
}
@ApiOperation(value = "景区攻略管理分页列表")
@PostMapping(value = "/pageList")
public R> pageList(@RequestBody TGuideQuery query) {
Page page = new Page<>(query.getPageNum(), query.getPageSize());
LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>();
wrapper.like(Objects.nonNull(query.getTitle()), TGuide::getTitle, query.getTitle());
if(query.getCreateTime()!=null && !query.getCreateTime().isEmpty()){
String createTime = query.getCreateTime();
String[] split = createTime.split(" - ");
wrapper.between(TGuide::getCreateTime, split[0] + " 00:00:00", split[1] + " 23:59:59");
}
wrapper.orderByDesc(TGuide::getCreateTime);
Page pageInfo = tGuideService.page(page, wrapper);
return R.ok(pageInfo);
}
@ApiOperation(value = "景区攻略详情")
@GetMapping(value = "/detail/{id}")
public R detail(@PathVariable Integer id ) {
TGuide Guide = tGuideService.getById(id);
return R.ok(Guide);
}
@ApiOperation(value = "景区攻略添加")
@PostMapping(value = "/add")
@Log(title = "景区攻略-添加", businessType = BusinessType.INSERT)
public R add(@RequestBody TGuide tGuide) {
LoginUser loginUser = tokenService.getLoginUser();
String nickName = loginUser.getUser().getNickName();
tGuide.setCreateBy(nickName);
boolean save = tGuideService.save(tGuide);
return save ? R.ok() : R.fail();
}
@ApiOperation(value = "景区攻略修改")
@PostMapping(value = "/update")
@Log(title = "景区攻略-修改", businessType = BusinessType.UPDATE)
public R update(@RequestBody TGuide tGuide) {
LoginUser loginUser = tokenService.getLoginUser();
tGuide.setUpdateBy(loginUser.getUser().getNickName());
boolean update = tGuideService.updateById(tGuide);
return update ? R.ok() : R.fail();
}
@ApiOperation(value = "景区攻略删除")
@DeleteMapping(value = "/delete/{id}")
@Log(title = "景区攻略-删除", businessType = BusinessType.DELETE)
public R delete(@PathVariable Integer id ) {
boolean remove = tGuideService.removeById(id);
return remove ? R.ok() : R.fail();
}
}