hyworkorder.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. package hyworkorder;
  2. import baseclass.PaoCust;
  3. import baseclass.tools.GetFieldsName;
  4. import openapi.base.data.Row;
  5. import openapi.base.data.Rows;
  6. import openapi.base.data.db.DBConnect;
  7. import openapi.restcontroller.housekeeperpublic.tools.HttpURLRest;
  8. import p2.p2server.P2Server;
  9. import p2.pao.PaoRemote;
  10. import p2.pao.PaoSet;
  11. import p2.pao.PaoSetRemote;
  12. import p2.util.P2AppException;
  13. import p2.util.P2Exception;
  14. import java.io.IOException;
  15. import java.util.Calendar;
  16. import java.util.Date;
  17. import java.util.Iterator;
  18. import java.util.Vector;
  19. import java.util.regex.Pattern;
  20. import org.apache.commons.lang.StringUtils;
  21. import com.sun.org.apache.xpath.internal.operations.And;
  22. public class hyworkorder extends PaoCust {
  23. /**
  24. * 构造函数
  25. *
  26. * @param arg0
  27. */
  28. public hyworkorder(PaoSet arg0) {
  29. super(arg0);
  30. }
  31. @Override
  32. public void canDelete() throws P2Exception {
  33. // TODO Auto-generated method stub
  34. super.canDelete();
  35. if (!"作废".equals(getString("fstatus"))) {
  36. throw new P2AppException("", "非作废状态不可删除");
  37. }
  38. }
  39. @Override
  40. public void init() throws P2Exception {
  41. super.init();
  42. if (!toBeAdded() && (!getString("fstatus").equals("待开始") && !getString("fstatus").equals("待接单"))) {
  43. setFieldFlag(new GetFieldsName(getName()).getFields(), READONLY, true);
  44. setFieldFlag("fisperiod", READONLY, false);
  45. }
  46. }
  47. @Override
  48. public void add() throws P2Exception {
  49. super.add();
  50. setValue("fworknum", getBillNum("HYORDER"), 11l);
  51. if (getSite().equals("HY")) {
  52. setValue("fstatus", "待开始", 11l);
  53. } else if (getSite().equals("TZ")) {
  54. setValue("fstatus", "待接单", 11l);
  55. }
  56. setValue("progress", 0, 11l);
  57. }
  58. @Override
  59. public void fieldValidate(Object paoField, String fieldname) throws P2Exception {
  60. super.fieldValidate(paoField, fieldname);
  61. if (fieldname.equalsIgnoreCase("ProjectLeader")) {
  62. // System.out.println("test:"+getString("ProjectLeader"));
  63. PaoSetRemote hyWorkorder = P2Server.getP2Server().getPaoSet("hyWorkorder",
  64. P2Server.getP2Server().getSystemUserInfo());
  65. hyWorkorder.setInsertSite(getSite());
  66. hyWorkorder.setWhere("servernum='" + getString("servernum") + "' and ProjectLeader='"
  67. + getString("ProjectLeader") + "' and FADDRESS='" + getString("FADDRESS") + "' and fstatus !='作废'");
  68. hyWorkorder.reset();
  69. if (!hyWorkorder.isEmpty()) {
  70. throw new P2AppException("", "不能指定该人员,该服务人员已经有指派工单");
  71. }
  72. } else if (fieldname.equalsIgnoreCase("FTYPE")) {
  73. String ftype = getString("ftype");
  74. PaoSetRemote hyWorkorder = P2Server.getP2Server().getPaoSet("hyWorkorder",
  75. P2Server.getP2Server().getSystemUserInfo());
  76. hyWorkorder.setInsertSite(getSite());
  77. hyWorkorder.setWhere("servernum='" + getString("servernum") + "' and HYWORKORDERID!=" + getUniqueIDValue()
  78. + " and fstatus !='作废'");
  79. hyWorkorder.reset();
  80. int i = 0;
  81. PaoRemote paoRemote = null;
  82. while ((paoRemote = hyWorkorder.getPao(i)) != null) {
  83. if (paoRemote.getString("ftype").equals(ftype)) {
  84. throw new P2AppException("", "对应的服务单已存在此类型的工单,无法再次新建");
  85. }
  86. i++;
  87. }
  88. }
  89. }
  90. @Override
  91. public void fieldAction(Object paoField, String fieldname) throws P2Exception {
  92. super.fieldAction(paoField, fieldname);
  93. if (fieldname.equalsIgnoreCase("templatenum")) {
  94. System.out.println(111);
  95. // 新增节点之前先删除原先的节点
  96. if (!getPaoSet("hyordernode").isEmpty()) {
  97. PaoSetRemote ordernode = getPaoSet("hyordernode");
  98. ordernode.deleteAll();
  99. ordernode.save();
  100. }
  101. // 新增节点
  102. PaoSetRemote ordernode = getPaoSet("hyordernode");
  103. PaoSetRemote workordertemplate = getPaoSet("hyWorkordertemplate");
  104. if (!workordertemplate.isEmpty()) {
  105. System.out.println(222);
  106. PaoRemote templatepao = workordertemplate.getPao(0);
  107. PaoSetRemote templatenode = templatepao.getPaoSet("hytemplatenode");
  108. if (!templatenode.isEmpty()) {
  109. System.out.println(333);
  110. int index = 0;
  111. for (int i = 0; i < templatenode.count(); i++) {
  112. PaoRemote pao = templatenode.getPao(i);
  113. System.out.println(pao.getString("oneprocessname"));
  114. PaoSetRemote templatenode2 = pao.getPaoSet("hytemplatenode2");
  115. if (templatenode2.isEmpty()) {
  116. PaoRemote remote = ordernode.addAtEnd();
  117. remote.setValue("FROWNUM", ++index, 11l);
  118. remote.setValue("oneprocessname", pao.getString("oneprocessname"), 11l);
  119. remote.setValue("Operating", pao.getString("Operating"), 11l);
  120. remote.setValue("fisupload", pao.getString("fisupload"), 11l);
  121. // remote.setValue("fisnotes",pao.getString("fisnotes"),11l);
  122. remote.setValue("fisaddtitem", pao.getString("fisaddtitem"), 11l);
  123. remote.setValue("fistext", pao.getString("fistext"), 11l);
  124. // remote.setValue("fiscreatecard",pao.getString("fiscreatecard"),11l);
  125. remote.setValue("fisconfirmation", pao.getString("fisconfirmation"), 11l);
  126. remote.setValue("fiscontract", pao.getString("fiscontract"), 11l);
  127. remote.setValue("FISCOMPLETE", pao.getString("FISCOMPLETE"), 11l);
  128. remote.setValue("FISADDTRAINING", pao.getString("FISADDTRAINING"), 11l);
  129. remote.setValue("FISADDTRAININGTITEM", pao.getString("FISADDTRAININGTITEM"), 11l);
  130. remote.setValue("FISPAID", pao.getString("FISPAID"), 11l);
  131. } else {
  132. System.out.println(555);
  133. PaoRemote remote = ordernode.addAtEnd();
  134. remote.setValue("FROWNUM", ++index, 11l);
  135. remote.setValue("oneprocessname", pao.getString("oneprocessname"), 11l);
  136. remote.setValue("Operating", pao.getString("Operating"), 11l);
  137. remote.setValue("ischilden", true, 11l);
  138. remote.setValue("fisupload", pao.getString("fisupload"), 11l);
  139. // remote.setValue("fisnotes",pao.getString("fisnotes"),11l);
  140. remote.setValue("fisaddtitem", pao.getString("fisaddtitem"), 11l);
  141. remote.setValue("fistext", pao.getString("fistext"), 11l);
  142. // remote.setValue("fiscreatecard",pao.getString("fiscreatecard"),11l);
  143. remote.setValue("fisconfirmation", pao.getString("fisconfirmation"), 11l);
  144. remote.setValue("fiscontract", pao.getString("fiscontract"), 11l);
  145. remote.setValue("FISCOMPLETE", pao.getString("FISCOMPLETE"), 11l);
  146. remote.setValue("FISADDTRAINING", pao.getString("FISADDTRAINING"), 11l);
  147. remote.setValue("FISADDTRAININGTITEM", pao.getString("FISADDTRAININGTITEM"), 11l);
  148. remote.setValue("FISPAID", pao.getString("FISPAID"), 11l);
  149. for (int j = 0; j < templatenode2.count(); j++) {
  150. PaoRemote templatenode2_pao = templatenode2.getPao(j);
  151. System.out.println(templatenode2_pao.getString("twoprocessname"));
  152. PaoRemote remote2 = ordernode.addAtEnd();
  153. remote2.setValue("FROWNUM", ++index, 11l);
  154. remote2.setValue("twoprocessname", templatenode2_pao.getString("twoprocessname"), 11l);
  155. remote2.setValue("Operating", templatenode2_pao.getString("Operating"), 11l);
  156. remote2.setValue("ischilden", false, 11l);
  157. remote2.setValue("supid", remote.getUniqueIDValue(), 11l);
  158. remote2.setValue("fisupload", templatenode2_pao.getString("fisupload"), 11l);
  159. // remote2.setValue("fisnotes",templatenode2_pao.getString("fisnotes"),11l);
  160. remote2.setValue("fisaddtitem", templatenode2_pao.getString("fisaddtitem"), 11l);
  161. remote2.setValue("fistext", templatenode2_pao.getString("fistext"), 11l);
  162. // remote2.setValue("fiscreatecard",templatenode2_pao.getString("fiscreatecard"),11l);
  163. remote2.setValue("fisconfirmation", templatenode2_pao.getString("fisconfirmation"),
  164. 11l);
  165. remote2.setValue("fiscontract", templatenode2_pao.getString("fiscontract"), 11l);
  166. remote2.setValue("FISCOMPLETE", templatenode2_pao.getString("FISCOMPLETE"), 11l);
  167. remote2.setValue("FISADDTRAINING", templatenode2_pao.getString("FISADDTRAINING"), 11l);
  168. remote2.setValue("FISADDTRAININGTITEM",
  169. templatenode2_pao.getString("FISADDTRAININGTITEM"), 11l);
  170. remote2.setValue("FISPAID", templatenode2_pao.getString("FISPAID"), 11l);
  171. }
  172. }
  173. }
  174. }
  175. }
  176. ordernode.save();
  177. // getThisPaoSet().save();
  178. } else if (fieldname.equalsIgnoreCase("Installerphone")) {
  179. PaoSetRemote installer = getPaoSet("Installer");
  180. if (installer.isEmpty())
  181. throw new P2AppException("", "该安装人员不存在");
  182. setValue("Installer", installer.getPao(0).getString("fname"), 11l);
  183. } else if (fieldname.equalsIgnoreCase("PROJECTLEADER")) {
  184. PaoSetRemote paoSet = getPaoSet("HYWORKORDER_TEAM");
  185. paoSet.setWhere("hyworkernum='" + getString("PROJECTLEADER") + "'");
  186. paoSet.reset();
  187. if (paoSet.isEmpty()) {
  188. PaoRemote remote = paoSet.addAtEnd();
  189. remote.setValue("hyworkernum", getString("PROJECTLEADER"), 2l);
  190. }
  191. try {
  192. PaoSetRemote hyworker = P2Server.getP2Server().getPaoSet("hyworker",
  193. P2Server.getP2Server().getSystemUserInfo());
  194. PaoSetRemote tagents = P2Server.getP2Server().getPaoSet("tagents",
  195. P2Server.getP2Server().getSystemUserInfo());
  196. PaoSetRemote afterserviceorder = P2Server.getP2Server().getPaoSet("AFTERSERVICEORDER",
  197. P2Server.getP2Server().getSystemUserInfo());
  198. afterserviceorder.setWhere("SERVICENUM='" + getString("SERVERNUM") + "'");
  199. tagents.setWhere("FAGENTNUM='" + getString("FAGENTNUM") + "'");
  200. hyworker.setWhere("HYWORKERNUM ='" + getString("PROJECTLEADER") + "'");
  201. hyworker.reset();
  202. if (!hyworker.isEmpty()) {
  203. String submitby = afterserviceorder.getPao(0).getString("SUBMITBY");
  204. String phone = hyworker.getPao(0).getString("WORKPHONE");
  205. String fagentshortname = tagents.getPao(0).getString("FAGENTSHORTNAME");
  206. HttpURLRest rest = new HttpURLRest("http://smssh1.253.com/msg/v1/send/json");
  207. rest.addHeader("Content-type", "application/json");
  208. org.json.JSONObject jsonObject = new org.json.JSONObject();
  209. jsonObject.put("account", "N3147701");
  210. jsonObject.put("password", "4ClGyab6fv6a87");
  211. jsonObject.put("msg", "【Banninger】工单号:" + getString("FWORKNUM") + "已指派请处理,客户名称:" + fagentshortname
  212. + ",提交人:" + submitby + ",备注:" + getString("FNOTES"));
  213. jsonObject.put("phone", phone);
  214. rest.addRawBody(jsonObject.toString());
  215. String s = rest.post();
  216. PaoSetRemote verCodehistory = P2Server.getP2Server().getPaoSet("VerCodehistory",
  217. P2Server.getP2Server().getSystemUserInfo());
  218. PaoRemote remote = verCodehistory.addAtEnd();
  219. remote.setValue("phone", phone);
  220. remote.setValue("msg", "【Banninger】工单号:" + getString("FWORKNUM") + "已指派请处理,客户名称:" + fagentshortname
  221. + ",提交人:" + submitby + ",备注:" + getString("FNOTES"));
  222. remote.setValue("content", s);
  223. verCodehistory.save();
  224. }
  225. } catch (IOException e) {
  226. e.printStackTrace();
  227. }
  228. if(getSite().equals("TZ")) {
  229. PaoSetRemote workermassage = getPaoSet("$workermassage", "workermassage", "");
  230. PaoRemote remote1 = workermassage.addAtEnd();
  231. remote1.setValue("ftype", "工单消息", 11l);
  232. remote1.setValue("title", "服务工单:"+getString("FWORKNUM")+"已指派请处理", 11l);
  233. remote1.setValue("content","服务工单:"+getString("FWORKNUM")+"已指派请处理", 11l);
  234. remote1.setValue("phone", getString("PROJECTLEADER"), 11l);
  235. }
  236. } else if (fieldname.equalsIgnoreCase("SCENEPHONE")) {
  237. if (!StringUtils.isBlank(getString("SCENEPHONE"))) {
  238. if (!Pattern.matches("^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$", getString("SCENEPHONE"))) {
  239. throw new P2AppException("", "手机格式有误");
  240. }
  241. if (getSite().equals("TZ")) {
  242. try {
  243. HttpURLRest rest = new HttpURLRest("http://smssh1.253.com/msg/v1/send/json");
  244. rest.addHeader("Content-type", "application/json");
  245. org.json.JSONObject jsonObject = new org.json.JSONObject();
  246. jsonObject.put("account", "N3147701");
  247. jsonObject.put("password", "4ClGyab6fv6a87");
  248. jsonObject.put("msg", "【Banninger】您好,您的服务申请单已处理,请点击链接前往查询https://oms.idcgroup.com.cn:8079/BGJ/tz/tripList.html?id="+getString("SCENEPHONE"));
  249. jsonObject.put("phone", getString("SCENEPHONE"));
  250. rest.addRawBody(jsonObject.toString());
  251. String s = rest.post();
  252. PaoSetRemote verCodehistory = P2Server.getP2Server().getPaoSet("VerCodehistory",
  253. P2Server.getP2Server().getSystemUserInfo());
  254. PaoRemote remote = verCodehistory.addAtEnd();
  255. remote.setValue("phone", getString("SCENEPHONE"));
  256. remote.setValue("msg", "【Banninger】您好,您的服务申请单已处理,请点击链接前往查询https://oms.idcgroup.com.cn:8079/BGJ/tz/tripList.html?id="+getString("SCENEPHONE"));
  257. remote.setValue("content", s);
  258. verCodehistory.save();
  259. } catch (Exception e) {
  260. // TODO: handle exception
  261. }
  262. }
  263. }
  264. }
  265. }
  266. /** 工单是否全部确认 **/
  267. public boolean fisAllComplete() throws P2Exception {
  268. PaoSetRemote ordernode_confirm = P2Server.getP2Server().getPaoSet("hyordernode",
  269. P2Server.getP2Server().getSystemUserInfo());
  270. ordernode_confirm.setInsertSite(getSite());
  271. ordernode_confirm.setWhere("fparentid=" + getInt("fparentid") + " and ischilden=0 and isconfirm=1");
  272. ordernode_confirm.reset();
  273. PaoSetRemote ordernode_count = P2Server.getP2Server().getPaoSet("hyordernode",
  274. P2Server.getP2Server().getSystemUserInfo());
  275. ordernode_count.setInsertSite(getSite());
  276. ordernode_count.setWhere("fparentid=" + getInt("fparentid") + " and ischilden=0");
  277. ordernode_count.reset();
  278. return ordernode_confirm.count() == ordernode_count.count();
  279. }
  280. /** 完成工单 **/
  281. public void complete(boolean iscreatecard, String hrid) throws Exception {
  282. if (!getString("fstatus").equals("进行中"))
  283. throw new P2AppException("", "该工单不在进行中状态");
  284. PaoSetRemote ordernodeset = getPaoSet("hyordernode");
  285. ordernodeset.setWhere("ischilden=0");
  286. ordernodeset.reset();
  287. int allcount = ordernodeset.count();
  288. ordernodeset.setWhere("ischilden=0 and isconfirm=1");
  289. ordernodeset.reset();
  290. int count = ordernodeset.count();
  291. // if(allcount!=count&&!getString("ftype").equals("维修")){
  292. //// throw new P2AppException("","还有工序没有确认");
  293. // }else{
  294. DBConnect dbConnect = new DBConnect();
  295. /** 判断预约单是否可以完成 **/
  296. PaoSetRemote serviceform = getPaoSet("AFTERSERVICEORDER");
  297. if (!serviceform.isEmpty()) {
  298. PaoRemote serviceformPao = serviceform.getPao(0);
  299. PaoSetRemote workorders = serviceformPao.getPaoSet("hyWORKORDER");
  300. workorders.setWhere("hyWORKORDERid!=" + getUniqueIDValue());
  301. workorders.reset();
  302. boolean isallcomplete = true;
  303. for (int i = 0; i < workorders.count(); i++) {
  304. if (!workorders.getPao(i).getString("fstatus").equals("已完成")
  305. && !workorders.getPao(i).getString("fstatus").equals("关闭")
  306. && !workorders.getPao(i).getString("fstatus").equals("作废")) {
  307. isallcomplete = false;
  308. }
  309. }
  310. if (isallcomplete) {
  311. serviceformPao.setValue("fstatus", "已完成", 11l);
  312. }
  313. }
  314. if (getSite().equals("TZ")) {
  315. /** 给经销商发送消息 **/
  316. PaoSetRemote paoSet = getPaoSet("$workermassage", "workermassage", "");
  317. PaoRemote remote = paoSet.addAtEnd();
  318. remote.setValue("ftype", "经销商消息", 11l);
  319. remote.setValue("title", "工单:" + getString("fworknum") + "已经完成", 11l);
  320. remote.setValue("content", "工单:" + getString("fworknum") + "已经完成", 11l);
  321. remote.setValue("phone", getString("fagentnum"), 11l);
  322. PaoRemote remote1 = paoSet.addAtEnd();
  323. remote1.setValue("ftype", "工单消息", 11l);
  324. remote1.setValue("title", "服务工单:" + getString("fworknum") + "已经完成", 11l);
  325. remote1.setValue("content", "服务工单:" + getString("fworknum") + "已经完成", 11l);
  326. remote1.setValue("phone", getString("PROJECTLEADER"), 11l);
  327. }
  328. setValue("Acceptancedate", new Date(), 11l);
  329. PaoSetRemote paoSet1 = getPaoSet("$hyworker", "hyworker", "hyworkernum='" + hrid + "'");
  330. if (!paoSet1.isEmpty()) {
  331. setValue("Acceptby", paoSet1.getPao(0).getString("FNAME"), 11l);
  332. }
  333. setValue("fstatus", "已完成", 11l);
  334. // }
  335. }
  336. static Date addDate(Date date, int day) throws Exception {
  337. Calendar rightNow = Calendar.getInstance();
  338. rightNow.setTime(date);
  339. rightNow.add(Calendar.YEAR, day);// 日期减1年
  340. return rightNow.getTime(); // 将毫秒数转换成日期
  341. }
  342. /** 开始工单 **/
  343. public void start() throws P2Exception {
  344. if (!getString("fstatus").equals("待开始"))
  345. throw new P2AppException("", "该工单不在待开始状态");
  346. setValue("startdate", new Date(), 11l);
  347. setValue("fstatus", "进行中", 11l);
  348. PaoSetRemote afterserviceorder = getPaoSet("AFTERSERVICEORDER");
  349. if (!afterserviceorder.isEmpty()) {
  350. afterserviceorder.getPao(0).setValue("fstatus", "进行中", 11l);
  351. // afterserviceorder.save();
  352. }
  353. if(getSite().equals("TZ")) {
  354. PaoSetRemote workermassage = getPaoSet("$workermassage", "workermassage", "");
  355. PaoRemote remote1 = workermassage.addAtEnd();
  356. remote1.setValue("ftype", "工单消息", 11l);
  357. remote1.setValue("title", "服务工单:"+getString("FWORKNUM")+"已开始请处理", 11l);
  358. remote1.setValue("content","服务工单:"+getString("FWORKNUM")+"已开始请处理", 11l);
  359. remote1.setValue("phone", getString("PROJECTLEADER"), 11l);
  360. }
  361. /** 给经销商发送消息 **/
  362. // PaoSetRemote paoSet = getPaoSet("$workermassage", "workermassage", "");
  363. // PaoRemote remote = paoSet.addAtEnd();
  364. // remote.setValue("ftype","经销商消息",11l);
  365. // remote.setValue("title","工单:"+getString("fworknum")+"已经开始",11l);
  366. // remote.setValue("content","工单:"+getString("fworknum")+"已经开始",11l);
  367. // remote.setValue("phone",getString("fagentnum"),11l);
  368. }
  369. public Row getCompleteAndTotal() throws P2Exception {
  370. DBConnect dbConnect = new DBConnect();
  371. Rows rows = dbConnect.runSqlQuery(
  372. "select isnull((select count(1) from hyordernode where fparentid=" + getInt("hyworkorderid")
  373. + " and ischilden=0),0)count,\n" + "isnull((select count(1) from hyordernode where fparentid="
  374. + getInt("hyworkorderid") + " and ischilden=0 and isconfirm=1),0)complete");
  375. return rows.get(0);
  376. }
  377. /** 后端完成工单 **/
  378. public void completeformback(String hrid) throws Exception {
  379. if (!getString("fstatus").equals("进行中") && !getString("fstatus").equals("质保卡审批"))
  380. throw new P2AppException("", "该工单不在进行中状态");
  381. PaoSetRemote ordernodeset = getPaoSet("ordernode");
  382. ordernodeset.setWhere("ischilden=0");
  383. ordernodeset.reset();
  384. int allcount = ordernodeset.count();
  385. ordernodeset.setWhere("ischilden=0 and isconfirm=1");
  386. ordernodeset.reset();
  387. int count = ordernodeset.count();
  388. if (allcount != count && !getString("ftype").equals("维修")) {
  389. throw new P2AppException("", "还有工序没有确认");
  390. }
  391. // PaoSetRemote workorder_errormsg = getPaoSet("workorder_errormsg");
  392. // workorder_errormsg.setWhere("fisprocess=0");
  393. // workorder_errormsg.reset();
  394. // if(!workorder_errormsg.isEmpty()){
  395. // throw new P2AppException("","有异常信息未处理");
  396. // }
  397. DBConnect dbConnect = new DBConnect();
  398. PaoSetRemote workordertemplate = getPaoSet("WORKORDERTEMPLATE");
  399. /** 判断预约单是否可以完成 **/
  400. PaoSetRemote serviceform = getPaoSet("SERVICEFORM");
  401. if (!serviceform.isEmpty()) {
  402. PaoRemote serviceformPao = serviceform.getPao(0);
  403. PaoSetRemote workorders = serviceformPao.getPaoSet("WORKORDER");
  404. workorders.setWhere("WORKORDERid!=" + getUniqueIDValue());
  405. workorders.reset();
  406. boolean isallcomplete = true;
  407. for (int i = 0; i < workorders.count(); i++) {
  408. if (!workorders.getPao(i).getString("fstatus").equals("已完成")
  409. && !workorders.getPao(i).getString("fstatus").equals("关闭")
  410. && !workorders.getPao(i).getString("fstatus").equals("作废")) {
  411. isallcomplete = false;
  412. }
  413. }
  414. if (isallcomplete) {
  415. serviceformPao.setValue("fstatus", "已完成", 11l);
  416. }
  417. }
  418. /** 给经销商发送消息 **/
  419. PaoSetRemote paoSet = getPaoSet("$workermassage", "workermassage", "");
  420. PaoRemote remote = paoSet.addAtEnd();
  421. remote.setValue("ftype", "经销商消息", 11l);
  422. remote.setValue("title", "工单:" + getString("fworknum") + "已经完成", 11l);
  423. remote.setValue("content", "工单:" + getString("fworknum") + "已经完成", 11l);
  424. remote.setValue("phone", getString("fagentnum"), 11l);
  425. setValue("Acceptancedate", new Date(), 11l);
  426. setValue("Acceptby", hrid, 11l);
  427. setValue("fstatus", "已完成", 11l);
  428. }
  429. /** 拒绝 **/
  430. public void refuse() throws P2Exception {
  431. if (!getString("fstatus").equals("质保卡审批"))
  432. throw new P2AppException("", "非质保卡审批状态无法拒绝");
  433. setValue("fstatus", "进行中", 11l);
  434. }
  435. /** 添加团队 **/
  436. public void addservertitem(PaoSetRemote paoSet) throws P2Exception {
  437. Vector<PaoRemote> selection = paoSet.getSelection();
  438. Iterator<PaoRemote> iterator = selection.iterator();
  439. PaoSetRemote HYWORKORDER_TEAM = getPaoSet("HYWORKORDER_TEAM");
  440. while (iterator.hasNext()) {
  441. PaoRemote next = iterator.next();
  442. PaoRemote remote = HYWORKORDER_TEAM.addAtEnd();
  443. remote.setValue("hyworkernum", next.getString("hyworkernum"), 2l);
  444. }
  445. HYWORKORDER_TEAM.save();
  446. }
  447. /** 是否作废 **/
  448. public boolean fisvoid() throws P2Exception {
  449. return getString("fstatus").equals("作废");
  450. }
  451. /** 是否暂停 **/
  452. public boolean fisSuspend() throws P2Exception {
  453. return getString("fstatus").equals("暂停");
  454. }
  455. }