Procházet zdrojové kódy

Merge branch 'master' of https://e.coding.net/chuanghaikeji/smartCampus/backend_code

夏文涛 před 2 roky
rodič
revize
ec1ae9a7e3

+ 1 - 1
src/main/java/com/template/AutoCode.java

@@ -56,7 +56,7 @@ public class AutoCode {
         mpg.setPackageInfo(pc);
         //4、策略配置
         StrategyConfig strategy = new StrategyConfig();
-        strategy.setInclude("smart_qrcode"); // 设置要映射的表名"smart_class","smart_grade","smart_attendance"
+        strategy.setInclude("smart_car_access"); // 设置要映射的表名"smart_class","smart_grade","smart_attendance"
         strategy.setNaming(NamingStrategy.underline_to_camel);//下划线转驼峰
         strategy.setColumnNaming(NamingStrategy.underline_to_camel);//下划线转驼峰
         strategy.setEntityLombokModel(true); // 自动lombok;

+ 7 - 0
src/main/java/com/template/api/SmartCarAccessControllerAPI.java

@@ -0,0 +1,7 @@
+package com.template.api;
+
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@RequestMapping("/auto/smart-car-access")
+public interface SmartCarAccessControllerAPI {
+}

+ 21 - 0
src/main/java/com/template/controller/SmartCarAccessController.java

@@ -0,0 +1,21 @@
+package com.template.controller;
+
+
+import com.template.api.SmartCarAccessControllerAPI;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author ceshi
+ * @since 2024-02-23
+ */
+@RestController
+public class SmartCarAccessController implements SmartCarAccessControllerAPI {
+
+}
+

+ 10 - 0
src/main/java/com/template/controller/SmartFaceDiscernController.java

@@ -6,13 +6,16 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.template.api.SmartCarAccessControllerAPI;
 import com.template.api.SmartFaceDiscernControllerAPI;
 import com.template.common.utils.*;
 import com.template.config.ControlConfig;
+import com.template.model.pojo.SmartCarAccess;
 import com.template.model.pojo.SmartFaceDiscern;
 import com.template.model.pojo.SmartQrcode;
 import com.template.model.pojo.SmartUser;
 import com.template.model.result.CommonResult;
+import com.template.services.SmartCarAccessService;
 import com.template.services.SmartFaceDiscernService;
 import com.template.services.SmartQrcodeService;
 import com.template.services.SmartUserService;
@@ -49,6 +52,8 @@ public class SmartFaceDiscernController implements SmartFaceDiscernControllerAPI
     @Autowired
     SmartQrcodeService smartQrcodeService;
 
+    @Autowired
+    SmartCarAccessService smartCarAccessService;
 
     @Override
     public CommonResult track(Integer id,int dateTime) {
@@ -83,10 +88,15 @@ public class SmartFaceDiscernController implements SmartFaceDiscernControllerAPI
             qrcodeWrapper.between(SmartQrcode::getCreateTime,stateTime,endTime);
             int qrcodeCount = smartQrcodeService.count(qrcodeWrapper);
 
+            LambdaQueryWrapper<SmartCarAccess> smartCarAccessWrapper=new LambdaQueryWrapper<>();
+            smartCarAccessWrapper.between(SmartCarAccess::getEnterTime,stateTime,endTime);
+            int carCount = smartCarAccessService.count(smartCarAccessWrapper);
+
             JSONObject jsonObject = new JSONObject();
             jsonObject.put("date",dateTime);
             jsonObject.put("face",faceDiscernCount);
             jsonObject.put("code",qrcodeCount);
+            jsonObject.put("car",carCount);
             jsonArray.add(jsonObject);
 
         }

+ 16 - 0
src/main/java/com/template/mapper/SmartCarAccessMapper.java

@@ -0,0 +1,16 @@
+package com.template.mapper;
+
+import com.template.model.pojo.SmartCarAccess;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author ceshi
+ * @since 2024-02-23
+ */
+public interface SmartCarAccessMapper extends BaseMapper<SmartCarAccess> {
+
+}

+ 73 - 0
src/main/java/com/template/model/pojo/SmartCarAccess.java

@@ -0,0 +1,73 @@
+package com.template.model.pojo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import java.util.Date;
+import com.baomidou.mybatisplus.annotation.Version;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableField;
+import java.io.Serializable;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author ceshi
+ * @since 2024-02-23
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value="SmartCarAccess对象", description="")
+public class SmartCarAccess implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    @ApiModelProperty(value = "索引ID")
+    private String indexId;
+
+    @ApiModelProperty(value = "状态,1:进站,2:出站")
+    private String type;
+
+    @ApiModelProperty(value = "车牌号码")
+    private String carNo;
+
+    @ApiModelProperty(value = "入场时间")
+    private String enterTime;
+
+    @ApiModelProperty(value = "入口车道名称")
+    private String enterGateName;
+
+    @ApiModelProperty(value = "创建时间")
+    @TableField(fill = FieldFill.INSERT)
+    private Date createTime;
+
+    @ApiModelProperty(value = "更新时间")
+    @TableField(fill = FieldFill.INSERT_UPDATE)
+    private Date updateTime;
+
+    @ApiModelProperty(value = "创建人员")
+    @TableField(fill = FieldFill.INSERT)
+    private String createUser;
+
+    @ApiModelProperty(value = "更新人员")
+    @TableField(fill = FieldFill.INSERT_UPDATE)
+    private String updateUser;
+
+    @ApiModelProperty(value = "逻辑删除 未删除:0;删除:1")
+    @TableField(fill = FieldFill.INSERT)
+    @TableLogic
+    private Integer deleted;
+
+
+}

