package restcontroller.webmanage.saletool.phonebook; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.mysql.cj.x.protobuf.MysqlxCrud; import common.Controller; import common.YosException; import common.annotation.API; import common.data.*; import restcontroller.R; public class PhoneBook2 extends Controller { /** * 构造函数 * * @param content */ public PhoneBook2(JSONObject content) throws YosException { super(content); } @API(title = "通讯录新增或编辑", apiversion = R.ID20240516144302.v1.class) public String insertOrUpdate() throws YosException { Long sys_phonebookid = content.getLongValue("sys_phonebookid"); if (sys_phonebookid <= 0) { sys_phonebookid = createTableID("sys_phonebook"); InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_phonebook"); insertSQL.setSiteid(siteid); insertSQL.setUniqueid(sys_phonebookid); insertSQL.setValue("userid", userid); insertSQL.setValue("qq", content.getStringValue("qq")); insertSQL.setValue("phonenumber", content.getStringValue("phonenumber")); insertSQL.setValue("wechatnum", content.getStringValue("wechatnum")); insertSQL.setValue("sys_phonebookgroupid", content.getLongValue("sys_phonebookgroupid")); insertSQL.setValue("name", content.getStringValue("name")); insertSQL.setValue("remarks", content.getStringValue("remarks")); insertSQL.setValue("depname", getDepartment(departmentid).getString("depname")); insertSQL.setValue("sourcetable", ""); insertSQL.setValue("sourceid", 0); insertSQL.insert(); } else { UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sys_phonebook"); updateSQL.setSiteid(siteid); updateSQL.setUniqueid(sys_phonebookid); updateSQL.setValue("userid", userid); updateSQL.setValue("qq", content.getStringValue("qq")); updateSQL.setValue("phonenumber", content.getStringValue("phonenumber")); updateSQL.setValue("wechatnum", content.getStringValue("wechatnum")); updateSQL.setValue("sys_phonebookgroupid", content.getLongValue("sys_phonebookgroupid")); updateSQL.setValue("name", content.getStringValue("name")); updateSQL.setValue("remarks", content.getStringValue("remarks")); updateSQL.update(); } Row row = new Row(); row.put("sys_phonebookid", sys_phonebookid); return getSucReturnObject().toString(); } @API(title = "通讯录删除", apiversion = R.ID20240516144402.v1.class) public String delete() throws YosException { JSONArray sys_phonebookids = content.getJSONArray("sys_phonebookids"); DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sys_phonebook"); deleteSQL.setSiteid(siteid); deleteSQL.setWhere("sys_phonebookid", sys_phonebookids.toArray()); deleteSQL.delete(); return getSucReturnObject().toString(); } @API(title = "通讯录列表", apiversion = R.ID20240516144502.v1.class) public String list() throws YosException { StringBuffer where = new StringBuffer(" 1=1 "); if (content.containsKey("where")) { JSONObject whereObject = content.getJSONObject("where"); if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) { where.append(" and ("); where.append("t1.name like'%").append(whereObject.getString("condition")).append("%' "); where.append("or t1.remarks like'%").append(whereObject.getString("condition")).append("%' "); where.append(")"); } if (whereObject.containsKey("groupname") && !"".equals(whereObject.getString("groupname"))) { where.append(" and ("); where.append("t2.groupname like'%").append(whereObject.getString("groupname")).append("%' "); where.append(")"); } } QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_phonebook" , "sys_phonebookid", "name", "qq", "wechatnum", "phonenumber", "remarks","sys_phonebookgroupid").setTableAlias("t1"); querySQL.addJoinTable(JOINTYPE.inner, "sys_phonebookgroup", "t2", "t2.sys_phonebookgroupid=t1.sys_phonebookgroupid and t2.siteid=t1.siteid", "groupname"); querySQL.setWhere("t2.classid", 1); querySQL.setSiteid(siteid); querySQL.setWhere(where.toString()); querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting); Rows rows = querySQL.query(); return getSucReturnObject().setData(rows).toString(); } @API(title = "小程序通讯录列表", apiversion = R.ID20240516144602.v1.class) public String applist() { return getSucReturnObject().toString(); } @API(title = "通讯录分组列表", apiversion = R.ID20240516150902.v1.class) public String phonebookgrouplist() throws YosException { if (pageSorting.equals("''")) { pageSorting = "t1.sequence"; } QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_phonebookgroup").setTableAlias("t1"); querySQL.setWhere("classid", 1); querySQL.setWhere("isenable", 1); querySQL.setSiteid(siteid); querySQL.setOrderBy(pageSorting); Rows rows = querySQL.query(); return getSucReturnObject().setData(rows).toString(); } }