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.dto.SysRefdatadDTO;
import com.prolog.rdc.tms.model.entity.SysRefdatadModel;
import com.prolog.rdc.tms.model.entity.SysRefdatahModel;
import com.prolog.rdc.tms.model.vo.DropDownBoxVO;
import com.prolog.rdc.tms.model.vo.RefdataVO;
import com.prolog.rdc.tms.model.vo.SysRefdatadDeleteVO;
import com.prolog.rdc.tms.model.vo.SysRefdatadQueryVO;
import com.prolog.rdc.tms.model.vo.SysRefdatadSaveVO;
import com.prolog.rdc.tms.model.vo.SysRefdatadSearchVO;
import com.prolog.rdc.tms.model.vo.SysRefdatadUpdateVO;
import com.prolog.rdc.tms.model.vo.SysRefdatahDeleteVO;
import com.prolog.rdc.tms.model.vo.SysRefdatahQueryVO;
import com.prolog.rdc.tms.model.vo.SysRefdatahSaveVO;
import com.prolog.rdc.tms.model.vo.SysRefdatahUpdateVO;
import com.prolog.rdc.tms.service.SysRefdatadService;

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

/**
 * 
 *
 * 数据字典控制层
 *
 * @className :SysRefdatadController
 * @author :fanzw
 * @creationTime :2020/07/02
 * @description :
 * @modifier :fanzw
 * @modifyTime :2020/07/02
 * @reviseRemarks:
 *
 * @version :1.0.0
 *
 */
@RestController
@Api(tags = "基础配置-数据字典控制层")
@RequestMapping("/refdata")
public class SysRefdatadController extends BaseController {

	@Autowired
	private SysRefdatadService sysRefdatadService;

