Browse Source

车辆备案

qzyReal 2 years ago
parent
commit
62e66bf8de

+ 1 - 1
pom.xml

@@ -47,7 +47,7 @@
 		<dependency>
 		    <groupId>com.baomidou</groupId>
 		    <artifactId>mybatis-plus-boot-starter</artifactId>
-		    <version>3.3.2</version>
+			<version>3.4.2</version>
 		</dependency>
 		
         <!-- pagehelper分页插件 -->

+ 82 - 0
sp-core/src/main/java/com/pj/current/mybatis/MyBatisPlusMetaObjectHandler.java

@@ -0,0 +1,82 @@
+package com.pj.current.mybatis;
+
+import cn.dev33.satoken.stp.StpUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.log.StaticLog;
+import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
+import com.pj.current.satoken.StpUserUtil;
+import org.apache.ibatis.reflection.MetaObject;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.Objects;
+import java.util.function.Supplier;
+
+/**
+ *
+ */
+@Component
+public class MyBatisPlusMetaObjectHandler implements MetaObjectHandler {
+
+    private static final String CREATE_TIME = "createTime";
+    private static final String CREATED_BY = "createBy";
+    private static final String UPDATE_TIME = "updateTime";
+    private static final String UPDATE_BY = "updateBy";
+
+
+    /**
+     * 插入填充
+     *
+     * @param metaObject 元数据对象
+     */
+    @Override
+    public void insertFill(MetaObject metaObject) {
+        String createBy = "";
+        if (StpUtil.isLogin()) {
+            createBy = StpUserUtil.getAdminName();
+        }
+        StaticLog.info("create by:{}", createBy);
+        if (metaObject.hasGetter(CREATED_BY)) {
+            strictInsertFill(metaObject, CREATED_BY, String.class, createBy);
+        }
+        if (metaObject.hasGetter(CREATE_TIME)) {
+            strictInsertFill(metaObject, CREATE_TIME, Date.class, new Date());
+        }
+        if (metaObject.hasGetter(UPDATE_BY)) {
+            strictUpdateFill(metaObject, UPDATE_BY, String.class, createBy);
+        }
+        if (metaObject.hasGetter(UPDATE_TIME)) {
+            strictUpdateFill(metaObject, UPDATE_TIME, Date.class, new Date());
+        }
+    }
+
+    /**
+     * 更新填充
+     *
+     * @param metaObject 元数据对象
+     */
+    @Override
+    public void updateFill(MetaObject metaObject) {
+        if (metaObject.hasGetter(UPDATE_BY)) {
+            strictUpdateFill(metaObject, UPDATE_BY, String.class, StpUserUtil.getAdminName());
+        }
+        if (metaObject.hasGetter(UPDATE_TIME)) {
+            strictUpdateFill(metaObject, UPDATE_TIME, Date.class, new Date());
+        }
+    }
+
+    @Override
+    public MetaObjectHandler strictFillStrategy(MetaObject metaObject, String fieldName, Supplier<?> fieldVal) {
+        Object value = metaObject.getValue(fieldName);
+        if (value == null
+                || StrUtil.isEmpty(value.toString())
+                || StrUtil.equals(fieldName, UPDATE_BY)
+                || StrUtil.equals(fieldName, UPDATE_TIME)) {
+            Object obj = fieldVal.get();
+            if (Objects.nonNull(obj)) {
+                metaObject.setValue(fieldName, obj);
+            }
+        }
+        return this;
+    }
+}

+ 1 - 1
sp-core/src/main/java/com/pj/current/netty/command/handler/impl/HealthlogHandler.java

