package com.aegis.web.controller.emergency.duty;

import java.util.List;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
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;
import com.aegis.common.annotation.Log;
import com.aegis.common.core.controller.BaseController;
import com.aegis.common.core.domain.AjaxResult;
import com.aegis.common.core.page.TableDataInfo;
import com.aegis.common.enums.BusinessType;
import com.aegis.emergency.duty.domain.DutyShiftMember;
import com.aegis.emergency.duty.service.DutyShiftMemberService;

/**
 * 排班成员Controller
 * 
 * @author aegis
 */
@RestController
@RequestMapping("/duty/shift-members")
public class DutyShiftMemberController extends BaseController {

    @Autowired
    private DutyShiftMemberService dutyShiftMemberService;

    /**
     * 查询排班成员列表
     */
    @PreAuthorize("@ss.hasPermi('duty:shift:member:list')")
    @GetMapping("/list")
    public TableDataInfo list(DutyShiftMember condition) {
        startPage();
        List<DutyShiftMember> list = dutyShiftMemberService.listByCondition(condition);
        return getDataTable(list);
    }

    /**
     * 根据排班ID查询成员列表
     */
    @PreAuthorize("@ss.hasPermi('duty:shift:member:list')")
    @GetMapping("/shift/{shiftId}")
    public AjaxResult listByShiftId(@PathVariable Long shiftId) {
        DutyShiftMember condition = new DutyShiftMember();
        condition.setShiftId(shiftId);
        List<DutyShiftMember> list = dutyShiftMemberService.listByCondition(condition);
        return success(list);
    }

    /**
     * 根据ID查询排班成员
     */
    @PreAuthorize("@ss.hasPermi('duty:shift:member:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(dutyShiftMemberService.getById(id));
    }

    /**
     * 新增排班成员
     */
    @PreAuthorize("@ss.hasPermi('duty:shift:member:add')")
    @Log(title = "排班成员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DutyShiftMember member) {
        return toAjax(dutyShiftMemberService.save(member));
    }

    /**
     * 修改排班成员
     */
    @PreAuthorize("@ss.hasPermi('duty:shift:member:edit')")
    @Log(title = "排班成员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DutyShiftMember member) {
        return toAjax(dutyShiftMemberService.updateById(member));
    }

    /**
     * 删除排班成员
     */
    @PreAuthorize("@ss.hasPermi('duty:shift:member:remove')")
    @Log(title = "排班成员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(dutyShiftMemberService.removeByIds(Arrays.asList(ids)));
    }
}