huanghongfa
2021-04-21 37ed2e4254c12db7d8135413d1965e463c7fba19
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
package com.panzhihua.service_user.dao;
 
 
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panzhihua.common.model.dtos.PageDTO;
import com.panzhihua.common.model.dtos.community.ExportUserDTO;
import com.panzhihua.common.model.dtos.user.EexcelUserDTO;
import com.panzhihua.common.model.dtos.user.PageUserAppletsBackstageDTO;
import com.panzhihua.common.model.vos.IndexDataKanbanVO;
import com.panzhihua.common.model.vos.IndexDataVO;
import com.panzhihua.common.model.vos.LoginUserInfoVO;
import com.panzhihua.common.model.vos.community.ComActVO;
import com.panzhihua.common.model.vos.community.ComMngVolunteerMngVO;
import com.panzhihua.common.model.vos.user.AdministratorsUserVO;
import com.panzhihua.common.model.vos.user.SysUserNoticeVO;
import com.panzhihua.common.model.vos.user.SysUserVO;
import com.panzhihua.service_user.model.dos.SysUserDO;
import com.panzhihua.service_user.model.dtos.DataKanbanDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
 
import java.util.Date;
import java.util.List;
 
/**
 * @program: springcloud_k8s_panzhihuazhihuishequ
 * @description: 用户
 * @author: huang.hongfa weixin hhf9596 qq 959656820
 * @create: 2020-11-20 15:55
 **/
@Mapper
public interface UserDao extends BaseMapper<SysUserDO> {
    //    @Select("<script> " +
//            " <where>" +
//            "<if test='nameCn != null and nameCn.trim() != &quot;&quot;'>" +
//            " </if> " +
//            "<if test='nameCn != null and nameCn.trim() != &quot;&quot;'>" +
//            " </if> " +
//            "<if test='nameCn != null and nameCn.trim() != &quot;&quot;'>" +
//            " </if> " +
//            " </where>" +
//            "</script>")
 
    @Select("<script> " +
            "SELECT\n" +
            "u.user_id,\n" +
            "u.face_url,\n" +
            "u.nick_name,\n" +
            "u.`name`,\n" +
            "u.phone,\n" +
            "u.id_card,\n" +
            "u.face_state,\n" +
            "c.area_name communityName,\n" +
            "u.create_at \n" +
            "FROM\n" +
            "sys_user u\n" +
            "JOIN com_mng_struct_area c ON u.area_id = c.id \n" +
            "<if test='loginUserInfoVO.communityName != null and loginUserInfoVO.communityName.trim() != &quot;&quot;'>" +
            "AND c.`area_name` like concat(#{loginUserInfoVO.communityName},'%')  \n" +
            " </if> " +
            " where u.face_state is not null and u.type=1 and u.community_id=#{loginUserInfoVO.communityId} " +
            "<if test='loginUserInfoVO.name != null and loginUserInfoVO.name.trim() != &quot;&quot;'>" +
            "and u.`name` like concat(#{loginUserInfoVO.name},'%')  \n" +
            " </if> " +
            "<if test='loginUserInfoVO.phone != null and loginUserInfoVO.phone.trim() != &quot;&quot;'>" +
            "AND u.phone like concat(#{loginUserInfoVO.phone},'%') " +
            " </if> " +
            " order by u.face_state asc,u.create_at asc " +
            "</script>")
    IPage<LoginUserInfoVO> pageUserFace(Page page, @Param("loginUserInfoVO") LoginUserInfoVO loginUserInfoVO);
 
    @Select("<script> " +
            "SELECT\n" +
            "u.user_id,\n" +
            "u.`name`,\n" +
            "u.`sex`,\n" +
            "u.nick_name,\n" +
            "u.phone,\n" +
            "YEAR (now()) - YEAR (substring(u.id_card, 7, 8)) age,\n"+
            "1 isRegister,\n"+
            "v.political_face political_outlook,\n"+
            "u.id_card,\n" +
            "u.job,\n" +
            "c.area_name communityName,\n" +
            "u.tags,\n" +
            "u.create_at \n" +
            "FROM\n" +
            "sys_user u\n" +
            "left join com_mng_volunteer_mng v on u.phone=v.phone \n"+
            "<if test='loginUserInfoVO.communityName != null and loginUserInfoVO.communityName.trim() != &quot;&quot;'>" +
            " JOIN com_mng_struct_area c ON u.area_id = c.id \n" +
            " </if> " +
            "<if test='loginUserInfoVO.communityName == null or loginUserInfoVO.communityName.trim() == &quot;&quot;'>" +
            "LEFT JOIN com_mng_struct_area c ON u.area_id = c.id \n" +
            " </if> " +
            "<if test='loginUserInfoVO.communityName != null and loginUserInfoVO.communityName.trim() != &quot;&quot;'>" +
            "AND c.`area_name` like concat(#{loginUserInfoVO.communityName},'%')  \n" +
            " </if> " +
            " where u.community_id=#{loginUserInfoVO.communityId} and u.type=1 " +
            "<if test='loginUserInfoVO.name != null and loginUserInfoVO.name.trim() != &quot;&quot;'>" +
            " and u.`name` like concat(#{loginUserInfoVO.name},'%')  \n" +
            " </if> " +
            "<if test='loginUserInfoVO.phone != null and loginUserInfoVO.phone.trim() != &quot;&quot;'>" +
            "AND u.phone like concat(#{loginUserInfoVO.phone},'%') " +
            " </if> " +
            "</script>")
    IPage<LoginUserInfoVO> pageUser(Page page, @Param("loginUserInfoVO") LoginUserInfoVO loginUserInfoVO);
 
