考勤排班导入接口,导入前校验

This commit is contained in:
dxfeng 2025-06-12 18:50:58 +08:00
parent ddb1560606
commit 3b78050547
3 changed files with 133 additions and 0 deletions

View File

@ -37,6 +37,11 @@ public class AttendanceSchedulingController {
return attendanceSchedulingService.saveChoseFirstShiftSec(header, body);
}
@PostMapping("/saveSheet")
public String saveSheet(@RequestHeader Map<String, String> header, @RequestBody Map<String, Object> body) {
return attendanceSchedulingService.saveSheet(header, body);
}
@PostMapping("/createWorkFlow")
private WeaResult<WfcRequestOperationResultDto> createWorkFlow(@RequestBody Map<String, String> params) throws UnsupportedEncodingException {

View File

@ -25,5 +25,8 @@ public interface AttendanceSchedulingService {
String saveChoseFirstShiftSec(Map<String, String> header,Map<String, Object> body);
String saveSheet(Map<String, String> header,Map<String, Object> body);
}

View File

@ -6,16 +6,22 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.weaver.common.base.entity.result.WeaResult;
import com.weaver.common.batch.excel.CellData;
import com.weaver.common.batch.excel.ExcelUtil;
import com.weaver.common.batch.excel.RowData;
import com.weaver.common.form.dto.data.FormDataDetailDto;
import com.weaver.common.form.dto.data.FormDataDto;
import com.weaver.common.form.dto.data.FormDataOptionDto;
import com.weaver.common.form.metadata.ModuleSource;
import com.weaver.common.hrm.dao.HrmCommonEmployeeDao;
import com.weaver.framework.rpc.annotation.RpcReference;
import com.weaver.seconddev.attend.entity.po.SchedulingStatusPo;
import com.weaver.seconddev.attend.mapper.AttendanceSchedulingMapper;
import com.weaver.seconddev.attend.mapper.SchedulingStatusMapper;
import com.weaver.seconddev.attend.service.AttendanceSchedulingService;
import com.weaver.teams.domain.user.SimpleEmployee;
import com.weaver.teams.security.context.UserContext;
import com.weaver.teams.security.session.TeamsSession;
import com.weaver.teams.security.user.User;
import com.weaver.workflow.core.api.rest.flow.entity.operate.WfcRequestOperateParamDataEntity;
import com.weaver.workflow.core.api.rest.flow.entity.operate.WfcRequestOperationResultDto;
@ -23,9 +29,12 @@ import com.weaver.workflow.core.api.rest.publicapi.WfcRequestOperateRest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Sheet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.*;
@ -48,6 +57,12 @@ public class AttendanceSchedulingServiceImpl implements AttendanceSchedulingServ
@Autowired
SchedulingStatusMapper schedulingStatusMapper;
@Autowired
HrmCommonEmployeeDao hrmCommonEmployeeDao;
@Autowired
private TeamsSession session;
@Override
public WeaResult<WfcRequestOperationResultDto> createFlowV2(Map<String, String> params) throws UnsupportedEncodingException {
String workflowId = params.get("workflowId");
@ -376,4 +391,114 @@ public class AttendanceSchedulingServiceImpl implements AttendanceSchedulingServ
log.error("resultObj===" + resultObj);
return JSON.toJSONString(resultObj);
}
@Override
public String saveSheet(Map<String, String> header, Map<String, Object> body) {
log.error("======saveSheet=========");
String result = "";
//1before callApi
//在调用接口前 可以做一些前置操作
//2调用实际api
String origin = header.get("origin");
String realUrl = String.valueOf(body.get("realUrl"));
String url = origin + realUrl;
log.error("url===" + url);
String bodyStr = JSON.toJSONString(body);
JSONObject jsonObject = JSONObject.parseObject(bodyStr);
String month = jsonObject.getString("month");
// 处理body参数
byte[] data = session.getAttribute("excel");
InputStream inputStream = new ByteArrayInputStream(data);
ExcelUtil.parse(inputStream);
Sheet sheet = ExcelUtil.getSheet(0);
List<RowData> rowDatas = ExcelUtil.getRowDatas(sheet, 0, ExcelUtil.MAX_IMPORT_ROW + 1);
if (CollectionUtils.isNotEmpty(rowDatas) && rowDatas.size() > 2) {
RowData columRowaData = rowDatas.get(2);
List<CellData> cells = columRowaData.getCells();
int empNameIndex = -1;
int workCodeIndex = -1;
for (CellData cell : cells) {
log.error((String) cell.getValue());
if ("工号".equals(cell.getValue())) {
log.error("工号所在列===" + JSON.toJSONString(cell));
workCodeIndex = cell.getIndex();
} else if ("人员".equals(cell.getValue())) {
log.error("人员所在列===" + JSON.toJSONString(cell));
empNameIndex = cell.getIndex();
}
}
if (workCodeIndex == -1) {
WeaResult<Object> fail = WeaResult.fail("未获取到[工号]列,请调整模板后再次尝试");
return JSON.toJSONString(fail);
}
String tenantKey = UserContext.getCurrentUser().getTenantKey();
for (int i = 3; i < rowDatas.size(); i++) {
RowData rowData = rowDatas.get(i);
List<CellData> dataCells = rowData.getCells();
String empName = dataCells.get(empNameIndex).getValue().toString();
String workCode = dataCells.get(workCodeIndex).getValue().toString();
log.error("empName===" + empName);
log.error("workCode===" + workCode);
Long employeeId;
if (StringUtils.isNotBlank(workCode) && !"-".equals(workCode)) {
List<SimpleEmployee> byJobNums = hrmCommonEmployeeDao.getByJobNums(Collections.singletonList(workCode), tenantKey);
if (CollectionUtils.isEmpty(byJobNums)) {
WeaResult<Object> fail = WeaResult.fail("" + i + "行未查询到对应人员,工号[" + workCode + "]");
return JSON.toJSONString(fail);
}
if (byJobNums.size() > 1) {
WeaResult<Object> fail = WeaResult.fail("" + i + "行工号不唯一,工号[" + workCode + "]");
return JSON.toJSONString(fail);
}
SimpleEmployee simpleEmployee = byJobNums.get(0);
employeeId = simpleEmployee.getEmployeeId();
} else {
List<SimpleEmployee> byUserNames = hrmCommonEmployeeDao.getByUserNames(Collections.singletonList(empName), tenantKey);
if (CollectionUtils.isEmpty(byUserNames)) {
WeaResult<Object> fail = WeaResult.fail("" + i + "行未查询到对应人员,人员[" + empName + "]");
return JSON.toJSONString(fail);
}
if (byUserNames.size() > 1) {
WeaResult<Object> fail = WeaResult.fail("" + i + "行人员不唯一,人员[" + empName + "]");
return JSON.toJSONString(fail);
}
SimpleEmployee simpleEmployee = byUserNames.get(0);
employeeId = simpleEmployee.getEmployeeId();
}
SchedulingStatusPo schedulingStatus = schedulingStatusMapper.getByCondition(tenantKey, employeeId, month);
if (schedulingStatus != null) {
if ("1".equals(schedulingStatus.getStatus())) {
WeaResult<Object> fail = WeaResult.fail("" + i + "行排班审核中,无法修改");
return JSON.toJSONString(fail);
} else if ("2".equals(schedulingStatus.getStatus())) {
WeaResult<Object> fail = WeaResult.fail("" + i + "行排班已审核,无法修改");
return JSON.toJSONString(fail);
}
}
}
}
log.error("bodyStr===" + bodyStr);
String resultStr = HttpRequest.post(url).headerMap(header, true).body(jsonObject.toJSONString()).execute().body();
log.error("resultStr===" + resultStr);
//3after callApi
JSONObject resultObj = JSON.parseObject(resultStr);
log.error("resultObj===" + resultObj);
return JSON.toJSONString(resultObj);
}
}