|
@@ -14,6 +14,8 @@ import com.jpsoft.bus.modules.bus.service.PriceInfoService;
|
|
|
import com.jpsoft.bus.modules.common.utils.OSSUtil;
|
|
|
import com.jpsoft.bus.modules.common.utils.POIUtils;
|
|
|
import com.jpsoft.bus.modules.common.utils.PojoUtils;
|
|
|
+import com.jpsoft.bus.modules.sys.entity.User;
|
|
|
+import com.jpsoft.bus.modules.sys.service.UserService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
@@ -21,6 +23,10 @@ import io.swagger.annotations.ApiOperation;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.joda.time.DateTime;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -51,6 +57,8 @@ public class PriceInfoController {
|
|
|
@Autowired
|
|
|
private RouteInfoService routeInfoService;
|
|
|
@Autowired
|
|
|
+ private UserService userService;
|
|
|
+ @Autowired
|
|
|
private OSSConfig ossConfig;
|
|
|
|
|
|
@ApiOperation(value="创建空记录")
|
|
@@ -249,7 +257,7 @@ public class PriceInfoController {
|
|
|
return msgResult;
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value="占点金额")
|
|
|
+ @ApiOperation(value="站点价格图列表")
|
|
|
@RequestMapping(value = "searchRoutePrice",method = RequestMethod.POST)
|
|
|
public Map<String,Object> searchRoutePrice(
|
|
|
@RequestParam(value="routeId",defaultValue="") String routeId,
|
|
@@ -273,17 +281,13 @@ public class PriceInfoController {
|
|
|
for(StationInfo endSi : stationInfoList){
|
|
|
Map<String,Object> priceMap = new HashMap<>();
|
|
|
PriceInfo priceInfo = priceInfoService.findByStartStationAndEndStation(startSi.getId(),endSi.getId());
|
|
|
- BigDecimal price = new BigDecimal(0);
|
|
|
+ String priceStr = "无";
|
|
|
+ //BigDecimal price = new BigDecimal(0);
|
|
|
if(priceInfo != null){
|
|
|
- price = priceInfo.getPrice();
|
|
|
- }else {
|
|
|
- PriceInfo priceInfo2 = priceInfoService.findByStartStationAndEndStation(endSi.getId(), startSi.getId());
|
|
|
- if(priceInfo2 != null){
|
|
|
- price = priceInfo2.getPrice();
|
|
|
- }
|
|
|
+ priceStr = priceInfo.getPrice().toString();
|
|
|
}
|
|
|
|
|
|
- priceMap.put("price",price);
|
|
|
+ priceMap.put("price",priceStr);
|
|
|
priceList.add(priceMap);
|
|
|
stationPriceMap.put(endSi.getId(),priceMap);
|
|
|
}
|
|
@@ -363,7 +367,7 @@ public class PriceInfoController {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- for(int endIndex = 1;endIndex <heardMap.size();endIndex++){
|
|
|
+ for(int endIndex = 1;endIndex <=heardMap.size();endIndex++){
|
|
|
String endName = heardMap.get(endIndex);
|
|
|
StationInfo endInfo = stationInfoService.findByRouteIdAndName(routeId,endName);
|
|
|
if(endInfo == null){
|
|
@@ -416,7 +420,10 @@ public class PriceInfoController {
|
|
|
byte[] buffer = output.toByteArray();
|
|
|
ByteArrayInputStream input = new ByteArrayInputStream(buffer);
|
|
|
|
|
|
- String downloadUrl = OSSUtil.upload(ossConfig,"import","error.xls",input);
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
+ String fileName = "error" + sdf.format(new Date()) + ".xls";
|
|
|
+
|
|
|
+ String downloadUrl = OSSUtil.upload(ossConfig,"import",fileName,input);
|
|
|
|
|
|
//todo 返回导入失败报表下载链接
|
|
|
msgResult.setData(downloadUrl);
|
|
@@ -435,4 +442,90 @@ public class PriceInfoController {
|
|
|
|
|
|
return msgResult;
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation(value="导出人员")
|
|
|
+ @PostMapping("exportXls")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "routeId", value = "线路Id", required = false, paramType = "form", dataType = "String"),
|
|
|
+ })
|
|
|
+ public MessageResult<String> exportXls(
|
|
|
+ @RequestParam(value="routeId",defaultValue="") String routeId,
|
|
|
+ @RequestAttribute String subject){
|
|
|
+ MessageResult<String> msgResult = new MessageResult<>();
|
|
|
+ User user = userService.get(subject);
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ if(StringUtils.isEmpty(routeId)){
|
|
|
+ throw new Exception("线路查询失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ RouteInfo routeInfo = routeInfoService.get(routeId);
|
|
|
+ if(routeInfo == null){
|
|
|
+ throw new Exception("线路不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ //站点
|
|
|
+ List<StationInfo> stationInfoList = stationInfoService.findByRouteId(routeId);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook();
|
|
|
+ XSSFSheet sheet = workbook.createSheet();
|
|
|
+ //表头
|
|
|
+ XSSFRow rowTitle = sheet.createRow(0);
|
|
|
+ XSSFCell cellTitle1 = rowTitle.createCell(0);
|
|
|
+ cellTitle1.setCellValue("站点");
|
|
|
+
|
|
|
+ //标题列
|
|
|
+ for(int i=0;i<stationInfoList.size();i++){
|
|
|
+ StationInfo startStation = stationInfoList.get(i);
|
|
|
+ XSSFCell cellTitle = rowTitle.createCell(i+1);
|
|
|
+ cellTitle.setCellValue(startStation.getName());
|
|
|
+
|
|
|
+ XSSFRow rowContent = sheet.createRow(i + 1);
|
|
|
+
|
|
|
+ XSSFCell cellContent1 = rowContent.createCell(0);
|
|
|
+ cellContent1.setCellValue(startStation.getName());
|
|
|
+
|
|
|
+ //第二列开始
|
|
|
+ for(int j=0; j<stationInfoList.size(); j++){
|
|
|
+ StationInfo endStation = stationInfoList.get(j);
|
|
|
+ PriceInfo priceInfo = priceInfoService.findByStartStationAndEndStation(startStation.getId(),endStation.getId());
|
|
|
+
|
|
|
+ XSSFCell cellContent2 = rowContent.createCell(j+1);
|
|
|
+ String priceStr = "无";
|
|
|
+ if(priceInfo != null) {
|
|
|
+ priceStr = priceInfo.getPrice().toString();
|
|
|
+ }
|
|
|
+ cellContent2.setCellValue(priceStr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //todo 将wb保存到oss
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
+ workbook.write(output);
|
|
|
+
|
|
|
+ byte[] buffer = output.toByteArray();
|
|
|
+ ByteArrayInputStream input = new ByteArrayInputStream(buffer);
|
|
|
+
|
|
|
+ //格式化
|
|
|
+ SimpleDateFormat sim = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
+ String fileName = "导出数据" + sim.format(new Date()) + ".xlsx";
|
|
|
+ String downloadUrl = OSSUtil.upload(ossConfig,"import",fileName,input);
|
|
|
+
|
|
|
+ //todo 返回导入失败报表下载链接
|
|
|
+
|
|
|
+ msgResult.setData(downloadUrl);
|
|
|
+ msgResult.setResult(true);
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
}
|