package org.security.trans.app.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.security.trans.app.dto.AppDeviceCheckDTO;
import org.security.trans.app.service.IAppDeviceService;
import org.security.trans.app.service.IAppService;
import org.security.trans.app.service.IAppEducateService;
import org.security.trans.app.vo.AppDeviceCheckItemVO;
import org.security.trans.app.vo.BacklogVO;
import org.security.trans.app.vo.AppDeviceVO;
import org.security.trans.app.vo.TaskHandInVO;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.text.ParseException;
import java.util.List;

/**
 * @author Create by wzf
 * @date 2022/4/20 9:47
 */
@RestController
@AllArgsConstructor
@RequestMapping("/app")
@Api(value = "app端接口", tags = "app端接口")
public class AppController extends BladeController {
	private final IAppService appService;
	private final IAppDeviceService appDeviceService;
	private final IAppEducateService appEducateService;

	@ApiOperation(value = "根据当前用户查询待办")
	@ApiOperationSupport(order = 0)
	@ApiImplicitParams({
		@ApiImplicitParam(name = "type", value = "默认为空，查询前十条，all-查询全部", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "dataType", value = "默认为空，查询应急演练、教育培训、设备检查、设备整改的待办信息；1-教育培训待办信息、2-应急演练待办信息、" +
			"3-设备检查待办信息、4-设备整改待办信息、5-设备持续整改代办信息", paramType = "query", dataType = "string")
	})
	@GetMapping("/backlog")
	public R<List<BacklogVO>> backlog(@RequestParam(required = false) String type,@RequestParam(required = false) String dataType) {
		return R.data(appService.backlog(type,dataType));
	}

	@ApiOperation(value = "获取设备检查代办事项详情")
	@ApiOperationSupport(order = 2)
	@GetMapping("/device/{id}")
	public R<AppDeviceVO> getDeviceDetail(@PathVariable String id) {
		return R.data(appDeviceService.getDetail(id));
	}

	@ApiOperation(value = "获取教育培训和应急演练代办事项详情")
	@ApiOperationSupport(order = 3)
	@GetMapping("/{id}")
	public R<TaskHandInVO> getDetail(@PathVariable String id) {
		return R.data(appEducateService.getOtherDetail(id));
	}

	@ApiOperation(value = "教育培训和应急演练代办事项提报")
	@ApiOperationSupport(order = 4)
	@PostMapping("/handIn")
	public R handInDetail(String id, List<MultipartFile> imgUrl) throws ParseException {
		return R.status(appEducateService.handInDetail(id,imgUrl));
	}

	@ApiOperation(value = "获取设备检查/整改明细项详情")
	@ApiOperationSupport(order = 5)
	@ApiImplicitParams({
		@ApiImplicitParam(name = "id", value = "id", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "type", value = "请求数据类型：1-设备检查待办数据，2-设备整改待办数据，3-设备持续整改数据", paramType = "query", dataType = "string")
	})
	@GetMapping("/device/item")
	public R<List<AppDeviceCheckItemVO>> getDeviceItemDetail(@RequestParam String id,@RequestParam String type) {
		return R.data(appDeviceService.getDeviceItemDetail(id,type));
	}

	@ApiOperation(value = "设备检查提报")
	@ApiOperationSupport(order = 6)
	@PostMapping("/device/handIn")
	public R handInDevice(@Valid @RequestBody AppDeviceCheckDTO appDeviceCheckDTO){
		return R.status(appDeviceService.handInDevice(appDeviceCheckDTO));
	}

	@ApiOperation(value = "获取设备整改待办详情")
	@ApiOperationSupport(order = 7)
	@GetMapping("/device/rectify/{id}")
	public R<AppDeviceVO> getDeviceRectifyDetail(@PathVariable String id) {
		return R.data(appDeviceService.getDeviceRectifyDetail(id));
	}

	@ApiOperation(value = "设备整改提报")
	@ApiOperationSupport(order = 8)
	@PostMapping("/device/rectify")
	public R rectifyDevice(@Valid @RequestBody AppDeviceCheckDTO appDeviceCheckDTO){
		return R.status(appDeviceService.rectifyDevice(appDeviceCheckDTO));
	}

	@ApiOperation(value = "获取设备持续整改待办详情")
	@ApiOperationSupport(order = 9)
	@GetMapping("/continued/rectify/{id}")
	public R<AppDeviceVO> getContinuedRectifyDetail(@PathVariable String id) {
		return R.data(appDeviceService.getContinuedRectifyDetail(id));
	}

	@ApiOperation(value = "设备持续整改提报")
	@ApiOperationSupport(order = 10)
	@PostMapping("/continued/rectify/handIn")
	public R continuedRectifyHandIn(@Valid @RequestBody AppDeviceCheckDTO appDeviceCheckDTO){
		return R.status(appDeviceService.continuedRectifyHandIn(appDeviceCheckDTO));
	}
}
