package com.mirs.biz.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.mirs.biz.domain.EmiMeasurement;
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.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
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.mirs.common.annotation.Log;
import com.mirs.common.core.controller.BaseController;
import com.mirs.common.core.domain.AjaxResult;
import com.mirs.common.enums.BusinessType;
import com.mirs.biz.domain.IntegratedData;
import com.mirs.biz.service.IIntegratedDataService;
import com.mirs.common.utils.poi.ExcelUtil;
import com.mirs.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 积分数据Controller
 * 
 * @author kk
 * @date 2025-04-24
 */
@RestController
@RequestMapping("/manage/integrated")
public class IntegratedDataController extends BaseController
{
    @Autowired
    private IIntegratedDataService integratedDataService;

    /**
     * 查询积分数据列表
     */
    @PreAuthorize("@ss.hasPermi('manage:integrated:list')")
    @GetMapping("/list")
    public TableDataInfo list(IntegratedData integratedData)
    {
        startPage();
        List<IntegratedData> list = integratedDataService.selectIntegratedDataList(integratedData);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('manage:integrated:list')")
    @GetMapping("/getList")
    public List<IntegratedData> getList(IntegratedData integratedData)
    {
         return integratedDataService.selectIntegratedDataList(integratedData);
    }

    /**
     * 导出积分数据列表
     */
    @PreAuthorize("@ss.hasPermi('manage:integrated:export')")
    @Log(title = "积分数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IntegratedData integratedData)
    {
        List<IntegratedData> list = integratedDataService.selectIntegratedDataList(integratedData);
        ExcelUtil<IntegratedData> util = new ExcelUtil<IntegratedData>(IntegratedData.class);
        util.exportExcel(response, list, "积分数据数据");
    }

    /**
     * 获取积分数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:integrated:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(integratedDataService.selectIntegratedDataById(id));
    }

    /**
     * 新增积分数据
     */
    @PreAuthorize("@ss.hasPermi('manage:integrated:add')")
    @Log(title = "积分数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IntegratedData integratedData)
    {
        return toAjax(integratedDataService.insertIntegratedData(integratedData));
    }

    /**
     * 修改积分数据
     */
    @PreAuthorize("@ss.hasPermi('manage:integrated:edit')")
    @Log(title = "积分数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IntegratedData integratedData)
    {
        return toAjax(integratedDataService.updateIntegratedData(integratedData));
    }

    /**
     * 删除积分数据
     */
    @PreAuthorize("@ss.hasPermi('manage:integrated:remove')")
    @Log(title = "积分数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(integratedDataService.deleteIntegratedDataByIds(ids));
    }


    @Log(title = "测量数据", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('manage:integrated:add')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<IntegratedData> util = new ExcelUtil<>(IntegratedData.class);
        List<IntegratedData> integratedDataList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = integratedDataService.importIntegratedData(integratedDataList, updateSupport, operName);
        return success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<IntegratedData> util = new ExcelUtil<>(IntegratedData.class);
        util.importTemplateExcel(response, "测量数据");
    }
}
