package com.changhong.epc.parsing.service.loop.impl;
|
|
import com.changhong.epc.constter.base.loop.LoopBaseBean;
|
import com.changhong.epc.constter.base.loop.LoopBaseService;
|
import com.changhong.epc.constter.parsing.loop.LoopServiceConst;
|
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
|
import lombok.Setter;
|
import lombok.extern.slf4j.Slf4j;
|
|
import java.io.ByteArrayOutputStream;
|
import java.io.PrintStream;
|
import java.util.List;
|
|
@Slf4j
|
public abstract class SimplAbstractLoopSuper<T extends LoopBaseBean> extends LoopSuper implements LoopServiceConst {
|
|
@Setter
|
private LoopBaseService<T> loopBaseService;
|
|
@Override
|
public void businessHandle() {
|
List<T> list = list();
|
if(ObjectUtil.empty(list)){
|
return;
|
}
|
list.stream().forEach(this::forEach);
|
}
|
|
List<T> list(){
|
return getLoopBaseService().list();
|
}
|
|
void forEach(T t){
|
init(t);
|
try {
|
doService(t);
|
t.setDataStart(TREATED);
|
success(t);
|
}catch (Exception e){
|
log.error(e.getMessage(), e);
|
t.setDataStart(OVERDUE);
|
error(t, e);
|
}
|
distray(t);
|
}
|
|
void init(T t){}
|
|
abstract void doService(T t);
|
|
void distray(T t){}
|
|
void success(T t){
|
t.setErrTxt("成功");
|
getLoopBaseService().update(t);
|
}
|
|
void error(T t, Exception e){
|
|
ByteArrayOutputStream byteArrayOutputStream;
|
e.printStackTrace(new PrintStream(byteArrayOutputStream = new ByteArrayOutputStream()));
|
t.setErrTxt(byteArrayOutputStream.toString());
|
getLoopBaseService().update(t);
|
}
|
|
LoopBaseService<T> getLoopBaseService(){
|
if(loopBaseService == null){
|
throw new IllegalArgumentException("loopBaseService is null!");
|
}
|
return loopBaseService;
|
}
|
|
}
|