Forráskód Böngészése

部门超时驳回队列处理程序

sugangqiang 2 éve
szülő
commit
adf0a08491
3 módosított fájl, 130 hozzáadás és 9 törlés
  1. 8 4
      app/common/api/TalentLogApi.php
  2. 9 5
      app/job/Import.php
  3. 113 0
      app/job/Talent.php

+ 8 - 4
app/common/api/TalentLogApi.php

@@ -147,10 +147,12 @@ class TalentLogApi {
         $log["mainId"] = $mainId;
         $log["typeFileId"] = $fileType;
         $log["fileId"] = $fileId;
-        $log["companyId"] = $user["companyId"];
+        if ($user) {
+            $log["companyId"] = $user["companyId"];
+        }
         $log["active"] = $active;
         $log["description"] = $description;
-        $log["createUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);
+        $log["createUser"] = $user ? sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]) : "系统";
         $log["createTime"] = date("Y-m-d H:i:s");
         return TalentLog::create($log);
     }
@@ -164,10 +166,12 @@ class TalentLogApi {
             $log["state"] = $log["new_state"] = $state;
         }
         $log["id"] = $id;
-        $log["companyId"] = $user["companyId"];
+        if ($user) {
+            $log["companyId"] = $user["companyId"];
+        }
         $log["active"] = $active;
         $log["description"] = $description;
-        $log["updateUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);
+        $log["updateUser"] = $user ? sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]) : "系统";
         $log["updateTime"] = date("Y-m-d H:i:s");
         return TalentLog::update($log);
     }

+ 9 - 5
app/job/Import.php

@@ -2,8 +2,10 @@
 
 namespace app\job;
 
+use app\common\api\BatchApi;
 use app\common\api\TalentLogApi;
 use app\common\model\TalentChecklog;
+use app\common\state\ProjectState;
 use think\queue\Job;
 use think\facade\Log;
 use think\facade\Db;
