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.THtmlConfig; import com.ruoyi.system.model.TPhysicalGoods; import com.ruoyi.system.query.BigGiftPackageQuery; import com.ruoyi.system.service.THtmlConfigService; import com.ruoyi.system.service.TPhysicalGoodsService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; import java.util.Objects; import static net.sf.jsqlparser.parser.feature.Feature.update; /** *

* 实物商品 前端控制器 *

* * @author xiaochen * @since 2025-12-08 */ @RestController @RequestMapping("/t-physical-goods") @Api(tags = "(嘉视达)实物商品") public class TPhysicalGoodsController { private final TPhysicalGoodsService tPhysicalGoodsService; private final TokenService tokenService; private final THtmlConfigService tHtmlConfigService; public TPhysicalGoodsController(TPhysicalGoodsService tPhysicalGoodsService, TokenService tokenService, THtmlConfigService tHtmlConfigService) { this.tPhysicalGoodsService = tPhysicalGoodsService; this.tokenService = tokenService; this.tHtmlConfigService = tHtmlConfigService; } @ApiOperation(value = "实物商品分页列表") @PostMapping(value = "/pageList") public R> pageList(@RequestBody BigGiftPackageQuery query) { Page tPhysicalGoodsPage = new Page<>(query.getPageNum(), query.getPageSize()); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(TPhysicalGoods::getStatus,1); wrapper.like(Objects.nonNull(query.getName()), TPhysicalGoods::getName, query.getName()); wrapper.orderByDesc(TPhysicalGoods::getCreateTime); Page pageInfo = tPhysicalGoodsService.page(tPhysicalGoodsPage, wrapper); return R.ok(pageInfo); } @ApiOperation(value = "实物商品详情") @GetMapping(value = "/detail/{id}") public R detail(@PathVariable Integer id ) { TPhysicalGoods tPhysicalGoods = tPhysicalGoodsService.getById(id); return R.ok(tPhysicalGoods); } @ApiOperation(value = "实物商品添加") @PostMapping(value = "/add") @Log(title = "实物商品-添加", businessType = BusinessType.INSERT) public R add(@RequestBody TPhysicalGoods tPhysicalGoods) { LoginUser loginUser = tokenService.getLoginUser(); tPhysicalGoods.setCreateUserId(loginUser.getUserId()); boolean save = tPhysicalGoodsService.save(tPhysicalGoods); return save ? R.ok() : R.fail(); } @ApiOperation(value = "实物商品修改") @PostMapping(value = "/update") @Log(title = "实物商品-修改", businessType = BusinessType.UPDATE) public R update(@RequestBody TPhysicalGoods tPhysicalGoods) { LoginUser loginUser = tokenService.getLoginUser(); tPhysicalGoods.setUpdateUserId(loginUser.getUserId()); boolean update = tPhysicalGoodsService.updateById(tPhysicalGoods); return update ? R.ok() : R.fail(); } @ApiOperation(value = "实物商品删除") @DeleteMapping(value = "/delete/{id}") @Log(title = "实物商品-删除", businessType = BusinessType.DELETE) public R delete(@PathVariable Integer id ) { TPhysicalGoods physicalGoods = tPhysicalGoodsService.getById(id); physicalGoods.setStatus(0); physicalGoods.setUpdateUserId(tokenService.getLoginUser().getUserId()); boolean remove = tPhysicalGoodsService.updateById(physicalGoods); return remove ? R.ok() : R.fail(); } @ApiOperation(value = "实物商品是否展示(0不展示 1展示)") @PostMapping(value = "/isShow") @Log(title = "实物商品-展示", businessType = BusinessType.UPDATE) public R isShow(@RequestParam String isShow) { THtmlConfig config = tHtmlConfigService.getById(8); config.setContent(isShow); boolean update = tHtmlConfigService.updateById(config); return update ? R.ok() : R.fail(); } }