zhuguifei
2026-03-10 2c1fd10c6fbabb8e9f0e9f07fe66fb36c008e883
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package com.shlanbao.tzsc.pms.md.eqp.controller;
 
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.List;
 
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
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.controller.BaseController;
import com.shlanbao.tzsc.base.mapping.MdEquipment;
import com.shlanbao.tzsc.base.model.Combobox;
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.controller.InputFilesController;
import com.shlanbao.tzsc.pms.equ.overhaul.beans.EqmMaintainBean;
import com.shlanbao.tzsc.pms.md.eqp.beans.EquipmentsBean;
import com.shlanbao.tzsc.pms.md.eqp.service.EquipmentsServiceI;
import com.shlanbao.tzsc.utils.tools.DateUtil;
 
/**
 * 设备主数据管理控制器
 * 
 * @author liuligong
 * @Time 2014/11/5 10:45
 */
@Controller
@RequestMapping("/pms/equc")
public class EquipmentsController extends BaseController {
    protected Logger log = Logger.getLogger(this.getClass());
 
    @Autowired
    private EquipmentsServiceI equipmentsService;
 
    @RequestMapping("/goToEqucMain")
    public String goToEqucMain(HttpServletRequest request) {
        return "/pms/equ/main/equAdd";
    }
 
    // 设备主数据新增
    @ResponseBody
    @RequestMapping("/addEqu")
    public Json addEqu(MdEquipment equBean) {
        Json json = new Json();
        try {
            equipmentsService.addEqu(equBean);
            json.setMsg("操作成功!");
            json.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            json.setMsg("操作失败!");
            json.setSuccess(false);
        }
        return json;
    }
 
    @ResponseBody
    @RequestMapping("/queryEqu")
    public DataGrid queryEqu(EquipmentsBean equBean, PageParams pageParams) {
        try {
            DataGrid gd = equipmentsService.queryEqu(equBean, pageParams);
            return gd;
        } catch (Exception e) {
            log.error("查询设备主数据异常。", e);
        }
        return null;
    }
 
    @RequestMapping("/goToEquEdit")
    public String goToEquEdit(HttpServletRequest request, String id) {
        try {
            request.setAttribute("equBean", equipmentsService.getEquById(id));
        } catch (Exception e) {
            log.error("编辑设备主数据异常:", e);
        }
        return "/pms/equ/main/equEdit";
    }
 
    /**
     * 查看设备主数据详情信息
     * @author sunzhen
     * @date 2019/07/11
     * @param request
     * @param id
     * @return
     */
    @RequestMapping("/goToEquDetails")
    public String goToEquDetails(HttpServletRequest request, String id) {
        try {
            request.setAttribute("equBean", equipmentsService.getEquById(id));
        } catch (Exception e) {
            log.error("查看设备主数据详情异常:", e);
        }
        return "/pms/equ/main/equDetails";
    }
 
    @ResponseBody
    @RequestMapping("/deleteEqu")
    public Json deleteEqu(String id) {
        Json json = new Json();
        try {
            equipmentsService.deleteEqu(id);
            json.setMsg("删除设备主数据成功!");
            json.setSuccess(true);
        } catch (Exception e) {
            log.error(message, e);
            json.setMsg("删除设备主数据失败!");
            json.setSuccess(false);
        }
        return json;
    }
 
    /**
     * 批量删除
     * @param ids
     * @return
     */
    @ResponseBody
    @RequestMapping("/batchDeleteEqu")
    public Json batchDeleteEqu(String ids) {
        Json json = new Json();
        try {
            equipmentsService.batchDeleteEqu(ids);
            json.setMsg("删除设备主数据成功!");
            json.setSuccess(true);
        } catch (Exception e) {
            log.error(message, e);
            json.setMsg("删除设备主数据失败!");
            json.setSuccess(false);
        }
        return json;
    }
 
    @ResponseBody
    @RequestMapping("/getAllEqpType")
    public List<Combobox> getAllEqpType(String id) {
        try {
            return equipmentsService.getAllEqpType(id);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
 
    @ResponseBody
    @RequestMapping("/queryAllEquipments")
    public List<EquipmentsBean> queryAllEquipments() {
        try {
            return equipmentsService.queryAllEquipments();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
 
    /**
     * excel導出 2015.9.9--张璐
     * 
     * @return
     */
    @ResponseBody
    @RequestMapping("/excelDeriveJuanBaoCP")
    public void excelDeriveJuanBaoCP(EquipmentsBean shopShiftBean,HttpServletResponse response) throws Exception {
 
        HSSFWorkbook wb = equipmentsService.ExportExcelJBPP2(shopShiftBean);
        String addtime = DateUtil.getNowDateTime("yyyyMMddHHmmSSS");
        response.reset();
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment; filename="
                + addtime + ".xls");
        ServletOutputStream os = response.getOutputStream();
        wb.write(os);
        os.flush();
        os.close();
 
    }
 
    @ResponseBody
    @RequestMapping("/inputExeclAndReadWrite")
    public Json inputExeclAndReadWrite(
            @RequestParam(value = "importFile", required = false) MultipartFile file,
            HttpServletRequest request) {
        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();
        }
            file.transferTo(targetFile);
        String url = path + "/" + fileName;
        String bm = fileName.substring((fileName.lastIndexOf(".") + 1),
                fileName.length());
        List<MdEquipment> list = null;
        InputFilesController fl = new InputFilesController();
        if ("xls".equals(bm)) {
            list = fl.readXls2003_4(url);
        } else if ("xlsx".equals(bm)) {
            list = fl.readXlsx2007_4(url);
        }
        if (list != null && list.size() > 0) {
                equipmentsService.inputExeclAndReadWrite(list);
                json.setMsg("导入成功!");
                json.setSuccess(true);
            }
        } catch (Exception e) {
            json.setMsg("导入失败!");
            json.setSuccess(false);
            e.printStackTrace();
        }
        return json;
    }
}