Commit 452c13ee authored by zhuxiang's avatar zhuxiang
Browse files

增加绩效计算定时任务,每日八点执行

parent 1cdf589a
......@@ -67,7 +67,7 @@ public class ReportDataInfoController extends BaseController {
@GetMapping("/test")
public void test() {
reportDataInfoService.test();
reportDataInfoService.countPerformance();
}
}
......@@ -18,7 +18,7 @@ import java.util.List;
public interface ReportDataInfoService extends IService<ReportDataInfoEntity> {
List<ReportDataInfoVO> queryList(ReportDataInfoDTO reportDataInfoDTO);
void test();
void countPerformance();
boolean saveOrUpdateReportData(ReportDataInfoDTO reportDataInfoDTO);
}
......@@ -2,6 +2,7 @@ package com.ruzhoukj.sms.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.utils.StringUtils;
import com.ruzhoukj.sms.dao.ReportDataInfoDao;
......@@ -40,43 +41,47 @@ public class ReportDataInfoServiceImpl extends ServiceImpl<ReportDataInfoDao, Re
}
@Override
public void test() {
ReportDataInfoEntity reportDataInfoEntity = getById("1894302342735548417");
String content = reportDataInfoEntity.getAllContent();
// 解析JSON字符串为JSONArray
JSONArray jsonArray = JSONArray.parseArray(content);
// 获取第一个元素(假设第一个元素是Sheet1的数据)
if (jsonArray.size() > 0) {
JSONObject jsonObject = jsonArray.getJSONObject(0);
// 获取Sheet1中的data数组
JSONArray data = jsonObject.getJSONArray("data");
String totalScore = "0";
// 遍历data数组,从第6行开始
for (int i = 5; i < data.size(); i++) {
JSONArray row = data.getJSONArray(i);
JSONObject total = row.getJSONObject(0);
String totalStr = total.getString("v");
if (StringUtils.isNotEmpty(totalStr) && totalStr.contains("合计:")) {
JSONObject score = row.getJSONObject(11);
totalScore = score.getString("v");
break;
public void countPerformance() {
//查看已填写完成,未计算的绩效
List<ReportDataInfoEntity> reportDataInfoEntityList = baseMapper.selectList(new LambdaQueryWrapper<ReportDataInfoEntity>()
.eq(ReportDataInfoEntity::getStatus, 3));
reportDataInfoEntityList.forEach(reportDataInfoEntity -> {
String content = reportDataInfoEntity.getAllContent();
// 解析JSON字符串为JSONArray
JSONArray jsonArray = JSONArray.parseArray(content);
// 获取第一个元素(假设第一个元素是Sheet1的数据)
if (jsonArray.size() > 0) {
JSONObject jsonObject = jsonArray.getJSONObject(0);
// 获取Sheet1中的data数组
JSONArray data = jsonObject.getJSONArray("data");
String totalScore = "0";
// 遍历data数组,从第6行开始
for (int i = 5; i < data.size(); i++) {
JSONArray row = data.getJSONArray(i);
JSONObject total = row.getJSONObject(0);
String totalStr = total.getString("v");
if (StringUtils.isNotEmpty(totalStr) && totalStr.contains("合计:")) {
JSONObject score = row.getJSONObject(11);
totalScore = score.getString("v");
break;
}
}
if (!totalScore.equals("0")) {
//更新用户绩效分
UserPerformanceEntity userPerformanceEntity = new UserPerformanceEntity();
userPerformanceEntity.setUserId(reportDataInfoEntity.getUserId());
userPerformanceEntity.setPerformanceDate(reportDataInfoEntity.getYear(), reportDataInfoEntity.getMonth());
userPerformanceEntity.setPerformanceScore(totalScore);
userPerformanceEntity.setDeptId(reportDataInfoEntity.getDeptId());
userPerformanceEntity.setReportDataId(reportDataInfoEntity.getId());
userPerformanceService.save(userPerformanceEntity);
reportDataInfoEntity.setStatus("4");
reportDataInfoEntity.setId(reportDataInfoEntity.getId());
}
} else {
System.out.println("No data available in the JSON array.");
}
if (!totalScore.equals("0")) {
//更新用户绩效分
UserPerformanceEntity userPerformanceEntity = new UserPerformanceEntity();
userPerformanceEntity.setUserId(reportDataInfoEntity.getUserId());
userPerformanceEntity.setPerformanceDate(reportDataInfoEntity.getYear(), reportDataInfoEntity.getMonth());
userPerformanceEntity.setPerformanceScore(totalScore);
userPerformanceEntity.setDeptId(reportDataInfoEntity.getDeptId());
userPerformanceEntity.setReportDataId(reportDataInfoEntity.getId());
userPerformanceService.save(userPerformanceEntity);
reportDataInfoEntity.setStatus("4");
reportDataInfoEntity.setId(reportDataInfoEntity.getId());
}
} else {
System.out.println("No data available in the JSON array.");
}
});
}
/**
......
package com.ruzhoukj.sms.task;
import com.ruzhoukj.sms.service.ReportDataInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component
@Slf4j
public class PerformanceTask {
@Resource
private ReportDataInfoService reportDataInfoService;
//每天八点查询一次绩效
@Scheduled(cron = "0 0 20 * * ?")
private void performanceTask() {
reportDataInfoService.countPerformance();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment