Просмотр исходного кода

海盐新增服务管理2021年12月18日09:31:41

hu 4 лет назад
Родитель
Сommit
b1d676de32

+ 1 - 1
src/apps/hyworkorder/HYWorkOrderAppBean.java

@@ -48,7 +48,7 @@ public class HYWorkOrderAppBean extends AppBeanCust {
         if (!hyworkorder.getString("fstatus").equals("暂停")) {
         	throw new P2AppException("","非暂停不可启用");
         	}
-        hyworkorder.setValue("fstatus", "启用",11L);
+        hyworkorder.setValue("fstatus", "进行中",11L);
         this.SAVE();
         this.REFRESH();
          byrefresh();

+ 1 - 0
src/apps/hyworkorder/hyworkorder.java

@@ -81,6 +81,7 @@ public class hyworkorder extends PaoCust {
     public void fieldAction(Object paoField, String fieldname) throws P2Exception {
         super.fieldAction(paoField, fieldname);
         if(fieldname.equalsIgnoreCase("templatenum")){
+        	System.out.println(111);
             //新增节点之前先删除原先的节点
             if(!getPaoSet("hyordernode").isEmpty()){
                 PaoSetRemote ordernode = getPaoSet("hyordernode");

+ 139 - 0
src/rest/openapi/restcontroller/hyworkorder/web/afterserviceorder/Afterserviceorder.java

@@ -13,8 +13,10 @@ import org.apache.commons.lang.time.DateFormatUtils;
 import p2.p2server.P2Server;
 import p2.pao.PaoRemote;
 import p2.pao.PaoSetRemote;
+import p2.util.P2AppException;
 import p2.util.P2Exception;
 
+import java.util.Calendar;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.Set;
@@ -152,6 +154,104 @@ public class Afterserviceorder extends Controller {
         return getReturnObject_err("缺少where参数").toString();
     }
 
+    /**工单模板查询**/
+    public String queryworkerordertemplate(){
+        if(StringUtils.isBlank(hrid))return getReturnObject_err("hrid为空").toString();
+        //if(StringUtils.isBlank(fagentnum))return getReturnObject_err("fagentnum为空").toString();
+        if(StringUtils.isBlank(siteid))return getReturnObject_err("siteid为空").toString();
+        JSONObject where = content.getJSONObject("where");
+        String wherestr="1=1";
+//        String s[] = {"servicenum"};
+//        for (String s1 : s) {
+//            if (!where.containsKey(s1))return getReturnObject_err("缺少" + s1 + "参数").toString();
+//        }
+        DBConnect dbConnect=new DBConnect();
+        Rows rows = dbConnect.runSqlQuery("select fname,ftype,fworknum from hyworkordertemplate where siteid='"+siteid+"' and fstatus='启用' ");
+        return getReturnObject_suc(rows,false).toString();
+    }
+    /**售后服务单转工单**/
+    public String AfterserviceOrderToHyworkorder(){
+        if(StringUtils.isBlank(hrid))return getReturnObject_err("hrid为空").toString();
+        //if(StringUtils.isBlank(fagentnum))return getReturnObject_err("fagentnum为空").toString();
+        if(StringUtils.isBlank(siteid))return getReturnObject_err("siteid为空").toString();
+        JSONObject where = content.getJSONObject("where");
+        String s[] = {"ftype","fworknum","servicenum","projectleader"};
+        for (String s1 : s) {
+            if (!where.containsKey(s1))return getReturnObject_err("缺少" + s1 + "参数").toString();
+        }
+        if (where != null) {
+            try {
+            	PaoSetRemote afterserviceorder = P2Server.getP2Server().getPaoSet("afterserviceorder",
+ 						P2Server.getP2Server().getSystemUserInfo());
+            	 afterserviceorder.setInsertSite(siteid);
+            	 afterserviceorder.setWhere("servicenum='"+where.getString("servicenum")+"'");
+            	 afterserviceorder.reset();
+            	 if(afterserviceorder.isEmpty()) {
+            		 return getReturnObject_err("此售后服务单不存在").toString();
+            	 }else{
+            		 if(!afterserviceorder.getPao(0).getString("fstatus").equals("待处理")&&!afterserviceorder.getPao(0).getString("fstatus").equals("进行中")) {
+            			 return getReturnObject_err("非处理和进行中状态不可生成工单").toString();
+            		 }
+            	 }
+                    PaoSetRemote workorders = P2Server.getP2Server().getPaoSet("hyWorkorder",
+    						P2Server.getP2Server().getSystemUserInfo());
+                    workorders.setInsertSite(siteid);
+                    workorders.setWhere("servernum='"+where.getString("servicenum")+"'");
+                    workorders.reset();
+                    //if(!afterserviceorder.isEmpty())return getReturnObject_err("已存在关联的售后服务单").toString();
+                    if(!workorders.isEmpty()) {
+            			int i=0;
+            			PaoRemote paoRemote =null;
+            			while ((paoRemote=workorders.getPao(i))!=null) {
+            				System.out.println(paoRemote.getString("ftype"));
+            				if(paoRemote.getString("ftype").equals(where.getString("ftype")) && !paoRemote.getString("fstatus").equals("作废")) {   
+            					return getReturnObject_err("已存在"+where.getString("ftype")+"类型的工单,无法继续生成此类型的工单").toString();
+            				}
+            				i++;
+            			}
+            		}
+                    PaoRemote remote = workorders.addAtEnd();
+                    remote.setValue("FAGENTNUM",afterserviceorder.getPao(0).getString("FAGENTNUM"),11l);
+                    remote.setValue("servernum",where.getString("servicenum"),11l);
+                    remote.setValue("PROJECTLEADER",where.getString("projectleader"),11l); 
+                    remote.setValue("FPROVINCE",afterserviceorder.getPao(0).getString("FPROVINCE"),11l);
+                    remote.setValue("FCITY",afterserviceorder.getPao(0).getString("FCITY"),11l);
+                    remote.setValue("FCOUNTY",afterserviceorder.getPao(0).getString("FCOUNTY"),11l);
+                    remote.setValue("FADDRESS",afterserviceorder.getPao(0).getString("FADDRESS"),11l);
+                    remote.setValue("scenefname",afterserviceorder.getPao(0).getString("scenefname"),11l);
+                    remote.setValue("scenephone",afterserviceorder.getPao(0).getString("scenephone"),11l);
+                    remote.setValue("errormsg",afterserviceorder.getPao(0).getString("error_msg"),11l);
+                    remote.setValue("ftext",afterserviceorder.getPao(0).getString("fnotes"),11l);
+                    remote.setValue("ftype",where.getString("ftype"),11l);
+                    remote.setValue("TEMPLATENUM",where.getString("fworknum"),2l);
+                    String fsonum=afterserviceorder.getPao(0).getString("fsonum");
+                    DBConnect connect = new DBConnect();
+                    SQLFactory factory = new SQLFactory(this, "查询订单收货日期");
+            		factory.addParameter("fsonum", fsonum);
+                    Rows rows = connect.runSqlQuery(factory.getSQL());		
+                    if(!rows.isEmpty()) {
+                    	Date receivedate=rows.get(0).getDate("receivedate");
+                    	Calendar calendar = Calendar.getInstance(); 
+                    	calendar.add(Calendar.YEAR, -2);
+                    	Date date =calendar.getTime();
+                    	if(date.before(receivedate)) {
+                    		 remote.setValue("FISPERIOD",true,11l);
+                    	}
+                    }
+                    
+                    workorders.save();
+                    Row row=new Row();
+                    row.put("FWORKNUM",remote.getString("FWORKNUM"));
+                    row.put("fstatus",remote.getString("fstatus"));
+                    row.put("createdate", DateFormatUtils.format(remote.getDate("createdate"),"yyyy-MM-dd HH:mm:ss"));
+                    return getReturnObject_suc(row,false).toString();
+            } catch (P2Exception e) {
+                e.printStackTrace();
+                return getReturnObject_err(e.getMessage()).toString();
+            }
+        }
+        return getReturnObject_err("缺少where参数").toString();
+    }
 
 
 
@@ -285,6 +385,45 @@ public class Afterserviceorder extends Controller {
         }
         return getReturnObject_err("缺少where参数").toString();
     }
+    /**退回服务单**/
+    public String sendback(){
+        if(StringUtils.isBlank(hrid))return getReturnObject_err("hrid为空").toString();
+        //if(StringUtils.isBlank(fagentnum))return getReturnObject_err("fagentnum为空").toString();
+        if(StringUtils.isBlank(siteid))return getReturnObject_err("siteid为空").toString();
+        JSONObject where = content.getJSONObject("where");
+        String s[] = {"servicenum","backreason"};
+        for (String s1 : s) {
+            if (!where.containsKey(s1))return getReturnObject_err("缺少" + s1 + "参数").toString();
+        }
+
+        if (where != null) {
+            try {
+                PaoSetRemote getpaoset = P2Server.getP2Server().getPaoSet("Afterserviceorder", P2Server.getP2Server().getSystemUserInfo());
+                getpaoset.setInsertSite(siteid);
+                getpaoset.setWhere("Servicenum='"+where.getString("servicenum")+"'");
+                getpaoset.reset();
+                if(getpaoset.isEmpty())return getReturnObject_err("没有该服务单").toString();
+                afterserviceorder afterserviceorder = (afterserviceorder)getpaoset.getPao(0);
+                if(!afterserviceorder.getString("fstatus").equals("待处理")) {
+                	return getReturnObject_err("非待处理不可退回").toString();
+                }
+                if(where.getString("backreason")==null || where.getString("backreason").length()==0) {
+                	return getReturnObject_err("退回原因为空不可退回").toString();
+            	}
+                afterserviceorder.setValue("backreason",where.getString("backreason"));
+                afterserviceorder.setValue("fstatus", "新建",11L);
+                afterserviceorder.setValue("submitby","",11l);
+                afterserviceorder.setValue("submitdate","",11l);
+                getpaoset.save();
+
+                return getReturnObject_suc().toString();
+            } catch (P2Exception e) {
+                e.printStackTrace();
+                return getReturnObject_err(e.getMessage()).toString();
+            }
+        }
+        return getReturnObject_err("缺少where参数").toString();
+    }
     /**删除服务单**/
     public String delete(){
         if(StringUtils.isBlank(hrid))return getReturnObject_err("hrid为空").toString();

+ 2 - 0
src/rest/openapi/restcontroller/hyworkorder/web/afterserviceorder/SQL/查询订单收货日期.sql

@@ -0,0 +1,2 @@
+select SALOGIS.receivedate from SALOGIS inner join  salogisdetail on salogisdetail.fparentid=SALOGIS.salogisid 
+                      inner join sainvoice on sainvoice.sainvoiceid=salogisdetail.fsourceid where SALOGIS.fstatus ='µ½»õ' and SALOGIS.siteid='HY' and fsonum=$fsonum$ order by SALOGIS.receivedate desc

+ 16 - 0
src/rest/openapi/restcontroller/hyworkorder/webapp/User/HyWorkerUser.java

@@ -131,4 +131,20 @@ public class HyWorkerUser extends Controller {
             return getReturnObject_err("没有指定where参数").toString();
         }
     }
+
+    /**海盐服务人员查询**/
+    public String queryworkers(){
+        if(StringUtils.isBlank(hrid))return getReturnObject_err("hrid为空").toString();
+        //if(StringUtils.isBlank(fagentnum))return getReturnObject_err("fagentnum为空").toString();
+        if(StringUtils.isBlank(siteid))return getReturnObject_err("siteid为空").toString();
+        JSONObject where = content.getJSONObject("where");
+        String wherestr="1=1";
+//        String s[] = {"servicenum"};
+//        for (String s1 : s) {
+//            if (!where.containsKey(s1))return getReturnObject_err("缺少" + s1 + "参数").toString();
+//        }
+        DBConnect dbConnect=new DBConnect();
+        Rows rows = dbConnect.runSqlQuery("select hyworkernum,fname,fsex,role from HYWORKER where siteid='"+siteid+"' and fisused=1");
+        return getReturnObject_suc(rows,false).toString();
+    }
 }

+ 889 - 711
src/rest/openapi/restcontroller/hyworkorder/webapp/workorder/HyWorkOrder.java

@@ -26,212 +26,241 @@ import java.util.*;
 
 public class HyWorkOrder extends Controller {
 
-    public HyWorkOrder(JSONObject content) {
-        super(content);
-    }
-
-    /**工单列表**/
-    public String list(){
-        if(StringUtils.isBlank(hrid))return getReturnObject_err("hrid为空").toString();
+	public HyWorkOrder(JSONObject content) {
+		super(content);
+	}
+
+	/** 工单列表 **/
+	public String list() {
+		if (StringUtils.isBlank(hrid))
+			return getReturnObject_err("hrid为空").toString();
 //        if(StringUtils.isBlank(fagentnum))return getReturnObject_err("fagentnum为空").toString();
-        if(StringUtils.isBlank(siteid))return getReturnObject_err("siteid为空").toString();
-        JSONObject where = content.getJSONObject("where");
-        String wherestr="1=1";
-        String s[]={"fstatus"};
-        for (String s1 : s) {
-            if(!where.containsKey(s1)&&!StringUtils.isBlank(where.getString(s1)))return getReturnObject_err("缺少"+s1+"参数").toString();
-        }
-        if(where!=null){
-            DBConnect dbConnect=new DBConnect();
-            if(where.containsKey("fstatus")&&!StringUtils.isBlank(where.getString("fstatus"))){
-                wherestr+=" and t.fstatus ='"+where.getString("fstatus")+"' ";
-            }
-
-            SQLFactory factory=new SQLFactory(this,"工单列表查询",pageSize,pageNumber,"t.createdate desc");
-            factory.addParameter("hrid",hrid);
-            factory.addParameter("siteid",siteid);
-            factory.addParameter_SQL("where",wherestr);
-            SQLFactory factory2=new SQLFactory(this,"工单状态统计");
-            factory2.addParameter("hrid",hrid);
-            factory2.addParameter("siteid",siteid);
-            Rows rows_total = dbConnect.runSqlQuery(factory2.getSQL());
-            Rows rows = dbConnect.runSqlQuery(factory.getSQL());
-            if(!rows_total.isEmpty())returnObject.put("rows_total",rows_total.get(0));
-            return getReturnObject_suc_page(rows,false,0).toString();
-        }
-        return getReturnObject_err("缺少where参数").toString();
-    }
-
-
-    /**工单详情**/
-    public String detail(){
+		if (StringUtils.isBlank(siteid))
+			return getReturnObject_err("siteid为空").toString();
+		JSONObject where = content.getJSONObject("where");
+		String wherestr = "1=1";
+		String s[] = { "fstatus" };
+		for (String s1 : s) {
+			if (!where.containsKey(s1) && !StringUtils.isBlank(where.getString(s1)))
+				return getReturnObject_err("缺少" + s1 + "参数").toString();
+		}
+		if (where != null) {
+			DBConnect dbConnect = new DBConnect();
+			if (where.containsKey("fstatus") && !StringUtils.isBlank(where.getString("fstatus"))) {
+				wherestr += " and t.fstatus ='" + where.getString("fstatus") + "' ";
+			}
+
+			SQLFactory factory = new SQLFactory(this, "工单列表查询", pageSize, pageNumber, "t.createdate desc");
+			factory.addParameter("hrid", hrid);
+			factory.addParameter("siteid", siteid);
+			factory.addParameter_SQL("where", wherestr);
+			SQLFactory factory2 = new SQLFactory(this, "工单状态统计");
+			factory2.addParameter("hrid", hrid);
+			factory2.addParameter("siteid", siteid);
+			Rows rows_total = dbConnect.runSqlQuery(factory2.getSQL());
+			Rows rows = dbConnect.runSqlQuery(factory.getSQL());
+			if (!rows_total.isEmpty())
+				returnObject.put("rows_total", rows_total.get(0));
+			return getReturnObject_suc_page(rows, false, 0).toString();
+		}
+		return getReturnObject_err("缺少where参数").toString();
+	}
+
+	/** 工单详情 **/
+	public String detail() {
 //        if (StringUtils.isBlank(hrid)) getReturnObject_err("hrid为空").toString();
 //        if (StringUtils.isBlank(fagentnum)) getReturnObject_err("fagentnum为空").toString();
 //        if (StringUtils.isBlank(siteid)) getReturnObject_err("siteid为空").toString();
-        JSONObject where = content.getJSONObject("where");
-        String s[] = {"fworknum"};
-        for (String s1 : s) {
-            if (!where.containsKey(s1) && !StringUtils.isBlank(where.getString(s1)))
-                return getReturnObject_err("缺少" + s1 + "参数").toString();
-        }
-        if (where != null) {
-
-            try {
-                PaoSetRemote workorder = getpaoset("hyWorkorder");
-                workorder.setInsertSite(siteid);
-                workorder.setWhere("fworknum='" + where.getString("fworknum") + "'");
-                workorder.reset();
-                if (!workorder.isEmpty()) {
-                    PaoRemote workorderpao = workorder.getPao(0);
-                    String []from_detail={"fstatus","ftype","fworknum","servernum","createdate","faddress","projectleader","ownerid","fagentnum","scenefname","scenephone"};
-                    String []to_detail={"fstatus","ftype","fworknum","servernum","createdate","faddress","projectleader","hyworkorderid","fagentnum","scenefname","scenephone"};
-                    Row row_detail = getrow(from_detail,to_detail,workorderpao);
-                    /**工单详情**/
-                    /**
-                     * t.fstatus,t.ftype,t.fworknum,t.servernum,t.customername,t.customephone,convert(varchar,t.createdate,120)createdate,t.faddress,t.installer,
-                     *        t.installerphone,t1.fisfillac,t.siteid,t.fagentnum
-                     * **/
-                    PaoSetRemote workordertemplate = workorderpao.getPaoSet("HYWORKORDERTEMPLATE");
-
-
-                    /**工单团队查询**/
-                    PaoSetRemote workorder_team = workorderpao.getPaoSet("HYWORKORDER_TEAM");
-                    Rows rows_team=new Rows();
-                    if(!workorder_team.isEmpty()){
-                        for(int i=0;i<workorder_team.count();i++){
-                            Row row=new Row();
-                            //t.workername,t.ftype role,t.workephone workerllphone
-                            row.put("workername",workorder_team.getPao(i).getString("workername"));
-                            row.put("role",workorder_team.getPao(i).getString("ftype"));
-                            row.put("workerllphone",workorder_team.getPao(i).getString("workephone"));
-                            row.put("hyworkernum",workorder_team.getPao(i).getString("hyworkernum"));
-                            rows_team.add(row);
-                        }
-                    }
-                    row_detail.put("team",rows_team);
-
-                    /**工单工序查询**/
-
-                    PaoSetRemote ordernode = workorderpao.getPaoSet("HYORDERNODE");
-                    ordernode.setWhere("oneprocessname is not null");
-                    ordernode.setOrderBy("frownum");
-                    ordernode.reset();
-                    Rows rows_nodes=new Rows();
-                    /**一级工序**/
-                    if(!ordernode.isEmpty()){
-                        String []from_nodes={"frownum","oneprocessname","twoprocessname","operating","operatingtime","fnotes","ownerid","supid","ischilden","isconfirm","fisupload","fisaddtitem","fiscomplete","fisOperator","fistext","fisconfirmation","fiscontract"};
-                        String []to_nodes={"frownum","oneprocessname","twoprocessname","operating","operatingtime","fnotes","hyordernodeid","supid","ischilden","isconfirm","fisupload","fisaddtitem","fiscomplete","fisOperator","fistext","fisconfirmation","fiscontract"};
-                        for(int i=0;i<ordernode.count();i++){
-
-                            PaoRemote pao = ordernode.getPao(i);
-                            Row row=getrow(from_nodes,to_nodes,pao);
-                            //t.frownum,t.oneprocessname,t.twoprocessname,t.operating,substring( convert(varchar,t.operatingtime,120),1,16)operatingtime,t1.fname operator,
-                            //       t.fnotes,t.ordernodeid ownerid,t.supid,t.ischilhyden,t.isconfirm,t.fisupload,t.fisnotes,t.fisaddtitem,t.fiscomplete
-
-                            PaoSetRemote paoSet = pao.getPaoSet("$hyworker", "hyworker", "hyworkernum='" + pao.getString("operator") + "'");
-                            if(!paoSet.isEmpty()){
-                                row.put("operator",paoSet.getPao(0).getString("fname"));
-                            }else{
-                                row.put("operator",null);
-                            }
-                            /**附件查询**/
-                            //select tattachmentid,fdocument document,UPPER(postfix) postfix,fobsurl url,serialnumber,type,case when postfix in ('JPG','PNG','JEPG','jpg','png','jepg') then 'image' when postfix in ('MP4','mp4') then 'video' else 'file' end type2 from tattachment where
-                            PaoSetRemote paoSet_url = pao.getPaoSet("$tattachment", "tattachment", "ownertable='HYORDERNODE' and ownerid =" + pao.getInt("hyordernodeid"));
-                            if(!paoSet_url.isEmpty()){
-                                Rows rows=new Rows();
-                                for(int index=0;index<paoSet_url.count();index++){
-                                    PaoRemote pao1 = paoSet_url.getPao(index);
-                                    Row row1=new Row();
-                                    String postfix = pao1.getString("postfix");
-                                    row1.put("tattachmentid",pao1.getInt("tattachmentid"));
-                                    row1.put("document",pao1.getString("fdocument"));
-                                    row1.put("postfix",postfix.toUpperCase());
-                                    row1.put("url",pao1.getString("fobsurl"));
-                                    row1.put("serialnumber",pao1.getString("serialnumber"));
-                                    row1.put("type",pao1.getString("type"));
-                                    if(postfix.equalsIgnoreCase("JPG")||postfix.equalsIgnoreCase("PNG")||postfix.equalsIgnoreCase("JEPG")){
-                                        row1.put("type2","image");
-                                    }else if(postfix.equalsIgnoreCase("mp4")){
-                                        row1.put("type2","video");
-                                    }else{
-                                        row1.put("type2","file");
-                                    }
-                                    rows.add(row1);
-                                }
-                                row.put("url",rows);
-                            }else{
-                                row.put("url",new Rows());
-                            }
-
-                            Rows child=new Rows();
-                            PaoSetRemote ordernode2 = workorderpao.getPaoSet("$HYORDERNODE","HYORDERNODE","fparentid="+workorderpao.getUniqueIDValue()+" and supid="+pao.getUniqueIDValue());
+		JSONObject where = content.getJSONObject("where");
+		String s[] = { "fworknum" };
+		for (String s1 : s) {
+			if (!where.containsKey(s1) && !StringUtils.isBlank(where.getString(s1)))
+				return getReturnObject_err("缺少" + s1 + "参数").toString();
+		}
+		if (where != null) {
+
+			try {
+				PaoSetRemote workorder = getpaoset("hyWorkorder");
+				workorder.setInsertSite(siteid);
+				workorder.setWhere("fworknum='" + where.getString("fworknum") + "'");
+				workorder.reset();
+				if (!workorder.isEmpty()) {
+					PaoRemote workorderpao = workorder.getPao(0);
+					String[] from_detail = { "fstatus", "ftype", "fworknum", "servernum", "createdate", "faddress",
+							"projectleader", "ownerid", "fagentnum", "scenefname", "scenephone" };
+					String[] to_detail = { "fstatus", "ftype", "fworknum", "servernum", "createdate", "faddress",
+							"projectleader", "hyworkorderid", "fagentnum", "scenefname", "scenephone" };
+					Row row_detail = getrow(from_detail, to_detail, workorderpao);
+					/** 工单详情 **/
+					/**
+					 * t.fstatus,t.ftype,t.fworknum,t.servernum,t.customername,t.customephone,convert(varchar,t.createdate,120)createdate,t.faddress,t.installer,
+					 * t.installerphone,t1.fisfillac,t.siteid,t.fagentnum
+					 **/
+					PaoSetRemote workordertemplate = workorderpao.getPaoSet("HYWORKORDERTEMPLATE");
+
+					/** 工单团队查询 **/
+					PaoSetRemote workorder_team = workorderpao.getPaoSet("HYWORKORDER_TEAM");
+					Rows rows_team = new Rows();
+					if (!workorder_team.isEmpty()) {
+						for (int i = 0; i < workorder_team.count(); i++) {
+							Row row = new Row();
+							// t.workername,t.ftype role,t.workephone workerllphone
+							row.put("workername", workorder_team.getPao(i).getString("workername"));
+							row.put("role", workorder_team.getPao(i).getString("ftype"));
+							row.put("workerllphone", workorder_team.getPao(i).getString("workephone"));
+							row.put("hyworkernum", workorder_team.getPao(i).getString("hyworkernum"));
+							rows_team.add(row);
+						}
+					}
+					row_detail.put("team", rows_team);
+
+					/** 工单工序查询 **/
+
+					PaoSetRemote ordernode = workorderpao.getPaoSet("HYORDERNODE");
+					ordernode.setWhere("oneprocessname is not null");
+					ordernode.setOrderBy("frownum");
+					ordernode.reset();
+					Rows rows_nodes = new Rows();
+					/** 一级工序 **/
+					if (!ordernode.isEmpty()) {
+						String[] from_nodes = { "frownum", "oneprocessname", "twoprocessname", "operating",
+								"operatingtime", "fnotes", "ownerid", "supid", "ischilden", "isconfirm", "fisupload",
+								"fisaddtitem", "fiscomplete", "fisOperator", "fistext", "fisconfirmation",
+								"fiscontract" };
+						String[] to_nodes = { "frownum", "oneprocessname", "twoprocessname", "operating",
+								"operatingtime", "fnotes", "hyordernodeid", "supid", "ischilden", "isconfirm",
+								"fisupload", "fisaddtitem", "fiscomplete", "fisOperator", "fistext", "fisconfirmation",
+								"fiscontract" };
+						for (int i = 0; i < ordernode.count(); i++) {
+
+							PaoRemote pao = ordernode.getPao(i);
+							Row row = getrow(from_nodes, to_nodes, pao);
+							// t.frownum,t.oneprocessname,t.twoprocessname,t.operating,substring(
+							// convert(varchar,t.operatingtime,120),1,16)operatingtime,t1.fname operator,
+							// t.fnotes,t.ordernodeid
+							// ownerid,t.supid,t.ischilhyden,t.isconfirm,t.fisupload,t.fisnotes,t.fisaddtitem,t.fiscomplete
+
+							PaoSetRemote paoSet = pao.getPaoSet("$hyworker", "hyworker",
+									"hyworkernum='" + pao.getString("operator") + "'");
+							if (!paoSet.isEmpty()) {
+								row.put("operator", paoSet.getPao(0).getString("fname"));
+							} else {
+								row.put("operator", null);
+							}
+							/** 附件查询 **/
+							// select tattachmentid,fdocument document,UPPER(postfix) postfix,fobsurl
+							// url,serialnumber,type,case when postfix in
+							// ('JPG','PNG','JEPG','jpg','png','jepg') then 'image' when postfix in
+							// ('MP4','mp4') then 'video' else 'file' end type2 from tattachment where
+							PaoSetRemote paoSet_url = pao.getPaoSet("$tattachment", "tattachment",
+									"ownertable='HYORDERNODE' and ownerid =" + pao.getInt("hyordernodeid"));
+							if (!paoSet_url.isEmpty()) {
+								Rows rows = new Rows();
+								for (int index = 0; index < paoSet_url.count(); index++) {
+									PaoRemote pao1 = paoSet_url.getPao(index);
+									Row row1 = new Row();
+									String postfix = pao1.getString("postfix");
+									row1.put("tattachmentid", pao1.getInt("tattachmentid"));
+									row1.put("document", pao1.getString("fdocument"));
+									row1.put("postfix", postfix.toUpperCase());
+									row1.put("url", pao1.getString("fobsurl"));
+									row1.put("serialnumber", pao1.getString("serialnumber"));
+									row1.put("type", pao1.getString("type"));
+									if (postfix.equalsIgnoreCase("JPG") || postfix.equalsIgnoreCase("PNG")
+											|| postfix.equalsIgnoreCase("JEPG")) {
+										row1.put("type2", "image");
+									} else if (postfix.equalsIgnoreCase("mp4")) {
+										row1.put("type2", "video");
+									} else {
+										row1.put("type2", "file");
+									}
+									rows.add(row1);
+								}
+								row.put("url", rows);
+							} else {
+								row.put("url", new Rows());
+							}
+
+							Rows child = new Rows();
+							PaoSetRemote ordernode2 = workorderpao.getPaoSet("$HYORDERNODE", "HYORDERNODE", "fparentid="
+									+ workorderpao.getUniqueIDValue() + " and supid=" + pao.getUniqueIDValue());
 //                            System.out.println(workorderpao.getUniqueIDValue());
 //                            System.out.println(pao.getInt("supid"));
-                            ordernode2.setOrderBy("frownum");
-                            ordernode2.reset();
-                            /**二级工序**/
-                            String []from_nodes2={"frownum","oneprocessname","twoprocessname","operating","operatingtime","fnotes","ownerid","supid","ischilden","isconfirm","fisupload","fisaddtitem","fiscomplete","fisOperator","fistext","fisconfirmation","fiscontract"};
-                            String []to_nodes2={"frownum","oneprocessname","twoprocessname","operating","operatingtime","fnotes","hyordernodeid","supid","ischilden","isconfirm","fisupload","fisaddtitem","fiscomplete","fisOperator","fistext","fisconfirmation","fiscontract"};
-                            for(int j=0;j<ordernode2.count();j++){
-                                PaoRemote pao1 = ordernode2.getPao(j);
-                                Row row1=getrow(from_nodes2, to_nodes2,pao1);
-
-                                PaoSetRemote paoSet2 = pao.getPaoSet("$hyworker", "hyworker", "hyworkernum='" + pao1.getString("operator") + "'");
-                                if(!paoSet2.isEmpty()){
-                                    row1.put("operator",paoSet2.getPao(0).getString("fname"));
-                                }else{
-                                    row1.put("operator",null);
-                                }
-                                PaoSetRemote paoSet_url2 = pao.getPaoSet("$tattachment", "tattachment", "ownertable='HYORDERNODE' and ownerid =" + pao1.getInt("hyordernodeid"));
-                                if(!paoSet_url.isEmpty()){
-                                    Rows rows=new Rows();
-                                    for(int index=0;index<paoSet_url2.count();index++){
-                                        PaoRemote pao2 = paoSet_url2.getPao(index);
-                                        Row row2=new Row();
-                                        String postfix = pao2.getString("postfix");
-                                        row2.put("tattachmentid",pao2.getInt("tattachmentid"));
-                                        row2.put("document",pao2.getString("fdocument"));
-                                        row2.put("postfix",postfix.toUpperCase());
-                                        row2.put("url",pao2.getString("fobsurl"));
-                                        row2.put("serialnumber",pao2.getString("serialnumber"));
-                                        row2.put("type",pao2.getString("type"));
-                                        if(postfix.equalsIgnoreCase("JPG")||postfix.equalsIgnoreCase("PNG")||postfix.equalsIgnoreCase("JEPG")){
-                                            row2.put("type2","image");
-                                        }else if(postfix.equalsIgnoreCase("mp4")){
-                                            row2.put("type2","video");
-                                        }else{
-                                            row2.put("type2","file");
-                                        }
-                                        rows.add(row2);
-                                    }
-                                    row1.put("url",rows);
-                                }else{
-                                    row1.put("url",new Rows());
-                                }
-                                child.add(row1);
-                            }
-                            row.put("child",child);
-                            rows_nodes.add(row);
-                        }
-                    }
-                    row_detail.put("nodes",rows_nodes);
-
-                    /**工单物料查询**/
-                    PaoSetRemote workorder_titem = workorderpao.getPaoSet("hyworkorder_titem");
-                    Rows rows_titems=new Rows();
-                    String url="null";
-                    PaoSetRemote sysvars = getpaoset("sysvars");
-                    sysvars.setInsertSite(workorderpao.getInsertSite());
-                    if(!sysvars.isEmpty())url=WebClientRest.FILE_URL+sysvars.getPao(0).getInt("fdefaultitempic");
-                    if(!workorder_titem.isEmpty()){
-                        for(int i=0;i<workorder_titem.count();i++){
-                            PaoRemote pao = workorder_titem.getPao(i);
-                            Row row=new Row();
-                            row.put("fitemno",pao.getString("fitemno"));
-                            row.put("fitemname",pao.getString("fitemname"));
-                            row.put("fmodel",pao.getString("fmodel"));
-                            row.put("fspec",pao.getString("fspec"));
-                            row.put("fqty",pao.getInt("fqty"));
+							ordernode2.setOrderBy("frownum");
+							ordernode2.reset();
+							/** 二级工序 **/
+							String[] from_nodes2 = { "frownum", "oneprocessname", "twoprocessname", "operating",
+									"operatingtime", "fnotes", "ownerid", "supid", "ischilden", "isconfirm",
+									"fisupload", "fisaddtitem", "fiscomplete", "fisOperator", "fistext",
+									"fisconfirmation", "fiscontract" };
+							String[] to_nodes2 = { "frownum", "oneprocessname", "twoprocessname", "operating",
+									"operatingtime", "fnotes", "hyordernodeid", "supid", "ischilden", "isconfirm",
+									"fisupload", "fisaddtitem", "fiscomplete", "fisOperator", "fistext",
+									"fisconfirmation", "fiscontract" };
+							for (int j = 0; j < ordernode2.count(); j++) {
+								PaoRemote pao1 = ordernode2.getPao(j);
+								Row row1 = getrow(from_nodes2, to_nodes2, pao1);
+
+								PaoSetRemote paoSet2 = pao.getPaoSet("$hyworker", "hyworker",
+										"hyworkernum='" + pao1.getString("operator") + "'");
+								if (!paoSet2.isEmpty()) {
+									row1.put("operator", paoSet2.getPao(0).getString("fname"));
+								} else {
+									row1.put("operator", null);
+								}
+								PaoSetRemote paoSet_url2 = pao.getPaoSet("$tattachment", "tattachment",
+										"ownertable='HYORDERNODE' and ownerid =" + pao1.getInt("hyordernodeid"));
+								if (!paoSet_url.isEmpty()) {
+									Rows rows = new Rows();
+									for (int index = 0; index < paoSet_url2.count(); index++) {
+										PaoRemote pao2 = paoSet_url2.getPao(index);
+										Row row2 = new Row();
+										String postfix = pao2.getString("postfix");
+										row2.put("tattachmentid", pao2.getInt("tattachmentid"));
+										row2.put("document", pao2.getString("fdocument"));
+										row2.put("postfix", postfix.toUpperCase());
+										row2.put("url", pao2.getString("fobsurl"));
+										row2.put("serialnumber", pao2.getString("serialnumber"));
+										row2.put("type", pao2.getString("type"));
+										if (postfix.equalsIgnoreCase("JPG") || postfix.equalsIgnoreCase("PNG")
+												|| postfix.equalsIgnoreCase("JEPG")) {
+											row2.put("type2", "image");
+										} else if (postfix.equalsIgnoreCase("mp4")) {
+											row2.put("type2", "video");
+										} else {
+											row2.put("type2", "file");
+										}
+										rows.add(row2);
+									}
+									row1.put("url", rows);
+								} else {
+									row1.put("url", new Rows());
+								}
+								child.add(row1);
+							}
+							row.put("child", child);
+							rows_nodes.add(row);
+						}
+					}
+					row_detail.put("nodes", rows_nodes);
+
+					/** 工单物料查询 **/
+					PaoSetRemote workorder_titem = workorderpao.getPaoSet("hyworkorder_titem");
+					Rows rows_titems = new Rows();
+					String url = "null";
+					PaoSetRemote sysvars = getpaoset("sysvars");
+					sysvars.setInsertSite(workorderpao.getInsertSite());
+					if (!sysvars.isEmpty())
+						url = WebClientRest.FILE_URL + sysvars.getPao(0).getInt("fdefaultitempic");
+					if (!workorder_titem.isEmpty()) {
+						for (int i = 0; i < workorder_titem.count(); i++) {
+							PaoRemote pao = workorder_titem.getPao(i);
+							Row row = new Row();
+							row.put("fitemno", pao.getString("fitemno"));
+							row.put("fitemname", pao.getString("fitemname"));
+							row.put("fmodel", pao.getString("fmodel"));
+							row.put("fspec", pao.getString("fspec"));
+							row.put("fqty", pao.getInt("fqty"));
 //                            PaoSetRemote tagents_titem = pao.getPaoSet("TAGENTS_TITEM");
 //                            if(!tagents_titem.isEmpty()){
 //                                PaoRemote tagents_titem_pao = tagents_titem.getPao(0);
@@ -259,100 +288,98 @@ public class HyWorkOrder extends Controller {
 //                            }else{
 //                                row.put("url",url);
 //                            }
-                            rows_titems.add(row);
-                        }
-                    }
-                    row_detail.put("titems",rows_titems);
-                    return getReturnObject_suc(row_detail,false).toString();
-                }
-                return getReturnObject_err("该工单不存在").toString();
-
-            } catch (P2Exception e) {
-                e.printStackTrace();
-                return getReturnObject_err(e.getMessage()).toString();
-            }
-
-        }
-        return null;
-    }
-
-
-
-    public Row getrow(String []from,String[]to,PaoRemote pao) throws P2Exception {
-        GetP2Type getP2Type = new GetP2Type(pao.getName());
-        String pattern="yyyy-MM-dd HH:mm:ss";
-
-        Row row=new Row();
-        for (int i = 0; i < from.length; i++) {
-            String p2Type = getP2Type.getP2Type(to[i]);
-            //DECIMAL,FLOAT,INTEGER,SMALLINT,BOOLEAN
-            if(p2Type.equals("BOOLEAN")){
-                row.put(from[i],String.valueOf(pao.getInt(to[i])));
-            }else if(p2Type.equals("INTEGER")||p2Type.equals("SMALLINT")){
-                row.put(from[i],pao.getInt(to[i]));
-            }else if(p2Type.equals("DECIMAL")||p2Type.equals("FLOAT")){
-                row.put(from[i],pao.getDouble(to[i]));
-            }else if(p2Type.equals("DATE")||p2Type.equals("DATETIME")){
-                Date date = pao.getDate(to[i]);
-                if(date!=null)row.put(from[i],DateFormatUtils.format(date,pattern));
-                else row.put(from[i],"");
-
-            }else {
-                row.put(from[i],pao.getString(to[i]));
-            }
-        }
-        return row;
-    }
-
-    /**节点详情**/
-    public String nodedetail(){
+							rows_titems.add(row);
+						}
+					}
+					row_detail.put("titems", rows_titems);
+					return getReturnObject_suc(row_detail, false).toString();
+				}
+				return getReturnObject_err("该工单不存在").toString();
+
+			} catch (P2Exception e) {
+				e.printStackTrace();
+				return getReturnObject_err(e.getMessage()).toString();
+			}
+
+		}
+		return null;
+	}
+
+	public Row getrow(String[] from, String[] to, PaoRemote pao) throws P2Exception {
+		GetP2Type getP2Type = new GetP2Type(pao.getName());
+		String pattern = "yyyy-MM-dd HH:mm:ss";
+
+		Row row = new Row();
+		for (int i = 0; i < from.length; i++) {
+			String p2Type = getP2Type.getP2Type(to[i]);
+			// DECIMAL,FLOAT,INTEGER,SMALLINT,BOOLEAN
+			if (p2Type.equals("BOOLEAN")) {
+				row.put(from[i], String.valueOf(pao.getInt(to[i])));
+			} else if (p2Type.equals("INTEGER") || p2Type.equals("SMALLINT")) {
+				row.put(from[i], pao.getInt(to[i]));
+			} else if (p2Type.equals("DECIMAL") || p2Type.equals("FLOAT")) {
+				row.put(from[i], pao.getDouble(to[i]));
+			} else if (p2Type.equals("DATE") || p2Type.equals("DATETIME")) {
+				Date date = pao.getDate(to[i]);
+				if (date != null)
+					row.put(from[i], DateFormatUtils.format(date, pattern));
+				else
+					row.put(from[i], "");
+
+			} else {
+				row.put(from[i], pao.getString(to[i]));
+			}
+		}
+		return row;
+	}
+
+	/** 节点详情 **/
+	public String nodedetail() {
 //        if (StringUtils.isBlank(hrid)) getReturnObject_err("hrid为空").toString();
 //        if (StringUtils.isBlank(fagentnum)) getReturnObject_err("fagentnum为空").toString();
 //        if (StringUtils.isBlank(siteid)) getReturnObject_err("siteid为空").toString();
-        JSONObject where = content.getJSONObject("where");
-        String s[] = {"fworknum","frownum"};
-        for (String s1 : s) {
-            if (!where.containsKey(s1) && !StringUtils.isBlank(where.getString(s1)))
-                return getReturnObject_err("缺少" + s1 + "参数").toString();
-        }
-        if (where != null) {
-            DBConnect dbConnect = new DBConnect();
-
-            SQLFactory factory=new SQLFactory(this,"工单节点详情查询");
-            factory.addParameter("fworknum",where.getString("fworknum"));
-            factory.addParameter("frownum",where.getString("frownum"));
-            Rows rows = dbConnect.runSqlQuery(factory.getSQL());
-            if(!rows.isEmpty()){
-                Row rowdetail = rows.get(0);
-
-                    SQLFactory factoryurl=new SQLFactory(this,"华为云附件查询");
-                    factoryurl.addParameter("ownerid",rowdetail.getInteger("ownerid"));
-                    Rows rowsimg = dbConnect.runSqlQuery(factoryurl.getSQL());
-                    rowdetail.put("url",rowsimg);
-
-
-                Rows rows_team = dbConnect.runSqlQuery("select t.workername,t.workerphone,t.hyworkernum from hyordernode_team t\n" +
-                        "where EXISTS(select 1 from hyordernode t1 where t1.hyordernodeid=t.fparentid and t1.hyordernodeid="+rowdetail.getInteger("ownerid")+") and siteid='"+siteid+"'");
-                SQLFactory factory_team_url = new SQLFactory(this, "工单节点参与人员头像查询");
-                factory_team_url.addParameter("siteid",rowdetail.getString("siteid"));
-                factory_team_url.addParameter_SQL("hyworkernum",rows_team.getInWhere("hyworkernum"));
-                Rows rows_team_url = dbConnect.runSqlQuery(factory_team_url.getSQL());
-                RowsMap workerphone = rows_team_url.toRowsMap("hyworkernum");
-                for (Row row : rows_team) {
-                    if(workerphone.containsKey(row.getString("hyworkernum"))){
-                        row.put("url",workerphone.get(row.getString("hyworkernum")).get(0).getString("url"));
-                    }else{
-                        row.put("url",null);
-                    }
-                }
-                /**节点关联物料查询**/
-                Rows rows_titem = dbConnect.runSqlQuery("select t.fitemno,t.fitemname,t.fmodel,t.fspec,t.fqty from \n" +
-                        "hyworkorder_titem t\n" +
-                        "where EXISTS(select 1 from hyWorkorder t1 where t1.fworknum='"+where.getString("fworknum")+"' and t1.hyWorkorderid=t.fparentid)\n" +
-                        " and t.sourcenode='"+where.getString("frownum")+"'");
-
-
-
+		JSONObject where = content.getJSONObject("where");
+		String s[] = { "fworknum", "frownum" };
+		for (String s1 : s) {
+			if (!where.containsKey(s1) && !StringUtils.isBlank(where.getString(s1)))
+				return getReturnObject_err("缺少" + s1 + "参数").toString();
+		}
+		if (where != null) {
+			DBConnect dbConnect = new DBConnect();
+
+			SQLFactory factory = new SQLFactory(this, "工单节点详情查询");
+			factory.addParameter("fworknum", where.getString("fworknum"));
+			factory.addParameter("frownum", where.getString("frownum"));
+			Rows rows = dbConnect.runSqlQuery(factory.getSQL());
+			if (!rows.isEmpty()) {
+				Row rowdetail = rows.get(0);
+
+				SQLFactory factoryurl = new SQLFactory(this, "华为云附件查询");
+				factoryurl.addParameter("ownerid", rowdetail.getInteger("ownerid"));
+				Rows rowsimg = dbConnect.runSqlQuery(factoryurl.getSQL());
+				rowdetail.put("url", rowsimg);
+
+				Rows rows_team = dbConnect
+						.runSqlQuery("select t.workername,t.workerphone,t.hyworkernum from hyordernode_team t\n"
+								+ "where EXISTS(select 1 from hyordernode t1 where t1.hyordernodeid=t.fparentid and t1.hyordernodeid="
+								+ rowdetail.getInteger("ownerid") + ") and siteid='" + siteid + "'");
+				SQLFactory factory_team_url = new SQLFactory(this, "工单节点参与人员头像查询");
+				factory_team_url.addParameter("siteid", rowdetail.getString("siteid"));
+				factory_team_url.addParameter_SQL("hyworkernum", rows_team.getInWhere("hyworkernum"));
+				Rows rows_team_url = dbConnect.runSqlQuery(factory_team_url.getSQL());
+				RowsMap workerphone = rows_team_url.toRowsMap("hyworkernum");
+				for (Row row : rows_team) {
+					if (workerphone.containsKey(row.getString("hyworkernum"))) {
+						row.put("url", workerphone.get(row.getString("hyworkernum")).get(0).getString("url"));
+					} else {
+						row.put("url", null);
+					}
+				}
+				/** 节点关联物料查询 **/
+				Rows rows_titem = dbConnect.runSqlQuery("select t.fitemno,t.fitemname,t.fmodel,t.fspec,t.fqty from \n"
+						+ "hyworkorder_titem t\n" + "where EXISTS(select 1 from hyWorkorder t1 where t1.fworknum='"
+						+ where.getString("fworknum") + "' and t1.hyWorkorderid=t.fparentid)\n" + " and t.sourcenode='"
+						+ where.getString("frownum") + "'");
 
 //                SQLFactory factory_imgurl = new SQLFactory(this, "物料图片查询");
 //                factory_imgurl.addParameter("fagentnum", rowdetail.getString("fagentnum"));
@@ -368,71 +395,76 @@ public class HyWorkOrder extends Controller {
 //                    }
 //                }
 
-                rowdetail.put("team",rows_team);
-                rowdetail.put("titem",rows_titem);
-
-
-                return getReturnObject_suc(rowdetail,false).toString();
-
-            }
-            return getReturnObject_err("该节点不是末级节点").toString();
+				rowdetail.put("team", rows_team);
+				rowdetail.put("titem", rows_titem);
 
+				return getReturnObject_suc(rowdetail, false).toString();
 
-        }
-        return getReturnObject_err("缺少where参数").toString();
-    }
+			}
+			return getReturnObject_err("该节点不是末级节点").toString();
 
+		}
+		return getReturnObject_err("缺少where参数").toString();
+	}
 
-
-    /**更新节点内容**/
-    public String updatenode(){
-        if(StringUtils.isBlank(hrid))return getReturnObject_err("hrid为空").toString();
+	/** 更新节点内容 **/
+	public String updatenode() {
+		if (StringUtils.isBlank(hrid))
+			return getReturnObject_err("hrid为空").toString();
 //        if(StringUtils.isBlank(fagentnum))return getReturnObject_err("fagentnum为空").toString();
-        if(StringUtils.isBlank(siteid))return getReturnObject_err("siteid为空").toString();
-        JSONObject where = content.getJSONObject("where");
-        String s[] = {"fworknum","frownum"};
-        for (String s1 : s) {
-            if (!where.containsKey(s1) && !StringUtils.isBlank(where.getString(s1)))
-                return getReturnObject_err("缺少" + s1 + "参数").toString();
-        }
-        if (where != null) {
-            try {
-                PaoSetRemote workorder = P2Server.getP2Server().getPaoSet("hyWorkorder", P2Server.getP2Server().getSystemUserInfo());
-                workorder.setInsertSite(siteid);
-                workorder.setWhere("fworknum='"+where.getString("fworknum")+"'");
-                workorder.reset();
-                if(!workorder.isEmpty()){
-                    hyworkorder workorderPao = (hyworkorder)workorder.getPao(0);
-                    if(workorderPao.fisSuspend())return getReturnObject_err("工单处于暂停中").toString();
-                    if(workorderPao.fisvoid())return getReturnObject_err("工单已作废").toString();
-                    if(!workorderPao.getString("fstatus").equals("进行中"))return getReturnObject_err("非进行中工单不可修改").toString();
-                    PaoSetRemote ordernodeset = workorderPao.getPaoSet("hyordernode");
-                    ordernodeset.setWhere("frownum="+where.getInt("frownum"));
-                    ordernodeset.reset();
-                    if(!ordernodeset.isEmpty()){
-                        hyordernode ordernodePao = (hyordernode) ordernodeset.getPao(0);
-                        if(ordernodePao.getBoolean("ischilden"))return getReturnObject_err("该工序不是末级节点").toString();
-                        //if(ordernodePao.getBoolean("isconfirm"))return getReturnObject_err("该工序已经确认").toString();
-                        /**添加备注**/
-                        if(where.containsKey("fnotes"))ordernodePao.setValue("fnotes",where.getString("fnotes"),11l);
-                        /**添加团队**/
-                        if(where.containsKey("team")){
-                            JSONArray team = where.getJSONArray("team");
-                            PaoSetRemote ordernode_team1 = ordernodePao.getPaoSet("hyordernode_team");
-                            ordernode_team1.deleteAll();
-
-                            Set<String> set=new HashSet<>();
-                            for (Object o : team) {
-                                String worker=(String)o;
-                                set.add(worker);
-                            }
-                            for (String s1 : set) {
-                                PaoSetRemote ordernode_team = ordernodePao.getPaoSet("hyordernode_team");
-                                PaoRemote remote = ordernode_team.addAtEnd();
-                                remote.setValue("hyworkernum",s1,2l);
-                            }
-                        }
-                        /**添加是否合格项**/
+		if (StringUtils.isBlank(siteid))
+			return getReturnObject_err("siteid为空").toString();
+		JSONObject where = content.getJSONObject("where");
+		String s[] = { "fworknum", "frownum" };
+		for (String s1 : s) {
+			if (!where.containsKey(s1) && !StringUtils.isBlank(where.getString(s1)))
+				return getReturnObject_err("缺少" + s1 + "参数").toString();
+		}
+		if (where != null) {
+			try {
+				PaoSetRemote workorder = P2Server.getP2Server().getPaoSet("hyWorkorder",
+						P2Server.getP2Server().getSystemUserInfo());
+				workorder.setInsertSite(siteid);
+				workorder.setWhere("fworknum='" + where.getString("fworknum") + "'");
+				workorder.reset();
+				if (!workorder.isEmpty()) {
+					hyworkorder workorderPao = (hyworkorder) workorder.getPao(0);
+					if (workorderPao.fisSuspend())
+						return getReturnObject_err("工单处于暂停中").toString();
+					if (workorderPao.fisvoid())
+						return getReturnObject_err("工单已作废").toString();
+					if (!workorderPao.getString("fstatus").equals("进行中"))
+						return getReturnObject_err("非进行中工单不可修改").toString();
+					PaoSetRemote ordernodeset = workorderPao.getPaoSet("hyordernode");
+					ordernodeset.setWhere("frownum=" + where.getInt("frownum"));
+					ordernodeset.reset();
+					if (!ordernodeset.isEmpty()) {
+						hyordernode ordernodePao = (hyordernode) ordernodeset.getPao(0);
+						if (ordernodePao.getBoolean("ischilden"))
+							return getReturnObject_err("该工序不是末级节点").toString();
+						// if(ordernodePao.getBoolean("isconfirm"))return
+						// getReturnObject_err("该工序已经确认").toString();
+						/** 添加备注 **/
+						if (where.containsKey("fnotes"))
+							ordernodePao.setValue("fnotes", where.getString("fnotes"), 11l);
+						/** 添加团队 **/
+						if (where.containsKey("team")) {
+							JSONArray team = where.getJSONArray("team");
+							PaoSetRemote ordernode_team1 = ordernodePao.getPaoSet("hyordernode_team");
+							ordernode_team1.deleteAll();
+
+							Set<String> set = new HashSet<>();
+							for (Object o : team) {
+								String worker = (String) o;
+								set.add(worker);
+							}
+							for (String s1 : set) {
+								PaoSetRemote ordernode_team = ordernodePao.getPaoSet("hyordernode_team");
+								PaoRemote remote = ordernode_team.addAtEnd();
+								remote.setValue("hyworkernum", s1, 2l);
+							}
+						}
+						/** 添加是否合格项 **/
 //                        if(where.containsKey("qualified")){
 //                            ordernodePao.setValue("qualified",where.getBoolean("qualified"),11l);
 //                        }
@@ -440,107 +472,116 @@ public class HyWorkOrder extends Controller {
 //                            ordernodePao.setValue("explain",where.getString("explain"),11l);
 //                        }
 
-                        /**添加文本**/
-                        if(where.containsKey("ftext")){
+						/** 添加文本 **/
+						if (where.containsKey("ftext")) {
 
 //                            System.out.println("where:"+where.getString("ftext"));
-                            ordernodePao.setValue("ftext",where.getString("ftext"),11l);
-                        }
-                        /**添加确认**/
-                        if(where.containsKey("confirmation")){
-                            ordernodePao.setValue("confirmation",where.getBoolean("confirmation"),11l);
-                        }
-                        /**添加服务价格**/
-                        if(where.containsKey("serverprice")){
-                            ordernodePao.setValue("serverprice",where.getDouble("serverprice"),11l);
-                        }
-                        if(where.containsKey("isconfirm")){
-                            if(where.getBoolean("isconfirm")){
-                                ordernodePao.setValue("isconfirm",true,11l);
-                                ordernodePao.setValue("Operator",hrid,11l);
-                                ordernodePao.setValue("fstatus","完成",11l);
-                                Row completeAndTotal = workorderPao.getCompleteAndTotal();
-                                double count = completeAndTotal.getDouble("count");
-                                double complete = completeAndTotal.getInteger("complete");
-                                double result=(complete+1)/count*100;
-                                workorderPao.setValue("progress",result>=100?100:result,11l);
-                                ordernodePao.setValue("Operatingtime",new Date(),11l);
-                                String fiscomplate = ordernodePao.fiscomplate();
-                                if(!fiscomplate.equals("true"))return getReturnObject_err(fiscomplate).toString();
-                            }else{
-                                ordernodePao.setValue("isconfirm",false,11l);
-                                ordernodePao.setValue("fstatus","进行中",11l);
-                                Row completeAndTotal = workorderPao.getCompleteAndTotal();
-                                double count = completeAndTotal.getDouble("count");
-                                double complete = completeAndTotal.getInteger("complete");
-                                workorderPao.setValue("progress",(complete-1)/count*100,11l);
-                            }
-                        }
-                        //设置是否操作过
-                        ordernodePao.setValue("fisOperator",true,11l);
-                        //ordernode.save();
-                        workorder.save();
-
-                        return getReturnObject_suc().toString();
-                    }
-                    getReturnObject_err("该节点不存在").toString();
-                }
-                return getReturnObject_err("该工单不存在").toString();
-            } catch (P2Exception e) {
-                return getReturnObject_err(e.getMessage()).toString();
-            }
-        }
-        return getReturnObject_err("缺少where参数").toString();
-    }
-    /**退回工单**/
-    public String backorder(){
-        if(StringUtils.isBlank(hrid))return getReturnObject_err("hrid为空").toString();
+							ordernodePao.setValue("ftext", where.getString("ftext"), 11l);
+						}
+						/** 添加确认 **/
+						if (where.containsKey("confirmation")) {
+							ordernodePao.setValue("confirmation", where.getBoolean("confirmation"), 11l);
+						}
+						/** 添加服务价格 **/
+						if (where.containsKey("serverprice")) {
+							ordernodePao.setValue("serverprice", where.getDouble("serverprice"), 11l);
+						}
+						if (where.containsKey("isconfirm")) {
+							if (where.getBoolean("isconfirm")) {
+								ordernodePao.setValue("isconfirm", true, 11l);
+								ordernodePao.setValue("Operator", hrid, 11l);
+								ordernodePao.setValue("fstatus", "完成", 11l);
+								Row completeAndTotal = workorderPao.getCompleteAndTotal();
+								double count = completeAndTotal.getDouble("count");
+								double complete = completeAndTotal.getInteger("complete");
+								double result = (complete + 1) / count * 100;
+								workorderPao.setValue("progress", result >= 100 ? 100 : result, 11l);
+								ordernodePao.setValue("Operatingtime", new Date(), 11l);
+								String fiscomplate = ordernodePao.fiscomplate();
+								if (!fiscomplate.equals("true"))
+									return getReturnObject_err(fiscomplate).toString();
+							} else {
+								ordernodePao.setValue("isconfirm", false, 11l);
+								ordernodePao.setValue("fstatus", "进行中", 11l);
+								Row completeAndTotal = workorderPao.getCompleteAndTotal();
+								double count = completeAndTotal.getDouble("count");
+								double complete = completeAndTotal.getInteger("complete");
+								workorderPao.setValue("progress", (complete - 1) / count * 100, 11l);
+							}
+						}
+						// 设置是否操作过
+						ordernodePao.setValue("fisOperator", true, 11l);
+						// ordernode.save();
+						workorder.save();
+
+						return getReturnObject_suc().toString();
+					}
+					getReturnObject_err("该节点不存在").toString();
+				}
+				return getReturnObject_err("该工单不存在").toString();
+			} catch (P2Exception e) {
+				return getReturnObject_err(e.getMessage()).toString();
+			}
+		}
+		return getReturnObject_err("缺少where参数").toString();
+	}
+
+	/** 退回工单 **/
+	public String backorder() {
+		if (StringUtils.isBlank(hrid))
+			return getReturnObject_err("hrid为空").toString();
 //        if(StringUtils.isBlank(fagentnum))return getReturnObject_err("fagentnum为空").toString();
-        if(StringUtils.isBlank(siteid))return getReturnObject_err("siteid为空").toString();
-        JSONObject where = content.getJSONObject("where");
-        String s[] = {"fworknum","reason"};
-        for (String s1 : s) {
-            if (!where.containsKey(s1) && !StringUtils.isBlank(where.getString(s1)))
-                return getReturnObject_err("缺少" + s1 + "参数").toString();
-        }
-        if (where != null) {
-            try {
-                PaoSetRemote workorder = P2Server.getP2Server().getPaoSet("Workorder", P2Server.getP2Server().getSystemUserInfo());
-                workorder.setInsertSite(siteid);
-                workorder.setWhere("fworknum='"+where.getString("fworknum")+"'");
-                workorder.reset();
-                if(!workorder.isEmpty()){
-                    workorder workorderPao = (workorder) workorder.getPao(0);
-                    workorderPao.back();
-                    workorder.save();
-                    return getReturnObject_suc().toString();
-                }
-                return getReturnObject_err("该工单不存在").toString();
-            } catch (P2Exception e) {
-                return getReturnObject_err(e.getMessage()).toString();
-            }
-        }
-        return getReturnObject_err("缺少where参数").toString();
-    }
-    /**完结工单**/
-    public String completeorder(){
-        if(StringUtils.isBlank(hrid))return getReturnObject_err("hrid为空").toString();
+		if (StringUtils.isBlank(siteid))
+			return getReturnObject_err("siteid为空").toString();
+		JSONObject where = content.getJSONObject("where");
+		String s[] = { "fworknum", "reason" };
+		for (String s1 : s) {
+			if (!where.containsKey(s1) && !StringUtils.isBlank(where.getString(s1)))
+				return getReturnObject_err("缺少" + s1 + "参数").toString();
+		}
+		if (where != null) {
+			try {
+				PaoSetRemote workorder = P2Server.getP2Server().getPaoSet("Workorder",
+						P2Server.getP2Server().getSystemUserInfo());
+				workorder.setInsertSite(siteid);
+				workorder.setWhere("fworknum='" + where.getString("fworknum") + "'");
+				workorder.reset();
+				if (!workorder.isEmpty()) {
+					workorder workorderPao = (workorder) workorder.getPao(0);
+					workorderPao.back();
+					workorder.save();
+					return getReturnObject_suc().toString();
+				}
+				return getReturnObject_err("该工单不存在").toString();
+			} catch (P2Exception e) {
+				return getReturnObject_err(e.getMessage()).toString();
+			}
+		}
+		return getReturnObject_err("缺少where参数").toString();
+	}
+
+	/** 完结工单 **/
+	public String completeorder() {
+		if (StringUtils.isBlank(hrid))
+			return getReturnObject_err("hrid为空").toString();
 //        if(StringUtils.isBlank(fagentnum))return getReturnObject_err("fagentnum为空").toString();
-        if(StringUtils.isBlank(siteid))return getReturnObject_err("siteid为空").toString();
-        JSONObject where = content.getJSONObject("where");
-        String s[] = {"fworknum"};
-        for (String s1 : s) {
-            if (!where.containsKey(s1) && !StringUtils.isBlank(where.getString(s1)))
-                return getReturnObject_err("缺少" + s1 + "参数").toString();
-        }
-        if (where != null) {
-            try {
-                PaoSetRemote workorder = P2Server.getP2Server().getPaoSet("hyWorkorder", P2Server.getP2Server().getSystemUserInfo());
-                workorder.setInsertSite(siteid);
-                workorder.setWhere("fworknum='"+where.getString("fworknum")+"'");
-                workorder.reset();
-                if(!workorder.isEmpty()){
-                    hyworkorder workorderPao = (hyworkorder) workorder.getPao(0);
+		if (StringUtils.isBlank(siteid))
+			return getReturnObject_err("siteid为空").toString();
+		JSONObject where = content.getJSONObject("where");
+		String s[] = { "fworknum" };
+		for (String s1 : s) {
+			if (!where.containsKey(s1) && !StringUtils.isBlank(where.getString(s1)))
+				return getReturnObject_err("缺少" + s1 + "参数").toString();
+		}
+		if (where != null) {
+			try {
+				PaoSetRemote workorder = P2Server.getP2Server().getPaoSet("hyWorkorder",
+						P2Server.getP2Server().getSystemUserInfo());
+				workorder.setInsertSite(siteid);
+				workorder.setWhere("fworknum='" + where.getString("fworknum") + "'");
+				workorder.reset();
+				if (!workorder.isEmpty()) {
+					hyworkorder workorderPao = (hyworkorder) workorder.getPao(0);
 //                    PaoSetRemote workorder_errormsg_set = workorderPao.getPaoSet("workorder_errormsg");
 //                    workorder_errormsg_set.setWhere("fisprocess=0");
 //                    workorder_errormsg_set.reset();
@@ -548,277 +589,414 @@ public class HyWorkOrder extends Controller {
 //                        return getReturnObject_err("该工单存在申请待处理,不能继续操作").toString();
 //                    }
 
-                    workorderPao.complete(true,hrid);
-                        /**客户积分更新**/
-                        workorder.save();
-                        return getReturnObject_suc().toString();
-
-                }
-                return getReturnObject_err("该工单不存在").toString();
-            } catch (P2Exception e) {
-                e.printStackTrace();
-                return getReturnObject_err(e.getMessage()).toString();
-            } catch (Exception e) {
-                e.printStackTrace();
-                return getReturnObject_err(e.getMessage()).toString();
-            }
-        }
-        return getReturnObject_err("缺少where参数").toString();
-    }
-
-    /**开始工单**/
-    public String start(){
-        if(StringUtils.isBlank(hrid))return getReturnObject_err("hrid为空").toString();
+					workorderPao.complete(true, hrid);
+					/** 客户积分更新 **/
+					workorder.save();
+					return getReturnObject_suc().toString();
+
+				}
+				return getReturnObject_err("该工单不存在").toString();
+			} catch (P2Exception e) {
+				e.printStackTrace();
+				return getReturnObject_err(e.getMessage()).toString();
+			} catch (Exception e) {
+				e.printStackTrace();
+				return getReturnObject_err(e.getMessage()).toString();
+			}
+		}
+		return getReturnObject_err("缺少where参数").toString();
+	}
+
+	/** 开始工单 **/
+	public String start() {
+		if (StringUtils.isBlank(hrid))
+			return getReturnObject_err("hrid为空").toString();
+//        if(StringUtils.isBlank(fagentnum))return getReturnObject_err("fagentnum为空").toString();
+		if (StringUtils.isBlank(siteid))
+			return getReturnObject_err("siteid为空").toString();
+		JSONObject where = content.getJSONObject("where");
+		String s[] = { "fworknum" };
+		for (String s1 : s) {
+			if (!where.containsKey(s1) && !StringUtils.isBlank(where.getString(s1)))
+				return getReturnObject_err("缺少" + s1 + "参数").toString();
+		}
+		if (where != null) {
+			try {
+				PaoSetRemote workorder = P2Server.getP2Server().getPaoSet("hyWorkorder",
+						P2Server.getP2Server().getSystemUserInfo());
+				workorder.setInsertSite(siteid);
+				workorder.setWhere("fworknum='" + where.getString("fworknum") + "'");
+				workorder.reset();
+				if (!workorder.isEmpty()) {
+					hyworkorder workorderPao = (hyworkorder) workorder.getPao(0);
+					workorderPao.start();
+					workorder.save();
+					return getReturnObject_suc().toString();
+				}
+				return getReturnObject_err("该工单不存在").toString();
+			} catch (P2Exception e) {
+				return getReturnObject_err(e.getMessage()).toString();
+			}
+		}
+		return getReturnObject_err("缺少where参数").toString();
+	}
+
+	/** 工单暂停 **/
+	public String stop() {
+		if (StringUtils.isBlank(hrid))
+			return getReturnObject_err("hrid为空").toString();
+//        if(StringUtils.isBlank(fagentnum))return getReturnObject_err("fagentnum为空").toString();
+		if (StringUtils.isBlank(siteid))
+			return getReturnObject_err("siteid为空").toString();
+
+		JSONObject where = content.getJSONObject("where");
+		String s[] = { "fworknum" };
+		for (String s1 : s) {
+			if (!where.containsKey(s1))
+				return getReturnObject_err("缺少" + s1 + "参数").toString();
+		}
+		if (where != null) {
+			PaoSetRemote workorders;
+			try {
+				workorders = P2Server.getP2Server().getPaoSet("hyWorkorder",
+						P2Server.getP2Server().getSystemUserInfo());
+
+				workorders.setInsertSite(siteid);
+				workorders.setWhere("fworknum='" + where.getString("fworknum") + "'");
+				workorders.reset();
+				if (workorders.isEmpty())
+					return getReturnObject_err("没有该工单").toString();
+				hyworkorder hyworkorder = (hyworkorder) workorders.getPao(0);
+				if (!hyworkorder.getString("fstatus").equals("进行中")) {
+					return getReturnObject_err("非进行中不可暂停").toString();
+				}
+				hyworkorder.setValue("fstatus", "暂停", 11L);
+				workorders.save();
+				return getReturnObject_suc().toString();
+			} catch (P2Exception e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+				return getReturnObject_err(e.getMessage()).toString();
+			}
+		}
+
+		return getReturnObject_err("where参数不存在").toString();
+	}
+	/** 工单启用**/
+	public String used() {
+		if (StringUtils.isBlank(hrid))
+			return getReturnObject_err("hrid为空").toString();
+//        if(StringUtils.isBlank(fagentnum))return getReturnObject_err("fagentnum为空").toString();
+		if (StringUtils.isBlank(siteid))
+			return getReturnObject_err("siteid为空").toString();
+
+		JSONObject where = content.getJSONObject("where");
+		String s[] = { "fworknum" };
+		for (String s1 : s) {
+			if (!where.containsKey(s1))
+				return getReturnObject_err("缺少" + s1 + "参数").toString();
+		}
+		if (where != null) {
+			PaoSetRemote workorders;
+			try {
+				workorders = P2Server.getP2Server().getPaoSet("hyWorkorder",
+						P2Server.getP2Server().getSystemUserInfo());
+
+				workorders.setInsertSite(siteid);
+				workorders.setWhere("fworknum='" + where.getString("fworknum") + "'");
+				workorders.reset();
+				if (workorders.isEmpty())
+					return getReturnObject_err("没有该工单").toString();
+				hyworkorder hyworkorder = (hyworkorder) workorders.getPao(0);
+				if (!hyworkorder.getString("fstatus").equals("暂停")) {
+					return getReturnObject_err("非暂停不可启用").toString();
+				}
+				hyworkorder.setValue("fstatus", "进行中", 11L);
+				workorders.save();
+				return getReturnObject_suc().toString();
+			} catch (P2Exception e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+				return getReturnObject_err(e.getMessage()).toString();
+			}
+		}
+
+		return getReturnObject_err("where参数不存在").toString();
+	}
+	/** 工单作废 **/
+	public String cancel() {
+		if (StringUtils.isBlank(hrid))
+			return getReturnObject_err("hrid为空").toString();
 //        if(StringUtils.isBlank(fagentnum))return getReturnObject_err("fagentnum为空").toString();
-        if(StringUtils.isBlank(siteid))return getReturnObject_err("siteid为空").toString();
-        JSONObject where = content.getJSONObject("where");
-        String s[] = {"fworknum"};
-        for (String s1 : s) {
-            if (!where.containsKey(s1) && !StringUtils.isBlank(where.getString(s1)))
-                return getReturnObject_err("缺少" + s1 + "参数").toString();
-        }
-        if (where != null) {
-            try {
-                PaoSetRemote workorder = P2Server.getP2Server().getPaoSet("hyWorkorder", P2Server.getP2Server().getSystemUserInfo());
-                workorder.setInsertSite(siteid);
-                workorder.setWhere("fworknum='"+where.getString("fworknum")+"'");
-                workorder.reset();
-                if(!workorder.isEmpty()){
-                    hyworkorder workorderPao = (hyworkorder) workorder.getPao(0);
-                    workorderPao.start();
-                    workorder.save();
-                    return getReturnObject_suc().toString();
-                }
-                return getReturnObject_err("该工单不存在").toString();
-            } catch (P2Exception e) {
-                return getReturnObject_err(e.getMessage()).toString();
-            }
-        }
-        return getReturnObject_err("缺少where参数").toString();
-    }
-
-
-
-    /**工单是否合格**/
-    public String fisqualified(){
-        if(StringUtils.isBlank(hrid))return getReturnObject_err("hrid为空").toString();
+		if (StringUtils.isBlank(siteid))
+			return getReturnObject_err("siteid为空").toString();
+
+		JSONObject where = content.getJSONObject("where");
+		String s[] = { "fworknum" };
+		for (String s1 : s) {
+			if (!where.containsKey(s1))
+				return getReturnObject_err("缺少" + s1 + "参数").toString();
+		}
+		if (where != null) {
+			PaoSetRemote workorders;
+			try {
+				workorders = P2Server.getP2Server().getPaoSet("hyWorkorder",
+						P2Server.getP2Server().getSystemUserInfo());
+
+				workorders.setInsertSite(siteid);
+				workorders.setWhere("fworknum='" + where.getString("fworknum") + "'");
+				workorders.reset();
+				if (workorders.isEmpty())
+					return getReturnObject_err("没有该工单").toString();
+				hyworkorder hyworkorder = (hyworkorder) workorders.getPao(0);
+				if (hyworkorder.getString("fstatus").equals("已完成")) {
+					return getReturnObject_err("已完成不可作废").toString();
+				}
+				hyworkorder.setValue("fstatus", "作废", 11L);
+				workorders.save();
+				return getReturnObject_suc().toString();
+			} catch (P2Exception e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+				return getReturnObject_err(e.getMessage()).toString();
+			}
+		}
+
+		return getReturnObject_err("where参数不存在").toString();
+	}
+
+	/** 工单是否合格 **/
+	public String fisqualified() {
+		if (StringUtils.isBlank(hrid))
+			return getReturnObject_err("hrid为空").toString();
 //        if(StringUtils.isBlank(fagentnum))return getReturnObject_err("fagentnum为空").toString();
-        if(StringUtils.isBlank(siteid))return getReturnObject_err("siteid为空").toString();
-
-        JSONObject where = content.getJSONObject("where");
-        String s[] = {"fworknum"};
-        for (String s1 : s) {
-            if (!where.containsKey(s1))
-                return getReturnObject_err("缺少" + s1 + "参数").toString();
-        }
-        if(where!=null){
-            SQLFactory factory=new SQLFactory(this,"工单是否合格");
-            factory.addParameter("fworknum",where.getString("fworknum"));
-            DBConnect dbConnect=new DBConnect();
-            Rows rows = dbConnect.runSqlQuery(factory.getSQL());
-            return getReturnObject_suc(rows.get(0),false).toString();
-        }
-
-        return getReturnObject_err("where参数不存在").toString();
-    }
-
-
-    /**工单添加物料**/
-    public String addtitem(){
-        if(StringUtils.isBlank(hrid))return getReturnObject_err("hrid为空").toString();
+		if (StringUtils.isBlank(siteid))
+			return getReturnObject_err("siteid为空").toString();
+
+		JSONObject where = content.getJSONObject("where");
+		String s[] = { "fworknum" };
+		for (String s1 : s) {
+			if (!where.containsKey(s1))
+				return getReturnObject_err("缺少" + s1 + "参数").toString();
+		}
+		if (where != null) {
+			SQLFactory factory = new SQLFactory(this, "工单是否合格");
+			factory.addParameter("fworknum", where.getString("fworknum"));
+			DBConnect dbConnect = new DBConnect();
+			Rows rows = dbConnect.runSqlQuery(factory.getSQL());
+			return getReturnObject_suc(rows.get(0), false).toString();
+		}
+
+		return getReturnObject_err("where参数不存在").toString();
+	}
+
+	/** 工单添加物料 **/
+	public String addtitem() {
+		if (StringUtils.isBlank(hrid))
+			return getReturnObject_err("hrid为空").toString();
 //        if(StringUtils.isBlank(fagentnum))return getReturnObject_err("fagentnum为空").toString();
-        if(StringUtils.isBlank(siteid))return getReturnObject_err("siteid为空").toString();
-        JSONObject where = content.getJSONObject("where");
-        String s[] = {"fworknum","frownum"};
-        for (String s1 : s) {
-            if (!where.containsKey(s1) && !StringUtils.isBlank(where.getString(s1)))
-                return getReturnObject_err("缺少" + s1 + "参数").toString();
-        }
-        if (where != null) {
-            try {
-                PaoSetRemote workorder = P2Server.getP2Server().getPaoSet("hyWorkorder", P2Server.getP2Server().getSystemUserInfo());
-                workorder.setInsertSite(siteid);
-                workorder.setWhere("fworknum='"+where.getString("fworknum")+"'");
-                workorder.reset();
-                if(!workorder.isEmpty()){
-                    hyworkorder workorderPao = (hyworkorder)workorder.getPao(0);
-                    if(!workorderPao.getString("fstatus").equals("进行中"))getReturnObject_err("该工单不在进行中状态").toString();
-                    PaoSetRemote ordernode = workorderPao.getPaoSet("hyordernode");
-                    ordernode.setWhere("frownum="+where.getInt("frownum"));
-                    ordernode.reset();
-                    if(!ordernode.isEmpty()){
-                        hyordernode ordernodePao = (hyordernode) ordernode.getPao(0);
-                        if(ordernodePao.getBoolean("fisaddtitem")){
-                            if(where.containsKey("titems")){
-                                PaoSetRemote workorder_titem = workorderPao.getPaoSet("hyworkorder_titem");
-                                workorder_titem.deleteAll();
-                                JSONArray titems = where.getJSONArray("titems");
-                                for (Object titem : titems) {
-                                    JSONObject titemnode=(JSONObject) titem;
-                                    PaoRemote remote = workorder_titem.addAtEnd();
-                                    remote.setValue("FITEMNO",titemnode.getString("fitemno"),2l);
-                                    remote.setValue("FQTY",titemnode.getInt("fqty"),11l);
-                                    remote.setValue("sourcenode",String.valueOf(ordernodePao.getInt("FROWNUM")),11l);
-                                }
+		if (StringUtils.isBlank(siteid))
+			return getReturnObject_err("siteid为空").toString();
+		JSONObject where = content.getJSONObject("where");
+		String s[] = { "fworknum", "frownum" };
+		for (String s1 : s) {
+			if (!where.containsKey(s1) && !StringUtils.isBlank(where.getString(s1)))
+				return getReturnObject_err("缺少" + s1 + "参数").toString();
+		}
+		if (where != null) {
+			try {
+				PaoSetRemote workorder = P2Server.getP2Server().getPaoSet("hyWorkorder",
+						P2Server.getP2Server().getSystemUserInfo());
+				workorder.setInsertSite(siteid);
+				workorder.setWhere("fworknum='" + where.getString("fworknum") + "'");
+				workorder.reset();
+				if (!workorder.isEmpty()) {
+					hyworkorder workorderPao = (hyworkorder) workorder.getPao(0);
+					if (!workorderPao.getString("fstatus").equals("进行中"))
+						getReturnObject_err("该工单不在进行中状态").toString();
+					PaoSetRemote ordernode = workorderPao.getPaoSet("hyordernode");
+					ordernode.setWhere("frownum=" + where.getInt("frownum"));
+					ordernode.reset();
+					if (!ordernode.isEmpty()) {
+						hyordernode ordernodePao = (hyordernode) ordernode.getPao(0);
+						if (ordernodePao.getBoolean("fisaddtitem")) {
+							if (where.containsKey("titems")) {
+								PaoSetRemote workorder_titem = workorderPao.getPaoSet("hyworkorder_titem");
+								workorder_titem.deleteAll();
+								JSONArray titems = where.getJSONArray("titems");
+								for (Object titem : titems) {
+									JSONObject titemnode = (JSONObject) titem;
+									PaoRemote remote = workorder_titem.addAtEnd();
+									remote.setValue("FITEMNO", titemnode.getString("fitemno"), 2l);
+									remote.setValue("FQTY", titemnode.getInt("fqty"), 11l);
+									remote.setValue("sourcenode", String.valueOf(ordernodePao.getInt("FROWNUM")), 11l);
+								}
 //                                workorder_titem.save();
 //                                ordernode.save();
-                                workorder.save();
-                                return getReturnObject_suc().toString();
-                            }
-                            return getReturnObject_err("titems参数为空").toString();
-                        }
-                        return getReturnObject_err("该节点没有授权添加物料").toString();
-                    }
-                    return getReturnObject_err("该节点不存在").toString();
-                }
-                return getReturnObject_err("该工单不存在").toString();
-            } catch (P2Exception e) {
-                return getReturnObject_err(e.getMessage()).toString();
-            }
-        }
-        return getReturnObject_err("缺少where参数").toString();
-    }
-
-
-
-    /**工单开始前做更新操作**/
-    public String beforesatrt(){
-
-        if(StringUtils.isBlank(hrid))return getReturnObject_err("hrid为空").toString();
+								workorder.save();
+								return getReturnObject_suc().toString();
+							}
+							return getReturnObject_err("titems参数为空").toString();
+						}
+						return getReturnObject_err("该节点没有授权添加物料").toString();
+					}
+					return getReturnObject_err("该节点不存在").toString();
+				}
+				return getReturnObject_err("该工单不存在").toString();
+			} catch (P2Exception e) {
+				return getReturnObject_err(e.getMessage()).toString();
+			}
+		}
+		return getReturnObject_err("缺少where参数").toString();
+	}
+
+	/** 工单开始前做更新操作 **/
+	public String beforesatrt() {
+
+		if (StringUtils.isBlank(hrid))
+			return getReturnObject_err("hrid为空").toString();
 //        if(StringUtils.isBlank(fagentnum))return getReturnObject_err("fagentnum为空").toString();
-        if(StringUtils.isBlank(siteid))return getReturnObject_err("siteid为空").toString();
-        JSONObject where = content.getJSONObject("where");
-        String s[] = {"fworknum","fisscenefname","fistitem","fiserror"};
-        for (String s1 : s) {
-            if (!where.containsKey(s1) && !StringUtils.isBlank(where.getString(s1)))
-                return getReturnObject_err("缺少" + s1 + "参数").toString();
-        }
-        if (where != null) {
-            try {
-                PaoSetRemote workorder = P2Server.getP2Server().getPaoSet("hyWorkorder", P2Server.getP2Server().getSystemUserInfo());
-                workorder.setInsertSite(siteid);
-                workorder.setWhere("fworknum='"+where.getString("fworknum")+"'");
-                workorder.reset();
-                if(!workorder.isEmpty()){
-                    PaoRemote pao = workorder.getPao(0);
-                    pao.setValue("fisscenefname",true,11l);
-                    pao.setValue("fistitem",where.getString("fistitem"),11l);
+		if (StringUtils.isBlank(siteid))
+			return getReturnObject_err("siteid为空").toString();
+		JSONObject where = content.getJSONObject("where");
+		String s[] = { "fworknum", "fisscenefname", "fistitem", "fiserror" };
+		for (String s1 : s) {
+			if (!where.containsKey(s1) && !StringUtils.isBlank(where.getString(s1)))
+				return getReturnObject_err("缺少" + s1 + "参数").toString();
+		}
+		if (where != null) {
+			try {
+				PaoSetRemote workorder = P2Server.getP2Server().getPaoSet("hyWorkorder",
+						P2Server.getP2Server().getSystemUserInfo());
+				workorder.setInsertSite(siteid);
+				workorder.setWhere("fworknum='" + where.getString("fworknum") + "'");
+				workorder.reset();
+				if (!workorder.isEmpty()) {
+					PaoRemote pao = workorder.getPao(0);
+					pao.setValue("fisscenefname", true, 11l);
+					pao.setValue("fistitem", where.getString("fistitem"), 11l);
 //                    pao.setValue("fisperiod",where.getBoolean("fisperiod"),11l);
-                    pao.setValue("fiserror",where.getString("fiserror"),11l);
-                    if(where.containsKey("repairprice")){
-                        pao.setValue("repairprice",where.getDouble("repairprice"),11l);
-                    }
-                    if(where.containsKey("errormsg")){
-                        pao.setValue("errormsg",where.getString("errormsg"),11l);
-                    }
-                    if(where.containsKey("scenefname")){
-                        pao.setValue("scenefname",where.getString("scenefname"),11l);
-                    }
-                    if(where.containsKey("scenephone")){
-                        pao.setValue("scenephone",where.getString("scenephone"),11l);
-                    }
-                    if(where.containsKey("ftext")){
-                        pao.setValue("ftext",where.getString("ftext"),11l);
-                    }
-                    if(where.containsKey("faddress")){
-                        pao.setValue("faddress",where.getString("faddress"),11l);
-                    }
-                    workorder.save();
-                    return getReturnObject_suc().toString();
-                }
-                return getReturnObject_err("该工单不存在").toString();
-            } catch (P2Exception e) {
-                return getReturnObject_err(e.getMessage()).toString();
-            }
-        }
-        return getReturnObject_err("缺少where参数").toString();
-    }
-    /**工单开始前详情**/
-    public String beforesatrtlist(){
-        JSONObject where = content.getJSONObject("where");
-        String s[] = {"fworknum"};
-        for (String s1 : s) {
-            if (!where.containsKey(s1) && !StringUtils.isBlank(where.getString(s1)))
-                return getReturnObject_err("缺少" + s1 + "参数").toString();
-        }
-        DBConnect dbConnect=new DBConnect();
-        SQLFactory factory=new SQLFactory(this,"工单开始前确认");
-        factory.addParameter("fworknum",where.getString("fworknum"));
-        Rows rows = dbConnect.runSqlQuery(factory.getSQL());
-        if(rows.isEmpty())return getReturnObject_err("没有此工单").toString();
-        Row row = rows.get(0);
-        Rows url = dbConnect.runSqlQuery("select tattachmentid,fdocument,fobsurl url,type,UPPER(postfix) postfix,case when postfix in ('JPG','PNG','JEPG','jpg','png','jepg') then 'image'\n" +
-                "when postfix in ('MP4','mp4') then 'video' else 'file' end type2 from tattachment where ownertable='HYWORKORDER' and ownerid=" + row.getInteger("ownerid"));
-        row.put("url",url);
-
-        return getReturnObject_suc(row,false).toString();
-    }
-
-
-    /**查询现场联系人,手机号,地址**/
-    public String findscenefname(){
-        if(StringUtils.isBlank(hrid))return getReturnObject_err("hrid为空").toString();
+					pao.setValue("fiserror", where.getString("fiserror"), 11l);
+					if (where.containsKey("repairprice")) {
+						pao.setValue("repairprice", where.getDouble("repairprice"), 11l);
+					}
+					if (where.containsKey("errormsg")) {
+						pao.setValue("errormsg", where.getString("errormsg"), 11l);
+					}
+					if (where.containsKey("scenefname")) {
+						pao.setValue("scenefname", where.getString("scenefname"), 11l);
+					}
+					if (where.containsKey("scenephone")) {
+						pao.setValue("scenephone", where.getString("scenephone"), 11l);
+					}
+					if (where.containsKey("ftext")) {
+						pao.setValue("ftext", where.getString("ftext"), 11l);
+					}
+					if (where.containsKey("faddress")) {
+						pao.setValue("faddress", where.getString("faddress"), 11l);
+					}
+					workorder.save();
+					return getReturnObject_suc().toString();
+				}
+				return getReturnObject_err("该工单不存在").toString();
+			} catch (P2Exception e) {
+				return getReturnObject_err(e.getMessage()).toString();
+			}
+		}
+		return getReturnObject_err("缺少where参数").toString();
+	}
+
+	/** 工单开始前详情 **/
+	public String beforesatrtlist() {
+		JSONObject where = content.getJSONObject("where");
+		String s[] = { "fworknum" };
+		for (String s1 : s) {
+			if (!where.containsKey(s1) && !StringUtils.isBlank(where.getString(s1)))
+				return getReturnObject_err("缺少" + s1 + "参数").toString();
+		}
+		DBConnect dbConnect = new DBConnect();
+		SQLFactory factory = new SQLFactory(this, "工单开始前确认");
+		factory.addParameter("fworknum", where.getString("fworknum"));
+		Rows rows = dbConnect.runSqlQuery(factory.getSQL());
+		if (rows.isEmpty())
+			return getReturnObject_err("没有此工单").toString();
+		Row row = rows.get(0);
+		Rows url = dbConnect.runSqlQuery(
+				"select tattachmentid,fdocument,fobsurl url,type,UPPER(postfix) postfix,case when postfix in ('JPG','PNG','JEPG','jpg','png','jepg') then 'image'\n"
+						+ "when postfix in ('MP4','mp4') then 'video' else 'file' end type2 from tattachment where ownertable='HYWORKORDER' and ownerid="
+						+ row.getInteger("ownerid"));
+		row.put("url", url);
+
+		return getReturnObject_suc(row, false).toString();
+	}
+
+	/** 查询现场联系人,手机号,地址 **/
+	public String findscenefname() {
+		if (StringUtils.isBlank(hrid))
+			return getReturnObject_err("hrid为空").toString();
 //        if(StringUtils.isBlank(fagentnum))return getReturnObject_err("fagentnum为空").toString();
-        if(StringUtils.isBlank(siteid))return getReturnObject_err("siteid为空").toString();
-
-        JSONObject where = content.getJSONObject("where");
-        String s[] = {"fworknum"};
-        for (String s1 : s) {
-            if (!where.containsKey(s1))
-                return getReturnObject_err("缺少" + s1 + "参数").toString();
-        }
-        if(where!=null){
-            DBConnect dbConnect=new DBConnect();
-            Rows rows = dbConnect.runSqlQuery("select t.scenefname,t.scenephone,t.faddress from hyWorkorder t\n" +
-                    "where t.fworknum='"+where.getString("fworknum")+"'");
-            if(!rows.isEmpty())
-                return getReturnObject_suc(rows.get(0),false).toString();
-            else
-                return getReturnObject_err("没有该工单").toString();
-        }
-        return getReturnObject_err("where参数不存在").toString();
-    }
-
-    /**更新现场联系人,手机号,地址**/
-    public String updatescenefname(){
-        if(StringUtils.isBlank(hrid))return getReturnObject_err("hrid为空").toString();
+		if (StringUtils.isBlank(siteid))
+			return getReturnObject_err("siteid为空").toString();
+
+		JSONObject where = content.getJSONObject("where");
+		String s[] = { "fworknum" };
+		for (String s1 : s) {
+			if (!where.containsKey(s1))
+				return getReturnObject_err("缺少" + s1 + "参数").toString();
+		}
+		if (where != null) {
+			DBConnect dbConnect = new DBConnect();
+			Rows rows = dbConnect.runSqlQuery("select t.scenefname,t.scenephone,t.faddress from hyWorkorder t\n"
+					+ "where t.fworknum='" + where.getString("fworknum") + "'");
+			if (!rows.isEmpty())
+				return getReturnObject_suc(rows.get(0), false).toString();
+			else
+				return getReturnObject_err("没有该工单").toString();
+		}
+		return getReturnObject_err("where参数不存在").toString();
+	}
+
+	/** 更新现场联系人,手机号,地址 **/
+	public String updatescenefname() {
+		if (StringUtils.isBlank(hrid))
+			return getReturnObject_err("hrid为空").toString();
 //        if(StringUtils.isBlank(fagentnum))return getReturnObject_err("fagentnum为空").toString();
-        if(StringUtils.isBlank(siteid))return getReturnObject_err("siteid为空").toString();
-
-        JSONObject where = content.getJSONObject("where");
-        String s[] = {"fworknum"};
-        for (String s1 : s) {
-            if (!where.containsKey(s1))
-                return getReturnObject_err("缺少" + s1 + "参数").toString();
-        }
-        if(where!=null){
-
-            try {
-                PaoSetRemote workorder = P2Server.getP2Server().getPaoSet("hyWorkorder", P2Server.getP2Server().getSystemUserInfo());
-                workorder.setInsertSite(siteid);
-                workorder.setWhere("fworknum='"+where.getString("fworknum")+"'");
-                workorder.reset();
-                if(workorder.isEmpty())return getReturnObject_err("没有该工单").toString();
-                PaoRemote pao = workorder.getPao(0);
-                if(where.containsKey("scenefname")){
-                    pao.setValue("scenefname",where.getString("scenefname"),11l);
-                }
-                if(where.containsKey("scenephone")){
-                    pao.setValue("scenephone",where.getString("scenephone"),11l);
-                }
-                if(where.containsKey("faddress")&&!StringUtils.isBlank(where.getString("faddress"))){
-                    pao.setValue("faddress",where.getString("faddress"),11l);
-                }
-                workorder.save();
-                return getReturnObject_suc().toString();
-            } catch (P2Exception e) {
-                return getReturnObject_err(e.getMessage()).toString();
-            }
-        }
-        return getReturnObject_err("where参数不存在").toString();
-    }
-
-
-
+		if (StringUtils.isBlank(siteid))
+			return getReturnObject_err("siteid为空").toString();
+
+		JSONObject where = content.getJSONObject("where");
+		String s[] = { "fworknum" };
+		for (String s1 : s) {
+			if (!where.containsKey(s1))
+				return getReturnObject_err("缺少" + s1 + "参数").toString();
+		}
+		if (where != null) {
+
+			try {
+				PaoSetRemote workorder = P2Server.getP2Server().getPaoSet("hyWorkorder",
+						P2Server.getP2Server().getSystemUserInfo());
+				workorder.setInsertSite(siteid);
+				workorder.setWhere("fworknum='" + where.getString("fworknum") + "'");
+				workorder.reset();
+				if (workorder.isEmpty())
+					return getReturnObject_err("没有该工单").toString();
+				PaoRemote pao = workorder.getPao(0);
+				if (where.containsKey("scenefname")) {
+					pao.setValue("scenefname", where.getString("scenefname"), 11l);
+				}
+				if (where.containsKey("scenephone")) {
+					pao.setValue("scenephone", where.getString("scenephone"), 11l);
+				}
+				if (where.containsKey("faddress") && !StringUtils.isBlank(where.getString("faddress"))) {
+					pao.setValue("faddress", where.getString("faddress"), 11l);
+				}
+				workorder.save();
+				return getReturnObject_suc().toString();
+			} catch (P2Exception e) {
+				return getReturnObject_err(e.getMessage()).toString();
+			}
+		}
+		return getReturnObject_err("where参数不存在").toString();
+	}
 
 }

+ 32 - 32
src/rest/openapi/restcontroller/wechatapp/orderform/SQL/订单出货未付款账期统计查询.sql

@@ -10,27 +10,27 @@ inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
 where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120) group by t1.fagentnum,fsaler) t1
 inner join (
 select fagentnum,sum(t.famount) famount,fsaler from 
-(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.fwriteoffamount,0) famount from saorder t1
+(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.famount-isnull(fwriteoffamount,0),0) famount from saorder t1
 inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
-) t7 on t1.fagentnum=t7.fagentnum
+left join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+left join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
+) t7 on t1.fagentnum=t7.fagentnum and isnull(t7.famount6,0)>=0
 left join
 (select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount1 from (
-select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
+select  t1.fagentnum,t1.fsaler,sum(isnull(t4.famount,0)) famount from saorder t1
 inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
 inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
 inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
 where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120) group by t1.fagentnum,fsaler) t1
 left join (
 select fagentnum,sum(t.famount) famount,fsaler from 
-(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.fwriteoffamount,0) famount from saorder t1
+(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.famount-isnull(fwriteoffamount,0),0) famount from saorder t1
 inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
-) t2 on t7.fagentnum=t2.fagentnum and t7.fsaler=t2.fsaler
+left join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+left join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
+) t2 on t7.fagentnum=t2.fagentnum and t7.fsaler=t2.fsaler and isnull(t2.famount1,0)>=0
 left join
 (select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount2 from (
 select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
@@ -40,12 +40,12 @@ inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
 where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120) group by t1.fagentnum,fsaler) t1
 inner join (
 select fagentnum,sum(t.famount) famount,fsaler from 
-(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.fwriteoffamount,0) famount from saorder t1
+(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.famount-isnull(fwriteoffamount,0),0) famount from saorder t1
 inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
-) t3 on t7.fagentnum=t3.fagentnum and t7.fsaler=t3.fsaler
+left join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+left join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
+) t3 on t7.fagentnum=t3.fagentnum and t7.fsaler=t3.fsaler and isnull(t3.famount2,0)>=0
 left join
 (select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount3 from (
 select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
@@ -55,12 +55,12 @@ inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
 where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120) group by t1.fagentnum,fsaler) t1
 inner join (
 select fagentnum,sum(t.famount) famount,fsaler from 
-(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.fwriteoffamount,0) famount from saorder t1
+(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.famount-isnull(fwriteoffamount,0),0) famount from saorder t1
 inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
-) t4 on t7.fagentnum=t4.fagentnum and t7.fsaler=t4.fsaler
+left join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+left join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
+) t4 on t7.fagentnum=t4.fagentnum and t7.fsaler=t4.fsaler and isnull(t4.famount3,0)>=0
 left join 
 (select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount4 from (
 select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
@@ -70,12 +70,12 @@ inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
 where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120) group by t1.fagentnum,fsaler) t1
 inner join (
 select fagentnum,sum(t.famount) famount,fsaler from 
-(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.fwriteoffamount,0) famount from saorder t1
+(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.famount-isnull(fwriteoffamount,0),0) famount from saorder t1
 inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
-) t5 on t7.fagentnum=t5.fagentnum and t7.fsaler=t5.fsaler
+left join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+left join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
+) t5 on t7.fagentnum=t5.fagentnum and t7.fsaler=t5.fsaler and isnull(t5.famount4,0)>=0
 left join 
 (select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount5 from (
 select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
@@ -85,11 +85,11 @@ inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
 where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) group by t1.fagentnum,fsaler) t1
 inner join (
 select fagentnum,sum(t.famount) famount,fsaler from 
-(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.fwriteoffamount,0) famount from saorder t1
+(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.famount-isnull(fwriteoffamount,0),0) famount from saorder t1
 inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
-) t6 on t7.fagentnum=t6.fagentnum and t7.fsaler=t6.fsaler
+left join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+left join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
+) t6 on t7.fagentnum=t6.fagentnum and t7.fsaler=t6.fsaler and isnull(t6.famount5,0)>=0
 
