fllmoyu 4 роки тому
батько
коміт
feec1651d5

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

@@ -15,4 +15,6 @@ public interface PassengerInfoDAO {
 	int delete(String id);
 	List<PassengerInfo> list();
 	List<PassengerInfo> search(Map<String,Object> searchParams,List<Sort> sortList);
+
+    List<PassengerInfo> findByPersonIdShiftIdStatus(Long personId, String shiftId, String status);
 }

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

@@ -55,7 +55,7 @@ public class PassengerInfo {
 	    @ApiModelProperty(value = "更新时间")
     private Date updateTime;
         @ApiModelProperty(value = "是否删除")
-    private Boolean delFlag;
+    private Boolean delFlag = false;
 
     @ApiModelProperty(value = "注册用户名")
     private String userName;

+ 10 - 0
common/src/main/java/com/jpsoft/bus/modules/bus/service/BaiduService.java

@@ -8,4 +8,14 @@ public interface BaiduService {
 
 
     void faceSearch(String faceImageUrl,String faceType,String groupId) throws Exception;
+
+    /**
+     * 创建人脸用户组
+     * @param faceGroupId
+     * @throws Exception
+     */
+    void createFaceGroup(String faceGroupId) throws Exception;
+
+
+    void faceUserAdd(String imageUrl,String groupId,String personId,String userInfo) throws Exception;
 }

+ 6 - 0
common/src/main/java/com/jpsoft/bus/modules/bus/service/PassengerInfoService.java

@@ -4,6 +4,8 @@ import java.util.List;
 import java.util.Map;
 import com.jpsoft.bus.modules.bus.entity.PassengerInfo;
 import com.github.pagehelper.Page;
+import com.jpsoft.bus.modules.bus.entity.ShiftInfo;
+import com.jpsoft.bus.modules.bus.entity.VehicleInfo;
 import com.jpsoft.bus.modules.common.dto.Sort;
 
 public interface PassengerInfoService {
@@ -14,4 +16,8 @@ public interface PassengerInfoService {
 	int delete(String id);
 	List<PassengerInfo> list();
 	Page<PassengerInfo> pageSearch(Map<String, Object> searchParams,int pageNum,int pageSize,boolean count,List<Sort> sortList);
+
+	List<PassengerInfo> findByPersonIdShiftIdStatus(Long personId,String shiftId,String status);
+
+    void passengerFace(VehicleInfo vehicleInfo, ShiftInfo shiftInfo, String retFileUrl, String recordTime, String stationId,String personId) throws Exception;
 }

+ 68 - 6
common/src/main/java/com/jpsoft/bus/modules/bus/service/impl/BaiduServiceImpl.java

@@ -1,6 +1,8 @@
 package com.jpsoft.bus.modules.bus.service.impl;
 
 import cn.hutool.http.HttpRequest;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
 import com.jpsoft.bus.modules.bus.service.BaiduService;
 import com.jpsoft.bus.modules.common.utils.BaiduAuthUtil;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -27,21 +29,81 @@ public class BaiduServiceImpl implements BaiduService {
 
         // 请求url
         String url = "https://aip.baidubce.com/rest/2.0/face/v3/search";
-        Map<String, Object> map1 = new HashMap<>();
-        map1.put("image",faceImageUrl);
-        map1.put("image_type", faceType);
-        map1.put("group_id_list",groupId);
-        map1.put("max_user_num",3);
+        Map<String, Object> map = new HashMap<>();
+        map.put("image",faceImageUrl);
+        map.put("image_type", faceType);
+        map.put("group_id_list",groupId);
+        map.put("max_user_num",3);
 
         // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。
         String accessToken = baiduAuthUtil.getAuth();
 
         String body = HttpRequest.post(url+"?access_token="+accessToken)
-                .form(map1)
+                .form(map)
                 .execute()
                 .body();
 
 
 
+    }
+
+    @Override
+    public void createFaceGroup(String faceGroupId) throws Exception {
+        // 请求url
+        String url = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/group/add";
+
+        Map<String, Object> map = new HashMap<>();
+        map.put("group_id", faceGroupId);
+
+        // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。
+        String accessToken = baiduAuthUtil.getAuth();
+
+        String body = HttpRequest.post(url+"?access_token="+accessToken)
+                .form(map)
+                .execute()
+                .body();
+
+        JSONObject jsonObject = JSONUtil.parseObj(body);
+
+        String errorMsg = jsonObject.getStr("error_msg");
+        Integer errorCode = jsonObject.getInt("error_code");
+        if (!"SUCCESS".equals(errorMsg)){
+            if (errorCode != 223101){
+                throw new Exception(errorMsg);
+            }
+        }
+
+
+    }
+
+    @Override
+    public void faceUserAdd(String imageUrl, String groupId, String personId,String userInfo) throws Exception {
+
+        // 请求url
+        String url = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/add";
+
+        Map<String, Object> map = new HashMap<>();
+        map.put("image",imageUrl);
+        map.put("image_type", "URL");
+        map.put("group_id",groupId);
+        map.put("user_id",personId);
+        map.put("user_info",userInfo);
+
+        // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。
+        String accessToken = baiduAuthUtil.getAuth();
+
+        String body = HttpRequest.post(url+"?access_token="+accessToken)
+                .form(map)
+                .execute()
+                .body();
+        JSONObject jsonObject = JSONUtil.parseObj(body);
+        String errorMsg = jsonObject.getStr("error_msg");
+        Integer errorCode = jsonObject.getInt("error_code");
+        if (!"SUCCESS".equals(errorMsg)){
+            if (errorCode != 223105){
+                throw new Exception(errorMsg);
+            }
+        }
+
     }
 }

+ 58 - 6
common/src/main/java/com/jpsoft/bus/modules/bus/service/impl/PassengerInfoServiceImpl.java

@@ -1,9 +1,18 @@
 package com.jpsoft.bus.modules.bus.service.impl;
 
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 import javax.annotation.Resource;
+
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.StrUtil;
+import com.jpsoft.bus.modules.bus.entity.ShiftInfo;
+import com.jpsoft.bus.modules.bus.entity.VehicleInfo;
+import com.jpsoft.bus.modules.bus.service.BaiduService;
+import com.jpsoft.bus.modules.common.utils.CommonUtil;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
 import com.jpsoft.bus.modules.bus.dao.PassengerInfoDAO;
@@ -19,6 +28,9 @@ public class PassengerInfoServiceImpl implements PassengerInfoService {
 	@Resource(name="passengerInfoDAO")
 	private PassengerInfoDAO passengerInfoDAO;
 
+	@Autowired
+	private BaiduService baiduService;
+
 	@Override
 	public PassengerInfo get(String id) {
 		// TODO Auto-generated method stub
@@ -29,14 +41,14 @@ public class PassengerInfoServiceImpl implements PassengerInfoService {
 	public int insert(PassengerInfo model) {
 		// TODO Auto-generated method stub
 		//model.setId(UUID.randomUUID().toString());
-		
+
 		return passengerInfoDAO.insert(model);
 	}
 
 	@Override
 	public int update(PassengerInfo model) {
 		// TODO Auto-generated method stub
-		return passengerInfoDAO.update(model);		
+		return passengerInfoDAO.update(model);
 	}
 
 	@Override
@@ -49,22 +61,62 @@ public class PassengerInfoServiceImpl implements PassengerInfoService {
 	public boolean exist(String id) {
 		// TODO Auto-generated method stub
 		int count = passengerInfoDAO.exist(id);
-		
+
 		return count > 0 ? true : false;
 	}
-	
+
 	@Override
 	public List<PassengerInfo> list() {
 		// TODO Auto-generated method stub
 		return passengerInfoDAO.list();
 	}
-		
+
 	@Override
 	public Page<PassengerInfo> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
         Page<PassengerInfo> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
             passengerInfoDAO.search(searchParams,sortList);
         });
-        
+
         return page;
 	}
+
+	@Override
+	public List<PassengerInfo> findByPersonIdShiftIdStatus(Long personId, String shiftId, String status) {
+		return passengerInfoDAO.findByPersonIdShiftIdStatus(personId,shiftId,status);
+	}
+
+	@Override
+	public void passengerFace(VehicleInfo vehicleInfo, ShiftInfo shiftInfo, String retFileUrl, String recordTime, String stationId,String personId) throws Exception {
+
+		Date recordDate = DateUtil.parse(recordTime,"yyyy-MM-dd HH:mm:ss");
+		//查询是否有已上车的乘客记录
+		List<PassengerInfo> passengerInfoList = findByPersonIdShiftIdStatus(Long.parseLong(personId),shiftInfo.getId(),"1");
+
+		if (passengerInfoList.size()>0){
+			PassengerInfo passengerInfo = passengerInfoList.get(0);
+			passengerInfo.setDownTime(recordDate);
+			passengerInfo.setDownStationId(stationId);
+			passengerInfo.setStatus("2");
+			update(passengerInfo);
+		}
+		else {
+			PassengerInfo passengerInfo = new PassengerInfo();
+			passengerInfo.setId(UUID.randomUUID().toString());
+			passengerInfo.setVehicleShiftId(shiftInfo.getId());
+			passengerInfo.setVehiclePersonId(Long.parseLong(personId));
+			passengerInfo.setImageUrl(retFileUrl);
+			passengerInfo.setUpTime(recordDate);
+			passengerInfo.setUpStationId(stationId);
+			passengerInfo.setStatus("1");
+			passengerInfo.setPayStatus("0");
+			passengerInfo.setCreateTime(new Date());
+			insert(passengerInfo);
+
+			String groupId = CommonUtil.getProvinceNum(vehicleInfo.getLicensePlateNumber()) + StrUtil.sub(vehicleInfo.getLicensePlateNumber(),1,10);
+			//将图片上传到百度AI人脸识别,  userInfo 1:司机,2:乘客
+			baiduService.faceUserAdd(retFileUrl,groupId,personId,"2");
+
+
+		}
+	}
 }

+ 24 - 2
common/src/main/resources/mapper/bus/PassengerInfo.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.PassengerInfoDAO">
@@ -126,7 +126,7 @@
 		]]>
 		<where>
 			a.del_flag = 0
