hyworkorder.java 18 KB

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