|
@@ -1,43 +1,62 @@
|
|
|
package com.xiaoan.dao.backend.provider;
|
|
|
|
|
|
import com.xiaoan.domain.dto.request.SceneProRequest;
|
|
|
+import lombok.extern.log4j.Log4j2;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* Created by Hb_zzZ on 2020/3/3.
|
|
|
*/
|
|
|
+@Log4j2
|
|
|
public class SceneProvider {
|
|
|
|
|
|
- public String findAllBySearchKey(SceneProRequest param, List<Long> ids){
|
|
|
+ public String findAllBySearchKey(SceneProRequest param, Long userId){
|
|
|
StringBuffer sql = new StringBuffer("SELECT a.id, a.thumb, a.view_count, " +
|
|
|
"a.scene_name, a.create_time, b.sn_code, c.real_name " +
|
|
|
"FROM tb_scene_pro a LEFT JOIN tb_camera b ON a.camera_id = b.id " +
|
|
|
"LEFT JOIN tb_user c ON a.user_id = c.id where a.rec_status = 'A' ");
|
|
|
|
|
|
- if(param.getStartTime() != null && param.getEndTime() != null){
|
|
|
- sql.append(" and a.create_time >= ").append(param.getStartTime());
|
|
|
- sql.append(" and a.create_time <= ").append(param.getEndTime());
|
|
|
+ if(StringUtils.isNotBlank(param.getStartTime()) && StringUtils.isNotBlank(param.getEndTime())){
|
|
|
+ sql.append(" and a.create_time >= ").append("'").append(param.getStartTime()).append("'");
|
|
|
+ sql.append(" and a.create_time <= ").append("'").append(param.getEndTime()).append("'");
|
|
|
}
|
|
|
if(StringUtils.isNotEmpty(param.getSearchKey())){
|
|
|
- sql.append("and a.scene_name like '%").append(param.getSearchKey()).append("%'");
|
|
|
- }
|
|
|
- if(ids != null && ids.size() > 0){
|
|
|
- sql.append(" and c.id in(");
|
|
|
- for(int i = 0, len = ids.size(); i < len; i ++){
|
|
|
- if(i == len){
|
|
|
- sql.append(ids.get(i));
|
|
|
- }else {
|
|
|
- sql.append(ids.get(i)).append(",");
|
|
|
- }
|
|
|
- }
|
|
|
+ sql.append(" and ( a.scene_name like '%").append(param.getSearchKey()).append("%'");
|
|
|
+ sql.append("or c.real_name like '%").append(param.getSearchKey()).append("%' )");
|
|
|
}
|
|
|
+
|
|
|
+// if(ids != null && ids.size() > 0){
|
|
|
+// sql.append(" and c.id in(");
|
|
|
+// for(int i = 0, len = ids.size(); i < len; i ++){
|
|
|
+//
|
|
|
+// if(len == 1){
|
|
|
+// sql.append(ids.get(i));
|
|
|
+// } else {
|
|
|
+// if (i == len-1 ) {
|
|
|
+// sql.append(ids.get(i));
|
|
|
+// } else {
|
|
|
+// sql.append(ids.get(i)).append(",");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// sql.append(" )");
|
|
|
+// }
|
|
|
+//
|
|
|
if(param.getStatus() != null){
|
|
|
sql.append(" and a.status = ").append(param.getStatus());
|
|
|
}
|
|
|
|
|
|
+ if (userId != null) {
|
|
|
+ sql.append(" and a.user_id = ").append(userId);
|
|
|
+ }
|
|
|
+
|
|
|
sql.append(" order by create_time desc");
|
|
|
+
|
|
|
+ log.info("sql: {}", sql.toString());
|
|
|
+
|
|
|
return sql.toString();
|
|
|
}
|
|
|
|
|
@@ -48,39 +67,42 @@ public class SceneProvider {
|
|
|
* @param ids
|
|
|
* @return
|
|
|
*/
|
|
|
- public String findAllBySearchKeyAndUserId(SceneProRequest param, List<Long> ids, Long userId){
|
|
|
- StringBuffer sql = new StringBuffer("SELECT a.id, a.thumb, a.view_count, " +
|
|
|
- "a.scene_name, a.create_time, b.sn_code, c.real_name " +
|
|
|
- "FROM tb_scene_pro a LEFT JOIN tb_camera b ON a.camera_id = b.id " +
|
|
|
- "LEFT JOIN tb_user c ON a.user_id = c.id where a.rec_status = 'A' ");
|
|
|
-
|
|
|
- if (userId != null) {
|
|
|
- sql.append(" and a.user_id = ").append(userId);
|
|
|
- }
|
|
|
-
|
|
|
- if(param.getStartTime() != null && param.getEndTime() != null){
|
|
|
- sql.append(" and a.create_time >= ").append(param.getStartTime());
|
|
|
- sql.append(" and a.create_time <= ").append(param.getEndTime());
|
|
|
- }
|
|
|
- if(StringUtils.isNotEmpty(param.getSearchKey())){
|
|
|
- sql.append("and a.scene_name like '%").append(param.getSearchKey()).append("%'");
|
|
|
- }
|
|
|
- if(ids != null && ids.size() > 0){
|
|
|
- sql.append(" and c.id in(");
|
|
|
- for(int i = 0, len = ids.size(); i < len; i ++){
|
|
|
- if(i == len){
|
|
|
- sql.append(ids.get(i));
|
|
|
- }else {
|
|
|
- sql.append(ids.get(i)).append(",");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if(param.getStatus() != null){
|
|
|
- sql.append(" and a.status = ").append(param.getStatus());
|
|
|
- }
|
|
|
-
|
|
|
- sql.append(" order by create_time desc");
|
|
|
- return sql.toString();
|
|
|
- }
|
|
|
+// public String findAllBySearchKeyAndUserId(SceneProRequest param, List<Long> ids, Long userId){
|
|
|
+// StringBuffer sql = new StringBuffer("SELECT a.id, a.thumb, a.view_count, " +
|
|
|
+// "a.scene_name, a.create_time, b.sn_code, c.real_name " +
|
|
|
+// "FROM tb_scene_pro a LEFT JOIN tb_camera b ON a.camera_id = b.id " +
|
|
|
+// "LEFT JOIN tb_user c ON a.user_id = c.id where a.rec_status = 'A' ");
|
|
|
+//
|
|
|
+// if (userId != null) {
|
|
|
+// sql.append(" and a.user_id = ").append(userId);
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(StringUtils.isNotBlank(param.getStartTime()) && StringUtils.isNotBlank(param.getEndTime())){
|
|
|
+// sql.append(" and a.create_time >= ").append("'").append(param.getStartTime()).append("'");
|
|
|
+// sql.append(" and a.create_time <= ").append("'").append(param.getEndTime()).append("'");
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(StringUtils.isNotEmpty(param.getSearchKey())){
|
|
|
+// sql.append("or a.scene_name like '%").append(param.getSearchKey()).append("%'");
|
|
|
+// sql.append("or c.real_name like '%").append(param.getSearchKey()).append("%'");
|
|
|
+// }
|
|
|
+// if(ids != null && ids.size() > 0){
|
|
|
+// sql.append(" and c.id in(");
|
|
|
+// for(int i = 0, len = ids.size(); i < len; i ++){
|
|
|
+// if(i == len){
|
|
|
+// sql.append(ids.get(i));
|
|
|
+// }else {
|
|
|
+// sql.append(ids.get(i)).append(",");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// sql.append(" )");
|
|
|
+// }
|
|
|
+// if(param.getStatus() != null){
|
|
|
+// sql.append(" and a.status = ").append(param.getStatus());
|
|
|
+// }
|
|
|
+//
|
|
|
+// sql.append(" order by create_time desc");
|
|
|
+// return sql.toString();
|
|
|
+// }
|
|
|
|
|
|
}
|