/*
|
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
*
|
* Redistribution and use in source and binary forms, with or without
|
* modification, are permitted provided that the following conditions are met:
|
*
|
* Redistributions of source code must retain the above copyright notice,
|
* this list of conditions and the following disclaimer.
|
* Redistributions in binary form must reproduce the above copyright
|
* notice, this list of conditions and the following disclaimer in the
|
* documentation and/or other materials provided with the distribution.
|
* Neither the name of the dreamlu.net developer nor the names of its
|
* contributors may be used to endorse or promote products derived from
|
* this software without specific prior written permission.
|
* Author: Chill 庄骞 (smallchill@163.com)
|
*/
|
package org.springblade.modules.taskqd.controller;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiParam;
|
import lombok.AllArgsConstructor;
|
import me.zhyd.oauth.log.Log;
|
import org.joda.time.DateTime;
|
import org.springblade.core.boot.ctrl.BladeController;
|
import org.springblade.core.mp.support.Condition;
|
import org.springblade.core.mp.support.Query;
|
import org.springblade.core.tool.api.R;
|
import org.springblade.core.tool.utils.Func;
|
import org.springblade.core.tool.utils.StringUtil;
|
import org.springblade.modules.task.entity.Task;
|
import org.springblade.modules.task.service.ITaskService;
|
import org.springblade.modules.task.vo.TaskVO;
|
import org.springblade.modules.task.wrapper.TaskWrapper;
|
import org.springblade.modules.taskqd.entity.Taskqd;
|
import org.springblade.modules.taskqd.service.impl.TaskqdServiceImpl;
|
import org.springblade.modules.taskqd.vo.TaskqdVO;
|
import org.springblade.modules.taskqd.wrapper.TaskqdWrapper;
|
import org.springblade.modules.webscoket.service.IPushMsgService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletResponse;
|
import javax.validation.Valid;
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
|
/**
|
* 控制器
|
*
|
* @author BladeX
|
* @since 2020-08-06
|
*/
|
@RestController
|
@AllArgsConstructor
|
@RequestMapping("/taskqd")
|
@Api(value = "", tags = "接口")
|
public class TaskqdController extends BladeController {
|
|
private final TaskqdServiceImpl taskqdService;
|
|
@Autowired
|
private IPushMsgService pushMsgService;
|
|
/**
|
* 详情
|
*/
|
@GetMapping("/detail")
|
@ApiOperationSupport(order = 1)
|
@ApiOperation(value = "详情", notes = "传入task")
|
public R<TaskqdVO> detail(Taskqd taskqd) {
|
Taskqd detail = taskqdService.getOne(Condition.getQueryWrapper(taskqd));
|
return R.data(TaskqdWrapper.build().entityVO(detail));
|
}
|
|
/**
|
* 分页
|
*/
|
@GetMapping("/list")
|
@ApiOperationSupport(order = 2)
|
@ApiOperation(value = "分页", notes = "传入task")
|
public R<IPage<TaskqdVO>> list(Taskqd taskqd, Query query) {
|
IPage<Taskqd> pages = taskqdService.page(Condition.getPage(query), Condition.getQueryWrapper(taskqd).orderByDesc("time"));
|
return R.data(TaskqdWrapper.build().pageVO(pages));
|
}
|
|
|
/**
|
* 新增
|
*/
|
@PostMapping("/save")
|
@ApiOperationSupport(order = 4)
|
@ApiOperation(value = "新增", notes = "传入task")
|
public R save(@Valid @RequestBody Taskqd taskqd) {
|
pushMsgService.pushMsg(taskqd.getJurisdiction());
|
return R.status(taskqdService.save(taskqd));
|
}
|
|
/**
|
* 修改
|
*/
|
@PostMapping("/update")
|
@ApiOperationSupport(order = 5)
|
@ApiOperation(value = "修改", notes = "传入task")
|
public R update(@Valid @RequestBody Taskqd taskqd) {
|
|
if (taskqd.getStime() == null || taskqd.getStime().equals("")){
|
taskqd.setStime(null);
|
}
|
if (taskqd.getSendtime() == null || taskqd.getSendtime().equals("")){
|
taskqd.setSendtime(null);
|
}
|
|
return R.status(taskqdService.updateById(taskqd));
|
}
|
|
/**
|
* 新增或修改
|
*/
|
@PostMapping("/submit")
|
@ApiOperationSupport(order = 6)
|
@ApiOperation(value = "新增或修改", notes = "传入task")
|
public R submit(@Valid @RequestBody Taskqd taskqd) {
|
return R.status(taskqdService.saveOrUpdate(taskqd));
|
}
|
|
|
/**
|
* 删除
|
*/
|
@PostMapping("/remove")
|
@ApiOperationSupport(order = 8)
|
@ApiOperation(value = "删除", notes = "传入ids")
|
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
return R.status(taskqdService.removeByIds(Func.toLongList(ids)));
|
}
|
|
/**
|
* 分页
|
*/
|
@GetMapping("/queryReceiver")
|
@ApiOperation(value = "分页", notes = "传入task")
|
public R queryReceiver(Taskqd taskqd, Query query) {
|
String sreid = taskqd.getSerid();
|
if (sreid.charAt(sreid.length() - 1) == ',') { //s.length()-1获取字符串最后一位字符的索引,传入charAt方法获取索引对应的字符,判断是否为逗号
|
sreid = sreid.substring(0, sreid.length() - 1);
|
}
|
return R.data(taskqdService.queryReceiver(sreid));
|
}
|
|
|
/**
|
* 抢单
|
*/
|
@PostMapping("/Graborder")
|
public R Graborder(@Valid @RequestBody Taskqd taskqd) {
|
|
//要接的任务
|
List<Taskqd> list = taskqdService.selectList(taskqd.getId());
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
//转换
|
try {
|
|
//获取要接任务的时间戳
|
Date timea = sdf.parse(list.get(0).getTime());
|
Date timejs = sdf.parse(list.get(0).getEndtime());
|
System.out.println("开始时间——————"+timea.getTime());
|
Long start = timea.getTime() ;
|
Long start2 = timejs.getTime() ;
|
System.out.println("开始时间——————"+start);
|
System.out.println("开始时间——————"+sdf.format(start));
|
|
//判断是否有同时间段的任务
|
//已接的任务
|
List<TaskqdVO> yjlist = taskqdService.getlist(taskqd.getSerid().toString(), "2");
|
for (int i = 0; i < yjlist.size(); i++) {
|
//获取已接任务开始时间的时间戳
|
Date times = sdf.parse(yjlist.get(i).getTime());
|
|
if (times.getTime() >= start2){
|
//已接任务提前两个小时
|
Long ends = times.getTime() - 2 * 60 * 60 * 1000;
|
System.out.println("结束时间——————"+sdf.format(ends));
|
if (ends < start2) {
|
return R.fail("已有正在进行的同时段任务");
|
}
|
}else{
|
//获取已接任务的结束时间戳
|
Date timeb = sdf.parse(yjlist.get(i).getEndtime());
|
//已接任务后两个小时
|
Long end = timeb.getTime()+ 2 * 60 * 60 * 1000;
|
System.out.println("结束时间——————"+sdf.format(end));
|
if (end > start) {
|
return R.fail("已有正在进行的同时段任务");
|
}
|
}
|
}
|
|
} catch (ParseException e) {
|
e.printStackTrace();
|
}
|
|
//总数
|
Integer jnum = list.get(0).getJnum();
|
//人数
|
Integer num = list.get(0).getNum();
|
boolean empty = StringUtil.isEmpty(list.get(0).getSerid());
|
if (num == jnum) {
|
return R.success("抢单失败");
|
} else {
|
if (num == jnum - 1) {
|
int i = num + 1;
|
String serid = taskqd.getSerid();
|
if (empty == true) {
|
//String serid2 = list.get(0).getSerid();
|
//String substring = serid2.substring(0, serid.length() - 1);
|
//String s = serid + substring;
|
System.out.println("用户id:" + serid);
|
taskqdService.updatet(taskqd.getId(), i, serid, null, null);
|
return R.success("抢单成功");
|
} else {
|
String ser = taskqd.getSerid();
|
String ser2 = list.get(0).getSerid();
|
//String sub = ser.substring(0, serid.length() - 1);
|
String ss = ser2 + ser;
|
|
String team = taskqd.getCaptain();
|
boolean isteam = StringUtil.isEmpty(list.get(0).getTeam());
|
String team2 = list.get(0).getTeam();
|
String teamz = "";
|
if (isteam) {
|
teamz = team;
|
} else {
|
teamz = team2 + "," + team;
|
}
|
|
taskqdService.updatet(taskqd.getId(), i, ss, null, teamz);
|
return R.success("抢单成功");
|
}
|
|
} else {
|
int i = num + 1;
|
String serid = taskqd.getSerid();
|
if (empty == true) {
|
String captain = taskqd.getCaptain();
|
taskqdService.updatet(taskqd.getId(), i, serid, captain, null);
|
return R.success("抢单成功");
|
} else {
|
String serid1 = list.get(0).getSerid();
|
String s = serid1 + serid;
|
|
String team = taskqd.getCaptain();
|
boolean isteam = StringUtil.isEmpty(list.get(0).getTeam());
|
String team2 = list.get(0).getTeam();
|
String teamz = "";
|
if (isteam) {
|
teamz = team;
|
} else {
|
teamz = team2 + "," + team;
|
}
|
|
|
taskqdService.updatet(taskqd.getId(), i, s, null, teamz);
|
return R.success("抢单成功");
|
}
|
}
|
}
|
|
}
|
|
|
/**
|
* 查询任务
|
*
|
* @param type
|
* @param serid
|
* @return
|
*/
|
@PostMapping("/selectLi")
|
public R selectLi(String type, String serid, String jurisdiction, String workjurisdiction, String tasktype) {
|
List<TaskqdVO> list = taskqdService.selectLi(type, serid, jurisdiction, workjurisdiction, tasktype);
|
for (int i = 0; i < list.size(); i++) {
|
Integer nums = list.get(i).getNums();
|
|
boolean isteam = StringUtil.isEmpty(list.get(i).getSerid());
|
if (isteam) {
|
list.get(i).setIscation("0");
|
} else {
|
if (list.get(i).getSerid().split(",")[0].equals(serid)) {
|
list.get(i).setIscation("1");
|
} else {
|
list.get(i).setIscation("0");
|
}
|
}
|
|
if (nums == 0) {
|
list.get(i).setType("0");
|
} else {
|
list.get(i).setType("1");
|
}
|
}
|
return R.data(list);
|
}
|
|
/**
|
* 查询可参与任务
|
*
|
* @param serid
|
* @param jurisdiction
|
* @return
|
*/
|
@GetMapping("/selectNum")
|
public R selectNum(String serid, String jurisdiction, String workjurisdiction) {
|
List<Map<String, Object>> maps = taskqdService.selectNum(serid, jurisdiction, workjurisdiction);
|
//0:治安巡查
|
Map map = new HashMap();
|
int a = 0;
|
int b = 0;
|
int c = 0;
|
for (int i = 0; i < maps.size(); i++) {
|
String tasktype = maps.get(i).get("tasktype").toString();
|
if (tasktype.equals("0")) {
|
map.put("xcha", maps.get(i).get("num"));
|
a = 1;
|
} else if (tasktype.equals("1")) {
|
map.put("xchuan", maps.get(i).get("num"));
|
b = 1;
|
} else if (tasktype.equals("2")) {
|
map.put("px", maps.get(i).get("num"));
|
c = 1;
|
}
|
}
|
if (a == 0) {
|
map.put("xcha", 0);
|
}
|
if (b == 0) {
|
map.put("xchuan", 0);
|
}
|
if (c == 0) {
|
map.put("px", 0);
|
}
|
return R.data(map);
|
}
|
|
@GetMapping("/startTask")
|
public R<Map> startTask(String rid, String serid, String type, String data) {
|
//获取组员id并进行通知
|
Map<String, Object> map = new HashMap<>();
|
|
serid = taskqdService.querySerid(rid);
|
|
int msg = pushMsgService.startTask(serid, rid, type, data);
|
map.put("res", msg);
|
map.put("type", type);
|
map.put("data", data);
|
if (!type.equals("stop")) {
|
taskqdService.updateRtype("0", rid);
|
}
|
return R.data(map);
|
}
|
|
@GetMapping("/cancelTask")
|
public R cancelTask(String rid, String serid, String name) {
|
//任务查询
|
//String id = taskqdService.querySerid(rid);
|
List<Taskqd> list = taskqdService.selectList(Integer.valueOf(rid));
|
|
//获取参与者id
|
String id = list.get(0).getSerid();
|
|
String captain[] = id.split(",");
|
if (captain[0].equals(serid)) {
|
return R.status(taskqdService.removeByIds(Func.toLongList(rid)));
|
}
|
|
//获取参与者名称
|
String[] nameList = list.get(0).getTeam().split(",");
|
//创建新的参与者
|
String newteam = "";
|
//设置标识防止删除同名人员
|
boolean flage = true;
|
for (int i = 0; i < nameList.length; i++) {
|
if (flage) {
|
if (!name.equals(nameList[i])) {
|
newteam += nameList[i] + ",";
|
} else {
|
flage = false;
|
}
|
} else {
|
newteam += nameList[i] + ",";
|
}
|
|
}
|
//去除最后的逗号
|
if (newteam.length() != 0) {
|
newteam = newteam.substring(0, newteam.length() - 1);
|
}
|
|
//扣去人数
|
int newnum = list.get(0).getNum() - 1;
|
|
//成员id拼接逗号方便删除
|
String delid = "," + serid;
|
//将指定成员删除
|
String resid = id.replaceAll(delid, "");
|
|
return R.status(taskqdService.updateSerid(rid, resid, newteam, newnum));
|
}
|
|
@GetMapping("/taskCount")
|
public R cancelTask(String id, String type) {
|
List<Map<String, Object>> cout = taskqdService.taskCount(id, type);
|
List<TaskqdVO> list = taskqdService.getlist(id, type);
|
Map<String, Object> res = new HashMap<>();
|
res.put("ywc", cout.get(0).get("count"));
|
res.put("wwc", cout.get(1).get("count"));
|
res.put("data", list);
|
return R.data(res);
|
}
|
|
/**
|
* 查询所有任务轨迹以及人员轨迹
|
* @return
|
*/
|
@GetMapping("/queryAllTrar")
|
public R queryAllTrar() {
|
List<Map<String, Object>> allTask = taskqdService.allTask();
|
|
|
return R.data(allTask);
|
}
|
|
/**
|
* @param nowTime 当前时间
|
* @param startTime 开始时间
|
* @param endTime 结束时间
|
* @return
|
* @author sunran 判断当前时间在时间区间内
|
*/
|
public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) {
|
if (nowTime.getTime() == startTime.getTime()
|
|| nowTime.getTime() == endTime.getTime()) {
|
return true;
|
}
|
|
Calendar date = Calendar.getInstance();
|
date.setTime(nowTime);
|
|
Calendar begin = Calendar.getInstance();
|
begin.setTime(startTime);
|
|
Calendar end = Calendar.getInstance();
|
end.setTime(endTime);
|
|
if (date.after(begin) && date.before(end)) {
|
return true;
|
} else {
|
return false;
|
}
|
}
|
|
/**
|
* 根据派出所展示发布数量前十五,根据日周月切换
|
* @param jurisdiction 派出所编号
|
* @param startTime 发布时间
|
* @param period 日(day) 月(week) 年(year)
|
* @return
|
*/
|
@GetMapping("/countTaskByJur")
|
@ApiOperation(value = "统计")
|
public R countTaskByJur(String jurisdiction, String startTime,String period ){
|
List<Taskqd> list = taskqdService.countTaskByJur(jurisdiction,startTime,period);
|
return R.data(list);
|
}
|
}
|