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.PickRecordService;

/**
 * <p>
 * 领料记录表 前端控制器
 * </p>
 *
 * @author system
 * @since 2025-01-13
 */
@RestController
//@RequestMapping("/pickRecord")
@RequestMapping("/PickRecord")
public class PickRecordController {

    @Autowired
    private PickRecordService pickRecordService;

    ResultJSON resultJSON;


    @RequestMapping(value = "/query")
    public ResultJSON query(int page, int rows, String params, HttpServletRequest request) {
        try {
            String userId = (String) request.getHeader("userId");
            resultJSON = pickRecordService.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 = pickRecordService.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 = pickRecordService.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 = pickRecordService.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 = pickRecordService.removeBatch(userId, ids);
        } catch (Exception ex) {
            ex.printStackTrace();
            resultJSON = JSONTools.toResultJSON(ResponseCodeMsg.CODE_EX, ex);
        } finally {
            return resultJSON;
        }
    }



}
