package com.dk.mdm.controller.core;

import com.dk.common.model.pojo.PageList;
import com.dk.common.response.ResponseResultVO;
import com.dk.mdm.model.pojo.core.Factory;
import com.dk.common.service.BaseService;
import com.dk.mdm.model.query.core.FactoryQuery;
import com.dk.mdm.model.response.core.FactoryResponse;
import com.dk.mdm.model.vo.core.FactoryVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import com.dk.mdm.service.core.FactoryService;

/**
 * @desc   : 工厂API接口
 * @author : 周兴
 * @date   : 2023/1/4 9:25
 */
@Api(tags = "工厂API接口")
@RestController
@RequestMapping("/core/factory")
public class FactoryController{

    public BaseService<Factory> getService() {
        return factoryService;
    }

    @Autowired
    private FactoryService factoryService;

    /**
     * @desc   : 条件查询
     * @author : 周兴
     * @date   : 2023/1/4 9:39
     */
    @ApiOperation( value = "分页、关联、条件查询", notes = "分页、关联、条件查询" )
    @PostMapping({"list_by"})
    public ResponseResultVO<PageList<FactoryResponse>> selectByCond(@RequestBody FactoryQuery factoryQuery) {
        return factoryService.selectByCond(factoryQuery);
    }

    /**
     * @desc : 通过ID查询
     * @author : 周兴
     * @date : 2023/1/4 9:39
     */
    @PostMapping({"{id}"})
    public ResponseResultVO selectById(@PathVariable String id) {
        return factoryService.selectById(id);
    }


    /**
     * @desc : 新建工厂
     * @author : 周兴
     * @date : 2023/1/4 9:39
     */
    @ApiOperation( value = "新建工厂", notes = "新建工厂" )
    @PostMapping({"insert"})
    public ResponseResultVO<?> insert(@RequestBody FactoryVO factoryVO) {
        return factoryService.insert(factoryVO);
    }

    /**
     * @desc : 编辑工厂
     * @author : 周兴
     * @date : 2023/1/4 9:39
     */
    @ApiOperation( value = "编辑工厂", notes = "编辑工厂" )
    @PostMapping({"update"})
    public ResponseResultVO<Boolean> update(@RequestBody FactoryVO factoryVO) {
        return factoryService.update(factoryVO);
    }

    /**
     * @desc : 停用
     * @author : 周兴
     * @date :  2023/1/4 9:39
     */
    @ApiOperation(value = "停用", notes = "停用")
    @PostMapping("disable/{id}")
    public ResponseResultVO<Boolean> disable(@PathVariable String id) {
        return this.getService().disable(id);
    }

    /**
     * @desc : 启用
     * @author : 周兴
     * @date :  2023/1/4 9:39
     */
    @ApiOperation(value = "启用", notes = "启用")
    @PostMapping("enable/{id}")
    public ResponseResultVO<Boolean> enable(@PathVariable String id) {return this.getService().enable(id); }
}
