hu пре 2 година
родитељ
комит
fafda41608

+ 10 - 11
src/custom/restcontroller/sale/aftersalesmag/aftersalesmag.java

@@ -77,17 +77,16 @@ public class aftersalesmag extends Controller {
         ArrayList<Long> ids = rows.toArrayList("sa_aftersalesmagid", new ArrayList<>());
         //查询反退金额
         RowsMap aftersalesmagReturnAmountRowsMap = Aftersalesmag.getAftersalesmagReturnAmount(this, ids);
-        if(!rows.isEmpty()) {
-        	  for (Row row : rows) {
-
-        	       	 Long id = row.getLong("sa_aftersalesmagid");
-        	            if (aftersalesmagReturnAmountRowsMap.get(id.toString()).isNotEmpty()) {
-        	                   row.put("returnamount", aftersalesmagReturnAmountRowsMap.get(id.toString()).get(0).getBigDecimal("returnamount").toPlainString());
-        	               } else {
-        	                   row.put("returnamount", 0);
-        	               }
-        	       
-        			}
+
+        for (Row row : rows) {
+
+            Long id = row.getLong("sa_aftersalesmagid");
+            if (aftersalesmagReturnAmountRowsMap.get(id.toString()).isNotEmpty()) {
+                row.put("returnamount", aftersalesmagReturnAmountRowsMap.get(id.toString()).get(0).getBigDecimal("returnamount").toPlainString());
+            } else {
+                row.put("returnamount", 0);
+            }
+
         }
         return getSucReturnObject().setData(rows).toString();
     }

+ 1 - 3
src/custom/restcontroller/sale/cashbill/cashbill.java

@@ -337,9 +337,7 @@ public class cashbill extends Controller {
         } else {
             Rows rowscount = dbConnect.runSqlQuery(
                     "select status from sa_cashbill where sa_cashbillid=" + sa_cashbillid);
-            if (rowscount.isEmpty()) {
-                return getErrReturnObject().setErrMsg("此收支凭证不存在").toString();
-            } else {
+            if (rowscount.isNotEmpty()){
                 if (!rowscount.get(0).getString("status").equals("新建")) {
                     return getErrReturnObject().setErrMsg("非新建状态的收支凭证无法更新").toString();
                 }

+ 1 - 3
src/custom/restcontroller/sale/creditbill/creditbill.java

@@ -56,9 +56,7 @@ public class creditbill extends Controller {
         } else {
             Rows rowscount = dbConnect
                     .runSqlQuery("select status from sa_creditbill where sa_creditbillid=" + sa_creditbillid);
-            if (rowscount.isEmpty()) {
-                return getErrReturnObject().setErrMsg("此信用额度调整单不存在").toString();
-            } else {
+            if (rowscount.isNotEmpty()){
                 if (!rowscount.get(0).getString("status").equals("新建")) {
                     return getErrReturnObject().setErrMsg("非新建状态的信用额度调整单无法更新").toString();
                 }

+ 29 - 30
src/custom/restcontroller/sale/invoice/invoiceapply.java

@@ -61,15 +61,13 @@ public class invoiceapply extends Controller {
         sqlFactorySum.addParameter_in("sa_invoiceapplyid", ids);
         Rows sumrows = dbConnect.runSqlQuery(sqlFactorySum);
         RowsMap rowsMap = sumrows.toRowsMap("sa_invoiceapplyid");
-        if (!rows.isEmpty()) {
-            for (Row row : rows) {
-                Long id = row.getLong("sa_invoiceapplyid");
-                if (rowsMap.get(id.toString()).isNotEmpty()) {
-                    row.put("suminvoiceamount",
-                            rowsMap.get(id.toString()).get(0).getBigDecimal("suminvoiceamount").toPlainString());
-                } else {
-                    row.put("suminvoiceamount", 0);
-                }
+        for (Row row : rows) {
+            Long id = row.getLong("sa_invoiceapplyid");
+            if (rowsMap.get(id.toString()).isNotEmpty()) {
+                row.put("suminvoiceamount",
+                        rowsMap.get(id.toString()).get(0).getBigDecimal("suminvoiceamount").toPlainString());
+            } else {
+                row.put("suminvoiceamount", 0);
             }
         }
         return getSucReturnObject().setData(rows).toString();
@@ -80,7 +78,6 @@ public class invoiceapply extends Controller {
     @CACHEING_CLEAN(apiversions = {R.ID20221216143003.v1.class, R.ID20221216143103.v1.class, R.ID20221219133703.v1.class})
     public String check() throws YosException {
         Long sa_invoiceapplyid = content.getLong("sa_invoiceapplyid");
-        Long sa_orderid = 0L;
 
         int invoicingpoint = 99; //开票节点 1为订单审核,2为订单发货
 
@@ -89,25 +86,6 @@ public class invoiceapply extends Controller {
                 "select sa_invoiceapplyid,status,billno,sys_enterpriseid from sa_invoiceapply where sa_invoiceapplyid ='"
                         + sa_invoiceapplyid + "' and  siteid='" + siteid + "'");
 
-        Rows rowsDetail = dbConnect.runSqlQuery(
-                "select * from sa_invoiceapply_order where sa_invoiceapplyid ='" + sa_invoiceapplyid + "' and  siteid='" + siteid + "'");  //获取开票申请单表体
-
-        Rows rowsOrderDetail = dbConnect.runSqlQuery("select t1.sa_orderitemsid,t4.sonum,t3.itemname from sa_invoiceapply_order t1 inner join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid inner join plm_item t3  on t2.itemid=t3.itemid and t2.siteid=t3.siteid inner join sa_order t4 on t4.sa_orderid=t2.sa_orderid and  t4.siteid=t2.siteid  where t1.sa_invoiceapplyid ='" + sa_invoiceapplyid + "' and  t1.siteid='" + siteid + "'");  //获取开票申请单表体对应的订单信息
-        RowsMap OrderDetailRowsMap = rowsOrderDetail.toRowsMap("sa_orderitemsid"); //获取开票申请单表体对应的订单信息,订单号,商品名称的rowsmap
-
-        Rows sa_orderitemsRows = dbConnect
-                .runSqlQuery("select t1.sa_orderitemsid,t1.price,t1.invoiceamount,t1.amount from sa_orderitems t1 inner join sa_order t2 on t1.sa_orderid=t2.sa_orderid and t1.siteid=t2.siteid  where t2.sys_enterpriseid=" + rows.get(0).getLong("sys_enterpriseid"));
-        RowsMap saorderitemsRowsMap = sa_orderitemsRows.toRowsMap("sa_orderitemsid"); //获取订单已开票金额,单价,订单金额的rowsmap
-
-        Rows saorderRecviceRows = dbConnect.runSqlQuery("select t1.sa_orderid,t2.sa_orderitemsid,SUM(t2.qty) as receivedqty,\r\n" +
-                "  case when SUM(t2.qty)!=t3.qty then sum(ifnull(t2.qty,0)*t3.price-ifnull(t3.returnqty,0)*t3.price) else t3.amount end as receivedamount \r\n" +
-                "from sa_dispatch t1\r\n" +
-                "inner join sa_dispatch_items t2 on t1.siteid=t2.siteid and t1.sa_dispatchid=t2.sa_dispatchid\r\n" +
-                "inner join sa_orderitems t3 on t2.siteid=t3.siteid and t2.sa_orderitemsid=t3.sa_orderitemsid\r\n" +
-                "where t1.siteid='" + siteid + "' and t1.status='关闭' \r\n" +
-                "group by t1.siteid,t1.sa_orderid,t2.sa_orderitemsid,t3.returnqty,t3.qty,t3.price,t3.amount");
-        RowsMap saorderRecviceRowsMap = saorderRecviceRows.toRowsMap("sa_orderitemsid"); //获取订单已收货数量、金额的rowsmap
-
         if (rows.isEmpty()) {
             return getErrReturnObject().setErrMsg("该开票申请单不存在").toString();
         } else {
@@ -132,12 +110,33 @@ public class invoiceapply extends Controller {
 //				"select sa_invoiceapplyid from sa_invoicebill where sa_invoiceapplyid ='"
 //						+ sa_invoiceapplyid + "' and  siteid='" + siteid + "'").isEmpty()) {
 //        	return getErrReturnObject().setErrMsg("开票信息为空不可提交").toString();
-//        }      
+//        }
         if ((dbConnect.runSqlQuery(
                 "select sa_invoiceapplyid,invoiceamount from sa_invoiceapply_order where sa_invoiceapplyid ='"
                         + sa_invoiceapplyid + "' and  siteid='" + siteid + "' order by invoiceamount asc").get(0).getBigDecimal("invoiceamount")).compareTo(BigDecimal.ZERO) <= 0) {
             return getErrReturnObject().setErrMsg("订单行开票金额必须大于0").toString();
         }
+
+        Rows rowsDetail = dbConnect.runSqlQuery(
+                "select * from sa_invoiceapply_order where sa_invoiceapplyid ='" + sa_invoiceapplyid + "' and  siteid='" + siteid + "'");  //获取开票申请单表体
+
+        Rows rowsOrderDetail = dbConnect.runSqlQuery("select t1.sa_orderitemsid,t4.sonum,t3.itemname from sa_invoiceapply_order t1 inner join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid inner join plm_item t3  on t2.itemid=t3.itemid and t2.siteid=t3.siteid inner join sa_order t4 on t4.sa_orderid=t2.sa_orderid and  t4.siteid=t2.siteid  where t1.sa_invoiceapplyid ='" + sa_invoiceapplyid + "' and  t1.siteid='" + siteid + "'");  //获取开票申请单表体对应的订单信息
+        RowsMap OrderDetailRowsMap = rowsOrderDetail.toRowsMap("sa_orderitemsid"); //获取开票申请单表体对应的订单信息,订单号,商品名称的rowsmap
+
+        Rows sa_orderitemsRows = dbConnect
+                .runSqlQuery("select t1.sa_orderitemsid,t1.price,t1.invoiceamount,t1.amount from sa_orderitems t1 inner join sa_order t2 on t1.sa_orderid=t2.sa_orderid and t1.siteid=t2.siteid  where t2.sys_enterpriseid=" + rows.get(0).getLong("sys_enterpriseid"));
+        RowsMap saorderitemsRowsMap = sa_orderitemsRows.toRowsMap("sa_orderitemsid"); //获取订单已开票金额,单价,订单金额的rowsmap
+
+        Rows saorderRecviceRows = dbConnect.runSqlQuery("select t1.sa_orderid,t2.sa_orderitemsid,SUM(t2.qty) as receivedqty,\r\n" +
+                "  case when SUM(t2.qty)!=t3.qty then sum(ifnull(t2.qty,0)*t3.price-ifnull(t3.returnqty,0)*t3.price) else t3.amount end as receivedamount \r\n" +
+                "from sa_dispatch t1\r\n" +
+                "inner join sa_dispatch_items t2 on t1.siteid=t2.siteid and t1.sa_dispatchid=t2.sa_dispatchid\r\n" +
+                "inner join sa_orderitems t3 on t2.siteid=t3.siteid and t2.sa_orderitemsid=t3.sa_orderitemsid\r\n" +
+                "where t1.siteid='" + siteid + "' and t1.status='关闭' \r\n" +
+                "group by t1.siteid,t1.sa_orderid,t2.sa_orderitemsid,t3.returnqty,t3.qty,t3.price,t3.amount");
+        RowsMap saorderRecviceRowsMap = saorderRecviceRows.toRowsMap("sa_orderitemsid"); //获取订单已收货数量、金额的rowsmap
+
+
 //        Rows tinvoiceapply_totalview =dbConnect.runSqlQuery("select t1.* from (\r\n" + 
 //        		"select sa_invoiceapplyid,sum(orderamount) as orderamount,sum(billamount) as billamount,sum(redbillamount) as redbillamount from \r\n" + 
 //        		"						(select sa_invoiceapplyid,ifnull(SUM(invoiceamount),0) as orderamount,0 as billamount,0 as redbillamount  from sa_invoiceapply_order group by sa_invoiceapplyid\r\n" + 

+ 13 - 16
src/custom/restcontroller/sale/itemgroup/itemgroup.java

@@ -193,10 +193,10 @@ public class itemgroup extends Controller {
             BigDecimal max = new BigDecimal(0);
             BigDecimal min = ((ItemPrice) ItemPriceList.values().toArray()[0]).getPrice();
             for (ItemPrice itemPrice : ItemPriceList.values()) {
-                if (itemPrice.getPrice().compareTo(max) == 1) {
+                if (itemPrice.getPrice().compareTo(max) >0) {
                     max = itemPrice.getPrice();
                 }
-                if (itemPrice.getPrice().compareTo(min) == -1) {
+                if (itemPrice.getPrice().compareTo(min) <0) {
                     min = itemPrice.getPrice();
                 }
             }
@@ -298,17 +298,6 @@ public class itemgroup extends Controller {
         sqlFactory.addParameter("siteid", siteid);
         Rows rows = dbConnect.runSqlQuery(sqlFactory);
 
-        for (Row row : rows) {
-            ItemPrice itemPrice = ItemPrice.getItemPrice(this, sys_enterpriseid, row.getLong("itemid"));
-            row.put("oldprice", itemPrice.getMarketprice());
-            if (sys_enterpriseid > 0 || (usertype == 21 || usertype == 22)) {
-                row.put("gradeprice", itemPrice.getContractprice());
-            } else {
-                row.put("gradeprice", itemPrice.getMarketprice());
-            }
-
-//            row.put("pricegrade", itemPrice.getEnterpriseGrade().getPricegrade());
-        }
 
         ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
 
@@ -332,7 +321,17 @@ public class itemgroup extends Controller {
                         + siteid + "'");
         RowsMap itemclassRowsMap = rowsitemclass.toRowsMap("itemid");
 
+        RowsMap itemextendRowsMap = dbConnect.runSqlQuery("select itemid,material,device,prodline,specalnote,pressure,connection,valveplatematerial,actuatortype,actuatorbrand,butterflyplatedrive from plm_itemextend where siteid='" + siteid + "'").toRowsMap("itemid");
         for (Row row : rows) {
+
+            ItemPrice itemPrice = ItemPrice.getItemPrice(this, sys_enterpriseid, row.getLong("itemid"));
+            row.put("oldprice", itemPrice.getMarketprice());
+            if (sys_enterpriseid > 0 || (usertype == 21 || usertype == 22)) {
+                row.put("gradeprice", itemPrice.getContractprice());
+            } else {
+                row.put("gradeprice", itemPrice.getMarketprice());
+            }
+
             Rows jsonArray = new Rows();
             Rows coverRows = coverRowsMap.get(row.getString("itemid"));
             if (coverRows.isEmpty()) {
@@ -354,9 +353,7 @@ public class itemgroup extends Controller {
             }
             row.put("technicalinfo", jsonArray);
             row.put("tradefield", tradefieldRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
-        }
-        RowsMap itemextendRowsMap = dbConnect.runSqlQuery("select itemid,material,device,prodline,specalnote,pressure,connection,valveplatematerial,actuatortype,actuatorbrand,butterflyplatedrive from plm_itemextend where siteid='" + siteid + "'").toRowsMap("itemid");
-        for (Row row : rows) {
+
             if (itemextendRowsMap.containsKey(row.getString("itemid"))) {
                 row.put("itemextend", itemextendRowsMap.get(row.getString("itemid")));
             } else {

+ 79 - 0
src/custom/restcontroller/webmanage/saletool/phonebook/SQL/通讯录列表查询_客户联系人.sql

@@ -0,0 +1,79 @@
+select t.sys_phonebookid,
+       t.name,
+       t.depname,
+       t.position,
+       t.phonenumber,
+       t.sys_phonebookgroupid,
+       t.groupname,
+       t.sex,
+       t.birthday,
+       t.email,
+       t.company,
+       t.homeaddress,
+       t.remarks,
+       t.fax,
+       t.wechatnum,
+       t.contactsid,
+       t.createby,
+       t.createdate,
+       t.projectname,
+       t.projectnum,
+       t.sa_project_contactsid,
+       t.isleader,
+       t.province,
+       t.city,
+       t.county,
+       t.conremarks,
+       t.workaddress,
+       t.isdefault,
+       t.isprimary,
+       t.sys_enterpriseid,
+       t.telephone
+from (SELECT DISTINCT 0  sys_phonebookid,
+                      t1.NAME,
+                      t1.depname,
+                      t1.position,
+                      t1.phonenumber,
+                      0  sys_phonebookgroupid,
+                      '客户联系人'      groupname,
+                      t1.sex,
+                      t1.birthday,
+                      t1.email,
+                      t2.enterprisename company,
+                      t1.address        homeaddress,
+                      t1.remarks,
+                      t1.createuserid   userid,
+                      t1.fax,
+                      t1.wechatnum,
+                      t1.contactsid,
+                      t5.name createby,
+                      t4.actiondate createdate,
+                      '' projectname,
+                      '' projectnum,
+                      0 sa_project_contactsid,
+                      t1.isleader,
+                      t1.province,
+                      t1.city,
+                      t1.county,
+                      '' conremarks,
+                      t1.workaddress,
+                      t1.isdefault,
+                      t1.isprimary,
+                      t1.sys_enterpriseid,
+                      t1.telephone,
+                      t1.createuserid
+      FROM (SELECT *
+            FROM sys_enterprise_contacts
+            WHERE contactsid IN (SELECT MAX(contactsid) FROM sys_enterprise_contacts GROUP BY phonenumber, name)) t1
+               LEFT JOIN sys_enterprise t2 ON t1.sys_enterpriseid = t2.sys_enterpriseid AND t1.siteid = t2.siteid
+               left join sys_datatag t3 on t1.siteid = t3.siteid and t1.contactsid = t3.ownerid and
+                                           t3.ownertable = 'sys_enterprise_contacts'
+               left join sys_contrllog t4 on t1.siteid = t4.siteid and t1.contactsid = t4.ownerid and
+                                             t4.ownertable = 'sys_enterprise_contacts' and t4.action = '新增'
+               left join sys_hr t5 on t1.siteid = t5.siteid and t1.createuserid = t5.userid
+      WHERE ifnull(t1.deleted, 0) = 0
+        and ifnull(workaddress, 0) = 0
+        AND t1.siteid = $siteid$
+        and $where3$) t
+where $where$
+  and $where1$

+ 79 - 0
src/custom/restcontroller/webmanage/saletool/phonebook/SQL/通讯录列表查询_项目联系人.sql

@@ -0,0 +1,79 @@
+select t.sys_phonebookid,
+       t.name,
+       t.depname,
+       t.position,
+       t.phonenumber,
+       t.sys_phonebookgroupid,
+       t.groupname,
+       t.sex,
+       t.birthday,
+       t.email,
+       t.company,
+       t.homeaddress,
+       t.remarks,
+       t.fax,
+       t.wechatnum,
+       t.contactsid,
+       t.createby,
+       t.createdate,
+       t.projectname,
+       t.projectnum,
+       t.sa_project_contactsid,
+       t.isleader,
+       t.province,
+       t.city,
+       t.county,
+       t.conremarks,
+       t.workaddress,
+       t.isdefault,
+       t.isprimary,
+       t.sys_enterpriseid,
+       t.telephone
+from (
+      SELECT DISTINCT 0                 sys_phonebookid,
+                      t2.NAME,
+                      t2.depname,
+                      t2.position,
+                      t2.phonenumber,
+                      0                 sys_phonebookgroupid,
+                      '项目联系人'      groupname,
+                      t2.sex,
+                      t2.birthday,
+                      t2.email,
+                      t4.enterprisename company,
+                      t2.address        homeaddress,
+                      t2.remarks,
+                      t2.createuserid   userid,
+                      t2.fax,
+                      t2.wechatnum,
+                      t2.contactsid,
+                      t2.createby,
+                      t2.createdate,
+                      t2.projectname,
+                      t2.projectnum,
+                      t2.sa_project_contactsid,
+                      t2.isleader,
+                      t2.province,
+                      t2.city,
+                      t2.county,
+                      t2.remarks conremarks,
+                      t2.workaddress,
+                      t2.isdefault,
+                      t2.isprimary,
+                      t2.sys_enterpriseid,
+                      t2.telephone,
+                      t2.createuserid
+      FROM (select distinct t2.*, t1.sa_project_contactsid, t3.projectname, t3.projectnum, t1.createby, t1.createdate
+            from sa_project_contacts t1
+                     inner join sys_enterprise_contacts t2 on t1.contactsid = t2.contactsid and t1.siteid = t2.siteid
+                     left join sa_project t3 on t1.siteid = t3.siteid and t1.sa_projectid = t3.sa_projectid
+            where ifnull(t2.deleted, 0) = 0) t2
+               left join sys_datatag t3 on t2.siteid = t3.siteid and t2.contactsid = t3.ownerid and
+                                           t3.ownertable = 'sys_enterprise_contacts'
+               LEFT JOIN sys_enterprise t4 ON t2.sys_enterpriseid = t4.sys_enterpriseid
+          AND t2.siteid = t3.siteid
+      WHERE ifnull(t2.deleted, 0) = 0
+        AND t2.siteid = $siteid$
+        and $where3$) t
+where $where$
+  and $where1$

+ 78 - 0
src/custom/restcontroller/webmanage/saletool/phonebook/SQL/通讯录列表查询_默认群组.sql

@@ -0,0 +1,78 @@
+select t.sys_phonebookid,
+       t.name,
+       t.depname,
+       t.position,
+       t.phonenumber,
+       t.sys_phonebookgroupid,
+       t.groupname,
+       t.sex,
+       t.birthday,
+       t.email,
+       t.company,
+       t.homeaddress,
+       t.remarks,
+       t.fax,
+       t.wechatnum,
+       t.contactsid,
+       t.createby,
+       t.createdate,
+       t.projectname,
+       t.projectnum,
+       t.sa_project_contactsid,
+       t.isleader,
+       t.province,
+       t.city,
+       t.county,
+       t.conremarks,
+       t.workaddress,
+       t.isdefault,
+       t.isprimary,
+       t.sys_enterpriseid,
+       t.telephone
+from (SELECT distinct t1.sys_phonebookid,
+                      t1.NAME,
+                      t1.depname,
+                      t1.position,
+                      t1.phonenumber,
+                      t1.sys_phonebookgroupid,
+                      t2.groupname,
+                      t1.sex,
+                      ifnull(t1.birthday, '') birthday,
+                      t1.email,
+                      t1.company,
+                      t1.homeaddress,
+                      t1.remarks,
+                      t1.userid,
+                      t1.fax,
+                      t1.wechatnum,
+                      0                       contactsid,
+                      t1.createby,
+                      t1.createdate,
+                      ''                      projectname,
+                      ''                      projectnum,
+                      0                       sa_project_contactsid,
+                      ''                      isleader,
+                      ''                      province,
+                      ''                      city,
+                      ''                      county,
+                      ''                      conremarks,
+                      ''                      workaddress,
+                      ''                      isdefault,
+                      ''                      isprimary,
+                      0                       sys_enterpriseid,
+                      t1.telephone,
+                      t1.createuserid
+      FROM sys_phonebook t1
+               LEFT JOIN (SELECT sys_phonebookgroupid, groupname
+                          FROM sys_phonebookgroup
+                          WHERE siteid = $siteid$
+                          UNION ALL
+                          SELECT 0 sys_phonebookgroupid, '默认群组' groupname) t2
+                         ON ifnull(t1.sys_phonebookgroupid, 0) = t2.sys_phonebookgroupid
+               left join sys_datatag t3 on t1.siteid = t3.siteid and t1.sys_phonebookid = t3.ownerid and
+                                           t3.ownertable = 'sys_phonebook'
+
+      WHERE t1.siteid = $siteid$
+        and $where3$) t
+where $where$
+  and $where1$

+ 98 - 21
src/custom/restcontroller/webmanage/saletool/phonebook/phonebook.java

@@ -1,5 +1,6 @@
 package restcontroller.webmanage.saletool.phonebook;
 
+import beans.datacontrllog.DataContrlLog;
 import beans.datatag.DataTag;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
@@ -17,13 +18,13 @@ import org.apache.commons.lang.StringUtils;
 import restcontroller.R;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 
 @API(title = "通讯录")
 public class phonebook extends Controller {
 
     public phonebook(JSONObject content) throws YosException {
         super(content);
-        // TODO Auto-generated constructor stub
     }
 
     @API(title = "通讯录新增修改", apiversion = R.ID20220831164503.v1.class)
@@ -32,7 +33,7 @@ public class phonebook extends Controller {
         long sys_phonebookid = content.getLong("sys_phonebookid");
         ArrayList<String> sqllist = new ArrayList<>();
         String sys_phonebookgroupid = content.getString("sys_phonebookgroupid");
-        String phonenumber = content.getString("phonenumber");
+        String phonenumber = content.getStringValue("phonenumber");
         String name = content.getString("name", "sys_phonebook");
         String company = content.getString("company");
         String depname = content.getString("depname", "sys_phonebook");
@@ -45,15 +46,15 @@ public class phonebook extends Controller {
         String birthday = content.getString("birthday");
         String homeaddress = content.getString("homeaddress");
         String remarks = content.getString("remarks");
-
-        if (sys_phonebookid <= 0 || dbConnect
-                .runSqlQuery("select sys_phonebookid from sys_phonebook where sys_phonebookid=" + sys_phonebookid)
-                .isEmpty()) {
+        String fax = content.getStringValue("fax");
+        Rows rows = dbConnect.runSqlQuery("select phonenumber,telephone from sys_phonebook where sys_phonebookid=" + sys_phonebookid);
+        if (sys_phonebookid <= 0 || rows.isEmpty()) {
             sys_phonebookid = createTableID("sys_phonebook");
             SQLFactory sqlFactory = new SQLFactory(this, "通讯录新增");
             sqlFactory.addParameter("sys_phonebookid", sys_phonebookid);
             sqlFactory.addParameter("siteid", siteid);
             sqlFactory.addParameter("userid", userid);
+            sqlFactory.addParameter("username", username);
             if (!StringUtils.isBlank(sys_phonebookgroupid)) {
                 sqlFactory.addParameter("sys_phonebookgroupid", sys_phonebookgroupid);
             } else {
@@ -63,6 +64,7 @@ public class phonebook extends Controller {
             sqlFactory.addParameter("name", name);
             sqlFactory.addParameter("company", company);
             sqlFactory.addParameter("depname", depname);
+            sqlFactory.addParameter("wechatnum", content.getStringValue("wechatnum"));
             sqlFactory.addParameter("position", position);
             sqlFactory.addParameter("email", email);
             DataTag.updateTag(this, "sys_phonebook", sys_phonebookid, list);
@@ -75,8 +77,10 @@ public class phonebook extends Controller {
             }
             sqlFactory.addParameter("homeaddress", homeaddress);
             sqlFactory.addParameter("remarks", remarks);
+            sqlFactory.addParameter("fax", fax);
             content.put("sys_phonebookid", sys_phonebookid);
             sqllist.add(sqlFactory.getSQL());
+            sqllist.add(DataContrlLog.createLog(this, "sys_phonebook", sys_phonebookid, "通讯录新增", "通讯录新增:" + name).getSQL());
         } else {
             SQLFactory sqlFactory = new SQLFactory(this, "通讯录更新");
             sqlFactory.addParameter("sys_phonebookid", sys_phonebookid);
@@ -92,6 +96,7 @@ public class phonebook extends Controller {
             sqlFactory.addParameter("company", company);
             sqlFactory.addParameter("depname", depname);
             sqlFactory.addParameter("position", position);
+            sqlFactory.addParameter("wechatnum", content.getStringValue("wechatnum"));
             sqlFactory.addParameter("email", email);
             DataTag.updateTag(this, "sys_phonebook", sys_phonebookid, list);
             sqlFactory.addParameter("tag", tagArray.toJSONString());
@@ -103,7 +108,9 @@ public class phonebook extends Controller {
             }
             sqlFactory.addParameter("homeaddress", homeaddress);
             sqlFactory.addParameter("remarks", remarks);
+            sqlFactory.addParameter("fax", fax);
             sqllist.add(sqlFactory.getSQL());
+            sqllist.add(DataContrlLog.createLog(this, "sys_phonebook", sys_phonebookid, "通讯录更新", "通讯录更新:" + name).getSQL());
         }
         dbConnect.runSqlUpdate(sqllist);
         return queryPhonebookMain();
@@ -113,7 +120,8 @@ public class phonebook extends Controller {
     @API(title = "通讯录列表", apiversion = R.ID20220831164603.v1.class)
     @CACHEING
     public String queryPhonebookList() throws YosException {
-
+        boolean isqueryall = content.getBooleanValue("isqueryall");
+        String where3 = " 1=1 ";
         /*
          * 过滤条件设置
          */
@@ -128,20 +136,56 @@ public class phonebook extends Controller {
             if (whereObject.containsKey("groupname") && !"".equals(whereObject.getString("groupname"))) {
                 where = where + " and t.groupname ='" + whereObject.getString("groupname") + "' ";
             }
+            if (whereObject.containsKey("tag") && !"".equals(whereObject.getString("tag"))) {
+                where3 = where3 + " and t3.tag ='" + whereObject.getString("tag") + "'";
+            }
         }
         SQLFactory factory = new SQLFactory(this, "通讯录分组列表查询");
         factory.addParameter("siteid", siteid);
         factory.addParameter("userid", userid);
         factory.addParameter_SQL("where", " 1=1 ");
+        if (isqueryall) {
+            factory.addParameter_SQL("where1", "1=1");
+        } else {
+            factory.addParameter_SQL("where1", "userid = " + userid);
+        }
         Rows rowsgroup = dbConnect.runSqlQuery(factory.getSQL());
-        if (content.getBooleanValue("isqueryall")) {
-            SQLFactory sqlFactory = new SQLFactory(this, "通讯录列表查询");
+
+        if (isqueryall) {
+            Rows rows =new Rows();
+            SQLFactory sqlFactory = new SQLFactory(this, "通讯录列表查询_默认群组");
+            sqlFactory.addParameter_SQL("where", where);
+            sqlFactory.addParameter_SQL("where3", where3);
+            sqlFactory.addParameter("siteid", siteid);
+            sqlFactory.addParameter_SQL("where1", " 1=1 and t.userid=" + userid);
+            rows.addAll( dbConnect.runSqlQuery(sqlFactory));
+
+            sqlFactory = new SQLFactory(this, "通讯录列表查询_客户联系人");
             sqlFactory.addParameter_SQL("where", where);
+            sqlFactory.addParameter_SQL("where3", where3);
             sqlFactory.addParameter("siteid", siteid);
             sqlFactory.addParameter_SQL("where1", " 1=1 and t.userid=" + userid);
-            Rows rows = dbConnect.runSqlQuery(sqlFactory);
+            rows.addAll( dbConnect.runSqlQuery(sqlFactory));
+
+            sqlFactory = new SQLFactory(this, "通讯录列表查询_项目联系人");
+            sqlFactory.addParameter_SQL("where", where);
+            sqlFactory.addParameter_SQL("where3", where3);
+            sqlFactory.addParameter("siteid", siteid);
+            sqlFactory.addParameter_SQL("where1", " 1=1 and t.userid=" + userid);
+            rows.addAll( dbConnect.runSqlQuery(sqlFactory));
+
+            HashMap<Long, ArrayList<String>> hashMap = DataTag.queryTag(this, "sys_phonebook", rows.toArrayList("sys_phonebookid",  new ArrayList<Long>()), false);
+            HashMap<Long, ArrayList<String>> hashMap2 = DataTag.queryTag(this, "sys_phonebook", rows.toArrayList("sys_phonebookid",  new ArrayList<Long>()), true);
             for (Row row2 : rows) {
-                ArrayList<String> list = DataTag.queryTag(this, "sys_phonebook", row2.getLong("sys_phonebookid"), false);
+                ArrayList<String> list =  hashMap.get(row2.getLong("sys_phonebookid"));
+                ArrayList<String> list1 = hashMap2.get(row2.getLong("sys_phonebookid"));
+                if(list==null){
+                    list=new ArrayList<>();
+                }
+                if(list1==null){
+                    list1=new ArrayList<>();
+                }
+                list.addAll(list1);
                 row2.put("tag1", JSONArray.parseArray(JSON.toJSONString(list)));
             }
             return getSucReturnObject().setData(rows).toString();
@@ -149,51 +193,84 @@ public class phonebook extends Controller {
             for (Row row : rowsgroup) {
                 String where1 = "";
                 if (row.getLong("sys_phonebookgroupid") == 0 && row.getString("groupname").equals("默认群组")) {
-                    SQLFactory sqlFactory = new SQLFactory(this, "通讯录列表查询");
+                    SQLFactory sqlFactory = new SQLFactory(this, "通讯录列表查询_默认群组");
                     sqlFactory.addParameter_SQL("where", where);
                     sqlFactory.addParameter("siteid", siteid);
+                    sqlFactory.addParameter_SQL("where3", where3);
                     where1 = " ifnull(t.sys_phonebookgroupid,0)=0 and t.groupname ='默认群组' and t.userid=" + userid;
                     sqlFactory.addParameter_SQL("where1", where1);
                     Rows rows = dbConnect.runSqlQuery(sqlFactory);
                     for (Row row2 : rows) {
-                        ArrayList<String> list = DataTag.queryTag(this, "sys_phonebook", row2.getLong("sys_phonebookid"), false);
-                        row2.put("tag1", JSONArray.parseArray(JSON.toJSONString(list)));
+                        row2.put("tag1", JSONArray.parseArray(JSON.toJSONString(new ArrayList<>())));
                     }
                     row.put("phonebook", rows);
                 } else if (row.getLong("sys_phonebookgroupid") == 0 && row.getString("groupname").equals("客户联系人")) {
-                    SQLFactory sqlFactory = new SQLFactory(this, "通讯录列表查询");
+                    SQLFactory sqlFactory = new SQLFactory(this, "通讯录列表查询_客户联系人");
                     sqlFactory.addParameter_SQL("where", where);
+                    sqlFactory.addParameter_SQL("where3", where3);
                     sqlFactory.addParameter("siteid", siteid);
                     where1 = " ifnull(t.sys_phonebookgroupid,0)=0 and t.groupname ='客户联系人' ";
                     sqlFactory.addParameter_SQL("where1", where1);
                     Rows rows = dbConnect.runSqlQuery(sqlFactory);
+                    HashMap<Long, ArrayList<String>> hashMap = DataTag.queryTag(this, "sys_enterprise_contacts", rows.toArrayList("contactsid",  new ArrayList<Long>()), false);
+                    HashMap<Long, ArrayList<String>> hashMap2 = DataTag.queryTag(this, "sys_enterprise_contacts", rows.toArrayList("contactsid",  new ArrayList<Long>()), true);
                     for (Row row2 : rows) {
-                        ArrayList<String> list = DataTag.queryTag(this, "sys_phonebook", row2.getLong("sys_phonebookid"), false);
+                        ArrayList<String> list = hashMap.get(row2.getLong("contactsid"));
+                        ArrayList<String> list1 = hashMap2.get(row2.getLong("contactsid"));
+                        if(list==null){
+                            list=new ArrayList<>();
+                        }
+                        if(list1==null){
+                            list1=new ArrayList<>();
+                        }
+                        list.addAll(list1);
                         row2.put("tag1", JSONArray.parseArray(JSON.toJSONString(list)));
                     }
                     row.put("phonebook", rows);
 
                 } else if (row.getLong("sys_phonebookgroupid") == 0 && row.getString("groupname").equals("项目联系人")) {
-                    SQLFactory sqlFactory = new SQLFactory(this, "通讯录列表查询");
+                    SQLFactory sqlFactory = new SQLFactory(this, "通讯录列表查询_项目联系人");
                     sqlFactory.addParameter_SQL("where", where);
+                    sqlFactory.addParameter_SQL("where3", where3);
                     sqlFactory.addParameter("siteid", siteid);
                     where1 = " ifnull(t.sys_phonebookgroupid,0)=0 and t.groupname ='项目联系人' ";
                     sqlFactory.addParameter_SQL("where1", where1);
                     Rows rows = dbConnect.runSqlQuery(sqlFactory);
+                    HashMap<Long, ArrayList<String>> hashMap = DataTag.queryTag(this, "sa_project_contacts", rows.toArrayList("sa_project_contactsid",  new ArrayList<Long>()), false);
+                    HashMap<Long, ArrayList<String>> hashMap2 = DataTag.queryTag(this, "sa_project_contacts", rows.toArrayList("sa_project_contactsid",  new ArrayList<Long>()), true);
                     for (Row row2 : rows) {
-                        ArrayList<String> list = DataTag.queryTag(this, "sys_phonebook", row2.getLong("sys_phonebookid"), false);
+                        ArrayList<String> list = hashMap.get(row2.getLong("sa_project_contactsid"));
+                        ArrayList<String> list1 = hashMap2.get(row2.getLong("sa_project_contactsid"));
+                        if(list==null){
+                            list=new ArrayList<>();
+                        }
+                        if(list1==null){
+                            list1=new ArrayList<>();
+                        }
+                        list.addAll(list1);
                         row2.put("tag1", JSONArray.parseArray(JSON.toJSONString(list)));
                     }
                     row.put("phonebook", rows);
                 } else if (row.getLong("sys_phonebookgroupid") != 0) {
-                    SQLFactory sqlFactory = new SQLFactory(this, "通讯录列表查询");
+                    SQLFactory sqlFactory = new SQLFactory(this, "通讯录列表查询_默认群组");
                     sqlFactory.addParameter_SQL("where", where);
+                    sqlFactory.addParameter_SQL("where3", where3);
                     sqlFactory.addParameter("siteid", siteid);
                     where1 = " t.sys_phonebookgroupid= " + row.getLong("sys_phonebookgroupid") + " and t.userid=" + userid;
                     sqlFactory.addParameter_SQL("where1", where1);
-                    Rows rows = dbConnect.runSqlQuery(sqlFactory);
+                    Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
+                    HashMap<Long, ArrayList<String>> hashMap = DataTag.queryTag(this, "sys_phonebook", rows.toArrayList("sys_phonebookid",  new ArrayList<Long>()), false);
+                    HashMap<Long, ArrayList<String>> hashMap2 = DataTag.queryTag(this, "sys_phonebook", rows.toArrayList("sys_phonebookid",  new ArrayList<Long>()), true);
                     for (Row row2 : rows) {
-                        ArrayList<String> list = DataTag.queryTag(this, "sys_phonebook", row2.getLong("sys_phonebookid"), false);
+                        ArrayList<String> list =  hashMap.get(row2.getLong("sys_phonebookid"));
+                        ArrayList<String> list1 = hashMap2.get(row2.getLong("sys_phonebookid"));
+                        if(list==null){
+                            list=new ArrayList<>();
+                        }
+                        if(list1==null){
+                            list1=new ArrayList<>();
+                        }
+                        list.addAll(list1);
                         row2.put("tag1", JSONArray.parseArray(JSON.toJSONString(list)));
                     }
                     row.put("phonebook", rows);