package cn.superdesk.uniorder.controller.operation;

import cn.superdesk.libs.common.json.JsonUtils;
import cn.superdesk.uniorder.common.pagination.PageQueryGenericParam;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.controller.base.BaseController;
import cn.superdesk.uniorder.dao.entity.operation.UnifiedOrderIssuesFlowing;
import cn.superdesk.uniorder.dto.param.operation.UnifiedOrderIssuesFlowingParam;
import cn.superdesk.uniorder.dto.param.operation.UnifiedOrderIssuesFlowingQueryCriteria;
import cn.superdesk.uniorder.dto.vo.operation.UnifiedOrderIssuesFlowingVo;
import cn.superdesk.uniorder.dubbo.consumer.operation.UnifiedOrderIssuesFlowingDubboConsumerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


/**
 * @Description: 问题订单-流水记录
 * @Author: linjinyu
 * @Email linjinyu@avic-s.com
 * @CreateDate: 2021-06-25 14:22:13
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021-06-25 14:22:13
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Api(value = "订单管理-订单问题-流水记录", tags = {"订单管理-订单问题-流水记录"})
@Slf4j
@RestController
@RequestMapping("/unifiedOrderIssuesFlowing")
public class UnifiedOrderIssuesFlowingController extends BaseController {

	@Autowired
	private UnifiedOrderIssuesFlowingDubboConsumerService unifiedOrderIssuesFlowingDubboConsumerService;

	@ApiOperation(value = "分页查询")
	@RequestMapping(value = "list", method = RequestMethod.POST)
	@ResponseBody
	public R<List<UnifiedOrderIssuesFlowingVo>> pageQueryUnifiedOrderIssuesFlowings(@RequestBody PageQueryGenericParam<UnifiedOrderIssuesFlowingQueryCriteria> param) {

		log.info("pageQueryUnifiedOrderIssuesFlowing:\n{}", JsonUtils.toJson(param));

		R<List<UnifiedOrderIssuesFlowingVo>> result = new R<>();

		// TODO 参数合法性判定

		result = unifiedOrderIssuesFlowingDubboConsumerService.pageQuery(param.getConditions(), param.getPageNo(), param.getPageSize());

		return result;
	}

	@ApiOperation(value = "按id查询")
	@RequestMapping(value = "{id}", method = RequestMethod.GET)
	@ResponseBody
	public R<List<UnifiedOrderIssuesFlowing>> getById(@PathVariable("id") long id) {

		R<List<UnifiedOrderIssuesFlowing>> result = new R<>();

		// TODO 参数合法性判定

		UnifiedOrderIssuesFlowing entity = unifiedOrderIssuesFlowingDubboConsumerService.findUnifiedOrderIssuesFlowingById(id);

		List<UnifiedOrderIssuesFlowing> data = new ArrayList<>();
		data.add(entity);

		result.setData(data);

		return result;
	}

	@ApiOperation(value = "新增")
	@RequestMapping(value = "add", method = RequestMethod.POST)
	@ResponseBody
	public R<String> addUnifiedOrderIssuesFlowing(@RequestBody UnifiedOrderIssuesFlowingParam param) {

		log.info("addUnifiedOrderIssuesFlowing:\n{}", JsonUtils.toJson(param));


		// TODO 参数合法性判定

		unifiedOrderIssuesFlowingDubboConsumerService.addUnifiedOrderIssuesFlowing(param);

		return new R<>("200", "操作成功", true);
	}

	@ApiOperation(value = "更新")
	@RequestMapping(value = "update", method = RequestMethod.POST)
	@ResponseBody
	public R<String> updateUnifiedOrderIssuesFlowing(@RequestBody UnifiedOrderIssuesFlowingParam param) {

		log.info("updateUnifiedOrderIssuesFlowing:\n{}", JsonUtils.toJson(param));

		unifiedOrderIssuesFlowingDubboConsumerService.updateUnifiedOrderIssuesFlowing(param);

		return new R<>("200", "操作成功", true);
	}

	@ApiOperation(value = "删除")
	@RequestMapping(value = "delete/{id}", method = RequestMethod.POST)
	@ResponseBody
	public R<String> deleteUnifiedOrderIssuesFlowing(@PathVariable("id") long id) {

		// TODO 参数合法性判定

		unifiedOrderIssuesFlowingDubboConsumerService.deleteUnifiedOrderIssuesFlowing(id);

		return new R<>("200", "操作成功", true);
	}

	@ApiOperation(value = "批量删除")
	@RequestMapping(value = "delete_ids", method = RequestMethod.POST)
	@ResponseBody
	public R<String> deleteIdsUnifiedOrderIssuesFlowing(@RequestParam(value = "ids") long[] ids) {

		log.info(JsonUtils.toJson(ids));

		for (long id : ids) {
			unifiedOrderIssuesFlowingDubboConsumerService.deleteUnifiedOrderIssuesFlowing(id);
		}

		return new R<>("200", "操作成功", true);

	}


}
