#
18516761980
2022-07-25 2c37b04bc0e5e2eae772166f514ff67113668f17
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
package com.slcf.service.impl;
 
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import com.slcf.bean.WaitPakOutLogCondition;
import com.slcf.controller.param.SetEmsParam;
import com.slcf.pojo.WaitPakOutLogBean;
import com.slcf.util.DateTimeUtil;
import org.apache.ibatis.annotations.Param;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.slcf.bean.WaitPakOutCondition;
import com.slcf.dao.WaitPakOutDao;
import com.slcf.dao.WorkFileDao;
import com.slcf.pojo.WaitPakOutBean;
import com.slcf.pojo.WorkDetailBean;
import com.slcf.pojo.WorkMastBean;
import com.slcf.service.WaitPakOutService;
 
import javax.servlet.http.HttpServletResponse;
 
/**
 * 入库通知档接口实现
 * @author admin
 * @date 2018年11月17日
 */
@Service
public class WaitPakOutServiceImpl implements WaitPakOutService {
 
    @Autowired
    WaitPakOutDao waitPakOutDao;
    
    @Autowired
    WorkFileDao workFileDao;
    /**
     * 添加
     */
    public int insertWaitPakOut(WaitPakOutBean waitPakOut) {
        int result=0;
        try {
            result=waitPakOutDao.insertWaitPakOut(waitPakOut);
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return result;
    }
 
//    /**
//     * 统计数量
//     */
//    public int queryWaitPakOutCount(){
//        int result = 0;
//        try {
//            result = WaitPakOutDao.getWaitPakOutCount();
//        }catch(Exception e) {
//            System.out.println(e.getMessage());
//        }
//        return result;
//    }
 
    /**
     * 分页查询所有
     */
    public Map<String,Object> queryWaitPakOutList(WaitPakOutCondition waitPakOutCon) {
        try {
            Map<String,Object> map=new HashMap<String, Object>();
            List<WaitPakOutBean> list=waitPakOutDao.queryWaitPakOutList(waitPakOutCon);
            int count =waitPakOutDao.getWaitPakOutCount(waitPakOutCon);
            map.put("rows", list);
            map.put("total", count);
            return map;
        }catch(Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }
//    public List<WaitPakOutBean> queryWaitPakOutList(int spage, int epage) {
//        try {
//            return WaitPakOutDao.queryWaitPakOutList(spage, epage);
//        }catch(Exception e) {
//            System.out.println(e.getMessage());
//            return null;
//        }
//    }
 
    public Integer waitPakOutSetEms(SetEmsParam setEmsParam) {
        return waitPakOutDao.waitPakOutSetEms(setEmsParam.getLgnum(), setEmsParam.getTanum(), setEmsParam.getTapos());
    }
 
    public Integer countEmsNum() {
        return waitPakOutDao.countEmsNum();
    }
 
    public List<WaitPakOutBean> queryWaitOutPak(String vlpla, String matnr) {
        return waitPakOutDao.queryWaitOutPak(vlpla, matnr);
    }
 
    /**
     * 根据id查找
     */
    public WaitPakOutBean queryWaitPakOutById(String sheet_no,String mat_no) {
        try {
            return waitPakOutDao.getWaitPakOutById(sheet_no,mat_no);
        }catch(Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }
    
    /**
     * 根据库位号查找
     */
    public WaitPakOutBean queryWaitPakOutByLocNo(String loc_no) {
        try {
            return waitPakOutDao.getWaitPakOutByLocNo(loc_no);
        }catch(Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }
    
    /**
     * 根据物料号号查找
     */
    public WaitPakOutBean queryWaitPakOutByMatNo(String mat_no) {
        try {
            return waitPakOutDao.getWaitPakOutByMatNo(mat_no);
        }catch(Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }
    
    //更新
    public int upWaitPakOut(WaitPakOutBean WaitPakOut, int type) {
        int result=0;
        try {
            result=waitPakOutDao.upWaitPakOut(WaitPakOut);
//            if(type==2) {
//                //如果工作档有数据,调整工作档优先级
//                WorkDetailBean workDetail = workFileDao.getWorkDetlByMatNo(WaitPakOut.getMat_no());
//                if(workDetail!=null) {
//                    WorkMastBean workMast = workFileDao.getWorkMastById(workDetail.getWrk_no());
//                    if(workMast!=null) {
//                        workMast.setIo_pri(WaitPakOut.getCtns());
//                        workFileDao.upWorkMast(workMast);
//                    }
//                }
//                
//            }
        }catch(Exception e) {
//            System.out.println("TQSTQS---" + e.getMessage());
            System.out.println(e.getMessage());
        }
        return result;
    }
 
    //更新
    public int upWaitPakOutByLocNo(WaitPakOutBean WaitPakOut) {
        int result=0;
        try {
            result=waitPakOutDao.upWaitPakOutByLocNo(WaitPakOut);
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return result;
    }
        
    /**
     * 根据id删除
     */
    public int delWaitPakOut(WaitPakOutBean WaitPakOut) {
        int result=0;
        try {
            result=waitPakOutDao.delWaitPakOutById(WaitPakOut);
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return result;
    }
 
    /**
     * 查询所有
     * @return
     */
    public List<WaitPakOutBean> getWaitPakOutList() {
        try {
            return waitPakOutDao.getWaitPakOutList();
        }catch(Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }
    
    /**
     * 转历史档
     */    
//    @Transactional(propagation=Propagation.REQUIRED)
    @Transactional
    public int moveToLog(WaitPakOutBean WaitPakOut) {
        int result=0;
        try {
            result=waitPakOutDao.insertLog(WaitPakOut);
            result=waitPakOutDao.delWaitPakOutById(WaitPakOut);
        }catch(Exception e) {
            System.out.println(e.getMessage());
        }
        return result;
    }
    
    /**
     * 查询所有单号
     * @return
     */
    public List<WaitPakOutBean> getSheetNoList() {
        try {
            return waitPakOutDao.getSheetNoList();
        }catch(Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }
    
    /**
     * 根据编号、行号查
     */
    public WaitPakOutBean queryWaitPakOutByNum(WaitPakOutBean waitPakOutBean) {
        try {
            return waitPakOutDao.getWaitPakOutByNum(waitPakOutBean);
        }catch(Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }
    
    /**
     * 查询最早一笔待反馈SAP数据
     */
    public WaitPakOutBean queryWaitPakOutFnh() {
        try {
            return waitPakOutDao.getWaitPakOutFnh();
        }catch(Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }
    
    /**
     * 查询最早一笔待打印标签数据
     */
    public WaitPakOutBean getWaitPakOutPrint() {
        try {
            return waitPakOutDao.getWaitPakOutPrint();
        }catch(Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }
 
    public void ExportWaitPakOutList(WaitPakOutCondition condition, HttpServletResponse response) {
        //输出Excel文件
        try {
            //HSSFWorkbook对象(excel的文档对象)
            HSSFWorkbook workBook=new HSSFWorkbook();
 
            //sheet对象(excel的表单)
            HSSFSheet sheet=workBook.createSheet("出库通知历史档");
 
            //行数,参数为行索引(excel的行)
//                HSSFRow rowHead=sheet.createRow(0);//第一行  可以是0~65535之间的任何一个
 
//                //创建excel的单元格,参数为列索引,可以是0~255之间的任何一个
//                HSSFCell cellOne=rowHead.createCell(0);
//                cellOne.setCellValue("用户信息");//表头
 
            //合并单元格CellRangeAddress构造参数依次表示起始行,截至行,起始列, 截至列
//                sheet.addMergedRegion(new CellRangeAddress(0,0,0,5));
 
            sheet.setColumnWidth(0, (int)((10 + 0.72) * 256));
            sheet.setColumnWidth(1, (int)((20 + 0.72) * 256));
            sheet.setColumnWidth(2, (int)((15 + 0.72) * 256));
            sheet.setColumnWidth(3, (int)((15 + 0.72) * 256));
            sheet.setColumnWidth(4, (int)((15 + 0.72) * 256));
            sheet.setColumnWidth(5, (int)((25 + 0.72) * 256));
            sheet.setColumnWidth(6, (int)((10 + 0.72) * 256));
            sheet.setColumnWidth(7, (int)((8 + 0.72) * 256));
            sheet.setColumnWidth(8, (int)((10 + 0.72) * 256));
            sheet.setColumnWidth(9, (int)((10 + 0.72) * 256));
            sheet.setColumnWidth(10, (int)((10 + 0.72) * 256));
            sheet.setColumnWidth(11, (int)((25 + 0.72) * 256));
            sheet.setColumnWidth(12, (int)((25 + 0.72) * 256));
            sheet.setColumnWidth(13, (int)((25 + 0.72) * 256));
 
            HSSFRow rows=sheet.createRow(0);//第二行
            //创建单元格并设置单元格内容
            rows.createCell(0).setCellValue("仓库号");
            rows.createCell(1).setCellValue("转储编号");
            rows.createCell(2).setCellValue("行项目");
            rows.createCell(3).setCellValue("物料");
            rows.createCell(4).setCellValue("物料描述");
            rows.createCell(5).setCellValue("工厂");
            rows.createCell(6).setCellValue("数量");
            rows.createCell(7).setCellValue("单位");
            rows.createCell(8).setCellValue("源发地类型");
            rows.createCell(9).setCellValue("源发地仓位");
            rows.createCell(10).setCellValue("目的地类型");
            rows.createCell(11).setCellValue("目的地仓位");
            rows.createCell(12).setCellValue("用户ID");
            rows.createCell(13).setCellValue("修改时间");
 
            List<WaitPakOutBean> list=waitPakOutDao.getWaitPakOutAll(condition);
            for(int i=0;i<list.size();i++){
                HSSFRow row=sheet.createRow(i+1);//从第三行开始
                //创建单元格并设置单元格内容
                row.createCell(0).setCellValue(list.get(i).getLgnum());
                row.createCell(1).setCellValue(list.get(i).getTanum());
                row.createCell(2).setCellValue(list.get(i).getTapos());
                row.createCell(3).setCellValue(list.get(i).getMatnr());
                row.createCell(4).setCellValue(list.get(i).getMaktx());
                row.createCell(5).setCellValue(list.get(i).getWerks());
                row.createCell(6).setCellValue(list.get(i).getVsolm());
                row.createCell(7).setCellValue(list.get(i).getMeins());
                row.createCell(8).setCellValue(list.get(i).getVltyp());
                row.createCell(9).setCellValue(list.get(i).getVlpla());
                row.createCell(10).setCellValue(list.get(i).getNltyp());
                row.createCell(11).setCellValue(list.get(i).getNlpla());
                row.createCell(12).setCellValue(list.get(i).getBname());
                row.createCell(13).setCellValue(list.get(i).getModi_time());
            }
//            //输出Excel文件
//            try {
            OutputStream output=response.getOutputStream();
            response.reset();
            response.setHeader("Content-disposition", "attachment; filename=WaitPakOut"+ DateTimeUtil.getStringDateTime(14)+".xls");
            response.setContentType("application/msexcel");
            workBook.write(output);
            output.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}