1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
package cn.flightfeather.thirdapp.fragment;
 
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
 
import com.ping.greendao.gen.ScenseDao;
 
import org.greenrobot.greendao.query.QueryBuilder;
 
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
 
import cn.flightfeather.thirdapp.CommonApplication;
import cn.flightfeather.thirdapp.R;
import cn.flightfeather.thirdapp.activity.NewMonthTaskActivity;
import cn.flightfeather.thirdapp.activity.ScenseMapActivity;
import cn.flightfeather.thirdapp.activity.TaskActivity;
import cn.flightfeather.thirdapp.adapter.RecyclerItemClickListener;
import cn.flightfeather.thirdapp.adapter.TaskListAdapter;
import cn.flightfeather.thirdapp.bean.entity.Scense;
import cn.flightfeather.thirdapp.bean.entity.Subtask;
import cn.flightfeather.thirdapp.bean.vo.TaskPack;
import cn.flightfeather.thirdapp.bean.entity.Userinfo;
import cn.flightfeather.thirdapp.bean.vo.TaskVo;
import cn.flightfeather.thirdapp.httpservice.SubTaskService;
import cn.flightfeather.thirdapp.httpservice.TaskService;
import cn.flightfeather.thirdapp.module.task.MonthTaskManagementActivity;
import cn.flightfeather.thirdapp.module.task.NewSubTaskActivity;
import cn.flightfeather.thirdapp.module.task.SceneDetailActivity;
import cn.flightfeather.thirdapp.util.CommonUtils;
import cn.flightfeather.thirdapp.util.Constant;
import cn.flightfeather.thirdapp.util.DateFormatter;
import cn.flightfeather.thirdapp.util.Domain;
import cn.flightfeather.thirdapp.util.UUIDGenerator;
import cn.flightfeather.thirdapp.view.CircleProgressView;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
 
/**
 * A simple {@link Fragment} subclass.
 */
