DesktopDeviceJob.php 8.8 KB

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