package com.sunda.spmsweb.ordercontroller;


import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.sunda.spmscommon.ResponseResult;
import com.sunda.spmsorder.entity.vo.MaterialDeliveryBoardsQueryVO;
import com.sunda.spmsorder.service.ISpmsPdaUpdateVersionService;
import com.sunda.spmsweb.util.JWTUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * PDA软件更新版本表 前端控制器
 * </p>
 *
 * @author Wayne
 * @since 2024-03-05
 */
@RestController
@RequestMapping("/spmsPdaUpdateVersion")
@Api(tags = "PDA软件更新版本接口", description = "PDA软件更新版本接口")
public class SpmsPdaUpdateVersionController {
	
	@Autowired
	ISpmsPdaUpdateVersionService iSpmsPdaUpdateVersionService;
	
	@RequestMapping("/getUpdateVersionByPage")
    @ApiOperation(value = "分页查询PDA版本更新信息", notes = "分页查询PDA版本更新信息；\n" +
            "可选输入版本名称versionName，版本号versionCode；\n" +
            "必填：当前页pageNo，页码大小pageSize；\n" +
            "{\n" +
            "\t\"versionName\": \"130011853\",\n" +
            "\t\"versionCode\": \"130011853\",\n" +
            "\t\"pageNo\": \"1\",\n" +
            "\t\"pageSize\": \"20\"\n" +
            "}", httpMethod = "POST")
    public ResponseResult getUpdateVersionByPage(@RequestBody JSONObject doc) {
        try {
            return iSpmsPdaUpdateVersionService.getUpdateVersionByPage(doc);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }
	
	@GetMapping("/getLastUpdateVersion")
    @ApiOperation(value = "查询PDA最新版本更新信息", notes = "查询PDA最新版本更新信息；")
    public ResponseResult getLastUpdateVersion() {
        try {
            return iSpmsPdaUpdateVersionService.getLastUpdateVersion();
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }
	
	@RequestMapping("/createUpdateVersion")
    @ApiOperation(value = "新增PDA版本更新信息", notes = "新增PDA版本更新信息；\n" +
            "{\n" +
            "\t\"versionName\": \"版本名称\",\n" +
            "\t\"versionCode\": \"版本号\",\n" +
            "\t\"comments\": \"更新内容\",\n" +
            "\t\"updateType\": \"更新状态：1强制更新，2选择更新\",\n" +
            "\t\"attachmentName\": \"附件名称\",\n" +
            "\t\"attachmentUrl\": \"附件路径\"\n" +
            "}", httpMethod = "POST")
    public ResponseResult saveUpdateVersion(@RequestBody JSONObject doc) {
        try {
        	String userId = JWTUtil.getUserId(SecurityUtils.getSubject().getPrincipal().toString());
            return iSpmsPdaUpdateVersionService.createUpdateVersion(doc, userId);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

}
