|
@@ -0,0 +1,118 @@
|
|
|
+package com.txz.cif.web.mng;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.txz.cif.core.Result;
|
|
|
+import com.txz.cif.core.ResultGenerator;
|
|
|
+import com.txz.cif.model.Goods;
|
|
|
+import com.txz.cif.model.RechargeRecord;
|
|
|
+import com.txz.cif.service.GoodsService;
|
|
|
+
|
|
|
+import com.txz.cif.core.ResultCode;
|
|
|
+
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import com.txz.cif.web.para.GoodsParam;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+
|
|
|
+import tk.mybatis.mapper.entity.Condition;
|
|
|
+import tk.mybatis.mapper.entity.Example.Criteria;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+* Created by CodeGenerator on 2025/07/15.
|
|
|
+*/
|
|
|
+@Api(tags = "[后台]充值商品管理")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/goods")
|
|
|
+public class GoodsController {
|
|
|
+
|
|
|
+ private static Logger log = LoggerFactory.getLogger(GoodsController.class);
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private GoodsService goodsService;
|
|
|
+
|
|
|
+ @PostMapping("/update")
|
|
|
+ @ApiOperation(value = "更新",httpMethod = "POST")
|
|
|
+ public Result update(@RequestBody Goods goods) {
|
|
|
+ if (goods.getId() == null) {
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.ID_IS_NULL);
|
|
|
+ }
|
|
|
+ goodsService.update(goods);
|
|
|
+ return ResultGenerator.genSuccessResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/add")
|
|
|
+ @ApiOperation(value = "新增",httpMethod = "POST")
|
|
|
+ public Result add(@RequestBody Goods goods) {
|
|
|
+ goods.setId(null);
|
|
|
+ goodsService.save(goods);
|
|
|
+ return ResultGenerator.genSuccessResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/delete")
|
|
|
+ @ApiOperation(value = "删除",httpMethod = "GET")
|
|
|
+ public Result<Goods> delete(@RequestParam Long id) {
|
|
|
+ if(id == null){
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.ID_IS_NULL);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ goodsService.deleteById(id);
|
|
|
+ return ResultGenerator.genSuccessResult();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询对象操作异常e:{}",e);
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/detail")
|
|
|
+ @ApiOperation(value = "获取详情",httpMethod = "GET")
|
|
|
+ public Result<Goods> detail(@RequestParam Long id) {
|
|
|
+ if(id == null){
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.ID_IS_NULL);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ Goods goods = goodsService.findById(id);
|
|
|
+ if (goods == null){
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.OBJECT_IS_NULL);
|
|
|
+ }
|
|
|
+ return ResultGenerator.genSuccessResult(goods);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询对象操作异常e:{}",e);
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/list")
|
|
|
+ @ApiOperation(value = "获取列表",httpMethod = "POST")
|
|
|
+ public Result<List<Goods>> list(@RequestBody GoodsParam param) {
|
|
|
+
|
|
|
+ PageHelper.startPage(param.getPage(), param.getSize());
|
|
|
+
|
|
|
+ Condition condition = new Condition(RechargeRecord.class);
|
|
|
+ Criteria criteria = condition.createCriteria();
|
|
|
+ if (param.getStatus() != null){
|
|
|
+ criteria.andEqualTo("status", param.getStatus());
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(param.getStartTime())){
|
|
|
+ criteria.andBetween("createTime", param.getStartTime(),param.getEndTime());
|
|
|
+ }
|
|
|
+ PageInfo pageInfo = null;
|
|
|
+ try {
|
|
|
+ condition.setOrderByClause("create_time desc");
|
|
|
+ List<Goods> list = goodsService.findByCondition(condition);
|
|
|
+ pageInfo = new PageInfo(list);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询对象操作异常e:{}",e);
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return ResultGenerator.genSuccessResult(pageInfo);
|
|
|
+ }
|
|
|
+}
|