aijinhui
2023-10-30 aeee74f4d8bcd7d0de8b76aff3c044b0baeaf6df
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
package com.ruoyi.app.task.controller;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.app.task.domain.*;
import com.ruoyi.common.core.domain.DeptUserTree;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.app.task.service.IArdAppTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
 
/**
 * app任务管理Controller
 *
 * @author ard
 * @date 2023-07-22
 */
@Api(tags = "app任务管理")
@RestController
@RequestMapping("/app/task")
public class ArdAppTaskController extends BaseController {
    @Autowired
    private IArdAppTaskService ardAppTaskService;
    @Autowired
    private ISysUserService sysUserService;
 
    @Autowired
    private ISysDeptService sysDeptService;
 
 
    /**
     * 查询app任务管理列表
     */
    @ApiOperation("指挥端-历史任务查询")
    @PreAuthorize("@ss.hasPermi('app:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArdAppTask ardAppTask) {
        startPage();
        List<ArdAppTask> list = ardAppTaskService.selectArdAppTaskList(ardAppTask);
        return getDataTable(list);
    }
 
    @ApiOperation("单兵端 - 下发给我的任务列表")
    @PreAuthorize("@ss.hasPermi('app:task:list')")
    @GetMapping("/listWithDetail")
    public TableDataInfo userlist(ArdAppTask ardAppTask) {
        startPage();
        List<ArdAppTask> list = ardAppTaskService.selectArdAppTaskListWithDetail(ardAppTask);
        return getDataTable(list);
    }
 
    @ApiOperation("单兵端 - 下发给我的任务详情")
    @PreAuthorize("@ss.hasPermi('app:task:list')")
    @GetMapping("/userDetailById")
    public AjaxResult userDetail(ArdAppTask ardAppTask) {
        List<ArdAppTask> ardAppTasks = ardAppTaskService.selectArdAppTaskListWithDetailById(ardAppTask);
        return AjaxResult.success(ardAppTasks);
    }
 
    /**
     * 导出app任务管理列表
     */
    @PreAuthorize("@ss.hasPermi('app:task:export')")
    @Log(title = "app任务管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArdAppTask ardAppTask) {
        List<ArdAppTask> list = ardAppTaskService.selectArdAppTaskList(ardAppTask);
        ExcelUtil<ArdAppTask> util = new ExcelUtil<ArdAppTask>(ArdAppTask.class);
        util.exportExcel(response, list, "app任务管理数据");
    }
 
    /**
     * 获取app任务管理详细信息
     */
    @ApiOperation("指挥端-获取app任务管理详细信息")
    @PreAuthorize("@ss.hasPermi('app:task:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(ardAppTaskService.selectArdAppTaskById(id));
    }
 
    /**
     * 新增app任务管理
     */
    @ApiOperation("指挥端-下发任务")
    @PreAuthorize("@ss.hasPermi('app:task:add')")
    @Log(title = "app任务管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArdAppTask ardAppTask) {
        return toAjax(ardAppTaskService.insertArdAppTask(ardAppTask));
    }
 
    /**
     * 修改app任务管理
     */
    @PreAuthorize("@ss.hasPermi('app:task:edit')")
    @Log(title = "app任务管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArdAppTask ardAppTask) {
        return toAjax(ardAppTaskService.updateArdAppTask(ardAppTask));
    }
 
    /**
     * 删除app任务管理
     */
    @PreAuthorize("@ss.hasPermi('app:task:remove')")
    @Log(title = "app任务管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(ardAppTaskService.deleteArdAppTaskByIds(ids));
    }
 
    /**
     * 更新app任务详情
     */
    @ApiOperation("单兵端-任务打卡")
    @PreAuthorize("@ss.hasPermi('app:taskdetail:edit')")
    @Log(title = "更新app任务详情", businessType = BusinessType.UPDATE)
    @PutMapping("/detail")
    public AjaxResult editDetail(@RequestBody ArdAppTaskDetail ardAppTaskDetail) {
        return toAjax(ardAppTaskService.updateArdAppTaskDetail(ardAppTaskDetail));
    }
 
    @ApiOperation("单兵端-任务查看")
    @PreAuthorize("@ss.hasPermi('app:taskdetail:edit')")
    @Log(title = "单兵端-任务查看", businessType = BusinessType.UPDATE)
    @PutMapping("/detail/view")
    public AjaxResult editDetailView(@RequestBody ArdAppTaskDetail ardAppTaskDetail) {
        return toAjax(ardAppTaskService.updateArdAppTaskDetailView(ardAppTaskDetail));
    }
 
    /**
     * 获取app任务详情的详细信息
     */
    @ApiOperation("单兵端-任务点详情")
    @PreAuthorize("@ss.hasPermi('app:task:query')")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult getTaskDetailInfo(@PathVariable("id") String id) {
        return success(ardAppTaskService.selectArdAppTaskDetailById(id));
    }
 
    @ApiOperation("单兵端-新任务轮询")
    @PostMapping(value = "/newTaskPolling")
    public AjaxResult newTaskPolling(@RequestBody AppParam param) {
        Map<String, Object> map = new HashMap<>();
        String userId = param.getUserId();
        if (StringUtils.isNotNull(param.getUserId())) {
            ArdAppTask ardAppTask = ardAppTaskService.selectNewArdAppTaskByUserId(userId);
            map.put("task", ardAppTask);
            int count = ardAppTaskService.selectUnreadArdAppTaskCount(userId);
            map.put("count", count);
        }
 
        return success(map);
    }
 
    @ApiOperation("指挥端-模糊分页查询所有兴趣点")
    @PostMapping(value = "/likeWell")
    public AjaxResult likeWell(@RequestBody WellParam wellParam) {
        return success(ardAppTaskService.likeWell(wellParam));
    }
 
    @ApiOperation("指挥端-查询树形组织架构")
    @PostMapping(value = "/treeDept")
    public AjaxResult treeDept() {
        //查询用户ID
        String usersId = SecurityUtils.getUserId();
        //根据userId查询部门Id
        SysUser sysUser = sysUserService.selectUserById(usersId);
        //根据当前deptId或者当前及所属下级的所有deptId
        List<Long> deptList = sysDeptService.deptIdBySub(sysUser.getDeptId());
        //查询所有部门信息
        List<SysDept> sysDeptList = sysDeptService.allByUser(deptList);
        List<DeptUserTree> deptUserTrees = new ArrayList<>();
        for (int i = 0; i < sysDeptList.size(); i++) {
            SysDept sysDept = sysDeptList.get(i);
            DeptUserTree deptUserTree = new DeptUserTree();
            deptUserTree.setAncestors(sysDept.getAncestors());
            deptUserTree.setDeptId(sysDept.getDeptId());
            deptUserTree.setDeptName(sysDept.getDeptName());
            deptUserTree.setParentId(sysDept.getParentId());
            deptUserTrees.add(deptUserTree);
            QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("dept_id",sysDept.getDeptId());
            List<SysUser> users = sysUserService.userByDept(sysDept.getDeptId());
            for (int j = 0; j < users.size(); j++) {
                SysUser user = users.get(j);
                DeptUserTree deptUserTree1 = new DeptUserTree();
                deptUserTree1.setDeptId(user.getDeptId());
                deptUserTree1.setUserId(user.getUserId());
                deptUserTree1.setNickName(user.getNickName());
                deptUserTree1.setParentId(user.getDeptId());
                deptUserTrees.add(deptUserTree1);
            }
        }
        return success(sysDeptService.deptUserTree(deptUserTrees));
    }
 
}