package com.ylx.web.controller.massage;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ylx.common.annotation.Log;
import com.ylx.common.core.controller.BaseController;
import com.ylx.common.enums.BusinessType;
import com.ylx.massage.domain.TConsumptionLog;
import com.ylx.massage.service.TConsumptionLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.ylx.common.core.domain.R;
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * 个人钱包记录表(TConsumptionLog)表控制层
 *
 * @author makejava
 * @since 2024-04-25 16:50:31
 */
@RestController
@RequestMapping("tConsumptionLog")
@Api(tags = {"余额记录"})
public class TConsumptionLogController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private TConsumptionLogService tConsumptionLogService;

    /**
     * 分页查询所有数据
     *
     * @param page            分页对象
     * @param tConsumptionLog 查询实体
     * @return 所有数据
     */
    @GetMapping("selectAll")
    @ApiOperation("分页查询数据")
    @Log(title = "分页查询数据", businessType = BusinessType.OTHER)
    public R<Page<TConsumptionLog>> selectAll(Page<TConsumptionLog> page, TConsumptionLog tConsumptionLog) {
        LambdaQueryWrapper<TConsumptionLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TConsumptionLog::getOpenId, tConsumptionLog.getOpenId())
                .eq(tConsumptionLog.getBillType() != null,TConsumptionLog::getBillType, tConsumptionLog.getBillType())
                .orderByDesc(TConsumptionLog::getCreateTime);
        return R.ok(this.tConsumptionLogService.page(page, queryWrapper));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public R selectOne(@PathVariable Serializable id) {
        return R.ok(this.tConsumptionLogService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param tConsumptionLog 实体对象
     * @return 新增结果
     */
    @PostMapping
    public R insert(@RequestBody TConsumptionLog tConsumptionLog) {
        return R.ok(this.tConsumptionLogService.save(tConsumptionLog));
    }

    /**
     * 修改数据
     *
     * @param tConsumptionLog 实体对象
     * @return 修改结果
     */
    @PutMapping
    public R update(@RequestBody TConsumptionLog tConsumptionLog) {
        return R.ok(this.tConsumptionLogService.updateById(tConsumptionLog));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public R delete(@RequestParam("idList") List<Long> idList) {
        return R.ok(this.tConsumptionLogService.removeByIds(idList));
    }
}

