package com.artfess.rescue.patrol.controller;


import com.artfess.base.annotation.ApiGroup;
import com.artfess.base.constants.ApiGroupConsts;
import com.artfess.base.controller.BaseController;
import com.artfess.base.model.CommonResult;
import com.artfess.base.util.StringUtil;
import com.artfess.rescue.monitor.manager.BizRankUserManager;
import com.artfess.rescue.monitor.model.BizRankUser;
import com.artfess.rescue.monitor.vo.RankUserVo;
import com.artfess.rescue.patrol.manager.BizInspectRankUserManager;
import com.artfess.rescue.patrol.model.BizInspectRankUser;
import com.artfess.rescue.patrol.vo.InspectRankUserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.docx4j.wml.R;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

/**
 * 排班人员 前端控制器
 *
 * @company 阿特菲斯信息技术有限公司
 * @author 管理员
 * @since 2023-11-30
 */

@RestController
@RequestMapping("/bizInspectRankUser/v1/")
@Api(tags = "排班管理")
@ApiGroup(group = {ApiGroupConsts.GROUP_BIZ_RESCUE})
public class BizInspectRankUserController extends BaseController<BizInspectRankUserManager, BizInspectRankUser> {

    @GetMapping("/findMonthArrangeInfo")
    @ApiOperation(value = "查询某月的排班信息")
    public List<InspectRankUserVo> findMonthArrangeInfo(@ApiParam(name = "queryDate", value = "查询某一个月的开始日期", required = true) @RequestParam(value = "queryDate", required = true) String queryDate,
                                                        @ApiParam(name = "orgId", value = "监控中心ID", required = true) @RequestParam(value = "orgId", required = true) String orgId,
                                                        @ApiParam(name = "rankGroupId", value = "班组id") @RequestParam(value = "rankGroupId", required = false) String rankGroupId) {

       return baseService.findMonthArrangeInfo(queryDate,orgId,rankGroupId);
    }

    @PostMapping(value = "/import")
    @ApiOperation(value = "S-导入排班管理信息", httpMethod = "POST", notes = "导入排班管理信息")
    public CommonResult importRankUsers(@ApiParam(name = "file", value = "excel模板文件", required = true)MultipartFile file,
                                        @ApiParam(name = "orgId", value = "监控中心ID", required = true)String orgId) {
        return baseService.importRankUsers(file, orgId);
    }

    @PostMapping(value = "/save")
    @ApiOperation(value = "S-新增,更新排班管理信息", httpMethod = "POST", notes = "新增,更新排班管理信息")
    public CommonResult<String> save(@ApiParam(name = "BizRankUser", value = "收费站排班管理信息对象", required = true) @RequestBody BizInspectRankUser rankUser) throws Exception {
        String msg = "添加成功";
        if (StringUtil.isEmpty(String.valueOf(rankUser.getId()))) {
            rankUser.setIsDele("0");
            baseService.save(rankUser);
        } else {
            baseService.update(rankUser);
            rankUser.setIsDele("0");
            msg = "更新成功";
        }
        return new CommonResult<>(msg);
    }



    @PostMapping(value = "/saveList")
    @ApiOperation(value = "S-批量新增,更新排班管理信息", httpMethod = "POST", notes = "新增,更新排班管理信息")
    public CommonResult<String> saveList(@ApiParam(name = "rankUsers", value = "收费站排班管理信息对象", required = true) @RequestBody List<BizInspectRankUser> rankUsers) throws Exception {
        String msg = "添加成功";
        for (BizInspectRankUser rankUser : rankUsers) {
            if (StringUtil.isEmpty(String.valueOf(rankUser.getId()))) {
                rankUser.setIsDele("0");
                baseService.save(rankUser);
            } else {
                baseService.update(rankUser);
                msg = "更新成功";
            }
        }
        return new CommonResult<>(msg);
    }


    @PostMapping(value = "/get/{id}")
    @ApiOperation(value = "S-排班管理详情", httpMethod = "POST", notes = "排班管理详情")
    public BizInspectRankUser get(@ApiParam(name = "id", value = "业务对象主键", required = true) @PathVariable String id) throws Exception {
        return baseService.get(id);
    }



    @PostMapping(value = "/removes")
    @ApiOperation(value = "S-批量删除", httpMethod = "POST", notes = "批量删除")
    public CommonResult<String> removes(@ApiParam(name = "ids", value = "多个主键之间用逗号分隔", required = true) @RequestParam String ids) throws Exception {
        List<String> rankIds = Arrays.asList(ids);

        baseService.removeByIds(rankIds);
        return new CommonResult<String>(true, "删除成功");
    }


}
