package com.diagbot.web;


import com.diagbot.annotation.SysLogger;
import com.diagbot.dto.QuestionShortDTO;
import com.diagbot.dto.RespDTO;
import com.diagbot.dto.VitalOrderDTO;
import com.diagbot.facade.VitalOrderFacade;
import com.diagbot.vo.VitalOrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 查体全局排序 前端控制器
 * </p>
 *
 * @author zhaops
 * @since 2018-11-22
 */
@RestController
@RequestMapping("/vitalOrder")
@SuppressWarnings("unchecked")
@Api(value = "查体排序相关API", tags = { "查体排序相关API" })
public class VitalOrderController {

    @Autowired
    private VitalOrderFacade vitalOrderFacade;

    @ApiOperation(value = "保存查体顺序-全部[by:zhaops]",
            notes = "vital:查体标签ID，必填<br>" +
                    "orderNo:查体排序号，必填<br>")
    @PostMapping("/saveAll")
    @SysLogger("saveAll")
    @Transactional
    public RespDTO<Boolean> saveAll(@RequestBody List<VitalOrderVO> vitalOrderVOList) {
        Boolean data = vitalOrderFacade.saveAll(vitalOrderVOList);
        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "获取查体排序[by:zhaops]")
    @PostMapping("/getVitalOrderList")
    @SysLogger("getVitalOrderList")
    public RespDTO<VitalOrderDTO> getVitalOrderList() {
        VitalOrderDTO data = vitalOrderFacade.getVitalOrderList();
        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "获取未排序查体标签-初始页面[by:zhaops]")
    @PostMapping("/getUnOrderedVitalList")
    @SysLogger("getUnOrderedVitalList")
    public RespDTO<QuestionShortDTO> getUnOrderedVitalList() {
        List<QuestionShortDTO> data = vitalOrderFacade.getUnOrderedVitalList();
        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "删除查体排序-单条[by:zhaops]",
            notes = "vitalId:查体标签ID，必填<br>")
    @PostMapping("/deleteVitalOrder")
    @SysLogger("deleteVitalOrder")
    @Transactional
    public RespDTO<Boolean> deleteVitalOrder(@RequestParam("vitalId") Long vitalId) {
        Boolean data = vitalOrderFacade.deleteVitalOrder(vitalId);
        return RespDTO.onSuc(data);
    }

    @ApiOperation(value = "删除查体排序-批量[by:zhaops]",
            notes = "vitalIds:查体标签ID，必填<br>")
    @PostMapping("/deleteVitalOrders")
    @SysLogger("deleteVitalOrders")
    @Transactional
    public RespDTO<Boolean> deleteVitalOrders(@RequestParam("vitalIds") Long[] vitalIds) {
        Boolean data = vitalOrderFacade.deleteVitalOrders(vitalIds);
        return RespDTO.onSuc(data);
    }
}