package com.zd.laboratory.controller.controller;

import java.util.HashMap;
import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.zd.common.core.domain.R;
import com.zd.common.core.domain.per.PerFun;
import com.zd.common.core.domain.per.PerPrefix;
import com.zd.common.core.web.domain.ResultData;
import com.zd.laboratory.domain.LabViolationScoreSite;
import com.zd.laboratory.service.ILabViolationScoreSiteService;
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.zd.common.log.annotation.Log;
import com.zd.common.log.enums.BusinessType;
import com.zd.common.security.annotation.PreAuthorize;
import com.zd.laboratory.domain.LabViolationSite;
import com.zd.laboratory.service.ILabViolationSiteService;
import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.web.domain.AjaxResult;
import com.zd.common.core.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.zd.common.swagger.config.Knife4jConfiguration;

import com.zd.common.core.web.page.TableDataInfo;

/**
 * 违规-违规处理方式设置Controller
 *
 * @author zd
 * @date 2021-12-13
 */
@RestController
@Api(tags = "【违规-处理方式设置】")
//作者手动加入 ，在接口上加作者@ApiOperationSupport(author = "XXX")

@RequestMapping("/violationSite")
public class LabViolationSiteController extends BaseController
{
    @Autowired
    private ILabViolationSiteService labViolationSiteService;

    @Autowired
    private ILabViolationScoreSiteService labViolationScoreSiteService;

    /**
     * 查询违规-处理方式设置列表
     */

    @GetMapping("/list")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SITE + PerFun.LIST)
    @ApiOperation(value = "查询违规-处理方式设置列表")
    public R list()
    {
       Map result  = new HashMap();
        List<LabViolationSite> list = labViolationSiteService.selectLabViolationSite();
        List<LabViolationScoreSite> scoreSite = labViolationScoreSiteService.selectLabViolationScore();
        result.put("violationType",list);
        result.put("violationMeth",scoreSite);
        result.put("remake",list.size()>0? list.get(0).getRemake():"0");
        return R.ok(result);
    }

    /**
     * 导出违规-违规项设置列表
     */
    @ApiOperation(value = "导出违规-处理方式设置列表")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SITE + PerFun.EXPORT)
    @Log(title = "违规-违���项设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LabViolationSite labViolationSite) throws IOException
    {
        List<LabViolationSite> list = labViolationSiteService.selectLabViolationSiteList(labViolationSite);
        ExcelUtil<LabViolationSite> util = new ExcelUtil<LabViolationSite>(LabViolationSite.class);
        util.exportExcel(response, list, "违规-违���项设置数据");
    }

    /**
     * 获取违规-违规处理方式详细信息
     */
    @ApiOperation(value = "获取违规-违规处理方式详细信息")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SITE + PerFun.QUERY)
    @GetMapping(value = "/{id}")
    public ResultData<LabViolationSite> getInfo(@PathVariable("id") Long id)
    {
        return ResultData.success(labViolationSiteService.selectLabViolationSiteById(id));
    }

    /**
     * 新增违规-违规项设置
     */
    @ApiOperation(value = "新增违规-违规处理方式设置,多个值用,号隔开")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SITE + PerFun.ADD)
    @Log(title = "违规-违规项设置", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultData add(@RequestBody Map obj)
    {
        return ResultData.result(labViolationSiteService.insertLabViolationSite(obj));
    }

    /**
     * 修改违规-违规项设置
     */
    @ApiOperation(value = "修改违规-处理方式设置")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SITE + PerFun.EDIT)
    @Log(title = "违规-违规项设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultData edit(@RequestBody LabViolationSite labViolationSite)
    {
        return  ResultData.result(labViolationSiteService.updateLabViolationSite(labViolationSite));
    }

    /**
     * 删除违规-违规项设置
     */
    @ApiOperation(value = "删除违规-处理方式设置")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SITE + PerFun.REMOVE)
    @Log(title = "违规-违规项设置", businessType = BusinessType.DELETE)
	@PostMapping("/del")
    public ResultData remove(@RequestBody Map obj)
    {
        return ResultData.result(labViolationSiteService.removeIds(obj));
    }



    @ApiOperation(value = "违规-违规项")
    @GetMapping("/type")
    public R type(){
        List<LabViolationScoreSite> scoreSite = labViolationScoreSiteService.selectLabViolationScore();
        return R.ok(scoreSite);
    }







}
