package com.th.demo.controller.maint;

import com.th.demo.model.maint.OrdTract;
import com.th.demo.model.system.ResponseCodeMsg;
import com.th.demo.model.system.Type;
import com.th.demo.service.maint.OrdTractService;
import com.th.demo.tools.JSONTools;
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;

@RestController
@RequestMapping(value = "/MaintOrdTract")
public class OrdTractController {
    @Autowired
    public OrdTractService ordTractService;
    String result = Type.FAIL;

    @RequestMapping(value = "/query.do")//查询方法 前两个参数是分页参数
    public String query(int page,
                        int rows,
                        String customerName,
                        HttpServletRequest request) {

        try {
            String userId = (String) request.getAttribute("userId");
            String belongId = (String) request.getAttribute("belongId");
            result = ordTractService.query(page, rows,customerName, userId,belongId);
        } catch (Exception ex) {
            ex.printStackTrace();
            result = JSONTools.toString(ResponseCodeMsg.CODE_EX, ex.getMessage());
        } finally {
            return result;
        }
    }

    @RequestMapping(value = "/save.do")//查询方法 前两个参数是分页参数
    public String save(String json,
                       HttpServletRequest request) {

        try {
            String userId = (String) request.getAttribute("userId");
            String belongId = (String) request.getAttribute("belongId");
            result = ordTractService.save(json, userId,belongId);
        } catch (Exception ex) {
            ex.printStackTrace();
            result = JSONTools.toString(ResponseCodeMsg.CODE_EX, ex.getMessage());
        } finally {
            return result;
        }
    }

    @RequestMapping(value = "/inImport.do")//查询方法 前两个参数是分页参数
    public String inImport(String json,
                       HttpServletRequest request) {

        try {
            String userId = (String) request.getAttribute("userId");
            String belongId = (String) request.getAttribute("belongId");
            result = ordTractService.inImport(json, userId,belongId);
        } catch (Exception ex) {
            ex.printStackTrace();
            result = JSONTools.toString(ResponseCodeMsg.CODE_EX, ex.getMessage());
        } finally {
            return result;
        }
    }

    @RequestMapping(value = "/remove.do")//查询方法 前两个参数是分页参数
    public String remove(String ordNo,
                         HttpServletRequest request) {

        try {
            String userId = (String) request.getAttribute("userId");
            String belongId = (String) request.getAttribute("belongId");
            result = ordTractService.remove(ordNo, userId,belongId);
        } catch (Exception ex) {
            ex.printStackTrace();
            result = JSONTools.toString(ResponseCodeMsg.CODE_EX, ex.getMessage());
        } finally {
            return result;
        }
    }
}
