package com.cim.idm.controller;

import com.alibaba.fastjson.JSONObject;
import com.cim.idm.framework.IDMFrameServiceProxy;
import com.cim.idm.utils.AjaxResult;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

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

@RestController
@RequestMapping("/OpCode")
@EnableAutoConfiguration
public class OpCodeController {

	/**
	 * 获取过账opcode
	 * @param in
	 * @return
	 */
	@RequestMapping(value = "/getOpCode", method = RequestMethod.POST)
	public AjaxResult getOpCode(@RequestBody JSONObject in ){
		String opCode = in.get("opcode") == null ? "" : in.get("opcode").toString();
		String user = in.get("user") == null ? "" : in.get("user").toString();
		if ("".equals(opCode) || opCode == null) {
			String sql = "SELECT  :USER || '-' || SYS_GUID() ID FROM DUAL";
			Map<String, Object> hashMap = new HashMap<String,Object> ();
			hashMap.put("USER", user);
			List<Map<String, Object>> queryForList = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql, hashMap);
			opCode = queryForList.get(0).get("ID").toString();
		}
		return AjaxResult.me().setResultObj(opCode);

	}
}
