Commit 26d94d75 by leialin

Merge branch 'lal' into 'develop'

提交

See merge request 8timerv2/8timerapiv200!500
parents 7be6b17c 762dedeb
......@@ -402,7 +402,12 @@
<version>1.4.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.sourceforge.htmlunit/htmlunit -->
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.43.0</version>
</dependency>
</dependencies>
<repositories>
......
package cn.timer.api.bean.kqmk;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author LAL 2020-09-22
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "kqmk_redletter_day")
@ApiModel("节假日")
public class KqmkRedletterDay extends Model<KqmkRedletterDay> {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@TableId(type = IdType.AUTO)
@ApiModelProperty(value = "id id", example = "101")
private Integer id;
@ApiModelProperty(value = "日期 ", example = "日期")
private String holiday;
@ApiModelProperty(value = "假日名称 ", example = "假日名称")
private String holidayName;
@ApiModelProperty(value = "是否为节假日(0:否;1:是) 是否为节假日(0:否;1:是)", example = "101")
private Integer holidayStatus;
@ApiModelProperty(value = "年月", example = "101")
private String belongYearmonth;
}
\ No newline at end of file
......@@ -30,6 +30,7 @@ import cn.timer.api.bean.kqmk.KqglAssoRelationSummary;
import cn.timer.api.bean.kqmk.KqglAssoTeshu;
import cn.timer.api.bean.kqmk.KqglAssoZhoupaiban;
import cn.timer.api.bean.kqmk.KqglMainKqz;
import cn.timer.api.bean.kqmk.KqmkRedletterDay;
import cn.timer.api.bean.qyzx.QyzxEntInfoM;
import cn.timer.api.bean.yggl.YgglMainLzb;
import cn.timer.api.controller.kqgl.ClockInController;
......@@ -130,9 +131,6 @@ public class LastMonthtimingExport {
.eq(YgglMainLzb::getEmpNum, user.getEmpnum()));
if(lzb == null) {//已离职 的人员不进入计算(已存在的不做任何处理)
// KqglAssoMonthPunchSummary.builder().build().delete(new QueryWrapper<KqglAssoMonthPunchSummary>().lambda().eq(KqglAssoMonthPunchSummary::getBelongYear, year)
// .eq(KqglAssoMonthPunchSummary::getBelongMonth, month).eq(KqglAssoMonthPunchSummary::getOrgCode, org_code));
KqglAssoMonthPunchSummary sum = KqglAssoMonthPunchSummary.builder().build().selectOne(new QueryWrapper<KqglAssoMonthPunchSummary>().lambda().eq(KqglAssoMonthPunchSummary::getOrgCode, org_code)
.eq(KqglAssoMonthPunchSummary::getBelongYear, year).eq(KqglAssoMonthPunchSummary::getBelongMonth, month).eq(KqglAssoMonthPunchSummary::getNum, user.getEmpnum()));
......@@ -215,6 +213,7 @@ public class LastMonthtimingExport {
// .eq(KqglAssoMonthPunchSummary::getNum, user.getEmpnum()).eq(KqglAssoMonthPunchSummary::getOrgCode, org_code));
String[] ycqts = new String[31];//应上班的具体天数(yyyy-MM-dd)
String[] xxts = new String[31];//休息的具体天数(yyyy-MM-dd)
String[] fdxx = new String[10];//法定休息的具体天数(yyyy-MM-dd)
List<String> rowData = new ArrayList<String>();
//休息天数,应出勤天数,实际出勤
double daysOff = 0,daysOnDuty = 0;//,actualAttDays = 0;
......@@ -261,9 +260,19 @@ public class LastMonthtimingExport {
needfig[e] = String.valueOf(awek.getType());//获取设置的应打卡周几
e++;
}
//法定節假日
List<KqmkRedletterDay> etter = KqmkRedletterDay.builder().build().selectList(new QueryWrapper<KqmkRedletterDay>().lambda().eq(KqmkRedletterDay::getHolidayStatus, 1).eq(KqmkRedletterDay::getBelongYearmonth, ttstr));
String[] holidays = new String[etter.size()];//法定节假日沦为休息日计算
int h = 0;
for(KqmkRedletterDay spe:etter){
holidays[h] = spe.getHoliday();
h++;
}
String yemo = year + "-" + month;
sdf1.setLenient(false);
int y = 0,q = 0;
int y = 0,q = 0,jj = 0;//jj:节假日
for(int i = 1; i <= ClockInTool.getDaysByYearMonth(year,month); i++){
Date date1 = sdf1.parse(yemo + "-" + i);
for(int u=0;u<week.length;u++){
......@@ -273,11 +282,18 @@ public class LastMonthtimingExport {
if(Arrays.asList(appmaps).contains(String.valueOf(sdf1.format(date1)))){
y = y-1;
}
if(attgro.getIsFdjjr().equals(1)) {
if(Arrays.asList(holidays).contains(String.valueOf(sdf1.format(date1)))){
y = y-1;
jj ++;
}
}
}
}
}
//全月时间 - 应打卡时间 - 必须打卡时间 + 无需打卡时间
int xiuxi = ClockInTool.getDaysByYearMonth(year,month) - q - bxdk + wxdk.size();
int xiuxi = ClockInTool.getDaysByYearMonth(year,month) - q - bxdk + wxdk.size()+jj;
daysOff = xiuxi;
daysOnDuty = y+bxdk;
// String[] range=ClockInTool.listToString(ClockInTool.getDays(sdf1.format(c.getTime()),str)).split(";");//目前为止所有日期
......@@ -285,6 +301,7 @@ public class LastMonthtimingExport {
//目前为止应出勤天数
int w = 0,x=0;
int zj = 6;
int fd = 0;
for(String num : range) {
if(ClockInTool.useArrayUtils(needfig, String.valueOf(ClockInTool.dateToWeek(num)))) {//对比排班应打卡时间
String[] ycqtst = new String[ycqts.length + zj];
......@@ -327,6 +344,30 @@ public class LastMonthtimingExport {
xxts = xxtst;
x++;
}
//当前考勤组开启法定节假日休息开关
if(attgro.getIsFdjjr().equals(1)) {
//法定节假日
if(ClockInTool.useArrayUtils(holidays, num)) {//法定节假日沦为休息日计算
// ycqts = ClockInTool.doChinFilters(ClockInTool.deleteArrayNull(ycqts), num);//为必须休息的话从上班日期中去除
if(ClockInTool.doChinFilters(ClockInTool.deleteArrayNull(ycqts), num) != null) {
ycqts = ClockInTool.doChinFilters(ClockInTool.deleteArrayNull(ycqts), num);//为必须休息的话从上班日期中去除
}
fdxx[fd] = num;
fd ++;
zjgzts = zjgzts - 1;
String[] xxtst = new String[xxts.length + zj];
System.arraycopy(xxts, 0, xxtst, 0, xxts.length);
xxtst[x] = num;
xxts = xxtst;
x++;
}
}
}
}else if(attgro.getPbfs() == 2){ //自由排班
DateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
......@@ -488,8 +529,10 @@ public class LastMonthtimingExport {
String sjs = "",qinjia = "",chuaca = "",waichu = "",buka = "",jiaban = "";
if(ClockInTool.useArrayUtils(ClockInTool.deleteArrayNull(xxts), num) && ClockInTool.useArrayUtils(ClockInTool.deleteArrayNull(dkjtts),num)) {
rowData.add("休息并打卡");
}else if(ClockInTool.useArrayUtils(ClockInTool.deleteArrayNull(xxts), num)){
}else if(ClockInTool.useArrayUtils(ClockInTool.deleteArrayNull(xxts), num) && !ClockInTool.useArrayUtils(ClockInTool.deleteArrayNull(fdxx), num)){
rowData.add("休息");
}else if(ClockInTool.useArrayUtils(ClockInTool.deleteArrayNull(fdxx), num)){
rowData.add("法定节假日休息");
}else {
if(ClockInTool.useArrayUtils(ClockInTool.deleteArrayNull(ycqts), num) && !ClockInTool.useArrayUtils(ClockInTool.deleteArrayNull(dkjtts), num) && !ClockInTool.useArrayUtils(ClockInTool.deleteArrayNull(leaves), num) && !ClockInTool.useArrayUtils(ClockInTool.deleteArrayNull(travels), num) && !ClockInTool.useArrayUtils(ClockInTool.deleteArrayNull(goouts), num) && !ClockInTool.useArrayUtils(ClockInTool.deleteArrayNull(cards), num)) {
rowData.add("旷工");
......
package cn.timer.api.controller.kqgl.holiday;
import java.util.Date;
public class ChinaDate {
/**
* 公历时间
*/
private Date solarDate;
/**
* 农历日
*/
private String lunar;
/**
* 公历日
*/
private String solar;
/**
* 是否是 休
*/
private boolean isVacation = false;
/**
* 如果是 休情况下的假期名字
*/
private String VacationName = "非假期";
/**
* 是否是 班
*/
private boolean isWorkFlag = false;
private boolean isSaturday = false;
private boolean isSunday = false;
/**
* @return the solarDate
*/
public Date getSolarDate() {
return solarDate;
}
/**
* @param solarDate the solarDate to set
*/
public void setSolarDate(Date solarDate) {
this.solarDate = solarDate;
}
/**
* @return the lunar
*/
public String getLunar() {
return lunar;
}
/**
* @param lunar the lunar to set
*/
public void setLunar(String lunar) {
this.lunar = lunar;
}
/**
* @return the solar
*/
public String getSolar() {
return solar;
}
/**
* @param solar the solar to set
*/
public void setSolar(String solar) {
this.solar = solar;
}
/**
* @return the isVacation
*/
public boolean isVacation() {
return isVacation;
}
/**
* @param isVacation the isVacation to set
*/
public void setVacation(boolean isVacation) {
this.isVacation = isVacation;
}
/**
* @return the vacationName
*/
public String getVacationName() {
return VacationName;
}
/**
* @param vacationName the vacationName to set
*/
public void setVacationName(String vacationName) {
VacationName = vacationName;
}
/**
* @return the isWorkFlag
*/
public boolean isWorkFlag() {
return isWorkFlag;
}
/**
* @param isWorkFlag the isWorkFlag to set
*/
public void setWorkFlag(boolean isWorkFlag) {
this.isWorkFlag = isWorkFlag;
}
/**
* @return the isSaturday
*/
public boolean isSaturday() {
return isSaturday;
}
/**
* @param isSaturday the isSaturday to set
*/
public void setSaturday(boolean isSaturday) {
this.isSaturday = isSaturday;
}
/**
* @return the isSunday
*/
public boolean isSunday() {
return isSunday;
}
/**
* @param isSunday the isSunday to set
*/
public void setSunday(boolean isSunday) {
this.isSunday = isSunday;
}
}
\ No newline at end of file
package cn.timer.api.controller.kqgl.holiday;
import java.io.IOException;
import java.net.MalformedURLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.DomNodeList;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import cn.timer.api.bean.kqmk.KqmkRedletterDay;
import cn.timer.api.dao.kqmk.KqmkRedletterDayMapper;
public class Main {
private static String latestVocationName = "";
public String getVocationName(DomNodeList<HtmlElement> htmlElements, String date) throws ParseException {
String rst = "";
boolean pastTimeFlag = false;
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date paramDate = dateFormat.parse(date);
if (new Date().getTime() >= paramDate.getTime()) {
pastTimeFlag = true;
}
//first step //jugde if can get vocation name from html page
for (int i = 0; i < htmlElements.size(); i++) {
HtmlElement element = htmlElements.get(i);
if (element.getAttribute("class").indexOf("vacation") != -1) {
boolean hitFlag = false;
String voationName = "";
for (; i < htmlElements.size(); i++) {
HtmlElement elementTmp = htmlElements.get(i);
String liDate = elementTmp.getAttribute("date");
List<HtmlElement> lunar = elementTmp.getElementsByAttribute("span", "class", "lunar");
String lanarText = lunar.get(0).asText();
if (lanarText.equals("元旦")) {
voationName = "元旦";
} else if (lanarText.equals("除夕") || lanarText.equals("春节")) {
voationName = "春节";
} else if (lanarText.equals("清明")) {
voationName = "清明";
} else if (lanarText.equals("国际劳动节")) {
voationName = "国际劳动节";
} else if (lanarText.equals("端午节")) {
voationName = "端午节";
} else if (lanarText.equals("中秋节")) {
voationName = "中秋节";
} else if (lanarText.equals("国庆节")) {
voationName = "国庆节";
}
if (liDate.equals(date)) {
hitFlag = true;
}
if (elementTmp.getAttribute("class").indexOf("vacation") == -1) {
break;
}
}
if (hitFlag == true && !voationName.equals("")) {
rst = voationName;
break;
}
} else {
continue;
}
}
//if first step fail(rarely), get from the latest Vocation name
if (rst.equals("")) {
System.out.println("warning: fail to get vocation name from html page.");
//you can judge by some simple rule
//from the latest Vocation name
rst = Main.latestVocationName;
} else if (pastTimeFlag == true) {
//更新《当前时间,且最近一次的可见的假期名
Main.latestVocationName = rst;
}
return rst;
}
public List<ChinaDate> getCurrentDateInfo() {
WebClient webClient = null;
List<ChinaDate> dateList = null;
try {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
dateList = new ArrayList<ChinaDate>();
webClient = new WebClient();
HtmlPage page = webClient.getPage("http://hao.360.cn/rili/");
//最大等待60秒
for (int k = 0; k < 60; k++) {
if (!page.getElementById("M-dates").asText().equals(""))
break;
Thread.sleep(1000);
}
//睡了8秒,等待页面加载完成...,有时候,页面可能获取不到,不稳定()
//Thread.sleep(8000);
DomNodeList<HtmlElement> htmlElements = page.getElementById("M-dates").getElementsByTagName("li");
//System.out.println(htmlElements.size());
for (HtmlElement element : htmlElements) {
ChinaDate chinaDate = new ChinaDate();
List<HtmlElement> lunar = element.getElementsByAttribute("span", "class", "lunar");
List<HtmlElement> solar = element.getElementsByAttribute("div", "class", "solar");
chinaDate.setLunar(lunar.get(0).asText());
chinaDate.setSolar(solar.get(0).asText());
chinaDate.setSolarDate(dateFormat.parse(element.getAttribute("date")));
if (element.getAttribute("class").indexOf("vacation") != -1) {
chinaDate.setVacation(true);
chinaDate.setVacationName(this.getVocationName(htmlElements, element.getAttribute("date")));
}
if (element.getAttribute("class").indexOf("weekend") != -1
&& element.getAttribute("class").indexOf("last") == -1) {
chinaDate.setSaturday(true);
}
if (element.getAttribute("class").indexOf("last weekend") != -1) {
chinaDate.setSunday(true);
}
if (element.getAttribute("class").indexOf("work") != -1) {
chinaDate.setWorkFlag(true);
} else if (chinaDate.isSaturday() == false && chinaDate.isSunday() == false
&& chinaDate.isVacation() == false) {
chinaDate.setWorkFlag(true);
} else {
chinaDate.setWorkFlag(false);
}
dateList.add(chinaDate);
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("get date from http://hao.360.cn/rili/ error~");
} finally {
webClient.close();
}
return dateList;
}
public ChinaDate getTodayInfo() {
List<ChinaDate> dateList = this.getCurrentDateInfo();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
for (ChinaDate date : dateList) {
if (dateFormat.format(date.getSolarDate()).equals(dateFormat.format(new Date()))) {
return date;
}
}
return new ChinaDate();
}
public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException, InterruptedException {
List<ChinaDate> dateList = new Main().getCurrentDateInfo();
ChinaDate today = new Main().getTodayInfo();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
System.out.println("本月详情:");
String yymm = new SimpleDateFormat("yyyy-MM").format(new Date()).toString();//
for (ChinaDate date : dateList) {
// System.out.println(dateFormat.format(date.getSolarDate()) + " " + date.getVacationName());
// System.out.println(dateFormat.format(date.getSolarDate()).replaceAll("/", "-") + " " + date.getVacationName());
String str = dateFormat.format(date.getSolarDate()).replaceAll("/", "-");
//INSERT INTO kqmk_redletter_day VALUES ( value1, value2,...valueN );
String jieri = date.getVacationName();
boolean status = jieri.contains("节");
int holidaystatus = 0;
if(status) {
holidaystatus = 1;
}
System.out.println("INSERT INTO kqmk_redletter_day(holiday,holiday_name,holiday_status,belong_yearmonth) VALUES(" + '"'+str +'"'+ "," +'"'+date.getVacationName()+'"'+ "," +holidaystatus+ "," + '"'+yymm+'"'+ ");");
}
// System.out.println("------------------------------------------------------------------------");
// System.out.println("今日详情:");
// System.out.println("日期:" + today.getSolarDate());
// System.out.println("农历:" + today.getLunar());
// System.out.println("公历:" + today.getSolar());
// System.out.println("假期名:" + today.getVacationName());
// System.out.println("是否周六:" + today.isSaturday());
// System.out.println("是否周日:" + today.isSunday());
// System.out.println("是否休假:" + today.isVacation());
// System.out.println("是否工作日:" + today.isWorkFlag());
// System.out.println("已发生的最近一次假期:" + Main.latestVocationName);
}
}
package cn.timer.api.dao.kqmk;
import org.springframework.stereotype.Repository;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.timer.api.bean.kqmk.KqmkRedletterDay;
/**
* 节假日
*
* @author LAL 2020-09-22
*/
@Repository
public interface KqmkRedletterDayMapper extends BaseMapper<KqmkRedletterDay> {
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.timer.api.dao.kqmk.KqmkRedletterDayMapper">
<resultMap id="BaseResultMap" type="cn.timer.api.bean.kqmk.KqmkRedletterDay" >
<id column="id" property="id" />
<result column="holiday" property="holiday" />
<result column="holiday_name" property="holidayName" />
<result column="holiday_status" property="holidayStatus" />
<result column="belong_yearmonth" property="belongYearmonth" />
</resultMap>
</mapper>
\ No newline at end of file
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