package com.highdatas.srs.web;
|
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
import com.highdatas.srs.entity.*;
|
import com.highdatas.srs.mapper.SysRoleMapper;
|
import com.highdatas.srs.pojo.CodeMsg;
|
import com.highdatas.srs.pojo.Result;
|
import com.highdatas.srs.pojo.SchemeDetailCountEntity;
|
import com.highdatas.srs.service.*;
|
import com.highdatas.srs.util.Constant;
|
import com.highdatas.srs.util.DbUtils;
|
import com.highdatas.srs.util.FileUtils;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.math.BigDecimal;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* <p>
|
* 前端控制器
|
* </p>
|
*
|
* @author kimi
|
* @since 2020-01-15
|
*/
|
@RestController
|
@Slf4j
|
@RequestMapping("/detail")
|
public class SchemeDetailController {
|
@Autowired
|
ISchemeDetailService schemeDetailService;
|
@Autowired
|
ISchemeService schemeService;
|
@Autowired
|
ISysRoleService roleService;
|
@Autowired
|
ISysRoleMappingService roleMappingService;
|
@Autowired
|
ISysUserService userService;
|
@Autowired
|
IPartimepayService partimepayService;
|
@Autowired
|
ISchemeDetailParttimeService detailParttimeService;
|
@Autowired
|
IModuleService moduleService;
|
@Value("{base.file.path}")
|
String basePath;
|
@Autowired
|
SysRoleMapper mapper;
|
|
|
@RequestMapping(value = "dayTask", method = RequestMethod.GET)
|
public Result dayByUser(HttpServletRequest request) {
|
String userId = request.getParameter("userId");
|
Date now = new Date();
|
|
EntityWrapper<SchemeDetail> schemeDetailEntityWrapper = new EntityWrapper<>();
|
schemeDetailEntityWrapper.le("start_time", now);
|
schemeDetailEntityWrapper.gt("end_time", now);
|
if (!StringUtils.isEmpty(userId)) {
|
schemeDetailEntityWrapper.eq("user_id", userId);
|
}
|
List<SchemeDetail> schemeDetailList = schemeDetailService.selectList(schemeDetailEntityWrapper);
|
JSONArray result = new JSONArray();
|
Collection<String> values = Constant.schemeDetailParentTypes.values();
|
Set<String> types = new LinkedHashSet(values);
|
long totalCnt = 0;
|
long delayCnt = 0;
|
for (String type : types) {
|
long total = schemeDetailList.stream().filter(schemeDetail -> schemeDetail.getType() != null).filter(schemeDetail -> type.equalsIgnoreCase(schemeDetail.getType().getParent())).count();
|
long delay = schemeDetailList.stream().filter(schemeDetail -> schemeDetail.getType() != null).filter(schemeDetail -> type.equalsIgnoreCase(schemeDetail.getType().getParent()))
|
.filter(schemeDetail -> schemeDetail.getDelay()).count();
|
totalCnt += total;
|
delayCnt += delay;
|
JSONObject object = new JSONObject();
|
object.fluentPut("type", type);
|
object.fluentPut("total", total);
|
object.fluentPut("delay", delay);
|
|
result.add(object);
|
}
|
JSONObject object = new JSONObject();
|
object.fluentPut("type", "我的任务");
|
object.fluentPut("total", totalCnt);
|
object.fluentPut("delay", delayCnt);
|
JSONArray endResult = new JSONArray();
|
|
endResult.add(object);
|
endResult.addAll(result);
|
|
return Result.success(endResult);
|
}
|
|
@RequestMapping(value = "/dealParttime/{id}", method = RequestMethod.GET)
|
public Result deal(@PathVariable String id, @RequestParam int month,@RequestParam int year, @RequestParam BigDecimal money ) {
|
partimepayService.delete(new EntityWrapper<Partimepay>().eq("month", month).eq("year", year).eq("parttime_id", id));
|
new Partimepay().setId(DbUtils.getUUID()).setYear(year).setMonth(month).setParttimeId(id).setMoney(money).insert();
|
return Result.success(null);
|
}
|
|
@RequestMapping(value = "/deal/{id}", method = RequestMethod.GET)
|
public Result deal(@PathVariable String id, HttpServletRequest request) {
|
String desp = request.getParameter("desp");
|
SchemeDetail schemeDetail = schemeDetailService.selectById(id);
|
schemeDetail.setFinish(true);
|
schemeDetail.setFinishTime(new Date());
|
new ProjectDeal().setId(DbUtils.getUUID()).setDesp(desp).setSchemeDetailId(id).setCreateTime(new Date()).insert();
|
schemeDetail.updateById();
|
Wrapper<SchemeDetail> eq = new EntityWrapper<SchemeDetail>().eq("parent_id", schemeDetail.getParentId()).eq("finish", false);
|
int i = schemeDetailService.selectCount(eq);
|
if (i == 0) {
|
Scheme scheme = schemeService.selectById(schemeDetail.getParentId());
|
scheme.setStatus("finish");
|
scheme.updateById();
|
}
|
return Result.success(schemeDetail);
|
}
|
@RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
|
public Result get(@PathVariable String id) {
|
SchemeDetail schemeDetail = schemeDetailService.selectById(id);
|
String userId = schemeDetail.getUserId();
|
SysRoleMapping mapping = roleMappingService.selectOne(new EntityWrapper<SysRoleMapping>().eq("user_id", userId));
|
if (mapping != null) {
|
String roleId = mapping.getRoleId();
|
SysRole sysRole = roleService.selectById(roleId);
|
if (sysRole != null) {
|
schemeDetail.setRoleName(sysRole.getName());
|
}
|
List<SchemeDetailParttime> parent_id = detailParttimeService.selectList(new EntityWrapper<SchemeDetailParttime>().eq("parent_id", schemeDetail.getId()));
|
schemeDetail.setParttimeList(parent_id);
|
}
|
|
String dataInfoTable = schemeDetail.getDataInfoTable();
|
|
if (!StringUtils.isEmpty(dataInfoTable)) {
|
Map<String, Object> stringObjectMap = mapper.selectTableById(dataInfoTable, schemeDetail.getDetailInfoId());
|
Set<String> keySet = stringObjectMap.keySet();
|
JSONObject object = new JSONObject();
|
for (String s : keySet) {
|
String key = DbUtils.lineToHump(s);
|
Object val = stringObjectMap.get(s);
|
object.fluentPut(key,val);
|
}
|
|
schemeDetail.setExistsObject(object);
|
}
|
return Result.success(schemeDetail);
|
}
|
|
|
|
@RequestMapping(value = "/getByParttime", method = RequestMethod.GET)
|
public Result getByParttime(@RequestParam int year, @RequestParam int month) {
|
Calendar calendar = Calendar.getInstance();
|
calendar.set(year,month - 1,00);
|
Date startTime = calendar.getTime();
|
calendar.set(year,month,00);
|
calendar.add(Calendar.DAY_OF_YEAR, -1);
|
Date endTime = calendar.getTime();
|
List<Scheme> schemes = schemeService.selectList(new EntityWrapper<Scheme>().ne("status", "edit"));
|
|
Map<String, Map<String,Double>> resultMap = new HashMap<>();
|
|
for (Scheme scheme : schemes) {
|
List<SchemeDetail> schemeDetailList = schemeDetailService.selectList(new EntityWrapper<SchemeDetail>().eq("parent_id", scheme.getId()).ge("start_time", startTime).le("end_time", endTime));
|
for (SchemeDetail detail : schemeDetailList) {
|
Boolean finish = detail.getFinish();
|
BigDecimal budget = detail.getBudget();
|
List<SchemeDetailParttime> parent_id = detailParttimeService.selectList(new EntityWrapper<SchemeDetailParttime>().eq("parent_id", detail.getId()));
|
if (parent_id == null || parent_id.isEmpty()) {
|
continue;
|
}
|
|
|
for (SchemeDetailParttime parttime : parent_id) {
|
String parttimeUser = parttime.getParttimeUser();
|
Map<String,Double> oneResult = resultMap.get(parttimeUser);
|
if (oneResult == null) {
|
oneResult = new HashMap<>();
|
oneResult.put("payMoney", parttime.getParttimePay().doubleValue());
|
}
|
|
if (finish) {
|
double finishCnt = oneResult.get("finishCnt") == null ? 0 : oneResult.get("finishCnt");
|
double finishMoney = oneResult.get("finishMoney") == null ? 0 : oneResult.get("finishMoney");
|
finishCnt++;
|
oneResult.put("finishCnt", finishCnt);
|
oneResult.put("finishMoney", finishMoney + budget.doubleValue());
|
} else {
|
double unFinishCnt = oneResult.get("unFinishCnt") == null ? 0 : oneResult.get("unFinishCnt");
|
double unFinishMoney = oneResult.get("unFinishMoney") == null ? 0 : oneResult.get("unFinishMoney");
|
unFinishCnt++;
|
oneResult.put("unFinishCnt", unFinishCnt);
|
oneResult.put("unFinishMoney", unFinishMoney + budget.doubleValue());
|
}
|
resultMap.put(parttimeUser, oneResult);
|
}
|
}
|
}
|
Set<String> keySet = resultMap.keySet();
|
List<Map<String,Object>> result = new ArrayList<>();
|
for (String userId : keySet) {
|
SysUser sysUser = userService.selectById(userId);
|
if (sysUser == null) {
|
continue;
|
}
|
Map<String,Double> doubles = resultMap.get(userId);
|
HashMap<String, Object> stringObjectHashMap = new HashMap<>(doubles);
|
stringObjectHashMap.put("userId", sysUser.getId());
|
stringObjectHashMap.put("userName", sysUser.getName());
|
|
Partimepay partimepay = partimepayService.selectOne(new EntityWrapper<Partimepay>().eq("year", year).eq("month", month).eq("parttime_id", userId));
|
if (partimepay != null) {
|
stringObjectHashMap.put("money", partimepay.getMoney());
|
}
|
|
result.add(stringObjectHashMap);
|
}
|
return Result.success(result);
|
}
|
|
@RequestMapping(value = "/getMoneyByPersion", method = RequestMethod.GET)
|
public Result getMoneyByPersion(@RequestParam String userId, @RequestParam Boolean isParttime) {
|
List<Scheme> schemes = schemeService.selectList(new EntityWrapper<Scheme>().ne("status", "edit"));
|
|
List<Map<String,Object>> resultMap = new ArrayList<>();
|
List<Map<String,Object>> parentMap = new ArrayList<>();
|
|
for (Scheme scheme : schemes) {
|
double schemeBudget = 0;
|
List<SchemeDetail> collect;
|
if (isParttime) {
|
List<String> detailIdList = schemeDetailService.selectList(new EntityWrapper<SchemeDetail>().eq("parent_id", scheme.getId())).stream().map(SchemeDetail::getId).collect(Collectors.toList());
|
if (detailIdList.isEmpty()) {
|
collect = new ArrayList<>();
|
} else {
|
List<SchemeDetailParttime> parttime_user = detailParttimeService.selectList(new EntityWrapper<SchemeDetailParttime>().eq("parttime_user", userId).in("parent_id", detailIdList));
|
List<String> detailList = parttime_user.stream().map(SchemeDetailParttime::getParentId).collect(Collectors.toList());
|
if (detailList == null || detailList.isEmpty()) {
|
collect = new ArrayList<>();
|
|
} else {
|
collect = schemeDetailService.selectBatchIds(detailList);
|
}
|
}
|
|
} else {
|
collect = schemeDetailService.selectList(new EntityWrapper<SchemeDetail>().eq("parent_id", scheme.getId()).eq("user_id", userId));
|
}
|
|
for (SchemeDetail detail : collect) {
|
Boolean finish = detail.getFinish();
|
BigDecimal budget = detail.getBudget();
|
String detailUserId = detail.getUserId();
|
List<SchemeDetailParttime> parttimeList = detailParttimeService.selectList(new EntityWrapper<SchemeDetailParttime>().eq("parent_id", detail.getId()));
|
List<String> parttimeIdList = parttimeList.stream().map(SchemeDetailParttime::getParttimeUser).collect(Collectors.toList());
|
if (isParttime) {
|
if (!parttimeIdList.contains(userId)) {
|
continue;
|
}
|
}else {
|
if (!detailUserId.equalsIgnoreCase(userId)) {
|
continue;
|
}
|
}
|
|
Date detailStartTime = detail.getStartTime();
|
Date detailEndTime = detail.getEndTime();
|
SchemeDetailType type = detail.getType();
|
HashMap<String, Object> stringObjectHashMap = new HashMap<>();
|
stringObjectHashMap.put("startTime", detailStartTime);
|
stringObjectHashMap.put("endTime", detailEndTime);
|
stringObjectHashMap.put("name", type.covert());
|
stringObjectHashMap.put("budget", budget.doubleValue());
|
stringObjectHashMap.put("finish", finish);
|
stringObjectHashMap.put("parentId", detail.getParentId());
|
stringObjectHashMap.put("isPro", false);
|
stringObjectHashMap.put("id", detail.getId());
|
|
schemeBudget += detail.getBudget().doubleValue();
|
resultMap.add(stringObjectHashMap);
|
|
}
|
if (!collect.isEmpty()) {
|
HashMap<String, Object> proMap = new HashMap<>();
|
proMap.put("startTime", scheme.getStartTime());
|
proMap.put("endTime", scheme.getEndTime());
|
proMap.put("name", scheme.getName());
|
proMap.put("budget", schemeBudget);
|
proMap.put("finish", false);
|
proMap.put("id", scheme.getId());
|
proMap.put("isPro", true);
|
parentMap.add(proMap);
|
}
|
|
}
|
JSONObject object = new JSONObject();
|
object.fluentPut("sub", resultMap);
|
object.fluentPut("scheme", parentMap);
|
return Result.success(object);
|
}
|
|
@RequestMapping(value = "/getPersion", method = RequestMethod.GET)
|
public Result getPersion() {
|
List<Scheme> schemes = schemeService.selectList(new EntityWrapper<Scheme>().ne("status", "edit"));
|
|
Map<String, Map<String,Double>> resultMap = new HashMap<>();
|
|
for (Scheme scheme : schemes) {
|
List<SchemeDetail> schemeDetailList = schemeDetailService.selectList(new EntityWrapper<SchemeDetail>().eq("parent_id", scheme.getId()));
|
for (SchemeDetail detail : schemeDetailList) {
|
Boolean finish = detail.getFinish();
|
BigDecimal budget = detail.getBudget();
|
String userId = detail.getUserId();
|
|
Map<String,Double> oneResult = resultMap.get(userId);
|
if (oneResult == null) {
|
oneResult = new HashMap<>();
|
}
|
if (finish) {
|
double finishCnt = oneResult.get("finishCnt") == null ? 0 : oneResult.get("finishCnt");
|
double finishMoney = oneResult.get("finishMoney") == null ? 0 : oneResult.get("finishMoney");
|
finishCnt++;
|
oneResult.put("finishCnt", finishCnt);
|
oneResult.put("finishMoney", finishMoney + budget.doubleValue());
|
} else {
|
double unFinishCnt = oneResult.get("unFinishCnt") == null ? 0 : oneResult.get("unFinishCnt");
|
double unFinishMoney = oneResult.get("unFinishMoney") == null ? 0 : oneResult.get("unFinishMoney");
|
unFinishCnt++;
|
oneResult.put("unFinishCnt", unFinishCnt);
|
oneResult.put("unFinishMoney", unFinishMoney + budget.doubleValue());
|
}
|
resultMap.put(userId, oneResult);
|
|
}
|
}
|
Set<String> keySet = resultMap.keySet();
|
List<Map<String,Object>> result = new ArrayList<>();
|
for (String userId : keySet) {
|
SysUser sysUser = userService.selectById(userId);
|
if (sysUser == null) {
|
continue;
|
}
|
Map<String,Double> doubles = resultMap.get(userId);
|
HashMap<String, Object> stringObjectHashMap = new HashMap<>(doubles);
|
stringObjectHashMap.put("userId", sysUser.getId());
|
stringObjectHashMap.put("userName", sysUser.getName());
|
|
|
result.add(stringObjectHashMap);
|
}
|
return Result.success(result);
|
}
|
|
@RequestMapping(value = "/getMonth", method = RequestMethod.GET)
|
public Result getMonth(@RequestParam Date startTime) {
|
Calendar instance = Calendar.getInstance();
|
instance.setTime(startTime);
|
instance.add(Calendar.MONTH,1);
|
Calendar start = Calendar.getInstance();
|
start.setTime(startTime);
|
Date endTime = instance.getTime();
|
List<JSONObject> result = new ArrayList<>();
|
while (startTime.before(endTime)) {
|
startTime = start.getTime();
|
EntityWrapper<SchemeDetail> schemeDetailEntityWrapper = new EntityWrapper<>();
|
schemeDetailEntityWrapper.le("start_time", startTime);
|
schemeDetailEntityWrapper.gt("end_time", startTime);
|
schemeDetailEntityWrapper.eq("finish", false);
|
schemeDetailEntityWrapper.eq("edit", false);
|
int cnt = schemeDetailService.selectCount(schemeDetailEntityWrapper);
|
if (cnt == 0) {
|
start.add(Calendar.DAY_OF_YEAR, 1);
|
continue;
|
}
|
JSONObject object = new JSONObject();
|
object.fluentPut("date", startTime);
|
object.fluentPut("task", cnt);
|
result.add(object);
|
start.add(Calendar.DAY_OF_YEAR, 1);
|
|
}
|
log.info(result.size() + "");
|
return Result.success(result);
|
}
|
|
@RequestMapping(value = "/getDay", method = RequestMethod.GET)
|
public Result getDay(@RequestParam Date startTime) {
|
EntityWrapper<SchemeDetail> schemeDetailEntityWrapper = new EntityWrapper<>();
|
schemeDetailEntityWrapper.le("start_time", startTime);
|
schemeDetailEntityWrapper.gt("end_time", startTime);
|
schemeDetailEntityWrapper.eq("finish", false);
|
schemeDetailEntityWrapper.eq("edit", false);
|
List<SchemeDetail> schemeDetails = schemeDetailService.selectList(schemeDetailEntityWrapper);
|
|
Set<Scheme> parent = new HashSet<>();
|
for (SchemeDetail schemeDetail : schemeDetails) {
|
schemeDetail.setTypeStr(schemeDetail.getType().covert());
|
String parentId = schemeDetail.getParentId();
|
Scheme scheme = schemeService.selectById(parentId);
|
parent.add(scheme);
|
}
|
JSONArray array = (JSONArray) JSON.toJSON(schemeDetails);
|
JSONArray schemeArray = (JSONArray) JSON.toJSON(parent);
|
array.addAll(schemeArray);
|
|
return Result.success(array);
|
}
|
|
@RequestMapping(value = "/parent/{id}", method = RequestMethod.GET)
|
public Result parent(@PathVariable String id) {
|
//TODO
|
List<SchemeDetail> dealList = schemeDetailService.selectList(new EntityWrapper<SchemeDetail>().eq("parent_id", id));
|
for (SchemeDetail detail : dealList) {
|
String userId = detail.getUserId();
|
SysRoleMapping mapping = roleMappingService.selectOne(new EntityWrapper<SysRoleMapping>().eq("user_id", userId));
|
if (mapping != null) {
|
String roleId = mapping.getRoleId();
|
SysRole sysRole = roleService.selectById(roleId);
|
if (sysRole == null) {
|
continue;
|
}
|
detail.setRoleName(sysRole.getName());
|
}
|
List<SchemeDetailParttime> parent_id = detailParttimeService.selectList(new EntityWrapper<SchemeDetailParttime>().eq("parent_id", detail.getId()));
|
detail.setParttimeList(parent_id);
|
|
String dataInfoTable = detail.getDataInfoTable();
|
if (!StringUtils.isEmpty(dataInfoTable)){
|
Map<String, Object> stringObjectMap = mapper.selectTableById(dataInfoTable, detail.getDetailInfoId());
|
|
Set<String> keySet = stringObjectMap.keySet();
|
JSONObject object = new JSONObject();
|
for (String s : keySet) {
|
String key = DbUtils.lineToHump(s);
|
Object val = stringObjectMap.get(s);
|
object.fluentPut(key,val);
|
}
|
detail.setExistsObject(object);
|
}
|
}
|
return Result.success(dealList);
|
}
|
|
@Transactional(rollbackFor = {RuntimeException.class, Error.class})
|
@RequestMapping(value = "/updates", method = RequestMethod.POST)
|
public Result updates(@RequestBody JSONObject reqObj) {
|
String schemeId = reqObj.getString("schemeId");
|
JSONArray datas = reqObj.getJSONArray("datas");
|
Scheme scheme = schemeService.selectById(schemeId);
|
schemeDetailService.delete(new EntityWrapper<SchemeDetail>().eq("parent_id", schemeId));
|
|
try {
|
for (Object data : datas) {
|
JSONObject one = (JSONObject) JSONObject.toJSON(data);
|
JSONObject existsObject = one.getJSONObject("existsObject");
|
if (existsObject == null) {
|
continue;
|
}
|
SchemeDetail detail = JSON.parseObject(one.toJSONString(), SchemeDetail.class);
|
String dataInfoTable = detail.getDataInfoTable();
|
if (!StringUtils.isEmpty(dataInfoTable)) {
|
String s = DbUtils.lineToHump(dataInfoTable);
|
String substring = s.substring(0, 1);
|
s = substring.toUpperCase() + s.substring(1);
|
s = "com.highdatas.srs.entity." +s;
|
Object o = JSON.parseObject(existsObject.toJSONString(), Class.forName(s));
|
if (o instanceof InfoSurface) {
|
InfoSurface surface = (InfoSurface) o;
|
surface.dataInsertOrUpdate();
|
}
|
if (o instanceof TitleService) {
|
TitleService titleService = (TitleService) o;
|
String title = titleService.getTitle();
|
scheme.setName(title).updateById();
|
}
|
}
|
|
}
|
List<SchemeDetail> array = JSON.parseArray(datas.toJSONString(), SchemeDetail.class);
|
for (SchemeDetail detail : array) {
|
if (StringUtils.isEmpty(detail.getId())) {
|
detail.setId(DbUtils.getUUID()).setCreateTime(new Date());
|
}
|
detail.setUpdateTime(new Date());
|
detail.insertOrUpdate();
|
|
if (detail.getMustAttach()) {
|
//必须传附件
|
|
detail.setAttachment(FileUtils.createFile(basePath, scheme.getName(), detail.getType().name()));
|
} else {
|
detail.setAttachment(null);
|
}
|
|
detailParttimeService.delete(new EntityWrapper<SchemeDetailParttime>().eq("parent_id", detail.getId()));
|
Boolean parttime = detail.getParttime();
|
if (parttime == null) {
|
parttime = false;
|
}
|
if(parttime) {
|
List<SchemeDetailParttime> parttimeList = detail.getParttimeList();
|
for (SchemeDetailParttime schemeDetailParttime : parttimeList) {
|
schemeDetailParttime.setId(DbUtils.getUUID()).setParentId(detail.getId()).insert();
|
}
|
}
|
detail.insertOrUpdate();
|
}
|
return Result.success(CodeMsg.UPDATE_SUCCESS);
|
}
|
catch (Exception e) {
|
e.printStackTrace();
|
return Result.error(CodeMsg.UPDATE_ERROR);
|
}
|
}
|
|
@RequestMapping(value = "/view")
|
public Result view(@RequestParam Date startTime, @RequestParam Date endTime, HttpServletRequest request) {
|
String schemeId = request.getParameter("schemeId");
|
String userId = request.getParameter("userId");
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(startTime);
|
// calendar.add(Calendar.DAY_OF_YEAR, 1);
|
calendar.set(Calendar.HOUR, 0);
|
// endTime = calendar.getTime();
|
// calendar.setTime(startTime);
|
// calendar.set(Calendar.HOUR, 0);
|
// calendar.add(Calendar.DAY_OF_YEAR, 1);
|
startTime = calendar.getTime();
|
LinkedHashMap<Date, SchemeDetailCountEntity> resultMap = new LinkedHashMap<>();
|
Date now = new Date();
|
|
ArrayList<String> dateList = new ArrayList<>();
|
ArrayList<Integer> runtimeList = new ArrayList<>();
|
ArrayList<Integer> delayList = new ArrayList<>();
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
while (startTime.before(endTime) || startTime.compareTo(endTime) == 0) {
|
Wrapper<SchemeDetail> runtimeWrapper = new EntityWrapper<SchemeDetail>().eq("edit",false).eq("finish", false).eq("delay", false).le("start_time", startTime).ge("end_time", startTime);
|
Wrapper<SchemeDetail> delayWrapper = new EntityWrapper<SchemeDetail>().eq("edit",false).eq("finish", false).eq("delay", true).le("start_time", startTime);
|
if(!StringUtils.isEmpty(userId)) {
|
runtimeWrapper.eq("user_id", userId);
|
delayWrapper.eq("user_id", userId);
|
}
|
if(!StringUtils.isEmpty(schemeId)) {
|
runtimeWrapper.eq("parent_id", schemeId);
|
delayWrapper.eq("parent_id", schemeId);
|
}
|
|
int runtimeCnt = schemeDetailService.selectCount(runtimeWrapper);
|
int delayCnt = 0;
|
// startTime.setDate(startTime.getDate() - 1);
|
|
if (startTime.before(now) || startTime.compareTo(now) == 0) {
|
List<SchemeDetail> detailList = schemeDetailService.selectList(delayWrapper);
|
for (SchemeDetail detail : detailList) {
|
Date detailEndTime = detail.getEndTime();
|
// detailEndTime.setDate(detailEndTime.getDate() + 1);
|
if (detailEndTime.compareTo(startTime) > -1) {
|
runtimeCnt++;
|
} else {
|
delayCnt++;
|
}
|
}
|
}
|
runtimeList.add(runtimeCnt);
|
delayList.add(delayCnt);
|
// startTime.setDate(startTime.getDate() - 1);
|
String dateStr = format.format(startTime);
|
// startTime.setDate(startTime.getDate() + 1);
|
dateList.add(dateStr);
|
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
startTime = calendar.getTime();
|
}
|
JSONObject object = new JSONObject();
|
object.fluentPut("date", dateList);
|
object.fluentPut("runtime", runtimeList);
|
object.fluentPut("delay", delayList);
|
return Result.success(object);
|
}
|
|
@RequestMapping(value = "/view/detail", method = RequestMethod.GET)
|
public Result view(@RequestParam Date startTime, HttpServletRequest request) {
|
String schemeId = request.getParameter("schemeId");
|
String userId = request.getParameter("userId");
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(startTime);
|
// calendar.add(Calendar.DAY_OF_YEAR, 1);
|
calendar.set(Calendar.HOUR, 0);
|
startTime = calendar.getTime();
|
Wrapper<SchemeDetail> runtimeWrapper = new EntityWrapper<SchemeDetail>().eq("edit",false).eq("finish", false).eq("delay", false).le("start_time", startTime).ge("end_time", startTime);
|
Wrapper<SchemeDetail> delayWrapper = new EntityWrapper<SchemeDetail>().eq("edit",false).eq("finish", false).eq("delay", true).le("start_time", startTime);
|
if(!StringUtils.isEmpty(userId)) {
|
runtimeWrapper.eq("user_id", userId);
|
delayWrapper.eq("user_id", userId);
|
}
|
if(!StringUtils.isEmpty(schemeId)) {
|
runtimeWrapper.eq("parent_id", schemeId);
|
delayWrapper.eq("parent_id", schemeId);
|
}
|
Date now = new Date();
|
List<SchemeDetail> resultList = new ArrayList<>();
|
List<SchemeDetail> detailList;
|
// now.setDate(now.getDate() + 1);
|
// now.setHours(23);
|
if(now.compareTo(startTime) > -1) {
|
detailList = schemeDetailService.selectList(delayWrapper);
|
if (detailList != null && !detailList.isEmpty()) {
|
for (SchemeDetail detail : detailList) {
|
Date detailEndTime = detail.getEndTime();
|
// detailEndTime.setDate(detailEndTime.getDate() + 1);
|
if (detailEndTime.compareTo(startTime) > -1) {
|
detail.setDelay(false);
|
}
|
// detailEndTime.setDate(detailEndTime.getDate() - 1);
|
resultList.add(detail);
|
}
|
|
}
|
}
|
|
detailList = schemeDetailService.selectList(runtimeWrapper);
|
if (detailList != null && !detailList.isEmpty()) {
|
detailList = detailList.stream().map(detail -> detail.setDelay(false)).collect(Collectors.toList());
|
resultList.addAll(detailList);
|
}
|
Collections.sort(resultList, new Comparator<SchemeDetail>() {
|
@Override
|
public int compare(SchemeDetail o1, SchemeDetail o2) {
|
return o1.getStartTime().compareTo(o2.getStartTime());
|
}
|
});
|
for (SchemeDetail detail : resultList) {
|
String parentId = detail.getParentId();
|
Scheme scheme = schemeService.selectById(parentId);
|
if (scheme == null) {
|
continue;
|
}
|
detail.setSchemeName(scheme.getName());
|
SysUser sysUser = userService.selectById(detail.getUserId());
|
detail.setUserId(sysUser.getName());
|
Module module = moduleService.selectById(detail.getType());
|
detail.setTypeStr(module.getTitle());
|
}
|
return Result.success(resultList);
|
}
|
|
|
}
|