|
|
@ -1,28 +1,38 @@ |
|
|
|
package com.ccsens.ptccsens.service; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
|
import cn.hutool.core.text.StrFormatter; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.poi.excel.ExcelUtil; |
|
|
|
import cn.hutool.poi.excel.ExcelWriter; |
|
|
|
import com.ccsens.ptccsens.bean.dto.CommonQueryDto; |
|
|
|
import com.ccsens.ptccsens.bean.dto.DailyAccountDto; |
|
|
|
import com.ccsens.ptccsens.bean.po.PluDailyAccountEmpProTask; |
|
|
|
import com.ccsens.ptccsens.bean.po.PluDailyAccountEmpProTaskExample; |
|
|
|
import com.ccsens.ptccsens.bean.po.PluDailyAccountTask; |
|
|
|
import com.ccsens.ptccsens.bean.po.*; |
|
|
|
import com.ccsens.ptccsens.bean.vo.DailyAccountVo; |
|
|
|
import com.ccsens.ptccsens.persist.dao.PluDailyAccountDao; |
|
|
|
import com.ccsens.ptccsens.persist.dao.PluDailyAccountEmpDao; |
|
|
|
import com.ccsens.ptccsens.persist.dao.PluDailyAccountProDao; |
|
|
|
import com.ccsens.ptccsens.persist.mapper.PluDailyAccountEmpProTaskMapper; |
|
|
|
import com.ccsens.ptccsens.persist.mapper.PluDailyAccountTaskMapper; |
|
|
|
import com.ccsens.util.PropUtil; |
|
|
|
import com.ccsens.util.StringUtil; |
|
|
|
import com.ccsens.util.WebConstant; |
|
|
|
import com.ccsens.util.exception.BaseException; |
|
|
|
import com.ccsensptos.tallsdk.bean.vo.TallTaskVo; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.io.*; |
|
|
|
import java.util.Calendar; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
@ -34,6 +44,7 @@ import java.util.stream.Collectors; |
|
|
|
* @version: v1.0 |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
@Slf4j |
|
|
|
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class) |
|
|
|
public class DailyAccountService implements IDailyAccountService{ |
|
|
|
@Resource |
|
|
@ -59,34 +70,6 @@ public class DailyAccountService implements IDailyAccountService{ |
|
|
|
return info; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public DailyAccountVo.QueryTasks queryTasks(DailyAccountDto.QueryTasksDto param, CommonQueryDto.PageInfo pageInfo) { |
|
|
|
DailyAccountVo.QueryTasks tasks = new DailyAccountVo.QueryTasks(); |
|
|
|
|
|
|
|
//获取项目集合
|
|
|
|
if(CollectionUtil.isNotEmpty(param.getPros())){ |
|
|
|
tasks.setPros(param.getPros()); |
|
|
|
}else{ |
|
|
|
tasks.setPros(pluDailyAccountProDao.selectProjects().stream().map(DailyAccountVo.DailyAccountPro::getId).collect(Collectors.toList())); |
|
|
|
} |
|
|
|
|
|
|
|
//查询总页数
|
|
|
|
Long total = pluDailyAccountDao.selectEmpProTasksRecordNums(param.getStartTime(),param.getEndTime(),param.getEmps()); |
|
|
|
|
|
|
|
//获取任务
|
|
|
|
List<DailyAccountVo.TableRow> empProTasks = |
|
|
|
pluDailyAccountDao.selectEmpProTasks(param.getStartTime(),param.getEndTime(),param.getEmps(),param.getPros(),pageInfo); |
|
|
|
|
|
|
|
//组装返回
|
|
|
|
PageInfo<DailyAccountVo.TableRow> pageResult = new PageInfo<>(empProTasks); |
|
|
|
pageResult.setTotal(total); |
|
|
|
pageResult.setPageNum(pageInfo.getPageNum().intValue()); |
|
|
|
pageResult.setPageSize(pageInfo.getPageSize()); |
|
|
|
pageResult.setPages((total.intValue()-1) / pageInfo.getPageSize() + 1); |
|
|
|
tasks.setRecs(pageResult); |
|
|
|
return tasks; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void saveTask(DailyAccountDto.SubmitTask param) { |
|
|
|
//处理时间信息,转换为0:0:0
|
|
|
@ -127,4 +110,116 @@ public class DailyAccountService implements IDailyAccountService{ |
|
|
|
pluDailyAccountEmpProTaskMapper.insertSelective(empProTask); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public DailyAccountVo.QueryTasks queryTasks(DailyAccountDto.QueryTasksDto param, CommonQueryDto.PageInfo pageInfo) { |
|
|
|
DailyAccountVo.QueryTasks tasks = new DailyAccountVo.QueryTasks(); |
|
|
|
|
|
|
|
//获取项目集合
|
|
|
|
PluDailyAccountProExample proExample = new PluDailyAccountProExample(); |
|
|
|
PluDailyAccountProExample.Criteria criteria = proExample.createCriteria(); |
|
|
|
if(CollectionUtil.isNotEmpty(param.getPros())) { |
|
|
|
criteria.andIdIn(param.getPros()); |
|
|
|
} |
|
|
|
criteria.andRecStatusEqualTo(WebConstant.REC_STATUS.Normal.value); |
|
|
|
proExample.setOrderByClause("sequence asc"); |
|
|
|
List<PluDailyAccountPro> pros = pluDailyAccountProDao.selectByExample(proExample); |
|
|
|
tasks.setPros(pros.stream().map(PluDailyAccountPro::getId).collect(Collectors.toList())); |
|
|
|
|
|
|
|
//获取每一行任务集合
|
|
|
|
List<DailyAccountVo.TableRow> empProTasks = |
|
|
|
pluDailyAccountDao.selectEmpProTasks(param.getStartTime(),param.getEndTime(),param.getEmps(),param.getPros(),null); |
|
|
|
|
|
|
|
//组装返回
|
|
|
|
tasks.setRecs(empProTasks); |
|
|
|
return tasks; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String exportTasks(DailyAccountDto.QueryTasksDto param) throws IOException { |
|
|
|
DailyAccountVo.QueryTasks tasks = new DailyAccountVo.QueryTasks(); |
|
|
|
|
|
|
|
//获取项目集合
|
|
|
|
PluDailyAccountProExample proExample = new PluDailyAccountProExample(); |
|
|
|
PluDailyAccountProExample.Criteria criteria = proExample.createCriteria(); |
|
|
|
if(CollectionUtil.isNotEmpty(param.getPros())) { |
|
|
|
criteria.andIdIn(param.getPros()); |
|
|
|
} |
|
|
|
criteria.andRecStatusEqualTo(WebConstant.REC_STATUS.Normal.value); |
|
|
|
proExample.setOrderByClause("sequence asc"); |
|
|
|
List<PluDailyAccountPro> pros = pluDailyAccountProDao.selectByExample(proExample); |
|
|
|
|
|
|
|
//获取任务
|
|
|
|
List<DailyAccountVo.TableRow> empProTasks = |
|
|
|
pluDailyAccountDao.selectEmpProTasks(param.getStartTime(),param.getEndTime(),param.getEmps(),param.getPros(),null); |
|
|
|
|
|
|
|
//生成文件路径
|
|
|
|
String fileName = "exportWbs/" + DateUtil.today() + "/" + System.currentTimeMillis() + ".xlsx"; |
|
|
|
String path = PropUtil.path + fileName; |
|
|
|
File tmpFile = new File(path); |
|
|
|
if (!tmpFile.getParentFile().exists()) { |
|
|
|
tmpFile.getParentFile().mkdirs(); |
|
|
|
} |
|
|
|
|
|
|
|
//创建ExcelWriter
|
|
|
|
ExcelWriter writer = ExcelUtil.getWriter(path); |
|
|
|
|
|
|
|
//生成wbs表的数据
|
|
|
|
writeTasksToExcel(writer, pros, empProTasks); |
|
|
|
|
|
|
|
//关闭文件
|
|
|
|
writer.close(); |
|
|
|
|
|
|
|
return PropUtil.imgDomain + "/" + fileName; |
|
|
|
} |
|
|
|
|
|
|
|
private void writeTasksToExcel(ExcelWriter writer, List<PluDailyAccountPro> pros, List<DailyAccountVo.TableRow> empProTasks) { |
|
|
|
//写入标题
|
|
|
|
int row = 0,col = 0; |
|
|
|
writer.writeCellValue(col++,row,"时间"); |
|
|
|
writer.writeCellValue(col++,row,"姓名"); |
|
|
|
for (PluDailyAccountPro pro : pros) { |
|
|
|
writer.writeCellValue(col++,row,pro.getProjectShortName()); |
|
|
|
} |
|
|
|
row++; |
|
|
|
col = 0; |
|
|
|
|
|
|
|
//写入内容
|
|
|
|
for (DailyAccountVo.TableRow empProTask : empProTasks) { |
|
|
|
writer.writeCellValue(col++,row,DateUtil.format(new Date(empProTask.getTime()),"yyyy/MM/dd")); |
|
|
|
writer.writeCellValue(col++,row,empProTask.getEmpName()); |
|
|
|
//循环所有要导出的项目
|
|
|
|
for (PluDailyAccountPro titlePro : pros) { |
|
|
|
for (DailyAccountVo.ProjectTask pro : empProTask.getPros()) { |
|
|
|
if (titlePro.getId().longValue() == pro.getProId().longValue()){ |
|
|
|
//write tasks
|
|
|
|
writer.writeCellValue(col,row,formatTasksString(pro.getTasks())); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
col++; |
|
|
|
} |
|
|
|
row++; |
|
|
|
col = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private Object formatTasksString(List<DailyAccountVo.DailyAccountTask> tasks) { |
|
|
|
String format = "【{}】计划结果{}【{}】,交付物【{}】,截至【{}】,时长【{}】,检查人【{}】,链接【{}】\r\n"; |
|
|
|
StringBuilder stringBuilder = new StringBuilder(); |
|
|
|
int index = 0; |
|
|
|
for (DailyAccountVo.DailyAccountTask task : tasks) { |
|
|
|
stringBuilder.append( |
|
|
|
StrUtil.format(format,task.getCooperation().intValue() == 0 ? "自" : "协" , |
|
|
|
++index, |
|
|
|
task.getTaskName(), |
|
|
|
task.getDeliverName(), |
|
|
|
DateUtil.format(new Date(task.getDeadline()),"yyyy/MM/dd"), |
|
|
|
task.getDuration()/1000/3600, |
|
|
|
task.getChecker(), |
|
|
|
task.getDeliverLink()) |
|
|
|
); |
|
|
|
} |
|
|
|
return stringBuilder.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|