package com.zehong.web.controller.gasBottleTrack;

import java.util.List;

import com.zehong.system.domain.TGasBottleInfo;
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.zehong.common.annotation.Log;
import com.zehong.common.core.controller.BaseController;
import com.zehong.common.core.domain.AjaxResult;
import com.zehong.common.enums.BusinessType;
import com.zehong.system.domain.TPractitionerInfo;
import com.zehong.system.service.ITPractitionerInfoService;
import com.zehong.common.utils.poi.ExcelUtil;
import com.zehong.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 从业人员信息Controller
 * 
 * @author zehong
 * @date 2023-08-16
 */
@RestController
@RequestMapping("/practitioner/info")
public class TPractitionerInfoController extends BaseController
{
    @Autowired
    private ITPractitionerInfoService tPractitionerInfoService;

    /**
     * 查询从业人员信息列表
     */
    @PreAuthorize("@ss.hasPermi('practitioner:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPractitionerInfo tPractitionerInfo)
    {
        startPage();
        List<TPractitionerInfo> list = tPractitionerInfoService.selectTPractitionerInfoList(tPractitionerInfo);
        return getDataTable(list);
    }

    /**
     * 导出从业人员信息列表
     */
    @PreAuthorize("@ss.hasPermi('practitioner:info:export')")
    @Log(title = "从业人员信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TPractitionerInfo tPractitionerInfo)
    {
        List<TPractitionerInfo> list = tPractitionerInfoService.selectTPractitionerInfoList(tPractitionerInfo);
        ExcelUtil<TPractitionerInfo> util = new ExcelUtil<TPractitionerInfo>(TPractitionerInfo.class);
        return util.exportExcel(list, "从业人员信息数据");
    }

    /**
     * 获取从业人员信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('practitioner:info:query')")
    @GetMapping(value = "/{practitionerId}")
    public AjaxResult getInfo(@PathVariable("practitionerId") Long practitionerId)
    {
        return AjaxResult.success(tPractitionerInfoService.selectTPractitionerInfoById(practitionerId));
    }

    /**
     * 新增从业人员信息
     */
    @PreAuthorize("@ss.hasPermi('practitioner:info:add')")
    @Log(title = "从业人员信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPractitionerInfo tPractitionerInfo)
    {
        return toAjax(tPractitionerInfoService.insertTPractitionerInfo(tPractitionerInfo));
    }

    /**
     * 修改从业人员信息
     */
    @PreAuthorize("@ss.hasPermi('practitioner:info:edit')")
    @Log(title = "从业人员信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPractitionerInfo tPractitionerInfo)
    {
        return toAjax(tPractitionerInfoService.updateTPractitionerInfo(tPractitionerInfo));
    }

    /**
     * 删除从业人员信息
     */
    @PreAuthorize("@ss.hasPermi('practitioner:info:remove')")
    @Log(title = "从业人员信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{practitionerIds}")
    public AjaxResult remove(@PathVariable Long[] practitionerIds)
    {
        return toAjax(tPractitionerInfoService.deleteTPractitionerInfoByIds(practitionerIds));
    }

    /**
     * 储配站导入
     * @param file
     * @param updateSupport
     * @return
     * @throws Exception
     */
    @PreAuthorize("@ss.hasPermi('practitioner:info:import')")
    @Log(title = "储配站维护", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<TPractitionerInfo> util = new ExcelUtil<>(TPractitionerInfo.class);
        List<TPractitionerInfo> tPractitionerInfo = util.importExcel(file.getInputStream());
        String message = tPractitionerInfoService.importTPractitionerInfo(tPractitionerInfo, updateSupport);
        return AjaxResult.success(message);
    }

    @GetMapping("/importTemplate")
    public AjaxResult importTemplate(){
        ExcelUtil<TPractitionerInfo> util = new ExcelUtil<>(TPractitionerInfo.class);
        return util.importTemplateExcel("从业人员数据");
    }
}
