package com.aucma.report.controller;

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

import com.aucma.common.utils.DateUtils;
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.aucma.common.annotation.Log;
import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import com.aucma.common.enums.BusinessType;
import com.aucma.report.domain.BasePdaRecord;
import com.aucma.report.service.IBasePdaRecordService;
import com.aucma.common.utils.poi.ExcelUtil;
import com.aucma.common.core.page.TableDataInfo;

/**
 * PDA管理Controller
 *
 * @author Yinq
 * @date 2023-11-21
 */
@RestController
@RequestMapping("/report/pdaRecord" )
public class BasePdaRecordController extends BaseController {
    @Autowired
    private IBasePdaRecordService basePdaRecordService;

    /**
     * 查询PDA管理列表
     */
    @PreAuthorize("@ss.hasPermi('pdaRecord:pdaRecord:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(BasePdaRecord basePdaRecord) {
        startPage();
        List<BasePdaRecord> list = basePdaRecordService.selectBasePdaRecordList(basePdaRecord);
        return getDataTable(list);
    }

    /**
     * PDA获取手持串号
     * @param basePdaRecord
     * @return
     */
    @GetMapping("/getPdaRecord" )
    public AjaxResult getPdaRecord(BasePdaRecord basePdaRecord) {
        List<BasePdaRecord> list = basePdaRecordService.selectBasePdaRecordList(basePdaRecord);
        return success(list);
    }

    /**
     * 导出PDA管理列表
     */
    @PreAuthorize("@ss.hasPermi('pdaRecord:pdaRecord:export')" )
    @Log(title = "PDA管理" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, BasePdaRecord basePdaRecord) {
        List<BasePdaRecord> list = basePdaRecordService.selectBasePdaRecordList(basePdaRecord);
        ExcelUtil<BasePdaRecord> util = new ExcelUtil<BasePdaRecord>(BasePdaRecord. class);
        util.exportExcel(response, list, "PDA管理数据" );
    }

    /**
     * 获取PDA管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('pdaRecord:pdaRecord:query')" )
    @GetMapping(value = "/{objId}" )
    public AjaxResult getInfo(@PathVariable("objId" ) Long objId) {
        return success(basePdaRecordService.selectBasePdaRecordByObjId(objId));
    }

    /**
     * 新增PDA管理
     */
    @PreAuthorize("@ss.hasPermi('pdaRecord:pdaRecord:add')" )
    @Log(title = "PDA管理" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasePdaRecord basePdaRecord) {
        basePdaRecord.setCreatedBy(getUsername());
        basePdaRecord.setCreatedTime(DateUtils.getNowDate());
        return toAjax(basePdaRecordService.insertBasePdaRecord(basePdaRecord));
    }

    /**
     * 修改PDA管理
     */
    @PreAuthorize("@ss.hasPermi('pdaRecord:pdaRecord:edit')" )
    @Log(title = "PDA管理" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasePdaRecord basePdaRecord) {
        basePdaRecord.setUpdatedBy(getUsername());
        basePdaRecord.setUpdatedTime(DateUtils.getNowDate());
        return toAjax(basePdaRecordService.updateBasePdaRecord(basePdaRecord));
    }

    /**
     * 删除PDA管理
     */
    @PreAuthorize("@ss.hasPermi('pdaRecord:pdaRecord:remove')" )
    @Log(title = "PDA管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{objIds}" )
    public AjaxResult remove(@PathVariable Long[] objIds) {
        return toAjax(basePdaRecordService.deleteBasePdaRecordByObjIds(objIds));
    }
}
