package cn.cecep.talroad.controller;

import cn.cecep.talroad.common.core.web.controller.BasesController;
import cn.cecep.talroad.common.core.web.domain.AjaxResults;
import cn.cecep.talroad.common.log.annotation.Log;
import cn.cecep.talroad.common.log.enums.BusinessType;
import cn.cecep.talroad.common.security.annotation.RequiresPermissions;
import cn.cecep.talroad.domain.PcLabelFactory;
import cn.cecep.talroad.service.IPcLabelFactoryService;
import cn.cecep.talroad.vo.PcLabelFactoryVo;
import cn.cecep.talroad.vo.query.PcLabelFactoryQuery;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * * 开发公司：中节能天融科技有限公司
 * 特征标签-与企业关系中间Controller 控制层
 */
@Api(tags = "基本档案--特征标签-与企业关系中间")
@RestController
@RequestMapping("/pcLabelFactory")
public class PcLabelFactoryController extends BasesController
{
    @Autowired
    private IPcLabelFactoryService pcLabelFactoryService;

    /**
     * 查询特征标签-与企业关系中间列表
     */
    @ApiOperation(value = "查询特征标签-与企业关系中间")
    @GetMapping("/list")
    public AjaxResults<IPage<PcLabelFactoryVo>> list(PcLabelFactoryQuery pcLabelFactory)
    {
        Page<PcLabelFactoryVo> voPage = new Page<>(pcLabelFactory.getPageNum(), pcLabelFactory.getPageSize());
        List<PcLabelFactoryVo> list = pcLabelFactoryService.selectFactoryLabelList(voPage, pcLabelFactory);
        voPage.setRecords(list);
        return AjaxResults.success(voPage);
    }


    /**
     * 获取特征标签-与企业关系中间详细信息
     */
    @ApiOperation(value = "获取特征标签-与企业关系中间详细信息")
    @PostMapping(value = "/getById/{id}")
    public AjaxResults<PcLabelFactory> getInfo(@PathVariable("id") String id) {
        return AjaxResults.success(pcLabelFactoryService.getById(id));
    }
    /**
     * 新增特征标签-与企业关系中间
     */
    @ApiOperation(value = "新增特征标签-与企业关系中间")
    @Log(title = "特征标签-与企业关系中间", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResults add(@RequestBody @Validated PcLabelFactory pcLabelFactory) {
        pcLabelFactoryService.add(pcLabelFactory);
        return AjaxResults.success(true);
    }
    /**
     * 修改特征标签-与企业关系中间
     */
    @ApiOperation(value = "修改特征标签-与企业关系中间")
    @Log(title = "特征标签-与企业关系中间", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public AjaxResults<Boolean> edit(@RequestBody PcLabelFactory pcLabelFactory) {
        pcLabelFactoryService.edit(pcLabelFactory);
        return AjaxResults.success(true);
    }

    /**
     * 删除特征标签-与企业关系中间
     */
    @ApiOperation(value = "删除特征标签-与企业关系中间")
    @RequiresPermissions("talroad:pcLabelFactory:remove")
    @Log(title = "特征标签-与企业关系中间", businessType = BusinessType.DELETE)
    @PostMapping("/{id}")
    public AjaxResults<Boolean> remove(@PathVariable String id) {
        pcLabelFactoryService.delete(id);
        return AjaxResults.success(true);
    }

    @ApiOperation(value = "批量将某一标签值赋予企业")
    @PostMapping(value = "/add/factory/batch")
    public AjaxResults<Boolean> batchAddFactoryLabel(@RequestBody PcLabelFactoryVo.FactoryLabelUpdateForm form) {
        pcLabelFactoryService.batchAddFactoryLabel(form);
        return AjaxResults.success(true);
    }
}
