|
@@ -1,15 +1,25 @@
|
|
|
package com.wtkj.service.impl;
|
|
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
|
|
+import com.alibaba.excel.write.metadata.style.WriteFont;
|
|
|
+import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.wtkj.dto.MyTaskPageDTO;
|
|
|
import com.wtkj.dto.ProjectTaskPageDTO;
|
|
|
import com.wtkj.entity.*;
|
|
|
+import com.wtkj.mapper.ProjectMapper;
|
|
|
import com.wtkj.mapper.TaskMapper;
|
|
|
import com.wtkj.service.*;
|
|
|
+import com.wtkj.util.Workload;
|
|
|
import com.wtkj.vo.MyTaskStatistics;
|
|
|
import com.wutong.file.feign.IFileClient;
|
|
|
import com.wutong.file.vo.FileVO;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
|
+import org.apache.poi.ss.usermodel.IndexedColors;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
import org.springblade.core.redis.cache.BladeRedis;
|
|
@@ -18,14 +28,25 @@ import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.utils.DateUtil;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
import org.springblade.core.tool.utils.StringUtil;
|
|
|
+import org.springblade.system.entity.DictBiz;
|
|
|
+import org.springblade.system.entity.Region;
|
|
|
+import org.springblade.system.feign.IDictBizClient;
|
|
|
+import org.springblade.system.feign.ISysClient;
|
|
|
import org.springblade.system.user.entity.User;
|
|
|
import org.springblade.system.user.feign.IUserClient;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import static com.wtkj.config.MagicValue.STAFF_ADMIN;
|
|
|
+import static com.wtkj.config.MagicValue.STAFF_SECOND_ADMIN;
|
|
|
|
|
|
/**
|
|
|
* @author Blizzard
|
|
@@ -43,19 +64,24 @@ public class TaskServiceImpl extends BaseServiceImpl<TaskMapper, Task> implement
|
|
|
private final IUserClient userClient;
|
|
|
private final IProjectStageService stageService;
|
|
|
private final BladeRedis redis;
|
|
|
+ private final ISysClient sysClient;
|
|
|
+ private final ProjectMapper projectMapper;
|
|
|
+ private final IDictBizClient dictBizClient;
|
|
|
|
|
|
@Override
|
|
|
public boolean submit(Task task) {
|
|
|
boolean flag = false;
|
|
|
Long taskId = task.getId();
|
|
|
- if (taskId == null) {
|
|
|
+ Long projectId = task.getProjectId();
|
|
|
+ Project project = projectMapper.selectById(projectId);
|
|
|
+ if (taskId == null && project != null) {
|
|
|
Long stageId = task.getStageId();
|
|
|
ProjectStage stage = stageService.getById(stageId);
|
|
|
if (stage != null) {
|
|
|
Date startTime = stage.getStartTime();
|
|
|
Date endTime = stage.getEndTime();
|
|
|
if (task.getStartTime().before(startTime) || task.getEndTime().after(endTime)) {
|
|
|
- throw new ServiceException(String.format("任务时间异常,不可超出当前阶段的起止时间%s-%s", startTime, endTime));
|
|
|
+ throw new ServiceException(String.format("任务时间异常,不可超出当前阶段的起止时间%s-%s", DateUtil.format(startTime, "yyyy-MM-dd"), DateUtil.format(endTime, "yyyy-MM-dd")));
|
|
|
}
|
|
|
}
|
|
|
LocalDate now = LocalDate.now();
|
|
@@ -63,6 +89,7 @@ public class TaskServiceImpl extends BaseServiceImpl<TaskMapper, Task> implement
|
|
|
Integer month = now.getMonthValue();
|
|
|
task.setYear(year);
|
|
|
task.setMonth(month);
|
|
|
+ task.setCompetentUnit(project.getCompetentUnit());
|
|
|
flag = this.save(task);
|
|
|
asyncService.createTask(task);
|
|
|
} else {
|
|
@@ -89,7 +116,7 @@ public class TaskServiceImpl extends BaseServiceImpl<TaskMapper, Task> implement
|
|
|
asyncService.updateTask(4, userId, task);
|
|
|
}
|
|
|
//5.指定任务审查者
|
|
|
- if (StringUtil.isBlank(byId.getCheckUser()) && StringUtil.isNotBlank(task.getCheckUser())) {
|
|
|
+ if (byId.getFirstCheckUser() == null && byId.getSecondCheckUser() == null && task.getFirstCheckUser() != null && task.getSecondCheckUser() != null) {
|
|
|
asyncService.updateTask(5, userId, task);
|
|
|
}
|
|
|
//6.提交了任务
|
|
@@ -191,7 +218,7 @@ public class TaskServiceImpl extends BaseServiceImpl<TaskMapper, Task> implement
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public IPage<Task> myTaskPage(Integer type, Integer isGroup, Integer year, Integer month, IPage<Task> page) {
|
|
|
+ public IPage<Task> myTaskPage(MyTaskPageDTO dto, IPage<Task> page) {
|
|
|
|
|
|
Long userId = AuthUtil.getUserId();
|
|
|
LambdaQueryWrapper<Task> lqw = new LambdaQueryWrapper<>();
|
|
@@ -199,21 +226,80 @@ public class TaskServiceImpl extends BaseServiceImpl<TaskMapper, Task> implement
|
|
|
LocalDate currentDate = LocalDate.now();
|
|
|
int currentYear = currentDate.getYear();
|
|
|
int currentMonth = currentDate.getMonthValue();
|
|
|
- lqw.eq(Task::getYear, year == null ? currentYear : year);
|
|
|
- lqw.eq(Task::getMonth, month == null ? currentMonth : month);
|
|
|
-
|
|
|
- //1.全部 2.我创建的 3.我执行的
|
|
|
- if (type == 1) {
|
|
|
+ lqw.eq(Task::getYear, dto.getYear() == null ? currentYear : dto.getYear());
|
|
|
+ lqw.eq(Task::getMonth, dto.getMonth() == null ? currentMonth : dto.getMonth());
|
|
|
+
|
|
|
+ //1.全部 2.我创建的 3.我执行的 4.我管理的
|
|
|
+ if (dto.getType() == 1) {
|
|
|
+ Set<Long> ids = new HashSet<>();
|
|
|
+ //我管理的
|
|
|
+ if (dto.getDeptCategory().equals(3)) {
|
|
|
+ //1.业主 ---> 项目权限表里 topDept 字段是自己的集合
|
|
|
+ List<Task> tasks = this.getByCompetentUnit(dto.getTopDept());
|
|
|
+ if (!CollectionUtils.isEmpty(tasks)) {
|
|
|
+ Set<Long> taskIds = tasks.stream().map(Task::getId).collect(Collectors.toSet());
|
|
|
+ ids.addAll(taskIds);
|
|
|
+ }
|
|
|
+ } else if (dto.getDeptCategory().equals(4)) {
|
|
|
+ //2.服务商
|
|
|
+ String role = AuthUtil.getUserRole();
|
|
|
+ Long deptId = Func.firstLong(AuthUtil.getDeptId());
|
|
|
+ if (role.contains(STAFF_ADMIN)) {
|
|
|
+ // 2.1 机构管理员 ---> 任务是派遣给自己机构的
|
|
|
+ List<Task> byOrgDeptId = this.getByOrgDeptId(dto.getTopDept(), null);
|
|
|
+ if (!CollectionUtils.isEmpty(byOrgDeptId)) {
|
|
|
+ Set<Long> taskIds = byOrgDeptId.stream().map(Task::getId).collect(Collectors.toSet());
|
|
|
+ ids.addAll(taskIds);
|
|
|
+ }
|
|
|
+ } else if (role.contains(STAFF_SECOND_ADMIN)) {
|
|
|
+ // 2.2 次级机构主管 ---> 任务是派遣给自己部门的
|
|
|
+ List<Task> list = this.getByExecuteDept(deptId);
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
+ Set<Long> taskIds = list.stream().map(Task::getId).collect(Collectors.toSet());
|
|
|
+ ids.addAll(taskIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
lqw.and(wq -> {
|
|
|
wq.eq(Task::getCreateUser, userId);
|
|
|
wq.or().like(Task::getExecuteUser, String.valueOf(userId));
|
|
|
+ wq.in(Task::getId, ids);
|
|
|
});
|
|
|
- } else if (type == 2) {
|
|
|
+ } else if (dto.getType() == 2) {
|
|
|
lqw.eq(Task::getCreateUser, userId);
|
|
|
- } else {
|
|
|
+ } else if (dto.getType() == 3) {
|
|
|
lqw.like(Task::getExecuteUser, String.valueOf(userId));
|
|
|
+ } else if (dto.getType() == 4) {
|
|
|
+ //我管理的
|
|
|
+ if (dto.getDeptCategory().equals(3)) {
|
|
|
+ //1.业主 ---> 任务主管单位是自己topDept
|
|
|
+ List<Task> tasks = this.getByCompetentUnit(dto.getTopDept());
|
|
|
+ if (!CollectionUtils.isEmpty(tasks)) {
|
|
|
+ Set<Long> taskIds = tasks.stream().map(Task::getId).collect(Collectors.toSet());
|
|
|
+ lqw.in(Task::getId, taskIds);
|
|
|
+ }
|
|
|
+ } else if (dto.getDeptCategory().equals(4)) {
|
|
|
+ //2.服务商
|
|
|
+ String role = AuthUtil.getUserRole();
|
|
|
+ Long deptId = Func.firstLong(AuthUtil.getDeptId());
|
|
|
+ if (role.contains(STAFF_ADMIN)) {
|
|
|
+ // 2.1 机构管理员 ---> 任务是派遣给自己机构的
|
|
|
+ List<Task> byOrgDeptId = this.getByOrgDeptId(dto.getTopDept(), null);
|
|
|
+ if (!CollectionUtils.isEmpty(byOrgDeptId)) {
|
|
|
+ Set<Long> taskIds = byOrgDeptId.stream().map(Task::getId).collect(Collectors.toSet());
|
|
|
+ lqw.in(Task::getId, taskIds);
|
|
|
+ }
|
|
|
+ } else if (role.contains(STAFF_SECOND_ADMIN)) {
|
|
|
+ // 2.2 次级机构主管 ---> 任务是派遣给自己部门的
|
|
|
+ List<Task> list = this.getByExecuteDept(deptId);
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
+ Set<Long> taskIds = list.stream().map(Task::getId).collect(Collectors.toSet());
|
|
|
+ lqw.in(Task::getId, taskIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- if (isGroup == 1) {
|
|
|
+ if (dto.getType() == 1) {
|
|
|
lqw.groupBy(Task::getProjectId, Task::getCreateTime);
|
|
|
lqw.orderByDesc(Task::getProjectId, Task::getCreateTime);
|
|
|
} else {
|
|
@@ -521,6 +607,174 @@ public class TaskServiceImpl extends BaseServiceImpl<TaskMapper, Task> implement
|
|
|
return baseMapper.getTodayToExpire(date);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<Workload> exportList(String startDate, String endDate) {
|
|
|
+ List<Workload> result = new ArrayList<>();
|
|
|
+ //1.时间段内已经完成的任务
|
|
|
+ LambdaQueryWrapper<Task> lqw = new LambdaQueryWrapper<>();
|
|
|
+ lqw.between(Task::getConfirmTime, DateUtil.parse(startDate, "yyyy-MM-dd"), DateUtil.parse(endDate, "yyyy-MM-dd"));
|
|
|
+ List<Task> list = this.list(lqw);
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
+ List<Workload> tempList = new ArrayList<>();
|
|
|
+ //2.Information for all tasks
|
|
|
+ for (Task task : list) {
|
|
|
+ Workload workload = new Workload();
|
|
|
+ //人员
|
|
|
+ String executeUser = task.getExecuteUser();
|
|
|
+ //项目信息
|
|
|
+ Long projectId = task.getProjectId();
|
|
|
+ //发布人
|
|
|
+ Long createUser = task.getCreateUser();
|
|
|
+ //科研 方案 其他
|
|
|
+ String category = task.getCategory();
|
|
|
+ //新写 修改
|
|
|
+ String tags = task.getTags();
|
|
|
+ if (executeUser != null && projectId != null && createUser != null && createUser > -1L && category != null && tags != null) {
|
|
|
+ //发布人
|
|
|
+ R<User> userR = userClient.userInfoById(createUser);
|
|
|
+ if (userR.isSuccess()) {
|
|
|
+ workload.setPubUser(userR.getData().getName());
|
|
|
+ }
|
|
|
+ //项目信息
|
|
|
+ Project project = projectMapper.selectById(projectId);
|
|
|
+ if (project != null) {
|
|
|
+ workload.setProjectName(project.getName());
|
|
|
+ String areaCode = project.getAreaCode();
|
|
|
+ if (areaCode != null) {
|
|
|
+ if (areaCode.length() == 4) {
|
|
|
+ //市
|
|
|
+ R<Region> region = sysClient.getRegion(areaCode);
|
|
|
+ if (region.isSuccess()) {
|
|
|
+ workload.setCity(region.getData().getName());
|
|
|
+ }
|
|
|
+ } else if (areaCode.length() == 6) {
|
|
|
+ //县
|
|
|
+ R<Region> region = sysClient.getRegion(areaCode);
|
|
|
+ if (region.isSuccess()) {
|
|
|
+ workload.setCounty(region.getData().getName());
|
|
|
+ }
|
|
|
+ //得到上级
|
|
|
+ String parentCode = areaCode.substring(0, areaCode.length() - 2);
|
|
|
+ R<Region> region1 = sysClient.getRegion(parentCode);
|
|
|
+ if (region1.isSuccess()) {
|
|
|
+ workload.setCity(region1.getData().getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //分类 可研 方案 其他
|
|
|
+ R<DictBiz> rpc = dictBizClient.getById(Long.valueOf(category));
|
|
|
+ R<DictBiz> rpc1 = dictBizClient.getById(Long.valueOf(tags));
|
|
|
+ if (rpc.isSuccess() && rpc1.isSuccess()) {
|
|
|
+ DictBiz data = rpc.getData();
|
|
|
+ DictBiz data1 = rpc1.getData();
|
|
|
+ if (data1.getDictKey().equals("1")) {
|
|
|
+ //新编
|
|
|
+ if (data != null) {
|
|
|
+ if (data.getDictKey().equals("2")) {
|
|
|
+ //可研
|
|
|
+ workload.setAdd1(1);
|
|
|
+ } else if (data.getDictKey().equals("4")) {
|
|
|
+ //方案
|
|
|
+ workload.setAdd2(1);
|
|
|
+ } else {
|
|
|
+ //其他
|
|
|
+ workload.setAdd(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (data1.getDictKey().equals("2")) {
|
|
|
+ //修改
|
|
|
+ if (data != null) {
|
|
|
+ if (data.getDictKey().equals("2")) {
|
|
|
+ //可研
|
|
|
+ workload.setAlter1(1);
|
|
|
+ } else if (data.getDictKey().equals("4")) {
|
|
|
+ //方案
|
|
|
+ workload.setAlter2(1);
|
|
|
+ } else {
|
|
|
+ //其他
|
|
|
+ workload.setAlter(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //人员
|
|
|
+ R<User> userR1 = userClient.userInfoById(Long.valueOf(executeUser));
|
|
|
+ if (userR1.isSuccess()) {
|
|
|
+ workload.setUserName(userR1.getData().getName());
|
|
|
+ }
|
|
|
+ tempList.add(workload);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //Grouping to achieve the purpose of arranging the same user groups
|
|
|
+ if (!CollectionUtils.isEmpty(tempList)) {
|
|
|
+ Map<String, List<Workload>> collect = tempList.stream().collect(Collectors.groupingBy(Workload::getUserName));
|
|
|
+ for (Map.Entry<String, List<Workload>> entry : collect.entrySet()) {
|
|
|
+ result.addAll(entry.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void export(List<Workload> list, HttpServletResponse response) throws IOException {
|
|
|
+ try {
|
|
|
+ WriteCellStyle headWriteCellStyle = new WriteCellStyle();
|
|
|
+ //设置背景颜色
|
|
|
+ headWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
|
|
|
+ //设置头字体
|
|
|
+ WriteFont headWriteFont = new WriteFont();
|
|
|
+ headWriteFont.setFontHeightInPoints((short) 13);
|
|
|
+ headWriteFont.setBold(true);
|
|
|
+ headWriteCellStyle.setWriteFont(headWriteFont);
|
|
|
+ //设置头居中
|
|
|
+ headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
|
|
+
|
|
|
+ //内容策略
|
|
|
+ WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
|
|
|
+ //设置 水平居中
|
|
|
+ contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
|
|
+
|
|
|
+ HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
|
|
|
+
|
|
|
+ response.setContentType("application/vnd.ms-excel");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ // 这里URLEncoder.encode可以防止中文乱码 当然和easy excel没有关系
|
|
|
+ String fileName = URLEncoder.encode("工作量统计", "UTF-8");
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
|
|
+ // 这里需要设置不关闭流
|
|
|
+ EasyExcel.write(response.getOutputStream(), Workload.class)
|
|
|
+ .registerWriteHandler(horizontalCellStyleStrategy).sheet("工作量统计")
|
|
|
+ .doWrite(list);
|
|
|
+ } catch (IOException e) {
|
|
|
+ //throw new RuntimeException(e);
|
|
|
+ // 重置response
|
|
|
+ response.reset();
|
|
|
+ response.setContentType("application/json");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ Map<String, String> map = new HashMap<String, String>();
|
|
|
+ map.put("status", "failure");
|
|
|
+ map.put("message", "下载文件失败" + e.getMessage());
|
|
|
+ response.getWriter().println(JSON.toJSONString(map));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Task> getByExecuteDept(Long deptId) {
|
|
|
+ return baseMapper.getByExecuteDept(deptId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Task> getByCompetentUnit(Long deptId) {
|
|
|
+ return baseMapper.selectByCompetentUnit(deptId);
|
|
|
+ }
|
|
|
+
|
|
|
private List<Task> getListByDateAndStageAndStatus(Long stageId, String formatDate, Integer taskStatus) {
|
|
|
return baseMapper.selectByDateAndStageAndStatus(stageId, formatDate, taskStatus);
|
|
|
}
|