package com.ylx.web.controller.massage; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ylx.common.annotation.Log; import com.ylx.common.core.domain.R; import com.ylx.common.enums.BusinessType; import com.ylx.common.exception.ServiceException; import com.ylx.massage.domain.TLbt; import com.ylx.massage.service.TLbtService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.List; /** * 轮播图 前端控制器 */ @RestController @RequestMapping("/api/lbt/v1") @Slf4j @Api(tags = {"轮播图管理"}) public class TLbtController { @Resource private TLbtService lbtService; /** * 获取轮播图 * * @return R> */ @ApiOperation("获取轮播图") @RequestMapping(value = "/getAll", method = RequestMethod.GET) public R> getAll() { try { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.lambda().orderByAsc(TLbt::getCSort); List list = lbtService.list(wrapper); return R.ok(list); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } } /** * 添加或者更新轮播图 * * @param lbt * @return R */ @Log(title = "轮播图管理", businessType = BusinessType.INSERT) @RequestMapping(value = "/addOrUpdate", method = RequestMethod.POST) @ApiOperation("添加或者更新轮播图") public R addOrUpdate(@RequestBody TLbt lbt) { try { log.info("请求参数:{}", JSON.toJSONString(lbt)); return R.ok(lbtService.addOrUpdate(lbt)); } catch (ServiceException s) { log.error(s.toString()); return R.fail(s.getMessage()); } catch (Exception e) { log.error(e.toString()); return R.fail("系统异常"); } } /** * 分页查询轮播图数据 * @param page * @param lbt * @return R> */ @ApiOperation("分页查询数据") @RequestMapping(value = "/select", method = RequestMethod.GET) public R> selectSpfl(Page page, TLbt lbt) { try { LambdaQueryWrapper tLbtLambdaQueryWrapper = new LambdaQueryWrapper<>(); tLbtLambdaQueryWrapper.like(StringUtils.isNotBlank(lbt.getCDescribe()), TLbt::getCDescribe, lbt.getCDescribe()) .orderByAsc(TLbt::getCSort); // 获取查询返回结果 Page pageSelect = lbtService.page(page, tLbtLambdaQueryWrapper); return R.ok(pageSelect); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } } /** * 删除轮播图 * * @param tLbt * @return R */ @Log(title = "轮播图管理", businessType = BusinessType.DELETE) @RequestMapping(value = "/del", method = RequestMethod.POST) @ApiOperation("删除轮播图") public R del(@RequestBody TLbt tLbt) { try { return R.ok(lbtService.del(tLbt)); } catch (ServiceException s) { log.error(s.toString()); return R.fail(s.getMessage()); } catch (Exception e) { log.error(e.toString()); return R.fail("系统异常"); } } /** * 根据id查询轮播图 * * @param tLbt * @return R */ @ApiOperation("根据id查询轮播图") @RequestMapping(value = "/wx/getByid", method = RequestMethod.POST) public R getById(@RequestBody TLbt tLbt) { return R.ok(lbtService.getById(tLbt.getCId())); } }