zjh
2024-07-02 a51a70b780ef0ed24abb81b096c80649a0255ece
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
package com.ltkj.hosp.mapper;
 
 
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ltkj.hosp.domain.TbTransition;
import org.apache.ibatis.annotations.*;
 
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
 
/**
 * 过渡Mapper接口
 *
 * @author ltkj
 * @date 2023-01-17
 */
@Mapper
public interface TbTransitionMapper extends BaseMapper<TbTransition> {
    /**
     * 查询过渡
     *
     * @param id 过渡主键
     * @return 过渡
     */
    public TbTransition selectTbTransitionById(String id);
 
    /**
     * 查询过渡列表
     *
     * @param tbTransition 过渡
     * @return 过渡集合
     */
    public List<TbTransition> selectTbTransitionList(TbTransition tbTransition);
 
    /**
     * 新增过渡
     *
     * @param tbTransition 过渡
     * @return 结果
     */
    public int insertTbTransition(TbTransition tbTransition);
 
    /**
     * 修改过渡
     *
     * @param tbTransition 过渡
     * @return 结果
     */
    public int updateTbTransition(TbTransition tbTransition);
 
    /**
     * 删除过渡
     *
     * @param id 过渡主键
     * @return 结果
     */
    public int deleteTbTransitionById(String id);
 