+ 16 - 0
src/main/java/com/template/services/SmartCarAccessService.java

@@ -0,0 +1,16 @@
+package com.template.services;
+
+import com.template.model.pojo.SmartCarAccess;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author ceshi
+ * @since 2024-02-23
+ */
+public interface SmartCarAccessService extends IService<SmartCarAccess> {
+
+}

+ 239 - 0
src/main/java/com/template/services/impl/SmartCarAccessServiceImpl.java

@@ -0,0 +1,239 @@
+package com.template.services.impl;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.template.common.utils.CommonUtil;
+import com.template.common.utils.RequestUtils;
+import com.template.config.ParkConfig;
+import com.template.model.pojo.SmartCarAccess;
+import com.template.mapper.SmartCarAccessMapper;
+import com.template.services.SmartCarAccessService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+
+/**
+ * <p>
+ * 服务实现类
+ * </p>
+ *
+ * @author ceshi
+ * @since 2024-02-23
+ */
+@Service
+public class SmartCarAccessServiceImpl extends ServiceImpl<SmartCarAccessMapper, SmartCarAccess> implements SmartCarAccessService {
+    @Autowired
+    ParkConfig parkConfig;
+
+    private Integer page = 0;
+    private Integer size = 20;
+
+    @Scheduled(cron = "0 0/45 * * * ? ")
+    public void car() {
+        try {
+            getEnterCar(page, size);
+            getOutCar(page, size);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+
+    }
+
+
+    /**
+     * 入场车辆
+     *
+     * @param pageindex
+     * @param pagesize
+     * @throws Exception
+     */
+    public void getEnterCar(Integer pageindex, Integer pagesize) throws Exception {
+
+        String url = parkConfig.getUrl() + "Inquire/GetEnterCar";
+
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("appid", parkConfig.getAppId());
+        jsonObject.put("parkKey", parkConfig.getParkKey());
+        String rand = String.valueOf(Math.random());
+        jsonObject.put("rand", rand);
+        jsonObject.put("version", "v1.1");
+
+//        时间
+        DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        LocalDateTime now = LocalDateTime.now();
+        LocalDateTime stateTime = now.withHour(0).withMinute(0).withSecond(0);
+        LocalDateTime endTime = now.withHour(23).withMinute(59).withSecond(59);
+        String startData = stateTime.format(dateTimeFormatter1);
+        String endData = endTime.format(dateTimeFormatter1);
+//        开始时间
+        jsonObject.put("startTime", startData);
+//        jsonObject.put("startTime", "2024-01-10 00:00:00");
+//        结束时间
+        jsonObject.put("endTime", endData);
+//        jsonObject.put("endTime", "2024-01-10 23:59:59");
+
+        jsonObject.put("size", "20");
+        jsonObject.put("indexId", "0");
+        jsonObject.put("carNo", "");
+
+
+        String md5Str = "appid=" + parkConfig.getAppId() + "&endTime=" + endData + "&indexId=" + pageindex + "&parkKey=" + parkConfig.getParkKey() + "&rand=" + rand + "&size=" + pagesize + "&startTime=" + startData + "&version=v1.1" + "&" + parkConfig.getAppSecret();
+//        String md5Str = "appid=" + parkConfig.getAppId() + "&endTime=" + "2024-01-10 23:59:59" + "&indexId=" + pageindex + "&parkKey=" + parkConfig.getParkKey() + "&rand=" + rand + "&size=" + pagesize + "&startTime=" + "2024-01-10 00:00:00" + "&version=v1.1" + "&" + parkConfig.getAppSecret();
+        String sign = CommonUtil.MD5(md5Str);
+        //sign签名
+        jsonObject.put("sign", sign);
+
+        String s = RequestUtils.httpPost(url, jsonObject.toJSONString());
+        JSONObject jsonObject1 = JSONObject.parseObject(s);
+
+        JSONArray dataArray = jsonObject1.getJSONArray("data");
+
+        if (ObjectUtils.isNotEmpty(dataArray) && dataArray.size() > 0) {
+
+            for (int i = 0; i < dataArray.size(); i++) {
+
+                JSONObject data = dataArray.getJSONObject(i);
+
+                if (ObjectUtils.isNotEmpty(data)) {
+                    SmartCarAccess smartCarAccess = new SmartCarAccess();
+
+//            索引ID
+                    String indexId = data.getString("indexId");
+//          车牌号码
+                    String carNo = data.getString("carNo");
+//            入场时间
+                    String enterTime = data.getString("enterTime");
+//             入口车道名称
+                    String enterGateName = data.getString("enterGateName");
+
+                    smartCarAccess.setIndexId(indexId);
+                    smartCarAccess.setType("1");
+                    smartCarAccess.setCarNo(carNo);
+                    smartCarAccess.setEnterTime(enterTime);
+                    smartCarAccess.setEnterGateName(enterGateName);
+
+                    //                    判断是否已经添加
+                    LambdaQueryWrapper<SmartCarAccess> wrapper = new LambdaQueryWrapper<>();
+                    wrapper.eq(SmartCarAccess::getType, 1)
+                            .eq(SmartCarAccess::getIndexId, indexId);
+                    List<SmartCarAccess> list = this.list(wrapper);
+
+                    if (ObjectUtils.isEmpty(list) && list.size() <= 0) {
+                        this.save(smartCarAccess);
+                    }
+                }
+            }
+
+            page=page+1;
+        } else {
+            if (page>0) {
+                page=page-1;
+            }else {
+                page=0;
+            }
+        }
+    }
+
+
+    /**
+     * 出场车辆
+     *
+     * @param pageindex
+     * @param pagesize
+     * @throws Exception
+     */
+    public void getOutCar(Integer pageindex, Integer pagesize) throws Exception {
+
+        String url = parkConfig.getUrl() + "Inquire/GetOutCar";
+
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("appid", parkConfig.getAppId());
+        jsonObject.put("parkKey", parkConfig.getParkKey());
+        String rand = String.valueOf(Math.random());
+        jsonObject.put("rand", rand);
+        jsonObject.put("version", "v1.1");
+
+//        时间
+        DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        LocalDateTime now = LocalDateTime.now();
+        LocalDateTime stateTime = now.withHour(0).withMinute(0).withSecond(0);
+        LocalDateTime endTime = now.withHour(23).withMinute(59).withSecond(59);
+        String startData = stateTime.format(dateTimeFormatter1);
+        String endData = endTime.format(dateTimeFormatter1);
+//        开始时间
+        jsonObject.put("startTime", startData);
+//        data.put("startTime", "2024-01-22 00:00:00");
+//        结束时间
+        jsonObject.put("endTime", endData);
+//        data.put("endTime", "2024-01-22 23:59:59");
+
+        jsonObject.put("size", "20");
+        jsonObject.put("indexId", "0");
+        jsonObject.put("carNo", "");
+
+
+        String md5Str = "appid=" + parkConfig.getAppId() + "&endTime=" + endData + "&indexId=" + pageindex + "&parkKey=" + parkConfig.getParkKey() + "&rand=" + rand + "&size=" + pagesize + "&startTime=" + startData + "&version=v1.1" + "&" + parkConfig.getAppSecret();
+        String sign = CommonUtil.MD5(md5Str);
+        //sign签名
+        jsonObject.put("sign", sign);
+
+        String s = RequestUtils.httpPost(url, jsonObject.toJSONString());
+        JSONObject jsonObject1 = JSONObject.parseObject(s);
+
+        JSONArray dataArray = jsonObject1.getJSONArray("data");
+
+        if (ObjectUtils.isNotEmpty(dataArray) && dataArray.size() > 0) {
+
+            for (int i = 0; i < dataArray.size(); i++) {
+
+                JSONObject data = dataArray.getJSONObject(i);
+
+                if (ObjectUtils.isNotEmpty(data)) {
+                    SmartCarAccess smartCarAccess = new SmartCarAccess();
+
+//            索引ID
+                    String indexId = data.getString("indexId");
+//          车牌号码
+                    String carNo = data.getString("carNo");
+//            入场时间
+                    String enterTime = data.getString("enterTime");
+//             入口车道名称
+                    String enterGateName = data.getString("enterGateName");
+
+                    smartCarAccess.setIndexId(indexId);
+                    smartCarAccess.setType("2");
+                    smartCarAccess.setCarNo(carNo);
+                    smartCarAccess.setEnterTime(enterTime);
+                    smartCarAccess.setEnterGateName(enterGateName);
+
+                    //                    判断是否已经添加
+                    LambdaQueryWrapper<SmartCarAccess> wrapper = new LambdaQueryWrapper<>();
+                    wrapper.eq(SmartCarAccess::getType, 2)
+                            .eq(SmartCarAccess::getIndexId, indexId);
+                    List<SmartCarAccess> list = this.list(wrapper);
+
+                    if (ObjectUtils.isEmpty(list) && list.size() <= 0) {
+                        this.save(smartCarAccess);
+                    }
+                }
+            }
+
+            page=page+1;
+        } else {
+            if (page>0) {
+                page=page-1;
+            }else {
+                page=0;
+            }
+        }
+    }
+
+}