|
@@ -10,7 +10,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.injector.methods.SelectById;
|
|
|
import com.management.platform.controller.WeiXinCorpController;
|
|
|
import com.management.platform.entity.*;
|
|
|
-import com.management.platform.entity.vo.TokenVo;
|
|
|
+import com.management.platform.entity.vo.*;
|
|
|
import com.management.platform.mapper.*;
|
|
|
import com.management.platform.service.*;
|
|
|
import com.management.platform.service.impl.WxCorpInfoServiceImpl;
|
|
@@ -113,6 +113,8 @@ public class TimingTask {
|
|
|
private ReportService reportService;
|
|
|
@Resource
|
|
|
private PlanExtraInfoService extraInfoService;
|
|
|
+ @Resource
|
|
|
+ private ApplyFormService applyFormService;
|
|
|
|
|
|
private static final List<Integer> VALID_TOKEN_CHARS = new ArrayList<>();
|
|
|
static {
|
|
@@ -1415,4 +1417,378 @@ public class TimingTask {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public void temporarilyApplyFormData(String endDate, String startDate, Integer templateType) throws Exception {
|
|
|
+ JSONArray jsonArrayFilter = new JSONArray();
|
|
|
+ JSONObject filter1 = new JSONObject();
|
|
|
+ WxCorpTemplate template = wxCorpTemplateService.getOne(new QueryWrapper<WxCorpTemplate>().eq("company_id",7).eq("type",templateType));//3:请假单;4:加班申请;(存在一张单据多人请假的情况)5:车间提前下班申请单 6考勤证明补卡单
|
|
|
+ filter1.put("key","template_id");
|
|
|
+ filter1.put("value",template.getTemplateId());
|
|
|
+ jsonArrayFilter.add(filter1);
|
|
|
+ JSONObject filter2 = new JSONObject();
|
|
|
+ filter2.put("key","sp_status");
|
|
|
+ filter2.put("value","2");
|
|
|
+ jsonArrayFilter.add(filter2);
|
|
|
+ List<String> approvalInfo = wxCorpInfoService.getApprovalInfo(7, startDate, endDate, "", jsonArrayFilter);
|
|
|
+
|
|
|
+ if(approvalInfo!=null&& !approvalInfo.isEmpty()){
|
|
|
+ for (int j = 0; j < approvalInfo.size(); j++) {
|
|
|
+ String codeNum = approvalInfo.get(j);
|
|
|
+ String approvalInfoDetailResp = wxCorpInfoService.getApprovalInfoDetail(7, codeNum);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(approvalInfoDetailResp);
|
|
|
+
|
|
|
+ if (templateType==3){
|
|
|
+ JSONObject info = jsonObject.getJSONObject("info");
|
|
|
+ String spNo = info.getString("sp_no");
|
|
|
+ ApplyForm applyForm = new ApplyForm();
|
|
|
+ int count = applyFormService.count(new QueryWrapper<ApplyForm>().eq("sp_no", spNo));
|
|
|
+ if (count==0){
|
|
|
+ String spName = info.getString("sp_name");
|
|
|
+ applyForm.setType(3);
|
|
|
+ applyForm.setTypeName(spName);
|
|
|
+ applyForm.setSpNo(spNo);
|
|
|
+ JSONObject applyer = info.getJSONObject("applyer");
|
|
|
+ String applyerId = applyer.getString("userid");
|
|
|
+ applyForm.setApplyId(applyerId);
|
|
|
+ JSONObject apply_data = info.getJSONObject("apply_data");
|
|
|
+ JSONArray contents = apply_data.getJSONArray("contents");
|
|
|
+
|
|
|
+ for (int i = 0; i < contents.size(); i++) {
|
|
|
+ JSONObject contentsJSONObject = contents.getJSONObject(i);
|
|
|
+ JSONArray title = contentsJSONObject.getJSONArray("title");
|
|
|
+ JSONObject value = contentsJSONObject.getJSONObject("value");
|
|
|
+ String control = contentsJSONObject.getString("control");
|
|
|
+
|
|
|
+
|
|
|
+ if (title.getJSONObject(0).getString("text").equals("请假类型")) {
|
|
|
+ if (control.equals("Vacation")) {
|
|
|
+ JSONObject selector = value.getJSONObject("vacation").getJSONObject("selector");
|
|
|
+ String type = selector.getString("type");
|
|
|
+
|
|
|
+ if (type.equals("single")) {
|
|
|
+ JSONObject leaveComment = selector.getJSONArray("options").getJSONObject(0).getJSONArray("value").getJSONObject(0);
|
|
|
+ String leaveName = leaveComment.getString("text");
|
|
|
+ applyForm.setApplyBillName(leaveName);
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject attendance = value.getJSONObject("vacation").getJSONObject("attendance");
|
|
|
+ long begin = attendance.getJSONObject("date_range").getLongValue("new_begin");
|
|
|
+ long end = attendance.getJSONObject("date_range").getLongValue("new_end");
|
|
|
+ long duration = attendance.getJSONObject("date_range").getLongValue("new_duration");
|
|
|
+
|
|
|
+ LocalDateTime startTime = Instant.ofEpochSecond(begin)
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
+ .toLocalDateTime();
|
|
|
+
|
|
|
+ LocalDateTime endTime = Instant.ofEpochSecond(end)
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
+ .toLocalDateTime();
|
|
|
+ // 1. 计算小时(秒 → 小时)
|
|
|
+ BigDecimal hours = BigDecimal.valueOf(duration)
|
|
|
+ .divide(BigDecimal.valueOf(3600), 1, RoundingMode.HALF_UP);
|
|
|
+ applyForm.setStartTime(startTime);
|
|
|
+ applyForm.setEndTime(endTime);
|
|
|
+ applyForm.setSumTime(hours);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (title.getJSONObject(0).getString("text").equals("请假事由")) {
|
|
|
+ if (control.equals("Textarea")) {
|
|
|
+ String leaveContent = value.getString("text");
|
|
|
+ applyForm.setContent(leaveContent);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ applyFormService.save(applyForm);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (templateType==4){
|
|
|
+ OverTimeVo overTimeVo = new OverTimeVo();
|
|
|
+ ArrayList<DeptVo> deptVoList = new ArrayList<>();
|
|
|
+ ArrayList<WorkVo> workVoList = new ArrayList<>();
|
|
|
+
|
|
|
+ JSONObject info = jsonObject.getJSONObject("info");
|
|
|
+ String spNo = info.getString("sp_no");
|
|
|
+ Integer spStatus = info.getInteger("sp_status");
|
|
|
+ String spName = info.getString("sp_name");
|
|
|
+ Long applyTime = info.getLongValue("apply_time");
|
|
|
+
|
|
|
+ overTimeVo.setSpNo(spNo);
|
|
|
+ int count = applyFormService.count(new QueryWrapper<ApplyForm>().eq("sp_no", spNo));
|
|
|
+ if (count>0){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ overTimeVo.setSpName(spName);
|
|
|
+ overTimeVo.setApplyTime(applyTime);
|
|
|
+ overTimeVo.setSpStatus(spStatus);
|
|
|
+
|
|
|
+ JSONObject applyer = info.getJSONObject("applyer");
|
|
|
+ String applyerId = applyer.getString("userid");
|
|
|
+
|
|
|
+ overTimeVo.setApplyId(applyerId);
|
|
|
+
|
|
|
+
|
|
|
+ JSONObject apply_data = info.getJSONObject("apply_data");
|
|
|
+ JSONArray contents = apply_data.getJSONArray("contents");
|
|
|
+
|
|
|
+ for (int i = 0; i < contents.size(); i++) {
|
|
|
+ JSONObject contentsJSONObject = contents.getJSONObject(i);
|
|
|
+ JSONArray title = contentsJSONObject.getJSONArray("title");
|
|
|
+ JSONObject value = contentsJSONObject.getJSONObject("value");
|
|
|
+ String control = contentsJSONObject.getString("control");
|
|
|
+
|
|
|
+
|
|
|
+ if(title.getJSONObject(0).getString("text").equals("部门(工位)")){
|
|
|
+ if(control.equals("Contact")){
|
|
|
+ JSONArray departmentJsons = value.getJSONArray("departments");
|
|
|
+ for (int i1 = 0; i1 < departmentJsons.size(); i1++) {
|
|
|
+ DeptVo deptVo = new DeptVo();
|
|
|
+ String dept_openapId = departmentJsons.getJSONObject(i1).getString("openapi_id");
|
|
|
+ String name = departmentJsons.getJSONObject(i1).getString("name");
|
|
|
+ deptVo.setDeptName(name);
|
|
|
+ deptVo.setDeptOpenapId(dept_openapId);
|
|
|
+ deptVoList.add(deptVo);
|
|
|
+ }
|
|
|
+ overTimeVo.setDeptList(deptVoList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(title.getJSONObject(0).getString("text").equals("填报日期")){
|
|
|
+ if(control.equals("Date")){
|
|
|
+ JSONObject dateJson = value.getJSONObject("date");
|
|
|
+ Long submitTime = dateJson.getLongValue("s_timestamp");
|
|
|
+ overTimeVo.setSubmitTime(submitTime);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(title.getJSONObject(0).getString("text").equals("明细")){
|
|
|
+ if(control.equals("Table")){
|
|
|
+ JSONArray childrens = value.getJSONArray("children");
|
|
|
+ for (int i1 = 0; i1 < childrens.size(); i1++) {
|
|
|
+ JSONArray list = childrens.getJSONObject(i1).getJSONArray("list");
|
|
|
+ WorkVo workVo = new WorkVo();
|
|
|
+ for (int i2 = 0; i2 < list.size(); i2++) {
|
|
|
+ JSONObject workMember = list.getJSONObject(i2);
|
|
|
+ //加班成员
|
|
|
+ if (workMember.getString("control").equals("Contact")&&workMember.getJSONArray("title").getJSONObject(0).getString("text").equals("加班成员")){
|
|
|
+ JSONObject workMemberJSONObjectValue = workMember.getJSONObject("value");
|
|
|
+ JSONArray members = workMemberJSONObjectValue.getJSONArray("members");
|
|
|
+ ArrayList<MemberVo> memberList = new ArrayList<>();
|
|
|
+ for (int i3 = 0; i3 < members.size(); i3++) {
|
|
|
+ MemberVo memberVo = new MemberVo();
|
|
|
+ String name = members.getJSONObject(i3).getString("name");
|
|
|
+ String userid = members.getJSONObject(i3).getString("userid");
|
|
|
+ memberVo.setMemberName(name);
|
|
|
+ memberVo.setMemberUserId(userid);
|
|
|
+ memberList.add(memberVo);
|
|
|
+ }
|
|
|
+ workVo.setMemberList(memberList);
|
|
|
+ }
|
|
|
+ //加班事由
|
|
|
+ if (workMember.getString("control").equals("Text")&&workMember.getJSONArray("title").getJSONObject(0).getString("text").equals("加班事由")){
|
|
|
+ JSONObject workMemberJSONObjectValue = workMember.getJSONObject("value");
|
|
|
+ String workCotent = workMemberJSONObjectValue.getString("text");
|
|
|
+ workVo.setWorkCotent(workCotent);
|
|
|
+ }
|
|
|
+ //加班时长
|
|
|
+ if (workMember.getString("control").equals("DateRange")&&workMember.getJSONArray("title").getJSONObject(0).getString("text").equals("加班时长")){
|
|
|
+ JSONObject workMemberJSONObjectValue = workMember.getJSONObject("value");
|
|
|
+ JSONObject workTime = workMemberJSONObjectValue.getJSONObject("date_range");
|
|
|
+ workVo.setDuration(workTime.getLongValue("new_duration"));
|
|
|
+ workVo.setBeginTime(workTime.getLongValue("new_begin"));
|
|
|
+ workVo.setEndTime(workTime.getLongValue("new_end"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ workVoList.add(workVo);
|
|
|
+ overTimeVo.setWorkVoList(workVoList);
|
|
|
+
|
|
|
+ List<WorkVo> workVos = overTimeVo.getWorkVoList();
|
|
|
+ ArrayList<ApplyForm> applyForms = new ArrayList<>();
|
|
|
+ for (WorkVo vo : workVos) {
|
|
|
+ String workCotent = vo.getWorkCotent();
|
|
|
+ Long beginTime = vo.getBeginTime();
|
|
|
+ Long endTime = vo.getEndTime();
|
|
|
+ Long duration = vo.getDuration();
|
|
|
+ LocalDateTime startTime = Instant.ofEpochSecond(beginTime)
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
+ .toLocalDateTime();
|
|
|
+
|
|
|
+ LocalDateTime end = Instant.ofEpochSecond(endTime)
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
+ .toLocalDateTime();
|
|
|
+ // 1. 计算小时(秒 → 小时)
|
|
|
+ BigDecimal hours = BigDecimal.valueOf(duration)
|
|
|
+ .divide(BigDecimal.valueOf(3600), 1, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+ List<MemberVo> memberList = vo.getMemberList();
|
|
|
+ for (MemberVo memberVo : memberList) {
|
|
|
+ ApplyForm applyForm = new ApplyForm();
|
|
|
+ applyForm.setStartTime(startTime);
|
|
|
+ applyForm.setEndTime(end);
|
|
|
+ applyForm.setSumTime(hours);
|
|
|
+ applyForm.setApplyId(memberVo.getMemberUserId());
|
|
|
+ applyForm.setContent(workCotent);
|
|
|
+ applyForm.setApplyBillName(overTimeVo.getLeaveName());
|
|
|
+ applyForm.setTypeName(spName);
|
|
|
+ applyForm.setSpNo(spNo);
|
|
|
+ applyForm.setType(4);
|
|
|
+ applyForms.add(applyForm);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ applyFormService.saveBatch(applyForms);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (templateType == 5) {
|
|
|
+ JSONObject info = jsonObject.getJSONObject("info");
|
|
|
+ String spNo = info.getString("sp_no");
|
|
|
+ int count = applyFormService.count(new QueryWrapper<ApplyForm>().eq("sp_no", spNo));
|
|
|
+ if (count>0){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Integer spStatus = info.getInteger("sp_status");
|
|
|
+ String spName = info.getString("sp_name");
|
|
|
+ Long applyTime = info.getLongValue("apply_time");
|
|
|
+
|
|
|
+ JSONObject apply_data = info.getJSONObject("apply_data");
|
|
|
+ JSONArray contents = apply_data.getJSONArray("contents");
|
|
|
+
|
|
|
+ ArrayList<String> applyIds = new ArrayList<>();//参与人的工号
|
|
|
+ StringJoiner joiner = new StringJoiner(",");//提前下班原因
|
|
|
+ long newDuration=0;
|
|
|
+ long newBegin=0;
|
|
|
+ long newEnd=0;
|
|
|
+
|
|
|
+ for (int i = 0; i < contents.size(); i++) {
|
|
|
+ JSONObject contentsJSONObject = contents.getJSONObject(i);
|
|
|
+ JSONArray title = contentsJSONObject.getJSONArray("title");
|
|
|
+ JSONObject value = contentsJSONObject.getJSONObject("value");
|
|
|
+ String control = contentsJSONObject.getString("control");
|
|
|
+
|
|
|
+ if (control.equals("Contact")&&title.getJSONObject(0).getString("text").contains("申请人")){
|
|
|
+ JSONArray members = value.getJSONArray("members");
|
|
|
+ for (int i1 = 0; i1 < members.size(); i1++) {
|
|
|
+ String userid = members.getJSONObject(i1).getString("userid");
|
|
|
+ applyIds.add(userid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (control.equals("Selector")&&title.getJSONObject(0).getString("text").contains("提前下班原因")){
|
|
|
+ JSONArray jsonArray = value.getJSONObject("selector").getJSONArray("options");
|
|
|
+ for (int i1 = 0; i1 < jsonArray.size(); i1++) {
|
|
|
+ JSONArray jsonArray1 = jsonArray.getJSONObject(i1).getJSONArray("value");
|
|
|
+ for (int i2 = 0; i2 < jsonArray1.size(); i2++) {
|
|
|
+ joiner.add(jsonArray1.getJSONObject(i2).getString("text"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (control.equals("DateRange")&&title.getJSONObject(0).getString("text").contains("提前下班时长")){
|
|
|
+ JSONObject jsonObject1 = value.getJSONObject("date_range");
|
|
|
+ newDuration = jsonObject1.getLongValue("new_duration");
|
|
|
+ newBegin = jsonObject1.getLongValue("new_begin");
|
|
|
+ newEnd = jsonObject1.getLongValue("new_end");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ArrayList<ApplyForm> list = new ArrayList<>();
|
|
|
+ for (String applyId : applyIds) {
|
|
|
+ ApplyForm applyForm = new ApplyForm();
|
|
|
+ applyForm.setType(5);
|
|
|
+ applyForm.setTypeName(spName);
|
|
|
+ applyForm.setApplyId(applyId);
|
|
|
+ applyForm.setSpNo(spNo);
|
|
|
+ applyForm.setContent(joiner.toString());
|
|
|
+ LocalDateTime startTime = Instant.ofEpochSecond(newBegin)
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
+ .toLocalDateTime();
|
|
|
+
|
|
|
+ LocalDateTime end = Instant.ofEpochSecond(newEnd)
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
+ .toLocalDateTime();
|
|
|
+ // 1. 计算小时(秒 → 小时)
|
|
|
+ BigDecimal hours = BigDecimal.valueOf(newDuration)
|
|
|
+ .divide(BigDecimal.valueOf(3600), 1, RoundingMode.HALF_UP);
|
|
|
+ applyForm.setStartTime(startTime);
|
|
|
+ applyForm.setEndTime(end);
|
|
|
+ applyForm.setSumTime(hours);
|
|
|
+ list.add(applyForm);
|
|
|
+ }
|
|
|
+ applyFormService.saveBatch(list);
|
|
|
+ }
|
|
|
+ else if (templateType == 6) {
|
|
|
+ JSONObject info = jsonObject.getJSONObject("info");
|
|
|
+ String spNo = info.getString("sp_no");
|
|
|
+ int count = applyFormService.count(new QueryWrapper<ApplyForm>().eq("sp_no", spNo));
|
|
|
+ if (count>0){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String spName = info.getString("sp_name");
|
|
|
+ JSONObject apply_data = info.getJSONObject("apply_data");
|
|
|
+ JSONArray contents = apply_data.getJSONArray("contents");
|
|
|
+
|
|
|
+ ArrayList<ApplyForm> list = new ArrayList<>();
|
|
|
+
|
|
|
+ for (int i = 0; i < contents.size(); i++) {
|
|
|
+ JSONObject contentsJSONObject = contents.getJSONObject(i);
|
|
|
+ JSONArray title = contentsJSONObject.getJSONArray("title");
|
|
|
+ JSONObject value = contentsJSONObject.getJSONObject("value");
|
|
|
+ String control = contentsJSONObject.getString("control");
|
|
|
+
|
|
|
+
|
|
|
+ if (control.equals("Table")&&title.getJSONObject(0).getString("text").equals("明细")){
|
|
|
+ JSONArray children = value.getJSONArray("children");
|
|
|
+ for (int i1 = 0; i1 < children.size(); i1++) {
|
|
|
+ JSONArray jsonArray = children.getJSONObject(i1).getJSONArray("list");
|
|
|
+ ArrayList<ApplyForm> subList = new ArrayList<>();
|
|
|
+ long longValue=0;
|
|
|
+ String content="";
|
|
|
+ for (int i2 = 0; i2 < jsonArray.size(); i2++) {
|
|
|
+ JSONObject jsonObject1 = jsonArray.getJSONObject(i2);
|
|
|
+ if (jsonObject1.getString("control").equals("Contact")&&jsonObject1.getJSONArray("title").getJSONObject(0).getString("text").equals("缺勤人员")){
|
|
|
+ JSONArray jsonArray1 = jsonObject1.getJSONObject("value").getJSONArray("members");
|
|
|
+ for (int i3 = 0; i3 < jsonArray1.size(); i3++) {
|
|
|
+ ApplyForm applyForm = new ApplyForm();
|
|
|
+ applyForm.setApplyId(jsonArray1.getJSONObject(i3).getString("userid"));
|
|
|
+ subList.add(applyForm);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (jsonObject1.getString("control").equals("Date")&&jsonObject1.getJSONArray("title").getJSONObject(0).getString("text").equals("缺勤日期")){
|
|
|
+ JSONObject jsonObject2 = jsonObject1.getJSONObject("value").getJSONObject("date");
|
|
|
+ longValue = jsonObject2.getLongValue("s_timestamp");
|
|
|
+ }
|
|
|
+ if (jsonObject1.getString("control").equals("Text")&&jsonObject1.getJSONArray("title").getJSONObject(0).getString("text").equals("缺勤原因")){
|
|
|
+ content = jsonObject1.getJSONObject("value").getString("text");
|
|
|
+ }
|
|
|
+ for (ApplyForm applyForm : subList) {
|
|
|
+ applyForm.setContent(content);
|
|
|
+ LocalDateTime startTime = Instant.ofEpochSecond(longValue)
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
+ .toLocalDateTime();
|
|
|
+ applyForm.setStartTime(startTime);
|
|
|
+ applyForm.setEndTime(startTime);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ list.addAll(subList);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ for (ApplyForm applyForm : list) {
|
|
|
+ applyForm.setType(6);
|
|
|
+ applyForm.setTypeName(spName);
|
|
|
+ applyForm.setSpNo(spNo);
|
|
|
+ }
|
|
|
+ applyFormService.saveBatch(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|