package com.yeejoin.amos.boot.module.tzs.biz.controller;

import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.tzs.api.dto.DispatchConsultFeedbackDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.DispatchPaperDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.DispatchPaperFormDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.DispatchRepairFeedbackDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.DispatchSaveFeedbackDto;
import com.yeejoin.amos.boot.module.tzs.api.entity.DispatchPaper;
import com.yeejoin.amos.boot.module.tzs.biz.service.impl.DispatchPaperServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
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 org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;

/**
 * 派遣单
 *
 * @author system_generator
 * @date 2021-08-03
 */
@RestController
@Api(tags = "派遣单Api")
@RequestMapping(value = "/tzs/dispatch-paper")
public class DispatchPaperController extends BaseController {

    @Autowired
    DispatchPaperServiceImpl dispatchPaperServiceImpl;

	@Autowired
	RedisUtils redisUtils;

	/**
	 * 通过警情id 获取 救援回访相关信息
	 * @param alertId
	 * @return
	 */
	@TycloudOperation(ApiLevel = UserType.AGENCY)
	@GetMapping(value = "/feedback/save/{alertId}")
	@ApiOperation(httpMethod = "GET", value = "通过警情id 获取 救援回访相关信息", notes = "通过警情id 获取 救援回访相关信息")
	public ResponseModel<DispatchSaveFeedbackDto> getSaveFeedback(@PathVariable Long alertId) {

		DispatchSaveFeedbackDto dispatchSaveFeedbackDto = dispatchPaperServiceImpl.getDispatchSaveFeedbackDtoByAlertId(alertId);
		return ResponseHelper.buildResponse(dispatchSaveFeedbackDto);
	}

	/**
	 * 保存救援回访信息
	 * @param dispatchSaveFeedbackDto
	 * @return
	 */
	@TycloudOperation(ApiLevel = UserType.AGENCY)
	@PostMapping(value = "/feedback/save")
	@ApiOperation(httpMethod = "POST", value = "保存救援回访信息", notes = "保存救援回访信息")
	public ResponseModel<Boolean> saveSaveFeedBack(@RequestBody DispatchSaveFeedbackDto dispatchSaveFeedbackDto) {
		if (ValidationUtil.isEmpty(dispatchSaveFeedbackDto)
				|| ValidationUtil.isEmpty(dispatchSaveFeedbackDto.getAlertId()))
			throw new BadRequest("参数校验失败.");
	    return ResponseHelper.buildResponse(dispatchPaperServiceImpl.saveDispatchSaveFeedback(dispatchSaveFeedbackDto,getSelectedOrgInfo().getUserModel()));
	}

	/**
	 * 通过警情id 获取 维修回访相关信息
	 * @param alertId
	 * @return
	 */
	@TycloudOperation(ApiLevel = UserType.AGENCY)
	@GetMapping(value = "/feedback/repair/{alertId}")
	@ApiOperation(httpMethod = "GET", value = "通过警情id 获取 维修回访相关信息", notes = "通过警情id 获取 维修回访相关信息")
	public ResponseModel<DispatchRepairFeedbackDto> getRepairFeedBack(@PathVariable Long alertId) {

		DispatchRepairFeedbackDto dispatchRepairFeedbackDto = dispatchPaperServiceImpl.getDispatchRepairFeedbackDtoByAlertId(alertId);
		return ResponseHelper.buildResponse(dispatchRepairFeedbackDto);
	}

	/**
	 * 保存维修回访信息
	 * @param dispatchRepairFeedbackDto
	 * @return
	 */
	@TycloudOperation(ApiLevel = UserType.AGENCY)
	@PostMapping(value = "/feedback/repair")
	@ApiOperation(httpMethod = "POST", value = "保存维修回访信息", notes = "保存维修回访信息")
	public ResponseModel<Boolean> saveRepairFeedBack(@RequestBody DispatchRepairFeedbackDto dispatchRepairFeedbackDto) {
		if (ValidationUtil.isEmpty(dispatchRepairFeedbackDto)
				|| ValidationUtil.isEmpty(dispatchRepairFeedbackDto.getAlertId()))
			throw new BadRequest("参数校验失败.");
		return ResponseHelper.buildResponse(dispatchPaperServiceImpl.saveDispatchRepairFeedback(dispatchRepairFeedbackDto,getSelectedOrgInfo().getUserModel()));
	}

	/**
	 * 通过警情id 获取 投诉回访相关信息
	 * @param alertId
	 * @return
	 */
	@TycloudOperation(ApiLevel = UserType.AGENCY)
	@GetMapping(value = "/feedback/consult/{alertId}")
	@ApiOperation(httpMethod = "GET", value = "通过警情id 获取 投诉回访相关信息", notes = "通过警情id 获取 投诉回访相关信息")
	public ResponseModel<DispatchConsultFeedbackDto> getConsultFeedBack(@PathVariable Long alertId) {
		DispatchConsultFeedbackDto dispatchConsultFeedbackDto = dispatchPaperServiceImpl.getDispatchConsultFeedbackDtoByAlertId(alertId);
		return ResponseHelper.buildResponse(dispatchConsultFeedbackDto);
	}

	/**
	 * 保存投诉回访信息
	 * @param dispatchConsultFeedbackDto
	 * @return
	 */
	@TycloudOperation(ApiLevel = UserType.AGENCY)
	@PostMapping(value = "/feedback/consult")
	@ApiOperation(httpMethod = "POST", value = "保存投诉回访信息", notes = "保存投诉回访信息")
	public ResponseModel<Boolean> saveConsultFeedBack(@RequestBody DispatchConsultFeedbackDto dispatchConsultFeedbackDto) {
		if (ValidationUtil.isEmpty(dispatchConsultFeedbackDto)
				|| ValidationUtil.isEmpty(dispatchConsultFeedbackDto.getAlertId()))
			throw new BadRequest("参数校验失败.");
		return ResponseHelper.buildResponse(dispatchPaperServiceImpl.saveDispatchConsultFeedback(dispatchConsultFeedbackDto,getSelectedOrgInfo().getUserModel()));
	}

	/**
	 * 根据警情id查询
	 *
	 * @param id
	 * @return
	 */
	@TycloudOperation(needAuth = true, ApiLevel = UserType.AGENCY)
	@GetMapping(value = "/alert/{id}")
	@ApiOperation(httpMethod = "GET", value = "根据警情id查询", notes = "根据警情id查询")
	public ResponseModel<Object> selectById(@PathVariable Long id) {

		return ResponseHelper.buildResponse(dispatchPaperServiceImpl.selectDispatchPaperDtoByAlertId(id));

	}



	/**
     * 根据sequenceNbr更新
     *
     * @param sequenceNbr 主键
     * @return
     */
	@TycloudOperation(ApiLevel = UserType.AGENCY)
	@PutMapping(value = "/{sequenceNbr}")
	@ApiOperation(httpMethod = "PUT", value = "根据sequenceNbr更新派遣单", notes = "根据sequenceNbr更新派遣单")
	public ResponseModel<DispatchPaperDto> updateBySequenceNbrDispatchPaper(@RequestBody DispatchPaperDto model,@PathVariable(value = "sequenceNbr") Long sequenceNbr) {
	    model.setSequenceNbr(sequenceNbr);
	    return ResponseHelper.buildResponse(dispatchPaperServiceImpl.updateWithModel(model));
	}




}