@@ -103,7 +103,7 @@ public class HealthlogHandler implements IHandler {
         if (tbPersonFiling == null) {
             if (!SpCfgUtil.termianlFilling()) {
                 log.error("系统不允许设备端进行备案============>删除设备端自动备份的信息,:{}", idCard);
-                tbPersonFilingService.deleteTerminalWhilte(idCard);
+                tbPersonFilingService.deleteTerminalWhilte(idCard,true);
                 ctx.write(OKMsg.ok());
                 ctx.flush();
                 return;

+ 4 - 0
sp-core/src/main/java/com/pj/project/tb_car_filing/TbCarFiling.java

@@ -110,21 +110,25 @@ public class TbCarFiling extends Model<TbCarFiling> implements Serializable {
 	/**
 	 * 创建时间 
 	 */
+	@TableField(fill = FieldFill.INSERT)
 	private Date createTime;
 
 	/**
 	 * 创建人 
 	 */
+	@TableField(fill = FieldFill.INSERT)
 	private String createBy;	
 
 	/**
 	 * 更新时间 
 	 */
+	@TableField(fill = FieldFill.UPDATE)
 	private Date updateTime;
 
 	/**
 	 * 更新人 
 	 */
+	@TableField(fill = FieldFill.UPDATE)
 	private String updateBy;
 
 	private int judgeState;

+ 77 - 45
sp-core/src/main/java/com/pj/project/tb_car_filing/TbCarFilingService.java

@@ -1,16 +1,24 @@
 package com.pj.project.tb_car_filing;
 
+import java.io.File;
 import java.util.Date;
 import java.util.List;
 
 import cn.dev33.satoken.stp.StpUtil;
+import cn.hutool.core.codec.Base64Encoder;
+import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.util.IdcardUtil;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.pj.current.config.SystemObject;
 import com.pj.current.global.BusinessException;
+import com.pj.current.netty.command.constants.CommandType;
+import com.pj.current.netty.command.handler.dto.WhitelistDTO;
 import com.pj.current.satoken.StpUserUtil;
 import com.pj.project.tb_car_black.TbCarBlack;
 import com.pj.project.tb_car_black.TbCarBlackService;
@@ -18,7 +26,11 @@ import com.pj.project.tb_dept.TbDept;
 import com.pj.project.tb_dept.TbDeptService;
 import com.pj.project.tb_person_filing.TbPersonFiling;
 import com.pj.project.tb_person_filing.TbPersonFilingService;
+import com.pj.project.tb_terminal.TbTerminal;
+import com.pj.project.tb_terminal.TbTerminalService;
 import com.pj.project4sp.spcfg.SpCfgUtil;
+import com.pj.project4sp.uploadfile.UploadConfig;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -33,6 +45,7 @@ import javax.annotation.Resource;
  */
 @Service
 @Transactional(rollbackFor = Exception.class)
+@Slf4j
 public class TbCarFilingService extends ServiceImpl<TbCarFilingMapper, TbCarFiling> implements IService<TbCarFiling> {
 
     /**
@@ -47,12 +60,16 @@ public class TbCarFilingService extends ServiceImpl<TbCarFilingMapper, TbCarFili
     private TbPersonFilingService tbPersonFilingService;
 
 
+
     /**
      * 增
      */
     public void add(TbCarFiling t) {
         String carNo = t.getCarNo().toUpperCase();
         String idCarNo = t.getDriverIdCard();
+        if (!IdcardUtil.isValidCard(t.getDriverIdCard())) {
+            throw new BusinessException("身份证不正确");
+        }
         //原来是否录入过
         TbCarFiling checkFiling = this.findByDriverIdCar(idCarNo);
         if (checkFiling != null) {
@@ -62,41 +79,45 @@ public class TbCarFilingService extends ServiceImpl<TbCarFilingMapper, TbCarFili
         if (carNoCheckFiling != null) {
             throw new BusinessException("车辆已备案");
         }
-        String needJudge = SpCfgUtil.getFillingJudge();
-        if (StrUtil.equals(needJudge, "2")) {
-            t.setJudgeState(1).setJudgeTime(new Date()).setJudgeBy("系统自动审核");
-        }
-        t.setCreateBy(StpUtil.getLoginIdAsString()).setCarNo(carNo)
-                .setCreateTime(new Date());
-        handler(t);
-        this.handlerDriver(t);
+        t.setCarNo(carNo);
+        handlerDriver(t);
         this.save(t);
     }
 
     /**
+     * 处理备案司机
+     *
      * @param tbCarFiling
      */
     private void handlerDriver(TbCarFiling tbCarFiling) {
         String idCarNo = tbCarFiling.getDriverIdCard();
         //人员是否备案
         TbPersonFiling t = tbPersonFilingService.findByIdCard(idCarNo);
-        Date now = new Date();
+        Long deptId = tbCarFiling.getDeptId();
+        TbDept tbDept = tbDeptService.getById(deptId);
+        tbCarFiling.setDeptName(tbDept.getName());
+        boolean judge = TbDept.NeedJudgeEnum.AUTO_JUDGE.getType().equals(tbDept.getNeedJudge());
+        if (judge) {
+            tbCarFiling.setJudgeState(1).setJudgeTime(new Date()).setJudgeBy("系统自动审核");
+        }
         if (t == null) {
-           // String pin = RandomUtil.randomNumbers(9);
-            String pin=tbCarFiling.getDriverIdCard();
+            String pin = tbCarFiling.getDriverIdCard();
             tbCarFiling.setDriverPin(pin);
             t = new TbPersonFiling();
-            t.setDeptId(tbCarFiling.getDeptId()).setPhoto(tbCarFiling.getDriverPhoto()).setPin(pin)
-                    .setIdCard(tbCarFiling.getDriverIdCard()).setName(tbCarFiling.getDriverName())
-                    .setPhone(tbCarFiling.getDriverPhoto()).setPin(tbCarFiling.getDriverPin());
-            String needJudge = SpCfgUtil.getFillingJudge();
-            if (StrUtil.equals(needJudge, "2")) {
-                t.setJudgeState(1).setJudgeTime(now).setJudgeBy("系统自动审核");
+            t.setDeptId(tbDept.getId())
+                    .setPhoto(tbCarFiling.getDriverPhoto())
+                    .setDeptName(tbDept.getName())
+                    .setType(tbCarFiling.getType())
+                    .setPin(idCarNo)
+                    .setIdCard(tbCarFiling.getDriverIdCard())
+                    .setName(tbCarFiling.getDriverName())
+                    .setPhone(tbCarFiling.getDriverContact());
+            if (judge) {
+                t.setJudgeState(1).setJudgeTime(new Date()).setJudgeBy("系统自动审核");
+                // todo 下发人脸到设备
+                tbPersonFilingService.issued(t);
             }
-            //下发司机白名单
-            tbPersonFilingService.issued(t);
-        } else {
-            tbCarFiling.setDriverPin(t.getIdCard());
+            tbPersonFilingService.save(t);
         }
     }
 
@@ -112,21 +133,6 @@ public class TbCarFilingService extends ServiceImpl<TbCarFilingMapper, TbCarFili
         return getOne(ew);
     }
 
-    private void handler(TbCarFiling t) {
-        if (!IdcardUtil.isValidCard(t.getDriverIdCard())) {
-            // throw new BusinessException("身份证不正确");
-        }
-        TbDept tbDept = tbDeptService.getById(t.getDeptId());
-        if (tbDept == null) {
-            throw new BusinessException("请选择组织");
-        }
-        String carNo = t.getCarNo().toUpperCase();
-        Date now = new Date();
-        t.setDeptName(tbDept.getName()).setUpdateTime(now).setCarNo(carNo)
-                .setUpdateBy(StpUtil.getLoginIdAsString());
-        t.setCarNo(t.getCarNo().toUpperCase());
-    }
-
 
     /**
      * 删
@@ -138,7 +144,7 @@ public class TbCarFilingService extends ServiceImpl<TbCarFilingMapper, TbCarFili
         //如果不存在白名单,则
         if (tbPersonFiling == null) {
             //删除设备的白名单
-            tbPersonFilingService.deleteTerminalWhilte(db.getDriverPin());
+            tbPersonFilingService.deleteTerminalWhilte(db.getDriverPin(), true);
         }
         this.removeById(id);
     }
@@ -147,25 +153,41 @@ public class TbCarFilingService extends ServiceImpl<TbCarFilingMapper, TbCarFili
      * 改
      */
     public void update(TbCarFiling t) {
-        handler(t);
-        String carNo = t.getCarNo();
+        String carNo = t.getCarNo().toUpperCase();
         TbCarFiling carNoCheck = this.findByCarNo(carNo);
         if (carNoCheck != null && t.getId().longValue() != carNoCheck.getId().longValue()) {
             throw new BusinessException("车辆已备案");
         }
         TbCarFiling db = this.getById(t.getId());
+        if (!t.getDeptId().equals(db.getDeptId())) {
+            TbDept tbDept = tbDeptService.getById(t.getDeptId());
+            t.setDeptName(tbDept.getName());
+        }
         String idCarNo = t.getDriverIdCard();
-        //改了身份证
-        if (!StrUtil.equals(idCarNo, db.getDriverIdCard())) {
+        String oldIdCardNo = db.getDriverIdCard();
+        //改了身份证或者人脸或者姓名
+        if (!StrUtil.equals(idCarNo, oldIdCardNo)
+                || !StrUtil.equals(t.getDriverPhoto(), db.getDriverPhoto())
+                || !StrUtil.equals(t.getDriverName(), db.getDriverName())
+        ) {
             //原来是否录入过
             TbCarFiling checkFiling = this.findByDriverIdCar(idCarNo);
             if (checkFiling != null) {
                 throw new BusinessException("司机已备案其他车辆");
             }
+            //更改备案人信息
+            TbPersonFiling tbPersonFiling = tbPersonFilingService.findByIdCard(oldIdCardNo);
+            if (tbPersonFiling != null) {
+                tbPersonFiling.setIdCard(idCarNo)
+                        .setName(t.getDriverName())
+                        .setPhone(t.getDriverContact());
+                tbPersonFilingService.updateById(tbPersonFiling);
+            }
             //司机身份证不一样 删除旧的,下发新的
-            tbPersonFilingService.deleteTerminalWhilte(db.getDriverPin());
-            this.handlerDriver(t);
+            tbPersonFilingService.deleteTerminalWhilte(db.getDriverIdCard(), false);
+            tbPersonFilingService.issued(idCarNo);
         }
+        t.setCarNo(t.getCarNo().toUpperCase());
         this.updateById(t);
     }
 
@@ -191,9 +213,17 @@ public class TbCarFilingService extends ServiceImpl<TbCarFilingMapper, TbCarFili
         return list.isEmpty() ? null : list.get(0);
     }
 
+    /**
+     * 审核
+     *
+     * @param t
+     */
     public void judge(TbCarFiling t) {
-        t.setJudgeTime(new Date()).setJudgeBy(StpUserUtil.getAdminName());
-        this.updateById(t);
+        TbCarFiling db=this.getById(t.getId());
+        db.setJudgeTime(new Date()).setJudgeBy(StpUserUtil.getAdminName()).setJudgeState(t.getJudgeState());
+        this.updateById(db);
+        //人员备案审核
+        tbPersonFilingService.judgeByIdCard(db.getDriverIdCard(), db.getJudgeState());
     }
 
     public List<TbCarFiling> getForWx(SoMap soMap) {
@@ -204,4 +234,6 @@ public class TbCarFilingService extends ServiceImpl<TbCarFilingMapper, TbCarFili
     public List<TbCarFiling> getOuterList(SoMap soMap) {
         return tbCarFilingMapper.getOuterList(soMap);
     }
+
+
 }

+ 1 - 1
sp-core/src/main/java/com/pj/project/tb_gate_terminal/TbGateTerminalService.java

@@ -141,7 +141,7 @@ public class TbGateTerminalService extends ServiceImpl<TbGateTerminalMapper, TbG
      */
     public void update(TbGateTerminal t) throws Exception {
         TbGateTerminal ipTerminal = findByIp(t.getIp());
-        if (!t.getId().equals(ipTerminal.getId())) {
+        if (ipTerminal!=null&&!t.getId().equals(ipTerminal.getId())) {
             throw new BusinessException("IP地址已被占用");
         }
         TbGateTerminal db = this.getById(t.getId());

+ 4 - 0
sp-core/src/main/java/com/pj/project/tb_person_filing/TbPersonFiling.java

@@ -112,21 +112,25 @@ public class TbPersonFiling extends Model<TbPersonFiling> implements Serializabl
     /**
      * 创建时间
      */
+    @TableField(fill = FieldFill.INSERT)
     private Date createTime;
 
     /**
      * 创建人
      */
+    @TableField(fill = FieldFill.INSERT)
     private String createBy;
 
     /**
      * 更新时间
      */
+    @TableField(fill = FieldFill.UPDATE)
     private Date updateTime;
 
     /**
      * 更新人
      */
+    @TableField(fill = FieldFill.UPDATE)
     private String updateBy;
 
     private int judgeState;

+ 47 - 12
sp-core/src/main/java/com/pj/project/tb_person_filing/TbPersonFilingService.java

@@ -34,6 +34,8 @@ import com.pj.current.netty.command.constants.CommandType;
 import com.pj.current.netty.command.handler.dto.WhitelistDTO;
 import com.pj.current.satoken.StpUserUtil;
 import com.pj.current.task.TaskService;
+import com.pj.project.tb_car_filing.TbCarFiling;
+import com.pj.project.tb_car_filing.TbCarFilingService;
 import com.pj.project.tb_dept.TbDept;
 import com.pj.project.tb_dept.TbDeptService;
 import com.pj.project.tb_person_black.TbPersonBlack;
@@ -84,6 +86,9 @@ public class TbPersonFilingService extends ServiceImpl<TbPersonFilingMapper, TbP
 
     @Resource
     private TaskService taskService;
+    @Resource
+    @Lazy
+    private TbCarFilingService tbCarFilingService;
 
 
     /**
@@ -98,28 +103,26 @@ public class TbPersonFilingService extends ServiceImpl<TbPersonFilingMapper, TbP
         if (db != null) {
             throw new BusinessException("人员已存在");
         }
-        //String pin = RandomUtil.randomNumbers(9);
         t.setPin(idCard);
         TbDept tbDept = tbDeptService.getById(t.getDeptId());
         if (TbDept.NeedJudgeEnum.AUTO_JUDGE.getType().equals(tbDept.getNeedJudge())) {
             t.setJudgeState(1).setJudgeTime(new Date()).setJudgeBy("系统自动审核");
         }
-        this.handlerTime(t);
-        t.setCreateBy(StpUtil.getLoginIdAsString()).setCreateTime(new Date());
         this.save(t);
         issued(t);
     }
 
-    private void handlerTime(TbPersonFiling t) {
-        t.setUpdateTime(new Date()).setUpdateBy(StpUtil.getLoginIdAsString());
-    }
+
 
     /**
      * 删
      */
     public void delete(Integer id) {
         TbPersonFiling db = this.getById(id);
-        deleteTerminalWhilte(db.getPin());
+        TbCarFiling tbCarFiling = tbCarFilingService.findByDriverIdCar(db.getIdCard());
+        if (tbCarFiling == null || tbCarFiling.getJudgeState() == 0) {//车辆司机不存在或者未审核,删除备案
+            deleteTerminalWhilte(db.getPin(), true);
+        }
         this.removeById(id);
     }
 
@@ -136,12 +139,11 @@ public class TbPersonFilingService extends ServiceImpl<TbPersonFilingMapper, TbP
             throw new BusinessException("人员已存在");
         }
         TbPersonFiling db = this.getById(t.getId());
-        handlerTime(t);
         //改了身份证或者名字,部门,要把旧的人员信息清除,下发新的
         if (!StrUtil.equals(t.getIdCard(), db.getIdCard())
                 || !StrUtil.equals(t.getName(), db.getName())) {
             //删除旧的
-            deleteTerminalWhilte(db.getIdCard());
+            deleteTerminalWhilte(db.getIdCard(), false);
             //下发新的
             issued(t);
         }
@@ -238,13 +240,15 @@ public class TbPersonFilingService extends ServiceImpl<TbPersonFilingMapper, TbP
     /**
      * 删除设备某个人的白名单
      */
-    public void deleteTerminalWhilte(String pin) {
+    public void deleteTerminalWhilte(String pin, boolean setHeart) {
         List<TbTerminal> tbTerminalList = tbTerminalService.list();
         JSONObject params = new JSONObject();
         params.putIfAbsent("pin", Collections.singleton(pin));
         tbTerminalList.forEach(tbTerminal -> {
             tbTerminalService.setCommand(CommandType.DELETE_USER_COMMAND.getFuncId(), params, tbTerminal);
-            tbTerminalService.startHeartCommand(tbTerminal.getSn());
+            if (setHeart) {
+                tbTerminalService.startHeartCommand(tbTerminal.getSn());
+            }
         });
 
     }
@@ -304,6 +308,24 @@ public class TbPersonFilingService extends ServiceImpl<TbPersonFilingMapper, TbP
     }
 
     /**
+     * 审核
+     *
+     * @param idCard
+     * @param judgeStatus
+     */
+    public void judgeByIdCard(String idCard, int judgeStatus) {
+        TbPersonFiling db = findByIdCard(idCard);
+        if (db == null) {
+            return;
+        }
+        db.setJudgeBy(StpUserUtil.getAdminName()).setJudgeTime(new Date()).setJudgeState(judgeStatus);
+        this.updateById(db);
+        if (StrUtil.isNotEmpty(db.getPhoto())) {
+            issued(db);
+        }
+    }
+
+    /**
      * 根据openid查找
      *
      * @param openid
@@ -346,7 +368,7 @@ public class TbPersonFilingService extends ServiceImpl<TbPersonFilingMapper, TbP
         String filename = file.getOriginalFilename();
         //创建临时目录
         String tempDir = uploadConfig.rootFolder + File.separator + RandomUtil.randomNumbers(6);
-        String fileDir = tempDir + File.separator + StrUtil.subBefore(filename,".",true);
+        String fileDir = tempDir + File.separator + StrUtil.subBefore(filename, ".", true);
         File temFileDir = FileUtil.mkdir(tempDir);
         try (InputStream is = file.getInputStream()) {
             //解压
@@ -400,4 +422,17 @@ public class TbPersonFilingService extends ServiceImpl<TbPersonFilingMapper, TbP
             tbTerminalService.startHeartCommand(tbTerminal.getSn());
         });
     }
+
+    /**
+     * 根据身份查找下发人员
+     *
+     * @param idCard
+     */
+    public void issued(String idCard) {
+        TbPersonFiling tbPersonFiling = this.findByIdCard(idCard);
+        if (tbPersonFiling == null) {
+            return;
+        }
+        issued(tbPersonFiling);
+    }
 }

+ 1 - 4
sp-core/src/main/java/com/pj/project4sp/spcfg/SpCfgUtil.java

@@ -71,10 +71,7 @@ public class SpCfgUtil {
         return SpCfgUtil.getCfgBy("app_cfg", key, defaultValue);
     }
 
-    // 获取配置信息:备案审核 1审核 2不审核
-    public static String getFillingJudge() {
-        return SpCfgUtil.getServerCfg("fillingJudge", "1");
-    }
+
 
     // 获取配置信息:行程卡限制
     public static boolean tourLimit() {