
import ComprehensiveWorkingHourServiceImpl.beforlog;
import com.engine.jucailinkq.attendance.attendanceanalysis.service.AttendanceSummaryService;
import com.engine.jucailinkq.attendance.attendanceanalysis.service.impl.AttendanceSummaryServiceImpl;
import com.engine.jucailinkq.attendance.enums.AccountingUnitEnum;
import com.engine.jucailinkq.attendance.workflow.enums.AskAndEvctionWayEnum;
import com.engine.jucailinkq.attendance.workflow.service.AllowanceService;
import com.engine.jucailinkq.attendance.workflow.service.MakeUpClockInService;
import com.engine.jucailinkq.attendance.workflow.service.impl.AllowanceServiceImpl;
import com.engine.jucailinkq.attendance.workflow.service.impl.MakeUpClockInServiceImpl;
import com.engine.common.util.*;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import org.junit.Test;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.interfaces.workflow.action.Action;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @Author: sy
 * @Description:
 * @Date: 2024/4/10
 **/
public class Tset_sy extends beforlog {
    @Test
    public void test() throws Exception {
        System.out.println("hello");
        User user = new User(Integer.parseInt("78"));
        user.setLanguage(7);

//        List<String> checkAmountJqIdList = CommonUtil.getJqInfoWithAmount();
//        //企业日历初始化
//        EnterpriseCalendarService getEnterpriseCalendarService = ServiceUtil.getService(EnterpriseCalendarServiceImpl.class);
//        Map<String,Object> param = Maps.newHashMap();
//        param.put("year","2030");
//        param.put("calendarId","6");
//        getEnterpriseCalendarService.initCalendar(param);

//        //生成津贴数据
//        AllowanceService getAllowanceService = ServiceUtil.getService(AllowanceServiceImpl.class);
//        Map<String,Object> param = Maps.newHashMap();
//        param.put("startDate","2024-06-17");
//        param.put("endDate","2024-06-17");
//        param.put("empIds", "81");
//        getAllowanceService.addAllowanceRecords(param);

        //出勤汇总浏览条件
//        AttendanceSummaryService getAttendanceSummaryService = ServiceUtil.getService(AttendanceSummaryServiceImpl.class, user);
//        Map<String, Object> cond = getAttendanceSummaryService.getCqSummarySearchCondition(null);
//        int i = 0;
//        //出勤汇总查询接口测试
//        AttendanceSummaryService getAttendanceSummaryService = ServiceUtil.getService(AttendanceSummaryServiceImpl.class, user);
//        Map<String,Object> param = Maps.newHashMap();
////        param.put("mainIds","2");
////        getAttendanceSummaryService.addAttendanceSummary(param);
//        param.put("data",
////                "{\"pageIndex\":1,\"typeselect\":\"3\",\"viewScope\":\"3\",\"resourceId\":\"31,32,82,22,36,38,30,29,56,28,37\",\"status\":\"8\",\"isNoAccount\":\"0\",\"attendanceSerial\":\"\"}");
////                "{\"pageIndex\":1,\"typeselect\":\"10\",\"viewScope\":\"0\",\"resourceId\":\"31\",\"status\":\"8\",\"isNoAccount\":\"0\",\"attendanceSerial\":\"\",\"pageSize\":100}");
//        "{\"pageIndex\":1,\"typeselect\":\"10\",\"viewScope\":\"0\",\"status\":\"8\",\"isNoAccount\":\"0\",\"attendanceSerial\":\"\",\"pageSize\":100}");
//
//        getAttendanceSummaryService.getCqSummaryReport(param);
        //新增出勤汇总数据接口测试
        AttendanceSummaryService getAttendanceSummaryService = ServiceUtil.getService(AttendanceSummaryServiceImpl.class, user);
        Map<String,Object> param1 = Maps.newHashMap();
        param1.put("mainIds","2");
        getAttendanceSummaryService.addAttendanceSummary(param1);
//        //出勤汇总明细数据列表查询接口测试
//        AttendanceSummaryService getAttendanceSummaryService = ServiceUtil.getService(AttendanceSummaryServiceImpl.class, user);
//        Map<String,Object> param = Maps.newHashMap();
//        param.put("mainId","2");
//        param.put("current","1");
//        param.put("pageSize","13");
//        param.put("empIds",null);
//        param.put("kqxmIds",null);
//        param.put("subCompanyIds",null);
//        param.put("depIds",null);
//        getAttendanceSummaryService.getCqSummaryDetailList(param);


//        //测试考勤项目浏览按钮
//        KqxmBrowserService getKqxmBrowserService = new KqxmBrowserService();
//        Map<String,Object> param = Maps.newHashMap();
//        param.put("selectids","126");
//
//        getKqxmBrowserService.getBrowserConditionInfo(param);

//        //企业日历初始化功能测试
//        Calendar calendar = Calendar.getInstance();
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//        // 使用SimpleDateFormat格式化Calendar中的日期
//        String formattedDate = sdf.format(calendar.getTime());
//        LunarCalendar lunarCalendar = new LunarCalendar(calendar);
//        Date date = lunarCalendar.getDate();
//        String cyclical = lunarCalendar.cyclical();
//        String animalsYear = lunarCalendar.animalsYear();
//        String traditionLunar = lunarCalendar.traditionLunarDay();
//        System.out.println(traditionLunar);
//
//        calendar.set(Calendar.YEAR, 2024);
//        calendar.set(Calendar.MONTH, Calendar.APRIL); // 注意月份从0开始，即0对应1月
//        calendar.set(Calendar.DATE, 4);
//        SolarTermsUtil solarTermsUtil = new SolarTermsUtil(calendar);
//        String termInfo = solarTermsUtil.getSolartermsMsg();
//        System.out.println(termInfo);

//        //请假流程提交校验action测试
//        MakeUpClockInService makeUpClockInService = ServiceUtil.getService(MakeUpClockInServiceImpl.class);
//        String requestid = "687693";
//        try {
//
//            // 流程表单主表数据
//            HashMap<String, String> mainTableData = new HashMap<>();
//
//            mainTableData.put("jqlx","147");mainTableData.put("cxjqj","1");mainTableData.put("qjzz","22");mainTableData.put("kssj","09:00");
//            mainTableData.put("jssj","18:00");mainTableData.put("szjg","21");mainTableData.put("qjry","27");mainTableData.put("sjqjlx","147");
//            mainTableData.put("ksrq","2024-05-13");mainTableData.put("scdw","0");mainTableData.put("mtcfsdjq","1");mainTableData.put("jsrq","2024-05-13");
//            mainTableData.put("id","22");mainTableData.put("qjsc","8");
//
////            mainTableData.put("jqlx","131");mainTableData.put("cxjqj","0");mainTableData.put("qjzz","14");mainTableData.put("kssj","09:00");
////            mainTableData.put("jssj","18:00");mainTableData.put("szjg","1");mainTableData.put("qjry","38");mainTableData.put("sjqjlx","131");
////            mainTableData.put("ksrq","2024-06-03");mainTableData.put("scdw","0");mainTableData.put("mtcfsdjq","1");mainTableData.put("jsrq","2024-06-06");
////            mainTableData.put("id","59");mainTableData.put("qjsc","4.00");
////            mainTableData.put("cxqj","0");
//
//
//            // 流程表单明细表1数据
//            List<Map<String, String>> detailTableData =new ArrayList<>();
//            Map<String, String> dmap = new HashMap<>();
//            dmap.put("cxqj","0");dmap.put("ksrq","2024-05-13");dmap.put("qtj","0");dmap.put("btj","0");dmap.put("id","521");
//            dmap.put("qjsc","8");
//            dmap.put("jssj","18:00");dmap.put("jsrq","2024-05-13");dmap.put("kssj","09:00");
//            detailTableData.add(dmap);
//            String detail2TableName = "formtable_main_53_dt2";
//
////            dmap.put("cxqj","0");dmap.put("ksrq","2024-06-03");dmap.put("qtj","1");dmap.put("btj","0");dmap.put("id","344");
//////            dmap.put("jssj","10:00");dmap.put("jsrq","2024-05-14");dmap.put("kssj","09:00");dmap.put("qjsc","1");
////            detailTableData.add(dmap);
////            dmap = new HashMap<>();
////            dmap.put("cxqj","0");dmap.put("ksrq","2024-06-04");dmap.put("qtj","1");dmap.put("btj","0");dmap.put("id","345");
////            detailTableData.add(dmap);
////            dmap = new HashMap<>();
////            dmap.put("cxqj","0");dmap.put("ksrq","2024-06-05");dmap.put("qtj","1");dmap.put("btj","0");dmap.put("id","346");
////            detailTableData.add(dmap);
////            dmap = new HashMap<>();
////            dmap.put("cxqj","0");dmap.put("ksrq","2024-06-06");dmap.put("qtj","1");dmap.put("btj","0");dmap.put("id","347");
////            detailTableData.add(dmap);
////            String detail2TableName = "formtable_main_153_dt2";
//
//            //请假人员
//            String qjry = mainTableData.get("qjry");
//            //实际假期类型
//            String jqlx = mainTableData.get("sjqjlx");
//            //需要校验假期额度的假期类型
//            List<String> checkAmountJqIdList = CommonUtil.getJqInfoWithAmount();
//            //第一笔开始时间
//            String firstStartDate = detailTableData.get(0).get("ksrq");
//
//            List<Map<String, Object>> detailTable2 = Lists.newArrayList();
//
//            /**
//             * 补打卡日期是否关账
//             */
//            Map<String, Object> params = Maps.newHashMap();
//            params.put("userId",qjry);
//            params.put("submitDate",DateUtil.getCurrentDate());
//            params.put("submitStr","ksrq");
//            params.put("submitDataList",detailTableData);
//            if (detailTableData == null || detailTableData.size() == 0){
//                System.out.println("明细表没有数据！");
//
//            }
//            Map<String,Object> dataMap = makeUpClockInService.getKqCycleTimeIntervalCmd(params);
//            List<Map<String,Object>> closeList = (List<Map<String,Object>>)dataMap.get("closeList");
//            List<String> nocycleList = (List<String>)dataMap.get("nocycleList");
//            List<Map<String,Object>> dateList = (List<Map<String,Object>>)dataMap.get("dataList");
//
//            boolean status = (boolean)dataMap.get("status");
//            if (!status){
//                System.out.println("该人员没有考勤周期");
//
//            }
//            if (closeList.size() > 0 || nocycleList.size() > 0){
//                String message = "";
//                if (nocycleList.size() > 0){
//                    message = message +String.join(",",nocycleList)+"未找对对应的考勤周期；";
//                }
//                if (closeList.size() > 0){
//                    List<String> list = closeList.stream().map(e->e.get("rq").toString()).collect(Collectors.toList());
//                    message = message +String.join(",",list)+"对应的考勤周期的考勤周期已关账";
//                }
//
//            }
//            /**
//             * 请假时长是否满足“请假类型”中单次最小休时长，由假期额度表和流程主表获取对比数据
//             */
//            String jqedSql = "select eddw, dczskxsc, edbxdcxw from uf_jcl_kq_jqed where jb = ?";
//            Map<String, Object> jqedInfo = DbTools.getSqlToMap(jqedSql, jqlx);
//            //假期额度的额度单位，0-天、1-小时
//            String eddw = Util.null2String(jqedInfo.get("eddw"));
//            String eddwValue = "";
//            //单次最小休时长
//            String minDuration = Util.null2String(jqedInfo.get("dczskxsc"));
//            //请假时长qjsc
//            String qjsc = Util.null2String(mainTableData.get("qjsc"));
//            //请假时长单位scdw，0-天、1-小时
//            String scdw = Util.null2String(mainTableData.get("scdw"));
//            String scdwValue = "";
//            if (!"".equals(eddw) && !"".equals(minDuration)) {
//                double minDurationValue = Double.parseDouble(minDuration);
//                if (eddw.equals(AccountingUnitEnum.DAY.getKey())) {
//                    minDurationValue = minDurationValue * 8;
//                    eddwValue = AccountingUnitEnum.DAY.getValue();
//                } else {
//                    eddwValue = AccountingUnitEnum.HOUR.getValue();
//                }
//                double qjscValue = "".equals(qjsc) ? 0 : Double.parseDouble(qjsc);
//                if (scdw.equals(AccountingUnitEnum.DAY.getKey())) {
//                    qjscValue = qjscValue * 8;
//                    scdwValue = AccountingUnitEnum.DAY.getValue();
//                } else {
//                    scdwValue = AccountingUnitEnum.HOUR.getValue();
//                }
//
//                if (Double.compare(minDurationValue, qjscValue) > 0) {
//                    String message = "请假时长" + qjsc + eddwValue + "，不能小于单次最小休时长" + minDuration + scdwValue;
//
//                }
//            }
//
//            /**
//             * 请假是否满足“请假类型”中单条请假余额可休次数要求，由假期额度表、假期余额表、请假记录表和流程主表获取对比数据
//             */
//            //先获取假期额度规则中指定假别的可休次数
//            String allowLeaveNumStr = Util.null2String(jqedInfo.get("edbxdcxw"));
//            String sql = "select id,jqid,sxrq,ktsc,yxsc,wxsc,yqsxrq,ztsc from uf_jcl_kq_jqye where ygid=? and jqid=? and sxrq<=? and yqsxrq>=? order by sxrq";
//            List<Map<String, Object>> holidayBalanceList = DbTools.getSqlToList(sql, qjry, jqlx, firstStartDate, firstStartDate);
//            if (!allowLeaveNumStr.equals("") && holidayBalanceList.size() > 0) {
//                //查询请假记录中，人员id+假期类别id情况下的结果，遍历每条主表数据下的明细数据中使用了哪些假期余额id
//                sql = "select a.id,dt2.jqye from uf_jcl_kq_qjjl a left join uf_jcl_kq_qjjl_dt1 dt1 on dt1.mainid = a.id left join uf_jcl_kq_qjjl_dt2 dt2 on dt2.glmxid = dt1.glmxid " +
//                        "where a.jqlx = " + jqlx + " and qjry = " + qjry + " and a.cxqj = 0  and a.jlzt in (0, 1) and dt1.cxqj = 0 and dt1.glmxid is not null";
//                List<Map<String, Object>> leaveList = DbTools.getSqlToList(sql);
//                Map<String, Integer> jqyeUseNumInfo = new HashMap<>();
//                List<String> leaveUseList = new ArrayList<>();
//                Integer useNum = 0;
//                for (Map<String, Object> leaveItem : leaveList) {
//                    String jqyeId = Util.null2String(leaveItem.get("jqye"));
//                    if (!"".equals(jqyeId)) {
//                        String leaveInfo = leaveItem.get("id").toString() + "_" + jqyeId;
//                        if (leaveUseList.size() == 0) {
//                            leaveUseList.add(leaveInfo);
//                            jqyeUseNumInfo.put(jqyeId, 1);
//                        } else if (!leaveUseList.contains(leaveInfo)) {
//                            leaveUseList.add(leaveInfo);
//                            useNum = jqyeUseNumInfo.get(jqyeId);
//                            jqyeUseNumInfo.put(jqyeId, useNum == null ? 1 : ++useNum);
//                        }
//                    }
//                }
//                //筛选次数未使用完的假期余额
//                holidayBalanceList = holidayBalanceList.stream().filter(f -> {
//                    int beforeUseNum = jqyeUseNumInfo.get(f.get("id").toString()) == null ? 0 : jqyeUseNumInfo.get(f.get("id").toString());
//                    return Integer.parseInt(allowLeaveNumStr) > beforeUseNum;
//                }).collect(Collectors.toList());
//
//                if (holidayBalanceList.size() == 0) {
//                    String message = "本次使用的假期类型下的假期余额可休次数不足！";
//
//                }
//
//            }
//
//            /**
//             * 假期校验及入库
//             */
////            String sql = "select id,jqid,sxrq,ktsc,yxsc,wxsc,yqsxrq,ztsc from uf_jcl_kq_jqye where ygid=? and jqid=? and sxrq<=? and yqsxrq>=? order by sxrq";
////            List<Map<String, Object>> holidayBalanceList = DbTools.getSqlToList(sql, qjry, jqlx, firstStartDate, firstStartDate);
//            Map<String, Object> holidayBalanceMap = holidayBalanceList.stream().collect(Collectors.toMap(e -> e.get("id").toString(), e -> e));
//            sql = "select id,mc,hsdw,hsl,jcbyxsyqjb,yxsydjb,qzsyyxjb  from uf_jcl_kq_kqxm  where id=?";
//            Map<String, Object> holidayItem = DbTools.getSqlToMap(sql, jqlx);
//            //当前假期类型需要校验剩余额度时则校验假期剩余额度，否则跳过校验
//            if (checkAmountJqIdList.contains(jqlx)) {
//                //假期核算单位
//                String hsdw = Util.null2String(holidayItem.get("hsdw"));
//                //请假方式
//                String cxjqj = mainTableData.get("cxjqj");
//
//                for (Map<String, String> detailData : detailTableData) {
//                    String ksrq = detailData.get("ksrq");
//                    //请假时间
//                    double leaveDuration = 0;
//                    if (cxjqj.equals(AskAndEvctionWayEnum.ALLDAY.getKey())) {
//                        leaveDuration = 1;
//                    } else if (cxjqj.equals(AskAndEvctionWayEnum.HALFDAY.getKey())) {
//                        leaveDuration = 0.5;
//                    } else if (cxjqj.equals(AskAndEvctionWayEnum.TIME_INTERVAL.getKey()) || cxjqj.equals(AskAndEvctionWayEnum.HOUR.getKey())) {
//                        leaveDuration = Double.valueOf(Util.null2String(detailData.get("qjsc")));
//                    }
//                    if (hsdw.equals(AccountingUnitEnum.HOUR.getKey()) && (cxjqj.equals(AskAndEvctionWayEnum.ALLDAY.getKey()) || cxjqj.equals(AskAndEvctionWayEnum.HALFDAY.getKey()))) {
//                        leaveDuration = leaveDuration * 8;
//                    }
//
////                    List<Map<String, Object>> holidayBalancefilterList = holidayBalanceList.stream().filter(e -> DateUtil.getTime(e.get("yqsxrq").toString()).compareTo(DateUtil.getTime(ksrq)) >= 0).collect(Collectors.toList());
//                    for (Map<String, Object> holidayBalance : holidayBalanceList) {
//                        //额定未休时长
//                        double wxsc = Util.null2String(holidayBalance.get("wxsc")).equals("") ? 0 : Double.valueOf(holidayBalance.get("wxsc").toString());
//                        if (leaveDuration > 0) {
//                            Map<String, Object> detail2Map = Maps.newHashMap();
//                            detail2Map.put("glmxid", detailData.get("id"));
//                            detail2Map.put("jqye", holidayBalance.get("id"));
//                            detail2Map.put("mainid", mainTableData.get("id"));
//                            detail2Map.put("glrq", detailData.get("ksrq"));
//                            if (leaveDuration > wxsc) {
//                                detail2Map.put("sysc", wxsc);
//                                leaveDuration = Utils.subtract(leaveDuration, wxsc);
//                                wxsc = 0;
//                            } else {
//                                detail2Map.put("sysc", leaveDuration);
//                                wxsc = Utils.subtract(wxsc, leaveDuration);
//                                leaveDuration = 0;
//                            }
//                            detailTable2.add(detail2Map);
//                            holidayBalance.put("wxsc", wxsc);
//                        }
//                    }
//                    if (leaveDuration > 0) {
//                        //假期余额不足
////                        String message = ksrq + "对应的" + holidayItem.get("mc") + "假期余额不足！";
//                        String message = holidayItem.get("mc") + "假期余额不足！";
//
//                    }
//                }
//
//
//                //更新流程明细表2
//                String delteSql = "delete from " + detail2TableName + " where mainid=?";
//                DbTools.update(delteSql, requestid);
//                if (detailTable2.size() > 0 && !CommonUtil.insertBatch(detailTable2, detail2TableName)) {
//                    //更新流程明细表2失败
//                    String message = "更新流程明细表2失败";
//
//                }
//
//                //更新假期余额在途时长
//                Map<String, Object> balanceMap = Maps.newHashMap();
//                for (Map<String, Object> data : detailTable2) {
//                    String jqye = Util.null2String(data.get("jqye"));
//                    double sysc = Double.valueOf(data.get("sysc").toString());
//                    double havedSysc = balanceMap.get(jqye) == null ? 0 : Double.valueOf(balanceMap.get(jqye).toString());
//                    sysc = Utils.add(sysc, havedSysc);
//                    balanceMap.put(jqye, sysc);
//                }
//                for (Map.Entry<String, Object> entry : balanceMap.entrySet()) {
//                    String id = entry.getKey();
//                    double ztsc = Double.valueOf(entry.getValue().toString());
//                    Map<String, Object> map = (Map<String, Object>) holidayBalanceMap.get(id);
//
//                    double havedztsc = Util.null2String(map.get("ztsc")).equals("") ? 0 : Double.valueOf(map.get("ztsc").toString());
//                    double havedwxsc = Util.null2String(map.get("wxsc")).equals("") ? 0 : Double.valueOf(map.get("wxsc").toString());
//
//                    double updatedztsc = Utils.add(havedztsc, ztsc);
//                    double updatedwxsc = Utils.subtract(havedwxsc, ztsc);
//
//                    String updateSql = "update uf_jcl_kq_jqye set wxsc=?,ztsc=? where id=?";
//                    if (!DbTools.update(updateSql, updatedwxsc, updatedztsc, id)) {
//                        //更新假期余额失败
//                        String message = "更新假期余额失败";
//
//                    }
//                }
//            }
//
//        }catch (Exception e){
//            System.out.println(e.getMessage());
//        }
//

    }
}
