Worker.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <?php
  2. namespace app\job;
  3. use think\queue\Job;
  4. use think\facade\Log;
  5. use think\facade\Db;
  6. use app\common\api\ChuanglanSmsApi;
  7. use app\common\api\TalentState;
  8. /**
  9. * Description of Worker
  10. *
  11. * @author sgq
  12. */
  13. class Worker {
  14. public function fire(Job $job, $data) {
  15. if ($this->deal($data)) {
  16. Log::info(json_encode($data));
  17. $job->delete();
  18. return true;
  19. }
  20. Log::error(json_encode($data));
  21. if ($job->attempts() >= 3) {
  22. $job->delete();
  23. return false;
  24. }
  25. $job->release(10); //10秒后重试
  26. }
  27. /**
  28. * 处理业务逻辑
  29. * @param type $data
  30. * @return bool
  31. */
  32. public function deal($data): bool {
  33. $type = $data["type"];
  34. switch ($type) {
  35. case 98:
  36. //转移旧集成电路的认定条款到新表
  37. $oldConditionId = $data["id"];
  38. return $this->getIdentifyCondition($oldConditionId);
  39. break;
  40. case 99://转移旧集成电路人才申报信息到新库
  41. $talent_info = $data["talent_info"];
  42. return $this->oldJcjlTalentInfoToNewTable($talent_info);
  43. break;
  44. }
  45. return false;
  46. }
  47. /**
  48. * 集成电路旧人才表转移到新人才表
  49. * @param type $talent_info
  50. */
  51. private function oldJcjlTalentInfoToNewTable($talent_info) {
  52. $whr = [];
  53. $whr[] = ["card_type", "=", $talent_info["cardType"]];
  54. $whr[] = ["card_number", "=", $talent_info["idCard"]];
  55. $whr[] = ["apply_year", "=", $talent_info["year"]];
  56. $whr[] = ["checkState", ">=", 0];
  57. if ($ti = Db::table("new_talent_info")->where($whr)->find()) {
  58. $where = [];
  59. $where[] = ["mainId", "=", $ti["id"]];
  60. $where[] = ["type", "=", \app\common\state\ProjectState::TALENT];
  61. $log = Db::table("new_talent_checklog")->where($where)->find();
  62. if (!$log) {
  63. $log["last_state"] = $log["new_state"] = $log["state"] = $ti["checkState"];
  64. $log["id"] = getStringId();
  65. $log["type"] = \app\common\state\ProjectState::TALENT;
  66. $log["mainId"] = $ti["id"];
  67. $log["active"] = 1;
  68. $log["description"] = "旧系统导入新系统自动生成";
  69. $log["createUser"] = "系统";
  70. $log["createTime"] = date("Y-m-d H:i:s");
  71. \app\common\model\TalentLog::create($log);
  72. return true;
  73. }
  74. if (!$ti["talent_condition"]) {
  75. $oldTi = Db::table("un_talent_info")->where("id", $ti["oldId"])->find();
  76. $oldCondition = Db::table("un_identify_condition")->where("id", $oldTi["identifyCondition"])->find();
  77. $where = [];
  78. $where[] = ["name", "=", $oldCondition["name"]];
  79. $where[] = ["type", "=", 2];
  80. $newCondition = Db::table("new_talent_condition")->where($where)->find();
  81. $newConditionId = $newCondition["id"];
  82. if (!$newCondition) {
  83. $condition["source"] = $oldCondition["source"];
  84. $condition["talentLevel"] = $oldCondition["talentLevel"];
  85. $condition["type"] = $oldCondition["type"];
  86. $condition["name"] = $oldCondition["name"];
  87. $condition["activeYear"] = $oldCondition["activeYear"];
  88. $condition["notWorkYear"] = $oldCondition["notWorkYear"];
  89. $condition["active"] = $oldCondition["active"];
  90. $condition["companyIds"] = $oldCondition["companyIds"];
  91. $condition["description"] = $oldCondition["description"];
  92. $condition["createTime"] = $oldCondition["createTime"];
  93. $condition["createUser"] = $oldCondition["createUser"];
  94. $condition["updateTime"] = $oldCondition["updateTime"];
  95. $condition["updateUser"] = $oldCondition["updateUser"];
  96. $newConditionId = Db::table("new_talent_condition")->insertGetId($condition);
  97. }
  98. if ($newConditionId) {
  99. $updData["id"] = $ti["id"];
  100. $updData["talent_condition"] = $newConditionId;
  101. Db::table("new_talent_info")->save($updData);
  102. }
  103. return true;
  104. }
  105. return false;
  106. }
  107. $data["oldId"] = $talent_info["id"];
  108. switch ($talent_info["checkState"]) {
  109. case -1:
  110. if ($talent_info["isPublic"] == 5) {
  111. $data["checkState"] = TalentState::PUBLISH_FAIL;
  112. } else {
  113. $data["checkState"] = TalentState::REVERIFY_FAIL;
  114. }
  115. break;
  116. case 1:
  117. $data["checkState"] = TalentState::SCND_SAVE;
  118. break;
  119. case 7:
  120. $data["checkState"] = TalentState::SCND_SUBMIT;
  121. break;
  122. case 10:
  123. $data["checkState"] = TalentState::SCND_SAVE;
  124. break;
  125. case 20:
  126. $data["checkState"] = TalentState::SCND_SUBMIT;
  127. break;
  128. case 25:
  129. $data["checkState"] = TalentState::FST_VERIFY_PASS;
  130. break;
  131. case 35:
  132. if ($talent_info["isPublic"] == 5) {
  133. $data["checkState"] = TalentState::PUBLISH_PASS;
  134. } else if ($talent_info["isPublic"] == 2) {
  135. $data["checkState"] = TalentState::ZX_PASS;
  136. } else if ($talent_info["isPublic"] == 6) {
  137. $data["checkState"] = TalentState::CERTIFICATED;
  138. } else {
  139. $data["checkState"] = TalentState::REVERIFY_PASS;
  140. }
  141. break;
  142. }
  143. $data["highProcess"] = 0;
  144. switch ($talent_info["highProcess"]) {
  145. case 1:
  146. if ($talent_info["checkState"] == 25) {
  147. $data["highProcess"] = 3;
  148. }
  149. break;
  150. case 3:
  151. if ($talent_info["checkState"] == 35) {
  152. $data["highProcess"] = 5;
  153. } else {
  154. $data["highProcess"] = 3;
  155. }
  156. break;
  157. }
  158. $data["enterprise_id"] = $talent_info["enterpriseId"];
  159. $data["name"] = $talent_info["name"];
  160. $data["phone"] = $talent_info["phone"];
  161. $data["email"] = $talent_info["email"];
  162. $data["sex"] = $talent_info["sex"];
  163. $data["card_type"] = $talent_info["cardType"];
  164. $data["card_number"] = $talent_info["idCard"];
  165. $data["headimgurl"] = $talent_info["photo"];
  166. $data["birthday"] = $talent_info["birthday"];
  167. $data["apply_year"] = $talent_info["year"];
  168. $data["province"] = $talent_info["provinceCode"];
  169. $data["city"] = $talent_info["cityCode"];
  170. $data["county"] = $talent_info["countyCode"];
  171. $data["nation"] = $this->getNewDictVal("un_nation", $talent_info["nation"], "nation");
  172. $data["nationality"] = $this->getNewDictVal("un_nationality", $talent_info["nationality"], "nationality", "other");
  173. $data["politics"] = $this->getNewDictVal("un_political", $talent_info["politics"], "politics");
  174. $data["highest_degree"] = $this->getNewDictVal("un_education", $talent_info["highEducation"], "highest_degree");
  175. $data["graduate_school"] = $talent_info["graduateSchool"];
  176. $data["major"] = $talent_info["major"];
  177. $data["position"] = $talent_info["post"];
  178. $data["study_abroad"] = $talent_info["studyAbroad"];
  179. $data["cur_entry_time"] = $talent_info["entryTime"];
  180. $data["cur_quit_time"] = $talent_info["quitTime"];
  181. $data["labor_contract_rangetime"] = $talent_info["startTime"] . " - " . $talent_info["endTime"];
  182. $data["talent_arrange"] = $talent_info["talentArrange"];
  183. $data["talent_condition"] = $this->getIdentifyCondition($talent_info["identifyCondition"]);
  184. $data["publicBatch"] = $talent_info["publicBatch"];
  185. $data["identifyConditionName"] = $talent_info["identifyConditionName"];
  186. $data["identifyGetTime"] = $talent_info["identifyGetTime"];
  187. $data["identifyExpireTime"] = $talent_info["identifyOutTime"];
  188. $data["identifyMonth"] = $talent_info["identifyMonth"];
  189. $data["certificateNo"] = $talent_info["certificateNO"];
  190. $data["certificateGetTime"] = $talent_info["certificateStartTime"];
  191. $data["certificateExpireTime"] = $talent_info["qzgccrcActiveTime"];
  192. $data["title"] = $talent_info["title"];
  193. $data["pro_qua"] = $talent_info["professionalQualifications"];
  194. $data["bank"] = $talent_info["bank"];
  195. $data["bank_branch_name"] = $talent_info["bankNetwork"];
  196. $data["bank_account"] = $talent_info["bankAccount"];
  197. $data["description"] = $talent_info["description"];
  198. $data["experience"] = $talent_info["mainHonours"];
  199. $data["education"] = $talent_info["educationAndResume"];
  200. $data["createTime"] = $talent_info["createTime"];
  201. $data["break_faith"] = $talent_info["breakFaith"];
  202. $data["first_submit_time"] = $talent_info["firstSubmitTime"];
  203. $data["new_submit_time"] = $talent_info["newSubmitTime"];
  204. $data["first_dept_check_time"] = $talent_info["firstDepPassTime"];
  205. $data["active"] = $talent_info["active"];
  206. $newTalentInfoId = Db::table("new_talent_info")->insertGetId($data);
  207. if ($newTalentInfoId) {
  208. $files = Db::table("un_talent_file")->where("mainId", $talent_info["id"])->select();
  209. foreach ($files as $file) {
  210. $newFileTypeId = $this->getFileTypeId($file["fileTypeId"]);
  211. $newFileData["mainId"] = $newTalentInfoId;
  212. $newFileData["type"] = 2;
  213. $newFileData["typeId"] = $newFileTypeId;
  214. $newFileData["orignName"] = $file["orignName"];
  215. $newFileData["url"] = $file["url"];
  216. $newFileData["sn"] = $file["sn"];
  217. $newFileData["description"] = $file["description"];
  218. $newFileData["createTime"] = $file["createTime"];
  219. $newFileData["createUser"] = $file["createUser"];
  220. $newFileData["updateTime"] = $file["updateTime"];
  221. $newFileData["updateUser"] = $file["updateUser"];
  222. Db::table("new_talent_file")->insert($newFileData);
  223. }
  224. $fieldMaps = [
  225. "name" => "name", "sex" => "sex", "birthday" => "birthday", "nationality" => "nationality", "provinceCode" => "province", "cityCode" => "city", "countyCode" => "county", "cardType" => "card_type",
  226. "idCard" => "card_number", "nation" => "nation", "politics" => "politics", "entryTime" => "cur_entry_time", "post" => "position", "startTime" => "labor_contract_rangetime",
  227. "endTime" => "labor_contract_rangetime", "highEducation" => "highest_degree", "graduateSchool" => "graduate_school", "major" => "major", "title" => "title", "professionalQualifications" => "pro_qua",
  228. "studyAbroad" => "study_abroad", "phone" => "phone", "email" => "email", "bank" => "bank", "bankNetwork" => "bank_branch_name", "bankNumber" => "bank_number", "bankAccount" => "bank_account",
  229. "breakFaith" => "break_faith", "talentArrange" => "talent_arrange", "identifyCondition" => "talent_condition", "identifyConditionName" => "identifyConditionName",
  230. "identifyGetTime" => "identifyGetTime", "educationAndResume" => "education", "mainHonours" => "experience"
  231. ];
  232. if (in_array($talent_info["checkState"], [10, 20])) {
  233. if ($talent_info["fields"]) {
  234. $oldFields = array_filter(explode(",", $talent_info["fields"]));
  235. $tmp = [];
  236. foreach ($oldFields as $_of) {
  237. $tmp[] = $fieldMaps[$_of];
  238. }
  239. $updData["modify_fields"] = implode(",", array_filter(array_unique($tmp)));
  240. }
  241. if ($talent_info["files"]) {
  242. $oldFiles = array_filter(explode(",", $talent_info["files"]));
  243. $tmp = [];
  244. foreach ($oldFiles as $_of) {
  245. $newFileTypeId = $this->getFileTypeId($_of);
  246. $tmp[] = $newFileTypeId;
  247. }
  248. $updData["modify_files"] = implode(",", array_filter(array_unique($tmp)));
  249. }
  250. $updData["id"] = $newTalentInfoId;
  251. Db::table("new_talent_info")->save($updData);
  252. }
  253. $log["last_state"] = $log["new_state"] = $log["state"] = $data["checkState"];
  254. $log["id"] = getStringId();
  255. $log["type"] = \app\common\state\ProjectState::TALENT;
  256. $log["mainId"] = $newTalentInfoId;
  257. $log["active"] = 1;
  258. $log["description"] = "旧系统导入新系统自动生成";
  259. $log["createUser"] = "系统";
  260. $log["createTime"] = date("Y-m-d H:i:s");
  261. \app\common\model\TalentLog::create($log);
  262. return true;
  263. }
  264. return false;
  265. }
  266. private function getNewDictVal($old_pcode, $old_code, $new_pcode, $new_code_default = "") {
  267. $where = [];
  268. $where[] = ["d2.code", "=", $old_pcode];
  269. $where[] = ["d1.code", "=", $old_code];
  270. $oldDict = Db::table("sys_dict")->alias("d1")->leftJoin("sys_dict d2", "d1.pid=d2.id")->where($where)->field("d1.*")->find();
  271. $oldDictName = $oldDict["name"];
  272. $where = [];
  273. $where[] = ["d2.code", "=", $new_pcode];
  274. $where[] = ["d1.name", "=", $oldDictName];
  275. $newDict = Db::table("new_talent_dict")->alias("d1")->leftJoin("new_talent_dict d2", "d1.pid=d2.id")->where($where)->field("d1.*")->find();
  276. return $newDict["code"] ?: $new_code_default;
  277. }
  278. private function getFileTypeId($typeId) {
  279. $fileType = Db::table("un_common_filetype")->where("id", $typeId)->find();
  280. $where = [];
  281. $where[] = ["type", "=", 2];
  282. $where[] = ["project", "=", 1];
  283. $where[] = ["name", "=", $fileType["name"]];
  284. $newFileType = Db::table("new_common_filetype")->where($where)->find();
  285. $newFileTypeId = $newFileType["id"];
  286. if (!$newFileTypeId) {
  287. $newFileTypeData["type"] = $newFileType["type"];
  288. $newFileTypeData["source"] = $newFileType["source"];
  289. $newFileTypeData["project"] = $newFileType["project"];
  290. $newFileTypeData["name"] = $newFileType["name"];
  291. $newFileTypeData["api"] = $newFileType["api"];
  292. $newFileTypeData["must"] = $newFileType["must"];
  293. $newFileTypeData["active"] = $newFileType["active"];
  294. $newFileTypeData["sn"] = $newFileType["sn"];
  295. $newFileTypeData["description"] = $newFileType["description"];
  296. $newFileTypeData["createUser"] = $newFileType["createUser"];
  297. $newFileTypeData["createTime"] = $newFileType["createTime"];
  298. $newFileTypeData["updateUser"] = $newFileType["updateUser"];
  299. $newFileTypeData["updateTime"] = $newFileType["updateTime"];
  300. $newFileTypeData["templateUrl"] = $newFileType["templateUrl"];
  301. $newFileTypeId = Db::table("new_common_filetype")->insertGetId($newFileTypeData);
  302. }
  303. return $newFileTypeId;
  304. }
  305. private function getIdentifyCondition($conditionId) {
  306. $oldCondition = Db::table("un_identify_condition")->where("id", $conditionId)->find();
  307. $where = [];
  308. $where[] = ["name", "=", $oldCondition["name"]];
  309. $where[] = ["type", "=", 2];
  310. $newCondition = Db::table("new_talent_condition")->where($where)->find();
  311. if (!$newCondition) {
  312. $condition["source"] = $oldCondition["source"];
  313. $condition["talentLevel"] = $oldCondition["talentLevel"];
  314. $condition["type"] = $oldCondition["type"];
  315. $condition["name"] = $oldCondition["name"];
  316. $condition["activeYear"] = $oldCondition["activeYear"];
  317. $condition["notWorkYear"] = $oldCondition["notWorkYear"];
  318. $condition["active"] = $oldCondition["active"];
  319. $condition["companyIds"] = $oldCondition["companyIds"];
  320. $condition["description"] = $oldCondition["description"];
  321. $condition["createTime"] = $oldCondition["createTime"];
  322. $condition["createUser"] = $oldCondition["createUser"];
  323. $condition["updateTime"] = $oldCondition["updateTime"];
  324. $condition["updateUser"] = $oldCondition["updateUser"];
  325. $newConditionId = Db::table("new_talent_condition")->insertGetId($condition);
  326. return $newConditionId;
  327. }
  328. return $newCondition["id"];
  329. }
  330. }