You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
4.2 KiB

9 months ago
package com.dsideal.base.Res.Model;
9 months ago
import com.jfinal.kit.Kv;
import com.jfinal.kit.StrKit;
9 months ago
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.SqlPara;
import com.jfinal.plugin.activerecord.Record;
9 months ago
import java.util.ArrayList;
import java.util.List;
9 months ago
public class ResourceModel {
9 months ago
//云南省
public final String YUNNAN = "530000";
9 months ago
/**
* code
*
* @param area_id
* @return
*/
public String getAreaCode(String area_id) {
String sql = "select * from t_dm_area where id=?";
return Db.findFirst(sql, area_id).getStr("area_code");
}
/**
*
*
* @param identity_id
* @param person_id
* @return
*/
public String getAreaCode(int identity_id, String person_id) {
String area_code = "";
//省管理员直接返回云南省的code
9 months ago
if (identity_id == 1) area_code = YUNNAN;
9 months ago
//如果是市州用户,直接返回市州用户的行政区划
String sql = "select * from t_sys_loginperson where person_id=?";
Record record = Db.findFirst(sql, person_id);
if (identity_id == 2) {
String city_id = record.getStr("city_id");
area_code = getAreaCode(city_id);
}
if (identity_id == 3) {
String area_id = record.getStr("area_id");
area_code = getAreaCode(area_id);
}
return area_code;
}
9 months ago
/**
*
*
9 months ago
* @param page
* @param limit
9 months ago
*/
9 months ago
public Page<Record> getZskPage(String person_id, int type_id, String keyword, String area_code, int page, int limit) {
9 months ago
List<String> idList = new ArrayList<>();
//1、如果是云南省:查看所有自己发布的文档,不管是省,市,县,都能看到全省的文档
idList.add(YUNNAN);
//如果是省管理员
if (area_code.equals(YUNNAN)) {
//什么也不做
}
//2、如果是市州,查看省发布的+自己本市州发布的文档,市州的判断条件是6位的area_code最后两位是00
else if (area_code.substring(area_code.length() - 2, area_code.length()).equals("00")) {
idList.add(area_code);//只添加市
} else {
//县区管理员
idList.add(area_code.substring(0, 4) + "00");//市
idList.add(area_code);//县区
}
Kv kv = new Kv();
kv.set("type_id", type_id);
kv.set("idList", idList);
if (!StrKit.isBlank(keyword)) {
kv.set("keyword", keyword);
}
9 months ago
SqlPara sqlPara = Db.getSqlPara("Resource.getZskPage", kv);
Page<Record> records = Db.paginate(page, limit, sqlPara);
for (Record record : records.getList()) {
String database_person_id = record.getStr("person_id");
9 months ago
record.set("can_del", database_person_id.equals(person_id));
9 months ago
}
return records;
9 months ago
}
/**
*
*
* @param id
*/
public void delZskDocument(int id) {
9 months ago
String sql = "delete from t_zsk_files where id=?";
9 months ago
Db.update(sql, id);
}
9 months ago
/**
*
9 months ago
*
9 months ago
* @param name
* @param file_name
* @param type_id
* @param identity_id
* @param area_code
*/
9 months ago
public void uploadZskDocument(String name, String file_name, int type_id, int identity_id, String area_code, String person_id) {
9 months ago
Record record = new Record();
record.set("name", name);
record.set("file_name", file_name);
record.set("type_id", type_id);
record.set("identity_id", identity_id);
record.set("area_code", area_code);
9 months ago
record.set("person_id", person_id);
9 months ago
Db.save("t_zsk_files", "id", record);
}
9 months ago
/**
*
* @param id
* @return
*/
public Record getZskDocument(int id){
String sql = "select * from t_zsk_files where id=?";
return Db.findFirst(sql, id);
}
9 months ago
}