|
|
|
@ -10,9 +10,11 @@ import org.hibernate.Session; |
|
|
|
|
import org.hibernate.query.NativeQuery; |
|
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import web.model.DataModelForm; |
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.math.BigInteger; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.LinkedList; |
|
|
|
|
import java.util.List; |
|
|
|
@ -21,14 +23,14 @@ import java.util.concurrent.Future; |
|
|
|
|
|
|
|
|
|
@Service |
|
|
|
|
@Model(HuaWeiCloud.class) |
|
|
|
|
public class DataService extends BaseService{ |
|
|
|
|
public class DataService extends BaseService { |
|
|
|
|
|
|
|
|
|
private ThreadPoolTaskExecutor executor; |
|
|
|
|
|
|
|
|
|
private boolean isStop; |
|
|
|
|
|
|
|
|
|
public void start(Integer threadSize){ |
|
|
|
|
isStop=false; |
|
|
|
|
public void start(Integer threadSize) { |
|
|
|
|
isStop = false; |
|
|
|
|
executor = new ThreadPoolTaskExecutor(); |
|
|
|
|
executor.setCorePoolSize(threadSize); |
|
|
|
|
executor.setMaxPoolSize(threadSize); |
|
|
|
@ -36,13 +38,13 @@ public class DataService extends BaseService{ |
|
|
|
|
executor.setWaitForTasksToCompleteOnShutdown(true); |
|
|
|
|
executor.initialize(); |
|
|
|
|
log.info("开始"); |
|
|
|
|
new Thread(()->{ |
|
|
|
|
new Thread(() -> { |
|
|
|
|
getCid(threadSize); |
|
|
|
|
}).start(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void stop(){ |
|
|
|
|
if(executor!=null) { |
|
|
|
|
public void stop() { |
|
|
|
|
if (executor != null) { |
|
|
|
|
executor.shutdown(); |
|
|
|
|
isStop = true; |
|
|
|
|
} |
|
|
|
@ -63,7 +65,7 @@ public class DataService extends BaseService{ |
|
|
|
|
} |
|
|
|
|
for (; i <= 15717791; ) { |
|
|
|
|
|
|
|
|
|
if(isStop){ |
|
|
|
|
if (isStop) { |
|
|
|
|
log.info("停止"); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
@ -75,8 +77,8 @@ public class DataService extends BaseService{ |
|
|
|
|
cid.add(i++); |
|
|
|
|
} |
|
|
|
|
do { |
|
|
|
|
Integer c=cid.poll(); |
|
|
|
|
if(c!=null) { |
|
|
|
|
Integer c = cid.poll(); |
|
|
|
|
if (c != null) { |
|
|
|
|
try { |
|
|
|
|
executor.execute(() -> { |
|
|
|
|
save(c); |
|
|
|
@ -120,10 +122,55 @@ public class DataService extends BaseService{ |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}catch (Exception e){ |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error(e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Long rowCount(DataModelForm form) { |
|
|
|
|
StringBuffer sql=new StringBuffer(); |
|
|
|
|
if(form.getTypeIds()==null) { |
|
|
|
|
sql.append("select count(*) from data"); |
|
|
|
|
}else{ |
|
|
|
|
union(sql,count,form.getTypeIds()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(form.getTitle())) { |
|
|
|
|
sql.append(" where title like '%").append(form.getTitle()).append("%'"); |
|
|
|
|
} |
|
|
|
|
log.info(sql); |
|
|
|
|
BigInteger count = getHibernateTemplate().execute(session -> (BigInteger) session.createNativeQuery(sql.toString()).getSingleResult()); |
|
|
|
|
return count.longValue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static final String union = "union all "; |
|
|
|
|
private static final String tableAlise="A"; |
|
|
|
|
private static final String clazz_="1 as clazz_"; |
|
|
|
|
private static final String head = "select "+tableAlise+".*,"+clazz_+" from ("; |
|
|
|
|
private static final String count="select count(*) from ("; |
|
|
|
|
|
|
|
|
|
private void union(StringBuffer sql,String head,List<Integer> ids){ |
|
|
|
|
sql.append(head); |
|
|
|
|
ids.forEach(id -> sql.append(union).append("select * from data_").append(id).append(" ")); |
|
|
|
|
sql.replace(0, head.length() + union.length(), head); |
|
|
|
|
sql.append(") ").append(tableAlise); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public List find(DataModelForm form,Integer firstResult,Integer maxResults) { |
|
|
|
|
StringBuffer sql = new StringBuffer(); |
|
|
|
|
if (form.getTypeIds() != null && !form.getTypeIds().isEmpty()) { |
|
|
|
|
union(sql,head,form.getTypeIds()); |
|
|
|
|
} else { |
|
|
|
|
sql.append("select *,").append(clazz_).append(" from data"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(form.getTitle())) { |
|
|
|
|
sql.append(" where title like '%").append(form.getTitle()).append("%'"); |
|
|
|
|
} |
|
|
|
|
log.info(sql); |
|
|
|
|
return getHibernateTemplate().execute(session -> session.createNativeQuery(sql.toString(),DataModel.class).setFirstResult(firstResult).setMaxResults(maxResults).getResultList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|