-			<if test="seauserNamerchParams.id != null">
+			<if test="searchParams.id != null">
 				and a.ID_ like #{searchParams.id}
 			</if>
 			<if test="searchParams.vehiclePersonId != null">
@@ -141,9 +141,31 @@
 			<if test="searchParams.payStatus != null">
 				and a.pay_status = #{searchParams.payStatus}
 			</if>
+			<if test="searchParams.vehicleShiftId != null">
+				and a.vehicle_shift_id = #{searchParams.vehicleShiftId}
+			</if>
+			<if test="searchParams.status != null">
+				and a.status_ = #{searchParams.status}
+			</if>
+			<if test="searchParams.notPayStatus != null">
+				and a.pay_status != #{searchParams.notPayStatus}
+			</if>
+			<if test="searchParams.downStationId != null">
+				and a.down_station_id = #{searchParams.downStationId}
+			</if>
 		</where>
 		<foreach item="sort" collection="sortList"  open="order by" separator=",">
 	        ${sort.name} ${sort.order}
 	 	</foreach>
 	</select>
+
+	<select id="findByPersonIdShiftIdStatus" resultMap="PassengerInfoMap">
+		<![CDATA[
+		select * from bus_passenger_info
+		where del_flag = 0
+		and vehicle_person_id = #{personId}
+		and vehicle_shift_id = #{shiftId}
+		and status_ = #{status}
+		]]>
+	</select>
 </mapper>

