package com.shinsoft.sto.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

import com.shinsoft.tools.JSONTools;
import com.shinsoft.tools.ExceptionTools;
import com.shinsoft.tools.model.common.ResultJSON;
import com.shinsoft.tools.model.common.ResponseCodeMsg;

import com.shinsoft.sto.service.ReverseService;

/**
 * <p>
 * 倒库记录表 前端控制器
 * </p>
 *
 * @author system
 * @since 2024-12-24
 */
@RestController
//@RequestMapping("/sto/reverse")
@RequestMapping("/Reverse")
public class ReverseController {


    @Autowired
    private ReverseService reverseService;

    ResultJSON resultJSON;


    @RequestMapping(value = "/query")
    public ResultJSON query(int page, int rows, String params, HttpServletRequest request) {
        try {
            String userId = (String) request.getHeader("userId");
            resultJSON = reverseService.query(page, rows, params);
        } catch (Exception ex) {
            ex.printStackTrace();
            resultJSON = JSONTools.toResultJSON(ResponseCodeMsg.CODE_EX, ex);
        } finally {
            return resultJSON;
        }
    }

    @RequestMapping(value = "/queryByPK")
    public ResultJSON queryByPK(String id, HttpServletRequest request) {
        try {
            String userId = (String) request.getHeader("userId");
            resultJSON = reverseService.queryByPK(id);
        } catch (Exception ex) {
            ex.printStackTrace();
            resultJSON = JSONTools.toResultJSON(ResponseCodeMsg.CODE_EX, ex);
        } finally {
            return resultJSON;
        }
    }

    @RequestMapping(value = "/save")
    public ResultJSON save(String json, HttpServletRequest request) {
        try {
            String userId = (String) request.getHeader("userId");
            resultJSON = reverseService.save(userId, json);
        } catch (Exception ex) {
            resultJSON = JSONTools.toResultJSON(ResponseCodeMsg.CODE_EX, ExceptionTools.getExceptionAllinformation(ex));
            ex.printStackTrace();
        } finally {
            return resultJSON;
        }
    }

    @RequestMapping(value = "/remove")
    public ResultJSON remove(String id, HttpServletRequest request) {
        try {
            String userId = (String) request.getHeader("userId");
            resultJSON = reverseService.remove(userId, id);
        } catch (Exception ex) {
            ex.printStackTrace();
            resultJSON = JSONTools.toResultJSON(ResponseCodeMsg.CODE_EX, ex);
        } finally {
            return resultJSON;
        }
    }

    @RequestMapping(value = "/removeBatch")
    public ResultJSON removeBatch(String ids, HttpServletRequest request) {
        try {
            String userId = (String) request.getHeader("userId");
            resultJSON = reverseService.removeBatch(userId, ids);
        } catch (Exception ex) {
            ex.printStackTrace();
            resultJSON = JSONTools.toResultJSON(ResponseCodeMsg.CODE_EX, ex);
        } finally {
            return resultJSON;
        }
    }

}
