xiao547607 4 éve
szülő
commit
fe2b24bf4d

+ 3 - 0
common/src/main/java/com/jpsoft/bus/modules/bus/dao/PriceInfoDAO.java

@@ -17,4 +17,7 @@ public interface PriceInfoDAO {
 	List<PriceInfo> search(Map<String, Object> searchParams, List<Sort> sortList);
 
     PriceInfo findByStartStationAndEndStation(String ticketUpStationId, String ticketDownStationId);
+
+	List<PriceInfo> findByStartSid(String startStationId);
+	List<PriceInfo> findByEndSid(String endStationId);
 }

+ 2 - 0
common/src/main/java/com/jpsoft/bus/modules/bus/dao/StationInfoDAO.java

@@ -18,4 +18,6 @@ public interface StationInfoDAO {
 	List<StationInfo> search(Map<String, Object> searchParams, List<Sort> sortList);
 
     List<StationInfo> findByRouteIdAndClassify(String routeId, int classify);
+
+	StationInfo findByRouteIdAndName(String routeId, String name);
 }

+ 15 - 7
common/src/main/java/com/jpsoft/bus/modules/bus/entity/PassengerInfo.java

@@ -61,26 +61,34 @@ public class PassengerInfo {
     @ApiModelProperty(value = "注册用户名")
     private String userName;
 
+    @ApiModelProperty(value = "上车站点名称")
+    private String upStationName;
+    @ApiModelProperty(value = "下车站点名称")
+    private String downStationName;
+
     @ApiModelProperty(value = "购票的上车站点")
     private String ticketUpStationId;
 
+    @ApiModelProperty(value = "购票的上车站点名")
+    private String ticketUpStationName;
+
     @ApiModelProperty(value = "购票的下车站点")
     private String ticketDownStationId;
 
-    public String getStatusName(){
+    @ApiModelProperty(value = "购票的下车站点名")
+    private String ticketDownStationName;
+
+    public String getStatusName() {
         String statusName = "";
 
         if ("0".equals(status)) {
             statusName = "未乘车";
-        }
-        else if ("1".equals(status)) {
+        } else if ("1".equals(status)) {
             statusName = "上车";
-        }
-        else if ("2".equals(status)) {
+        } else if ("2".equals(status)) {
             statusName = "下车";
         }
-
-        return statusName;
+        return  statusName;
     }
 
     public String getPayStatusName() {

+ 2 - 0
common/src/main/java/com/jpsoft/bus/modules/bus/service/PriceInfoService.java

@@ -16,4 +16,6 @@ public interface PriceInfoService {
 	Page<PriceInfo> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize, boolean count, List<Sort> sortList);
 
     PriceInfo findByStartStationAndEndStation(String ticketUpStationId, String ticketDownStationId);
+	List<PriceInfo> findByStartSid(String startStationId);
+	List<PriceInfo> findByEndSid(String endStationId);
 }

+ 2 - 0
common/src/main/java/com/jpsoft/bus/modules/bus/service/StationInfoService.java

@@ -17,4 +17,6 @@ public interface StationInfoService {
 	Page<StationInfo> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize, boolean count, List<Sort> sortList);
 
     List<StationInfo> findByRouteIdAndClassify(String routeId, int classify);
+
+	StationInfo findByRouteIdAndName(String routeId, String name);
 }

+ 12 - 0
common/src/main/java/com/jpsoft/bus/modules/bus/service/impl/PriceInfoServiceImpl.java

@@ -68,6 +68,18 @@ public class PriceInfoServiceImpl implements PriceInfoService {
         return page;
 	}
 
+	@Override
+	public List<PriceInfo> findByStartSid(String startStationId) {
+		// TODO Auto-generated method stub
+		return priceInfoDAO.findByStartSid(startStationId);
+	}
+
+	@Override
+	public List<PriceInfo> findByEndSid(String endStationId) {
+		// TODO Auto-generated method stub
+		return priceInfoDAO.findByEndSid(endStationId);
+	}
+
 	@Override
 	public PriceInfo findByStartStationAndEndStation(String ticketUpStationId, String ticketDownStationId) {
 		return priceInfoDAO.findByStartStationAndEndStation(ticketUpStationId,ticketDownStationId);

+ 5 - 0
common/src/main/java/com/jpsoft/bus/modules/bus/service/impl/StationInfoServiceImpl.java

@@ -78,4 +78,9 @@ public class StationInfoServiceImpl implements StationInfoService {
 	public List<StationInfo> findByRouteIdAndClassify(String routeId, int classify) {
 		return stationInfoDAO.findByRouteIdAndClassify(routeId,classify);
 	}
+
+	@Override
+	public StationInfo findByRouteIdAndName(String routeId, String name){
+		return stationInfoDAO.findByRouteIdAndName(routeId,name);
+	}
 }

+ 14 - 2
common/src/main/resources/mapper/bus/PassengerInfo.xml

@@ -13,6 +13,8 @@
 			<result property="downTime" column="down_time" />
 			<result property="upStationId" column="up_station_id" />
 			<result property="downStationId" column="down_station_id" />
+			<result property="upStationName" column="up_station_name"/>
+			<result property="downStationName" column="down_station_name"/>
 			<result property="status" column="status_" />
 			<result property="payStatus" column="pay_status" />
 			<result property="createBy" column="create_by" />
@@ -23,6 +25,8 @@
 			<result property="userName" column="user_name" />
 			<result property="ticketUpStationId" column="ticket_up_station_id"/>
 			<result property="ticketDownStationId" column="ticket_down_station_id"/>
+			<result property="ticketUpStationName" column="ticket_up_station_name"/>
+			<result property="ticketDownStationName" column="ticket_down_station_name"/>
 			</resultMap>
 	<insert id="insert" parameterType="com.jpsoft.bus.modules.bus.entity.PassengerInfo">
 	<!--
@@ -129,11 +133,19 @@
 	<select id="search" parameterType="hashmap" resultMap="PassengerInfoMap">
 		<![CDATA[
 			SELECT
-				a.* ,
-				b.name_ as user_name
+				a.*,
+				b.name_ AS user_name,
+				c.name_ AS up_station_name,
+				d.name_ AS down_station_name,
+				e.name_ AS ticket_up_station_name,
+				f.name_ AS ticket_down_station_name
 			FROM
 				bus_passenger_info a
 				LEFT JOIN bus_user_info b ON a.user_id = b.id_
+				LEFT JOIN bus_station_info c ON a.up_station_id = c.id_
+				LEFT JOIN bus_station_info d ON a.down_station_id = d.id_
+				LEFT JOIN bus_station_info e ON a.ticket_up_station_id = e.id_
+				LEFT JOIN bus_station_info f ON a.ticket_down_station_id = f.id_
 		]]>
 		<where>
 			a.del_flag = 0

+ 15 - 1
common/src/main/resources/mapper/bus/PriceInfo.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <!-- namespace必须指向DAO接口 -->
 <mapper namespace="com.jpsoft.bus.modules.bus.dao.PriceInfoDAO">
@@ -78,6 +78,7 @@
 	<select id="get" parameterType="string" resultMap="PriceInfoMap">
 		select
 id_,start_station_id,end_station_id,distance_,price_,create_by,create_time,update_by,update_time,del_flag		from bus_price_info where id_=#{0}
+		select *	from bus_price_info where id_=#{0}
 	</select>
 	<select id="exist" parameterType="string" resultType="int">
 		select count(*) from bus_price_info where id_=#{0}
@@ -90,6 +91,7 @@ id_,start_station_id,end_station_id,distance_,price_,create_by,create_time,updat
 			select * from bus_price_info
 		]]>
 		<where>
