|
@@ -0,0 +1,177 @@
|
|
|
+package com.management.platform.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.management.platform.entity.TaskRestart;
|
|
|
+import com.management.platform.entity.User;
|
|
|
+import com.management.platform.entity.WxCorpInfo;
|
|
|
+import com.management.platform.entity.vo.ProjectWithStage;
|
|
|
+import com.management.platform.entity.vo.StageCost;
|
|
|
+import com.management.platform.entity.vo.SysRichFunction;
|
|
|
+import com.management.platform.mapper.SysFunctionMapper;
|
|
|
+import com.management.platform.mapper.TaskRestartMapper;
|
|
|
+import com.management.platform.mapper.UserMapper;
|
|
|
+import com.management.platform.mapper.WxCorpInfoMapper;
|
|
|
+import com.management.platform.service.ExcelExportService;
|
|
|
+import com.management.platform.service.TaskRestartService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.management.platform.util.HttpRespMsg;
|
|
|
+import com.management.platform.util.MessageUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author Seyason
|
|
|
+ * @since 2023-01-17
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class TaskRestartServiceImpl extends ServiceImpl<TaskRestartMapper, TaskRestart> implements TaskRestartService {
|
|
|
+
|
|
|
+ String pathPrefix = "/upload/";
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TaskRestartMapper taskRestartMapper;
|
|
|
+ @Resource
|
|
|
+ private UserMapper userMapper;
|
|
|
+ @Resource
|
|
|
+ private WxCorpInfoMapper wxCorpInfoMapper;
|
|
|
+ @Resource
|
|
|
+ private SysFunctionMapper sysFunctionMapper;
|
|
|
+ @Resource
|
|
|
+ private ExcelExportService excelExportService;
|
|
|
+
|
|
|
+ @Value(value = "${upload.path}")
|
|
|
+ private String path;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getTaskRestartList(HttpServletRequest request, String startDate, String endDate, String personLiableId, String projectId,Integer pageIndex,Integer pageSize) {
|
|
|
+ String token = request.getHeader("TOKEN");
|
|
|
+ User user = userMapper.selectById(token);
|
|
|
+ Integer companyId = user.getCompanyId();
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", companyId));
|
|
|
+ List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
|
|
|
+ DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ DateTimeFormatter df2=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String needEndDate= LocalDate.parse(endDate, df).plusDays(1).format(df);
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ int startIndex = (pageIndex-1)*pageSize;
|
|
|
+ int endIndex = pageSize*pageIndex;
|
|
|
+ List<SysRichFunction> functionAllList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "全部项目任务重启表");
|
|
|
+ List<SysRichFunction> functionInchargeList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "负责项目任务重启表");
|
|
|
+ //判断查看权限
|
|
|
+ List<Map<String,Object>> record = taskRestartMapper.getTaskRestartList(companyId,startDate,needEndDate,null,personLiableId,projectId,startIndex,endIndex);
|
|
|
+ long total=taskRestartMapper.getTaskRestartCount(companyId,startDate,needEndDate,null,personLiableId,projectId,startIndex,endIndex);
|
|
|
+ if(functionAllList.size()==0){
|
|
|
+ if(functionInchargeList.size()>0){
|
|
|
+ record = taskRestartMapper.getTaskRestartList(companyId,startDate,needEndDate,user.getId(),personLiableId,projectId,startIndex,endIndex);
|
|
|
+ total=taskRestartMapper.getTaskRestartCount(companyId,startDate,needEndDate,user.getId(),personLiableId,projectId,null,null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (Map<String, Object> map : record) {
|
|
|
+ String personLiableIds = String.valueOf(map.get("personLiableIds"));
|
|
|
+ String restartDateString = String.valueOf(map.get("restartDate"));
|
|
|
+ String restartDate = LocalDateTime.parse(restartDateString, df2).format(df2);
|
|
|
+ map.put("restartDate",restartDate);
|
|
|
+ String[] split = personLiableIds.split(",");
|
|
|
+ List<String> list = Arrays.asList(split);
|
|
|
+ StringBuilder personLiableNames=new StringBuilder();
|
|
|
+ for (String s : list) {
|
|
|
+ Optional<User> first = userList.stream().filter(ul -> ul.getId().equals(s)).findFirst();
|
|
|
+ if(first.isPresent()){
|
|
|
+ if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
|
|
|
+ if(first.get().getCorpwxRealUserid()!=null){
|
|
|
+ personLiableNames.append(first.get().getCorpwxUserid()+",");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ personLiableNames.append(first.get().getName()+",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put("personLiableNames",personLiableNames.length()>1?personLiableNames.toString().substring(0,personLiableNames.length()-1):"");
|
|
|
+ }
|
|
|
+ HashMap map=new HashMap();
|
|
|
+ map.put("record",record);
|
|
|
+ map.put("total",total);
|
|
|
+ msg.data=map;
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg exportTaskRestartList(HttpServletRequest request, String startDate, String endDate, String personLiableId, String projectId) {
|
|
|
+ String token = request.getHeader("TOKEN");
|
|
|
+ User user = userMapper.selectById(token);
|
|
|
+ Integer companyId = user.getCompanyId();
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", companyId));
|
|
|
+ List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
|
|
|
+ DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ DateTimeFormatter df2=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String needEndDate= LocalDate.parse(endDate, df).plusDays(1).format(df);
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ List<SysRichFunction> functionAllList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "全部项目任务重启表");
|
|
|
+ List<SysRichFunction> functionInchargeList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "负责项目任务重启表");
|
|
|
+ //判断查看权限
|
|
|
+ List<Map<String,Object>> record = taskRestartMapper.getTaskRestartList(companyId,startDate,needEndDate,null,personLiableId,projectId,null,null);
|
|
|
+ if(functionAllList.size()==0){
|
|
|
+ if(functionInchargeList.size()>0){
|
|
|
+ record = taskRestartMapper.getTaskRestartList(companyId,startDate,needEndDate,user.getId(),personLiableId,projectId,null,null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<List<String>> dataList=new ArrayList<>();
|
|
|
+ List<String> titleList=new ArrayList<>();
|
|
|
+ titleList.add("项目编号");
|
|
|
+ titleList.add("项目名称");
|
|
|
+ titleList.add("任务名称");
|
|
|
+ titleList.add("重启原因");
|
|
|
+ titleList.add("责任人");
|
|
|
+ titleList.add("重启时间");
|
|
|
+ dataList.add(titleList);
|
|
|
+ for (Map<String, Object> map : record) {
|
|
|
+ List<String> item=new ArrayList<>();
|
|
|
+ item.add(String.valueOf(map.get("projectCode")==null?"":map.get("projectCode")));
|
|
|
+ item.add(String.valueOf(map.get("projectName")==null?"":map.get("projectName")));
|
|
|
+ item.add(String.valueOf(map.get("taskName")==null?"":map.get("taskName")));
|
|
|
+ item.add(String.valueOf(map.get("restartReason")==null?"":map.get("restartReason")));
|
|
|
+ String personLiableIds = String.valueOf(map.get("personLiableIds"));
|
|
|
+ String restartDateString = String.valueOf(map.get("restartDate"));
|
|
|
+ String restartDate = LocalDateTime.parse(restartDateString, df2).format(df2);
|
|
|
+ map.put("restartDate",restartDate);
|
|
|
+ String[] split = personLiableIds.split(",");
|
|
|
+ List<String> list = Arrays.asList(split);
|
|
|
+ StringBuilder personLiableNames=new StringBuilder();
|
|
|
+ for (String s : list) {
|
|
|
+ Optional<User> first = userList.stream().filter(ul -> ul.getId().equals(s)).findFirst();
|
|
|
+ if(first.isPresent()){
|
|
|
+ if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
|
|
|
+ if(first.get().getCorpwxRealUserid()!=null){
|
|
|
+ personLiableNames.append("$userName="+(first.get().getCorpwxUserid()==null?"":first.get().getCorpwxUserid())+"$"+",");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ personLiableNames.append(first.get().getName()+",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ item.add(String.valueOf(personLiableNames.length()>1?personLiableNames.toString().substring(0,personLiableNames.length()-1):""));
|
|
|
+ item.add(String.valueOf(map.get("restartDate")));
|
|
|
+ dataList.add(item);
|
|
|
+ }
|
|
|
+ String fileName = "任务重启报表_"+System.currentTimeMillis();
|
|
|
+ try {
|
|
|
+ return excelExportService.exportGeneralExcelByTitleAndList2(wxCorpInfo,fileName, dataList, path);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ msg.data = pathPrefix + fileName+".xlsx";
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+}
|