    @Select("<script> " +
            "SELECT\n" +
            "u.user_id,\n" +
            "u.account,\n" +
            "u.`name`,\n" +
            "u.`password`,\n" +
            "u.phone,\n" +
            "e.role_name,\n" +
            "e.role_id ,\n" +
            "u.`status`,\n" +
            "u.create_at,\n" +
            "u.last_login_time \n" +
            "FROM\n" +
            "sys_user u\n" +
            "JOIN sys_user_role r ON u.user_id = r.user_id\n" +
            "JOIN sys_role e ON r.role_id = e.role_id \n" +
            "<if test='administratorsUserVO.roleId != null and administratorsUserVO.roleId!=0'>" +
            " and e.role_id=#{administratorsUserVO.roleId}" +
            " </if> " +
            " <where>" +
            "<if test='administratorsUserVO.communityId != null '>" +
            "AND u.community_id = #{administratorsUserVO.communityId} \n" +
            " </if> " +
            "<if test='administratorsUserVO.name != null and administratorsUserVO.name.trim() != &quot;&quot;'>" +
            "AND u.name like concat (#{administratorsUserVO.name},'%')  \n" +
            " </if> " +
            "<if test='administratorsUserVO.phone != null and administratorsUserVO.phone.trim() != &quot;&quot;'>" +
            "AND u.phone like concat(#{administratorsUserVO.phone},'%') " +
            " </if> " +
            "<if test='administratorsUserVO.account != null and administratorsUserVO.account.trim() != &quot;&quot;'>" +
            "AND u.account like concat(#{administratorsUserVO.account},'%') " +
            " </if> " +
            " </where>" +
            "</script>")
    IPage<AdministratorsUserVO> pageUserBackstage(Page page, @Param("administratorsUserVO") AdministratorsUserVO administratorsUserVO);
 
    @Select("<script> " +
            "select \n" +
            "u.user_id,\n" +
            "u.phone,\n" +
            "u.nick_name,\n" +
            "u.name,\n" +
            "a.name communityName,\n" +
            "u.status,\n" +
            "u.create_at,\n" +
            "u.last_login_time\n" +
            "from sys_user u\n" +
            "left join com_act a on u.community_id=a.community_id\n" +
            " where\n" +
            "u.type=1\n" +
            "<if test='pageUserAppletsBackstageDTO.phone != null and pageUserAppletsBackstageDTO.phone.trim() != &quot;&quot;'>" +
            "and u.phone=#{pageUserAppletsBackstageDTO.phone}\n" +
            " </if> " +
            "<if test='pageUserAppletsBackstageDTO.communityId != null and pageUserAppletsBackstageDTO.communityId != 0'>" +
            "and u.community_id=#{pageUserAppletsBackstageDTO.communityId}\n" +
            " </if> " +
            "<if test='pageUserAppletsBackstageDTO.status != null and pageUserAppletsBackstageDTO.status != 0'>" +
            "and u.status=#{pageUserAppletsBackstageDTO.status}\n" +
            " </if> " +
            "<if test='pageUserAppletsBackstageDTO.createAtBegin != null '>" +
            "and u.create_at between #{pageUserAppletsBackstageDTO.createAtBegin} and #{pageUserAppletsBackstageDTO.createAtEnd}\n" +
            " </if> " +
            "<if test='pageUserAppletsBackstageDTO.lastLoginTimeBegin != null '>" +
            "and u.last_login_time between #{pageUserAppletsBackstageDTO.lastLoginTimeBegin} and #{pageUserAppletsBackstageDTO.lastLoginTimeEnd}\n" +
            " </if> " +
            "order by u.create_at desc \n" +
            "</script>")
    IPage<SysUserVO> pageUserAppletsBackstage(Page page, @Param("pageUserAppletsBackstageDTO") PageUserAppletsBackstageDTO pageUserAppletsBackstageDTO);
 
