DesktopDeviceJob.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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.'getlist'.PHP_EOL,8);
  90. return json_decode($response,true);
  91. }
  92. public function completionOrders($data){
  93. list($status,$token) = ClearDataService::getToken();
  94. if(! $status) return;
  95. //组织数据
  96. $completion_orders_dtl = [];
  97. $first = $data['content'][0]['dispatch_orders'];
  98. foreach ($data['content'] as $value){
  99. $completion_orders_dtl[] = [
  100. "item_num" => $value['item_num'],
  101. "product_no" => $value['product_no'],
  102. "in_product_tile" => $value['in_product_tile'],
  103. "in_process_title" => $value['in_process_title'],
  104. "in_color" => $value['in_color'],
  105. "in_process_title_two" => $value['in_process_title_two'],
  106. "in_color_two" => $value['in_color_two'],
  107. "product_size" => $value['product_size'],
  108. "product_unit" => $value['product_unit'],
  109. "product_unit_title" => $value['product_unit_title'],
  110. "finished_num" => $value['dispatch_num'],
  111. "dispatch_num" => $value['dispatch_num'],
  112. "production_num" => $value['production_num'],
  113. "production_no" => $value['production_no'],
  114. "production_item_no" => $value['production_item_no'],
  115. "dispatch_order_no" => $first['dispatch_no'],
  116. // "dispatch_item_no" => $value['dispatch_item_no'],
  117. "order_no" => $value['order_no'],
  118. "order_item_no" => $value['order_item_no'],
  119. "customer_no" => $value['customer_no'],
  120. "customer_name" => $value['customer_name'],
  121. "dealer_no" => $value['dealer_no'],
  122. "dealer_name" => $value['dealer_name'],
  123. "product_title" => $value['product_title'],
  124. "process_title" => $value['process_title'],
  125. "color" => $value['color'],
  126. "process_title_two" => $value['process_title_two'],
  127. "color_two" => $value['color_two'],
  128. "color_code_two" => $value['color_code_two'],
  129. // "dispatch_item_id" => $value['dispatch_item_id'],
  130. "process_code_two" => $value['process_code_two'],
  131. "color_code" => $value['color_code'],
  132. "order_item_id" => $value['order_item_id'],
  133. "production_item_id" => $value['production_item_id'],
  134. "process_code" => $value['process_code'],
  135. "process_router_id" => $value['process_router_id'],
  136. "craft_type_dk" => $value['craft_type_dk'],
  137. "craft_type_dk_show" => $value['craft_type_dk_show'],
  138. "mat_type" => $value['mat_type'],
  139. "site" => null,
  140. // "not_finished_num" => $value['not_finished_num'],
  141. // "lineId" => $value['lineId'],
  142. // "mainKey" => $value['mainKey']
  143. ];
  144. }
  145. $completion_orders = [
  146. "completion_order_no" => null,
  147. "completion_time" => gmdate("Y-m-d\TH:i:s.000\Z"),
  148. "process_id" => $first['process_id'],
  149. "team_id" => $first['team_id'],
  150. "equipment_id" => $first['equipment_id'],
  151. "employee_id" => $first['employee_id'],
  152. "remark" => $first['remark'],
  153. "site" => null,
  154. "created_by" => null,
  155. "created_date" => null,
  156. "last_modified_by" => null,
  157. "last_modified_date" => null,
  158. "process_id_show" => $first['process_id_show'],
  159. "team_id_show" => $first['team_id_show'],
  160. "equipment_id_show" => $first['equipment_id_show'],
  161. "employee_id_show" => $first['employee_id_show']
  162. ];
  163. $post = [
  164. "bizTypeEk" => "LOWCODE",
  165. "bizId" => -1,
  166. "data" => [
  167. "completion_orders_dtl" => $completion_orders_dtl,
  168. "completion_orders" => $completion_orders
  169. ],
  170. "dynamicFormId" => "474201923419320320",
  171. "showModelId" => "474382714828959744"
  172. ];
  173. //组织数据------
  174. $url = 'http://121.36.142.167:7774/jbl/api/module-data/completion_orders/completion_orders';
  175. $header = ["Authorization: Bearer {$token}","Content-Type:application/json",'Site:91451322MA5P9JNKXA'];
  176. $curl = curl_init();
  177. curl_setopt_array($curl, array(
  178. CURLOPT_URL => $url,
  179. CURLOPT_RETURNTRANSFER => true,
  180. CURLOPT_ENCODING => '',
  181. CURLOPT_MAXREDIRS => 10,
  182. CURLOPT_TIMEOUT => 0,
  183. CURLOPT_FOLLOWLOCATION => true,
  184. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  185. CURLOPT_CUSTOMREQUEST => 'POST',
  186. CURLOPT_POSTFIELDS => json_encode($post),
  187. CURLOPT_HTTPHEADER => $header,
  188. ));
  189. $response = curl_exec($curl);
  190. curl_close($curl);
  191. file_put_contents('record_get_dispatch.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL.'create'.PHP_EOL,8);
  192. }
  193. protected function echoMessage(OutputInterface $output)
  194. {
  195. $output->writeln($this->data);
  196. }
  197. }