package com.cim.idm.controller;

import com.alibaba.fastjson.JSONObject;
import com.cim.idm.framework.IDMFrameServiceProxy;
import com.cim.idm.utils.AjaxResult;
import io.swagger.annotations.Api;
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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api("PDA自动更新")
@RestController
@RequestMapping("/pdaDownload")
@EnableAutoConfiguration
public class UpdateController {

	
	@RequestMapping(value = "/getVersion", method = RequestMethod.POST)
	public AjaxResult CommitTransferInInvoice(@RequestBody JSONObject in ) throws Exception{
		String app_url,app_vision;
		Number vision = (Number) in.get("vision");
		if(vision.equals(2)) {
			app_url = "PDA_DOWNLOADURL2";
			app_vision = "PDA_VERSION2";
		}else {
			app_url = "PDA_DOWNLOADURL";
			app_vision = "PDA_VERSION";
		}
		
		List<Map<String, Object>> arrayList = new ArrayList<Map<String,Object>> ();
		Map<String, Object> hashMap2 = new HashMap<String,Object> ();
//		String sql = "SELECT * FROM ENUMDEFVALUE e  WHERE e.ENUMNAME =  'PDA_DOWNLOADURL'";
		String sql = "SELECT * FROM ENUMDEFVALUE e  WHERE e.ENUMNAME = " + "'" + app_url + "'";
		Map<String, Object> hashMap = new HashMap<String,Object> ();
//		String sql2 = "SELECT * FROM ENUMDEFVALUE e  WHERE e.ENUMNAME =  'PDA_VERSION'";
		String sql2 = "SELECT * FROM ENUMDEFVALUE e  WHERE e.ENUMNAME = "  + "'" + app_vision + "'";
		List<Map<String, Object>> queryForList = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql, hashMap);
		if (queryForList != null && queryForList.size() > 0) {
			hashMap2.put("PDA_DOWNLOADURL", queryForList.get(0).get("ENUMVALUE"));
		}
		List<Map<String, Object>> queryForList2 = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql2, hashMap);
		if (queryForList2 != null && queryForList2.size() > 0) {
			hashMap2.put("PDA_VERSION", queryForList2.get(0).get("ENUMVALUE"));
		}
		arrayList.add(hashMap2);
		return AjaxResult.me().setResultObj(hashMap2);

	}
}
