package com.fs.his.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.domain.R;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.his.domain.FsPromotionalActive;
import com.fs.his.dto.FsPromotionalActiveDTO;
import com.fs.his.service.IFsPromotionalActiveService;
import com.fs.his.vo.FsPromotionalActiveVO;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 宣传活动控制类
 */
@RestController
@RequestMapping("/his/promotionActive")
@AllArgsConstructor
public class FsPromotionalActiveController extends BaseController {

    private final IFsPromotionalActiveService fsPromotionalActiveService;

    @PreAuthorize("@ss.hasPermi('his:promotionActive:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsPromotionalActive active) {
        startPage();
        List<FsPromotionalActiveVO> list = fsPromotionalActiveService.selectPromotionalActiveVOList(active);
        return getDataTable(list);
    }

    @GetMapping(value = "/{activeId}")
    public AjaxResult getInfo(@PathVariable Long activeId) {
        return AjaxResult.success(fsPromotionalActiveService.selectPromotionalActiveVOById(activeId));
    }

    @PreAuthorize("@ss.hasPermi('his:promotionActive:add')")
    @Log(title = "宣传活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody FsPromotionalActiveDTO param) {
        fsPromotionalActiveService.addPromotionalActive(param);
        return AjaxResult.success();
    }

    @PreAuthorize("@ss.hasPermi('his:promotionActive:edit')")
    @Log(title = "宣传活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody FsPromotionalActiveDTO param) {
        fsPromotionalActiveService.editPromotionalActive(param);
        return AjaxResult.success();
    }

    @PreAuthorize("@ss.hasPermi('his:promotionActive:remove')")
    @Log(title = "宣传活动", businessType = BusinessType.DELETE)
    @DeleteMapping("/{activeIds}")
    public AjaxResult remove(@PathVariable Long[] activeIds) {
        fsPromotionalActiveService.logicalRemove(activeIds);
        return AjaxResult.success();
    }

    @GetMapping("/getPromotionalActiveOption")
    public R getPromotionalActiveOption() {
        return R.ok().put("list", fsPromotionalActiveService.getPromotionalActiveOption());
    }
}
