zm
2024-10-18 ac2e912c9dd7bafc9101775462fbe7060ce27a91
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package com.product.administration.service;
import com.product.administration.config.CmnConst;
import com.product.common.lang.StringUtils;
import com.product.core.dao.BaseDao;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.exception.BaseException;
import com.product.core.permission.PermissionService;
import com.product.core.service.support.AbstractBaseService;
import com.product.core.service.support.QueryFilterService;
import com.product.core.spring.context.SpringMVCContextHolder;
 
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
/**
 * Copyright © LX-BASE
 *
 * @Title: LeaveRequestService
 * @Project: LX-BASE-SERVER
 * @Date: 2020-11-13 09:27:35
 * @Author: Xin.Luo
 * @Description: 请假申请
 */
@Component
public class LeaveRequestService extends AbstractBaseService {
 
    @Autowired
    private BaseDao baseDao;
    @Autowired
    PermissionService permissionService;
    @Autowired
    QueryFilterService queryFilterService;
 
    /**
     * @Date: 2020-03-30 14:10
     * @Author: ZhouJie
     * 请假申请列表
     */
    public DataTableEntity getLeaveRequestList(FieldSetEntity fs) throws BaseException {
        String filter=fs.getString("filter");
        String dataFilter = permissionService.getDataFilter(fs.getTableName(),CmnConst.CREATED_BY);
        if(!StringUtils.isEmpty(dataFilter)){
            filter += " and "+dataFilter;
        }
        DataTableEntity dt = baseDao.listTable(CmnConst.PRODUCT_SYS_ASK_FOR_LEAVE,filter,null,null,"id desc",fs.getInteger(CmnConst.PAGESIZE),fs.getInteger(CmnConst.CPAGE),false);
        baseDao.loadPromptData(dt);
        return dt;
    }
    /**
     * @Date: 2020-03-30 14:46
     * @Author: ZhouJie
     * 请假申请详情
     */
    public FieldSetEntity getLeaveRequestInfo(FieldSetEntity fs) throws BaseException {
        return baseDao.listInternationDataTable(baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ASK_FOR_LEAVE, fs.getString(CmnConst.UUID), true),null);
    }
    /**
     * @Date: 2020-03-30 15:32
     * @Author: ZhouJie
     * 请假申请保存
     */
    public String saveLeaveRequest(FieldSetEntity fs) throws BaseException {
        DataTableEntity dataTableEntity = baseDao.listTable(CmnConst.PRODUCT_SYS_ASK_FOR_LEAVE, " uuid  not in (?) and user_id=? and ((start_time<=? and end_time>=?) or(start_time<=? and end_time>=?))"
                , new String[]{StringUtils.isEmpty(fs.getUUID())?"":fs.getUUID(), fs.getString("user_id"), fs.getString("start_time"), fs.getString("start_time"), fs.getString("end_time"), fs.getString("end_time")});
        if (dataTableEntity.getRows()>0){
            return "1";
        }else {
            if (StringUtils.isEmpty(fs.getString(CmnConst.UUID))) {
                fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
                fs.setValue("created_utc_datetime", new Date());
                fs.setValue("org_level_uuid", SpringMVCContextHolder.getCurrentUser().getOrg_level_uuid());
                return baseDao.add(fs);
            } else {
                fs.setValue("updated_by", SpringMVCContextHolder.getCurrentUser().getUser_id());
                fs.setValue("updated_utc_datetime", new Date());
                baseDao.update(fs);
                return fs.getString(CmnConst.UUID);
            }
 
        }
    }
 
    /**
     * 计算请假天数
     * @param fs
     * @return
     * @throws BaseException
     */
    public FieldSetEntity getDay(FieldSetEntity fs) throws BaseException {
        DataTableEntity dt = baseDao.listTable(com.product.org.admin.config.CmnConst.PRODUCT_SYS_COMPANY_HOLIDAY, "date_holiday >=? and date_holiday<=?", new String[]{fs.getString("start_time"), fs.getString("end_time")});
        String dateStr1 = fs.getString("start_time");
        String dateStr2 = fs.getString("end_time");
 
        // 使用DateTimeFormatter解析日期字符串
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
 
        // 将字符串解析为LocalDate对象
        LocalDate date1 = LocalDate.parse(dateStr1, formatter);
        LocalDate date2 = LocalDate.parse(dateStr2, formatter);
 
        // 计算两个日期之间的天数差
        long daysBetween = java.time.Duration.between(date1.atStartOfDay(), date2.atStartOfDay()).toDays()+1;
        fs.setValue("day",daysBetween-dt.getRows());
 
        return fs;
    }
    /**
     * @Date: 2020-03-30 16:43
     * @Author: ZhouJie
     * 删除请假申请
     */
    public boolean deleteLeaveRequest(FieldSetEntity fs) throws BaseException {
        return baseDao.delete(CmnConst.PRODUCT_SYS_ASK_FOR_LEAVE,CmnConst.UUID+"=?",new Object[]{fs.getString(CmnConst.UUID)});
    }
}