package hyworkorder; import baseclass.PaoCust; import baseclass.tools.GetFieldsName; import openapi.base.data.Row; import openapi.base.data.Rows; import openapi.base.data.db.DBConnect; import openapi.restcontroller.housekeeperpublic.tools.HttpURLRest; import p2.p2server.P2Server; import p2.pao.PaoRemote; import p2.pao.PaoSet; import p2.pao.PaoSetRemote; import p2.util.P2AppException; import p2.util.P2Exception; import java.io.IOException; import java.util.Calendar; import java.util.Date; import java.util.Iterator; import java.util.Vector; import java.util.regex.Pattern; import org.apache.commons.lang.StringUtils; import com.sun.org.apache.xpath.internal.operations.And; public class hyworkorder extends PaoCust { /** * 构造函数 * * @param arg0 */ public hyworkorder(PaoSet arg0) { super(arg0); } @Override public void canDelete() throws P2Exception { // TODO Auto-generated method stub super.canDelete(); if (!"作废".equals(getString("fstatus"))) { throw new P2AppException("", "非作废状态不可删除"); } } @Override public void init() throws P2Exception { super.init(); if (!toBeAdded() && (!getString("fstatus").equals("待开始") && !getString("fstatus").equals("待接单"))) { setFieldFlag(new GetFieldsName(getName()).getFields(), READONLY, true); setFieldFlag("fisperiod", READONLY, false); } } @Override public void add() throws P2Exception { super.add(); setValue("fworknum", getBillNum("HYORDER"), 11l); if (getSite().equals("HY")) { setValue("fstatus", "待开始", 11l); } else if (getSite().equals("TZ")) { setValue("fstatus", "待接单", 11l); } setValue("progress", 0, 11l); } @Override public void fieldValidate(Object paoField, String fieldname) throws P2Exception { super.fieldValidate(paoField, fieldname); if (fieldname.equalsIgnoreCase("ProjectLeader")) { // System.out.println("test:"+getString("ProjectLeader")); PaoSetRemote hyWorkorder = P2Server.getP2Server().getPaoSet("hyWorkorder", P2Server.getP2Server().getSystemUserInfo()); hyWorkorder.setInsertSite(getSite()); hyWorkorder.setWhere("servernum='" + getString("servernum") + "' and ProjectLeader='" + getString("ProjectLeader") + "' and FADDRESS='" + getString("FADDRESS") + "' and fstatus !='作废'"); hyWorkorder.reset(); if (!hyWorkorder.isEmpty()) { throw new P2AppException("", "不能指定该人员,该服务人员已经有指派工单"); } } else if (fieldname.equalsIgnoreCase("FTYPE")) { String ftype = getString("ftype"); PaoSetRemote hyWorkorder = P2Server.getP2Server().getPaoSet("hyWorkorder", P2Server.getP2Server().getSystemUserInfo()); hyWorkorder.setInsertSite(getSite()); hyWorkorder.setWhere("servernum='" + getString("servernum") + "' and HYWORKORDERID!=" + getUniqueIDValue() + " and fstatus !='作废'"); hyWorkorder.reset(); int i = 0; PaoRemote paoRemote = null; while ((paoRemote = hyWorkorder.getPao(i)) != null) { if (paoRemote.getString("ftype").equals(ftype)) { throw new P2AppException("", "对应的服务单已存在此类型的工单,无法再次新建"); } i++; } } } @Override 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"); ordernode.deleteAll(); ordernode.save(); } // 新增节点 PaoSetRemote ordernode = getPaoSet("hyordernode"); PaoSetRemote workordertemplate = getPaoSet("hyWorkordertemplate"); if (!workordertemplate.isEmpty()) { System.out.println(222); PaoRemote templatepao = workordertemplate.getPao(0); PaoSetRemote templatenode = templatepao.getPaoSet("hytemplatenode"); if (!templatenode.isEmpty()) { System.out.println(333); int index = 0; for (int i = 0; i < templatenode.count(); i++) { PaoRemote pao = templatenode.getPao(i); System.out.println(pao.getString("oneprocessname")); PaoSetRemote templatenode2 = pao.getPaoSet("hytemplatenode2"); if (templatenode2.isEmpty()) { PaoRemote remote = ordernode.addAtEnd(); remote.setValue("FROWNUM", ++index, 11l); remote.setValue("oneprocessname", pao.getString("oneprocessname"), 11l); remote.setValue("Operating", pao.getString("Operating"), 11l); remote.setValue("fisupload", pao.getString("fisupload"), 11l); // remote.setValue("fisnotes",pao.getString("fisnotes"),11l); remote.setValue("fisaddtitem", pao.getString("fisaddtitem"), 11l); remote.setValue("fistext", pao.getString("fistext"), 11l); // remote.setValue("fiscreatecard",pao.getString("fiscreatecard"),11l); remote.setValue("fisconfirmation", pao.getString("fisconfirmation"), 11l); remote.setValue("fiscontract", pao.getString("fiscontract"), 11l); remote.setValue("FISCOMPLETE", pao.getString("FISCOMPLETE"), 11l); remote.setValue("FISADDTRAINING", pao.getString("FISADDTRAINING"), 11l); remote.setValue("FISADDTRAININGTITEM", pao.getString("FISADDTRAININGTITEM"), 11l); remote.setValue("FISPAID", pao.getString("FISPAID"), 11l); } else { System.out.println(555); PaoRemote remote = ordernode.addAtEnd(); remote.setValue("FROWNUM", ++index, 11l); remote.setValue("oneprocessname", pao.getString("oneprocessname"), 11l); remote.setValue("Operating", pao.getString("Operating"), 11l); remote.setValue("ischilden", true, 11l); remote.setValue("fisupload", pao.getString("fisupload"), 11l); // remote.setValue("fisnotes",pao.getString("fisnotes"),11l); remote.setValue("fisaddtitem", pao.getString("fisaddtitem"), 11l); remote.setValue("fistext", pao.getString("fistext"), 11l); // remote.setValue("fiscreatecard",pao.getString("fiscreatecard"),11l); remote.setValue("fisconfirmation", pao.getString("fisconfirmation"), 11l); remote.setValue("fiscontract", pao.getString("fiscontract"), 11l); remote.setValue("FISCOMPLETE", pao.getString("FISCOMPLETE"), 11l); remote.setValue("FISADDTRAINING", pao.getString("FISADDTRAINING"), 11l); remote.setValue("FISADDTRAININGTITEM", pao.getString("FISADDTRAININGTITEM"), 11l); remote.setValue("FISPAID", pao.getString("FISPAID"), 11l); for (int j = 0; j < templatenode2.count(); j++) { PaoRemote templatenode2_pao = templatenode2.getPao(j); System.out.println(templatenode2_pao.getString("twoprocessname")); PaoRemote remote2 = ordernode.addAtEnd(); remote2.setValue("FROWNUM", ++index, 11l); remote2.setValue("twoprocessname", templatenode2_pao.getString("twoprocessname"), 11l); remote2.setValue("Operating", templatenode2_pao.getString("Operating"), 11l); remote2.setValue("ischilden", false, 11l); remote2.setValue("supid", remote.getUniqueIDValue(), 11l); remote2.setValue("fisupload", templatenode2_pao.getString("fisupload"), 11l); // remote2.setValue("fisnotes",templatenode2_pao.getString("fisnotes"),11l); remote2.setValue("fisaddtitem", templatenode2_pao.getString("fisaddtitem"), 11l); remote2.setValue("fistext", templatenode2_pao.getString("fistext"), 11l); // remote2.setValue("fiscreatecard",templatenode2_pao.getString("fiscreatecard"),11l); remote2.setValue("fisconfirmation", templatenode2_pao.getString("fisconfirmation"), 11l); remote2.setValue("fiscontract", templatenode2_pao.getString("fiscontract"), 11l); remote2.setValue("FISCOMPLETE", templatenode2_pao.getString("FISCOMPLETE"), 11l); remote2.setValue("FISADDTRAINING", templatenode2_pao.getString("FISADDTRAINING"), 11l); remote2.setValue("FISADDTRAININGTITEM", templatenode2_pao.getString("FISADDTRAININGTITEM"), 11l); remote2.setValue("FISPAID", templatenode2_pao.getString("FISPAID"), 11l); } } } } } ordernode.save(); // getThisPaoSet().save(); } else if (fieldname.equalsIgnoreCase("Installerphone")) { PaoSetRemote installer = getPaoSet("Installer"); if (installer.isEmpty()) throw new P2AppException("", "该安装人员不存在"); setValue("Installer", installer.getPao(0).getString("fname"), 11l); } else if (fieldname.equalsIgnoreCase("PROJECTLEADER")) { PaoSetRemote paoSet = getPaoSet("HYWORKORDER_TEAM"); paoSet.setWhere("hyworkernum='" + getString("PROJECTLEADER") + "'"); paoSet.reset(); if (paoSet.isEmpty()) { PaoRemote remote = paoSet.addAtEnd(); remote.setValue("hyworkernum", getString("PROJECTLEADER"), 2l); } try { PaoSetRemote hyworker = P2Server.getP2Server().getPaoSet("hyworker", P2Server.getP2Server().getSystemUserInfo()); PaoSetRemote tagents = P2Server.getP2Server().getPaoSet("tagents", P2Server.getP2Server().getSystemUserInfo()); PaoSetRemote afterserviceorder = P2Server.getP2Server().getPaoSet("AFTERSERVICEORDER", P2Server.getP2Server().getSystemUserInfo()); afterserviceorder.setWhere("SERVICENUM='" + getString("SERVERNUM") + "'"); tagents.setWhere("FAGENTNUM='" + getString("FAGENTNUM") + "'"); hyworker.setWhere("HYWORKERNUM ='" + getString("PROJECTLEADER") + "'"); hyworker.reset(); if (!hyworker.isEmpty()) { String submitby = afterserviceorder.getPao(0).getString("SUBMITBY"); String phone = hyworker.getPao(0).getString("WORKPHONE"); String fagentshortname = tagents.getPao(0).getString("FAGENTSHORTNAME"); HttpURLRest rest = new HttpURLRest("http://smssh1.253.com/msg/v1/send/json"); rest.addHeader("Content-type", "application/json"); org.json.JSONObject jsonObject = new org.json.JSONObject(); jsonObject.put("account", "N3147701"); jsonObject.put("password", "4ClGyab6fv6a87"); jsonObject.put("msg", "【Banninger】工单号:" + getString("FWORKNUM") + "已指派请处理,客户名称:" + fagentshortname + ",提交人:" + submitby + ",备注:" + getString("FNOTES")); jsonObject.put("phone", phone); rest.addRawBody(jsonObject.toString()); String s = rest.post(); PaoSetRemote verCodehistory = P2Server.getP2Server().getPaoSet("VerCodehistory", P2Server.getP2Server().getSystemUserInfo()); PaoRemote remote = verCodehistory.addAtEnd(); remote.setValue("phone", phone); remote.setValue("msg", "【Banninger】工单号:" + getString("FWORKNUM") + "已指派请处理,客户名称:" + fagentshortname + ",提交人:" + submitby + ",备注:" + getString("FNOTES")); remote.setValue("content", s); verCodehistory.save(); } } catch (IOException e) { e.printStackTrace(); } if(getSite().equals("TZ")) { PaoSetRemote workermassage = getPaoSet("$workermassage", "workermassage", ""); PaoRemote remote1 = workermassage.addAtEnd(); remote1.setValue("ftype", "工单消息", 11l); remote1.setValue("title", "服务工单:"+getString("FWORKNUM")+"已指派请处理", 11l); remote1.setValue("content","服务工单:"+getString("FWORKNUM")+"已指派请处理", 11l); remote1.setValue("phone", getString("PROJECTLEADER"), 11l); } } else if (fieldname.equalsIgnoreCase("SCENEPHONE")) { if (!StringUtils.isBlank(getString("SCENEPHONE"))) { if (!Pattern.matches("^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$", getString("SCENEPHONE"))) { throw new P2AppException("", "手机格式有误"); } if (getSite().equals("TZ")) { try { HttpURLRest rest = new HttpURLRest("http://smssh1.253.com/msg/v1/send/json"); rest.addHeader("Content-type", "application/json"); org.json.JSONObject jsonObject = new org.json.JSONObject(); jsonObject.put("account", "N3147701"); jsonObject.put("password", "4ClGyab6fv6a87"); jsonObject.put("msg", "【Banninger】您好,您的服务申请单已处理,请点击链接前往查询https://oms.idcgroup.com.cn:8079/BGJ/tz/tripList.html?id="+getString("SCENEPHONE")); jsonObject.put("phone", getString("SCENEPHONE")); rest.addRawBody(jsonObject.toString()); String s = rest.post(); PaoSetRemote verCodehistory = P2Server.getP2Server().getPaoSet("VerCodehistory", P2Server.getP2Server().getSystemUserInfo()); PaoRemote remote = verCodehistory.addAtEnd(); remote.setValue("phone", getString("SCENEPHONE")); remote.setValue("msg", "【Banninger】您好,您的服务申请单已处理,请点击链接前往查询https://oms.idcgroup.com.cn:8079/BGJ/tz/tripList.html?id="+getString("SCENEPHONE")); remote.setValue("content", s); verCodehistory.save(); } catch (Exception e) { // TODO: handle exception } } } } } /** 工单是否全部确认 **/ public boolean fisAllComplete() throws P2Exception { PaoSetRemote ordernode_confirm = P2Server.getP2Server().getPaoSet("hyordernode", P2Server.getP2Server().getSystemUserInfo()); ordernode_confirm.setInsertSite(getSite()); ordernode_confirm.setWhere("fparentid=" + getInt("fparentid") + " and ischilden=0 and isconfirm=1"); ordernode_confirm.reset(); PaoSetRemote ordernode_count = P2Server.getP2Server().getPaoSet("hyordernode", P2Server.getP2Server().getSystemUserInfo()); ordernode_count.setInsertSite(getSite()); ordernode_count.setWhere("fparentid=" + getInt("fparentid") + " and ischilden=0"); ordernode_count.reset(); return ordernode_confirm.count() == ordernode_count.count(); } /** 完成工单 **/ public void complete(boolean iscreatecard, String hrid) throws Exception { if (!getString("fstatus").equals("进行中")) throw new P2AppException("", "该工单不在进行中状态"); PaoSetRemote ordernodeset = getPaoSet("hyordernode"); ordernodeset.setWhere("ischilden=0"); ordernodeset.reset(); int allcount = ordernodeset.count(); ordernodeset.setWhere("ischilden=0 and isconfirm=1"); ordernodeset.reset(); int count = ordernodeset.count(); // if(allcount!=count&&!getString("ftype").equals("维修")){ //// throw new P2AppException("","还有工序没有确认"); // }else{ DBConnect dbConnect = new DBConnect(); /** 判断预约单是否可以完成 **/ PaoSetRemote serviceform = getPaoSet("AFTERSERVICEORDER"); if (!serviceform.isEmpty()) { PaoRemote serviceformPao = serviceform.getPao(0); PaoSetRemote workorders = serviceformPao.getPaoSet("hyWORKORDER"); workorders.setWhere("hyWORKORDERid!=" + getUniqueIDValue()); workorders.reset(); boolean isallcomplete = true; for (int i = 0; i < workorders.count(); i++) { if (!workorders.getPao(i).getString("fstatus").equals("已完成") && !workorders.getPao(i).getString("fstatus").equals("关闭") && !workorders.getPao(i).getString("fstatus").equals("作废")) { isallcomplete = false; } } if (isallcomplete) { serviceformPao.setValue("fstatus", "已完成", 11l); } } if (getSite().equals("TZ")) { /** 给经销商发送消息 **/ PaoSetRemote paoSet = getPaoSet("$workermassage", "workermassage", ""); PaoRemote remote = paoSet.addAtEnd(); remote.setValue("ftype", "经销商消息", 11l); remote.setValue("title", "工单:" + getString("fworknum") + "已经完成", 11l); remote.setValue("content", "工单:" + getString("fworknum") + "已经完成", 11l); remote.setValue("phone", getString("fagentnum"), 11l); PaoRemote remote1 = paoSet.addAtEnd(); remote1.setValue("ftype", "工单消息", 11l); remote1.setValue("title", "服务工单:" + getString("fworknum") + "已经完成", 11l); remote1.setValue("content", "服务工单:" + getString("fworknum") + "已经完成", 11l); remote1.setValue("phone", getString("PROJECTLEADER"), 11l); } setValue("Acceptancedate", new Date(), 11l); PaoSetRemote paoSet1 = getPaoSet("$hyworker", "hyworker", "hyworkernum='" + hrid + "'"); if (!paoSet1.isEmpty()) { setValue("Acceptby", paoSet1.getPao(0).getString("FNAME"), 11l); } setValue("fstatus", "已完成", 11l); // } } static Date addDate(Date date, int day) throws Exception { Calendar rightNow = Calendar.getInstance(); rightNow.setTime(date); rightNow.add(Calendar.YEAR, day);// 日期减1年 return rightNow.getTime(); // 将毫秒数转换成日期 } /** 开始工单 **/ public void start() throws P2Exception { if (!getString("fstatus").equals("待开始")) throw new P2AppException("", "该工单不在待开始状态"); setValue("startdate", new Date(), 11l); setValue("fstatus", "进行中", 11l); PaoSetRemote afterserviceorder = getPaoSet("AFTERSERVICEORDER"); if (!afterserviceorder.isEmpty()) { afterserviceorder.getPao(0).setValue("fstatus", "进行中", 11l); // afterserviceorder.save(); } if(getSite().equals("TZ")) { PaoSetRemote workermassage = getPaoSet("$workermassage", "workermassage", ""); PaoRemote remote1 = workermassage.addAtEnd(); remote1.setValue("ftype", "工单消息", 11l); remote1.setValue("title", "服务工单:"+getString("FWORKNUM")+"已开始请处理", 11l); remote1.setValue("content","服务工单:"+getString("FWORKNUM")+"已开始请处理", 11l); remote1.setValue("phone", getString("PROJECTLEADER"), 11l); } /** 给经销商发送消息 **/ // PaoSetRemote paoSet = getPaoSet("$workermassage", "workermassage", ""); // PaoRemote remote = paoSet.addAtEnd(); // remote.setValue("ftype","经销商消息",11l); // remote.setValue("title","工单:"+getString("fworknum")+"已经开始",11l); // remote.setValue("content","工单:"+getString("fworknum")+"已经开始",11l); // remote.setValue("phone",getString("fagentnum"),11l); } public Row getCompleteAndTotal() throws P2Exception { DBConnect dbConnect = new DBConnect(); Rows rows = dbConnect.runSqlQuery( "select isnull((select count(1) from hyordernode where fparentid=" + getInt("hyworkorderid") + " and ischilden=0),0)count,\n" + "isnull((select count(1) from hyordernode where fparentid=" + getInt("hyworkorderid") + " and ischilden=0 and isconfirm=1),0)complete"); return rows.get(0); } /** 后端完成工单 **/ public void completeformback(String hrid) throws Exception { if (!getString("fstatus").equals("进行中") && !getString("fstatus").equals("质保卡审批")) throw new P2AppException("", "该工单不在进行中状态"); PaoSetRemote ordernodeset = getPaoSet("ordernode"); ordernodeset.setWhere("ischilden=0"); ordernodeset.reset(); int allcount = ordernodeset.count(); ordernodeset.setWhere("ischilden=0 and isconfirm=1"); ordernodeset.reset(); int count = ordernodeset.count(); if (allcount != count && !getString("ftype").equals("维修")) { throw new P2AppException("", "还有工序没有确认"); } // PaoSetRemote workorder_errormsg = getPaoSet("workorder_errormsg"); // workorder_errormsg.setWhere("fisprocess=0"); // workorder_errormsg.reset(); // if(!workorder_errormsg.isEmpty()){ // throw new P2AppException("","有异常信息未处理"); // } DBConnect dbConnect = new DBConnect(); PaoSetRemote workordertemplate = getPaoSet("WORKORDERTEMPLATE"); /** 判断预约单是否可以完成 **/ PaoSetRemote serviceform = getPaoSet("SERVICEFORM"); if (!serviceform.isEmpty()) { PaoRemote serviceformPao = serviceform.getPao(0); PaoSetRemote workorders = serviceformPao.getPaoSet("WORKORDER"); workorders.setWhere("WORKORDERid!=" + getUniqueIDValue()); workorders.reset(); boolean isallcomplete = true; for (int i = 0; i < workorders.count(); i++) { if (!workorders.getPao(i).getString("fstatus").equals("已完成") && !workorders.getPao(i).getString("fstatus").equals("关闭") && !workorders.getPao(i).getString("fstatus").equals("作废")) { isallcomplete = false; } } if (isallcomplete) { serviceformPao.setValue("fstatus", "已完成", 11l); } } /** 给经销商发送消息 **/ PaoSetRemote paoSet = getPaoSet("$workermassage", "workermassage", ""); PaoRemote remote = paoSet.addAtEnd(); remote.setValue("ftype", "经销商消息", 11l); remote.setValue("title", "工单:" + getString("fworknum") + "已经完成", 11l); remote.setValue("content", "工单:" + getString("fworknum") + "已经完成", 11l); remote.setValue("phone", getString("fagentnum"), 11l); setValue("Acceptancedate", new Date(), 11l); setValue("Acceptby", hrid, 11l); setValue("fstatus", "已完成", 11l); } /** 拒绝 **/ public void refuse() throws P2Exception { if (!getString("fstatus").equals("质保卡审批")) throw new P2AppException("", "非质保卡审批状态无法拒绝"); setValue("fstatus", "进行中", 11l); } /** 添加团队 **/ public void addservertitem(PaoSetRemote paoSet) throws P2Exception { Vector selection = paoSet.getSelection(); Iterator iterator = selection.iterator(); PaoSetRemote HYWORKORDER_TEAM = getPaoSet("HYWORKORDER_TEAM"); while (iterator.hasNext()) { PaoRemote next = iterator.next(); PaoRemote remote = HYWORKORDER_TEAM.addAtEnd(); remote.setValue("hyworkernum", next.getString("hyworkernum"), 2l); } HYWORKORDER_TEAM.save(); } /** 是否作废 **/ public boolean fisvoid() throws P2Exception { return getString("fstatus").equals("作废"); } /** 是否暂停 **/ public boolean fisSuspend() throws P2Exception { return getString("fstatus").equals("暂停"); } }