@@ -188,7 +190,7 @@ class Import {
                     $datas = $sheet->toArray();
                     $datas = array_slice($datas, 1); //去标题
                     $country = Db::table("sys_dict")->where("pid", 35)->column("code", "name");
-
+                    $batch = BatchApi::getValidBatch(ProjectState::TALENT, 1);
                     for ($index = 0; $index < count($datas); $index++) {
                         $row = $datas[$index];
                         $msg = [];
@@ -207,7 +209,7 @@ class Import {
                                     }
                                     break;
                                 case 1:
-                                    $info = Db::table("un_enterprise")->where('idCard', $row[$i])->where('delete',0)->findOrEmpty();
+                                    $info = Db::table("un_enterprise")->where('idCard', $row[$i])->where('delete',0)->where('apply_year',$batch["batch"])->findOrEmpty();
                                     if (!$info) {
                                         array_push($msg, "机构代码不存在,请检查");
                                     } else {
@@ -308,6 +310,7 @@ class Import {
                             } else {
                                 $item["highProcess"] = 5; //最高进度
                                 $item['createTime'] = date("Y-m-d H:i:s", time());
+                                $item['apply_year'] = $batch["batch"];
                                 Db::table("new_talent_info")->insert($item);
                                 $sheet->setCellValue('AL' . ($index + 2), '导入成功');
 
@@ -342,10 +345,9 @@ class Import {
                     $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($path ."/public/storage/" . $res['task_file']);
                     $sheet = $spreadsheet->getSheet(0);
                     $datas = $sheet->toArray();
-
                     $datas = array_slice($datas, 1); //去标题
                     $country = Db::table("sys_dict")->where("pid", 35)->column("code", "name");
-
+                    $batch = BatchApi::getValidBatch(ProjectState::TALENT, 1);
                     for ($index = 0; $index < count($datas); $index++) {
                         $row = $datas[$index];
                         $msg = [];
@@ -364,7 +366,8 @@ class Import {
                                     }
                                     break;
                                 case 1:
-                                    $info = Db::table("un_enterprise")->where('idCard', $row[$i])->where('delete',0)->findOrEmpty();
+
+                                    $info = Db::table("un_enterprise")->where('idCard', $row[$i])->where('delete',0)->where('apply_year',$batch["batch"])->findOrEmpty();
                                     if (!$info) {
                                         array_push($msg, "机构代码不存在,请检查");
                                     } else {
@@ -471,6 +474,7 @@ class Import {
                                 Db::table("new_talent_info")->where('id', $talent_info['id'])->update($item);
                                 $sheet->setCellValue('AC' . ($index + 2), '更新成功');
                             } else {
+                                $item['apply_year'] = $batch["batch"];
                                 $item['createTime'] = date("Y-m-d H:i:s", time());
                                 Db::table("new_talent_info")->insert($item);
                                 $sheet->setCellValue('AC' . ($index + 2), '导入成功');

+ 113 - 0
app/job/Talent.php

@@ -0,0 +1,113 @@
+<?php
+
+namespace app\job;
+
+use think\queue\Job;
+use think\facade\Log;
+use think\facade\Db;
+use app\common\api\ChuanglanSmsApi;
+use app\common\model\MessageRecord;
+use app\common\api\TalentLogApi;
+use app\common\api\TalentConditionApi;
+use app\common\api\TalentState;
+use app\enterprise\model\Talent as TalentModel;
+
+/**
+ * Description of Talent
+ *
+ * @author sgq
+ */
+class Talent {
+
+    public function fire(Job $job, $data) {
+        if ($this->deal($data)) {
+            $job->delete();
+            return true;
+        }
+        if ($job->attempts() >= 3) {
+            $job->delete();
+            return false;
+        }
+        $job->release(10); //10秒后重试
+    }
+
+    /**
+     * 处理业务逻辑
+     * @param type $data
+     * @return bool
+     */
+    public function deal($data): bool {
+        switch ($data["type"]) {
+            case 1:
+                //部门超时驳回
+                $mainId = $data["id"];
+                $where[] = ["ti.id", "=", $mainId];
+                $where[] = ["ti.checkState", "=", TalentState::FST_VERIFY_PASS];
+                $where[] = ["ti.pass_dept_check", "=", 0];
+                $talent_info = TalentModel::alias("ti")
+                                ->leftJoin("new_talent_condition tc", "tc.id=ti.talent_condition")
+                                ->leftJoin("un_enterprise e", "e.id=ti.enterprise_id")
+                                ->leftJoin("(select description,mainId,last_state,new_state,state,createTime from new_talent_checklog where md5(concat(createTime,mainId,`type`)) in (select md5(concat(max(createTime),mainId,`type`)) from `new_talent_checklog` where `type`=1 and `step` is null and active=1 and typeFileId is null group by mainId,`type`)) tl", "`tl`.`mainId`=ti.id")
+                                ->where($where)->field("ti.*,tc.companyIds,tc.companyWithFileType")->find();
+                if ($talent_info) {
+                    $weekDay = date("w"); //0周日,6周六
+                    if ($weekDay == 6) {
+                        $delay = 2 * 24 * 3600;
+                        queue("app\job\Talent", ["type" => 1, "id" => $mainId], $delay);
+                        return true;
+                    }
+                    if (!$weekDay || $weekDay == 0) {
+                        $delay = 1 * 24 * 3600;
+                        queue("app\job\Talent", ["type" => 1, "id" => $mainId], $delay);
+                        return true;
+                    }
+                    $modify_files = array_filter(explode(",", $talent_info["modify_files"]));
+                    $companyAndTypes = [];
+                    $companyWithFileType = array_filter(explode(";", $talent_info["companyWithFileType"]));
+                    foreach ($companyWithFileType as $c) {
+                        list($companyId, $fileTypesStr) = array_filter(explode(":", $c));
+                        $companyAndTypes[$companyId] = array_filter(explode(",", $fileTypesStr));
+                    }
+
+                    $companyIds = array_filter(explode(",", $talent_info["companyIds"]));
+                    if ($companyIds) {
+                        if ($talent_info["re_check_companys"]) {
+                            $unpass_companyIds = array_filter(explode(",", $talent_info["re_check_companys"]));
+                        } else {
+                            //这边去除已经审核通过的单位,主要通过日志是否存在记录。
+                            $pass_companyIds = TalentLogApi::getPassDepts($talent_info["id"]); //已经通过的单位
+                            $unpass_companyIds = array_diff($companyIds, (array) $pass_companyIds); //排除已经通过的单位
+                        }
+                        if (!$unpass_companyIds) {
+                            //没有未审部门
+                            return true;
+                        }
+                        //开始驳回操作
+                        $fst_dept_check_time = $talent_info["first_dept_check_time"];
+                        $log_checkState = TalentState::FST_VERIFY_PASS; //当前状态不变
+                        $checkState = TalentState::SCND_SUBMIT; //退回待初审
+                        foreach ($unpass_companyIds as $companyId) {
+                            $fileTypes = $companyAndTypes[$companyId];
+                            $modify_files = array_unique((array_merge((array) $modify_files, (array) $fileTypes)));
+                            $dept_log = TalentLogApi::getLogByCompanyId($talent_info["id"], $companyId, $fst_dept_check_time);
+                            TalentLogApi::rewrite($dept_log["id"], [$log_checkState, $checkState], "审核超时,系统自动驳回");
+                        }
+                        $log_checkState = TalentState::DEPT_VERIFY_REJECT;
+                        $data["id"] = $talent_info["id"];
+                        $data["modify_files"] = implode(",", $modify_files);
+                        $data["checkState"] = $checkState;
+                        $data["first_dept_check_time"] = null;
+                        $data["re_check_companys"] = null;
+                        TalentModel::update($data);
+                        TalentLogApi::write(1, $talent_info["id"], [$log_checkState, $checkState], "审核超时,系统自动驳回,部门审核结束", 1);
+                        return true;
+                    } else {
+                        return true;
+                    }
+                }
+                break;
+        }
+        return false;
+    }
+
+}