package com.yc.sdk.shopping.action.jiazhuang.task;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.dao.DataAccessException;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import com.google.gson.JsonArray;
|
import com.google.gson.JsonObject;
|
import com.yc.action.BaseAction;
|
import com.yc.entity.DataSourceEntity;
|
import com.yc.multiData.MultiDataSource;
|
import com.yc.multiData.SpObserver;
|
import com.yc.sdk.shopping.entity.PanicBuyingEntity;
|
|
@Controller
|
@RequestMapping("/shopping/panicBuyingTaskTest.do")
|
public class PanicBuyingTaskTest extends BaseAction {
|
@Autowired
|
PanicBuyingTaskIfc panicBuyingTaskIfc ;
|
@RequestMapping(params = "m=startCron")
|
public void getAddressList(HttpServletRequest request, HttpServletResponse response) {
|
JsonObject json = new JsonObject();
|
JsonObject errJson = new JsonObject();
|
String docCode = request.getParameter("doccode");
|
try {
|
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
|
SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
|
PanicBuyingEntity panicBuyingEntity = new PanicBuyingEntity();
|
panicBuyingEntity.setDocCode(docCode);
|
panicBuyingTaskIfc.addStatusTask(dataSourceEntity, panicBuyingEntity);
|
json.addProperty("state", "success");
|
this.printJson(response, json.toString());
|
return;
|
}catch(DataAccessException e ) {
|
errJson.addProperty("warning", e.getCause() != null ?e.getCause().getMessage():e.getMessage());
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return;
|
}catch(Exception e){
|
errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return;
|
}finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
|
@RequestMapping(params = "m=getTaskList")
|
public void getTaskList(HttpServletRequest request, HttpServletResponse response) {
|
JsonObject json = new JsonObject();
|
JsonObject errJson = new JsonObject();
|
try {
|
|
JsonArray jsonArray = new JsonArray();
|
PanicBuyingTask.task.forEach((taskName, future) -> {
|
//System.out.println(key + ":" + value);
|
jsonArray.add(taskName);
|
});
|
json.add("list", jsonArray);
|
json.addProperty("state", "success");
|
this.printJson(response, json.toString());
|
return;
|
}catch(DataAccessException e ) {
|
errJson.addProperty("warning", e.getCause() != null ?e.getCause().getMessage():e.getMessage());
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return;
|
}catch(Exception e){
|
errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return;
|
}
|
}
|
}
|