+			del_flag=0
 			<if test="searchParams.id != null">
 				and ID_ like #{searchParams.id}
 			</if>
@@ -108,4 +110,16 @@ id_,start_station_id,end_station_id,distance_,price_,create_by,create_time,updat
 		limit 1
 		]]>
 	</select>
+
+	<select id="findByStartSid" resultMap="PriceInfoMap">
+		select * from bus_price_info
+		where del_flag = 0
+		and start_station_id = #{startStationId}
+	</select>
+
+	<select id="findByEndSid" resultMap="PriceInfoMap">
+		select * from bus_price_info
+		where del_flag = 0
+		and end_station_id = #{endStationId}
+	</select>
 </mapper>

+ 11 - 0
common/src/main/resources/mapper/bus/StationInfo.xml

@@ -120,4 +120,15 @@ id_,sort_no,route_id,name_,longitude_,latitude_,classify_,create_by,create_time,
 		and classify_ = #{classify}
 		]]>
 	</select>
+
+	<select id="findByRouteIdAndName" resultMap="StationInfoMap">
+		<![CDATA[
+		select * from bus_station_info
+		where del_flag = 0
+		and route_id = #{routeId}
+		and name_ = #{name}
+		limit 1
+		]]>
+	</select>
+
 </mapper>

+ 5 - 0
web/src/main/java/com/jpsoft/bus/modules/bus/controller/PassengerInfoController.java

@@ -200,6 +200,7 @@ public class PassengerInfoController {
     @ApiOperation(value="列表")
     @RequestMapping(value = "pageList",method = RequestMethod.POST)
     public MessageResult<Map> pageList(
+            @RequestParam(value="vehicleShiftId",defaultValue="") String vehicleShiftId,
             @RequestParam(value="vehiclePersonId",defaultValue="") String vehiclePersonId,
             @RequestParam(value="userName",defaultValue="") String userName,
             @RequestParam(value="payStatus",defaultValue="") String payStatus,
@@ -217,6 +218,10 @@ public class PassengerInfoController {
         List<Sort> sortList = new ArrayList<>();
         sortList.add(new Sort("a.create_time","desc"));
 
+        if (StringUtils.isNotEmpty(vehicleShiftId)) {
+            searchParams.put("vehicleShiftId",vehicleShiftId);
+        }
+
         if (StringUtils.isNotEmpty(vehiclePersonId)) {
             searchParams.put("vehiclePersonId",Long.valueOf(vehiclePersonId));
         }

+ 210 - 0
web/src/main/java/com/jpsoft/bus/modules/bus/controller/PriceInfoController.java

@@ -1,20 +1,37 @@
 package com.jpsoft.bus.modules.bus.controller;
 
 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.Sort;
 import com.jpsoft.bus.modules.bus.entity.PriceInfo;
 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 io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
 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.joda.time.DateTime;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -29,6 +46,12 @@ public class PriceInfoController {
 
     @Autowired
     private PriceInfoService priceInfoService;
+    @Autowired
+    private StationInfoService stationInfoService;
+    @Autowired
+    private RouteInfoService routeInfoService;
+    @Autowired
+    private OSSConfig ossConfig;
 
     @ApiOperation(value="创建空记录")
     @GetMapping("create")
@@ -225,4 +248,191 @@ public class PriceInfoController {
 
         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;
+    }
 }