Worker.php 12 KB

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