You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
7.3 KiB
Java
130 lines
7.3 KiB
Java
package weaver.haikang.cronjob;
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import com.weaver.file.Prop;
|
|
import weaver.conn.RecordSet;
|
|
import weaver.formmode.setup.ModeRightInfo;
|
|
import weaver.general.Util;
|
|
import weaver.integration.logging.Logger;
|
|
import weaver.integration.logging.LoggerFactory;
|
|
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
public class LeaveSummaryService {
|
|
private final Logger log = LoggerFactory.getLogger(LeaveSummaryService.class);
|
|
//销假申请表单
|
|
private static final String xjshtablename = Prop.getPropValue("leave_summary_cron","xjshtablename");
|
|
//销假申请表单明细
|
|
private static final String xjshtablenamemx = Prop.getPropValue("leave_summary_cron","xjshtablenamemx");
|
|
private static final String nianjia = Prop.getPropValue("leave_summary_cron","nianjia");
|
|
private static final String tiaoxiu = Prop.getPropValue("leave_summary_cron","tiaoxiu");
|
|
private static final String shijia = Prop.getPropValue("leave_summary_cron","shijia");
|
|
private static final String bingjia = Prop.getPropValue("leave_summary_cron","bingjia");
|
|
private static final String chanjia = Prop.getPropValue("leave_summary_cron","chanjia");
|
|
private static final String peichanjia = Prop.getPropValue("leave_summary_cron","peichanjia");
|
|
private static final String hunjia = Prop.getPropValue("leave_summary_cron","hunjia");
|
|
private static final String sangjia = Prop.getPropValue("leave_summary_cron","sangjia");
|
|
private static final String burujia = Prop.getPropValue("leave_summary_cron","burujia");
|
|
private static final String qjhztablename = Prop.getPropValue("leave_summary_cron","qjhztablename");
|
|
private static final String jmid = Prop.getPropValue("leave_summary_cron","jmid");
|
|
|
|
|
|
public synchronized void execute() {
|
|
log.error("定时任务:更新请假汇总begin");
|
|
RecordSet recordSeta = new RecordSet();
|
|
RecordSet recordSetb = new RecordSet();
|
|
RecordSet recordSetc = new RecordSet();
|
|
RecordSet recordSetd = new RecordSet();
|
|
RecordSet recordSete = new RecordSet();
|
|
//年份人员组合
|
|
String sql = "SELECT LEFT (a.fromdate, 4 ) AS YEAR, a.RESOURCEID, b.lastname, b.workcode FROM kq_flow_split_leave a inner join hrmresource b on a.resourceid = b.id GROUP BY YEAR, a.RESOURCEID";
|
|
log.error("定时任务-sql1:"+sql);
|
|
recordSeta.executeQuery(sql);
|
|
while (recordSeta.next()) {
|
|
//每一条代表一个记录
|
|
log.error(">>>>>>>>>>>>>>>>3>>>>>>>>>>>>>>>>>>>>>");
|
|
String year = recordSeta.getString("YEAR");
|
|
String RESOURCEID = recordSeta.getString("RESOURCEID");
|
|
String lastname = recordSeta.getString("lastname");
|
|
String workcode = recordSeta.getString("workcode");
|
|
Map<String,String> hoursrs = getHours(year,RESOURCEID,recordSete);
|
|
String sql3 = "select count(id) as sums from "+qjhztablename+" where xm = "+RESOURCEID+" and nf = '"+year+"'";
|
|
log.error(">>>>>>>>>>>>>>>>4>>>>>>>>>>>>>>>>>>>>>sql6:"+sql3);
|
|
recordSetb.executeQuery(sql3);
|
|
if(recordSetb.next()) {
|
|
log.error(">>>>>>>>>>>>>>>>>>>>>>>>>xxxxxx>>>>>>>>>>>>>>>>>>>>>>>>>");
|
|
int sums = recordSetb.getInt("sums");
|
|
String sql4 = "";
|
|
if(sums>0) {//更新
|
|
sql4 = "update "+qjhztablename+" set nj = ?,dx = ?,sqj = ?,bj = ?,cj = ?,pcj = ?,hj = ?,sj = ?,brj = ? where xm = "+RESOURCEID + " and nf = '"+year+"'";
|
|
log.error("定时任务-sql3:"+sql4);
|
|
recordSetc.executeUpdate(sql4,hoursrs.get(nianjia),hoursrs.get(tiaoxiu),hoursrs.get(shijia),hoursrs.get(bingjia),hoursrs.get(chanjia),hoursrs.get(peichanjia),hoursrs.get(hunjia),hoursrs.get(sangjia),hoursrs.get(burujia));
|
|
}else {//新增
|
|
sql4 = "INSERT INTO "+qjhztablename+"(gh,xm,nf,nj,dx,sqj,bj,cj,pcj,hj,sj,brj,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
|
log.error("定时任务-sql4:"+sql4);
|
|
recordSetc.executeUpdate(sql4,workcode,RESOURCEID,year,hoursrs.get(nianjia),hoursrs.get(tiaoxiu),hoursrs.get(shijia),hoursrs.get(bingjia),hoursrs.get(chanjia),hoursrs.get(peichanjia),
|
|
hoursrs.get(hunjia),hoursrs.get(sangjia),hoursrs.get(burujia),
|
|
jmid,"1","0", DateUtil.today(),DateUtil.formatTime(new Date())
|
|
);
|
|
|
|
String idSql = "SELECT max(id) as mid from "+qjhztablename+" order by id desc";
|
|
log.error("定时任务-sql5:"+idSql);
|
|
recordSetd.executeQuery(idSql);
|
|
String id = recordSetd.getString("mid");
|
|
// 权限重构
|
|
permissionReconstruction(Util.getIntValue(id));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//根据年份,人员id,请假类型获取时间
|
|
private Map<String,String> getHours(String year,String resourceid,RecordSet recordSete) {
|
|
log.error(">>>>>>>>>>>>>>>>2>>>>>>>>>>>>>>>>>>>>>");
|
|
String key = year+resourceid;
|
|
Map<String,String> rs = new HashMap<>();
|
|
//初始化
|
|
rs.put(nianjia,"0");
|
|
rs.put(tiaoxiu,"0");
|
|
rs.put(shijia,"0");
|
|
rs.put(bingjia,"0");
|
|
rs.put(chanjia,"0");
|
|
rs.put(peichanjia,"0");
|
|
rs.put(hunjia,"0");
|
|
rs.put(sangjia,"0");
|
|
rs.put(burujia,"0");
|
|
|
|
String insql = nianjia+","+tiaoxiu+","+","+shijia+","+","+bingjia+","+","+chanjia+","+","+peichanjia+","+","+hunjia+","+","+sangjia+","+burujia;
|
|
String sql = "SELECT c11.year, c11.RESOURCEID, c11.newleavetype, hours - IFNULL( hoursf, 0 ) AS hours FROM " +
|
|
"( SELECT * FROM ( SELECT LEFT ( fromdate, 4 ) AS YEAR, RESOURCEID, newleavetype, SUM( durationdb ) AS hours, " +
|
|
"concat( LEFT ( fromdate, 4 ), \"-\", newleavetype, \"-\", RESOURCEID ) AS cid FROM kq_flow_split_leave GROUP BY YEAR, " +
|
|
"RESOURCEID, newleavetype ) a11 LEFT JOIN ( SELECT a.detail_newLeaveType, LEFT ( a.detail_leavefromDate, 4 ) AS YEAR1, " +
|
|
"b.RESOURCEID AS RESOURCEID1, SUM( a.detail_duration ) AS hoursf, " +
|
|
"concat( LEFT ( a.detail_leavefromDate, 4 ), \"-\", a.detail_newLeaveType, \"-\", b.RESOURCEID ) AS cidf " +
|
|
"FROM "+xjshtablenamemx+" a INNER JOIN "+xjshtablename+" b ON a.mainid = b.id WHERE b.spzt = '1' GROUP BY " +
|
|
"YEAR1, RESOURCEID1, detail_newLeaveType ) b11 ON a11.cid = b11.cidf WHERE 1 = 1 and a11.year = '"+year+"' and a11.resourceid = '"+resourceid+"' ) c11 ";
|
|
log.error("定时任务-sql2:"+sql);
|
|
recordSete.executeQuery(sql);
|
|
while (recordSete.next()) {
|
|
String type = recordSete.getString("newleavetype");
|
|
Double hours = recordSete.getDouble("hours");
|
|
String hours1 = Double.toString(hours);
|
|
rs.put(type,hours1);
|
|
}
|
|
return rs;
|
|
}
|
|
|
|
/**
|
|
* 权限重构
|
|
* @param billId
|
|
*/
|
|
private void permissionReconstruction(int billId) {
|
|
ModeRightInfo ModeRightInfo = new ModeRightInfo();
|
|
ModeRightInfo.setNewRight(true);
|
|
ModeRightInfo.editModeDataShare(1, Util.getIntValue(jmid),billId);
|
|
}
|
|
|
|
}
|