package com.ruoyi.web.controller.biz;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ruoyi.biz.domain.BizPatentValidOg;
import com.ruoyi.biz.service.IBizPatentValidOgService;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileTypeUtils;
import com.ruoyi.common.utils.file.MimeTypeUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.ResponseData;
import javax.validation.Valid;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

/**
 * 专利有效原始Controller
 * 
 * @author dm
 * @date 2023-03-09
 */
@Api(value = "专利有效原始",tags = "专利有效原始")
@ApiSupport(author = "dm",order = 10)
@RestController
@RequestMapping("/biz/bizPatentValidOg")
public class BizPatentValidOgController extends BaseController
{
    @Autowired
    private IBizPatentValidOgService bizPatentValidOgService;

    /**
     * 查询专利有效原始列表
     */
    @ApiOperation(value = "查询专利有效原始列表",notes = "查询专利有效原始列表")
    @ApiOperationSupport(order = 10)
    @PreAuthorize("@ss.hasPermi('biz:bizPatentValidOg:list')")
    @GetMapping("/list")
    public TableDataInfo<BizPatentValidOg> list(BizPatentValidOg bizPatentValidOg)
    {
        startPage();
        List<BizPatentValidOg> list = bizPatentValidOgService.selectBizPatentValidOgList(bizPatentValidOg);
        return getDataTable(list);
    }

    /**
     * 导出专利有效原始列表
     */
    @ApiOperation(value = "导出专利有效原始列表",notes = "导出专利有效原始列表")
    @ApiOperationSupport(order = 20)
    @PreAuthorize("@ss.hasPermi('biz:bizPatentValidOg:export')")
    @Log(title = "专利有效原始", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizPatentValidOg bizPatentValidOg)
    {
        List<BizPatentValidOg> list = bizPatentValidOgService.selectBizPatentValidOgList(bizPatentValidOg);
        ExcelUtil<BizPatentValidOg> util = new ExcelUtil<BizPatentValidOg>(BizPatentValidOg.class);
        util.exportExcel(response, list, "专利有效原始数据");
    }

    /**
     * 获取专利有效原始详细信息
     */
    @ApiOperation(value = "获取专利有效原始详细信息",notes = "获取专利有效原始详细信息")
    @ApiOperationSupport(order = 30)
    @PreAuthorize("@ss.hasPermi('biz:bizPatentValidOg:query')")
    @GetMapping(value = "/{id}")
    public ResponseData<BizPatentValidOg> getInfo(@PathVariable("id") String id)
    {
        return ResponseData.success(bizPatentValidOgService.selectBizPatentValidOgById(id));
    }

    /**
     * 新增专利有效原始
     */
    @ApiOperation(value = "新增专利有效原始",notes = "新增专利有效原始")
    @ApiOperationSupport(order = 40,ignoreParameters = {"bizPatentValidOg.id"})
    @PreAuthorize("@ss.hasPermi('biz:bizPatentValidOg:add')")
    @Log(title = "专利有效原始", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public ResponseData add(@RequestBody @Valid @ApiParam(required=true) BizPatentValidOg bizPatentValidOg)
    {
        int i = bizPatentValidOgService.insertBizPatentValidOg(bizPatentValidOg);
        if(i>0){
            //返回主键
            return ResponseData.success(bizPatentValidOg.getId());
        }else{
            return ResponseData.error();
        }
    }

    /**
     * 修改专利有效原始
     */
    @ApiOperation(value = "修改专利有效原始",notes = "修改专利有效原始")
    @ApiOperationSupport(order = 50)
    @PreAuthorize("@ss.hasPermi('biz:bizPatentValidOg:edit')")
    @Log(title = "专利有效原始", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @RepeatSubmit
    public ResponseData edit(@RequestBody @Valid @ApiParam(required=true) BizPatentValidOg bizPatentValidOg)
    {
        int i = bizPatentValidOgService.updateBizPatentValidOg(bizPatentValidOg);
        if(i>0){
            //返回主键
            return ResponseData.success(bizPatentValidOg.getId());
        }else{
            return ResponseData.error();
        }
    }

    /**
     * 删除专利有效原始
     */
    @ApiOperation(value = "删除专利有效原始",notes = "删除专利有效原始")
    @ApiOperationSupport(order = 60)
    @PreAuthorize("@ss.hasPermi('biz:bizPatentValidOg:remove')")
    @Log(title = "专利有效原始", businessType = BusinessType.DELETE)
    @PostMapping("/delete/{ids}")
    public ResponseData remove(@PathVariable String[] ids)
    {
        //return toResult(bizPatentValidOgService.deleteBizPatentValidOgByIds(ids));
        //逻辑删除
        return toResult(bizPatentValidOgService.setDeleteByIds(ids));
    }

    /**
     * 查询专利有效原始列表---不进行分页
     */
    @ApiOperation(value = "查询专利有效原始列表---不进行分页",notes = "查询专利有效原始列表---不进行分页")
    @ApiOperationSupport(order = 70)
    @PreAuthorize("@ss.hasPermi('biz:bizPatentValidOg:list')")
    @PostMapping("/getDataList")
    public ResponseData<List<BizPatentValidOg>> getDataList(@RequestBody BizPatentValidOg bizPatentValidOg)
    {
        List<BizPatentValidOg> list = bizPatentValidOgService.selectBizPatentValidOgList(bizPatentValidOg);
        return ResponseData.success(list);
    }

    @ApiOperation(value = "导入专利有效原始信息",notes = "导入专利有效原始信息")
    @ApiOperationSupport(order = 80)
    @Log(title = "专利有效原始", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('biz:bizPatentValidOg:import')")
    @PostMapping("/importData")
    public ResponseData importData(MultipartFile file) throws Exception
    {
        String message = null;
        if (!file.isEmpty())
        {
            String extension = FileTypeUtils.getExtension(file);
            if (!StringUtils.equalsAnyIgnoreCase(extension, MimeTypeUtils.CSV_EXTENSION))
            {
                message = "文件格式不正确，请上传" + Arrays.toString(MimeTypeUtils.CSV_EXTENSION) + "格式";
                return ResponseData.error(message);
            }
        }
        ExcelUtil<BizPatentValidOg> util = new ExcelUtil<BizPatentValidOg>(BizPatentValidOg.class);
        List<BizPatentValidOg> bizPatentValidOgList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        message = bizPatentValidOgService.importBizPatentValidOg(bizPatentValidOgList, operName);
        return ResponseData.success(message);
    }
}
