zhuguifei
2026-03-10 58402bd5e762361363a0f7d7907153c77dbb819f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package com.shlanbao.tzsc.pms.cos.spare.controller;
 
import java.io.File;
import java.util.List;
 
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
 
import com.shlanbao.tzsc.base.dao.CosSparePartsDaoI;
import com.shlanbao.tzsc.base.model.DataGrid;
import com.shlanbao.tzsc.base.model.Json;
import com.shlanbao.tzsc.base.model.PageParams;
import com.shlanbao.tzsc.pms.cos.spare.beans.CosSparePartsBean;
import com.shlanbao.tzsc.pms.cos.spare.service.CosSparePartsServiceI;
 
@Controller
@RequestMapping("/pms/spare")
public class CosSparePartsController {
    @Autowired
    public CosSparePartsServiceI cosSparePartsServiceI;
    @RequestMapping("/gotoUpdateBean")
    public String gotoUpdateBean(HttpServletRequest request,String id) throws Exception{
        request.setAttribute("bean", cosSparePartsServiceI.getBeanById(id));
        request.setAttribute("id", "i");
        return "/pms/equ/spare/editSpareParts";
    }
    //WCT备品备件查询
    @ResponseBody
    @RequestMapping("/queryData")
    public DataGrid queryDataGrid(CosSparePartsBean bean,PageParams pageParams) throws Exception{
        
        return cosSparePartsServiceI.queryGridByBean(bean, pageParams);
    }
    
    //PMS备品备件查询
    @ResponseBody
    @RequestMapping("/queryDataPMS")
    public DataGrid queryDataGridPMS(CosSparePartsBean bean,PageParams pageParams) throws Exception{
        
        return cosSparePartsServiceI.queryGridByBeanPMS(bean, pageParams);
    }
    
    @ResponseBody
    @RequestMapping("/updateBean")
    public Json updateBean(CosSparePartsBean bean) {
        Json json=new Json();
        try{
            if(cosSparePartsServiceI.saveOrUpdateBean(bean)){
                json.setMsg("操作成功!");
                json.setSuccess(true);
            }
        }catch(Exception e){
            json.setMsg("操作失败!");
            json.setSuccess(false);
            return json;
        }
        return json;
    }
    
    @ResponseBody
    @RequestMapping("/addBean")
    public Json addBean(CosSparePartsBean bean,PageParams pageParams){
        Json json=new Json();
        try{
            if(cosSparePartsServiceI.saveOrUpdateBean(bean)){
                json.setMsg("操作成功!");
                json.setSuccess(true);
            }
        }catch(Exception e){
            json.setMsg("操作失败!");
            json.setSuccess(false);
            return json;
        }
        return json;
    }
    
    @ResponseBody
    @RequestMapping("/deleteBean")
    public Json deleteBean(String id) {
        Json json=new Json();
        try{
            cosSparePartsServiceI.deleteById(id);
            json.setMsg("操作成功!");
            json.setSuccess(true);
        }catch(Exception e){
            json.setMsg("操作失败!");
            json.setSuccess(false);
            return json;
        }
        return json;
    }
 
    @ResponseBody
    @RequestMapping("/batchDeleteBean")
    public Json batchDeleteBean(String ids){
        Json json=new Json();
        try{
            cosSparePartsServiceI.batchDeleteBean(ids);
            json.setMsg("操作成功!");
            json.setSuccess(true);
        }catch(Exception e){
            json.setMsg("操作失败!");
            json.setSuccess(false);
            return json;
        }
        return json;
    }
 
 
    /**
     * 【功能说明】:备品备件批量导入功能- 跳转导入选择界面
     * @author wchuang
     * @time 2015年8月2日14:50:16
     * @param id
     * @param request
     * @return path -页面路径
     * 
     * */
    @RequestMapping("/inputExcelDatas")
    public String inputExcelDatas(HttpServletRequest request,String id) {
        return "/pms/equ/spare/iframe_excel";
    }
    
    /**
     * 【功能说明】:备品备件批量导入功能- 添加解析excel
     * @author wchuang
     * @time 2015年8月2日14:50:16
     * @param id
     * @param request
     * @return path -页面路径
     * 
     * */
    @RequestMapping("/inputExeclAndReadWrite")
    @ResponseBody
     public Json inputExeclAndReadWrite(@RequestParam(value = "importFile", required = false)
                                           MultipartFile file,HttpServletRequest request, CosSparePartsBean cspb) {
            Json json=new Json();   
            try {
                String path = request.getSession().getServletContext().getRealPath("upload");
                String fileName = file.getOriginalFilename();
                File targetFile = new File(path, fileName);
                if (!targetFile.exists()) {
                    targetFile.mkdirs();
                }
                try {
                    file.transferTo(targetFile);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                String url = path + "/" + fileName;
                String bm=fileName.substring( (fileName.lastIndexOf(".")+1) ,fileName.length());
                List<CosSparePartsBean> list =null;
                InputFilesController fl=new InputFilesController();
                if("xls".equals(bm)){ 
                    list=fl.readXls2003(url);
                }else if("xlsx".equals(bm)){ 
                    list=fl.readXlsx2007(url);
                }
                if(list!=null&&list.size()>0){
                     cosSparePartsServiceI.batchInputExeclAndReadWrite(list,cspb);
                     json.setMsg("导入成功!");
                     json.setSuccess(true);
                }
            } catch (Exception e) {
                json.setMsg("导入失败!");
                 json.setSuccess(false);
                e.printStackTrace();
            }
            return json;
    }
 
 
}