|
@@ -1,20 +1,37 @@
|
|
package com.jpsoft.bus.modules.bus.controller;
|
|
package com.jpsoft.bus.modules.bus.controller;
|
|
|
|
|
|
import com.github.pagehelper.Page;
|
|
import com.github.pagehelper.Page;
|
|
|
|
+import com.jpsoft.bus.config.OSSConfig;
|
|
|
|
+import com.jpsoft.bus.modules.bus.entity.CompanyInfo;
|
|
|
|
+import com.jpsoft.bus.modules.bus.entity.RouteInfo;
|
|
|
|
+import com.jpsoft.bus.modules.bus.entity.StationInfo;
|
|
|
|
+import com.jpsoft.bus.modules.bus.service.RouteInfoService;
|
|
|
|
+import com.jpsoft.bus.modules.bus.service.StationInfoService;
|
|
import com.jpsoft.bus.modules.common.dto.MessageResult;
|
|
import com.jpsoft.bus.modules.common.dto.MessageResult;
|
|
import com.jpsoft.bus.modules.common.dto.Sort;
|
|
import com.jpsoft.bus.modules.common.dto.Sort;
|
|
import com.jpsoft.bus.modules.bus.entity.PriceInfo;
|
|
import com.jpsoft.bus.modules.bus.entity.PriceInfo;
|
|
import com.jpsoft.bus.modules.bus.service.PriceInfoService;
|
|
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.common.utils.PojoUtils;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
+import org.joda.time.DateTime;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
|
+import java.math.BigDecimal;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
@@ -29,6 +46,12 @@ public class PriceInfoController {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private PriceInfoService priceInfoService;
|
|
private PriceInfoService priceInfoService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private StationInfoService stationInfoService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private RouteInfoService routeInfoService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private OSSConfig ossConfig;
|
|
|
|
|
|
@ApiOperation(value="创建空记录")
|
|
@ApiOperation(value="创建空记录")
|
|
@GetMapping("create")
|
|
@GetMapping("create")
|
|
@@ -225,4 +248,191 @@ public class PriceInfoController {
|
|
|
|
|
|
return msgResult;
|
|
return msgResult;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="占点金额")
|
|
|
|
+ @RequestMapping(value = "searchRoutePrice",method = RequestMethod.POST)
|
|
|
|
+ public Map<String,Object> searchRoutePrice(
|
|
|
|
+ @RequestParam(value="routeId",defaultValue="") String routeId,
|
|
|
|
+ @RequestAttribute String subject){
|
|
|
|
+
|
|
|
|
+ Map<String,Object> dataMap = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ Map<String,Object> searchParams = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ try{
|
|
|
|
+ //查询所有站点
|
|
|
|
+ List<StationInfo> stationInfoList = stationInfoService.findByRouteId(routeId);
|
|
|
|
+ List<Map> stationMap = new ArrayList<>();
|
|
|
|
+ List<Map> stationPriceColumns = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ for (StationInfo startSi : stationInfoList){
|
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
|
+ List<Map> priceList = new ArrayList<>();
|
|
|
|
+ Map<String,Map> stationPriceMap = new HashMap<>();
|
|
|
|
+ for(StationInfo endSi : stationInfoList){
|
|
|
|
+ Map<String,Object> priceMap = new HashMap<>();
|
|
|
|
+ PriceInfo priceInfo = priceInfoService.findByStartStationAndEndStation(startSi.getId(),endSi.getId());
|
|
|
|
+ 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();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ priceMap.put("price",price);
|
|
|
|
+ priceList.add(priceMap);
|
|
|
|
+ stationPriceMap.put(endSi.getId(),priceMap);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ map.put("id",startSi.getId());
|
|
|
|
+ map.put("name",startSi.getName());
|
|
|
|
+ map.put("priceList",priceList);
|
|
|
|
+ map.put("stationPriceMap",stationPriceMap);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ stationMap.add(map);
|
|
|
|
+ stationPriceColumns.add(map);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ dataMap.put("stationPriceColumns", stationPriceColumns);
|
|
|
|
+ dataMap.put("stationInfoList", stationMap);
|
|
|
|
+
|
|
|
|
+ }catch (Exception ex){
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return dataMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="导入线路")
|
|
|
|
+ @PostMapping("importXls")
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
+ @ApiImplicitParam(name = "uploadFile",value = "上传文件", required = true,paramType="form", dataType = "__file")
|
|
|
|
+ })
|
|
|
|
+ public MessageResult<String> importXls(
|
|
|
|
+ MultipartFile uploadFile,
|
|
|
|
+ @RequestParam(value="routeId",defaultValue="") String routeId,
|
|
|
|
+ @RequestAttribute String subject){
|
|
|
|
+ MessageResult<String> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+
|
|
|
|
+ if(StringUtils.isEmpty(routeId)){
|
|
|
|
+ throw new Exception("线路查询失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ RouteInfo routeInfo = routeInfoService.get(routeId);
|
|
|
|
+ if(routeInfo == null){
|
|
|
|
+ throw new Exception("线路不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ POIUtils poiUtils = new POIUtils(uploadFile.getInputStream());
|
|
|
|
+ int sheetIndex = 0;
|
|
|
|
+ Sheet sheet1 = poiUtils.getSheetAt(sheetIndex);
|
|
|
|
+
|
|
|
|
+ int affectCount = 0;
|
|
|
|
+ int failCount = 0;
|
|
|
|
+ int validateColIndex = 10;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Map<Integer,String> heardMap = new HashMap<Integer,String>();
|
|
|
|
+ //查第一列 表头的站点名称名称 -- 终点站
|
|
|
|
+ if(sheet1.getLastRowNum() > 0){
|
|
|
|
+ int coloumNum = sheet1.getRow(0).getPhysicalNumberOfCells();
|
|
|
|
+ for(int i = 1;i<coloumNum;i++){
|
|
|
|
+ String endName = (String)poiUtils.getCellValue(sheetIndex,0,i).toString().replace(" ","");
|
|
|
|
+ heardMap.put(i,endName);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ for(int rowIndex=0 ; rowIndex<=sheet1.getLastRowNum(); rowIndex++){
|
|
|
|
+ try {
|
|
|
|
+ //第一列为起点站点
|
|
|
|
+ String startName = (String)poiUtils.getCellValue(sheetIndex,rowIndex,0).toString().replace(" ","");
|
|
|
|
+ StationInfo startInfo = stationInfoService.findByRouteIdAndName(routeId,startName);
|
|
|
|
+ if(startInfo == null){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for(int endIndex = 1;endIndex <heardMap.size();endIndex++){
|
|
|
|
+ String endName = heardMap.get(endIndex);
|
|
|
|
+ StationInfo endInfo = stationInfoService.findByRouteIdAndName(routeId,endName);
|
|
|
|
+ if(endInfo == null){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ PriceInfo pi = priceInfoService.findByStartStationAndEndStation(startInfo.getId(),endInfo.getId());
|
|
|
|
+
|
|
|
|
+ String price = (String)poiUtils.getCellValue(sheetIndex,rowIndex,endIndex).toString().replace(" ","");
|
|
|
|
+
|
|
|
|
+ if(pi == null){
|
|
|
|
+ pi = new PriceInfo();
|
|
|
|
+ pi.setId(UUID.randomUUID().toString());
|
|
|
|
+ pi.setPrice(new BigDecimal(price));
|
|
|
|
+ pi.setStartStationId(startInfo.getId());
|
|
|
|
+ pi.setEndStationId(endInfo.getId());
|
|
|
|
+
|
|
|
|
+ pi.setDelFlag(false);
|
|
|
|
+ pi.setCreateBy(subject);
|
|
|
|
+ pi.setCreateTime(new Date());
|
|
|
|
+ priceInfoService.insert(pi);
|
|
|
|
+ }else{
|
|
|
|
+ pi.setPrice(new BigDecimal(price));
|
|
|
|
+
|
|
|
|
+ pi.setDelFlag(false);
|
|
|
|
+ pi.setUpdateBy(subject);
|
|
|
|
+ pi.setUpdateTime(new Date());
|
|
|
|
+ priceInfoService.update(pi);
|
|
|
|
+ }
|
|
|
|
+ affectCount++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch(Exception innerEx){
|
|
|
|
+ logger.error(innerEx.getMessage(),innerEx);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (failCount>0){
|
|
|
|
+ //有导入失败的记录
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage("数据成功导入" + affectCount + "条,有" + failCount + "条数据未导入成功,错误原因请查看报表。");
|
|
|
|
+
|
|
|
|
+ //todo 只保留错误数据的sheet
|
|
|
|
+ Workbook wb = poiUtils.exportErrorXls(sheetIndex,validateColIndex,1 + affectCount + failCount);
|
|
|
|
+
|
|
|
|
+ //todo 将wb保存到oss
|
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
|
+ wb.write(output);
|
|
|
|
+
|
|
|
|
+ byte[] buffer = output.toByteArray();
|
|
|
|
+ ByteArrayInputStream input = new ByteArrayInputStream(buffer);
|
|
|
|
+
|
|
|
|
+ String downloadUrl = OSSUtil.upload(ossConfig,"import","error.xls",input);
|
|
|
|
+
|
|
|
|
+ //todo 返回导入失败报表下载链接
|
|
|
|
+ msgResult.setData(downloadUrl);
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setMessage("数据成功导入" + affectCount + "条");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch(Exception ex){
|
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
}
|
|
}
|