package com.ruoyi.web.controller.info;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
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.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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AkmData;
import com.ruoyi.system.service.IAkmDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 安康码扫码地点Controller
 * 
 * @author ruoyi
 * @date 2022-10-10
 */
@RestController
@RequestMapping("/system/data")
public class AkmDataController extends BaseController
{
    @Autowired
    private IAkmDataService akmDataService;

    /**
     * 查询安康码扫码地点列表
     */
    @PreAuthorize("@ss.hasPermi('system:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(AkmData akmData)
    {
        startPage();
        List<AkmData> list = akmDataService.selectAkmDataList(akmData);
        return getDataTable(list);
    }


    /**
     * 查询安康码扫码地点列表（对外）
     */
    @GetMapping("/foreign/list")
    public AjaxResult foreignList(HttpServletRequest request, String secretKey, AkmData akmData)
    {

        return akmDataService.getForeignList(request,secretKey,akmData);
    }


    /**
     * 导出安康码扫码地点列表
     */
    @PreAuthorize("@ss.hasPermi('system:data:export')")
    @Log(title = "安康码扫码地点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AkmData akmData)
    {
        List<AkmData> list = akmDataService.selectAkmDataList(akmData);
        ExcelUtil<AkmData> util = new ExcelUtil<AkmData>(AkmData.class);
        util.exportExcel(response, list, "安康码扫码地点数据");
    }

    /**
     * 获取安康码扫码地点详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:data:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(akmDataService.selectAkmDataById(id));
    }

    /**
     * 新增安康码扫码地点
     */
    //@Log(title = "安康码扫码地点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AkmData akmData)
    {
        return akmDataService.insertAkmData(akmData);
    }


    /**
     * 修改安康码扫码地点
     */
    @Log(title = "安康码扫码地点", businessType = BusinessType.UPDATE)
    @PostMapping("put")
    public AjaxResult edit(@RequestBody AkmData akmData)
    {
        return toAjax(akmDataService.updateAkmData(akmData));
    }

    /**
     * 删除安康码扫码地点
     */
    @PreAuthorize("@ss.hasPermi('system:data:remove')")
    @Log(title = "安康码扫码地点", businessType = BusinessType.DELETE)
    @GetMapping(value = "/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(akmDataService.deleteAkmDataByIds(ids));
    }
}
