zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
commit | author | age
a18bfa 1 package com.changhong.epc.form.rest.Assets;
Z 2
3 import com.changhong.epc.bean.admin.AssetDepreciation;
4 import com.changhong.epc.bean.form.Accrued;
5 import com.changhong.epc.bean.form.Asset;
6 import com.changhong.epc.bean.form.QueryParam;
7 import com.changhong.epc.bean.form.SectoralAssets;
8 import com.changhong.epc.constter.form.utf.FormUrlConst;
9 import com.changhong.epc.form.service.assets.AssetService;
10 import org.apache.poi.hssf.usermodel.HSSFCellStyle;
11 import org.apache.poi.hssf.usermodel.HSSFRow;
12 import org.apache.poi.hssf.usermodel.HSSFSheet;
13 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
14 import org.springframework.web.bind.annotation.*;
15
16 import javax.annotation.Resource;
17 import javax.servlet.http.HttpServletRequest;
18 import javax.servlet.http.HttpServletResponse;
19 import java.io.IOException;
20 import java.io.OutputStream;
21 import java.net.URLEncoder;
22 import java.text.ParseException;
23 import java.text.SimpleDateFormat;
24 import java.util.ArrayList;
25 import java.util.Date;
26 import java.util.List;
27 import java.util.Map;
28
29 @RestController
30 public class AssetsRest implements FormUrlConst {
31     @Resource(name="assetService")
32     private AssetService assetService;
33                 
34     /**
35      * 页面初始化查询资产
36      * @throws Exception 
37      */    
38     @RequestMapping(value = SELECT_ASSETS, method={RequestMethod.OPTIONS, RequestMethod.POST})
39     public List<SectoralAssets> selectAssets(@RequestBody Map<String,String> data){
40         return assetService.getSectoralAsset(data.get("date"));
41     }
42     
43     /**
44      * 同过一级部门进行查找异常数据
45      * 
46      */
47     @RequestMapping(value = SELECT_ERRASSETS, method={RequestMethod.OPTIONS, RequestMethod.POST})
48     public List<Asset> selectErrAssets(@RequestBody QueryParam queryParam) throws Exception{
49         return assetService.getErrAsset(queryParam);
50     }
51     
52     /**
53      *通过子部门查询异常资产 
54      * 
55      */
56     @RequestMapping(value = SELECT_ERRASSETSBYONE, method={RequestMethod.OPTIONS, RequestMethod.POST})
57     public List<Asset> selectErrAsset(@RequestBody QueryParam queryParam) throws Exception{
58         return assetService.getErrAssetOne(queryParam);
59     }
60     /**
61      * 分页
62      * 通过条件查询
63      * 查询详细
64      * 2018-1-18
65      */
66     @RequestMapping(value = SELECT_ACCRUED, method={RequestMethod.OPTIONS, RequestMethod.POST})
67     public List<Accrued> selectAccrued(@RequestBody QueryParam queryParam){
68         try {
69             return assetService.getAccrueds(queryParam);
70         } catch (ParseException e) {
71             return null;
72         }
73     }
74
75     /**
76      * 保存前验证资产
77      * @param assetDepreciation
78      * @return
79      */
80     @PostMapping(VALIDATE_ASSET)
81     public Boolean validateAsset(@RequestBody AssetDepreciation assetDepreciation){
82         return assetService.validateAsset(assetDepreciation);
83     }
84     
85     //下载exl
86     @GetMapping(SELECT_DOEXL)    
87     public boolean doExl(String date,String useDepCode,String useDepName,String state,String assetName,String assetCode,HttpServletRequest request, HttpServletResponse response){
88         QueryParam qp = new QueryParam();
89         if(date != null && (!date.equals("null")) && (!date.equals(""))){
90             qp.setDate(date);
91         }
92         if(state != null && (!state.equals("null")) && (!state.equals(""))){
93             qp.setState(state);
94         }
95         if(assetCode != null && (!assetCode.equals("null")) && (!assetCode.equals(""))){
96             qp.setAssetCode(assetCode);
97         }
98         if(assetName != null && (!assetName.equals("null")) && (!assetName.equals(""))){
99             qp.setAssetName(assetName);
100         }
101         if(useDepCode != null && (!useDepCode.equals("null")) && (!useDepCode.equals(""))){
102             qp.setUseDepCode(useDepCode);
103         }
104         if(useDepName != null && (!useDepName.equals("null")) && (!useDepName.equals(""))){
105             qp.setUseDepName(useDepName);
106         }        
107         List <Accrued> acc = new ArrayList<Accrued>();
108         try {
109             acc=assetService.getAccrueds(qp);
110         } catch (ParseException e1) {
111         }
112         
113         // 第一步,创建一个webbook,对应一个Excel文件  
114         HSSFWorkbook workbook = new HSSFWorkbook();  
115         // 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet 页 
116         HSSFSheet sheet = workbook.createSheet(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));  
117         // 第三步,在sheet中添加表头第0行  
118         HSSFRow row = sheet.createRow(0);  
119         // 第四步,创建单元格,并设置值表头 设置表头居中  
120         HSSFCellStyle style = workbook.createCellStyle();  
121         // 创建一个居中格  
122         style.setAlignment(HSSFCellStyle.ALIGN_CENTER);  
123
124         row.createCell(0).setCellValue("序号");  
125         row.createCell(1).setCellValue("部门");
126         row.createCell(2).setCellValue("资产编号");  
127         row.createCell(3).setCellValue("资产名称");  
128         row.createCell(4).setCellValue("规格型号");
129         row.createCell(5).setCellValue("资产化日期");
130         row.createCell(6).setCellValue("预计使用年限(月)");
131         row.createCell(7).setCellValue("已使用年限(月)");
132         row.createCell(8).setCellValue("原值");
133         row.createCell(9).setCellValue("折旧方法");
134         row.createCell(10).setCellValue("累计折旧");
135         row.createCell(11).setCellValue("本月折旧");
136         row.createCell(12).setCellValue("月折旧率(%)");
137         row.createCell(13).setCellValue("折后净值");      
138         
139         for(int i = 0;i < 14;i++){
140             //设置表头居中  
141             row.getCell(i).setCellStyle(style);
142             //设置列宽  
143             sheet.setColumnWidth(i, 3500); 
144         }
145         sheet.setColumnWidth(0, 1500);
146         // 第五步,写入实体数据  
147         for (int i = 0; i < acc.size(); i++) {  
148             row = sheet.createRow(i + 1);  
149             // 第六步,创建单元格,并设置值  
150             if(acc.get(i).getDepreciationMethod().equals("1")){
151                 acc.get(i).setDepreciationMethod("双倍余额递减法");
152             }else if(acc.get(i).getDepreciationMethod().equals("2")){
153                 acc.get(i).setDepreciationMethod("平均年限法");
154             }else if(acc.get(i).getDepreciationMethod().equals("3")){
155                 acc.get(i).setDepreciationMethod("年限总和法");
156             }
157             row.createCell(0).setCellValue(i+1);          
158             row.createCell(1).setCellValue(acc.get(i).getUseDepartmentName() == null ? "" : acc.get(i).getUseDepartmentName());
159             row.createCell(2).setCellValue(acc.get(i).getAssetsCode() == null ? "" : acc.get(i).getAssetsCode());
160             row.createCell(3).setCellValue(acc.get(i).getAssetsName() == null ? "" : acc.get(i).getAssetsName());
161             row.createCell(4).setCellValue(acc.get(i).getSpecifications() == null ? "" : acc.get(i).getSpecifications());
162             row.createCell(5).setCellValue(acc.get(i).getCapitalizationData() == null ? "" : acc.get(i).getCapitalizationData());
163             row.createCell(6).setCellValue(acc.get(i).getEstimateTime() == null ? "" : acc.get(i).getEstimateTime());
164             row.createCell(7).setCellValue(acc.get(i).getAlreadyTime() == null ? "" : acc.get(i).getAlreadyTime());
165             row.createCell(8).setCellValue(acc.get(i).getOriginalMoney() == null ? "" : acc.get(i).getOriginalMoney());
166             row.createCell(9).setCellValue(acc.get(i).getDepreciationMethod() == null ? "" : acc.get(i).getDepreciationMethod());
167             row.createCell(10).setCellValue(acc.get(i).getCumulativeDepreciation() == null ? 0 : acc.get(i).getCumulativeDepreciation());
168             row.createCell(11).setCellValue(acc.get(i).getCurrentDepreciation() == null ? 0 : acc.get(i).getCurrentDepreciation());
169             row.createCell(12).setCellValue(acc.get(i).getDepreciationRate() == null ? 0 : acc.get(i).getDepreciationRate());
170             row.createCell(13).setCellValue(acc.get(i).getNetMoney() == null ? 0 : acc.get(i).getNetMoney());
171         }
172         String downFileName = new String("资产折旧信息"+new SimpleDateFormat("yyyy-MM").format(new Date())+".xls");  
173         try {  
174             //若不进行编码在IE下会乱码  
175             downFileName = URLEncoder.encode(downFileName, "UTF-8");  
176         } catch (Exception e) {
177         }  
178         try (OutputStream os = response.getOutputStream()){
179             // 清空response  
180             response.reset();  
181             response.setContentType("application/msexcel");//设置生成的文件类型  
182             response.setCharacterEncoding("UTF-8");//设置文件头编码方式和文件名  
183             response.setHeader("Content-Disposition", "attachment; filename=" + new String(downFileName.getBytes("utf-8"), "ISO8859-1"));
184             workbook.write(os);  
185             os.flush();
186         } catch (IOException e) {
187             // System.err.println(e.getMessage());
188             return false;
189         }  
190         return true;
191     }
192
193     @PostMapping(ASSET_UPDATESTATUS)
194     public int updateAssetsByState(@RequestBody Map<String,String> map){
195         return assetService.updateAssetsByState(map);
196     }
197
198 }