package com.hotent.uc.controller;

import com.hotent.base.annotation.ApiGroup;
import com.hotent.base.constants.ApiGroupConsts;
import com.hotent.base.controller.BaseController;
import com.hotent.base.controller.BaseController2;
import com.hotent.base.model.CommonResult;
import com.hotent.base.util.StringUtil;
import com.hotent.uc.manager.ShiftRuleManager;
import com.hotent.uc.manager.ShiftUserManager;
import com.hotent.uc.model.ShiftRule;
import com.hotent.uc.model.ShiftUser;
import com.hotent.uc.params.user.DurationParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 
 * <pre> 
 * 描述：轮班规则 控制器类
 * 构建组：x7
 * 作者:qiuxd
 * 邮箱:qiuxd@jee-soft.cn
 * 日期:2020-08-04 16:07:34
 * 版权：广州宏天软件股份有限公司
 * </pre>
 */
@RestController
@RequestMapping(value="/uc/shiftRule/v2")
@Api(tags="shiftRuleController2")
@ApiGroup(group= {ApiGroupConsts.GROUP_UC})
public class ShiftRuleController2 extends BaseController2<ShiftRuleManager,ShiftRule> {
	@Resource
	ShiftRuleManager shiftRuleManager;
	@Resource
	ShiftUserManager shiftUserManager;
	


	@PostMapping(value="/saveShiftUser")
	@ApiOperation(value = "保存排班人员", httpMethod = "POST", notes = "保存排班人员")
	public CommonResult<String> saveShiftUser(@RequestBody List<ShiftUser> shiftUsers){
		shiftUserManager.saveShiftUser(shiftUsers);
		return CommonResult.<String>ok().message("保存成功");
	}

	@DeleteMapping(value="/removeShiftUser")
	@ApiOperation(value = "批量删除轮班规则记录", httpMethod = "DELETE", notes = "批量删除轮班规则记录")
	public CommonResult<String> removeShiftUser(@ApiParam(name="ids",value="业务主键数组,多个业务主键之间用逗号分隔", required = true)@RequestParam String...ids) throws Exception{
		shiftUserManager.removeByUserIds(ids);
		return CommonResult.<String>ok().message("删除成功");
	}

	@GetMapping(value="/computeSendDate", produces = {"application/json; charset=utf-8" })
	@ApiOperation(value = "计算发送时间", httpMethod = "GET", notes = "计算发送时间")
	public CommonResult<Long> computeSendDate(@RequestParam(value="userId") String userId,@RequestParam(value="minute") long minute) throws Exception{
		long date = shiftRuleManager.computeSendDate(userId, minute);
		return CommonResult.<Long>ok().value(date);
	}

	@PostMapping(value="/computeDuration", produces = {"application/json; charset=utf-8" })
	@ApiOperation(value = "计算发送时间", httpMethod = "GET", notes = "计算发送时间")
	public CommonResult<Long> computeDuration(@RequestParam(value="userId") String userId, @RequestBody DurationParam param) throws Exception{
		long date = shiftRuleManager.computeDuration(userId, param.getStartDate(), param.getEndDate());
		return CommonResult.<Long>ok().value(date);

	}
}
