fixed 首页任务数据添加任务/人员筛选

master
zhangjinli 2 years ago
parent e20db155b8
commit bb476496d4

@ -58,6 +58,10 @@ public class StatisticsController {
@Data @Data
static class SSParam { static class SSParam {
@Schema(title = "任务Id")
private int taskId;
@Schema(title = "员工Id")
private int userId;
@Schema(title = "时间条件", description = "1今日;2本周;3本月;4全年") @Schema(title = "时间条件", description = "1今日;2本周;3本月;4全年")
private int dateCondition; private int dateCondition;
@Schema(title = "开始时间(yyyy-MM-dd HH:mm:ss)", description = "如果传入dateCondition以月份区间为条件") @Schema(title = "开始时间(yyyy-MM-dd HH:mm:ss)", description = "如果传入dateCondition以月份区间为条件")
@ -72,14 +76,12 @@ public class StatisticsController {
@PostMapping("/data2") @PostMapping("/data2")
@AdminTokenValid @AdminTokenValid
public Result data2(@Validated @RequestBody SSParam param) { public Result data2(@Validated @RequestBody SSParam param) {
Integer condition = param.getDateCondition(); int condition = param.getDateCondition();
System.out.println(condition);
QueryWrapper<Video> qw = new QueryWrapper<>(); QueryWrapper<Video> qw = new QueryWrapper<>();
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd"); DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
DateTimeFormatter df2 = DateTimeFormatter.ofPattern("yyyy-MM"); DateTimeFormatter df2 = DateTimeFormatter.ofPattern("yyyy-MM");
LocalDate now = LocalDateTime.now().toLocalDate(); LocalDate now = LocalDateTime.now().toLocalDate();
LocalDate before =now.with(TemporalAdjusters.firstDayOfMonth()); LocalDate before = now.with(TemporalAdjusters.firstDayOfMonth());
if (null != condition) {
switch (condition) { switch (condition) {
case 1: case 1:
before = now; before = now;
@ -94,19 +96,20 @@ public class StatisticsController {
before = now.with(TemporalAdjusters.firstDayOfYear()); before = now.with(TemporalAdjusters.firstDayOfYear());
break; break;
default: default:
}
} else {
before = param.getBeginTime() != null ? param.getBeginTime().toLocalDate() : before; before = param.getBeginTime() != null ? param.getBeginTime().toLocalDate() : before;
now = param.getEndTime() != null ? param.getEndTime().toLocalDate() : now; now = param.getEndTime() != null ? param.getEndTime().toLocalDate() : now;
} }
if(param.getTaskId()>0){
qw.eq("taskId", param.getTaskId());
}
if(param.getUserId()>0){
qw.eq("userId", param.getUserId());
}
ArrayList<JSONObject> res = new ArrayList<>(); ArrayList<JSONObject> res = new ArrayList<>();
if(condition == 4){ if (4 == condition) {
qw.between("date_format(creatAt, '%Y-%m')", before.format(df2), now.plusMonths(1).format(df2)); qw.between("date_format(creatAt, '%Y-%m')", before.format(df2), now.plusMonths(1).format(df2));
List<JSONObject> videoDataBydDay =adminMapper.statistics3(qw); List<JSONObject> videoDataBydDay = adminMapper.statistics3(qw);
if (videoDataBydDay == null || videoDataBydDay.size() == 0) { for (int i = 0; i <= ChronoUnit.MONTHS.between(before, now); i++) {
return Result.success(null, "请求成功");
}
for (int i = 0; i <= ChronoUnit.MONTHS.between(before,now); i++) {
LocalDate today = before.plusMonths(i); LocalDate today = before.plusMonths(i);
JSONObject obj = null; JSONObject obj = null;
// Stream<JSONObject> dat1 = videoDataBydDay.stream().filter(x -> LocalDate.parse((CharSequence) x.get("dat"), df) == today); // Stream<JSONObject> dat1 = videoDataBydDay.stream().filter(x -> LocalDate.parse((CharSequence) x.get("dat"), df) == today);
@ -116,15 +119,12 @@ public class StatisticsController {
break; break;
} }
} }
res.add(obj == null ? new JSONObject().fluentPut("dat", today.format(df2)).fluentPut("playNumSum",0).fluentPut("collectionNumSum",0).fluentPut("reSendNumSum",0) res.add(obj == null ? new JSONObject().fluentPut("dat", today.format(df2)).fluentPut("playNumSum", 0).fluentPut("collectionNumSum", 0).fluentPut("reSendNumSum", 0)
.fluentPut("recommendNumSum",0).fluentPut("commentNumSum",0).fluentPut("commendNumSum",0): obj); .fluentPut("recommendNumSum", 0).fluentPut("commentNumSum", 0).fluentPut("commendNumSum", 0) : obj);
} }
}else { } else {
qw.between("date_format(creatAt, '%Y-%m-%d')", before, now.plusDays(1)); qw.between("date_format(creatAt, '%Y-%m-%d')", before, now.plusDays(1));
List<JSONObject> videoDataBydDay = adminMapper.statistics2(qw); List<JSONObject> videoDataBydDay = adminMapper.statistics2(qw);
if (videoDataBydDay == null || videoDataBydDay.size() == 0) {
return Result.success(null, "请求成功");
}
for (int i = 0; i <= ChronoUnit.DAYS.between(before, now); i++) { for (int i = 0; i <= ChronoUnit.DAYS.between(before, now); i++) {
LocalDate today = before.plusDays(i); LocalDate today = before.plusDays(i);
JSONObject obj = null; JSONObject obj = null;
@ -135,8 +135,8 @@ public class StatisticsController {
break; break;
} }
} }
res.add(obj == null ? new JSONObject().fluentPut("dat", today).fluentPut("playNumSum",0).fluentPut("collectionNumSum",0).fluentPut("reSendNumSum",0) res.add(obj == null ? new JSONObject().fluentPut("dat", today).fluentPut("playNumSum", 0).fluentPut("collectionNumSum", 0).fluentPut("reSendNumSum", 0)
.fluentPut("recommendNumSum",0).fluentPut("commentNumSum",0).fluentPut("commendNumSum",0) : obj); .fluentPut("recommendNumSum", 0).fluentPut("commentNumSum", 0).fluentPut("commendNumSum", 0) : obj);
} }
} }
return Result.success(res, "请求成功"); return Result.success(res, "请求成功");
@ -180,6 +180,7 @@ public class StatisticsController {
} }
} }
qw.between("createAt", before, now.plusDays(1)); qw.between("createAt", before, now.plusDays(1));
IPage page =(param.getType() != null && param.getType() == 1) ? userEffectRecordsMapper.rankByDepartment(pg,qw) : userEffectRecordsMapper.rankByUser(pg,qw); IPage page = (param.getType() != null && param.getType() == 1) ? userEffectRecordsMapper.rankByDepartment(pg, qw) : userEffectRecordsMapper.rankByUser(pg, qw);
return Result.success(page, "请求成功"); } return Result.success(page, "请求成功");
}
} }

