package com.sf.system.deployment.controller;

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

import com.sf.common.utils.StringUtils;
import com.sf.system.deployment.domain.rqs.ModuleListByCoreRequest;
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.sf.common.annotation.Log;
import com.sf.common.core.controller.BaseController;
import com.sf.common.core.domain.AjaxResult;
import com.sf.common.enums.BusinessType;
import com.sf.system.deployment.domain.DeploymentModuleList;
import com.sf.system.deployment.service.IDeploymentModuleListService;
import com.sf.common.utils.poi.ExcelUtil;
import com.sf.common.core.page.TableDataInfo;

/**
 * H5模块包Controller
 * 
 * @author ztzh
 * @date 2024-04-22
 */
@RestController
@RequestMapping("/deployment/module")
public class DeploymentModuleListController extends BaseController
{
    @Autowired
    private IDeploymentModuleListService deploymentModuleListService;

    /**
     * 查询H5模块包列表
     */
    @PreAuthorize("@ss.hasPermi('deployment:module:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeploymentModuleList deploymentModuleList)
    {
        startPage();
        List<DeploymentModuleList> list = deploymentModuleListService.selectDeploymentModuleListList(deploymentModuleList);
        return getDataTable(list);
    }
    /**
     * 查询H5模块包列表
     */
    @GetMapping("/qurey/list")
    public AjaxResult queryByCore(ModuleListByCoreRequest request)
    {
        if(StringUtils.isEmpty(request.getAppCore())){
            return error("appCore不能为空");
        }
        DeploymentModuleList deploymentModuleList = new DeploymentModuleList();
        deploymentModuleList.setAppCore(request.getAppCore());
        deploymentModuleList.setSysType(request.getSysType());
        List<DeploymentModuleList> list = deploymentModuleListService.selectDeploymentModuleListList(deploymentModuleList);
        return success(list);
    }

    /**
     * 导出H5模块包列表
     */
    @PreAuthorize("@ss.hasPermi('deployment:module:export')")
    @Log(title = "H5模块包", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeploymentModuleList deploymentModuleList)
    {
        List<DeploymentModuleList> list = deploymentModuleListService.selectDeploymentModuleListList(deploymentModuleList);
        ExcelUtil<DeploymentModuleList> util = new ExcelUtil<DeploymentModuleList>(DeploymentModuleList.class);
        util.exportExcel(response, list, "H5模块包数据");
    }

    /**
     * 获取H5模块包详细信息
     */
    @PreAuthorize("@ss.hasPermi('deployment:module:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deploymentModuleListService.selectDeploymentModuleListById(id));
    }

    /**
     * 新增H5模块包
     */
    @PreAuthorize("@ss.hasPermi('deployment:module:add')")
    @Log(title = "H5模块包", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeploymentModuleList deploymentModuleList)
    {
        return toAjax(deploymentModuleListService.insertDeploymentModuleList(deploymentModuleList));
    }

    /**
     * 修改H5模块包
     */
    @PreAuthorize("@ss.hasPermi('deployment:module:edit')")
    @Log(title = "H5模块包", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeploymentModuleList deploymentModuleList)
    {
        return toAjax(deploymentModuleListService.updateDeploymentModuleList(deploymentModuleList));
    }

    /**
     * 删除H5模块包
     */
    @PreAuthorize("@ss.hasPermi('deployment:module:remove')")
    @Log(title = "H5模块包", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deploymentModuleListService.deleteDeploymentModuleListByIds(ids));
    }
}
