package com.palmnest.webapp.controller.api;

import com.palmnest.application.bean.AppResultDto;
import com.palmnest.application.core.util.AppResultUtil;
import com.palmnest.application.dto.output.AppUseVersionOutPutDto;
import com.palmnest.service.appVersion.AppUseVersionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * app端获取app版本管理
 *
 * @author longmeizhen
 */
@Slf4j
@Controller
@RequestMapping(value = "/wechat/appVersion/*")
public class ApiAppUseVersionController {


	@Autowired
	private AppUseVersionService appUseVersionService;

	/**
	 * 获取app最新版本配置
	 *
	 * @param useCode
	 * @param type
	 * @return
	 */
	@RequestMapping(value = "getAppVersion")
	@ResponseBody
	public AppResultDto getAppVersion(String useCode, String type) {
		try {
			AppUseVersionOutPutDto appVersion = appUseVersionService.getLatestRecode(useCode, type);
			return AppResultUtil.createSuccesDto(appVersion);
		} catch (Exception e) {
			log.error(e.getMessage());
			e.printStackTrace();
			return AppResultUtil.createErrorDto("100", "获取记录失败：" + e.getMessage());
		}
	}
}