@ -30,6 +30,7 @@ import java.util.stream.Collectors;
public class RestExceptionHandler { public class RestExceptionHandler {
/** /**
* *
*
* @param e the e * @param e the e
* @return ResultData * @return ResultData
*/ */
@ -38,47 +39,52 @@ public class RestExceptionHandler {
Result<String> result = null; Result<String> result = null;
if (e instanceof MethodArgumentNotValidException) { if (e instanceof MethodArgumentNotValidException) {
MethodArgumentNotValidException ex =(MethodArgumentNotValidException) e; MethodArgumentNotValidException ex = (MethodArgumentNotValidException) e;
result = Result.fail(HttpStatusEnum.BAD_REQUEST, result = Result.fail(HttpStatusEnum.BAD_REQUEST,
ex.getBindingResult().getAllErrors().stream() ex.getBindingResult().getAllErrors().stream()
.map(ObjectError::getDefaultMessage) .map(ObjectError::getDefaultMessage)
.collect(Collectors.joining(";")) .collect(Collectors.joining(";"))
); );
} else if (e instanceof ConstraintViolationException){ } else if (e instanceof ConstraintViolationException) {
ConstraintViolationException ex = (ConstraintViolationException) e; ConstraintViolationException ex = (ConstraintViolationException) e;
result = Result.fail(HttpStatusEnum.BAD_REQUEST, result = Result.fail(HttpStatusEnum.BAD_REQUEST,
ex.getConstraintViolations().stream() ex.getConstraintViolations().stream()
.map(ConstraintViolation::getMessage) .map(ConstraintViolation::getMessage)
.collect(Collectors.joining("; ")) .collect(Collectors.joining("; "))
); );
}else if (e instanceof BindException) { } else if (e instanceof BindException) {
BindException ex = (BindException ) e; BindException ex = (BindException) e;
result = Result.fail(HttpStatusEnum.BAD_REQUEST, result = Result.fail(HttpStatusEnum.BAD_REQUEST,
ex.getAllErrors().stream() ex.getAllErrors().stream()
.map(ObjectError::getDefaultMessage) .map(ObjectError::getDefaultMessage)
.collect(Collectors.joining("; ")) .collect(Collectors.joining("; "))
); );
} }
return new ResponseEntity<>(result,HttpStatus.BAD_REQUEST); return new ResponseEntity<>(result, HttpStatus.BAD_REQUEST);
} }
@ResponseStatus(HttpStatus.BAD_REQUEST) // @ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
@ResponseBody @ResponseBody
public Result<String> badRequestExceptionHandler(){ public Result<String> badRequestExceptionHandler(Exception e) {
return Result.fail(HttpStatusEnum.BAD_REQUEST); return Result.fail(HttpStatusEnum.CUSTOM_EXCEPTION, e.toString()
+ ":error at "
+ e.getStackTrace()[0].getClassName() + "<<Class>>"
+ e.getStackTrace()[0].getMethodName() + "<<method>>"
+ e.getStackTrace()[0].getLineNumber() + "<<lineNumber>>");
} }
/** /**
* *
*
* @param req * @param req
* @param e * @param e
* @return * @return
*/ */
@ExceptionHandler(value = BizException.class) @ExceptionHandler(value = BizException.class)
@ResponseBody @ResponseBody
public Result<String> bizExceptionHandler(HttpServletRequest req, BizException e){ public Result<String> bizExceptionHandler(HttpServletRequest req, BizException e) {
// log.error("发生业务异常!原因是:{}",e.getMessage()); // log.error("发生业务异常!原因是:{}",e.getMessage());
return Result.fail(e.getCode(),e.getMessage()); return Result.fail(e.getCode(), e.getMessage());
} }
} }

Loading…
Cancel
Save