Worker.php 14 KB

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