%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.hrm.*" %>
<%@ page import="java.util.*" %>
<%@ page import="weaver.general.TimeUtil" %>
<%@ page import="com.alibaba.fastjson.JSON" %>
<%@ page import="com.engine.kq.service.KQReportService" %>
<%@ page import="com.engine.common.util.ServiceUtil" %>
<%@ page import="com.engine.kq.service.impl.KQReportServiceImpl" %>
<%@ page import="weaver.formmode.setup.ModeRightInfo" %>
<%@ page import="java.time.format.DateTimeFormatter" %>
<%@ page import="java.time.LocalDate" %>
<%@ page import="java.time.format.DateTimeParseException" %>
<%
int kqbbsd_formmodeid = Util.getIntValue(rs.getPropValue("wuyuan_hrminfo","kqbbsd_formmodeid"));
JSONObject data = new JSONObject();
User user = HrmUserVarify.getUser(request, response);
int userid = user.getUID();
//发起审批按钮
boolean flag = false;
String parmm = Util.null2String(request.getParameter("parmm"));
rs.writeLog("=============== kqConfirmMessage.jsp parmm ==================="+ parmm);
JSONObject jsonObject = JSONObject.parseObject(parmm);
rs.writeLog("=============== kqConfirmMessage.jsp jsonObject ==================="+ jsonObject);
Map params = jsonObject.toJavaObject(Map.class);
rs.writeLog("=============== kqConfirmMessage.jsp params ==================="+ params);
String sqlWhere = "";
JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data")));
String fromDate = Util.null2String(jsonObj.get("fromDate"));
String toDate = Util.null2String(jsonObj.get("toDate"));
String typeselect =Util.null2String(jsonObj.get("typeselect"));
String subCompanyId = Util.null2String(jsonObj.get("subCompanyId"));
String departmentId = Util.null2String(jsonObj.get("departmentId"));
String resourceId = Util.null2String(jsonObj.get("resourceId"));
String status = Util.null2String(jsonObj.get("status"));
if(status.length()>0){
if (!status.equals("8") && !status.equals("9")) {
sqlWhere += " and a.status = "+status+ "";
}else if (status.equals("8")) {
sqlWhere += " and (a.status = 0 or a.status = 1 or a.status = 2 or a.status = 3) ";
}
}
if(subCompanyId.length()>0){
sqlWhere +=" and b.subcompanyid in("+subCompanyId+") ";
}
if(departmentId.length()>0){
sqlWhere +=" and b.departmentid in("+departmentId+") ";
}
if(resourceId.length()>0){
sqlWhere +=" and b.resourceid in("+resourceId+") ";
}
if(typeselect.length()==0)typeselect = "3";
if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){
if(typeselect.equals("1")){
fromDate = TimeUtil.getCurrentDateString();
toDate = TimeUtil.getCurrentDateString();
}else{
fromDate = TimeUtil.getDateByOption(typeselect,"0");
toDate = TimeUtil.getDateByOption(typeselect,"1");
}
}
String deptids = "";
rs.executeQuery("select id from Matrixtable_2 where bmfzr in ("+ userid+")");
while(rs.next()){
String deptid = Util.null2String(rs.getString("id"));
deptids += deptid + ",";
}
if(deptids.endsWith(",")){
deptids = deptids.substring(0,deptids.length()-1);
}
Set deptSet = new HashSet<>();
rs1.executeQuery("select a.id,a.lastname,a.workcode,a.dsporder,b.resourceid,a.subcompanyid1 as subcompanyid,a.departmentid,a.jobtitle,case when b.sfqr='0' then '是' else '否' end as sfqr, " +
"b.kqdate " +
"from hrmresource a, kq_format_total b " +
"where a.id= b.resourceid and b.kqdate >='"+fromDate+"' and b.kqdate <='"+toDate+"' " +
"and a.loginid is not null and a.loginid<>'' and (a.status = 0 or a.status = 1 or a.status = 2 or a.status = 3) "+ sqlWhere);
while(rs1.next()){
String mxid = Util.null2String(rs1.getString("id"));
String kqdate = Util.null2String(rs1.getString("kqdate"));
String departmentid = Util.null2String(rs1.getString("departmentid"));
deptSet.add(departmentid);
flag = rst.executeUpdate("update kq_format_total set sfqr='0' where resourceid = ? and kqdate = ?",mxid,kqdate);
}
if(flag){
for(String deptid:deptids.split(",")) {
rs.executeQuery("select id from uf_kqbbsd where ksrq=? and bm=?", fromDate, deptid);
if (!rs.next()) {
String yearmonth = getMonthByDateStr(fromDate);
toDate = yearmonth + "-25";
//入库明细存档
String insertSql = " insert into uf_kqbbsd(ksrq,jsrq,bm,sfsd," +
"modedatacreater,modedatacreatedate,modedatacreatetime,formmodeid,modeuuid) " +
"values(?,?,?,?,?,?,?,?,?)";
String currentdate = TimeUtil.getCurrentDateString();
String currenttime = TimeUtil.getOnlyCurrentTimeString();
String uuid = UUID.randomUUID().toString();
boolean exeRes = rs1.executeUpdate(insertSql, fromDate, toDate, deptid, "0", userid, currentdate, currenttime, kqbbsd_formmodeid, uuid);
int billid = -1;
if (exeRes) {
//重构权限
rs2.executeQuery(" select id from uf_kqbbsd where modeuuid=? ", new Object[]{uuid});
rs2.next();
billid = rs2.getInt("id");
ModeRightInfo moderight = new ModeRightInfo();
moderight.editModeDataShare(userid, kqbbsd_formmodeid, billid);
}
}else{
String mxid = Util.null2String(rs.getString("id"));
rst.executeUpdate("update uf_kqbbsd set sfsd='0' where id=?",mxid);
}
}
}
data.put("flag",flag);
out.print(data.toJSONString());
%>
<%!
/**
* 获取日期字符串中的年月份
* @param dateString
* @return
*/
public static String getMonthByDateStr(String dateString){
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); // 定义日期格式
String result = "";
try {
// 解析日期字符串并获取LocalDate对象
LocalDate date = LocalDate.parse(dateString, formatter);
int year = date.getYear();
System.out.println(year);
// 获取月份(1代表1月,...,12代表12月)
int month = date.getMonthValue(); // 或者使用date.getMonth().getValue()也是可以的,两者效果相同
System.out.println("月份: " + month); // 输出4,因为4月是第4个月份
result += year+"-";
System.out.println(result);
if(month > 10){
result += ""+month;
}else{
result += "0"+month;
}
} catch (DateTimeParseException e) {
System.out.println("日期格式错误"); // 如果日期字符串格式不正确,将抛出异常并打印错误信息
}
return result;
}
private KQReportService getService(User user) {
return (KQReportService) ServiceUtil.getService(KQReportServiceImpl.class, user);
}
%>