|
@@ -4,16 +4,11 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.management.platform.entity.FinanceProjects;
|
|
|
-import com.management.platform.entity.Project;
|
|
|
-import com.management.platform.entity.ProjectPercentage;
|
|
|
-import com.management.platform.entity.User;
|
|
|
-import com.management.platform.mapper.ProjectMapper;
|
|
|
-import com.management.platform.mapper.ProjectPercentageMapper;
|
|
|
-import com.management.platform.mapper.ReportMapper;
|
|
|
-import com.management.platform.mapper.UserMapper;
|
|
|
+import com.management.platform.entity.*;
|
|
|
+import com.management.platform.mapper.*;
|
|
|
import com.management.platform.service.FinanceProjectsService;
|
|
|
import com.management.platform.service.ProjectPercentageService;
|
|
|
+import com.management.platform.service.WxCorpInfoService;
|
|
|
import com.management.platform.util.ExcelUtil;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
import com.management.platform.util.MessageUtils;
|
|
@@ -21,6 +16,7 @@ import com.taobao.api.internal.util.StringUtils;
|
|
|
import org.apache.poi.EncryptedDocumentException;
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
@@ -53,6 +49,10 @@ public class ProjectPercentageServiceImpl extends ServiceImpl<ProjectPercentageM
|
|
|
@Resource
|
|
|
private ReportMapper reportMapper;
|
|
|
@Resource
|
|
|
+ private WxCorpInfoService wxCorpInfoService;
|
|
|
+ @Resource
|
|
|
+ private WxCorpInfoMapper wxCorpInfoMapper;
|
|
|
+ @Resource
|
|
|
private ProjectPercentageService projectPercentageService;
|
|
|
@Override
|
|
|
public HttpRespMsg saveMonthSetting(String projectCols, String userSettings, String ymonth) {
|
|
@@ -139,7 +139,7 @@ public class ProjectPercentageServiceImpl extends ServiceImpl<ProjectPercentageM
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg importData(Integer companyId, Integer withCheckIn, MultipartFile multipartFile, HttpServletRequest request,String ymonth) {
|
|
|
+ public HttpRespMsg importData(Integer companyId, Integer withCheckIn, MultipartFile multipartFile, HttpServletRequest request,String ymonth) throws Exception {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
String fileName=multipartFile.getOriginalFilename();
|
|
|
File file = new File(fileName == null ? "file" : fileName);
|
|
@@ -160,6 +160,7 @@ public class ProjectPercentageServiceImpl extends ServiceImpl<ProjectPercentageM
|
|
|
Workbook workbook = WorkbookFactory.create(new FileInputStream(file));
|
|
|
//获取公司全部成员
|
|
|
List<User> allUserList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id",companyId));
|
|
|
Sheet sheet = workbook.getSheetAt(0);
|
|
|
//由于第一行需要指明列对应的标题
|
|
|
int rowNum = sheet.getLastRowNum();
|
|
@@ -176,6 +177,37 @@ public class ProjectPercentageServiceImpl extends ServiceImpl<ProjectPercentageM
|
|
|
List<FinanceProjects> filterFPList = new ArrayList<>();
|
|
|
int projectNameStartIndex=1;
|
|
|
int dataCount = 0;
|
|
|
+ List<String> userNameList=new ArrayList<>();
|
|
|
+ for(int rowIndex = 1; rowIndex <= rowNum; rowIndex++){
|
|
|
+ Row row = sheet.getRow(rowIndex);
|
|
|
+ if (row == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (ExcelUtil.isRowEmpty(row)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (row.getCell(0) == null) {
|
|
|
+ //msg.setError("第"+dataCount+"行缺少员工姓名");
|
|
|
+ msg.setError(MessageUtils.message("staff.nameNullByRow",rowIndex));
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ Cell userNameCell = row.getCell(0);
|
|
|
+ if (userNameCell!=null)userNameCell.setCellType(CellType.STRING);
|
|
|
+ String username = userNameCell.getStringCellValue().trim();
|
|
|
+ if(!userNameList.contains(username)&&!StringUtils.isEmpty(username)){
|
|
|
+ userNameList.add(username);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ HttpRespMsg respMsg=new HttpRespMsg();
|
|
|
+ if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1&&userNameList.size()>0){
|
|
|
+ System.out.println("参与搜素的人员列表"+userNameList + userNameList.size());
|
|
|
+ respMsg = wxCorpInfoService.getBatchSearchUserInfo(wxCorpInfo, userNameList,null);
|
|
|
+ if(respMsg.code.equals("0")){
|
|
|
+ msg.setError("姓名为["+String.valueOf(respMsg.data)+"]的人员存在重复,请使用工号!");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<User> targetUserList= (List<User>) respMsg.data;
|
|
|
for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
|
|
|
Row row = sheet.getRow(rowIndex);
|
|
|
if (row == null) {
|
|
@@ -198,8 +230,10 @@ public class ProjectPercentageServiceImpl extends ServiceImpl<ProjectPercentageM
|
|
|
break;
|
|
|
}
|
|
|
//查询对应名称项目 id存到projectList
|
|
|
- Project project = projectMapper.selectList(new QueryWrapper<Project>().eq("project_name", projectName)).get(0);
|
|
|
- projectList.add(project.getId().toString());
|
|
|
+ Optional<Project> first = allProjectList.stream().filter(al -> al.getProjectName().equals(projectName)).findFirst();
|
|
|
+ if(first.isPresent()){
|
|
|
+ projectList.add(first.get().getId().toString());
|
|
|
+ }
|
|
|
pIndex++;
|
|
|
}
|
|
|
if (projectNotExists) {
|
|
@@ -221,19 +255,27 @@ public class ProjectPercentageServiceImpl extends ServiceImpl<ProjectPercentageM
|
|
|
msg.setError(MessageUtils.message("staff.nameNullByRow",dataCount));
|
|
|
return msg;
|
|
|
}
|
|
|
- String username = row.getCell(0).getStringCellValue().trim();
|
|
|
+ Cell userNameCell = row.getCell(0);
|
|
|
+ if (userNameCell!=null)userNameCell.setCellType(CellType.STRING);
|
|
|
+ String username = userNameCell.getStringCellValue().trim();
|
|
|
//检查人员是否存在
|
|
|
- Optional<User> any = allUserList.stream().filter(u -> u.getName().equals(username)).findAny();
|
|
|
- if (!any.isPresent()) {
|
|
|
+ Optional<User> userOp;
|
|
|
+ if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
|
|
|
+ Optional<User> optional = targetUserList.stream().filter(tl -> tl.getName().equals(username)).findFirst();
|
|
|
+ userOp= allUserList.stream().filter(u ->((u.getJobNumber()!=null&&u.getJobNumber().equals(username))||(optional.isPresent()&&u.getCorpwxUserid()!=null&&u.getCorpwxUserid().equals(optional.get().getCorpwxUserid())))).findFirst();
|
|
|
+ }else {
|
|
|
+ userOp= allUserList.stream().filter(u -> u.getName().equals(username)||(u.getJobNumber()!=null&&u.getJobNumber().equals(username))).findFirst();
|
|
|
+ }
|
|
|
+ if (!userOp.isPresent()) {
|
|
|
//msg.setError("人员["+username+"]不存在,请先在组织结构中添加或者通过钉钉同步导入");
|
|
|
msg.setError(MessageUtils.message("staff.peopleNullAndAdd",username));
|
|
|
return msg;
|
|
|
}
|
|
|
//人员存在
|
|
|
- User user = userMapper.selectList(new QueryWrapper<User>().eq("name", username)).get(0);
|
|
|
+ User user = userOp.get();
|
|
|
Integer s = 0;
|
|
|
JSONObject jsonObject=new JSONObject();
|
|
|
- jsonObject.put("name",username);
|
|
|
+ jsonObject.put("name",user.getName());
|
|
|
jsonObject.put("id",user.getId());
|
|
|
for (int i=projectNameStartIndex; i < projectNameStartIndex + projectList.size(); i++) {
|
|
|
if (row.getCell(i) == null) {
|