加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
archivesService.js 11.30 KB
一键复制 编辑 原始数据 按行查看 历史
自动部署 提交于 2018-11-21 14:05 . x
const rp = require("request-promise");
class Archives {
constructor() {
}
//获取员工档案信息
async getArchives(code) {
let data = await rp.get(`http://localhost:8080/data/getDoc?code=${code}`, { json: true });
return data;
}
async postname(PK_ORG, POSTNAME) {
let json = await rp.get(`http://localhost:8080/data/queryViewPost?pkOrg=${PK_ORG}&postName=${POSTNAME}`, { json: true });
return json;
}
//动态计算当前可修年假
async getAnnual(code, year) {
let month = new Date().getMonth() + 1; //当期月份
let today_year = year; //当前年份
let data = await this.getArchives(code); //员工档案信息
let psncl = data[0].PSNCL; //人员类别(正式员工才有年假)
let indate = data[0].INDATE; //入职日期
let joindate = data[0].JOINDATE; //参加工作日期
let myDate = new Date(indate);
let woekDate = new Date(joindate);
let indate_year = myDate.getFullYear(); //入职年份
let indate_month = myDate.getMonth() + 1; //入职月份
let work_year = woekDate.getFullYear(); //参加工作年份
let work_month = woekDate.getMonth() + 1; //参加工作月份
let min_year = today_year - indate_year; //已入职年长
let inwork_year = today_year - work_year; //已工作年长
let min_month = month - indate_month; //入职月份与当月差
//我的年假
let annual_leave = 0; //该员工当前月可休年假
let temporary = 0; //每月可休年假
let mini = 0; //余数
if (min_year < 0) {
annual_leave = 0;
}
else if (min_year == 0) {
if (inwork_year < 10 && inwork_year > 1) {
temporary = 5 / 12 * min_month;
mini = temporary - Math.floor(temporary);
if (mini < 0.5) {
annual_leave = parseInt(temporary.toString()) - 0;
}
else {
annual_leave = parseInt(temporary.toString()) + 0.5;
}
}
else if (inwork_year >= 10 && inwork_year < 15) {
temporary = 10 / 12 * min_month;
mini = temporary - parseInt(temporary.toString()) - 0;
if (mini < 0.5) {
annual_leave = parseInt(temporary.toString()) - 0;
}
else {
annual_leave = parseInt(temporary.toString()) + 0.5;
}
}
else if (inwork_year >= 15 && inwork_year < 20) {
temporary = 15 / 12 * min_month;
}
else if (inwork_year >= 20) {
temporary = 20 / 12 * min_month;
}
else {
annual_leave = 0;
}
}
else if (min_year == 1 && min_month < 0) {
if (inwork_year < 10 && inwork_year > 1) {
temporary = 5 / 12 * min_month;
mini = temporary - parseInt(temporary.toString()) - 0;
if (mini < 0.5) {
annual_leave = parseInt(temporary.toString()) - 0;
}
else {
annual_leave = parseInt(temporary.toString()) + 0.5;
}
}
else if (inwork_year >= 10 && inwork_year < 15) {
temporary = 10 / 12 * min_month;
mini = temporary - parseInt(temporary.toString()) - 0;
if (mini < 0.5) {
annual_leave = parseInt(temporary.toString()) - 0;
}
else {
annual_leave = parseInt(temporary.toString()) + 0.5;
}
}
else if (inwork_year >= 15 && inwork_year < 20) {
temporary = 15 / 12 * min_month;
mini = temporary - parseInt(temporary.toString()) - 0;
if (mini < 0.5) {
annual_leave = parseInt(temporary.toString()) - 0;
}
else {
annual_leave = parseInt(temporary.toString()) + 0.5;
}
}
else if (inwork_year >= 20) {
temporary = 20 / 12 * min_month;
mini = temporary - parseInt(temporary.toString()) - 0;
if (mini < 0.5) {
annual_leave = parseInt(temporary.toString()) - 0;
}
else {
annual_leave = parseInt(temporary.toString()) + 0.5;
}
}
else {
annual_leave = 0;
}
}
else if (min_year == 1 && min_month > 0) {
annual_leave = await this.getCount(code, year);
}
else if (min_year == 1 && min_month == 0) {
annual_leave = await this.getCount(code, year);
}
else if (min_year > 1) {
annual_leave = await this.getCount(code, year);
}
return annual_leave;
}
//正式员工可修年假
async getCount(code, year) {
let month = new Date().getMonth() + 1; //当期月份
let today_year = year; //当前年份
let data = await this.getArchives(code); //员工档案信息
let psncl = data[0].PSNCL; //人员类别(正式员工才有年假)
let indate = data[0].INDATE; //入职日期
let joindate = data[0].JOINDATE; //参加工作日期
let myDate = new Date(indate);
let woekDate = new Date(joindate);
let indate_year = myDate.getFullYear(); //入职年份
let indate_month = myDate.getMonth() + 1; //入职月份
let work_year = woekDate.getFullYear(); //参加工作年份
let work_month = woekDate.getMonth() + 1; //参加工作年份
let min_year = today_year - indate_year; //已入职年长
let inwork_year = today_year - work_year; //已工作年长
// let inwork_year = 7;
// let work_month = 11;
// if (psncl == '10018810000000000254') //根据人员类别区分有无年假
//我的年假
let annual_leave = 0; //该员工当前月可休年假
let temporary = 0; //每月可休年假
let mini = 0; //余数
console.log('当前年份', year, '当期月份', month, '入职年份', indate_year, '入职月份', indate_month, '参加工作年份', work_year, '参加工作年份', work_month, '已入职年长', min_year, '已工作年长', inwork_year);
if (inwork_year == 1) {
console.log('已工作1年');
if (month > work_month) {
console.log('已工作1年');
temporary = 5 / 12 * (month - work_month);
mini = temporary - parseInt(temporary.toString()) - 0;
if (mini < 0.5) {
annual_leave = parseInt(temporary.toString()) - 0;
}
else {
annual_leave = parseInt(temporary.toString()) + 0.5;
}
}
else {
annual_leave = 0;
}
}
else if (inwork_year < 1) {
console.log('工作不足1年');
annual_leave = 0;
}
else if (inwork_year < 10 && inwork_year > 1) {
console.log('工作1-10年');
temporary = 5 / 12 * month;
mini = temporary - parseInt(temporary.toString()) - 0;
if (mini < 0.5) {
annual_leave = parseInt(temporary.toString()) - 0;
}
else {
annual_leave = parseInt(temporary.toString()) + 0.5;
}
}
else if (inwork_year >= 10 && inwork_year < 15) {
console.log('工作10-15年');
if (inwork_year == 10 && work_month != 1) {
if (work_month > month) {
temporary = 5 / 12 * month;
mini = temporary - parseInt(temporary.toString()) - 0;
if (mini < 0.5) {
annual_leave = parseInt(temporary.toString()) - 0;
}
else {
annual_leave = parseInt(temporary.toString()) + 0.5;
}
}
else {
temporary = 5 / 12 * work_month + 10 / 12 * (month - work_month) - 0;
mini = temporary - parseInt(temporary.toString()) - 0;
if (mini < 0.5) {
annual_leave = parseInt(temporary.toString()) - 0;
}
else {
annual_leave = parseInt(temporary.toString()) + 0.5;
}
}
}
else {
temporary = 10 / 12 * month;
mini = temporary - parseInt(temporary.toString()) - 0;
if (mini < 0.5) {
annual_leave = parseInt(temporary.toString()) - 0;
}
else {
annual_leave = parseInt(temporary.toString()) + 0.5;
}
}
}
else if (inwork_year >= 15 && inwork_year < 20) {
console.log('工作15-20年');
if (inwork_year == 15 && work_month != 1) {
if (work_month > month) {
temporary = 15 / 12 * month;
mini = temporary - parseInt(temporary.toString()) - 0;
if (mini < 0.5) {
annual_leave = parseInt(temporary.toString()) - 0;
}
else {
annual_leave = parseInt(temporary.toString()) + 0.5;
}
}
else {
temporary = 15 / 12 * work_month + 20 / 12 * (month - work_month) - 0;
mini = temporary - parseInt(temporary.toString()) - 0;
if (mini < 0.5) {
annual_leave = parseInt(temporary.toString()) - 0;
}
else {
annual_leave = parseInt(temporary.toString()) + 0.5;
}
}
}
else {
temporary = 15 / 12 * month;
mini = temporary - parseInt(temporary.toString()) - 0;
if (mini < 0.5) {
annual_leave = parseInt(temporary.toString()) - 0;
}
else {
annual_leave = parseInt(temporary.toString()) + 0.5;
}
}
}
else if (inwork_year >= 20) {
console.log('工作20年以上');
temporary = 20 / 12 * month;
mini = temporary - parseInt(temporary.toString()) - 0;
if (mini < 0.5) {
annual_leave = parseInt(temporary.toString()) - 0;
}
else {
annual_leave = parseInt(temporary.toString()) + 0.5;
}
}
console.log(year, '', month, '月可休年假', annual_leave);
return annual_leave;
}
}
let archives = new Archives();
module.exports = archives;
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化