package com.ruoyi.hv.controller;

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

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
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.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.bean.PojoUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.dimp.domain.DHighValueInfo;
import com.ruoyi.dimp.domain.DHighValueInfoExp;
import com.ruoyi.dimp.service.IDHighValueInfoService;
import com.ruoyi.hv.domain.DHeightValuePatentCompare;
import com.ruoyi.hv.service.IDHeightValuePatentCompareService;
import com.ruoyi.hv.service.IDHeightValuePatentDetailService;

/**
 * 高价值专利对照Controller
 *
 * @author ruoyi
 * @date 2023-04-02
 */
@RestController
@RequestMapping("/heightval/dHeightValuePatentCompare")
public class DHeightValuePatentCompareController extends BaseController {
	
    private final IDHeightValuePatentCompareService dHeightValuePatentCompareService;
    @Autowired
	private  IDHeightValuePatentDetailService dHeightValuePatentDetailService;
    @Autowired
	private IDHighValueInfoService dHighValueInfoService;
    
    
    public DHeightValuePatentCompareController(IDHeightValuePatentCompareService dHeightValuePatentCompareService) {
        this.dHeightValuePatentCompareService = dHeightValuePatentCompareService;
    }


    /**
     * 查询高价值专利对照列表
     *
     * @param dHeightValuePatentCompare 高价值专利对照
     * @return 高价值专利对照集合
     * @date 2023-04-02
     */
    @PreAuthorize("@ss.hasPermi('heightval:dHeightValuePatentCompare:list')")
    @GetMapping("/list")
    public TableDataInfo list(DHeightValuePatentCompare dHeightValuePatentCompare) {
        startPage();
//        int pageNum=PageMethod.getLocalPage().getPageNum();
//        int pageSize = PageMethod.getLocalPage().getPageSize();
//        
//        List<DHeightValuePatentCompare>detailList= dHeightValuePatentDetailService.queryCompare(dHeightValuePatentCompare);
//        
//        for(DHeightValuePatentCompare d:detailList) {
//        	if(d.getAppliAddress().contains("云南省")) {
//        		d.setAppliAddress(d.getAppliAddress().substring(d.getAppliAddress().indexOf("云南省")));
//        	}
//        }
//        
//        TableDataInfo tb =  getDataTable(detailList);
//        if(tb!=null) {
//        	tb.setTotal(dHeightValuePatentCompare.getTotal());
//        }
//        return tb;
        
        List<DHeightValuePatentCompare>detailList= dHeightValuePatentCompareService.queryList(dHeightValuePatentCompare);
        TableDataInfo tb =  getDataTable(detailList);
        return tb;
    }


    /**
     * 导出高价值专利对照列表
     *
     * @param dHeightValuePatentCompare 高价值专利对照
     * @date 2023-04-02
     */
    @PreAuthorize("@ss.hasPermi('heightval:dHeightValuePatentCompare:export')")
    @Log(title = "高价值专利对照", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DHighValueInfo dHighValueInfo) {
    	
    	List<DHighValueInfo>list=dHighValueInfoService.doList(dHighValueInfo);
//        List<DHeightValuePatentCompare> list = dHeightValuePatentCompareService.list(new QueryWrapper<>());
//        ExcelUtil<DHeightValuePatentCompare> util = new ExcelUtil<>(DHeightValuePatentCompare. class);
    	List<DHighValueInfoExp>expList =PojoUtils.copyToList(DHighValueInfoExp.class, list);
    	ExcelUtil<DHighValueInfoExp> util = new ExcelUtil<>(DHighValueInfoExp. class);
        util.exportExcel(response, expList, "高价值专利对照数据");
    }

    /**
     * 获取高价值专利对照详细信息
     *
     * @param id 主键id
     * @return 结果
     * @date 2023-04-02
     */
    @PreAuthorize("@ss.hasPermi('heightval:dHeightValuePatentCompare:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(dHeightValuePatentCompareService.getById(id));
    }


    /**
     * 新增高价值专利对照信息
     *
     * @param dHeightValuePatentCompare 高价值专利对照
     * @return 结果
     * @date 2023-04-02
     */
    @PreAuthorize("@ss.hasPermi('heightval:dHeightValuePatentCompare:add')")
    @Log(title = "高价值专利对照", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DHeightValuePatentCompare dHeightValuePatentCompare) {
        return toAjax(dHeightValuePatentCompareService.save(dHeightValuePatentCompare));
    }


    /**
     * 修改高价值专利对照信息
     *
     * @param dHeightValuePatentCompare 高价值专利对照
     * @return 结果
     * @date 2023-04-02
     */
    @PreAuthorize("@ss.hasPermi('heightval:dHeightValuePatentCompare:edit')")
    @Log(title = "高价值专利对照", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DHeightValuePatentCompare dHeightValuePatentCompare) {
        return toAjax(dHeightValuePatentCompareService.updateById(dHeightValuePatentCompare));
    }


    /**
     * 删除高价值专利对照信息
     *
     * @param ids 主键ids
     * @return 结果
     * @date 2023-04-02
     */
    @PreAuthorize("@ss.hasPermi('heightval:dHeightValuePatentCompare:remove')")
    @Log(title = "高价值专利对照", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(dHeightValuePatentCompareService.removeByIds(Arrays.asList(ids)));
    }


}
