package com.xinelu.manage.controller.projectgroup;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.domain.R;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.projectgroup.ProjectGroup;
import com.xinelu.manage.dto.projectgroup.ProjectGroupSaveListDto;
import com.xinelu.manage.service.projectgroup.IProjectGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
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.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 检测项目分组Controller
 *
 * @author haown
 * @date 2024-03-11
 */
@Api(tags = "检测项目分组控制器")
@RestController
@RequestMapping("/manage/projectgroup")
public class ProjectGroupController extends BaseController {
    @Resource
    private IProjectGroupService projectGroupService;

	/**
	 * 查询检测项目分组列表
	 */
	@ApiOperation("分页查询检测项目分组列表")
	@PreAuthorize("@ss.hasPermi('manage:projectgroup:list')")
	@GetMapping("/list")
    public TableDataInfo list(ProjectGroup projectGroup) {
        startPage();
        List<ProjectGroup> list = projectGroupService.selectProjectGroupList(projectGroup);
        return getDataTable(list);
    }

	/**
	 * 查询检测项目分组列表
	 */
	@ApiOperation("查询检测项目分组列表")
	@PreAuthorize("@ss.hasPermi('manage:projectgroup:list')")
	@GetMapping("/getList")
	public R<List<ProjectGroup>> getList(ProjectGroup projectGroup) {
		List<ProjectGroup> list = projectGroupService.selectProjectGroupList(projectGroup);
		return R.ok(list);
	}

    /**
     * 导出检测项目分组列表
     */
    @PreAuthorize("@ss.hasPermi('manage:projectgroup:export')")
    @Log(title = "检测项目分组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectGroup projectGroup) {
        List<ProjectGroup> list = projectGroupService.selectProjectGroupList(projectGroup);
        ExcelUtil<ProjectGroup> util = new ExcelUtil<ProjectGroup>(ProjectGroup. class);
        util.exportExcel(response, list, "检测项目分组数据");
    }

    /**
     * 获取检测项目分组详细信息
     */
    @ApiOperation("根据id获取检测项目分组详细信息")
    @PreAuthorize("@ss.hasPermi('manage:projectgroup:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(projectGroupService.selectProjectGroupById(id));
    }

    /**
     * 新增检测项目分组
     */
	@ApiOperation("新增检测项目分组")
    @PreAuthorize("@ss.hasPermi('manage:projectgroup:add')")
    @Log(title = "检测项目分组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectGroup projectGroup) {
        return toAjax(projectGroupService.insertProjectGroup(projectGroup));
    }

	/**
	 * 新增检测项目分组
	 */
	@ApiOperation("批量新增检测项目分组")
	@PreAuthorize("@ss.hasPermi('manage:projectgroup:add')")
	@Log(title = "检测项目分组", businessType = BusinessType.INSERT)
	@PostMapping("addList")
	public R<String> addList(@RequestBody ProjectGroupSaveListDto saveDto) {
		int flag = projectGroupService.insertList(saveDto);
		return flag > 0 ? R.ok() : R.fail();
	}

    /**
     * 修改检测项目分组
     */
    @ApiOperation("修改检测项目分组")
    @PreAuthorize("@ss.hasPermi('manage:projectgroup:edit')")
    @Log(title = "检测项目分组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectGroup projectGroup) {
        return toAjax(projectGroupService.updateProjectGroup(projectGroup));
    }

    /**
     * 删除检测项目分组
     */
    @ApiOperation("删除检测项目分组")
    @PreAuthorize("@ss.hasPermi('manage:projectgroup:remove')")
    @Log(title = "检测项目分组", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(projectGroupService.deleteProjectGroupByIds(ids));
    }
}