-left join pp_hr on pp_hr.hrid=t7.fsaler where $where$
+left join pp_hr on pp_hr.hrid=t7.fsaler where  $where$

+ 32 - 32
src/rest/openapi/restcontroller/wechatapp/orderform/SQL/订单出货未开票账期统计查询.sql

@@ -10,27 +10,27 @@ inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
 where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120) group by t1.fagentnum,fsaler) t1
 inner join (
 select fagentnum,sum(t.famount) famount,fsaler from 
-(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.finvoiceamount,0) famount from saorder t1
+(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.famount-isnull(finvoiceamount,0),0) famount from saorder t1
 inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
-) t7 on t1.fagentnum=t7.fagentnum
+left join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+left join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
+) t7 on t1.fagentnum=t7.fagentnum and isnull(t7.famount6,0)>=0
 left join
 (select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount1 from (
-select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
+select  t1.fagentnum,t1.fsaler,sum(isnull(t4.famount,0)) famount from saorder t1
 inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
 inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
 inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
 where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120) group by t1.fagentnum,fsaler) t1
 left join (
 select fagentnum,sum(t.famount) famount,fsaler from 
-(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.finvoiceamount,0) famount from saorder t1
+(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.famount-isnull(finvoiceamount,0),0) famount from saorder t1
 inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
-) t2 on t7.fagentnum=t2.fagentnum and t7.fsaler=t2.fsaler
+left join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+left join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,0,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
+) t2 on t7.fagentnum=t2.fagentnum and t7.fsaler=t2.fsaler and isnull(t2.famount1,0)>=0
 left join
 (select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount2 from (
 select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
@@ -40,12 +40,12 @@ inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
 where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120) group by t1.fagentnum,fsaler) t1
 inner join (
 select fagentnum,sum(t.famount) famount,fsaler from 
-(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.finvoiceamount,0) famount from saorder t1
+(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.famount-isnull(finvoiceamount,0),0) famount from saorder t1
 inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
-) t3 on t7.fagentnum=t3.fagentnum and t7.fsaler=t3.fsaler
+left join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+left join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-1,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
+) t3 on t7.fagentnum=t3.fagentnum and t7.fsaler=t3.fsaler and isnull(t3.famount2,0)>=0
 left join
 (select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount3 from (
 select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
@@ -55,12 +55,12 @@ inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
 where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120) group by t1.fagentnum,fsaler) t1
 inner join (
 select fagentnum,sum(t.famount) famount,fsaler from 
-(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.finvoiceamount,0) famount from saorder t1
+(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.famount-isnull(finvoiceamount,0),0) famount from saorder t1
 inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
-) t4 on t7.fagentnum=t4.fagentnum and t7.fsaler=t4.fsaler
+left join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+left join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-3,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
+) t4 on t7.fagentnum=t4.fagentnum and t7.fsaler=t4.fsaler and isnull(t4.famount3,0)>=0
 left join 
 (select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount4 from (
 select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
@@ -70,12 +70,12 @@ inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
 where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120) group by t1.fagentnum,fsaler) t1
 inner join (
 select fagentnum,sum(t.famount) famount,fsaler from 
-(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.finvoiceamount,0) famount from saorder t1
+(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.famount-isnull(finvoiceamount,0),0) famount from saorder t1
 inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
-) t5 on t7.fagentnum=t5.fagentnum and t7.fsaler=t5.fsaler
+left join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+left join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)>=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) and  CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-6,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
+) t5 on t7.fagentnum=t5.fagentnum and t7.fsaler=t5.fsaler and isnull(t5.famount4,0)>=0
 left join 
 (select t1.fagentnum,t1.fsaler,(t1.famount-t2.famount) famount5 from (
 select  t1.fagentnum,t1.fsaler,sum(t4.famount) famount from saorder t1
@@ -85,11 +85,11 @@ inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
 where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid  and CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120) group by t1.fagentnum,fsaler) t1
 inner join (
 select fagentnum,sum(t.famount) famount,fsaler from 
-(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.finvoiceamount,0) famount from saorder t1
+(select distinct t2.saorderdetailid,t1.fagentnum,t1.fsaler,isnull(t2.famount-isnull(finvoiceamount,0),0) famount from saorder t1
 inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid
-inner join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
-inner join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
-where t1.fstatus in('审核','关闭') and t3.fstatus='关闭' and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
-) t6 on t7.fagentnum=t6.fagentnum and t7.fsaler=t6.fsaler
+left join sainvoicedetail t4 on t4.fsourceid=t2.saorderdetailid and t4.siteid=t2.siteid 
+left join sainvoice t3 on t4.siteid=t3.siteid and t4.fparentid=t3.sainvoiceid
+where t1.fstatus in('审核','关闭') and t1.siteid=@siteid and CONVERT(VARCHAR(10),t1.checkdate,120)<=CONVERT(VARCHAR(10),DATEADD(mm,-12,getdate()),120)) t group by fagentnum,FSALER) t2 on t1.fagentnum=t2.fagentnum and t1.fsaler=t2.fsaler
+) t6 on t7.fagentnum=t6.fagentnum and t7.fsaler=t6.fsaler and isnull(t6.famount5,0)>=0
 
-left join pp_hr on pp_hr.hrid=t7.fsaler where $where$
+left join pp_hr on pp_hr.hrid=t7.fsaler where  $where$