package com.inspect.metadata.montdata.controller;

import com.inspect.metadata.montdata.domain.BasedataMontPatDevAlmAbn;
import com.inspect.metadata.montdata.domain.BasedataMontPatDevStaData;
import com.inspect.metadata.montdata.service.IBasedataMontPatDevAlmAbnService;
import com.inspect.metadata.montdata.service.IBasedataMontPatDevStaDataService;
import com.inspect.base.core.utils.poi.ExcelUtil;
import com.inspect.base.core.web.controller.BaseController;
import com.inspect.base.core.web.domain.AjaxResult;
import com.inspect.base.core.web.page.TableDataInfo;
import com.inspect.common.log.annotation.Log;
import com.inspect.common.log.enums.BizType;
import com.inspect.common.security.annotation.RequiresPermissions;

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

import org.springframework.beans.BeanUtils;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/montdata/patdevstadata"})
public class BasedataMontPatDevStaDataController extends BaseController {
    @Resource
    private IBasedataMontPatDevStaDataService basedataMontPatDevStaDataService;
    @Resource
    private IBasedataMontPatDevAlmAbnService basedataMontPatDevAlmAbnService;

    @RequiresPermissions({"basedata/montdata:patdevstadata:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(BasedataMontPatDevStaData basedataMontPatdevstadata) {
        this.startPage();
        BasedataMontPatDevAlmAbn basedataMontPatdevalmabn = new BasedataMontPatDevAlmAbn();
        BeanUtils.copyProperties(basedataMontPatdevstadata, basedataMontPatdevalmabn);
        if ("99".equals(basedataMontPatdevstadata.getType())) {
            List<BasedataMontPatDevAlmAbn> listAlmAbn = this.basedataMontPatDevAlmAbnService.selectBasedataMontPatDevAlmAbnList(basedataMontPatdevalmabn);
            return this.getDataTable(listAlmAbn);
        } else {
            List<BasedataMontPatDevStaData> listSta = this.basedataMontPatDevStaDataService.selectBasedataMontPatDevStaDataList(basedataMontPatdevstadata);
            return this.getDataTable(listSta);
        }
    }

    @RequiresPermissions({"basedata/montdata:patdevstadata:export"})
    @Log(title = "巡视设备状态数据", businessType = BizType.EXPORT)
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, BasedataMontPatDevStaData basedataMontPatdevstadata) {
        List<BasedataMontPatDevStaData> list = this.basedataMontPatDevStaDataService.selectBasedataMontPatDevStaDataList(basedataMontPatdevstadata);
        ExcelUtil<BasedataMontPatDevStaData> util = new ExcelUtil<>(BasedataMontPatDevStaData.class);
        util.exportExcel(response, list, "巡视设备状态数据数据");
    }

    @RequiresPermissions({"basedata/montdata:patdevstadata:query"})
    @GetMapping({"/{mont_patdevstadata_id}"})
    public AjaxResult getInfo(@PathVariable("mont_patdevstadata_id") Long montPatDevStaDataId) {
        return AjaxResult.success(this.basedataMontPatDevStaDataService.selectBasedataMontPatDevStaDataByMontPatDevStaDataId(montPatDevStaDataId));
    }

    @RequiresPermissions({"basedata/montdata:patdevstadata:add"})
    @Log(title = "巡视设备状态数据", businessType = BizType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasedataMontPatDevStaData basedataMontPatdevstadata) {
        return this.toAjax(this.basedataMontPatDevStaDataService.insertBasedataMontPatDevStaData(basedataMontPatdevstadata));
    }

    @RequiresPermissions({"basedata/montdata:patdevstadata:edit"})
    @Log(title = "巡视设备状态数据", businessType = BizType.UPDATE)
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody BasedataMontPatDevStaData basedataMontPatdevstadata) {
        return this.toAjax(this.basedataMontPatDevStaDataService.updateBasedataMontPatDevStaData(basedataMontPatdevstadata));
    }

    @RequiresPermissions({"basedata/montdata:patdevstadata:remove"})
    @Log(title = "巡视设备状态数据", businessType = BizType.DELETE)
    @PostMapping({"/remove/{mont_patdevstadata_ids}"})
    public AjaxResult remove(@PathVariable("mont_patdevstadata_ids") Long[] montPatDevStaDataIds) {
        return this.toAjax(this.basedataMontPatDevStaDataService.deleteBasedataMontPatDevStaDataByMontPatDevStaDataIds(montPatDevStaDataIds));
    }
}