	@UserLog("数据字典分页查询")
	@ApiOperation(value = "数据字典分页查询", notes = "数据字典分页查询")
	@PostMapping("/hdr/list")
	public RestMessage<Page<SysRefdatahModel>> listSysRefdatahPageExecute(@RequestBody SysRefdatahQueryVO sysRefdatahQueryVO) {
		try {
			Page<SysRefdatahModel> sysRefdatahModels = sysRefdatadService.listSysRefdatahPageData(sysRefdatahQueryVO);
			return RestMessage.newInstance(true, "数据字典分页查询成功", sysRefdatahModels);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("数据字典明细查询")
	@ApiOperation(value = "数据字典明细查询", notes = "数据字典明细查询")
	@PostMapping("/dtl/get-part")
	public RestMessage<Map<String, Object>> listSysRefdatadPageExecute(@RequestBody SysRefdatadSearchVO sysRefdatadSearchVO) {
		try {
			Map<String, Object> map = sysRefdatadService.listSysRefdatadPageData(sysRefdatadSearchVO);
			return RestMessage.newInstance(true, "数据字典明细查询成功", map);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("数据字典修改")
	@ApiOperation(value = "数据字典修改", notes = "数据字典修改")
	@PostMapping("/hdr/update")
	public RestMessage<String> updateSysRefdatahExecute(@RequestBody SysRefdatahUpdateVO sysRefdatahUpdateVO) {
		try {
			sysRefdatadService.updateSysRefdatahData(sysRefdatahUpdateVO);
			return RestMessage.newInstance(true, "数据字典修改成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("数据字典删除")
	@ApiOperation(value = "数据字典删除", notes = "数据字典删除")
	@PostMapping("/hdr/delete")
	public RestMessage<String> deleteSysRefdatahExecute(@RequestBody SysRefdatahDeleteVO sysRefdatahDeleteVO) {
		try {
			sysRefdatadService.deleteSysRefdatahData(sysRefdatahDeleteVO);
			return RestMessage.newInstance(true, "数据字典删除成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("数据字典保存")
	@ApiOperation(value = "数据字典保存", notes = "数据字典保存")
	@PostMapping("/hdr/create")
	public RestMessage<String> saveSysRefdatahExecute(@RequestBody SysRefdatahSaveVO sysRefdatahSaveVO) {
		try {
			sysRefdatadService.saveSysRefdatahData(sysRefdatahSaveVO);
			return RestMessage.newInstance(true, "数据字典保存", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("数据字典下拉框")
	@ApiOperation(value = "数据字典下拉框", notes = "数据字典下拉框")
	@PostMapping("/dtl/dd-list")
	public RestMessage<Map<String, Object>> listDropDownBoxExecute(@RequestBody List<DropDownBoxVO> dropDownBoxVOs) {
		try {
			Map<String, Object> data = sysRefdatadService.listDropDownBoxData(dropDownBoxVOs);
			return RestMessage.newInstance(true, "数据字典下拉框查询成功", data);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("数据字典明细新增")
	@ApiOperation(value = "数据字典明细新增", notes = "数据字典明细新增")
	@PostMapping("/dtl/create")
	public RestMessage<String> saveSysRefdatadExecute(@RequestBody List<SysRefdatadSaveVO> sysRefdatadSaveVOs) {
		try {
			sysRefdatadService.saveSysRefdatadData(sysRefdatadSaveVOs);
			return RestMessage.newInstance(true, "数据字典明细新增成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("数据字典明细修改")
	@ApiOperation(value = "数据字典明细修改", notes = "数据字典明细修改")
	@PostMapping("/dtl/update")
	public RestMessage<String> updateSysRefdatadExecute(@RequestBody List<SysRefdatadUpdateVO> sysRefdatadUpdateVOs) {
		try {
			sysRefdatadService.updateSysRefdatadData(sysRefdatadUpdateVOs);
			return RestMessage.newInstance(true, "数据字典明细修改成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("数据字典明细删除")
	@ApiOperation(value = "数据字典明细删除", notes = "数据字典明细删除")
	@PostMapping("/dtl/delete")
	public RestMessage<String> deleteSysRefdatadExecute(@RequestBody List<SysRefdatadDeleteVO> sysRefdatadDeleteVOs) {
		try {
			sysRefdatadService.deleteSysRefdatadData(sysRefdatadDeleteVOs);
			return RestMessage.newInstance(true, "数据字典明细删除成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@ApiOperation(value = "根据ID获取汇总信息", notes = "通过字段编码-getSysRefdatahById/v1.0")
	@ApiImplicitParams({ @ApiImplicitParam(name = "objectcode", value = "字段编码") })
	@UserLog("根据ID获取汇总信息")
	@GetMapping("/hdr/get")
	public RestMessage<SysRefdatahModel> getSysRefdatahById(String objectcode) {
		SysRefdatahModel list = sysRefdatadService.getSysRefdatahById(objectcode);
		return RestMessage.newInstance(true, "成功", list);
	}

	@ApiOperation(value = "获取明细信息", notes = "通过字段编码、存储值，显示名称查询-getSysRefdatad/v1.0")
	@ApiImplicitParams({ @ApiImplicitParam(name = "objectcode", value = "字段编码"), @ApiImplicitParam(name = "code", value = "存储值"), @ApiImplicitParam(name = "name", value = "显示名称") })
	@UserLog("获取明细信息")
	@PostMapping("/dtl/list-by-code-name")
	public RestMessage<List<SysRefdatadModel>> getSysRefdatad(String objectcode, String code, String name) {
		List<SysRefdatadModel> list = sysRefdatadService.getSysRefdatad(objectcode, code, name);
		return RestMessage.newInstance(true, "成功", list);
	}

	@ApiOperation(value = "通过ID获取明细信息", notes = "通过字段编码、排序号查询-/getSysRefdatadById/v1.0")
	@ApiImplicitParams({ @ApiImplicitParam(name = "objectcode", value = "字段编码", required = true), @ApiImplicitParam(name = "sortnum", value = "排序号", required = true) })
	@UserLog("通过ID获取明细信息")
	@PostMapping("/dtl/get")
	public RestMessage<SysRefdatadModel> getSysRefdatadById(@RequestParam String objectcode, @RequestParam String sortnum) {
		SysRefdatadModel refd = sysRefdatadService.getSysRefdatadById(objectcode, sortnum);
		return RestMessage.newInstance(true, "成功", refd);
	}

	@ApiOperation(value = "获取objectcode和code获取名称", notes = "获取objectcode和code获取名称-/getSysByNames/v1.0")
	@ApiImplicitParam(name = "map", value = "{\"objectcode\":\"字段编码\",\"code\":\"储存值\"}")
	@UserLog("获取objectcode和code获取名称")
	@PostMapping("/dtl/list-objcode") // 指定调用sys-service服务的接口 找不到则404
	public RestMessage<List<Map<String, Object>>> getSysByNames(@RequestBody Map<String, Object> map) throws Exception {
		List<Map<String, Object>> list = sysRefdatadService.getSysByNames(map);
		return RestMessage.newInstance(true, "成功", list);
	}

	@ApiOperation(value = "批量获取objectcode和code获取名称", notes = "批量获取objectcode和code获取名称-batchGetNamesByCodes/v1.0")
	@ApiImplicitParam(name = "vo", value = "{\"objectcodes\":[值1，值2],\"codes\":[值1，值2]}")
	@UserLog("批量获取objectcode和code获取名称")
	@PostMapping("/dtl/list-objcode2")
	public RestMessage<List<Map<String, Object>>> batchGetNamesByCodes(@RequestBody RefdataVO vo) throws Exception {
		List<Map<String, Object>> result = sysRefdatadService.batchGetNamesByCodes(vo);
		return RestMessage.newInstance(true, "成功", result);
	}

	@ApiOperation(value = "获取参照明细信息", notes = "通过字段编码、存储值，分组编号查询-getSysRefdatadCom/v1.0")
	@ApiImplicitParams({ @ApiImplicitParam(name = "objectcode", value = "字段编码"), @ApiImplicitParam(name = "code", value = "存储值"), @ApiImplicitParam(name = "groupcode1", value = "分组编号") })
	@UserLog("获取参照明细信息")
	@PostMapping("/dtl/list-by-objcode-code-grp")
	public RestMessage<List<SysRefdatadModel>> getSysRefdatadCom(String objectcode, String code, String groupcode1) {
		List<SysRefdatadModel> list = sysRefdatadService.getSysRefdatadCom(objectcode, code, groupcode1);
		return RestMessage.newInstance(true, "成功", list);
	}

	@ApiOperation(value = "根据objectcode和code获取名称", notes = "获取objectcode和code获取名称-findsysrefdatadn/v1.0")
	@ApiImplicitParam(name = "map", value = "{\"objectcode\":\"字段编码\",\"code\":\"储存值\"}")
	@UserLog("获取objectcode和code获取名称")
	@PostMapping("/dtl/list-name-code") // 指定调用sys-service服务的接口 找不到则404
	public RestMessage<List<Map<String, Object>>> findsysrefdatadn(@RequestBody Map<String, Object> map) {
		List<Map<String, Object>> list = sysRefdatadService.findsysrefdatadn(map);
		return RestMessage.newInstance(true, "成功", list);
	}

	@UserLog("参照数据明细查询")
	@ApiOperation(value = "参照数据明细查询", notes = "参照数据明细查询")
	@PostMapping("/get/v1.0")
	public RestMessage<List<SysRefdatadDTO>> getSysRefdatadExecute(@RequestBody SysRefdatadQueryVO sysrefdatadqueryvo) {
		try {
			List<SysRefdatadDTO> sysrefdataddtos = sysRefdatadService.getSysRefdatadData(sysrefdatadqueryvo);
			return RestMessage.newInstance(true, "查询成功", sysrefdataddtos);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@ApiOperation(value = "获取数据字典键值对", notes = "获取数据字典键值对-getRefdKeyValue/v1.0")
	@ApiImplicitParams({ @ApiImplicitParam(name = "objectcode", value = "字段编码", required = true) })
	@UserLog("获取数据字典键值对")
	@PostMapping("/getRefdKeyValue/v1.0")
	public RestMessage<Map<String, String>> getRefdKeyValue(@RequestParam String[] strArr, @RequestParam String enterpriseid) throws Exception {
		Map<String, String> map = sysRefdatadService.getRefdKeyValue(strArr, enterpriseid);
		return RestMessage.newInstance(true, "成功", map);
	}

	@ApiOperation(value = "获参数配置列表", notes = "获参数配置列表-getDropDownById/v1.0")
	@ApiImplicitParams({ @ApiImplicitParam(name = "objectcode", value = "字段编码", required = true), @ApiImplicitParam(name = "groupcode1", value = "分组编号") })
	@UserLog("获参数配置列表")
	@PostMapping("/dtl/dd-list/get")
	public RestMessage<List<Map<String, Object>>> getDropDownById(@RequestParam String objectcode, String groupcode1, String groupcode2, String code) throws Exception {
		List<Map<String, Object>> list = sysRefdatadService.getDropDownById(objectcode, groupcode1, groupcode2, code);
		return RestMessage.newInstance(true, "成功", list);
	}

	@UserLog("数据字典批量查询")
	@ApiOperation(value = "数据字典批量查询", notes = "数据字典批量查询")
	@PostMapping("/dtl/list")
	public RestMessage<Map<String, Object>> ListDropDownExecute(@RequestBody List<Map<String, Object>> param) {
		try {
			Map<String, Object> data = sysRefdatadService.ListDropDownData(param);
			return RestMessage.newInstance(true, "成功", data);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@ApiOperation(value = "通用字典翻译查询")
	@UserLog("通用字典翻译查询")
	@PostMapping("/getSysRefdatadDatas")
	public RestMessage<List<SysRefdatadModel>> getDropDownById(@RequestBody SysRefdatadQueryVO vo) throws Exception {
		List<SysRefdatadModel> list = sysRefdatadService.getSysRefdatadDatas(vo);
		return RestMessage.newInstance(true, "查询成功", list);
	}

	@ApiOperation(value = "获取明细信息", notes = "通过字段编码、存储值，显示名称查询-getSysRefdatad/v1.0")
	@UserLog("获取明细信息")
	@PostMapping("/dtl/list-by-name")
	public RestMessage<List<SysRefdatadModel>> getSysRefdatadByName(@RequestBody SysRefdatadSearchVO sysRefdatadSearchVO) {
		List<SysRefdatadModel> list = sysRefdatadService.getSysRefdatadByName(sysRefdatadSearchVO);
		return RestMessage.newInstance(true, "成功", list);
	}

}
