package com.zhgd.xmgl.modules.basicdata.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhgd.annotation.OperLog;
import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.jeecg.common.util.PageUtil;
import com.zhgd.xmgl.modules.basicdata.entity.AppVersion;
import com.zhgd.xmgl.modules.basicdata.service.IAppVersionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;

import java.util.Map;


 /**
 * @Title: Controller
 * @Description: APP版本表
 * @author： pengj
 * @date：   2023-02-23
 * @version： V1.0
 */
@RestController
@RequestMapping("/xmgl/appVersion")
@Slf4j
@Api(tags = "APP管理")
public class AppVersionController {
	@Autowired
	private IAppVersionService appVersionService;
	
	/**
	  * 分页列表查询
	 * @return
	 */
	@OperLog(operModul = "APP管理", operType = "分页查询", operDesc = "分页列表查询APP版本表信息")
	@ApiOperation(value = " 分页列表查询APP版本表信息", notes = "分页列表查询APP版本表信息", httpMethod="POST")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "pageNo", value = "页数", paramType = "query", required = true, defaultValue = "1", dataType = "Integer"),
			@ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query", required = true, defaultValue = "10", dataType = "Integer")
	})
	@PostMapping(value = "/page")
	public Result<IPage<AppVersion>> queryPageList(@RequestBody Map<String, Object> map) {
		Page<AppVersion> page = PageUtil.getPage(map);
		return Result.success(appVersionService.page(page, null));
	}
	
	/**
	  *   添加
	 * @param appVersion
	 * @return
	 */
	@OperLog(operModul = "APP管理", operType = "新增", operDesc = "添加APP版本表信息")
	@ApiOperation(value = " 添加APP版本表信息", notes = "添加APP版本表信息" , httpMethod="POST")
	@PostMapping(value = "/add")
	public Result<Object> add(@RequestBody AppVersion appVersion) {
		appVersionService.save(appVersion);
		return Result.success("添加成功！");
	}
	
	/**
	  *  编辑
	 * @param appVersion
	 * @return
	 */
	@OperLog(operModul = "APP管理", operType = "修改", operDesc = "编辑APP版本表信息")
	@ApiOperation(value = "编辑APP版本表信息", notes = "编辑APP版本表信息" , httpMethod="POST")
	@PostMapping(value = "/edit")
	public Result<AppVersion> edit(@RequestBody AppVersion appVersion) {
		Result<AppVersion> result = new Result<AppVersion>();
		AppVersion appVersionEntity = appVersionService.getById(appVersion.getVersionId());
		if(appVersionEntity==null) {
			result.error500("未找到对应实体");
		}else {
			boolean ok = appVersionService.updateById(appVersion);
			if(ok) {
				result.success("修改成功!");
			}
			result.success("操作失败!");
		}
		return result;
	}
	
	/**
	  * 通过id查询
	 * @return
	 */
	@OperLog(operModul = "APP管理", operType = "查询", operDesc = "通过id查询APP版本表信息")
	@ApiOperation(value = "通过id查询APP版本表信息", notes = "通过id查询APP版本表信息" , httpMethod="POST")
    @ApiImplicitParam(name = "versionId", value = "APP版本表ID", paramType = "query", required = true, dataType = "Integer")
	@PostMapping(value = "/queryById")
	public Result<AppVersion> queryById(@RequestBody AppVersion appVersionEntity) {
		Result<AppVersion> result = new Result<AppVersion>();
		AppVersion appVersion = appVersionService.getById(appVersionEntity.getVersionId());
		if(appVersion==null) {
			result.error500("未找到对应实体");
		}else {
			result.setResult(appVersion);
			result.setSuccess(true);
		}
		return result;
	}
}
