Worker.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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[] = ["checkState", ">=", 0];
  51. if (Db::table("new_talent_info")->where($whr)->find()) {
  52. return false;
  53. }
  54. $data["oldId"] = $talent_info["id"];
  55. switch ($talent_info["checkState"]) {
  56. case -1:
  57. $data["checkState"] = TalentState::REVERIFY_FAIL;
  58. break;
  59. case 1:
  60. $data["checkState"] = TalentState::SCND_SAVE;
  61. break;
  62. case 7:
  63. $data["checkState"] = TalentState::SCND_SUBMIT;
  64. break;
  65. case 10:
  66. $data["checkState"] = TalentState::SCND_SAVE;
  67. break;
  68. case 20:
  69. $data["checkState"] = TalentState::SCND_SUBMIT;
  70. break;
  71. case 25:
  72. $data["checkState"] = TalentState::FST_VERIFY_PASS;
  73. break;
  74. case 35:
  75. if ($talent_info["isPublic"] == 5) {
  76. $data["checkState"] = TalentState::PUBLISH_PASS;
  77. } else if ($talent_info["isPublic"] == 6) {
  78. $data["checkState"] = TalentState::CERTIFICATED;
  79. } else {
  80. $data["checkState"] = TalentState::REVERIFY_PASS;
  81. }
  82. break;
  83. }
  84. $data["highProcess"] = 0;
  85. switch ($talent_info["highProcess"]) {
  86. case 1:
  87. if ($talent_info["checkState"] == 25) {
  88. $data["highProcess"] = 3;
  89. }
  90. break;
  91. case 3:
  92. if ($talent_info["checkState"] == 35) {
  93. $data["highProcess"] = 5;
  94. } else {
  95. $data["highProcess"] = 3;
  96. }
  97. break;
  98. }
  99. $data["enterprise_id"] = $talent_info["enterpriseId"];
  100. $data["name"] = $talent_info["name"];
  101. $data["phone"] = $talent_info["phone"];
  102. $data["email"] = $talent_info["email"];
  103. $data["sex"] = $talent_info["sex"];
  104. $data["card_type"] = $talent_info["cardType"];
  105. $data["card_number"] = $talent_info["idCard"];
  106. $data["headimgurl"] = $talent_info["photo"];
  107. $data["birthday"] = $talent_info["birthday"];
  108. $data["apply_year"] = $talent_info["year"];
  109. $data["province"] = $talent_info["provinceCode"];
  110. $data["city"] = $talent_info["cityCode"];
  111. $data["county"] = $talent_info["countyCode"];
  112. $data["nation"] = $this->getNewDictVal("un_nation", $talent_info["nation"], "nation");
  113. $data["nationality"] = $this->getNewDictVal("un_nationality", $talent_info["nationality"], "nationality", "other");
  114. $data["politics"] = $this->getNewDictVal("un_political", $talent_info["politics"], "politics");
  115. $data["highest_degree"] = $this->getNewDictVal("un_education", $talent_info["highEducation"], "highest_degree");
  116. $data["graduate_school"] = $talent_info["graduateSchool"];
  117. $data["major"] = $talent_info["major"];
  118. $data["position"] = $talent_info["post"];
  119. $data["study_abroad"] = $talent_info["studyAbroad"];
  120. $data["cur_entry_time"] = $talent_info["entryTime"];
  121. $data["cur_quit_time"] = $talent_info["quitTime"];
  122. $data["labor_contract_rangetime"] = $talent_info["startTime"] . " - " . $talent_info["endTime"];
  123. $data["talent_arrange"] = $talent_info["talentArrange"];
  124. $data["talent_condition"] = $this->getIdentifyCondition($talent_info["identifyCondition"]);
  125. $data["publicBatch"] = $talent_info["publicBatch"];
  126. $data["identifyConditionName"] = $talent_info["identifyConditionName"];
  127. $data["identifyGetTime"] = $talent_info["identifyGetTime"];
  128. $data["identifyExpireTime"] = $talent_info["identifyOutTime"];
  129. $data["identifyMonth"] = $talent_info["identifyMonth"];
  130. $data["certificateNo"] = $talent_info["certificateNO"];
  131. $data["certificateGetTime"] = $talent_info["certificateStartTime"];
  132. $data["certificateExpireTime"] = $talent_info["qzgccrcActiveTime"];
  133. $data["title"] = $talent_info["title"];
  134. $data["pro_qua"] = $talent_info["professionalQualifications"];
  135. $data["bank"] = $talent_info["bank"];
  136. $data["bank_branch_name"] = $talent_info["bankNetwork"];
  137. $data["bank_account"] = $talent_info["bankAccount"];
  138. $data["description"] = $talent_info["description"];
  139. $data["experience"] = $talent_info["mainHonours"];
  140. $data["education"] = $talent_info["educationAndResume"];
  141. $data["createTime"] = $talent_info["createTime"];
  142. $data["break_faith"] = $talent_info["breakFaith"];
  143. $data["first_submit_time"] = $talent_info["firstSubmitTime"];
  144. $data["new_submit_time"] = $talent_info["newSubmitTime"];
  145. $data["first_dept_check_time"] = $talent_info["firstDepPassTime"];
  146. $data["active"] = $talent_info["active"];
  147. $newTalentInfoId = Db::table("new_talent_info")->insertGetId($data);
  148. if ($newTalentInfoId) {
  149. $files = Db::table("un_talent_file")->where("mainId", $talent_info["id"])->select();
  150. foreach ($files as $file) {
  151. $newFileTypeId = $this->getFileTypeId($file["fileTypeId"]);
  152. $newFileData["mainId"] = $newTalentInfoId;
  153. $newFileData["type"] = 2;
  154. $newFileData["typeId"] = $newFileTypeId;
  155. $newFileData["orignName"] = $file["orignName"];
  156. $newFileData["url"] = $file["url"];
  157. $newFileData["sn"] = $file["sn"];
  158. $newFileData["description"] = $file["description"];
  159. $newFileData["createTime"] = $file["createTime"];
  160. $newFileData["createUser"] = $file["createUser"];
  161. $newFileData["updateTime"] = $file["updateTime"];
  162. $newFileData["updateUser"] = $file["updateUser"];
  163. Db::table("new_talent_file")->insert($newFileData);
  164. }
  165. $fieldMaps = [
  166. "name" => "name", "sex" => "sex", "birthday" => "birthday", "nationality" => "nationality", "provinceCode" => "province", "cityCode" => "city", "countyCode" => "county", "cardType" => "card_type",
  167. "idCard" => "card_number", "nation" => "nation", "politics" => "politics", "entryTime" => "cur_entry_time", "post" => "position", "startTime" => "labor_contract_rangetime",
  168. "endTime" => "labor_contract_rangetime", "highEducation" => "highest_degree", "graduateSchool" => "graduate_school", "major" => "major", "title" => "title", "professionalQualifications" => "pro_qua",
  169. "studyAbroad" => "study_abroad", "phone" => "phone", "email" => "email", "bank" => "bank", "bankNetwork" => "bank_branch_name", "bankNumber" => "bank_number", "bankAccount" => "bank_account",
  170. "breakFaith" => "break_faith", "talentArrange" => "talent_arrange", "identifyCondition" => "talent_condition", "identifyConditionName" => "identifyConditionName",
  171. "identifyGetTime" => "identifyGetTime", "educationAndResume" => "education", "mainHonours" => "experience"
  172. ];
  173. if (in_array($talent_info["checkState"], [10, 20])) {
  174. if ($talent_info["fields"]) {
  175. $oldFields = array_filter(explode(",", $talent_info["fields"]));
  176. $tmp = [];
  177. foreach ($oldFields as $_of) {
  178. $tmp[] = $fieldMaps[$_of];
  179. }
  180. $updData["modify_fields"] = implode(",", array_filter(array_unique($tmp)));
  181. }
  182. if ($talent_info["files"]) {
  183. $oldFiles = array_filter(explode(",", $talent_info["files"]));
  184. $tmp = [];
  185. foreach ($oldFiles as $_of) {
  186. $newFileTypeId = $this->getFileTypeId($_of);
  187. $tmp[] = $newFileTypeId;
  188. }
  189. $updData["modify_files"] = implode(",", array_filter(array_unique($tmp)));
  190. }
  191. $updData["id"] = $newTalentInfoId;
  192. Db::table("un_talent_info")->save($updData);
  193. }
  194. return true;
  195. }
  196. return false;
  197. }
  198. private function getNewDictVal($old_pcode, $old_code, $new_pcode, $new_code_default = "") {
  199. $where = [];
  200. $where[] = ["d2.code", "=", $old_pcode];
  201. $where[] = ["d1.code", "=", $old_code];
  202. $oldDict = Db::table("sys_dict")->alias("d1")->leftJoin("sys_dict d2", "d1.pid=d2.id")->where($where)->field("d1.*")->find();
  203. $oldDictName = $oldDict["name"];
  204. $where = [];
  205. $where[] = ["d2.code", "=", $new_pcode];
  206. $where[] = ["d1.name", "=", $oldDictName];
  207. $newDict = Db::table("new_talent_dict")->alias("d1")->leftJoin("new_talent_dict d2", "d1.pid=d2.id")->where($where)->field("d1.*")->find();
  208. return $newDict["code"] ?: $new_code_default;
  209. }
  210. private function getFileTypeId($typeId) {
  211. $fileType = Db::table("un_common_filetype")->where("id", $typeId)->find();
  212. $where = [];
  213. $where[] = ["type", "=", 2];
  214. $where[] = ["project", "=", 1];
  215. $where[] = ["name", "=", $fileType["name"]];
  216. $newFileType = Db::table("new_common_filetype")->where($where)->find();
  217. $newFileTypeId = $newFileType["id"];
  218. if (!$newFileTypeId) {
  219. $newFileTypeData["type"] = $newFileType["type"];
  220. $newFileTypeData["source"] = $newFileType["source"];
  221. $newFileTypeData["project"] = $newFileType["project"];
  222. $newFileTypeData["name"] = $newFileType["name"];
  223. $newFileTypeData["api"] = $newFileType["api"];
  224. $newFileTypeData["must"] = $newFileType["must"];
  225. $newFileTypeData["active"] = $newFileType["active"];
  226. $newFileTypeData["sn"] = $newFileType["sn"];
  227. $newFileTypeData["description"] = $newFileType["description"];
  228. $newFileTypeData["createUser"] = $newFileType["createUser"];
  229. $newFileTypeData["createTime"] = $newFileType["createTime"];
  230. $newFileTypeData["updateUser"] = $newFileType["updateUser"];
  231. $newFileTypeData["updateTime"] = $newFileType["updateTime"];
  232. $newFileTypeData["templateUrl"] = $newFileType["templateUrl"];
  233. $newFileTypeId = Db::table("new_common_filetype")->insertGetId($newFileTypeData);
  234. }
  235. return $newFileTypeId;
  236. }
  237. private function getIdentifyCondition($conditionId) {
  238. $oldCondition = Db::table("un_identify_condition")->where("id", $conditionId)->find();
  239. $where = [];
  240. $where[] = ["name", "=", $oldCondition["name"]];
  241. $where[] = ["type", "=", 2];
  242. $newCondition = Db::table("new_talent_condition")->where($where)->find();
  243. return $newCondition["id"];
  244. }
  245. }