diff --git a/.gitignore b/.gitignore index fb16b86..31e631b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ target/ /src/META-INF ### IntelliJ IDEA ### -/log \ No newline at end of file +/log +/build/ diff --git a/README.md b/README.md index aec01c4..1ea6409 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# secondev_zjzlt +# secondev-wugang-dxfeng -浙江浙旅投数字科技有限公司 \ No newline at end of file +华润武钢 \ No newline at end of file diff --git a/secondev-wugang-dxfeng.gradle b/secondev-wugang-dxfeng.gradle new file mode 100644 index 0000000..5c9b018 --- /dev/null +++ b/secondev-wugang-dxfeng.gradle @@ -0,0 +1,5 @@ +description = "子模块demo项目" + +dependencies { + // 子项目私有依赖添加 +} \ No newline at end of file diff --git a/src/main/java/com/weaver/seconddev/attend/action/AttendanceSchedulingArchiveAction.java b/src/main/java/com/weaver/seconddev/attend/action/AttendanceSchedulingArchiveAction.java new file mode 100644 index 0000000..ff37b94 --- /dev/null +++ b/src/main/java/com/weaver/seconddev/attend/action/AttendanceSchedulingArchiveAction.java @@ -0,0 +1,100 @@ +package com.weaver.seconddev.attend.action; + +import cn.hutool.core.convert.Convert; +import com.alibaba.fastjson.JSON; +import com.weaver.common.base.entity.result.WeaResult; +import com.weaver.esb.api.rpc.EsbServerlessRpcRemoteInterface; +import com.weaver.seconddev.attend.entity.po.PreSchedulingDetailPo; +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.workflow.common.entity.org.WeaUser; +import com.weaver.workflow.common.util.OrgUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2025/06/09 + * @version: 1.0 + */ +@Slf4j +@Service("attendanceSchedulingArchiveAction") +public class AttendanceSchedulingArchiveAction implements EsbServerlessRpcRemoteInterface { + @Autowired + AttendanceSchedulingMapper schedulingMapper; + + @Autowired + SchedulingStatusMapper schedulingStatusMapper; + + + @Override + public WeaResult> execute(Map params) { + try { + log.error("params=>20250610:{}", params); + + Long formDataId = Convert.toLong(params.get("requestId")); + Long employeeId = Convert.toLong(params.get("employeeId")); + log.error("employeeId:{}", employeeId); + WeaUser user = OrgUtil.getUser(employeeId); + String tenantKey = user.getTenantKey(); + + log.error("tenantKey:{}", tenantKey); + + List detailList = schedulingMapper.getDetailList(formDataId, tenantKey); + for (PreSchedulingDetailPo preSchedulingDetailPo : detailList) { + log.error("preSchedulingDetailPo===333>{}", preSchedulingDetailPo); + SchedulingStatusPo schedulingStatus = schedulingStatusMapper.getByCondition(tenantKey, Long.valueOf(preSchedulingDetailPo.getEmployeeId()), preSchedulingDetailPo.getMonth()); + log.error("schedulingStatus===>{}", schedulingStatus); + + if (null != schedulingStatus) { + log.error("===数据更新==="); + // 更新状态 + SchedulingStatusPo.buildBaseFields(schedulingStatus, true, user); + // 审批中 + schedulingStatus.setStatus("2"); + schedulingStatusMapper.updateStatusById(schedulingStatus.getId(), "2"); + log.error("===数据更新完成===>{}", JSON.toJSONString(schedulingStatus)); + } else { + log.error("===数据插入==="); + // 插入数据 + schedulingStatus = new SchedulingStatusPo(); + // 审批中 + schedulingStatus.setStatus("2"); + schedulingStatus.setMonth(preSchedulingDetailPo.getMonth()); + schedulingStatus.setEmployeeId(preSchedulingDetailPo.getEmployeeId()); + SchedulingStatusPo.buildBaseFields(schedulingStatus, false, user); + schedulingStatusMapper.addSchedulingStatus(schedulingStatus); + log.error("===数据插入完成===>{}", JSON.toJSONString(schedulingStatus)); + } + + } + + //String groupId = "weaver-ebuilder-app-service"; + //// String groupId = ""; + //String sql = "select t.id,form_data_id,ygid,ssyf from ft_ypbsp_mxb1 t where t.form_data_id='" + formDataId + "' and tenant_key = '" + tenantKey + "' and delete_type = 0"; + //log.error("sql:{}", sql); + //Map recordMap = new HashMap<>(); + //String sourceType = "LOGIC"; + // + //Map result = databaseUtils.execute(sourceType, groupId, sql); + //List> recordList = databaseUtils.getDataSourceList(result); + // + //for (Map record : recordList) { + // log.error("record===>{}", record); + // String id = Convert.toStr(record.get("id")); + //} + + log.error("formDataId:{}", formDataId); + return WeaResult.success(); + } catch (Throwable t) { // 改为捕获所有Throwable + log.error("执行异常", t); // 打印完整堆栈 + t.printStackTrace(); // 补充控制台输出 + return WeaResult.fail("操作失败111: " + t.getMessage()); + } + } +} diff --git a/src/main/java/com/weaver/seconddev/attend/action/AttendanceSchedulingSubmitAction.java b/src/main/java/com/weaver/seconddev/attend/action/AttendanceSchedulingSubmitAction.java new file mode 100644 index 0000000..dd89580 --- /dev/null +++ b/src/main/java/com/weaver/seconddev/attend/action/AttendanceSchedulingSubmitAction.java @@ -0,0 +1,109 @@ +package com.weaver.seconddev.attend.action; + +import cn.hutool.core.convert.Convert; +import com.alibaba.fastjson.JSON; +import com.weaver.common.base.entity.result.WeaResult; +import com.weaver.esb.api.rpc.EsbServerlessRpcRemoteInterface; +import com.weaver.seconddev.attend.entity.po.PreSchedulingDetailPo; +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.workflow.common.entity.org.WeaUser; +import com.weaver.workflow.common.util.OrgUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2025/06/09 + * @version: 1.0 + */ +@Slf4j +@Service("attendanceSchedulingSubmitAction") +public class AttendanceSchedulingSubmitAction implements EsbServerlessRpcRemoteInterface { + @Autowired + AttendanceSchedulingMapper schedulingMapper; + + @Autowired + SchedulingStatusMapper schedulingStatusMapper; + + @Override + public WeaResult> execute(Map params) { + try { + log.error("params=>20250610:{}", params); + + //用户employeeId + //Long employeeId = currentUser.getEmployeeId(); + //租户key + //String tenantKey = currentUser.getTenantKey(); + Long formDataId = Convert.toLong(params.get("requestId")); + Long employeeId = Convert.toLong(params.get("employeeId")); + log.error("employeeId:{}", employeeId); + WeaUser user = OrgUtil.getUser(employeeId); + String tenantKey1 = user.getTenantKey(); + //String tenantKey = "tva1v1at2z"; + String tenantKey = user.getTenantKey(); + + + + log.error("tenantKey:{}", tenantKey); + log.error("tenantKey1:{}", tenantKey1); + + List detailList = schedulingMapper.getDetailList(formDataId, tenantKey); + for (PreSchedulingDetailPo preSchedulingDetailPo : detailList) { + log.error("preSchedulingDetailPo===333>{}", preSchedulingDetailPo); + SchedulingStatusPo schedulingStatus = schedulingStatusMapper.getByCondition(tenantKey, Long.valueOf(preSchedulingDetailPo.getEmployeeId()), preSchedulingDetailPo.getMonth()); + log.error("schedulingStatus===>{}", schedulingStatus); + + if (null != schedulingStatus) { + log.error("===数据更新==="); + // 更新状态 + SchedulingStatusPo.buildBaseFields(schedulingStatus, true, user); + // 审批中 + schedulingStatus.setStatus("1"); + schedulingStatusMapper.updateStatusById(schedulingStatus.getId(), "1"); + log.error("===数据更新完成===>{}", JSON.toJSONString(schedulingStatus)); + } else { + log.error("===数据插入==="); + // 插入数据 + schedulingStatus = new SchedulingStatusPo(); + // 审批中 + schedulingStatus.setStatus("1"); + schedulingStatus.setMonth(preSchedulingDetailPo.getMonth()); + schedulingStatus.setEmployeeId(preSchedulingDetailPo.getEmployeeId()); + SchedulingStatusPo.buildBaseFields(schedulingStatus, false, user); + schedulingStatusMapper.addSchedulingStatus(schedulingStatus); + log.error("===数据插入完成===>{}", JSON.toJSONString(schedulingStatus)); + + } + + } + + //String groupId = "weaver-ebuilder-app-service"; + //// String groupId = ""; + //String sql = "select t.id,form_data_id,ygid,ssyf from ft_ypbsp_mxb1 t where t.form_data_id='" + formDataId + "' and tenant_key = '" + tenantKey + "' and delete_type = 0"; + //log.error("sql:{}", sql); + //Map recordMap = new HashMap<>(); + //String sourceType = "LOGIC"; + // + //Map result = databaseUtils.execute(sourceType, groupId, sql); + //List> recordList = databaseUtils.getDataSourceList(result); + // + //for (Map record : recordList) { + // log.error("record===>{}", record); + // String id = Convert.toStr(record.get("id")); + //} + + log.error("formDataId:{}", formDataId); + return WeaResult.success(); + } catch (Throwable t) { // 改为捕获所有Throwable + log.error("执行异常", t); // 打印完整堆栈 + t.printStackTrace(); // 补充控制台输出 + return WeaResult.fail("操作失败111: " + t.getMessage()); + } + } +} diff --git a/src/main/java/com/weaver/seconddev/attend/controller/AttendanceSchedulingController.java b/src/main/java/com/weaver/seconddev/attend/controller/AttendanceSchedulingController.java new file mode 100644 index 0000000..a3d604c --- /dev/null +++ b/src/main/java/com/weaver/seconddev/attend/controller/AttendanceSchedulingController.java @@ -0,0 +1,113 @@ +package com.weaver.seconddev.attend.controller; + +import cn.hutool.http.HttpRequest; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.weaver.common.authority.annotation.WeaPermission; +import com.weaver.common.base.entity.result.WeaResult; +import com.weaver.seconddev.attend.entity.po.SchedulingStatusPo; +import com.weaver.seconddev.attend.service.AttendanceSchedulingService; +import com.weaver.workflow.core.api.rest.flow.entity.operate.WfcRequestOperationResultDto; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.Map; + + +/** + * @author:dxfeng + * @createTime: 2025/06/05 + * @version: 1.0 + */ +@Slf4j +@RestController +@RequestMapping("/api/secondev/attendanceScheduling") +@WeaPermission(publicPermission = true) +public class AttendanceSchedulingController { + + @Autowired + AttendanceSchedulingService attendanceSchedulingService; + + @PostMapping("/dealSaveParams") + public WeaResult dealSaveParams( @RequestBody Map params) { + return attendanceSchedulingService.dealSaveParams(params); + } + + @PostMapping("/saveChoseFirstShiftSec") + public String saveChoseFirstShiftSec(@RequestHeader Map header, @RequestBody Map body) { + log.error("======saveChoseFirstShiftSec========="); + String result = ""; + + //1、before 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); + log.error("bodyStr===" + bodyStr); + String resultStr = HttpRequest.post(url).headerMap(header, true).body(bodyStr).execute().body(); + log.error("resultStr===" + resultStr); + //3、after callApi + //对返回的数据做加工 + JSONObject resultObj = JSON.parseObject(resultStr); + JSONObject data = resultObj.getJSONObject("data"); + + //for (Object o : data.getJSONArray("listDataGroup")) { + // JSONObject group = (JSONObject) o; + // group.put("typename", group.getString("typename") + "_二开"); + //} + + return JSON.toJSONString(resultObj); + + } + + public static String removeKeyFromJson(String jsonString, String keyToRemove) throws IOException { + // 创建 ObjectMapper 实例,用于处理 JSON 数据 + ObjectMapper objectMapper = new ObjectMapper(); + // 将 JSON 字符串解析为 JsonNode 对象 + JsonNode rootNode = objectMapper.readTree(jsonString); + + // 检查根节点是否为 ObjectNode + if (rootNode instanceof ObjectNode) { + ObjectNode objectNode = (ObjectNode) rootNode; + // 移除指定的 key + objectNode.remove(keyToRemove); + } + + // 将修改后的 JsonNode 对象转换为 JSON 字符串 + return objectMapper.writeValueAsString(rootNode); + } + + + @PostMapping("/createWorkFlow") + private WeaResult createWorkFlow(@RequestBody Map params) throws UnsupportedEncodingException { + return attendanceSchedulingService.createFlowV2(params); + } + + @PostMapping("/updateAttendStatus") + private WeaResult> updateAttendStatus(@RequestBody Map params) throws UnsupportedEncodingException { + return attendanceSchedulingService.updateAttendStatus(params); + } + + //@PostMapping("/batchGetAttendStatus") + //private WeaResult> batchGetAttendStatus(@RequestBody Map params) { + // return attendanceSchedulingService.batchGetAttendStatus(params); + //} + + @GetMapping("/getAttendStatus") + private WeaResult getAttendStatus(@RequestParam("empId") String empId, @RequestParam("month") String month) { + return attendanceSchedulingService.getAttendStatus(empId, month); + } + +} diff --git a/src/main/java/com/weaver/seconddev/attend/entity/po/PreSchedulingDetailPo.java b/src/main/java/com/weaver/seconddev/attend/entity/po/PreSchedulingDetailPo.java new file mode 100644 index 0000000..14dec82 --- /dev/null +++ b/src/main/java/com/weaver/seconddev/attend/entity/po/PreSchedulingDetailPo.java @@ -0,0 +1,23 @@ +package com.weaver.seconddev.attend.entity.po; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author:dxfeng + * @createTime: 2025/06/09 + * @version: 1.0 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PreSchedulingDetailPo { + private String id; + private String formDataId; + private String flowId; + private String employeeId; + private String month; +} diff --git a/src/main/java/com/weaver/seconddev/attend/entity/po/SchedulingStatusPo.java b/src/main/java/com/weaver/seconddev/attend/entity/po/SchedulingStatusPo.java new file mode 100644 index 0000000..29ccf64 --- /dev/null +++ b/src/main/java/com/weaver/seconddev/attend/entity/po/SchedulingStatusPo.java @@ -0,0 +1,70 @@ +package com.weaver.seconddev.attend.entity.po; + +import com.weaver.common.distribution.genid.IdGenerator; +import com.weaver.teams.security.user.User; +import com.weaver.workflow.common.entity.org.WeaUser; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * @author:dxfeng + * @createTime: 2025/06/10 + * @version: 1.0 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class SchedulingStatusPo extends UfBaseField { + private String month; + private String employeeId; + private String status; + + + /** + * 构建基础字段 + * + * @param schedulingStatus + * @param isUpdate + * @param user + */ + public static void buildBaseFields(SchedulingStatusPo schedulingStatus, boolean isUpdate, WeaUser user) { + if (isUpdate) { + schedulingStatus.setUpdater(user.getUserId()); + schedulingStatus.setUpdate_time(new Date()); + } else { + schedulingStatus.setId(IdGenerator.generate()); + schedulingStatus.setIs_flow("0"); + schedulingStatus.setFlow_id(""); + schedulingStatus.setData_status("1"); + schedulingStatus.setData_index("0"); + schedulingStatus.setData_index("0"); + schedulingStatus.setCreator(user.getUserId()); + schedulingStatus.setCreate_time(new Date()); + schedulingStatus.setDelete_type("0"); + schedulingStatus.setFt_status("0"); + schedulingStatus.setForm_data_id(schedulingStatus.getId()); + schedulingStatus.setTenant_key(user.getTenantKey()); + } + } + + public static void buildBaseFields(SchedulingStatusPo schedulingStatus, boolean isUpdate, User user) { + if (isUpdate) { + schedulingStatus.setUpdater(user.getUserId()); + schedulingStatus.setUpdate_time(new Date()); + } else { + schedulingStatus.setId(IdGenerator.generate()); + schedulingStatus.setIs_flow("0"); + schedulingStatus.setFlow_id(""); + schedulingStatus.setData_status("1"); + schedulingStatus.setData_index("0"); + schedulingStatus.setData_index("0"); + schedulingStatus.setCreator(user.getUserId()); + schedulingStatus.setCreate_time(new Date()); + schedulingStatus.setDelete_type("0"); + schedulingStatus.setFt_status("0"); + schedulingStatus.setForm_data_id(schedulingStatus.getId()); + schedulingStatus.setTenant_key(user.getTenantKey()); + } + } +} diff --git a/src/main/java/com/weaver/seconddev/attend/entity/po/UfBaseField.java b/src/main/java/com/weaver/seconddev/attend/entity/po/UfBaseField.java new file mode 100644 index 0000000..463eb28 --- /dev/null +++ b/src/main/java/com/weaver/seconddev/attend/entity/po/UfBaseField.java @@ -0,0 +1,27 @@ +package com.weaver.seconddev.attend.entity.po; + +import lombok.Data; + +import java.util.Date; + +/** + * @author:dxfeng + * @createTime: 2025/06/10 + * @version: 1.0 + */ +@Data +public class UfBaseField { + private Long id; + private String is_flow; + private String flow_id; + private String data_status; + private String data_index; + private Long creator; + private Date create_time; + private Long updater; + private Date update_time; + private String delete_type; + private String ft_status; + private Long form_data_id; + private String tenant_key; +} diff --git a/src/main/java/com/weaver/seconddev/attend/mapper/AttendanceSchedulingMapper.java b/src/main/java/com/weaver/seconddev/attend/mapper/AttendanceSchedulingMapper.java new file mode 100644 index 0000000..4b41a1f --- /dev/null +++ b/src/main/java/com/weaver/seconddev/attend/mapper/AttendanceSchedulingMapper.java @@ -0,0 +1,18 @@ +package com.weaver.seconddev.attend.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.weaver.seconddev.attend.entity.po.PreSchedulingDetailPo; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @author:dxfeng + * @createTime: 2025/06/09 + * @version: 1.0 + */ +@Mapper +public interface AttendanceSchedulingMapper extends BaseMapper { + List getDetailList(@Param("formDataId") Long formDataId, @Param("tenantKey") String tenantKey); +} diff --git a/src/main/java/com/weaver/seconddev/attend/mapper/SchedulingStatusMapper.java b/src/main/java/com/weaver/seconddev/attend/mapper/SchedulingStatusMapper.java new file mode 100644 index 0000000..fa69943 --- /dev/null +++ b/src/main/java/com/weaver/seconddev/attend/mapper/SchedulingStatusMapper.java @@ -0,0 +1,21 @@ +package com.weaver.seconddev.attend.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.weaver.seconddev.attend.entity.po.SchedulingStatusPo; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * @author:dxfeng + * @createTime: 2025/06/10 + * @version: 1.0 + */ +@Mapper +public interface SchedulingStatusMapper extends BaseMapper { + + SchedulingStatusPo getByCondition(@Param("tenantKey") String tenantKey,@Param("employeeId") Long employeeId,@Param("month") String month); + + void updateStatusById(@Param("id") Long id,@Param("status") String status); + + void addSchedulingStatus(SchedulingStatusPo schedulingStatusPo); +} diff --git a/src/main/java/com/weaver/seconddev/attend/service/AttendanceSchedulingService.java b/src/main/java/com/weaver/seconddev/attend/service/AttendanceSchedulingService.java new file mode 100644 index 0000000..c689ebe --- /dev/null +++ b/src/main/java/com/weaver/seconddev/attend/service/AttendanceSchedulingService.java @@ -0,0 +1,27 @@ +package com.weaver.seconddev.attend.service; + +import com.weaver.common.base.entity.result.WeaResult; +import com.weaver.seconddev.attend.entity.po.SchedulingStatusPo; +import com.weaver.workflow.core.api.rest.flow.entity.operate.WfcRequestOperationResultDto; + +import java.io.UnsupportedEncodingException; +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2025/06/06 + * @version: 1.0 + */ +public interface AttendanceSchedulingService { + WeaResult createFlowV2(Map params) throws UnsupportedEncodingException; + + WeaResult> updateAttendStatus(Map params); + + WeaResult getAttendStatus(String empId, String month); + + WeaResult> batchGetAttendStatus(Map params); + + WeaResult dealSaveParams(Map params); + + +} diff --git a/src/main/java/com/weaver/seconddev/attend/service/impl/AttendanceSchedulingServiceImpl.java b/src/main/java/com/weaver/seconddev/attend/service/impl/AttendanceSchedulingServiceImpl.java new file mode 100644 index 0000000..440897a --- /dev/null +++ b/src/main/java/com/weaver/seconddev/attend/service/impl/AttendanceSchedulingServiceImpl.java @@ -0,0 +1,324 @@ +package com.weaver.seconddev.attend.service.impl; + +import cn.hutool.core.convert.Convert; +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.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.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.security.context.UserContext; +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; +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.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.*; + +/** + * @author:dxfeng + * @createTime: 2025/06/06 + * @version: 1.0 + */ +@Slf4j +@Service +public class AttendanceSchedulingServiceImpl implements AttendanceSchedulingService { + + @RpcReference + private WfcRequestOperateRest wfcRequestOperateRest; + + @Autowired + AttendanceSchedulingMapper schedulingMapper; + + @Autowired + SchedulingStatusMapper schedulingStatusMapper; + + @Override + public WeaResult createFlowV2(Map params) throws UnsupportedEncodingException { + String workflowId = params.get("workflowId"); + String formId = params.get("formId"); + String detailData = params.get("detailData"); + String month = params.get("month"); + + WfcRequestOperateParamDataEntity wfcRequestOperateParamDataEntity = new WfcRequestOperateParamDataEntity(); + wfcRequestOperateParamDataEntity.setWorkflowId(Long.parseLong(workflowId)); + //String formId = "1134268904057012233"; + Map mainFieldsMap = new HashMap<>(); + mainFieldsMap.put("ssks", "1142076308540252161"); + mainFieldsMap.put("ssgs", "1142076308540252162"); + mainFieldsMap.put("tjrq", "1142076308540252163"); + mainFieldsMap.put("tjr", "1142076308540252164"); + + Map detailFieldsMap = new HashMap<>(); + detailFieldsMap.put("ygid", "1142426185342279681"); + detailFieldsMap.put("ssyf", "1142426185342279682"); + detailFieldsMap.put("ygxm", "1142076746702413826"); + detailFieldsMap.put("gw", "1142076746702413827"); + // 排班 + detailFieldsMap.put("1", "1142076746702413828"); + detailFieldsMap.put("2", "1142076746702413829"); + detailFieldsMap.put("3", "1142076772472217609"); + detailFieldsMap.put("4", "1142076772472217610"); + detailFieldsMap.put("5", "1142076772472217611"); + detailFieldsMap.put("6", "1142076772472217612"); + detailFieldsMap.put("7", "1142076772472217613"); + detailFieldsMap.put("8", "1142076978731311105"); + detailFieldsMap.put("9", "1142076978731311106"); + detailFieldsMap.put("10", "1142076978731311107"); + detailFieldsMap.put("11", "1142076978731311108"); + detailFieldsMap.put("12", "1142076978731311109"); + detailFieldsMap.put("13", "1142077030052814857"); + detailFieldsMap.put("14", "1142077030052814858"); + detailFieldsMap.put("15", "1142077030052814859"); + detailFieldsMap.put("16", "1142077030052814860"); + detailFieldsMap.put("17", "1142077030052814861"); + detailFieldsMap.put("18", "1142077030052814862"); + detailFieldsMap.put("19", "1142077030052814863"); + detailFieldsMap.put("20", "1142077030052814864"); + detailFieldsMap.put("21", "1142077030052814865"); + detailFieldsMap.put("22", "1142077030052814866"); + detailFieldsMap.put("23", "1142077094527655943"); + detailFieldsMap.put("24", "1142077094527655944"); + detailFieldsMap.put("25", "1142077094527655945"); + detailFieldsMap.put("26", "1142077094527655946"); + detailFieldsMap.put("27", "1142077094527655947"); + detailFieldsMap.put("28", "1142077098847789057"); + detailFieldsMap.put("29", "1142077098847789058"); + detailFieldsMap.put("30", "1142077098847789059"); + detailFieldsMap.put("31", "1142077098847789060"); + + + //表单字段集合 + List formDataDetailDtos = new ArrayList<>(); + + // 构建明细表数据 + String decode = URLDecoder.decode(detailData, "UTF-8"); + User currentUser = UserContext.getCurrentUser(); + + JSONArray detailDataArray = JSON.parseArray(decode); + for (int rorIndex = 0; rorIndex < detailDataArray.size(); rorIndex++) { + int rowNum = rorIndex + 1; + JSONObject detailRow = detailDataArray.getJSONObject(rorIndex); + String empId = detailRow.getString("empId"); + String employee = detailRow.getString("employee"); + String jobNo = detailRow.getString("jobNo"); + String position = detailRow.getString("position"); + + // TODO 判断数据是否可以提交 + SchedulingStatusPo byCondition = schedulingStatusMapper.getByCondition(currentUser.getTenantKey(), Long.valueOf(empId), month); + if (byCondition != null && ("1".equals(byCondition.getStatus()) || "2".equals(byCondition.getStatus()))) { + log.error("SchedulingStatusPo===跳过该条数据>{}", byCondition); + continue; + } + + + FormDataDetailDto empIdDetailDto = new FormDataDetailDto(); + empIdDetailDto.setFieldId(Long.valueOf(detailFieldsMap.get("ygid"))); + empIdDetailDto.setDataIndex((long) rowNum); + empIdDetailDto.setContent(empId); + formDataDetailDtos.add(empIdDetailDto); + + FormDataDetailDto employeeDetailDto = new FormDataDetailDto(); + employeeDetailDto.setFieldId(Long.valueOf(detailFieldsMap.get("ygxm"))); + employeeDetailDto.setDataIndex((long) rowNum); + employeeDetailDto.setContent(employee); + formDataDetailDtos.add(employeeDetailDto); + + // 岗位 + FormDataDetailDto jobNoDetailDto = new FormDataDetailDto(); + jobNoDetailDto.setFieldId(Long.valueOf(detailFieldsMap.get("gw"))); + jobNoDetailDto.setDataIndex((long) rowNum); + jobNoDetailDto.setContent(position); + formDataDetailDtos.add(jobNoDetailDto); + + // 所属月份 + FormDataDetailDto monthDetailDto = new FormDataDetailDto(); + monthDetailDto.setFieldId(Long.valueOf(detailFieldsMap.get("ssyf"))); + monthDetailDto.setDataIndex((long) rowNum); + monthDetailDto.setContent(month); + formDataDetailDtos.add(monthDetailDto); + + + // 处理班次字段 + JSONObject shifts = detailRow.getJSONObject("shifts"); + for (int i = 1; i <= 31; i++) { + FormDataDetailDto shiftDetailDto = new FormDataDetailDto(); + // 对应字段标识 + shiftDetailDto.setFieldId(Long.valueOf(detailFieldsMap.get(String.valueOf(i)))); + shiftDetailDto.setDataIndex((long) rowNum); + JSONArray shift = shifts.getJSONArray(String.valueOf(i)); + List shiftValueList = new ArrayList<>(); + List dataOptions = new ArrayList<>(); + for (Object shiftObj : shift) { + JSONObject shiftObjJson = (JSONObject) shiftObj; + log.error("shiftObjJson==" + JSON.toJSONString(shiftObjJson)); + FormDataOptionDto formDataOptionDto = new FormDataOptionDto(); + formDataOptionDto.setOptionId(shiftObjJson.getString("id")); + formDataOptionDto.setContent(shiftObjJson.getString("name")); + //formDataOptionDto.setContent(shiftObjJson.getString("id")); + formDataOptionDto.setType(ModuleSource.attendShift); + String shiftValue = shiftObjJson.getString("id"); + shiftValueList.add(shiftValue); + dataOptions.add(formDataOptionDto); + } + shiftDetailDto.setContent(StringUtils.join(shiftValueList, ",")); + //shiftDetailDto.setDataOptions(dataOptions); + log.error("[" + i + "]shiftDetailDto==" + JSON.toJSONString(shiftDetailDto)); + formDataDetailDtos.add(shiftDetailDto); + } + log.error("formDataDetailDtos==" + JSON.toJSONString(formDataDetailDtos)); + + // 插入数据到考勤排班状态表 + SchedulingStatusPo schedulingStatus = schedulingStatusMapper.getByCondition(currentUser.getTenantKey(), Long.valueOf(empId), month); + log.error("schedulingStatus===>{}", schedulingStatus); + + if (null != schedulingStatus) { + log.error("===数据更新==="); + // 更新状态 + SchedulingStatusPo.buildBaseFields(schedulingStatus, true, currentUser); + // 审批中 + schedulingStatus.setStatus("0"); + schedulingStatusMapper.updateStatusById(schedulingStatus.getId(), "0"); + log.error("===数据更新完成===>{}", JSON.toJSONString(schedulingStatus)); + } else { + log.error("===数据插入==="); + // 插入数据 + schedulingStatus = new SchedulingStatusPo(); + // 审批中 + schedulingStatus.setStatus("0"); + schedulingStatus.setMonth(month); + schedulingStatus.setEmployeeId(empId); + SchedulingStatusPo.buildBaseFields(schedulingStatus, false, currentUser); + schedulingStatusMapper.addSchedulingStatus(schedulingStatus); + log.error("===数据插入完成===>{}", JSON.toJSONString(schedulingStatus)); + } + + } + + if (CollectionUtils.isEmpty(formDataDetailDtos)) { + return WeaResult.fail("审批中、已审核的无法提交审核"); + } + + + //表单数据 + FormDataDto formDataDto = new FormDataDto(); + formDataDto.setFormId(Long.valueOf(formId)); + formDataDto.setDataDetails(formDataDetailDtos); + + //FormDataDtoParam formDataDtoParam = new FormDataDtoParam(); + //formDataDtoParam.setFormDataDtos(Arrays.asList(formDataDto)); + //formDataDtoParam.setFormId(Long.valueOf(formId)); + // + //WeaResult flow = + // wfcRequestOperateRest.createFlowV2(wfcRequestOperateParamDataEntity, UserContext.getCurrentUser(), formDataDtoParam); + + WeaResult flow = + wfcRequestOperateRest.createFlow(wfcRequestOperateParamDataEntity, UserContext.getCurrentUser(), formDataDto); + return flow; + + } + + @Override + public WeaResult> updateAttendStatus(Map params) { + try { + String detailData = params.get("detailData"); + String month = params.get("month"); + String decode = URLDecoder.decode(detailData, "UTF-8"); + User currentUser = UserContext.getCurrentUser(); + + JSONArray detailDataArray = JSON.parseArray(decode); + for (int rorIndex = 0; rorIndex < detailDataArray.size(); rorIndex++) { + JSONObject detailRow = detailDataArray.getJSONObject(rorIndex); + String empId = detailRow.getString("empId"); + // 插入数据到考勤排班状态表 + SchedulingStatusPo schedulingStatus = schedulingStatusMapper.getByCondition(currentUser.getTenantKey(), Long.valueOf(empId), month); + log.error("schedulingStatus===>{}", schedulingStatus); + + if (null != schedulingStatus) { + log.error("===数据更新==="); + // 更新状态 + SchedulingStatusPo.buildBaseFields(schedulingStatus, true, currentUser); + // 审批中 + schedulingStatus.setStatus("0"); + schedulingStatusMapper.updateStatusById(schedulingStatus.getId(), "3"); + log.error("===数据更新完成===>{}", JSON.toJSONString(schedulingStatus)); + } else { + log.error("===数据插入==="); + // 插入数据 + schedulingStatus = new SchedulingStatusPo(); + // 审批中 + schedulingStatus.setStatus("3"); + schedulingStatus.setMonth(month); + schedulingStatus.setEmployeeId(empId); + SchedulingStatusPo.buildBaseFields(schedulingStatus, false, currentUser); + schedulingStatusMapper.addSchedulingStatus(schedulingStatus); + log.error("===数据插入完成===>{}", JSON.toJSONString(schedulingStatus)); + } + } + return null; + } catch (Exception e) { + e.printStackTrace(); + return WeaResult.fail(e.getMessage()); + } + } + + @Override + public WeaResult getAttendStatus(String empId, String month) { + User currentUser = UserContext.getCurrentUser(); + SchedulingStatusPo schedulingStatus = schedulingStatusMapper.getByCondition(currentUser.getTenantKey(), Long.valueOf(empId), month); + return WeaResult.success(schedulingStatus); + } + + @Override + public WeaResult> batchGetAttendStatus(Map params) { + String empIds = Convert.toStr(params.get("empIds")); + String month = Convert.toStr(params.get("month")); + Map returnMap = new HashMap<>(); + String[] split = empIds.split(","); + for (String empId : split) { + SchedulingStatusPo schedulingStatus = schedulingStatusMapper.getByCondition(UserContext.getCurrentUser().getTenantKey(), Long.valueOf(empId), month); + returnMap.put(empId, schedulingStatus.getStatus()); + } + return WeaResult.success(returnMap); + } + + @Override + public WeaResult dealSaveParams(Map params) { + String selectedObjMap = Convert.toStr(params.get("selectedObjMap")); + String month = Convert.toStr(params.get("month")); + if (StringUtils.isBlank(selectedObjMap)) { + return WeaResult.success("{}"); + } + + // String转Map + Map selectedObjMapMap = JSON.parseObject(selectedObjMap, Map.class); + log.error("selectedObjMapMap===>{}", selectedObjMapMap); + Set keySet = selectedObjMapMap.keySet(); + Iterator iterator = keySet.iterator(); + while (iterator.hasNext()) { + String key = iterator.next(); + SchedulingStatusPo schedulingStatus = schedulingStatusMapper.getByCondition(UserContext.getCurrentUser().getTenantKey(), Long.valueOf(key), month); + if (schedulingStatus != null && ("1".equals(schedulingStatus.getStatus()) || "2".equals(schedulingStatus.getStatus()))) { + log.error("schedulingStatus===保存时不处理该条数据===>{}", schedulingStatus); + iterator.remove(); + } + } + + + return WeaResult.success(JSON.toJSONString(selectedObjMapMap)); + } +} diff --git a/src/main/resources/mapper/AttendanceSchedulingMapper.xml b/src/main/resources/mapper/AttendanceSchedulingMapper.xml new file mode 100644 index 0000000..72b28a5 --- /dev/null +++ b/src/main/resources/mapper/AttendanceSchedulingMapper.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + t.id,form_data_id,ygid,ssyf + + + + + diff --git a/src/main/resources/mapper/SchedulingStatusMapper.xml b/src/main/resources/mapper/SchedulingStatusMapper.xml new file mode 100644 index 0000000..8d92ff4 --- /dev/null +++ b/src/main/resources/mapper/SchedulingStatusMapper.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + t.id,ry,yf,zt + + + insert into uf_kqpbztb + (id,is_flow,data_status,data_index,creator,create_time,delete_type,ft_status,form_data_id,tenant_key,ry,yf,zt) + values + (#{id},0,1,0,#{creator},#{create_time},0,0,#{form_data_id},#{tenant_key},#{employeeId},#{month},#{status}) + + + update uf_kqpbztb t set zt = #{status} where id = #{id} + + + + + + +