public class TaskFragment extends Fragment implements RecyclerItemClickListener.OnItemClickListener
        , View.OnClickListener {
 
    private int taskKindChoice;
    private CommonApplication application;
    private Retrofit mRetrofit;
    private boolean requestAgain;
    private Map<String, List<TaskVo>> taskAllMapList = new HashMap<>();
    private boolean firstLoad = true;
    private String mCurYearMonth;
    private String mToday;
    private ArrayList<TaskVo> mTopClassTaskList = new ArrayList<>();
    private ArrayList<Subtask> mSubtaskList = new ArrayList<>();
    private ArrayList<TaskVo> mDayTaskList = new ArrayList<>();
    private CircleProgressView daytask_circleprogress;
    private CircleProgressView weektask_circleprogress;
    private CircleProgressView monthtask_circleprogress;
    private TaskListAdapter mAdapter;
    private View tv_no_task;
    private View view_waiting;
    private AlertDialog mCreateUnfixedScenseTaskDialog;
    private int mTopClassTaskChoice;
 
    public TaskFragment() {
        // Required empty public constructor
    }
 
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_task, container, false);
    }
 
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initData();
        initUI(view);
    }
 
    /**
     * 获取数据
     */
    private void initData() {
        application = (CommonApplication) getActivity().getApplication();
        mRetrofit = application.getRetrofit();
        Date now = Calendar.getInstance().getTime();
        mCurYearMonth = DateFormatter.YearMonthFormat.format(now);
        mToday = DateFormatter.dateFormat2.format(now);
        getThreeMonthTask(mCurYearMonth, Constant.TASK_GETINFOTYPE_MIDDLE);
    }
 
    private void initUI(View view) {
        ViewGroup rl_addTask = view.findViewById(R.id.rl_add_task);
        view.findViewById(R.id.rl_scense_map).setOnClickListener(this);
        view.findViewById(R.id.rl_add_scense).setOnClickListener(this);
        view.findViewById(R.id.day_task).setOnClickListener(this);
        view.findViewById(R.id.week_task).setOnClickListener(this);
        view.findViewById(R.id.month_task).setOnClickListener(this);
        view.findViewById(R.id.ll_container_taskadjust).setOnClickListener(this);
        view_waiting = view.findViewById(R.id.view_waiting);
        tv_no_task = view.findViewById(R.id.tv_no_task);
        RecyclerView mRecyclerView = (RecyclerView) view.findViewById(R.id.rv_container);
        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        mRecyclerView.setLayoutManager(manager);
        mAdapter = new TaskListAdapter(getActivity(), mSubtaskList);
        mAdapter.setShowDate(false);
        mRecyclerView.setAdapter(mAdapter);
        mRecyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), mRecyclerView, this));
        daytask_circleprogress = (CircleProgressView) view.findViewById(R.id.daytask_circleprogress);
        weektask_circleprogress = (CircleProgressView) view.findViewById(R.id.weektask_circleprogress);
        monthtask_circleprogress = (CircleProgressView) view.findViewById(R.id.monthtask_circleprogress);
 
        daytask_circleprogress.setRGB(83, 230, 149);
        weektask_circleprogress.setRGB(107, 191, 245);
        monthtask_circleprogress.setRGB(236, 120, 101);
 
        daytask_circleprogress.setProgress(0, 0);
        weektask_circleprogress.setProgress(0, 0);
        monthtask_circleprogress.setProgress(0, 0);
        rl_addTask.setOnClickListener(this);
    }
 
    /**
     * 获取当前月及前后月的任务信息
     *
     * @param yearMonth 年月:例:2018-01
     * @param type      Middle、Left、Right
     */
    private void getThreeMonthTask(final String yearMonth, final String type) {
        Call<List<TaskPack>> loadThreeMonthTasks = mRetrofit.create(TaskService.class).loadThreeMonthTasks(yearMonth, application.getCurrentUser().getGuid(), type);
        loadThreeMonthTasks.enqueue(new Callback<List<TaskPack>>() {
            @Override
            public void onResponse(@NonNull Call<List<TaskPack>> call, @NonNull Response<List<TaskPack>> response) {
                view_waiting.setVisibility(View.GONE);
                if (response.body() != null) {
                    requestAgain = false;
                    List<TaskPack> taskPackList = response.body();
                    if (taskPackList != null && taskPackList.size() > 0) {
                        for (TaskPack taskPack : taskPackList) {
                            taskAllMapList.put(taskPack.getDate(), taskPack.getUpperTaskList());
                        }
                        if (firstLoad) {
                            firstLoad = false;
//                            showMonthAllTask(calendarCurrent);
                        }
                        invalidate();
                    }
                } else if (response.errorBody() != null) {
                    if (!requestAgain) {
                        requestAgain = true;
                        getThreeMonthTask(yearMonth, type);
                    } else {
                        Toast.makeText(application, "获取任务信息出错", Toast.LENGTH_SHORT).show();
//                        showMonthAllTask(calendarCurrent);
                    }
                    System.out.println("ThreeMonthTask:" + response.errorBody());
                }
            }
 
            @Override
            public void onFailure(@NonNull Call<List<TaskPack>> call, @NonNull Throwable t) {
                if (!requestAgain) {
                    requestAgain = true;
                    getThreeMonthTask(yearMonth, type);
                } else {
                    Toast.makeText(application, "网络链接失败", Toast.LENGTH_SHORT).show();
//                    showMonthAllTask(calendarCurrent);
                }
                System.out.println("ThreeMonthTask:" + t.toString());
            }
        });
    }
 
    /**
     * 遍历获取的数据,更新界面
     */
    private void invalidate() {
        mTopClassTaskList.clear();
        mDayTaskList.clear();
        mSubtaskList.clear();
        int daytaskTotalNumThisWeek = 0;
        int daytaskFinishedNumThisWeek = 0;
        int daytaskTotalNumThisMonth = 0;
        int daytaskFinishedNumThisMonth = 0;
        int subtaskTotalNumToday = 0;
        int subtaskFinishedNumToday = 0;
        for (TaskVo taskVo : taskAllMapList.get(mCurYearMonth)) {
            mTopClassTaskList.add(taskVo);
            for (TaskVo dayTaskVo : taskVo.getDaytaskList()) {
                daytaskTotalNumThisMonth++;
                mDayTaskList.add(dayTaskVo);
                long taskTime = dayTaskVo.getStarttime().getTime();
                long monday = CommonUtils.getTimesWeekmorning().getTime();
                long sunday = CommonUtils.getTimesWeeknight().getTime();
                if (taskTime >= monday && taskTime <= sunday) {
                    daytaskTotalNumThisWeek++;
                    if (dayTaskVo.getRuningstatus().equals(Domain.TASK_STATUS_FINISHED)) {
                        daytaskFinishedNumThisWeek++;
                    }
                }
                if (dayTaskVo.getRuningstatus().equals(Domain.TASK_STATUS_FINISHED)) {
                    daytaskFinishedNumThisMonth++;
                }
                List<Subtask> subTaskList = dayTaskVo.getSubtaskList();
                for (Subtask subtask : subTaskList) {
                    String subtaskStartTime = DateFormatter.dateFormat2.format(subtask.getPlanstarttime());
                    if (subtaskStartTime.equals(mToday)) {
                        subtaskTotalNumToday++;
                        if (subtask.getStatus().equals(Domain.TASK_STATUS_FINISHED)) {
                            subtaskFinishedNumToday++;
                        }
                        mSubtaskList.add(subtask);
                    }
                }
            }
        }
        daytask_circleprogress.setProgress(subtaskFinishedNumToday, subtaskTotalNumToday);
        weektask_circleprogress.setProgress(daytaskFinishedNumThisWeek, daytaskTotalNumThisWeek);
        monthtask_circleprogress.setProgress(daytaskFinishedNumThisMonth, daytaskTotalNumThisMonth);
 
        if (mSubtaskList.size() > 0) {
            mAdapter.notifyDataSetChanged();
            tv_no_task.setVisibility(View.GONE);
        }
    }
 
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_add_task:
                showTaskKindDialog();
                break;
            case R.id.rl_scense_map:
                Intent intent1 = new Intent(getActivity(), ScenseMapActivity.class);
                intent1.putExtra(Constant.KEY_INTENT_TODAY_TASKLIST, mSubtaskList);
                getActivity().startActivityForResult(intent1, Constant.REQUESTCODE_FROM_TASKFRAGMENT);
                break;
            case R.id.rl_add_scense:
                startActivity(new Intent(getActivity(), SceneDetailActivity.class));
                break;
            case R.id.day_task:
            case R.id.week_task:
            case R.id.month_task:
                Intent intent = new Intent(getActivity(), TaskActivity.class);
                intent.putExtra(Constant.KEY_INTENT_TASK_PERIOD, v.getId());
                startActivity(intent);
                break;
            case R.id.ll_container_taskadjust:
                Intent intent2 = new Intent(getActivity(), MonthTaskManagementActivity.class);
                startActivity(intent2);
                break;
        }
    }
 
    /**
     * 显示新增任务类型:顶层任务、子任务
     * @deprecated Use {@link #showTaskKindDialog_newType()}
     */
    @Deprecated
    private void showTaskKindDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
        //无固定场景巡查任务是当任务类型为巡查时才使用,故此次放该选项不合适,暂时先放此处
        final String[] items = {"顶层任务", "子任务", "无固定场景巡查任务"};
        builder.setTitle("选择任务类型");
        builder.setSingleChoiceItems(items, taskKindChoice,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        taskKindChoice = which;
                    }
                });
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                Intent intent;
                if (taskKindChoice < 2) {
                    if (taskKindChoice == 0) {
                        intent = new Intent(getActivity(), NewMonthTaskActivity.class);
                    } else {
//                        intent = new Intent(getActivity(), MOVMapActivity.class);
//                        intent.putExtra(Constant.KEY_INTENT_MODE, MOVMapActivity.MODE_ADD_SUBTASK);
                        intent = new Intent(getActivity(), NewSubTaskActivity.class);
                    }
                    startActivity(intent);
                } else {
                    showCreateUnfixedScenseTaskDialog();
                }
 
            }
        });
        builder.create().show();
    }
 
    /**
     * 2018.11.05 by riku
     * 更换新样式的弹出框,功能未修改
     * 显示新增任务类型:顶层任务、子任务
     */
    private void showTaskKindDialog_newType() {
 
    }
 
    private void showCreateUnfixedScenseTaskDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
        final ArrayList<TaskVo> list = new ArrayList<>();
        for (TaskVo taskVo : mTopClassTaskList) {
            if (taskVo.getExtension2() != null && taskVo.getExtension2().equals(Domain.UNFIXED_SCNESE_ALLOWED)) {
                list.add(taskVo);
            }
        }
        final String[] items = new String[list.size()];
        for (int i = 0; i < items.length; i++) {
            TaskVo taskVo = list.get(i);
            items[i] = taskVo.getName();
        }
        builder.setSingleChoiceItems(items, mTopClassTaskChoice,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        mTopClassTaskChoice = which;
                    }
                });
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (list.isEmpty()) {
                    return;
                }
                showCheckTaskInfoDialog(list.get(mTopClassTaskChoice));
            }
        });
        mCreateUnfixedScenseTaskDialog = builder.create();
        mCreateUnfixedScenseTaskDialog.show();
    }
 
    private void showCheckTaskInfoDialog(final TaskVo taskVo) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
        builder.setTitle("提示");
        builder.setMessage("当前选中的顶层任务为" + taskVo.getName());
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                createSubtask(taskVo);
            }
        });
        builder.create().show();
    }
 
    private void createSubtask(TaskVo topClassTask) {
        SubTaskService subtaskService = mRetrofit.create(SubTaskService.class);
        Subtask subtask = new Subtask();
        TaskVo currentDayTask = null;
        Calendar now = Calendar.getInstance();
        for (TaskVo taskVo : mDayTaskList) {
            if (taskVo.getTsguid().equals(topClassTask.getTguid())) {
                Calendar cal = Calendar.getInstance();
                cal.setTime(taskVo.getStarttime());
                if (now.get(Calendar.YEAR) == cal.get(Calendar.YEAR)
                        && now.get(Calendar.MONTH) == cal.get(Calendar.MONTH)
                        && now.get(Calendar.DAY_OF_MONTH) == cal.get(Calendar.DAY_OF_MONTH)) {
                    currentDayTask = taskVo;
                    break;
                }
            }
        }
        if (currentDayTask == null) {
            currentDayTask = createDayTask(topClassTask);
            callPutDayTask(topClassTask, subtaskService, subtask, currentDayTask, now);
        } else {
            callPutSubtask(topClassTask, subtaskService, subtask, currentDayTask, now);
        }
    }
 
    private void callPutSubtask(TaskVo topClassTask, SubTaskService subtaskService,
                                final Subtask subtask, TaskVo currentDayTask, Calendar now) {
        subtask.setStguid(UUIDGenerator.generate16ShortUUID());
        subtask.setTguid(topClassTask.getTguid());
        subtask.setTsguid(currentDayTask.getTguid());
        subtask.setTypeno(topClassTask.getTypeno());
        subtask.setType(topClassTask.getTypename());
        subtask.setProvincecode(topClassTask.getProvincecode());
        subtask.setProvincename(topClassTask.getProvincename());
        subtask.setCitycode(topClassTask.getCitycode());
        subtask.setCityname(topClassTask.getCityname());
        subtask.setDistrictcode(topClassTask.getDistrictcode());
        subtask.setDistrictname(topClassTask.getDistrictname());
        subtask.setTowncode(topClassTask.getTowncode());
        subtask.setTownname(topClassTask.getTownname());
        QueryBuilder<Scense> qb = application.getDaoSession().getScenseDao().queryBuilder();
        Scense scense;
        if (subtask.getTowncode() == null) {
            scense = qb.where(ScenseDao.Properties.Provincecode.eq(subtask.getProvincecode())
                    , ScenseDao.Properties.Citycode.eq(subtask.getCitycode())
                    , ScenseDao.Properties.Districtcode.eq(subtask.getDistrictcode())
                    , ScenseDao.Properties.Typeid.eq(Domain.SCENSETYPE_UNFIXED_SCENSE)).unique();
        } else {
            scense = qb.where(ScenseDao.Properties.Provincecode.eq(subtask.getProvincecode())
                    , ScenseDao.Properties.Citycode.eq(subtask.getCitycode())
                    , ScenseDao.Properties.Districtcode.eq(subtask.getDistrictcode())
                    , ScenseDao.Properties.Towncode.eq(subtask.getTowncode())
                    , ScenseDao.Properties.Typeid.eq(Domain.SCENSETYPE_UNFIXED_SCENSE)).unique();
        }
        subtask.setScenseid(scense.getGuid());
        subtask.setScensename(scense.getName());
        subtask.setDeploytime(now.getTime());
        subtask.setPlanstarttime(now.getTime());
        now.set(Calendar.HOUR_OF_DAY, 23);
        now.set(Calendar.MINUTE, 59);
        now.set(Calendar.SECOND, 59);
        subtask.setPlanendtime(now.getTime());
        Userinfo currentUser = application.getCurrentUser();
        subtask.setDeployerguid(currentUser.getGuid());
        subtask.setDeployerrealname(currentUser.getRealname());
        subtask.setDeployerusername(currentUser.getAcountname());
        subtask.setExecutorguids(currentUser.getGuid());
        subtask.setExecutorrealtimes(currentUser.getRealname());
        subtask.setExecutorusernames(currentUser.getAcountname());
        subtask.setStatus(Domain.TASK_STATUS_WAITING);
        String template = "%s%s的%s无固定场景巡查";
        String area;
        if (subtask.getTownname() == null) {
            area = subtask.getCityname() + subtask.getDistrictname();
        } else {
            area = subtask.getCityname() + subtask.getDistrictname() + subtask.getTownname();
        }
        subtask.setName(String.format(Locale.CHINA, template
                , DateFormatter.dateTimeFormat_month_2_minute.format(subtask.getPlanstarttime())
                , subtask.getExecutorrealtimes(), area));
        Call<ResponseBody> call = subtaskService.putSubTask(subtask);
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
                if (response.body() != null) {
                    Toast.makeText(getActivity(), "子任务创建成功。", Toast.LENGTH_SHORT).show();
                    showTurnToInspectionDialog(subtask);
                } else if (response.errorBody() != null) {
                    Toast.makeText(getActivity(), "子任务创建失败。", Toast.LENGTH_SHORT).show();
                }
            }
 
            @Override
            public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
                Toast.makeText(getActivity(), "接口调用失败。", Toast.LENGTH_SHORT).show();
            }
        });
    }
 
    private void showTurnToInspectionDialog(final Subtask subtask) {
        new AlertDialog.Builder(getActivity()).setTitle("提示")
                .setMessage("子任务创建成功,前往执行?")
                .setNegativeButton(R.string.cancel, null)
                .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                        if (subtask != null) {
                            Intent intent = new Intent("cn.flightfeather.thirdapp.broadcasereceiver.MainReceiver");
                            try {
                                intent.putExtra("subtask", subtask);
//                        Log.e("数据!!", intent.getStringExtra("subtask"));
                                intent.setAction(Constant.GOTOSUBTASK);
//                        getActivity().switchSelectedFragment(ll_inspection);
                                getActivity().sendBroadcast(intent);
                            } catch (NullPointerException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }).show();
    }
 
    private TaskVo createDayTask(TaskVo topClassTask) {
        TaskVo dayTask = topClassTask.clone();
        dayTask.setTguid(UUIDGenerator.generate16ShortUUID());
        dayTask.setTsguid(topClassTask.getTguid());
        dayTask.setDeadlinetype(null);
        dayTask.setExtension1(null);
        dayTask.setLevelnum(null);
        Calendar cal = Calendar.getInstance();
        dayTask.setSettime(cal.getTime());
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        dayTask.setStarttime(cal.getTime());
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        dayTask.setEndtime(cal.getTime());
        dayTask.setPlannerguid(application.getCurrentUser().getGuid());
        dayTask.setPlannerusername(application.getCurrentUser().getAcountname());
        dayTask.setPlannerrealname(application.getCurrentUser().getRealname());
        dayTask.setT1stverifierguid(application.getCurrentUser().getGuid());
        dayTask.setT1stverifierusername(application.getCurrentUser().getAcountname());
        dayTask.setT1stverifierrealname(application.getCurrentUser().getRealname());
        String template = "%d月%d日%s无固定场景巡查任务";
        cal.setTime(dayTask.getStarttime());
        String area = dayTask.getCityname()+dayTask.getDistrictname();
        dayTask.setName(String.format(Locale.CHINA, template, cal.get(Calendar.MONTH)+1,
                cal.get(Calendar.DAY_OF_MONTH), area));
        return dayTask;
    }
 
    private void callPutDayTask(final TaskVo topClassTask, final SubTaskService subtaskService,
                                final Subtask subtask, final TaskVo currentDayTask, final Calendar now) {
        Call<ResponseBody> call = mRetrofit.create(TaskService.class).putTask(currentDayTask.taskVo2Task());
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
                if (response.body() != null) {
                    Toast.makeText(getActivity(), "日任务创建成功。", Toast.LENGTH_SHORT).show();
                    callPutSubtask(topClassTask, subtaskService, subtask, currentDayTask, now);
                } else if (response.errorBody() != null) {
                    Toast.makeText(getActivity(), "日任务创建失败。", Toast.LENGTH_SHORT).show();
                }
            }
 
            @Override
            public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
                Toast.makeText(getActivity(), "日任务创建失败。", Toast.LENGTH_SHORT).show();
            }
        });
    }
 
    @Override
    public void onItemClick(View view, int position) {
 
    }
 
    @Override
    public void onItemLongClick(View view, int position) {
 
    }
}