package com.xinelu.manage.controller.specialdiseasetriggercondition;

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.specialdiseasetriggercondition.SpecialDiseaseTriggerCondition;
import com.xinelu.manage.dto.specialdiseasetriggercondition.TriggerConditionSaveDTO;
import com.xinelu.manage.dto.specialdiseasetriggercondition.TriggerConditionUpdateDto;
import com.xinelu.manage.service.specialdiseasetriggercondition.ISpecialDiseaseTriggerConditionService;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
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 xinelu
 * @date 2024-03-18
 */
@RestController
@RequestMapping("/system/triggerCondition")
public class SpecialDiseaseTriggerConditionController extends BaseController {
    @Resource
    private ISpecialDiseaseTriggerConditionService specialDiseaseTriggerConditionService;

    /**
     * 查询触发条件关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:triggerCondition:list')")
    @GetMapping("/list")
    public TableDataInfo list(SpecialDiseaseTriggerCondition specialDiseaseTriggerCondition) {
        startPage();
        List<SpecialDiseaseTriggerCondition> list = specialDiseaseTriggerConditionService.selectSpecialDiseaseTriggerConditionList(specialDiseaseTriggerCondition);
        return getDataTable(list);
    }

    /**
     * 查询触发条件关系列表
     */
    @GetMapping("/triggerConditionList")
    public AjaxResult triggerConditionList(SpecialDiseaseTriggerCondition specialDiseaseTriggerCondition) {
        if (Objects.isNull(specialDiseaseTriggerCondition) || Objects.isNull(specialDiseaseTriggerCondition.getRouteId())) {
            return AjaxResult.success(new ArrayList<>());
        }
        return AjaxResult.success(specialDiseaseTriggerConditionService.selectSpecialDiseaseTriggerConditionList(specialDiseaseTriggerCondition));
    }

    /**
     * 导出触发条件关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:triggerCondition:export')")
    @Log(title = "触发条件关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SpecialDiseaseTriggerCondition specialDiseaseTriggerCondition) {
        List<SpecialDiseaseTriggerCondition> list = specialDiseaseTriggerConditionService.selectSpecialDiseaseTriggerConditionList(specialDiseaseTriggerCondition);
        ExcelUtil<SpecialDiseaseTriggerCondition> util = new ExcelUtil<SpecialDiseaseTriggerCondition>(SpecialDiseaseTriggerCondition.class);
        util.exportExcel(response, list, "触发条件关系数据");
    }

    /**
     * 获取触发条件关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:triggerCondition:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(specialDiseaseTriggerConditionService.selectSpecialDiseaseTriggerConditionById(id));
    }

    /**
     * 新增触发条件关系
     */
    @PreAuthorize("@ss.hasPermi('system:triggerCondition:add')")
    @Log(title = "触发条件关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TriggerConditionSaveDTO triggerConditionSaveDTO) {
        return toAjax(specialDiseaseTriggerConditionService.insertSpecialDiseaseTriggerCondition(triggerConditionSaveDTO));
    }

	/**
     * 修改触发条件关系
     */
    @PreAuthorize("@ss.hasPermi('system:triggerCondition:edit')")
    @Log(title = "触发条件关系", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public R<String> edit(@RequestBody TriggerConditionUpdateDto triggerConditionUpdateDto) {
        return R.ok(specialDiseaseTriggerConditionService.updateSpecialDiseaseTriggerCondition(triggerConditionUpdateDto));
    }

    /**
     * 删除触发条件关系
     */
    @PreAuthorize("@ss.hasPermi('system:triggerCondition:remove')")
    @Log(title = "触发条件关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(specialDiseaseTriggerConditionService.deleteSpecialDiseaseTriggerConditionByIds(ids));
    }
}
