package com.tecnova.ifrcs.api.mapper.provider;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.ibatis.annotations.Param;
import com.tecnova.ifrcs.api.entity.EventsKeys;
/**
* @ClassName: EventsKeysSqlProvider
* @Description: 查询自定义事件sql拼接
* @author fk
* @date 2018年8月8日 上午9:15:53
*
*/
public class EventsKeysSqlProvider {
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”);
final String time = sdf.format(new Date());
final String DbName = “tecnova_ifrcs_data”;
final String tables = “.events_keys”;
/**
* @Title: selectEventsKeys
* @Description: 展示自定义事件列表
* @param @param userId
* @param @param pid
* @param @param status
* @param @param search
* @param @return 参数
* @return String 返回类型
* @throws
*/
public String selectEventsKeys(@Param("userId") long userId,
@Param("pid") Integer pid, @Param("status") Integer status,
@Param("search") String search) {
//status null全部,0未开始,1采集中,2停止
StringBuilder sql = new StringBuilder();
sql.append("SELECT * from tecnova_ifrcs_data").append(userId)
.append(".events_keys WHERE 1=1 ");
if (status != null) {
sql.append(" AND `status` =" + status);
}
if (search != null) {
sql.append(" AND `title` LIKE '%" + search + "%'")
.append(" OR `url` LIKE '%" + search + "%'")
.append(" OR `description` LIKE '%" + search + "%'")
.append(" OR `company` LIKE '%" + search + "%'")
.append(" OR `person` LIKE '%" + search + "%'");
}
if (pid != null) {
sql.append(" AND `p_id` = " + pid);
}
sql.append(" order by is_focus desc, update_time desc,id desc");
System.out.println("&&&&&&&查询自定义事件&&&&&&&&&&&&&&& sql = " + sql.toString());
return sql.toString();
}
}
package com.tecnova.ifrcs.api.mapper;
import com.tecnova.ifrcs.api.driver.InsertByMapLanguageDriver;
import com.tecnova.ifrcs.api.driver.UpdateByMapLanguageDriver;
import com.tecnova.ifrcs.api.driver.WhereInLanguageDriver;
import com.tecnova.ifrcs.api.entity.EventEntity;
import com.tecnova.ifrcs.api.entity.EventsKeys;
import com.tecnova.ifrcs.api.mapper.provider.DailyPaperSqlProvider;
import com.tecnova.ifrcs.api.mapper.provider.EventsKeysSqlProvider;
import org.apache.ibatis.annotations.*;
import java.util.List;
import java.util.Map;
public interface EventMapper {
final String DBNAME = “tecnova_ifrcs_data${user_id}”;
final String TABLE = DBNAME + “.” + “user_events”;
@Select("SELECT * FROM " + TABLE + " WHERE id = #{id}")
EventEntity first(@Param("id") long id, @Param("user_id") long user_id);
@Select("SELECT * FROM " + TABLE + " order by is_focus desc, updated desc")
List select(@Param("user_id") long user_id);
@Select("SELECT * FROM " + TABLE + " WHERE status = #{status} order by is_focus desc, updated desc")
List selectByStatus(@Param("user_id") long user_id,@Param("status") int status);
@Lang(WhereInLanguageDriver.class)
@Select("SELECT * FROM " + TABLE + " WHERE id IN (#{ids})")
List selectWithIds(@Param("ids") List ids, @Param("user_id") long user_id);
@Lang(InsertByMapLanguageDriver.class)
@Insert("INSERT INTO " + TABLE + " (#{map})")
boolean save(@Param("map") Map map, @Param("user_id") long user_id);
@Lang(UpdateByMapLanguageDriver.class)
@Update("UPDATE " + TABLE + " (#{map}) WHERE id = #{id}")
boolean update(@Param("map") Map map, @Param("id") long id, @Param("user_id") long user_id);
@Update("UPDATE " + TABLE + " set status = #{status},updated = #{updated} WHERE id = #{id}")
boolean updated(@Param("status") int status, @Param("updated")Long updated, @Param("id") long id, @Param("user_id") long user_id);
@Delete("DELETE FROM " + TABLE + " WHERE id = #{id}")
boolean delete(@Param("id") long id, @Param("user_id") long user_id);
@Select("select count(1) as ct from tecnova_ifrcs_data.user_events_${userId} where event_name = #{name}")
boolean isExist(@Param("name") String name, @Param("userId") long userId);
//---------------------------------重构------------------------------------------
final String DbName = " tecnova_ifrcs_data${userId}";
final String tables = DbName + ".events_keys";
@SelectProvider(type = EventsKeysSqlProvider.class, method = "selectEventsKeys")
List selectEventsKeys(@Param("userId") long userId,@Param("pid")Integer PId, @Param("status")Integer status,@Param("search")String search);
@DeleteProvider(type = EventsKeysSqlProvider.class, method = "deleteEventKeys")
int deleteEventKeys(@Param("userId") long userId,@Param("pid")Integer pid, @Param("ids")String ids);
@SelectProvider(type = EventsKeysSqlProvider.class, method = "selectEventsKeysById")
EventsKeys selectEventsKeysById(@Param("userId") long userId,@Param("pId")Integer pId, @Param("id")String id);
//-分页修复
@UpdateProvider(type = EventsKeysSqlProvider.class, method = "updateStatus")
boolean updateStatus(@Param("userId") long userId,@Param("pid")Integer pid, @Param("time")String time,@Param("page")Integer page,@Param("size")Integer size);
//
@InsertProvider(type = EventsKeysSqlProvider.class, method = "createEvent")
int createEvent(@Param("userId") long userId,@Param("event") EventsKeys events);
@Lang(UpdateByMapLanguageDriver.class)
@Update("UPDATE " + tables + " (#{map}) WHERE id in (${ids})")
int updateEvent(@Param("map") Map map, @Param("ids") String ids, @Param("userId") long user_id);
@Lang(UpdateByMapLanguageDriver.class)
@Update("UPDATE " + tables + " (#{map}) WHERE id in (${ids}) AND p_id = ${pId}")
int updateEventByPid(@Param("map") Map map, @Param("ids") String ids, @Param("userId") long user_id,@Param("pId") Integer pId);
//
@UpdateProvider(type = EventsKeysSqlProvider.class, method = “updateEventById”)
int updateEventById(@Param(“userId”) long userId,@Param(“pId”) Integer pId,@Param(“event”) EventsKeys events,@Param(“id”) String id);
}