package com.sqx.modules.artificerselfgoods.controller;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sqx.common.utils.Result;
import com.sqx.modules.artificerselfgoods.entity.BlArtificerSelfGoods;
import com.sqx.modules.artificerselfgoods.entity.BlArtificerSelfGoodsEntryExitRecords;
import com.sqx.modules.artificerselfgoods.service.BlArtificerSelfGoodsEntryExitRecordsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * @author bai
 * @date 2024/06/08
 */
@RestController
@Api(value = "v3-技师与物料关系表出入库记录", tags = { "v3-技师与物料关系表出入库记录" })
@RequestMapping(value = "/blArtificerSelfGoodsEntryExitRecords")
public class BlArtificerSelfGoodsEntryExitRecordsController {

    @Autowired
    private BlArtificerSelfGoodsEntryExitRecordsService service;

    @GetMapping("/list")
    @ApiOperation("获取数据列表")
    public Result list(BlArtificerSelfGoodsEntryExitRecords entity, Integer page,Integer limit){
        QueryWrapper<BlArtificerSelfGoodsEntryExitRecords> qw = new QueryWrapper<>();

        if(entity != null) {
            //技师
            qw.lambda().eq(entity.getArtificerId() != null, BlArtificerSelfGoodsEntryExitRecords::getArtificerId, entity.getArtificerId());
            qw.lambda().eq(entity.getSelfGoodsId() != null, BlArtificerSelfGoodsEntryExitRecords::getSelfGoodsId, entity.getSelfGoodsId());
        }

        qw.orderByAsc("create_time");
        IPage<BlArtificerSelfGoodsEntryExitRecords> pageList = service.page(new Page<>(page,limit),qw);
        return Result.success().put("data",pageList);
    }

    @RequestMapping("/info/{id}")
    public Result info(@PathVariable("id") Long id){
        BlArtificerSelfGoodsEntryExitRecords data = service.getById(id);
        return Result.success().put("data", data);
    }

}