use of cn.cerc.jdb.core.DataSet in project summer-bean by cn-cerc.
the class Barcode128Template method add.
public Barcode128Template add(String barcode, String description) {
DataSet dataSet = this.getDataSet();
if (dataSet == null) {
dataSet = new DataSet();
this.setDataSet(dataSet);
}
dataSet.append();
dataSet.setField("Code_", barcode);
dataSet.setField("Name_", description);
return this;
}
use of cn.cerc.jdb.core.DataSet in project summer-bean by cn-cerc.
the class ImportExcel method readRecords.
public void readRecords(ImportRecord readHandle) throws Exception {
this.setReadHandle(readHandle);
DataSet ds = getDataSet();
while (ds.fetch()) {
readFileData(ds.getCurrent());
}
}
use of cn.cerc.jdb.core.DataSet in project summer-bean by cn-cerc.
the class ImportExcel method readFileData.
public DataSet readFileData(Record record) throws Exception {
FileItem file = this.getFile(record);
// 获取Excel文件对象
Workbook rwb = Workbook.getWorkbook(file.getInputStream());
// 获取文件的指定工作表 默认的第一个
Sheet sheet = rwb.getSheet(0);
Template template = this.getTemplate();
if (template.getColumns().size() != sheet.getColumns())
throw new RuntimeException(String.format("导入的文件:<b>%s</b>, 其总列数为 %d,而模版总列数为 %d 二者不一致,无法导入!", file.getName(), sheet.getColumns(), template.getColumns().size()));
DataSet ds = new DataSet();
for (int row = 0; row < sheet.getRows(); row++) {
if (row == 0) {
for (int col = 0; col < sheet.getColumns(); col++) {
Cell cell = sheet.getCell(col, row);
String value = cell.getContents();
String title = template.getColumns().get(col).getName();
if (!title.equals(value))
throw new RuntimeException(String.format("导入的文件:<b>%s</b>,其标题第 %d 列为【 %s】, 模版中为【%s】,二者不一致,无法导入!", file.getName(), col + 1, value, title));
}
} else {
ds.append();
for (int col = 0; col < sheet.getColumns(); col++) {
Cell cell = sheet.getCell(col, row);
String value = cell.getContents();
if (cell.getType() == CellType.NUMBER) {
NumberCell numberCell = (NumberCell) cell;
double d = numberCell.getValue();
value = formatFloat("0.######", d);
}
Column column = template.getColumns().get(col);
if (!column.validate(row, col, value)) {
ColumnValidateException err = new ColumnValidateException("其数据不符合模版要求,当前值为:" + value);
err.setTitle(column.getName());
err.setValue(value);
err.setCol(col);
err.setRow(row);
if (errorHandle == null || !errorHandle.process(err))
throw err;
}
ds.setField(column.getCode(), value);
}
if (readHandle != null && !readHandle.process(ds.getCurrent()))
break;
}
}
return ds;
}
use of cn.cerc.jdb.core.DataSet in project summer-bean by cn-cerc.
the class RemoteService method exec.
@Override
public boolean exec(Object... args) {
if (args.length > 0) {
Record headIn = getDataIn().getHead();
if (args.length % 2 != 0)
throw new RuntimeException("传入的参数数量必须为偶数!");
for (int i = 0; i < args.length; i = i + 2) headIn.setField(args[i].toString(), args[i + 1]);
}
String postParam = getDataIn().getJSON();
String url = String.format("http://%s/services/%s", this.host, this.service);
if (token != null)
url = url + "?token=" + token;
try {
log.debug("datain: " + postParam);
// String rst = CURL.doPost(url, params, "UTF-8");
String rst = postData(url, postParam);
log.debug("datatout:" + rst);
if (rst == null)
return false;
JSONObject json = JSONObject.fromObject(rst);
if (json.get("message") != null) {
this.setMessage(json.getString("message"));
}
if (json.containsKey("data")) {
JSONArray datas = json.getJSONArray("data");
if (datas != null && datas.size() > 0) {
if (dataOut == null)
dataOut = new DataSet();
else
dataOut.close();
dataOut.setJSON(datas.getString(0));
}
}
return json.getBoolean("result");
} catch (Exception e) {
log.error(e.getMessage(), e);
if (e.getCause() != null)
setMessage(e.getCause().getMessage());
else
setMessage(e.getMessage());
return false;
}
}
use of cn.cerc.jdb.core.DataSet in project summer-mis by cn-cerc.
the class SvrCustomMenus method append.
public boolean append() {
DataSet dataIn = getDataIn();
String corpNo = dataIn.getHead().getString("CorpNo_");
BuildQuery f1 = new BuildQuery(this);
BuildQuery f2 = new BuildQuery(this);
f1.byField("Custom_", true);
f1.add("select * from %s ", SystemTable.get(SystemTable.getAppMenus));
SqlQuery ds1 = f1.open();
f2.byField("CorpNo_", corpNo);
f2.add("select * from %s ", SystemTable.get(SystemTable.getCustomMenus));
SqlQuery ds2 = f2.open();
while (!ds2.eof()) {
if (!dataIn.locate("id", ds2.getString("ID_")))
ds2.delete();
else
ds2.next();
}
while (dataIn.fetch()) {
if (!ds1.locate("ID_", dataIn.getString("id")))
throw new RuntimeException("菜单错误,请核查!");
if (!ds2.locate("ID_", dataIn.getString("id"))) {
ds1.locate("ID_", dataIn.getString("id"));
ds2.append();
ds2.setField("CorpNo_", corpNo);
ds2.setField("Code_", ds1.getString("Code_"));
ds2.setField("Name_", ds1.getString("Name_"));
ds2.setField("AppUser_", getUserCode());
ds2.setField("AppDate_", TDateTime.Now().getDate());
ds2.setField("Remark_", "");
ds2.post();
}
}
return true;
}
Aggregations