Commit b3cfbe77e52e56a90a3bd4de2ccfb24ff9292e55
1 parent
5453f6ac
pda控制器
Showing
1 changed file
with
232 additions
and
0 deletions
src/main/java/com/zteits/irain/portal/web/parkinglotcloudplatform/devicemanagement/PdaController.java
0 → 100644
1 | +package com.zteits.irain.portal.web.parkinglotcloudplatform.devicemanagement; | ||
2 | + | ||
3 | +import java.io.IOException; | ||
4 | +import java.util.ArrayList; | ||
5 | +import java.util.List; | ||
6 | + | ||
7 | +import javax.servlet.http.HttpServletRequest; | ||
8 | +import javax.servlet.http.HttpServletResponse; | ||
9 | + | ||
10 | +import org.apache.poi.xssf.usermodel.XSSFSheet; | ||
11 | +import org.slf4j.Logger; | ||
12 | +import org.slf4j.LoggerFactory; | ||
13 | +import org.springframework.beans.factory.annotation.Autowired; | ||
14 | +import org.springframework.beans.factory.annotation.Value; | ||
15 | +import org.springframework.web.bind.annotation.GetMapping; | ||
16 | +import org.springframework.web.bind.annotation.PostMapping; | ||
17 | +import org.springframework.web.bind.annotation.RequestBody; | ||
18 | +import org.springframework.web.bind.annotation.RequestParam; | ||
19 | +import org.springframework.web.bind.annotation.RestController; | ||
20 | +import org.springframework.web.multipart.MultipartFile; | ||
21 | + | ||
22 | +import com.clouds.common.utils.DateUtil; | ||
23 | +import com.clouds.common.utils.excle.ExcelReadUtil; | ||
24 | +import com.clouds.common.utils.excle.ExcelUtil; | ||
25 | +import com.clouds.common.utils.excle.ExcleFillDateManager; | ||
26 | +import com.clouds.common.utils.excle.Layouter; | ||
27 | +import com.clouds.common.web.BizController; | ||
28 | +import com.clouds.common.web.vo.BizResultVO; | ||
29 | +import com.clouds.common.web.vo.EasyUIDataGridVO; | ||
30 | +import com.google.common.collect.Lists; | ||
31 | +import com.xiaoleilu.hutool.util.CollectionUtil; | ||
32 | +import com.zteits.clouds.api.apibase.bean.BizResult; | ||
33 | +import com.zteits.clouds.api.apibase.bean.PageBean; | ||
34 | +import com.zteits.clouds.api.apibase.constants.ErrorType; | ||
35 | +import com.zteits.clouds.api.apibase.exception.BizException; | ||
36 | +import com.zteits.clouds.api.dto.park.dto.TpPPdaDTO; | ||
37 | +import com.zteits.clouds.api.dto.park.param.TpPPdaRequest; | ||
38 | +import com.zteits.clouds.api.dto.park.param.TpPPdaSRequest; | ||
39 | +import com.zteits.clouds.api.service.park.TpPPdaService; | ||
40 | +import com.zteits.irain.portal.web.parkinglotcloudplatform.datastatistic.InOutParkStatisticController; | ||
41 | + | ||
42 | +import io.swagger.annotations.ApiOperation; | ||
43 | + | ||
44 | +/** | ||
45 | + * PDA管理控制器 | ||
46 | + * | ||
47 | + * Copyright: Copyright (c) 2017 ZTE-ITS | ||
48 | + * | ||
49 | + * @ClassName: PdaController.java | ||
50 | + * @Description: | ||
51 | + * @version: v1.0.0 | ||
52 | + * @author: wangbiao | ||
53 | + * @date: 2017年8月31日 下午3:05:03 | ||
54 | + * Modification History: | ||
55 | + * Date Author Version Description | ||
56 | + *---------------------------------------------------------* | ||
57 | + * 2017年8月31日 wangbiao v1.0.0 创建 | ||
58 | + */ | ||
59 | +@RestController | ||
60 | +public class PdaController extends BizController { | ||
61 | + | ||
62 | + private static final Logger logger = LoggerFactory.getLogger(InOutParkStatisticController.class); | ||
63 | + | ||
64 | + @Autowired | ||
65 | + private TpPPdaService tpPPdaService; | ||
66 | + | ||
67 | + @Value("${project.syscode}") | ||
68 | + private String sysCode; | ||
69 | + | ||
70 | + @ApiOperation("PDA信息信息") | ||
71 | + @PostMapping("/queryPdaInfo4pabe") | ||
72 | + public BizResultVO<EasyUIDataGridVO<TpPPdaDTO>> queryPdaInfo4pabe(@RequestBody TpPPdaRequest tpPPdaRequest, HttpServletRequest request, | ||
73 | + HttpServletResponse response){ | ||
74 | + BizResult<PageBean<TpPPdaDTO>> bizResult = new BizResult<PageBean<TpPPdaDTO>>(); | ||
75 | + try { | ||
76 | + tpPPdaRequest.setSysCode(sysCode); | ||
77 | + bizResult = tpPPdaService.queryPdaInfo4pabe(tpPPdaRequest); | ||
78 | + if(bizResult.isSuccess()){ | ||
79 | + return returnJqGridData(bizResult, TpPPdaDTO.class); | ||
80 | + } | ||
81 | + } catch (Exception e) { | ||
82 | + logger.debug("分页查询pda信息异常:{}",bizResult.getErrMsg()); | ||
83 | + } | ||
84 | + return new BizResultVO<EasyUIDataGridVO<TpPPdaDTO>>(); | ||
85 | + } | ||
86 | + | ||
87 | + @ApiOperation("新增PDA信息信息") | ||
88 | + @PostMapping("/insertPda") | ||
89 | + public BizResultVO<Integer> insertPda(@RequestBody TpPPdaRequest tpPPdaRequest, HttpServletRequest request, | ||
90 | + HttpServletResponse response){ | ||
91 | + tpPPdaRequest.setSysCode(sysCode); | ||
92 | + BizResult<Integer> bizResult = tpPPdaService.insertPda(tpPPdaRequest); | ||
93 | + if(bizResult.isSuccess()){ | ||
94 | + return new BizResultVO<Integer>(bizResult); | ||
95 | + }else{ | ||
96 | + logger.debug("新增PDA信息信息异常 :{}",bizResult.getErrMsg()); | ||
97 | + } | ||
98 | + return new BizResultVO<Integer>(); | ||
99 | + } | ||
100 | + | ||
101 | + @ApiOperation("删除PDA信息信息") | ||
102 | + @PostMapping("/deletePda") | ||
103 | + public BizResultVO<Integer> deletePda(@RequestBody TpPPdaRequest tpPPdaRequest, HttpServletRequest request, | ||
104 | + HttpServletResponse response){ | ||
105 | + tpPPdaRequest.setSysCode(sysCode); | ||
106 | + BizResult<Integer> bizResult = tpPPdaService.deletetPda(tpPPdaRequest); | ||
107 | + if(bizResult.isSuccess()){ | ||
108 | + return new BizResultVO<Integer>(bizResult); | ||
109 | + }else{ | ||
110 | + logger.debug("删除PDA信息信息异常 :{}",bizResult.getErrMsg()); | ||
111 | + } | ||
112 | + return new BizResultVO<Integer>(); | ||
113 | + } | ||
114 | + | ||
115 | + @ApiOperation("删除PDA信息信息") | ||
116 | + @PostMapping("/deleteBatchPda") | ||
117 | + public BizResultVO<Integer> deleteBatchPda(@RequestBody TpPPdaSRequest tpPPdaSRequest, HttpServletRequest request, | ||
118 | + HttpServletResponse response){ | ||
119 | + tpPPdaSRequest.setSysCode(sysCode); | ||
120 | + BizResult<Integer> bizResult = tpPPdaService.deleteBatchPda(tpPPdaSRequest); | ||
121 | + if(bizResult.isSuccess()){ | ||
122 | + return new BizResultVO<Integer>(bizResult); | ||
123 | + }else{ | ||
124 | + logger.debug("删除PDA信息信息异常 :{}",bizResult.getErrMsg()); | ||
125 | + } | ||
126 | + return new BizResultVO<Integer>(); | ||
127 | + } | ||
128 | + | ||
129 | + @ApiOperation("根据id查询PDA信息") | ||
130 | + @PostMapping("/queryPdaById") | ||
131 | + public BizResultVO<TpPPdaDTO> queryPdaById(@RequestBody TpPPdaRequest tpPPdaRequest, HttpServletRequest request, | ||
132 | + HttpServletResponse response){ | ||
133 | + tpPPdaRequest.setSysCode(sysCode); | ||
134 | + BizResult<TpPPdaDTO> bizResult = tpPPdaService.queryPdaById(tpPPdaRequest); | ||
135 | + if(bizResult.isSuccess()){ | ||
136 | + return new BizResultVO<TpPPdaDTO>(bizResult); | ||
137 | + }else{ | ||
138 | + logger.debug("根据id查询PDA信息异常 :{}",bizResult.getErrMsg()); | ||
139 | + } | ||
140 | + return new BizResultVO<TpPPdaDTO>(); | ||
141 | + } | ||
142 | + | ||
143 | + @ApiOperation("修改PDA信息") | ||
144 | + @PostMapping("/updatePda") | ||
145 | + public BizResultVO<Integer> updatePda(@RequestBody TpPPdaRequest tpPPdaRequest, HttpServletRequest request, | ||
146 | + HttpServletResponse response){ | ||
147 | + tpPPdaRequest.setSysCode(sysCode); | ||
148 | + BizResult<Integer> bizResult = tpPPdaService.updatePda(tpPPdaRequest); | ||
149 | + if(bizResult.isSuccess()){ | ||
150 | + return new BizResultVO<Integer>(bizResult); | ||
151 | + }else{ | ||
152 | + logger.debug("修改PDA信息异常 :{}",bizResult.getErrMsg()); | ||
153 | + } | ||
154 | + return new BizResultVO<Integer>(); | ||
155 | + } | ||
156 | + | ||
157 | + @ApiOperation("pda信息导出excel") | ||
158 | + @GetMapping("exportpdaExcel") | ||
159 | + public void exportBerthInfoExcel(@RequestBody TpPPdaRequest tpPPdaRequest, HttpServletRequest requests, HttpServletResponse response) { | ||
160 | + tpPPdaRequest.setSysCode(sysCode); | ||
161 | + BizResult<List<TpPPdaDTO>> list = tpPPdaService.queryPdaInfo(tpPPdaRequest); | ||
162 | + String[] title = new String[] { "序号","设备编号", "设备名称", "设备类型", "状态","持有人","资源描述" }; | ||
163 | + String sheetName = "PDA信息"; | ||
164 | + String fileName = sheetName+DateUtil.getDate(); | ||
165 | + // 1.创建excel信息 | ||
166 | + XSSFSheet workSheet = ExcelUtil.createExcel(fileName); | ||
167 | + // 2.设置excel表头和表体 | ||
168 | + Layouter.buildReport(workSheet, title, 0, 0); | ||
169 | + // 3.填充数据 | ||
170 | + List<Object[]> contentList = new ArrayList<Object[]>(); | ||
171 | + int number = 1; | ||
172 | + if(list.isSuccess() && CollectionUtil.isNotEmpty(list.getData())){ | ||
173 | + for (TpPPdaDTO b : list.getData()) { | ||
174 | + Object[] obj = new Object[title.length]; | ||
175 | + int index = 0; | ||
176 | + obj[index++] = number++; | ||
177 | + obj[index++] = b.getId(); | ||
178 | + obj[index++] = b.getPdaNo(); | ||
179 | + obj[index++] = b.getPdaName(); | ||
180 | + obj[index++] = b.getPdaType(); | ||
181 | + obj[index++] = b.getPdaStatus(); | ||
182 | + obj[index++] = b.getOwnerName(); | ||
183 | + obj[index++] = b.getRemark(); | ||
184 | + contentList.add(obj); | ||
185 | + } | ||
186 | + } | ||
187 | + ExcleFillDateManager fillUserManager = new ExcleFillDateManager(); | ||
188 | + fillUserManager.fillSalesOrga(workSheet, title, contentList, 2); | ||
189 | + // 4.excel输出配置 | ||
190 | + ExcelUtil.write(response, workSheet, fileName); | ||
191 | + } | ||
192 | + | ||
193 | + | ||
194 | + @ApiOperation("pda信息 导入模板下载") | ||
195 | + @GetMapping("exportpdaExcel") | ||
196 | + public void exportModelExcel(HttpServletRequest requests, HttpServletResponse response) { | ||
197 | + String[] title = new String[] { "设备编号", "设备名称", "设备类型","停车场编号","sim卡号","持有人编号","持有人名称","状态","资源描述" }; | ||
198 | + String fileName = "PDA信息导入模板"; | ||
199 | + // 1.创建excel信息 | ||
200 | + XSSFSheet workSheet = ExcelUtil.createExcel(fileName); | ||
201 | + // 2.设置excel表头和表体 | ||
202 | + Layouter.buildReport(workSheet, title, 0, 0); | ||
203 | + // 3.填充数据 | ||
204 | + ExcleFillDateManager fillUserManager = new ExcleFillDateManager(); | ||
205 | + fillUserManager.fillSalesOrga(workSheet, title, null, 2); | ||
206 | + // 4.excel输出配置 | ||
207 | + ExcelUtil.write(response, workSheet, fileName); | ||
208 | + } | ||
209 | + | ||
210 | + | ||
211 | + @PostMapping("/importPda") | ||
212 | + public BizResultVO<Integer> importPda(@RequestParam(value="excelFile") MultipartFile file,HttpServletRequest request) throws IOException{ | ||
213 | + if(file==null){ | ||
214 | + throw new BizException(ErrorType.PARAMM_NULL, "导入文件不能为空"); | ||
215 | + } | ||
216 | + //读取Excel数据到List中 | ||
217 | + List<ArrayList<String>> list = ExcelReadUtil.readExcel(file); | ||
218 | + //list中存的就是excel中的数据,可以根据excel中每一列的值转换成你所需要的值(从0开始),如: | ||
219 | + TpPPdaRequest tpPPdaRequest = null; | ||
220 | + List<TpPPdaRequest> padList = Lists.newArrayList(); | ||
221 | + for(ArrayList<String> arr:list){ | ||
222 | + tpPPdaRequest= new TpPPdaRequest(); | ||
223 | + tpPPdaRequest.setPdaNo(arr.get(0)); | ||
224 | + padList.add(tpPPdaRequest); | ||
225 | + } | ||
226 | + TpPPdaSRequest TpPPdaSRequest = new TpPPdaSRequest(); | ||
227 | + TpPPdaSRequest.setPadList(padList); | ||
228 | + BizResult<Integer> rsInteger = tpPPdaService.insertBatchPda(TpPPdaSRequest); | ||
229 | + return new BizResultVO<Integer>(rsInteger); | ||
230 | + } | ||
231 | + | ||
232 | +} |