main
HuangHai 4 months ago
parent 9c0e4dd878
commit 106404c29b

@ -18,18 +18,6 @@ import java.util.List;
public class DataAuthorityController extends Controller {
DataAuthorityModel dm = new DataAuthorityModel();
/**
*
*/
@Before({POST.class})
@IsLoginInterface({})
public void syncResource() {
Kv kv = dm.syncResource();
kv.set("success", true);
kv.set("message", "共同步了" + kv.getInt("count") + "条数据,共" + kv.getInt("total") + "条数据");
renderJson(kv);
}
/**
*
*

@ -10,40 +10,6 @@ import java.util.List;
@SuppressWarnings("unchecked")
public class DataAuthorityModel {
/**
*
*
*
* @return
*/
public static Kv syncResource() {
//找出所有需要同步的资源类型
String sql = "select * from t_sys_resource_type";
List<Record> list = Db.find(sql);
int count = 0;
for (Record record : list) {
String sync_sql = record.getStr("sync_sql");
if (sync_sql != null) {
String resource_type_code = record.getStr("resource_type_code");
sql = "delete from t_sys_resource where resource_type_code=?";
Db.update(sql, resource_type_code);
List<Record> records = Db.find(sync_sql);
for (int i = 0; i < records.size(); i++) {
Record r = records.get(i);
String resource_id = r.getStr("resource_id");
String resource_name = r.getStr("resource_name");
sql = "insert into t_sys_resource(resource_type_code,resource_id,resource_name) values(?,?,?)";
Db.update(sql, resource_type_code, resource_id, resource_name);
count++;
}
}
}
sql = "select count(1) as c from t_sys_resource";
Record record = Db.findFirst(sql);
int total = record.getInt("c");
return Kv.by("total", total).set("count", count);
}
/**
*
*

Loading…
Cancel
Save