package com.prolog.rdc.tms.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.product.core.framework.controller.BaseController;
import com.prolog.rdc.tms.model.entity.SysCodeengineModel;
import com.prolog.rdc.tms.model.vo.SysCodeengineDeleteVO;
import com.prolog.rdc.tms.model.vo.SysCodeengineQueryVO;
import com.prolog.rdc.tms.model.vo.SysCodeengineSaveVO;
import com.prolog.rdc.tms.model.vo.SysCodeengineUpdateVO;
import com.prolog.rdc.tms.service.SysCodeengineService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 
 *
 * 号码管理器控制层
 *
 * @className :SysCodeengineController
 * @author :fanzw
 * @creationTime :2021/04/21
 * @description :
 * @modifier :fanzw
 * @modifyTime :2021/04/21
 * @reviseRemarks:
 *
 * @version :1.0.0
 *
 */
@Api(tags = "基础数据-号码管理器控制层")
@RestController
@RequestMapping("/codes")
public class SysCodeengineController extends BaseController {

	@Autowired
	private SysCodeengineService service;

	@UserLog("号码管理器分页查询")
	@ApiOperation(value = "号码管理器分页查询", notes = "号码管理器分页查询")
	@PostMapping("query")
	public RestMessage<Page<SysCodeengineModel>> listSysCodeengineExecute(@RequestBody SysCodeengineQueryVO sysCodeengineQueryVO) {
		try {
			Page<SysCodeengineModel> sysCodeengineModels = service.listSysCodeengineData(sysCodeengineQueryVO);
			return RestMessage.newInstance(true, "号码管理器分页查询成功", sysCodeengineModels);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("号码管理器新增")
	@ApiOperation(value = "号码管理器新增", notes = "号码管理器新增")
	@PostMapping("/create")
	public RestMessage<String> saveSysCodeengineExecute(@RequestBody SysCodeengineSaveVO sysCodeengineSaveVO) {
		try {
			service.saveSysCodeengineData(sysCodeengineSaveVO);
			return RestMessage.newInstance(true, "号码管理器新增成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("号码管理器修改")
	@ApiOperation(value = "号码管理器修改", notes = "号码管理器修改")
	@PostMapping("/update")
	public RestMessage<String> updateSysCodeengineExecute(@RequestBody SysCodeengineUpdateVO sysCodeengineUpdateVO) {
		try {
			service.updateSysCodeengineData(sysCodeengineUpdateVO);
			return RestMessage.newInstance(true, "号码管理器修改成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("号码管理器删除")
	@ApiOperation(value = "号码管理器删除", notes = "号码管理器删除")
	@PostMapping("/delete")
	public RestMessage<String> deleteSysCodeengineExecute(@RequestBody List<SysCodeengineDeleteVO> sysCodeengineDeleteVOs) {
		try {
			service.deleteSysCodeengineData(sysCodeengineDeleteVOs);
			return RestMessage.newInstance(true, "号码管理器删除成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@ApiOperation(value = "号码配置查询", notes = "可按资源编号和资源名称查询-v1.0")
	@ApiImplicitParams({ @ApiImplicitParam(name = "search", value = "查询条件") })
	@UserLog("号码配置查询")
	@GetMapping("/list-all")
	public RestMessage<List<SysCodeengineModel>> getCodeengine(String search) {
		List<SysCodeengineModel> list = service.getCodeengine(search);
		return RestMessage.newInstance(true, "成功", list);
	}

	@ApiOperation(value = "获取资源码", notes = "获取资源码-GetCodeNumberByCode/v1.0")
	@ApiImplicitParams({ @ApiImplicitParam(name = "code", value = "资源编号", required = true), @ApiImplicitParam(name = "codetype", value = "资源类型") })
	@UserLog("获取资源码")
	@PostMapping("/one")
	public RestMessage<String> getCodeNumberByCode(@RequestParam String code, String codetype) throws Exception {
		String maxbillno = service.getCodeNumberByCode(code, codetype);
		return RestMessage.newInstance(true, "成功", maxbillno);
	}

	@ApiOperation(value = "批量获取资源码", notes = "批量获取资源码-getCodeNumberByCodes/v1.0")
	@ApiImplicitParams({ @ApiImplicitParam(name = "code", value = "资源编号", required = true), @ApiImplicitParam(name = "codetype", value = "资源类型", required = true), @ApiImplicitParam(name = "codenum", value = "资源码个数", required = true) })
	@UserLog("批量获取资源码")
	@PostMapping("/many")
	public RestMessage<List<String>> getCodeNumberByCodes(@RequestParam String code, @RequestParam String codetype, @RequestParam Integer codenum) {
		List<String> codeList = service.getCodeNumberByCodes(code, codetype, codenum);
		return RestMessage.newInstance(true, "成功", codeList);
	}

	@ApiOperation(value = "批量获取资源码", notes = "批量获取资源码-getCodeNumberGroupByCodes/v1.0")
	@ApiImplicitParam(name = "list", value = "[{'code':'资源编号','codetype':'资源类型','codenum':'资源码个数'}]", required = true)
	@UserLog("批量获取资源码")
	@PostMapping("/many-by-map")
	public RestMessage<Map<String, List<String>>> getCodeNumberGroupByCodes(@RequestBody List<Map<String, Object>> list) {
		Map<String, List<String>> codeList = service.getCodeNumberGroupByCodes(list);
		return RestMessage.newInstance(true, "成功", codeList);
	}
}