    /**
     * 批量删除过渡
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteTbTransitionByIds(String[] ids);
 
    @Delete("DELETE  FROM tb_transition WHERE cus_id=#{cusId} and isnull(tj_num)")
    public boolean deletedTbTransitionByCusId(String cusId);
 
 
    @Delete("DELETE  FROM tb_transition WHERE tj_num=#{tjNum}")
    public boolean deletedTbTransitionByTjNum(String tjNum);
 
    @Delete("DELETE  FROM tb_transition WHERE isnull(tj_num)  and  cus_id=#{cdId} and parent_pro_id=#{proId}")
    public boolean delTbBycusCardIdAndProId(@Param("cdId") String cdId,@Param("proId")String proId);
 
    @Update("UPDATE tb_transition a SET "+
            "a.tj_num=null" +
            " WHERE a.tj_num=#{tjNum}")
    boolean updateTbTransitionByTjNum(String tjNum);
 
    @Select("SELECT * FROM tb_transition WHERE cus_id=#{cusId} AND pac_id=#{pacId}")
    public List<TbTransition> getTbTransitionListByCusIdAndPac(@Param("cusId") String cusId,@Param("pacId") String pacId);
 
    @Select("SELECT * FROM tb_transition WHERE cus_id=#{cusId} and card_id=#{cardId}")
    public List<TbTransition> getTbTransitionListByCusId(@Param("cusId")String cusId,@Param("cardId")String cardId);
 
    @Delete("DELETE FROM tb_transition WHERE cus_id=#{cusId} AND !ISNULL(pac_id) and isnull(tj_num)")
    public boolean deletedTbTransitionListByCusIdAndPac(@Param("cusId")String cusId,@Param("cardId")String cardId);
 
    @Delete("DELETE FROM tb_transition WHERE cus_id=#{cusId} AND ISNULL(tj_num)and card_id=#{cardId}")
    public boolean deletedTbTransitionListByCusIdAndTjNum(@Param("cusId")String cusId,@Param("cardId")String cardId);
 
    //根据身份证号和套餐id查询和项目id
//    @Select("SELECT * FROM tb_transition WHERE cus_id=#{cusId} AND ISNULL(pac_id)  AND pro_id =#{proId}")
//    public List<TbTransition> getTbTransitionListByCusIdAndPacIdAndProId(@Param("cusId") String cusId,@Param("proId") String proId);
 
    @Select("SELECT * FROM tb_transition WHERE cus_id=#{cusId}  AND pro_id =#{proId} and ISNULL(tj_num)")
    public List<TbTransition> getTbTransitionListByCusIdAndPacIdAndProId(@Param("cusId") String cusId,@Param("proId") String proId);
 
    @Select("SELECT DISTINCT pac_id FROM tb_transition WHERE cus_id=#{cusId} AND !ISNULL(pac_id)")
    String getTbTransitionPacIdByCusIdAndPac(String cusId);
 
    @Select("SELECT SUM(a.now_price) now_price FROM tb_transition a WHERE cus_id=#{cusId}")
    BigDecimal sumNowPrice(String cusId);
 
    @Select("SELECT MAX(a.create_time) FROM tb_transition a WHERE a.cus_id=#{cusId} ")
    Date getTbTransitionCreateTimeByCusId(String cusId);
 
 
    @Update("UPDATE tb_transition a SET \n" +
            "a.ord_price=a.now_price,\n" +
            "a.now_price=a.ord_price*(#{discount}/10)," +
            "a.tj_num=#{tjNum}"+
            " WHERE a.cus_id=#{cusId} ")
    boolean updateTbTransitionPriceByCusId(@Param("cusId")String cusId,@Param("discount")BigDecimal discount,@Param("tjNum")String tjNum);
 
 
    @Insert("INSERT INTO tb_transition(\n" +
            "   cus_id,\n" +
            "   pac_id,\n" +
            "   pac_name,\n" +
            "   pro_id,\n" +
            "   pro_name,\n" +
            "   parent_pro_id,\n" +
            "   parent_pro_name,\n" +
            "   ord_price,\n" +
            "   now_price,\n" +
            "   create_time,\n" +
            "   pro_check_method,\n" +
            "   pro_type,\n" +
            "   card_id\n" +
            ")\n" +
            "SELECT\n" +
            "\t#{cusId},\n" +
            "\ta.pac_id,\n" +
            "\td.pac_name,\n" +
            "\tc.pro_id,\n" +
            "\tc.pro_name,\n" +
            "\tb.pro_id,\n" +
            "\tb.pro_name,\n" +
            "\tTRUNCATE(c.pro_price,2),\n" +
            "\tTRUNCATE(c.pro_price,2),\n" +
//            " IFNULL(TRUNCATE(c.pro_price * (TRUNCATE ( a.price_now / b.pro_price, 5 )),2),0), " +
            "\tSYSDATE(),\n" +
            "\tc.pro_check_method,\n" +
            "\tIFNULL(c.pro_type,''),\n" +
            "\t#{cardId}\n" +
            "FROM\n" +
            "\ttj_package_project a\n" +
            "\tLEFT JOIN tj_project b ON a.pro_id = b.pro_id\n" +
            "\tLEFT JOIN tj_project c ON b.pro_id = c.pro_parent_id\n" +
            "\tLEFT JOIN tj_package d ON a.pac_id=d.pac_id\n" +
            "\t\n" +
            "\tWHERE a.pac_id=#{pacId} and c.deleted=0")
    void saveRedisTransitionByPacId(@Param("cusId") String cusId,@Param("cardId")String cardId,@Param("pacId") Long pacId);
 
 
    @Insert("INSERT INTO tb_transition \n" +
            "(cus_id, pro_id, pro_name, parent_pro_id, parent_pro_name, ord_price, now_price, create_time, pro_check_method, pro_type,card_id ) \n" +
            "SELECT\n" +
            "#{cusId},\n" +
            "a.pro_id,a.pro_name,b.pro_id,b.pro_name,a.pro_price,a.pro_price,SYSDATE(),a.pro_check_method,\n" +
            "IFNULL ( a.pro_type, '' ), \n" +
            "#{cardId}\n" +
            "FROM\n" +
            "\ttj_project a\n" +
            "\tLEFT JOIN \n" +
            "\ttj_project b \n" +
            "\tON a.pro_parent_id = b.pro_id \n" +
            "WHERE\n" +
            "\ta.pro_id = #{proId}")
    void saveRedisTransitionByProId(@Param("cusId")String cusId,@Param("cardId")String cardId,@Param("proId") Long proId);
 
 
    @Insert("INSERT INTO tb_transition(\n" +
            "   cus_id,\n" +
            "   pro_id,\n" +
            "   pro_name,\n" +
            "   parent_pro_id,\n" +
            "   parent_pro_name,\n" +
            "   ord_price,\n" +
            "   now_price,\n" +
            "   create_time,\n" +
            "   pro_check_method,\n" +
            "   pro_type\n" +
            ")\n" +
            "SELECT\n" +
            "#{cusId},\n" +
            "c.pro_id,\n" +
            "c.pro_name,\n" +
            "b.pro_id,\n" +
            "b.pro_name,\n" +
            "c.pro_price * (a.limits/10),\n" +
            "c.pro_price * (a.limits/10),\n" +
            "SYSDATE(),\n" +
            "c.pro_check_method,\n" +
            "c.pro_type\n" +
            "FROM\n" +
            "\ttj_grouping_pro a\n" +
            "\tLEFT JOIN tj_project b ON a.pro_id = b.pro_id \n" +
            "\tLEFT JOIN tj_project c ON c.pro_parent_id=b.pro_id\n" +
            "WHERE 1=1 AND a.grouping_id =#{groupingId} and c.deleted=0 ")
    boolean saveTemoTransitionByGroupingId(@Param("cusId")String cusId,@Param("groupingId")String groupingId);
 
 
//    @Select("SELECT b.price_now FROM \n" +
//            "(SELECT a.pac_id FROM tb_transition a  WHERE\n" +
//            "\ta.cus_id = #{cusId} \n" +
//            "GROUP BY\n" +
//            "\ta.pac_id) aa \n" +
//            "LEFT JOIN tj_package_project b\n" +
//            "\tON aa.pac_id=b.pac_id WHERE b.pro_id=#{proId} ")
//    BigDecimal getTbTransitionPriceAndOrdPrice(@Param("cusId")String cusId,@Param("proId")Long proId);
 
    @Select("SELECT SUM(a.now_price) FROM tb_transition a WHERE a.cus_id=#{cusId} AND a.parent_pro_id=#{proId}")
    BigDecimal getTbTransitionPriceAndOrdPrice(@Param("cusId")String cusId,@Param("proId")Long proId);
 
 
    @Select("SELECT SUM(c.pro_price) FROM tj_project c WHERE c.pro_id IN " +
            "(SELECT b.pro_id FROM tb_transition b WHERE" +
            " b.cus_id=(SELECT a.cus_idcard FROM tj_customer a " +
            "WHERE a.cus_id=#{cusId}) AND b.parent_pro_id=#{proId})  ")
    BigDecimal getTbTransitionDxPriceAndOrdPrice(@Param("cusId")String cusId,@Param("proId")Long proId);
 
    @Select("SELECT DISTINCT a.pac_id FROM tb_transition a WHERE a.tj_num=#{tjNum}AND a.card_id=#{cardId} AND !ISNULL(a.pac_id)")
    String selectPacIdByTbTransitionTjNumAndProId(@Param("tjNum")String tjNum,@Param("cardId")String cardId);
 
    @Select("SELECT SUM(a.now_price) FROM tb_transition a WHERE a.cus_id=#{cusId} AND a.parent_pro_id=#{proId} and a.card_id=#{cardId} and a.pac_id=#{pacId}")
    BigDecimal getTbTransitionDxPriceByPac(@Param("cusId")String cusId,@Param("proId")Long proId,@Param("cardId")String cardId,@Param("pacId")Long pacId);
 
 
    @Update("UPDATE tb_transition a \n" +
            "SET \n" +
            "a.card_id=#{cardId}\n" +
            "WHERE\n" +
            "\ta.cus_id =#{idCard}\n" +
            "\tAND a.tj_num = #{tjNumber}")
    boolean updateCardIdByTjNumAndIdCard(@Param("idCard")String idCard,@Param("cardId")String cardId,@Param("tjNumber") String tjNumber);
 
}