刘光辉
15 小时以前 34981c30a78e8bbd7791131059a9210f9928b62c
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
<?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="jnpf.limsMapper.LimsSxtQuyangJihuaMapper">
 
    <!-- 结果映射 -->
    <resultMap id="BaseResultMap" type="jnpf.limsEntity.LimsSxtQuyangJihuaEntity">
        <id column="f_id" property="id"/>
        <result column="jihua_mingcheng" property="jihuaMingcheng"/>
        <result column="yangpin_leixing" property="yangpinLeixing"/>
        <result column="suoshu_chejian" property="suoshuChejian"/>
        <result column="zhidingren" property="zhidingren"/>
        <result column="kaishi_shijian" property="kaishiShijian"/>
        <result column="yangpin_mingcheng" property="yangpinMingcheng"/>
        <result column="jieshu_shijian" property="jieshuShijian"/>
        <result column="jihua_zhouqi_leixing" property="jihuaZhouqiLeixing"/>
        <result column="jihua_zhouqi_jiange" property="jihuaZhouqiJiange"/>
        <result column="jiahua_jiange_danwei" property="jiahuaJiangeDanwei"/>
        <result column="biz_sign" property="bizSign"/>
        <result column="biz_status" property="bizStatus"/>
        <result column="plan_status" property="planStatus"/>
        <result column="f_tenant_id" property="fTenantId"/>
        <result column="f_flow_id" property="fFlowId"/>
        <result column="f_version" property="fVersion"/>
        <result column="f_flow_task_id" property="fFlowTaskId"/>
        <result column="f_flow_state" property="fFlowState"/>
        <result column="f_delete_mark" property="fDeleteMark"/>
        <result column="f_delete_time" property="fDeleteTime"/>
        <result column="f_delete_user_id" property="fDeleteUserId"/>
        <result column="f_creator_time" property="fCreatorTime"/>
        <result column="f_creator_user_id" property="fCreatorUserId"/>
        <result column="f_last_modify_time" property="fLastModifyTime"/>
        <result column="f_last_modify_user_id" property="fLastModifyUserId"/>
        <result column="yangpin_leixing_mingcheng" property="yangpinLeixingMingcheng"/>
    </resultMap>
 
    <!-- 查询指定日期的计划 -->
    <select id="selectDailyJihua" resultMap="BaseResultMap">
        SELECT *
        FROM lims_sxt_quyang_jihua
        WHERE f_delete_mark = 0
        AND f_flow_state = 2
        AND plan_status IN ('available', 'terminating')
        AND DATE(kaishi_shijian) &lt;= #{day}
        AND DATE(jieshu_shijian) &gt;= #{day}
        AND (
        CASE jihua_zhouqi_leixing
        WHEN 'daily' THEN
        DATEDIFF(#{day}, DATE(kaishi_shijian)) % (CAST(jihua_zhouqi_jiange AS UNSIGNED) + 1) = 0
 
        WHEN 'weekly' THEN
        WEEKDAY(#{day}) = WEEKDAY(DATE(kaishi_shijian))
        AND FLOOR(DATEDIFF(#{day}, DATE(kaishi_shijian)) / 7) % (CAST(jihua_zhouqi_jiange AS UNSIGNED) + 1) = 0
 
        WHEN 'monthly' THEN
        (
        DAY(#{day}) = DAY(DATE(kaishi_shijian))
        OR
        (
        DAY(DATE(kaishi_shijian)) = DAY(LAST_DAY(DATE(kaishi_shijian)))
        AND #{day} = LAST_DAY(#{day})
        )
        )
        AND PERIOD_DIFF(
        DATE_FORMAT(#{day}, '%Y%m'),
        DATE_FORMAT(DATE(kaishi_shijian), '%Y%m')
        ) % (CAST(jihua_zhouqi_jiange AS UNSIGNED) + 1) = 0
 
        WHEN 'quarterly' THEN
        (
        DAY(#{day}) = DAY(DATE(kaishi_shijian))
        OR
        (
        DAY(DATE(kaishi_shijian)) = DAY(LAST_DAY(DATE(kaishi_shijian)))
        AND #{day} = LAST_DAY(#{day})
        )
        )
        AND PERIOD_DIFF(
        DATE_FORMAT(#{day}, '%Y%m'),
        DATE_FORMAT(DATE(kaishi_shijian), '%Y%m')
        ) % ((CAST(jihua_zhouqi_jiange AS UNSIGNED) + 1) * 3) = 0
 
        WHEN 'yearly' THEN
        (
        DATE_FORMAT(#{day}, '%m-%d') = DATE_FORMAT(DATE(kaishi_shijian), '%m-%d')
        OR
        (
        MONTH(DATE(kaishi_shijian)) = 2
        AND DAY(DATE(kaishi_shijian)) = 29
        AND MONTH(#{day}) = 2
        AND DAY(#{day}) = 28
        AND NOT (YEAR(#{day}) % 4 = 0 AND (YEAR(#{day}) % 100 != 0 OR YEAR(#{day}) % 400 = 0))
        )
        )
        AND (YEAR(#{day}) - YEAR(DATE(kaishi_shijian))) % (CAST(jihua_zhouqi_jiange AS UNSIGNED) + 1) = 0
 
        ELSE 0
        END
        )
        ORDER BY kaishi_shijian ASC
    </select>
 
</mapper>