|
|
@ -4,18 +4,25 @@ import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.io.FileUtil; |
|
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.core.util.ZipUtil; |
|
|
|
import cn.hutool.crypto.SecureUtil; |
|
|
|
import com.ccsens.tall.bean.dto.ProjectDto; |
|
|
|
import com.ccsens.tall.bean.dto.RoleDto; |
|
|
|
import com.ccsens.tall.bean.po.*; |
|
|
|
import com.ccsens.tall.bean.vo.MemberVo; |
|
|
|
import com.ccsens.tall.bean.vo.ProjectVo; |
|
|
|
import com.ccsens.tall.bean.vo.RoleVo; |
|
|
|
import com.ccsens.tall.bean.vo.WbsVo; |
|
|
|
import com.ccsens.tall.persist.dao.*; |
|
|
|
import com.ccsens.util.PoiUtil; |
|
|
|
import com.ccsens.util.PropUtil; |
|
|
|
import com.ccsens.util.WebConstant; |
|
|
|
import com.ccsens.util.*; |
|
|
|
import com.ccsens.util.exception.BaseException; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFRow; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.core.io.DefaultResourceLoader; |
|
|
@ -24,6 +31,7 @@ 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.io.File; |
|
|
|
import java.math.BigDecimal; |
|
|
@ -34,26 +42,32 @@ import java.util.*; |
|
|
|
@Service |
|
|
|
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class) |
|
|
|
public class ExportWbsService implements IExportWbsService{ |
|
|
|
@Autowired |
|
|
|
@Resource |
|
|
|
private SysProjectDao sysProjectDao; |
|
|
|
@Autowired |
|
|
|
@Resource |
|
|
|
private ProMemberDao proMemberDao; |
|
|
|
@Autowired |
|
|
|
@Resource |
|
|
|
private ProMemberRoleDao proMemberRoleDao; |
|
|
|
@Resource |
|
|
|
private ProRoleDao proRoleDao; |
|
|
|
@Autowired |
|
|
|
@Resource |
|
|
|
private ProRoleExcludeDao proRoleExcludeDao; |
|
|
|
@Autowired |
|
|
|
@Resource |
|
|
|
private TaskDetailDao taskDetailDao; |
|
|
|
@Autowired |
|
|
|
@Resource |
|
|
|
private TaskDeliverDao taskDeliverDao; |
|
|
|
@Autowired |
|
|
|
@Resource |
|
|
|
private SysPluginDao sysPluginDao; |
|
|
|
@Autowired |
|
|
|
@Resource |
|
|
|
private TaskDeliverService taskDeliverService; |
|
|
|
@Autowired |
|
|
|
@Resource |
|
|
|
private ProTaskDetailService taskDetailService; |
|
|
|
@Autowired |
|
|
|
@Resource |
|
|
|
private ProRoleService proRoleService; |
|
|
|
@Resource |
|
|
|
private IUserService userService; |
|
|
|
@Resource |
|
|
|
private Snowflake snowflake; |
|
|
|
|
|
|
|
@Override |
|
|
|
public String exportWbs(Long projectId) throws Exception { |
|
|
@ -607,9 +621,9 @@ public class ExportWbsService implements IExportWbsService{ |
|
|
|
List<PoiUtil.PoiUtilCell> taskTitle = new ArrayList<>(); |
|
|
|
taskTitle.add(new PoiUtil.PoiUtilCell("序号")); |
|
|
|
taskTitle.add(new PoiUtil.PoiUtilCell("成员名")); |
|
|
|
taskTitle.add(new PoiUtil.PoiUtilCell("电话/账号")); |
|
|
|
taskTitle.add(new PoiUtil.PoiUtilCell("电话")); |
|
|
|
taskTitle.add(new PoiUtil.PoiUtilCell("奖惩干系人")); |
|
|
|
taskTitle.add(new PoiUtil.PoiUtilCell("干系人账号")); |
|
|
|
taskTitle.add(new PoiUtil.PoiUtilCell("干系人手机号")); |
|
|
|
memberSheet.add(taskTitle); |
|
|
|
|
|
|
|
int index = 1; |
|
|
@ -703,13 +717,7 @@ public class ExportWbsService implements IExportWbsService{ |
|
|
|
//生成文件
|
|
|
|
String fileName = "/exportWbs/" + DateUtil.today() + "/" + System.currentTimeMillis() + ".xlsx"; |
|
|
|
String path = WebConstant.UPLOAD_PATH_BASE + fileName; |
|
|
|
File tmpFile = new File(path); |
|
|
|
if (!tmpFile.getParentFile().exists()) { |
|
|
|
tmpFile.getParentFile().mkdirs(); |
|
|
|
} |
|
|
|
OutputStream stream = new FileOutputStream(tmpFile); |
|
|
|
wb.write(stream); |
|
|
|
stream.close(); |
|
|
|
writeFile(wb, path); |
|
|
|
|
|
|
|
return PropUtil.imgDomain + "/" + fileName; |
|
|
|
} |
|
|
@ -889,6 +897,40 @@ public class ExportWbsService implements IExportWbsService{ |
|
|
|
//生成文件
|
|
|
|
String fileName = "/"+filePath+"/" + "MVP" + ".xlsx"; |
|
|
|
String path = WebConstant.UPLOAD_PATH_BASE + fileName; |
|
|
|
writeFile(wb, path); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 导出项目成员表 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public String exportMember(ProjectDto.ProjectIdDto params, Long userId) throws Exception { |
|
|
|
String fileName = "exportWbs/" + DateUtil.today() + "/" + System.currentTimeMillis() + ".xlsx"; |
|
|
|
String path = PropUtil.path + fileName; |
|
|
|
//权限验证
|
|
|
|
int power = proRoleService.selectPowerByRoleName(userId, params.getProjectId()); |
|
|
|
if (power < 2) { |
|
|
|
throw new BaseException(CodeEnum.NOT_POWER); |
|
|
|
} |
|
|
|
//查找项目内所有成员
|
|
|
|
List<MemberVo.ExportMember> exportMemberList = proMemberDao.queryByProjectId(params.getProjectId()); |
|
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(exportMemberList)){ |
|
|
|
//生成写入数据
|
|
|
|
List<List<PoiUtil.PoiUtilCell>> list = writeMember(exportMemberList); |
|
|
|
//导出文件
|
|
|
|
XSSFWorkbook wb = new XSSFWorkbook(); |
|
|
|
//写入数据
|
|
|
|
PoiUtil.exportWB("项目成员表", list, wb); |
|
|
|
//生成文件
|
|
|
|
writeFile(wb, path); |
|
|
|
|
|
|
|
} |
|
|
|
return PropUtil.imgDomain + "/" + fileName; |
|
|
|
} |
|
|
|
|
|
|
|
private void writeFile(XSSFWorkbook wb, String path) throws IOException { |
|
|
|
File tmpFile = new File(path); |
|
|
|
if (!tmpFile.getParentFile().exists()) { |
|
|
|
tmpFile.getParentFile().mkdirs(); |
|
|
@ -898,4 +940,158 @@ public class ExportWbsService implements IExportWbsService{ |
|
|
|
stream.close(); |
|
|
|
} |
|
|
|
|
|
|
|
private List<List<PoiUtil.PoiUtilCell>> writeMember(List<MemberVo.ExportMember> exportMemberList) { |
|
|
|
List<List<PoiUtil.PoiUtilCell>> list = new ArrayList<>(); |
|
|
|
List<PoiUtil.PoiUtilCell> title = new ArrayList<>(); |
|
|
|
title.add(new PoiUtil.PoiUtilCell("序号")); |
|
|
|
title.add(new PoiUtil.PoiUtilCell("成员名")); |
|
|
|
title.add(new PoiUtil.PoiUtilCell("电话")); |
|
|
|
title.add(new PoiUtil.PoiUtilCell("奖惩干系人")); |
|
|
|
title.add(new PoiUtil.PoiUtilCell("干系人手机号")); |
|
|
|
title.add(new PoiUtil.PoiUtilCell("备注")); |
|
|
|
list.add(title); |
|
|
|
|
|
|
|
for (int i = 0; i < exportMemberList.size(); i++) { |
|
|
|
MemberVo.ExportMember exportMember = exportMemberList.get(i); |
|
|
|
List<PoiUtil.PoiUtilCell> member = new ArrayList<>(); |
|
|
|
member.add(new PoiUtil.PoiUtilCell((i + 1) + "")); |
|
|
|
member.add(new PoiUtil.PoiUtilCell(exportMember.getMName())); |
|
|
|
member.add(new PoiUtil.PoiUtilCell(exportMember.getMPhone())); |
|
|
|
member.add(new PoiUtil.PoiUtilCell(exportMember.getSName())); |
|
|
|
member.add(new PoiUtil.PoiUtilCell(exportMember.getSPhone())); |
|
|
|
list.add(member); |
|
|
|
} |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 导入项目成员表 |
|
|
|
* @param path 路径 |
|
|
|
* @param currentUserId userId |
|
|
|
* @param projectId 项目id |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void importMember(String path, Long currentUserId, Long projectId) throws Exception { |
|
|
|
|
|
|
|
// //验证权限
|
|
|
|
// int power = proRoleService.selectPowerByRoleName(currentUserId, projectId);
|
|
|
|
// if (power < 2) {
|
|
|
|
// throw new BaseException(CodeEnum.NOT_POWER);
|
|
|
|
// }
|
|
|
|
// //获取excel表格
|
|
|
|
// InputStream is = new FileInputStream(path);
|
|
|
|
// XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is);
|
|
|
|
// //获取项目成员表
|
|
|
|
// XSSFSheet memberSheet = xssfWorkbook.getSheet("项目成员表");
|
|
|
|
//
|
|
|
|
// //读取WBS表
|
|
|
|
// List<ProMember> stakeholderList = new ArrayList<>();
|
|
|
|
// if (ObjectUtil.isNotNull(memberSheet)) {
|
|
|
|
// Set<Long> userIdSet = new HashSet<>();
|
|
|
|
//
|
|
|
|
// for (int i = 1; i <= memberSheet.getLastRowNum(); i++) {
|
|
|
|
// XSSFRow row = memberSheet.getRow(i);
|
|
|
|
// if(ObjectUtil.isNull(row)){
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
// String memberCell = ExcelUtil.getCellValue(row.getCell(1));
|
|
|
|
// String phoneCell = ExcelUtil.getCellValue(row.getCell(2));
|
|
|
|
// String stakeholderCell = ExcelUtil.getCellValue(row.getCell(3));
|
|
|
|
// String stakeholderPhoneCell = ExcelUtil.getCellValue(row.getCell(4));
|
|
|
|
// ProMember stakeholder = null;
|
|
|
|
// ProMember member;
|
|
|
|
// //成员名为空,跳至下一行
|
|
|
|
// if ((StrUtil.isEmpty(memberCell))) {
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
// //手机号不能为空
|
|
|
|
// if (StrUtil.isNotEmpty(memberCell) && StrUtil.isEmpty(phoneCell)) {
|
|
|
|
// throw new BaseException(CodeEnum.WBS_NOT_PHONE.addMsg(memberSheet.getSheetName(), (i+1),memberCell));
|
|
|
|
// }
|
|
|
|
// //判断手机号格式
|
|
|
|
// String regex ="^[1]([3-9])[0-9]{9}$";
|
|
|
|
// if (StrUtil.isEmpty(phoneCell) || !phoneCell.matches(regex)){
|
|
|
|
// throw new BaseException(CodeEnum.WBS_PHONE_ERROR.addMsg(memberSheet.getSheetName(),(i+1),memberCell));
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// //添加奖惩干系人
|
|
|
|
// if (StrUtil.isNotEmpty(stakeholderCell)) {
|
|
|
|
// //判断奖惩干系人的手机号是否为空
|
|
|
|
// if ( StrUtil.isEmpty(stakeholderPhoneCell)){
|
|
|
|
// throw new BaseException(CodeEnum.WBS_NOT_PHONE.addMsg(memberSheet.getSheetName(), (i+1),stakeholderCell));
|
|
|
|
// }
|
|
|
|
// //判断奖惩干系人的手机号格式是否正确
|
|
|
|
// if (!stakeholderPhoneCell.matches(regex)){
|
|
|
|
// throw new BaseException(CodeEnum.WBS_PHONE_ERROR.addMsg(memberSheet.getSheetName(),(i+1),stakeholderCell));
|
|
|
|
// }
|
|
|
|
// if (!stakeholderWithPhone(stakeholderList, stakeholderCell, stakeholderPhoneCell)) {
|
|
|
|
// Long userId = userService.selectUserIdByPhone(stakeholderPhoneCell);
|
|
|
|
// if (ObjectUtil.isNotNull(userId)) {
|
|
|
|
// userIdSet.add(userId);
|
|
|
|
// }
|
|
|
|
// stakeholder = new ProMember();
|
|
|
|
// stakeholder.setId(snowflake.nextId());
|
|
|
|
// stakeholder.setProjectId(projectId);
|
|
|
|
// stakeholder.setUserId(userId);
|
|
|
|
// stakeholder.setNickname(stakeholderCell);
|
|
|
|
// stakeholder.setPhone(stakeholderPhoneCell);
|
|
|
|
// proMemberDao.insertSelective(stakeholder);
|
|
|
|
// stakeholderList.add(stakeholder);
|
|
|
|
//
|
|
|
|
// ProMemberRole proMemberRole = new ProMemberRole();
|
|
|
|
// proMemberRole.setId(snowflake.nextId());
|
|
|
|
// proMemberRole.setMemberId(stakeholder.getId());
|
|
|
|
// proMemberRole.setRoleId(stakeholderId);
|
|
|
|
// proMemberRoleDao.insertSelective(proMemberRole);
|
|
|
|
// } else {
|
|
|
|
// throw new BaseException(CodeEnum.WBS_STAKEHOLDER_PHONE.addMsg(memberSheet.getSheetName(),(i+1),stakeholderCell));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// //成员
|
|
|
|
// if (StrUtil.isNotEmpty(memberCell)) {
|
|
|
|
// if (!memberAndPhoneRepeat(proMembers, memberCell, phoneCell)) {
|
|
|
|
// Long userId = userService.selectUserIdByPhone(phoneCell);
|
|
|
|
// if (ObjectUtil.isNotNull(userId)) {
|
|
|
|
// userIdSet.add(userId);
|
|
|
|
// }
|
|
|
|
// member = new ProMember();
|
|
|
|
// member.setId(snowflake.nextId());
|
|
|
|
// member.setProjectId(sysProject.getId());
|
|
|
|
// member.setUserId(userId);
|
|
|
|
// member.setNickname(memberCell);
|
|
|
|
// member.setPhone(phoneCell);
|
|
|
|
// if (ObjectUtil.isNotNull(stakeholder)) {
|
|
|
|
// member.setStakeholderId(stakeholder.getId());
|
|
|
|
// }
|
|
|
|
// proMemberService.saveMember(member);
|
|
|
|
// proMembers.add(member);
|
|
|
|
//// //创建者依据project的creatorId判断,不需要添加成员
|
|
|
|
// } else {
|
|
|
|
// throw new BaseException(CodeEnum.WBS_REPEAT_MEMBER_PHONE.addMsg(memberSheet.getSheetName(),(i+1)));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// //TODO 每个成员都关注此项目(暂时)
|
|
|
|
// addUserAttention(userIdSet, sysProject);
|
|
|
|
// } else {
|
|
|
|
// throw new BaseException(CodeEnum.WBS_NOT_MEMBER_SHEET);
|
|
|
|
// }
|
|
|
|
} |
|
|
|
|
|
|
|
private boolean stakeholderWithPhone(List<ProMember> stakeholderList, String stakeholderName, String phone) { |
|
|
|
if (CollectionUtil.isNotEmpty(stakeholderList)) { |
|
|
|
for (ProMember proMember : stakeholderList) { |
|
|
|
if (stakeholderName.equalsIgnoreCase(proMember.getNickname())) { |
|
|
|
if (!proMember.getPhone().equalsIgnoreCase(phone)) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (proMember.getPhone().equalsIgnoreCase(phone)) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|