    @Update("update sys_user set nick_name=null ,community_id=null,area_id=null where user_id=#{userId}")
    int deleteUserTest(Long userId);
 
    @Select("<script> " +
            "select * from \n" +
            "sys_user_notice \n" +
            "where \n" +
            "user_id=#{pageDTO.userId} \n" +
            "<if test='pageDTO.type != null and pageDTO.type != 0'>" +
            "and type=#{pageDTO.type}\n" +
            " </if> " +
            "order by create_at desc\n" +
            "</script>")
    IPage<SysUserNoticeVO> pageNotice(Page page, @Param("pageDTO") PageDTO pageDTO);
 
    @Select("SELECT \n" +
            "COUNT(user_id)allUser,\n" +
            "COUNT(case WHEN DATE_FORMAT(create_at,'%m-%d-%Y')=DATE_FORMAT(SYSDATE(),'%m-%d-%Y') then user_id else null end )addUser,\n" +
            "COUNT(case WHEN DATE_FORMAT(last_login_time,'%m-%d-%Y')=DATE_FORMAT(SYSDATE(),'%m-%d-%Y') then user_id else null end )activeDayUser,\n" +
            "(SELECT count(user_id) FROM sys_user WHERE type = 1 AND last_login_time > date_sub(SYSDATE(), INTERVAL 7 DAY))activeWeekUser\n" +
            "FROM\n" +
            "sys_user\n" +
            "where type=1 and community_id is not null")
    IndexDataKanbanVO selectIndexDataKanban();
 
    @Select("select t.* from (\n" +
            "SELECT \n" +
            "a.`name`,\n" +
            "COUNT(u.user_id)num\n" +
            "FROM\n" +
            "com_act a\n" +
            "LEFT JOIN sys_user u ON a.community_id = u.community_id and u.type=1\n" +
            "GROUP BY a.community_id)t ORDER BY t.num desc  ")
    List<DataKanbanDTO>  selectCommunityUserOrder();
 
    @Select("SELECT\n" +
            "\tCOUNT( a.id ) num \n" +
            "FROM\n" +
            "\tcom_act_activity a \n" +
            "WHERE\n" +
            "\tDATE_FORMAT( #{date1}, '%Y-%m-%d' )= DATE_FORMAT(\n" +
            "\t\ta.create_at,\n" +
            "\t'%Y-%m-%d')\n" +
            "\t")
    DataKanbanDTO selectCommunityActiveUserOrder(Date date1);
    @Select("SELECT \n" +
            "COUNT(DISTINCT u.user_id)allUser,\n" +
            "(select COUNT(m.id) from com_mng_volunteer_mng m where m.community_id=#{communityId} and m.`state`=2)volunteerUser,\n" +
            "COUNT(DISTINCT case when u.is_partymember=1 then u.user_id else null end )partymemberUser,\n" +
            "COUNT(h.id)house\n" +
            "FROM\n" +
            "sys_user u\n" +
            "JOIN com_act c ON u.community_id = c.community_id \n" +
            "LEFT JOIN com_mng_struct_house_user h on u.user_id=h.user_id\n" +
            "WHERE\n" +
            "u.community_id =#{communityId} and u.type=1")
    IndexDataVO indexDataCommunityBackstage(Long communityId);
    @Update("UPDATE sys_user u \n" +
            "SET u.continuous_landing_days =\n" +
            "IF\n" +
            "(\n" +
            "DATE_FORMAT( u.last_login_time, '%m-%d-%Y' )= DATE_FORMAT( SYSDATE(), '%m-%d-%Y' ),\n" +
            "u.continuous_landing_days + 1,\n" +
            "0)")
    int timedTaskContinuousLandingDays();
    @Select("select state from com_mng_volunteer_mng where phone=#{phone} order by create_at desc limit 1")
    ComMngVolunteerMngVO selectVolunteerMngByPhone(String phone);
    @Update("update sys_user set face_state=null where user_id=#{userId}")
    int updateFaceState(Long userId);
    @Select("select name from com_act where community_id=#{communityId}")
    ComActVO selectCommunity(Long communityId);
    @Select("select COUNT(a.id) from com_mng_struct_area a where a.area_name=#{areaName}")
    Integer selectCountArea(String areaName);
    @Select("SELECT\n" +
            "\tCOUNT(h.id)\n" +
            "FROM\n" +
            "\tcom_mng_struct_area a \n" +
            "\tLEFT JOIN com_mng_struct_house h on  h.parent_code=a.area_code\n" +
            "WHERE\n" +
            "\ta.area_name = #{areaName}")
    Integer selectCountHouse(String areaName);
 
