DesktopDeviceJob.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. namespace App\Jobs;
  3. use App\Service\ClearDataService;
  4. use Illuminate\Bus\Queueable;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Foundation\Bus\Dispatchable;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. use Illuminate\Queue\SerializesModels;
  9. use Illuminate\Support\Facades\Redis;
  10. use Symfony\Component\Console\Output\ConsoleOutput;
  11. use Symfony\Component\Console\Output\OutputInterface;
  12. class DesktopDeviceJob implements ShouldQueue
  13. {
  14. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  15. protected $data;
  16. /**
  17. * Create a new job instance.
  18. *
  19. * @return void
  20. */
  21. public function __construct($data)
  22. {
  23. $this->data = $data;
  24. }
  25. /**
  26. * Execute the job.
  27. *
  28. * @return void
  29. */
  30. public function handle()
  31. {
  32. try{
  33. $first = ltrim($this->data[0],'0');//取第一个值
  34. $order_num = hex2bin($first); //十六进制字符串转回 原来字符串
  35. file_put_contents('record_complete.txt',date("Y-m-d H:i:s",time())."原数据:$first" . "解析后:" . $order_num . PHP_EOL,8);
  36. if(! $order_num) return;
  37. // 使用Redis Facade设置键名为order_number的值,当键名不存在时才设置成功
  38. if (Redis::setnx($order_num, $order_num)) {
  39. Redis::expire($order_num, 120);
  40. $dispatchList = $this->getDispatchList($order_num);
  41. if(empty($dispatchList) || empty($dispatchList['content'])) return;
  42. $this->completionOrders($dispatchList);
  43. file_put_contents('send_record.txt',date('Y-m-d H:i:s').$order_num . PHP_EOL,8);
  44. }
  45. //输出信息 测试
  46. $this->echoMessage(new ConsoleOutput());
  47. }catch (\Exception $exception){
  48. file_put_contents('record_error.txt',date("Y-m-d H:i:s",time()).json_encode($this->data) . PHP_EOL.$exception->getMessage().PHP_EOL,8);
  49. }
  50. }
  51. public function getDispatchList($data){
  52. if(empty($data)) return [];
  53. list($status,$token) = ClearDataService::getToken();
  54. if(! $status) return;
  55. $url = 'http://121.36.142.167:7774/jbl/api/module-data/dispatch_orders/page';
  56. $post = [
  57. 'direction' => 'DESC',
  58. 'property' => 'id',
  59. 'fromClientType' => 'pc',
  60. 'number' => 0,
  61. 'sorts' => [],
  62. 'rules' => [['field' =>'dispatch_orders.dispatch_no','option' => 'LIKE_ANYWHERE', 'values' => [$data]]],
  63. "size"=> 15,
  64. "specialConditions" => [],
  65. "workflowSearchBean" => [],
  66. "dynamicFormCode" => "dispatch_orders",
  67. "dynamicFormTable" => null,
  68. "ignoreField" => true,
  69. "developmentSystemId" => null,
  70. "debugFlag" => true,
  71. ];
  72. $header = ["Authorization: Bearer {$token}","Content-Type:application/json",'Site:91451322MA5P9JNKXA'];
  73. $json = str_replace('"workflowSearchBean":[]','"workflowSearchBean":{}',json_encode($post));
  74. $curl = curl_init();
  75. curl_setopt_array($curl, array(
  76. CURLOPT_URL => $url,
  77. CURLOPT_RETURNTRANSFER => true,
  78. CURLOPT_ENCODING => '',
  79. CURLOPT_MAXREDIRS => 10,
  80. CURLOPT_TIMEOUT => 0,
  81. CURLOPT_FOLLOWLOCATION => true,
  82. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  83. CURLOPT_CUSTOMREQUEST => 'POST',
  84. CURLOPT_POSTFIELDS => $json,
  85. CURLOPT_HTTPHEADER => $header,
  86. ));
  87. $response = curl_exec($curl);
  88. curl_close($curl);
  89. file_put_contents('record_get_dispatch.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL,8);
  90. return json_decode($response,true);
  91. }
  92. public function completionOrders($data){
  93. //组织数据
  94. $completion_orders_dtl = [];
  95. $first = $data['content'][0]['dispatch_orders'];
  96. foreach ($data['content'] as $value){
  97. $completion_orders_dtl[] = [
  98. "item_num" => $value['item_num'],
  99. "product_no" => $value['product_no'],
  100. "in_product_tile" => $value['in_product_tile'],
  101. "in_process_title" => $value['in_process_title'],
  102. "in_color" => $value['in_color'],
  103. "in_process_title_two" => $value['in_process_title_two'],
  104. "in_color_two" => $value['in_color_two'],
  105. "product_size" => $value['product_size'],
  106. "product_unit" => $value['product_unit'],
  107. "product_unit_title" => $value['product_unit_title'],
  108. "finished_num" => $value['dispatch_num'],
  109. "dispatch_num" => $value['dispatch_num'],
  110. "production_num" => $value['production_num'],
  111. "production_no" => $value['production_no'],
  112. "production_item_no" => $value['production_item_no'],
  113. "dispatch_order_no" => $first['dispatch_no'],
  114. // "dispatch_item_no" => $value['dispatch_item_no'],
  115. "order_no" => $value['order_no'],
  116. "order_item_no" => $value['order_item_no'],
  117. "customer_no" => $value['customer_no'],
  118. "customer_name" => $value['customer_name'],
  119. "dealer_no" => $value['dealer_no'],
  120. "dealer_name" => $value['dealer_name'],
  121. "product_title" => $value['product_title'],
  122. "process_title" => $value['process_title'],
  123. "color" => $value['color'],
  124. "process_title_two" => $value['process_title_two'],
  125. "color_two" => $value['color_two'],
  126. "color_code_two" => $value['color_code_two'],
  127. // "dispatch_item_id" => $value['dispatch_item_id'],
  128. "process_code_two" => $value['process_code_two'],
  129. "color_code" => $value['color_code'],
  130. "order_item_id" => $value['order_item_id'],
  131. "production_item_id" => $value['production_item_id'],
  132. "process_code" => $value['process_code'],
  133. "process_router_id" => $value['process_router_id'],
  134. "craft_type_dk" => $value['craft_type_dk'],
  135. "craft_type_dk_show" => $value['craft_type_dk_show'],
  136. "mat_type" => $value['mat_type'],
  137. "site" => null,
  138. // "not_finished_num" => $value['not_finished_num'],
  139. // "lineId" => $value['lineId'],
  140. // "mainKey" => $value['mainKey']
  141. ];
  142. }
  143. $completion_orders = [
  144. "completion_order_no" => null,
  145. "completion_time" => gmdate("Y-m-d\TH:i:s.000\Z"),
  146. "process_id" => $first['process_id'],
  147. "team_id" => $first['team_id'],
  148. "equipment_id" => $first['equipment_id'],
  149. "employee_id" => $first['employee_id'],
  150. "remark" => $first['remark'],
  151. "site" => null,
  152. "created_by" => null,
  153. "created_date" => null,
  154. "last_modified_by" => null,
  155. "last_modified_date" => null,
  156. "process_id_show" => $first['process_id_show'],
  157. "team_id_show" => $first['team_id_show'],
  158. "equipment_id_show" => $first['equipment_id_show'],
  159. "employee_id_show" => $first['employee_id_show']
  160. ];
  161. $post = [
  162. "bizTypeEk" => "LOWCODE",
  163. "bizId" => -1,
  164. "data" => [
  165. "completion_orders_dtl" => $completion_orders_dtl,
  166. "completion_orders" => $completion_orders
  167. ],
  168. "dynamicFormId" => "474201923419320320",
  169. "showModelId" => "474382714828959744"
  170. ];
  171. //组织数据------
  172. $url = 'http://121.36.142.167:7774/jbl/api/module-data/completion_orders/completion_orders';
  173. $header = ['Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwiYXV0aCI6IlJPTEVfSU5ORVJfVVNFUixST0xFX0FETUlOLFJPTEVfSU5URVJGQUNFIiwidG9rZW5JZCI6IjM1IiwiZXhwIjoxNjk0Njc0MTE0fQ.L3Di3K_cpF0rWSgvzbcLufLm8bkCxd3Y-xudfKzSm4F-qdpDr0hYWWQP5K5BYTNuZnu4tWpGmSW2KRHU0pjt-A','Content-Type:application/json','Site:010800179'];
  174. $curl = curl_init();
  175. curl_setopt_array($curl, array(
  176. CURLOPT_URL => $url,
  177. CURLOPT_RETURNTRANSFER => true,
  178. CURLOPT_ENCODING => '',
  179. CURLOPT_MAXREDIRS => 10,
  180. CURLOPT_TIMEOUT => 0,
  181. CURLOPT_FOLLOWLOCATION => true,
  182. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  183. CURLOPT_CUSTOMREQUEST => 'POST',
  184. CURLOPT_POSTFIELDS => json_encode($post),
  185. CURLOPT_HTTPHEADER => $header,
  186. ));
  187. $response = curl_exec($curl);
  188. curl_close($curl);
  189. file_put_contents('record_get_dispatch.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL,8);
  190. }
  191. protected function echoMessage(OutputInterface $output)
  192. {
  193. $output->writeln($this->data);
  194. }
  195. }