+ 68 - 7
web/src/main/java/com/jpsoft/bus/modules/driver/controller/DriverApiController.java

@@ -1,13 +1,18 @@
 package com.jpsoft.bus.modules.driver.controller;
 
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.StrUtil;
+import com.github.pagehelper.Page;
 import com.jpsoft.bus.config.OSSConfig;
 import com.jpsoft.bus.modules.bus.dto.StationStatusDTO;
 import com.jpsoft.bus.modules.bus.entity.*;
 import com.jpsoft.bus.modules.bus.service.*;
 import com.jpsoft.bus.modules.common.dto.MessageResult;
+import com.jpsoft.bus.modules.common.dto.Sort;
+import com.jpsoft.bus.modules.common.utils.CommonUtil;
 import com.jpsoft.bus.modules.common.utils.JwtUtil;
 import com.jpsoft.bus.modules.common.utils.OSSUtil;
+import com.jpsoft.bus.modules.common.utils.PojoUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -43,9 +48,15 @@ public class DriverApiController {
     @Autowired
     private ShiftInfoService shiftInfoService;
 
+    @Autowired
+    private BaiduService baiduService;
+
     @Autowired
     private GpsService gpsService;
 
+    @Autowired
+    private PassengerInfoService passengerInfoService;
+
     @Autowired
     private StationInfoService stationInfoService;
 
@@ -147,18 +158,16 @@ public class DriverApiController {
         MessageResult<DriverRecordInfo> messageResult = new MessageResult<>();
 
         try {
-            VehicleInfo vehicleInfo = vehicleInfoService.get(subject);
 
+            VehicleInfo vehicleInfo = vehicleInfoService.get(subject);
             if (vehicleInfo == null){
                 throw new Exception("当前车辆不存在");
             }
-
             DriverInfo driverInfo = driverInfoService.get(driverId);
             if (driverInfo == null){
                 throw new Exception("当前司机不存在");
             }
-
-            String retFileUrl = OSSUtil.uploadBase64(photoBase64Data,driverInfo.getName()+".jpg",ossConfig);
+            String retFileUrl = OSSUtil.uploadBase64(photoBase64Data,driverId+".jpg",ossConfig);
            // String retFileUrl = OSSUtil.upload(ossConfig, "/faceImage", driverInfo.getName(), photoFile.getInputStream());
             DriverRecordInfo driverRecordInfo = new DriverRecordInfo();
             driverRecordInfo.setId(UUID.randomUUID().toString());
@@ -365,11 +374,10 @@ public class DriverApiController {
             @ApiImplicitParam(name = "personId", value = "乘客在设备上的id", required = true, paramType = "form"),
             @ApiImplicitParam(name = "recordTime", value = "登记时间", required = true, paramType = "form"),
             @ApiImplicitParam(name = "photoBase64Data", value = "照片base64编码", required = true, paramType = "form"),
-            @ApiImplicitParam(name = "upStationId", value = "上车站点", required = true, paramType = "form"),
             @ApiImplicitParam(name = "token", value = "令牌", paramType = "form"),
             @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form")
     })
-    public MessageResult<Map> passengerFaceRegister(String personId, String photoBase64Data, String recordTime, String token, @RequestAttribute String subject) {
+    public MessageResult<Map> passengerFaceRegister(String personId, String photoBase64Data, String recordTime,String token, @RequestAttribute String subject) {
         MessageResult<Map> messageResult = new MessageResult<>();
 
         try {
@@ -385,14 +393,68 @@ public class DriverApiController {
             }
 
             ShiftInfo shiftInfo = shiftInfoList.get(0);
+            String retFileUrl = OSSUtil.uploadBase64(photoBase64Data,personId+".jpg",ossConfig);
+
+
+            passengerInfoService.passengerFace(vehicleInfo,shiftInfo,retFileUrl,recordTime,shiftInfo.getCurrentStationId(),personId);
+
+            messageResult.setResult(true);
+            messageResult.setCode(200);
+        } catch (Exception ex) {
+            messageResult.setResult(false);
+            messageResult.setMessage(ex.getMessage());
+        }
+
+        return messageResult;
+    }
 
+    @PostMapping("busShiftTicketList")
+    @ApiOperation(value = "车辆班次购票情况列表")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "token", value = "令牌", paramType = "form"),
+            @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
+            @ApiImplicitParam(name = "type", value = "1:未购票,2:待下车,3:待补票,4:全部", required = true, paramType = "form")
+    })
+    public MessageResult<Map> busShiftNoTicket(String token, @RequestAttribute String subject,@RequestParam(value = "pageIndex", defaultValue = "1") int pageIndex,@RequestParam(value = "pageSize", defaultValue = "20") int pageSize,String type) {
+        MessageResult<Map> messageResult = new MessageResult<>();
 
+        try {
+
+            VehicleInfo vehicleInfo = vehicleInfoService.get(subject);
+            if (vehicleInfo == null){
+                throw new Exception("当前车辆不存在");
+            }
 
+            List<ShiftInfo> shiftInfoList = shiftInfoService.findByVehicleIdAndStatus(vehicleInfo.getId(),"1");
+            if (shiftInfoList.size() == 0){
+                throw new Exception("车辆没有相关班次信息");
+            }
 
+            ShiftInfo shiftInfo = shiftInfoList.get(0);
+            Map<String,Object> searchParams = new HashMap<>();
+            searchParams.put("vehicleShiftId",shiftInfo.getId());
+            searchParams.put("status","1");
+            //未购票
+            if ("1".equals(type)){
+                searchParams.put("payStatus","0");
+            }
+            //待下车
+            if ("2".equals(type)){
+                searchParams.put("notPayStatus","0");
+                searchParams.put("downStationId",shiftInfo.getCurrentStationId());
+            }
+            //待补票
+            if ("3".equals(type)){
+                searchParams.put("payStatus","2");
+            }
 
 
+            List<Sort> sortList = new ArrayList<>();
+            sortList.add(new Sort("create_time","desc"));
+            Page<PassengerInfo> page = passengerInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
 
 
+            messageResult.setData(PojoUtils.pageWrapper(page));
             messageResult.setResult(true);
             messageResult.setCode(200);
         } catch (Exception ex) {
@@ -402,5 +464,4 @@ public class DriverApiController {
 
         return messageResult;
     }
-
 }

+ 3 - 3
web/src/main/resources/application-production.yml

@@ -38,9 +38,9 @@ wx:
   #荆楚云服务器内不能访问自身域名
   commonAccessTokenUrl: http://192.168.0.1:8080/weixin/token
   pay:
-    #企业联合会
-    appId: wx343bf93d2a3dc8af
-    appSecret: ac61fa669a7a79c7d2a8188ff7ddaef6
+    #车信达
+    appId: wx93675268c87a5a46
+    appSecret: 8a55e8cc8cffbf2db66f3024311036bc
 #    appId: wx0b3c41a903053808
 #    appSecret: 43557bd62f77b0c3d6670e991872f0e7
     mchId: 1500160622

+ 3 - 3
web/src/main/resources/application-test.yml

@@ -42,9 +42,9 @@ springfox:
 
 wx:
   pay:
-    #企业联合会
-    appId: wx343bf93d2a3dc8af
-    appSecret: ac61fa669a7a79c7d2a8188ff7ddaef6
+    #车信达
+    appId: wx93675268c87a5a46
+    appSecret: 8a55e8cc8cffbf2db66f3024311036bc
     token: weixin
     tokenUrl: "https://api.weixin.qq.com/cgi-bin/token"
     refreshOAuth2TokenUrl: "https://api.weixin.qq.com/sns/oauth2/refresh_token"