    @Select("<script> " +
            "SELECT\n" +
            "u.user_id 'order',\n" +
            "h.house_name doorNumber,\n" +
            "if(h.state=2,'租住','自主')isRent,\n" +
            "u.`name`,\n" +
            "'汉' nation,\n" +
            "if(u.is_partymember=1,'党员','群众')politicalOutlook,\n" +
            "'未知' maritalStatus,\n" +
            "u.phone,\n" +
            "'未知' education,\n" +
            "u.id_card,\n" +
            "'未知' company,\n" +
            "'未知' residence,\n" +
            "'未知' isPanZhiHua,\n" +
            "'未知' situation,\n" +
            "'未知' isContact,\n" +
            "'未知' major,\n" +
            "'未知' soldier,\n" +
            "'未知' disability,\n" +
            "'未知' lowIncomeHouseholds,\n" +
            "'未知' lowIncomePeople,\n" +
            "'未知' oldPeople,\n" +
            "'未知' specialServiceFamily,\n" +
            "'未知' keyPersonnel\n" +
            "FROM\n" +
            "sys_user u\n" +
            "left join com_mng_struct_house_user hu on hu.user_id=u.user_id\n"+
            "left join com_mng_struct_house h on hu.house_code=h.house_code\n"+
            "<if test='exportUserDTO.areaName != null and exportUserDTO.areaName.trim() != &quot;&quot;'>" +
            " JOIN com_mng_struct_area c ON u.area_id = c.id \n" +
            " </if> " +
            "<if test='exportUserDTO.areaName == null or exportUserDTO.areaName.trim() == &quot;&quot;'>" +
            "LEFT JOIN com_mng_struct_area c ON u.area_id = c.id \n" +
            " </if> " +
            "<if test='exportUserDTO.areaName != null and exportUserDTO.areaName.trim() != &quot;&quot;'>" +
            "AND c.`area_name` like concat(#{exportUserDTO.areaName},'%')  \n" +
            " </if> " +
            " where u.community_id=#{exportUserDTO.communityId} and u.type=1 " +
            "<if test='exportUserDTO.name != null and exportUserDTO.name.trim() != &quot;&quot;'>" +
            " and u.`name` like concat(#{exportUserDTO.name},'%')  \n" +
            " </if> " +
            "<if test='exportUserDTO.phone != null and exportUserDTO.phone.trim() != &quot;&quot;'>" +
            "AND u.phone like concat(#{exportUserDTO.phone},'%') " +
            " </if> " +
            " group by u.user_id  "+
            "</script>")
    List<EexcelUserDTO> selectExport(@Param("exportUserDTO") ExportUserDTO exportUserDTO);
    
    @Select("SELECT\n" +
            "\t COUNT(a.id)\n" +
            "FROM\n" +
            "\t com_pb_member_role a \n" +
            "WHERE\n" +
            "\t a.phone = #{phone}")
    Integer selectCountMemberRole(@Param("phone")String phone);
    
    @Select("SELECT\n" +
            "\t COUNT(a.id)\n" +
            "FROM\n" +
            "\t com_pb_service_team a \n" +
            "WHERE\n" +
            "\t a.phone = #{phone}")
    Integer selectCountTeam(@Param("phone")String phone);
    
    
    @Update("update com_pb_member_role u set u.phone=#{newphone},is_reg=1 where u.phone=#{oldphone}")
    void updateMemberRole(@Param("newphone")String newphone,@Param("oldphone")String oldphone);
    @Update("update com_pb_service_team u set u.phone=#{newphone},is_reg=1 where u.phone=#{oldphone}")
    void updateServiceTeam(@Param("newphone")String newphone,@Param("oldphone")String oldphone);
 
    @Select("SELECT\n" +
            "\t COUNT(ur.role_id) \n" +
            "FROM\n" +
            "\t sys_user u LEFT JOIN sys_user_role ur ON u.user_id = ur.user_id \n" +
            "\t LEFT JOIN sys_role r ON ur.role_id = r.role_id  \n" +
            "WHERE ur.role_id IS  NOT NULL AND  u.phone = #{phone} ")
    Integer selectCountSysUser(@Param("phone")String phone);
 
    @Select("update com_shop_store set sys_user_id = #{sysUserId} where phone = #{phone}")
    void updateStoreByPhone(@Param("phone")String phone, @Param("sysUserId")Long sysUserId);
}