Worker.php 16 KB

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