package com.qmth.sop.server.api;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.sop.business.entity.TBProduct;
import com.qmth.sop.business.service.TBProductService;
import com.qmth.sop.common.contant.SystemConstant;
import com.qmth.sop.common.enums.ProductTypeEnum;
import com.qmth.sop.common.util.Result;
import com.qmth.sop.common.util.ResultUtil;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * 产品信息 控制器.
 *
 * @author: shudonghui
 * @date: 2023-08-17 09:37:24
 * @version: 1.0
 * @email: shudonghui@qmth.com.cn
 * @Company: www.qmth.com.cn
 */
@Api(tags = "产品信息 Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_PRODUCT)
public class TBProductController {


    @Resource
    TBProductService tbProductService;

    @ApiOperation(value = "获取产品信息列表接口")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "产品信息列表", response = TBProduct.class)})
    public Result list(@ApiParam(value = "是否启用") @RequestParam(required = false) Boolean enable,
                       @ApiParam(value = "产品类型") @RequestParam(required = false) ProductTypeEnum productType) {
        QueryWrapper<TBProduct> queryWrapper = new QueryWrapper<>();
        if (enable != null) {
            queryWrapper.lambda().eq(TBProduct::getEnable, enable);
        }
        if (productType != null) {
            queryWrapper.lambda().eq(TBProduct::getCode, productType);
        }
        return ResultUtil.ok(tbProductService.list(queryWrapper.lambda().orderByDesc(TBProduct::getCreateTime)));
    }
}
