workorder.java 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. package workorder;
  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.RowsMap;
  7. import openapi.base.data.db.DBConnect;
  8. import ordernode.ordernode;
  9. import org.apache.commons.lang.StringUtils;
  10. import p2.p2server.P2Server;
  11. import p2.pao.PaoRemote;
  12. import p2.pao.PaoSet;
  13. import p2.pao.PaoSetRemote;
  14. import p2.util.P2AppException;
  15. import p2.util.P2Exception;
  16. import java.util.Calendar;
  17. import java.util.Date;
  18. import java.util.Iterator;
  19. import java.util.Vector;
  20. public class workorder extends PaoCust {
  21. /**
  22. * 构造函数
  23. *
  24. * @param arg0
  25. */
  26. public workorder(PaoSet arg0) {
  27. super(arg0);
  28. }
  29. @Override
  30. public void init() throws P2Exception {
  31. super.init();
  32. if (!toBeAdded()) {
  33. setFieldFlag(new GetFieldsName(getName()).getFields(), READONLY, true);
  34. }
  35. }
  36. @Override
  37. public void add() throws P2Exception {
  38. super.add();
  39. setValue("fworknum", getBillNum("WORKORDER"), 11l);
  40. setValue("fstatus", "待开始", 11l);
  41. setValue("progress", 0, 11l);
  42. }
  43. @Override
  44. public void fieldAction(Object paoField, String fieldname) throws P2Exception {
  45. super.fieldAction(paoField, fieldname);
  46. if (fieldname.equalsIgnoreCase("templatenum")) {
  47. // 新增节点之前先删除原先的节点
  48. if (!getPaoSet("ORDERNODE").isEmpty()) {
  49. PaoSetRemote ordernode = getPaoSet("ORDERNODE");
  50. ordernode.deleteAll();
  51. ordernode.save();
  52. }
  53. // 新增节点
  54. PaoSetRemote ordernode = getPaoSet("ORDERNODE");
  55. PaoSetRemote workordertemplate = getPaoSet("WORKORDERTEMPLATE");
  56. if (!workordertemplate.isEmpty()) {
  57. PaoRemote templatepao = workordertemplate.getPao(0);
  58. PaoSetRemote templatenode = templatepao.getPaoSet("TEMPLATENODE");
  59. templatenode.setOrderBy("FROWNUM asc");
  60. templatenode.reset();
  61. if (!templatenode.isEmpty()) {
  62. int index = 0;
  63. for (int i = 0; i < templatenode.count(); i++) {
  64. PaoRemote pao = templatenode.getPao(i);
  65. PaoSetRemote templatenode2 = pao.getPaoSet("TEMPLATENODE2");
  66. if (templatenode2.isEmpty()) {
  67. PaoRemote remote = ordernode.addAtEnd();
  68. remote.setValue("FROWNUM", ++index, 11l);
  69. remote.setValue("oneprocessname", pao.getString("oneprocessname"), 11l);
  70. remote.setValue("Operating", pao.getString("Operating"), 11l);
  71. remote.setValue("fisupload", pao.getString("fisupload"), 11l);
  72. // remote.setValue("fisnotes",pao.getString("fisnotes"),11l);
  73. remote.setValue("fisaddtitem", pao.getString("fisaddtitem"), 11l);
  74. remote.setValue("fiscomplete", pao.getString("fiscomplete"), 11l);
  75. // remote.setValue("fiscreatecard",pao.getString("fiscreatecard"),11l);
  76. remote.setValue("fisqualified", pao.getString("fisqualified"), 11l);
  77. remote.setValue("FISSIGNATURE", pao.getString("FISSIGNATURE"), 11l);
  78. remote.setValue("FISREQUIREDNODE", pao.getString("FISREQUIREDNODE"), 11l);
  79. } else {
  80. PaoRemote remote = ordernode.addAtEnd();
  81. remote.setValue("FROWNUM", ++index, 11l);
  82. remote.setValue("oneprocessname", pao.getString("oneprocessname"), 11l);
  83. remote.setValue("Operating", pao.getString("Operating"), 11l);
  84. remote.setValue("ischilden", true, 11l);
  85. remote.setValue("fisupload", pao.getString("fisupload"), 11l);
  86. // remote.setValue("fisnotes",pao.getString("fisnotes"),11l);
  87. remote.setValue("fisaddtitem", pao.getString("fisaddtitem"), 11l);
  88. remote.setValue("fiscomplete", pao.getString("fiscomplete"), 11l);
  89. // remote.setValue("fiscreatecard",pao.getString("fiscreatecard"),11l);
  90. remote.setValue("fisqualified", pao.getString("fisqualified"), 11l);
  91. remote.setValue("FISSIGNATURE", pao.getString("FISSIGNATURE"), 11l);
  92. remote.setValue("FISREQUIREDNODE", pao.getString("FISREQUIREDNODE"), 11l);
  93. for (int j = 0; j < templatenode2.count(); j++) {
  94. PaoRemote templatenode2_pao = templatenode2.getPao(j);
  95. PaoRemote remote2 = ordernode.addAtEnd();
  96. remote2.setValue("FROWNUM", ++index, 11l);
  97. remote2.setValue("twoprocessname", templatenode2_pao.getString("twoprocessname"), 11l);
  98. remote2.setValue("Operating", templatenode2_pao.getString("Operating"), 11l);
  99. remote2.setValue("ischilden", false, 11l);
  100. remote2.setValue("supid", remote.getUniqueIDValue(), 11l);
  101. remote2.setValue("fisupload", templatenode2_pao.getString("fisupload"), 11l);
  102. // remote2.setValue("fisnotes",templatenode2_pao.getString("fisnotes"),11l);
  103. remote2.setValue("fisaddtitem", templatenode2_pao.getString("fisaddtitem"), 11l);
  104. remote2.setValue("fiscomplete", templatenode2_pao.getString("fiscomplete"), 11l);
  105. // remote2.setValue("fiscreatecard",templatenode2_pao.getString("fiscreatecard"),11l);
  106. remote2.setValue("fisqualified", templatenode2_pao.getString("fisqualified"), 11l);
  107. remote2.setValue("FISSIGNATURE", templatenode2_pao.getString("FISSIGNATURE"), 11l);
  108. remote2.setValue("FISREQUIREDNODE", templatenode2_pao.getString("FISREQUIREDNODE"), 11l);
  109. }
  110. }
  111. }
  112. }
  113. }
  114. // ordernode.save();
  115. // getThisPaoSet().save();
  116. } else if (fieldname.equalsIgnoreCase("Installerphone")) {
  117. PaoSetRemote installer = getPaoSet("Installer");
  118. if (installer.isEmpty())
  119. throw new P2AppException("", "该安装人员不存在");
  120. setValue("Installer", installer.getPao(0).getString("fname"), 11l);
  121. }
  122. }
  123. public void addworktitem(PaoSetRemote paoSet) throws P2Exception {
  124. Vector<PaoRemote> selection = paoSet.getSelection();
  125. Iterator<PaoRemote> iterator = selection.iterator();
  126. PaoSetRemote workorder_titem = getPaoSet("WORKORDER_TITEM");
  127. System.out.println("addworktitem");
  128. while (iterator.hasNext()) {
  129. PaoRemote next = iterator.next();
  130. PaoRemote remote = workorder_titem.addAtEnd();
  131. remote.setValue("FITEMNO", next.getString("FITEMNO"), 11l);
  132. remote.setValue("FITEMNAME", next.getString("FITEMNAME"), 11l);
  133. remote.setValue("FMODEL", next.getString("FMODEL"), 11l);
  134. remote.setValue("FSPEC", next.getString("FSPEC"), 11l);
  135. }
  136. workorder_titem.save();
  137. }
  138. /** 工单是否全部确认 **/
  139. public boolean fisAllComplete() throws P2Exception {
  140. PaoSetRemote ordernode_confirm = P2Server.getP2Server().getPaoSet("ordernode",
  141. P2Server.getP2Server().getSystemUserInfo());
  142. ordernode_confirm.setInsertSite(getSite());
  143. ordernode_confirm.setWhere("fparentid=" + getInt("fparentid") + " and ischilden=0 and isconfirm=1");
  144. ordernode_confirm.reset();
  145. PaoSetRemote ordernode_count = P2Server.getP2Server().getPaoSet("ordernode",
  146. P2Server.getP2Server().getSystemUserInfo());
  147. ordernode_count.setInsertSite(getSite());
  148. ordernode_count.setWhere("fparentid=" + getInt("fparentid") + " and ischilden=0");
  149. ordernode_count.reset();
  150. return ordernode_confirm.count() == ordernode_count.count();
  151. }
  152. /** 关闭 **/
  153. public void back() throws P2Exception {
  154. if (!getString("fstatus").equals("进行中"))
  155. throw new P2AppException("", "该工单不在进行中状态");
  156. setValue("fstatus", "关闭", 11l);
  157. }
  158. /** 完成工单 **/
  159. public void complete(boolean iscreatecard, String hrid) throws Exception {
  160. if (!getString("fstatus").equals("进行中"))
  161. throw new P2AppException("", "该工单不在进行中状态");
  162. PaoSetRemote ordernodeset = getPaoSet("ordernode");
  163. // ordernodeset.setWhere("ischilden=0");
  164. // ordernodeset.reset();
  165. // int allcount = ordernodeset.count();
  166. // ordernodeset.setWhere("ischilden=0 and isconfirm=1");
  167. // ordernodeset.reset();
  168. // int count = ordernodeset.count();
  169. // if (allcount != count && !getString("ftype").equals("维修")) {
  170. // throw new P2AppException("", "还有工序没有确认");
  171. // } else {
  172. ordernodeset.setWhere("fisrequirednode =1 and isconfirm=0");
  173. ordernodeset.reset();
  174. if(ordernodeset.count()>0) {
  175. throw new P2AppException("", "还有必填的服务工序没有确认");
  176. }
  177. DBConnect dbConnect = new DBConnect();
  178. /** 质保卡生成 **/
  179. PaoSetRemote workordertemplate = getPaoSet("WORKORDERTEMPLATE");
  180. if (!workordertemplate.isEmpty()) {
  181. PaoRemote pao = workordertemplate.getPao(0);
  182. // if(pao.getBoolean("fisfillAC")){
  183. // PaoSetRemote AINTEGRALRULE = getPaoSet("AINTEGRALRULE");
  184. // PaoSetRemote CINTEGRALRULE = getPaoSet("CINTEGRALRULE");
  185. // if(AINTEGRALRULE.isEmpty()||CINTEGRALRULE.isEmpty())throw new P2AppException("","请填写项目信息后再提交!");
  186. // }
  187. if (pao.getBoolean("fiscreatecard")) {
  188. /** 判断工序中是否含有不合格的工序,如有,则不生成质保卡 **/
  189. // Rows rows = dbConnect.runSqlQuery("select 1 result from ordernode where
  190. // fparentid=" + getUniqueIDValue() + " and fisqualified=1 and ischilden=0 and
  191. // qualified=0");
  192. if (iscreatecard) {
  193. PaoSetRemote qualitycard = P2Server.getP2Server().getPaoSet("Qualitycard",
  194. P2Server.getP2Server().getSystemUserInfo());
  195. qualitycard.setInsertSite(getSite());
  196. PaoRemote remote = qualitycard.addAtEnd();
  197. remote.setValue("fworknum", getString("fworknum"), 11l);
  198. remote.setValue("customername", getString("customername"), 11l);
  199. remote.setValue("customerphone", getString("customephone"), 11l);
  200. Rows rows_dateset = dbConnect.runSqlQuery(
  201. "select value from PS_DATABIND_LIST where databindid='QUALITYCARDDATE' and siteid='"
  202. + getSite() + "'");
  203. if (!rows_dateset.isEmpty()) {
  204. remote.setValue("Expirationtime",
  205. addDate(new Date(), rows_dateset.get(0).getInteger("value")), 11l);
  206. } else {
  207. remote.setValue("Expirationtime", addDate(new Date(), 1), 11l);
  208. }
  209. remote.setValue("FPROVINCE", getString("FPROVINCE"), 11l);
  210. remote.setValue("FCITY", getString("FCITY"), 11l);
  211. remote.setValue("FCOUNTY", getString("FCOUNTY"), 11l);
  212. remote.setValue("FADDRESS", getString("FADDRESS"), 11l);
  213. PaoSetRemote customer = getPaoSet("CUSTOMER");
  214. if (!customer.isEmpty()) {
  215. remote.setValue("contacts", customer.getPao(0).getString("contacts"), 11l);
  216. } else {
  217. remote.setValue("contacts", getString("customername"), 11l);
  218. }
  219. remote.setValue("Installer", getString("Installer"), 11l);
  220. remote.setValue("Installerphone", getString("Installerphone"), 11l);
  221. PaoSetRemote paoSet = getPaoSet("$worker", "worker", "workphone='" + hrid + "'");
  222. if (!paoSet.isEmpty()) {
  223. remote.setValue("CREATEBY", paoSet.getPao(0).getString("FNAME"), 11l);
  224. }
  225. qualitycard.save();
  226. }
  227. }
  228. }
  229. /** 判断预约单是否可以完成 **/
  230. PaoSetRemote serviceform = getPaoSet("SERVICEFORM");
  231. if (!serviceform.isEmpty()) {
  232. PaoRemote serviceformPao = serviceform.getPao(0);
  233. PaoSetRemote workorders = serviceformPao.getPaoSet("WORKORDER");
  234. workorders.setWhere("WORKORDERid!=" + getUniqueIDValue());
  235. workorders.reset();
  236. boolean isallcomplete = true;
  237. for (int i = 0; i < workorders.count(); i++) {
  238. if (!workorders.getPao(i).getString("fstatus").equals("已完成")
  239. && !workorders.getPao(i).getString("fstatus").equals("关闭")
  240. && !workorders.getPao(i).getString("fstatus").equals("作废")) {
  241. isallcomplete = false;
  242. }
  243. }
  244. if (isallcomplete) {
  245. if (getString("ftype") != null && getString("ftype").length() != 0
  246. && getString("ftype").equals("施工")) {
  247. serviceformPao.setValue("fstatus", "待验收", 11l);
  248. } else {
  249. serviceformPao.setValue("fstatus", "已完成", 11l);
  250. }
  251. }
  252. }
  253. /** 积分规则计算 **/
  254. ACcalculation(workordertemplate);
  255. /** 给经销商发送消息 **/
  256. PaoSetRemote paoSet = getPaoSet("$workermassage", "workermassage", "");
  257. PaoRemote remote = paoSet.addAtEnd();
  258. remote.setValue("ftype", "经销商消息", 11l);
  259. remote.setValue("title", "工单:" + getString("fworknum") + "已经完成", 11l);
  260. remote.setValue("content", "工单:" + getString("fworknum") + "已经完成", 11l);
  261. remote.setValue("phone", getString("fagentnum"), 11l);
  262. setValue("Acceptancedate", new Date(), 11l);
  263. PaoSetRemote paoSet1 = getPaoSet("$worker", "worker", "workphone='" + hrid + "'");
  264. if (!paoSet1.isEmpty()) {
  265. setValue("Acceptby", paoSet1.getPao(0).getString("FNAME"), 11l);
  266. }
  267. setValue("fstatus", "已完成", 11l);
  268. }
  269. /** 创建积分变动 **/
  270. private void createintegralchange(String ftype, int result_cunt, String phone, String name, String type, int fvalue,
  271. int kitchen, int toilet, int balcony, int result) throws P2Exception {
  272. PaoSetRemote personnelset = P2Server.getP2Server().getPaoSet("personnel",
  273. P2Server.getP2Server().getSystemUserInfo());
  274. personnelset.setInsertSite(getSite());
  275. personnelset.setWhere("customerphone='" + phone + "'");
  276. personnelset.reset();
  277. PaoRemote pao = null;
  278. if (!personnelset.isEmpty()) {
  279. pao = personnelset.getPao(0);
  280. PaoSetRemote integralchange = pao.getPaoSet("integralchange");
  281. PaoRemote remote = integralchange.addAtEnd();
  282. remote.setValue("ftype", ftype, 11l);
  283. remote.setValue("changevalue", result_cunt, 11l);
  284. remote.setValue("valuetotal",
  285. result_cunt + (ftype.equals("A积分") ? pao.getInt("Aintegral") : pao.getInt("Cintegral")), 11l);
  286. String reason = "工单奖励,工单来源:" + getString("fworknum") + ",规则:" + type + ",";
  287. if (type.equals("管材") || type.equals("丝扣嵌件")) {
  288. reason += "数量:" + fvalue + ",积分:" + result;
  289. } else {
  290. reason += "厨房数:" + kitchen + ",卫生间数:" + balcony + ",阳台数:" + toilet + ",积分:" + result;
  291. }
  292. remote.setValue("Reason", reason, 11l);
  293. remote.setValue("customerphone", phone, 11l);
  294. personnelset.save();
  295. }
  296. }
  297. static Date addDate(Date date, int day) throws Exception {
  298. Calendar rightNow = Calendar.getInstance();
  299. rightNow.setTime(date);
  300. rightNow.add(Calendar.YEAR, day);// 日期减1年
  301. return rightNow.getTime(); // 将毫秒数转换成日期
  302. }
  303. /** 获取经销商积分规则 **/
  304. public PaoRemote getTagentIntegralruleType(String ftype) throws P2Exception {
  305. PaoSetRemote tagents = P2Server.getP2Server().getPaoSet("TAGENTS", P2Server.getP2Server().getSystemUserInfo());
  306. tagents.setWhere("fagentnum='" + getString("fagentnum") + "'");
  307. tagents.reset();
  308. if (!tagents.isEmpty()) {
  309. PaoRemote tagentsPao = tagents.getPao(0);
  310. PaoSetRemote integralrule = tagentsPao.getPaoSet("Integralrule");
  311. integralrule.setWhere("ftype='" + ftype + "'");
  312. integralrule.reset();
  313. if (!integralrule.isEmpty()) {
  314. PaoRemote pao = integralrule.getPao(0);
  315. return pao;
  316. }
  317. }
  318. return null;
  319. }
  320. /** 开始工单 **/
  321. public void start() throws P2Exception {
  322. if (!getString("fstatus").equals("待开始"))
  323. throw new P2AppException("", "该工单不在待开始状态");
  324. setValue("startdate", new Date(), 11l);
  325. setValue("fstatus", "进行中", 11l);
  326. /** 给经销商发送消息 **/
  327. PaoSetRemote paoSet = getPaoSet("$workermassage", "workermassage", "");
  328. PaoRemote remote = paoSet.addAtEnd();
  329. remote.setValue("ftype", "经销商消息", 11l);
  330. remote.setValue("title", "工单:" + getString("fworknum") + "已经开始", 11l);
  331. remote.setValue("content", "工单:" + getString("fworknum") + "已经开始", 11l);
  332. remote.setValue("phone", getString("fagentnum"), 11l);
  333. }
  334. /** 创建积分人员 **/
  335. public void createpersonal(String fname, String phone) throws P2Exception {
  336. PaoSetRemote personnel2 = P2Server.getP2Server().getPaoSet("personnel",
  337. P2Server.getP2Server().getSystemUserInfo());
  338. personnel2.setInsertSite(getSite());
  339. personnel2.setWhere("customerphone='" + phone + "'");
  340. personnel2.reset();
  341. if (personnel2.isEmpty()) {
  342. PaoRemote remote = personnel2.addAtEnd();
  343. remote.setValue("customername", fname, 11l);
  344. remote.setValue("customerphone", phone, 11l);
  345. remote.setValue("FAGENTNUM", getString("fagentnum"), 11l);
  346. personnel2.save();
  347. }
  348. }
  349. public Row getCompleteAndTotal() throws P2Exception {
  350. DBConnect dbConnect = new DBConnect();
  351. Rows rows = dbConnect
  352. .runSqlQuery("select isnull((select count(1) from ordernode where fparentid=" + getInt("workorderid")
  353. + " and ischilden=0),0)count,\n" + "isnull((select count(1) from ordernode where fparentid="
  354. + getInt("workorderid") + " and ischilden=0 and isconfirm=1),0)complete");
  355. return rows.get(0);
  356. }
  357. /** 作废 **/
  358. public void toVoid(String returnreason) throws P2Exception {
  359. if (!getString("fstatus").equals("进行中") && !getString("fstatus").equals("待开始")
  360. && !getString("fstatus").equals("暂停"))
  361. throw new P2AppException("", "该工单不在进行中或待开始状态");
  362. setValue("fstatus", "作废", 11l);
  363. setValue("returnreason", returnreason, 11l);
  364. PaoSetRemote serviceform = getPaoSet("SERVICEFORM");
  365. if (!serviceform.isEmpty()) {
  366. serviceform.getPao(0).setValue("fstatus", "待处理", 11l);
  367. }
  368. /** 发送消息 **/
  369. PaoSetRemote workorder_team = getPaoSet("WORKORDER_TEAM");
  370. if (!workorder_team.isEmpty()) {
  371. PaoSetRemote workermassage = P2Server.getP2Server().getPaoSet("workermassage",
  372. P2Server.getP2Server().getSystemUserInfo());
  373. for (int i = 0; i < workorder_team.count(); i++) {
  374. String workephone = workorder_team.getPao(i).getString("workephone");
  375. workermassage.setInsertSite(getSite());
  376. PaoRemote remote = workermassage.addAtEnd();
  377. remote.setValue("ftype", "系统消息", 11l);
  378. remote.setValue("title", "您有一个" + getString("ftype") + "单:" + getString("fworknum") + "已作废", 11l);
  379. remote.setValue("content", "您有一个" + getString("ftype") + "单:" + getString("fworknum") + "已作废", 11l);
  380. remote.setValue("phone", workephone, 11l);
  381. remote.setValue("fworknum", getString("fworknum"), 11l);
  382. }
  383. workermassage.save();
  384. }
  385. }
  386. /** 启用 **/
  387. public void toUsed() throws P2Exception {
  388. if (!getString("fstatus").equals("暂停"))
  389. throw new P2AppException("", "该工单不在暂停中状态");
  390. setValue("fstatus", "进行中", 11l);
  391. PaoSetRemote workorder_team = getPaoSet("WORKORDER_TEAM");
  392. if (!workorder_team.isEmpty()) {
  393. PaoSetRemote workermassage = P2Server.getP2Server().getPaoSet("workermassage",
  394. P2Server.getP2Server().getSystemUserInfo());
  395. for (int i = 0; i < workorder_team.count(); i++) {
  396. String workephone = workorder_team.getPao(i).getString("workephone");
  397. workermassage.setInsertSite(getSite());
  398. PaoRemote remote = workermassage.addAtEnd();
  399. remote.setValue("ftype", "跳转消息", 11l);
  400. remote.setValue("title", "您有一个" + getString("ftype") + "单:" + getString("fworknum") + "已启用", 11l);
  401. remote.setValue("content", "您有一个" + getString("ftype") + "单:" + getString("fworknum") + "已启用", 11l);
  402. remote.setValue("phone", workephone, 11l);
  403. remote.setValue("fworknum", getString("fworknum"), 11l);
  404. }
  405. workermassage.save();
  406. }
  407. }
  408. /** 暂停 **/
  409. public void toSuspend() throws P2Exception {
  410. if (!getString("fstatus").equals("进行中"))
  411. throw new P2AppException("", "该工单不在进行中状态");
  412. setValue("fstatus", "暂停", 11l);
  413. /** 推送消息 **/
  414. PaoSetRemote workorder_team = getPaoSet("WORKORDER_TEAM");
  415. if (!workorder_team.isEmpty()) {
  416. PaoSetRemote workermassage = P2Server.getP2Server().getPaoSet("workermassage",
  417. P2Server.getP2Server().getSystemUserInfo());
  418. for (int i = 0; i < workorder_team.count(); i++) {
  419. String workephone = workorder_team.getPao(i).getString("workephone");
  420. workermassage.setInsertSite(getSite());
  421. PaoRemote remote = workermassage.addAtEnd();
  422. remote.setValue("ftype", "系统消息", 11l);
  423. remote.setValue("title", "您有一个" + getString("ftype") + "单:" + getString("fworknum") + "已暂停", 11l);
  424. remote.setValue("content", "您有一个" + getString("ftype") + "单:" + getString("fworknum") + "已暂停", 11l);
  425. remote.setValue("phone", workephone, 11l);
  426. remote.setValue("fworknum", getString("fworknum"), 11l);
  427. }
  428. workermassage.save();
  429. }
  430. }
  431. /** 是否暂停 **/
  432. public boolean fisSuspend() throws P2Exception {
  433. return getString("fstatus").equals("暂停");
  434. }
  435. /** 是否作废 **/
  436. public boolean fisvoid() throws P2Exception {
  437. return getString("fstatus").equals("作废");
  438. }
  439. /** 生成质保卡 **/
  440. public void createQualitycard(String hrid) throws Exception {
  441. if (!getString("fstatus").equals("已完成") && !getString("fstatus").equals("进行中")
  442. && !getString("fstatus").equals("质保卡审批"))
  443. throw new P2AppException("", "非进行或完成状态不可生成质保卡");
  444. if (getString("fstatus").equals("进行中") || getString("fstatus").equals("质保卡审批")) {
  445. completeformback(hrid);
  446. }
  447. PaoSetRemote qualitycard_set = getPaoSet("QUALITYCARD");
  448. if (!qualitycard_set.isEmpty())
  449. throw new P2AppException("", "该质保卡已经生成");
  450. DBConnect dbConnect = new DBConnect();
  451. PaoSetRemote qualitycard = P2Server.getP2Server().getPaoSet("Qualitycard",
  452. P2Server.getP2Server().getSystemUserInfo());
  453. qualitycard.setInsertSite(getSite());
  454. PaoRemote remote = qualitycard.addAtEnd();
  455. remote.setValue("fworknum", getString("fworknum"), 11l);
  456. remote.setValue("customername", getString("customername"), 11l);
  457. remote.setValue("customerphone", getString("customephone"), 11l);
  458. Rows rows_dateset = dbConnect.runSqlQuery(
  459. "select value from PS_DATABIND_LIST where databindid='QUALITYCARDDATE' and siteid='" + getSite() + "'");
  460. if (!rows_dateset.isEmpty()) {
  461. remote.setValue("Expirationtime", addDate(new Date(), rows_dateset.get(0).getInteger("value")), 11l);
  462. } else {
  463. remote.setValue("Expirationtime", addDate(new Date(), 1), 11l);
  464. }
  465. remote.setValue("FPROVINCE", getString("FPROVINCE"), 11l);
  466. remote.setValue("FCITY", getString("FCITY"), 11l);
  467. remote.setValue("FCOUNTY", getString("FCOUNTY"), 11l);
  468. remote.setValue("FADDRESS", getString("FADDRESS"), 11l);
  469. PaoSetRemote customer = getPaoSet("CUSTOMER");
  470. if (!customer.isEmpty()) {
  471. remote.setValue("contacts", customer.getPao(0).getString("contacts"), 11l);
  472. } else {
  473. remote.setValue("contacts", getString("customername"), 11l);
  474. }
  475. remote.setValue("Installer", getString("Installer"), 11l);
  476. remote.setValue("Installerphone", getString("Installerphone"), 11l);
  477. remote.setValue("CREATEBY", hrid, 11l);
  478. qualitycard.save();
  479. }
  480. /** 后端完成工单 **/
  481. public void completeformback(String hrid) throws Exception {
  482. if (!getString("fstatus").equals("进行中") && !getString("fstatus").equals("质保卡审批"))
  483. throw new P2AppException("", "该工单不在进行中状态");
  484. PaoSetRemote ordernodeset = getPaoSet("ordernode");
  485. // ordernodeset.setWhere("ischilden=0");
  486. // ordernodeset.reset();
  487. // int allcount = ordernodeset.count();
  488. // ordernodeset.setWhere("ischilden=0 and isconfirm=1");
  489. // ordernodeset.reset();
  490. // int count = ordernodeset.count();
  491. // if (allcount != count && !getString("ftype").equals("维修")) {
  492. // throw new P2AppException("", "还有工序没有确认");
  493. // }
  494. // PaoSetRemote workorder_errormsg = getPaoSet("workorder_errormsg");
  495. // workorder_errormsg.setWhere("fisprocess=0");
  496. // workorder_errormsg.reset();
  497. // if(!workorder_errormsg.isEmpty()){
  498. // throw new P2AppException("","有异常信息未处理");
  499. // }
  500. ordernodeset.setWhere("fisrequirednode =1 and isconfirm=0");
  501. ordernodeset.reset();
  502. if(ordernodeset.count()>0) {
  503. throw new P2AppException("", "还有必填的服务工序没有确认");
  504. }
  505. DBConnect dbConnect = new DBConnect();
  506. PaoSetRemote workordertemplate = getPaoSet("WORKORDERTEMPLATE");
  507. /** 判断预约单是否可以完成 **/
  508. PaoSetRemote serviceform = getPaoSet("SERVICEFORM");
  509. if (!serviceform.isEmpty()) {
  510. PaoRemote serviceformPao = serviceform.getPao(0);
  511. PaoSetRemote workorders = serviceformPao.getPaoSet("WORKORDER");
  512. workorders.setWhere("WORKORDERid!=" + getUniqueIDValue());
  513. workorders.reset();
  514. boolean isallcomplete = true;
  515. for (int i = 0; i < workorders.count(); i++) {
  516. if (!workorders.getPao(i).getString("fstatus").equals("已完成")
  517. && !workorders.getPao(i).getString("fstatus").equals("关闭")
  518. && !workorders.getPao(i).getString("fstatus").equals("作废")) {
  519. isallcomplete = false;
  520. }
  521. }
  522. if (isallcomplete) {
  523. if (getString("ftype") != null && getString("ftype").length() != 0 && getString("ftype").equals("施工")) {
  524. serviceformPao.setValue("fstatus", "待验收", 11l);
  525. } else {
  526. serviceformPao.setValue("fstatus", "已完成", 11l);
  527. }
  528. }
  529. }
  530. /** 积分规则计算 **/
  531. ACcalculation(workordertemplate);
  532. /** 给经销商发送消息 **/
  533. PaoSetRemote paoSet = getPaoSet("$workermassage", "workermassage", "");
  534. PaoRemote remote = paoSet.addAtEnd();
  535. remote.setValue("ftype", "经销商消息", 11l);
  536. remote.setValue("title", "工单:" + getString("fworknum") + "已经完成", 11l);
  537. remote.setValue("content", "工单:" + getString("fworknum") + "已经完成", 11l);
  538. remote.setValue("phone", getString("fagentnum"), 11l);
  539. setValue("Acceptancedate", new Date(), 11l);
  540. setValue("Acceptby", hrid, 11l);
  541. setValue("fstatus", "已完成", 11l);
  542. }
  543. /** AC积分计算 **/
  544. public void ACcalculation(PaoSetRemote workordertemplate) throws P2Exception {
  545. /** 积分规则计算 **/
  546. if (!workordertemplate.isEmpty() && workordertemplate.getPao(0).getBoolean("fisfillAC")) {
  547. PaoSetRemote aintegralrule = getPaoSet("AINTEGRALRULE");
  548. PaoSetRemote cintegralrule = getPaoSet("CINTEGRALRULE");
  549. /** A积分设置 **/
  550. if (!aintegralrule.isEmpty()) {
  551. PaoRemote pao = aintegralrule.getPao(0);
  552. if (!pao.isNull("phone")) {
  553. String calculationrules = pao.getString("CALCULATIONRULES");
  554. PaoRemote AtagentIntegralruleType = getTagentIntegralruleType("A积分");
  555. if (calculationrules.equals("管材")) {
  556. if (AtagentIntegralruleType != null && !AtagentIntegralruleType.isNull("fvalue")
  557. && AtagentIntegralruleType.getInt("fvalue") != 0) {
  558. int result_cunt = AtagentIntegralruleType == null ? 0
  559. : AtagentIntegralruleType.getInt("fvalue") * pao.getInt("fvalue");
  560. if (result_cunt != 0 && !pao.isNull("phone") && !pao.isNull("fname")) {
  561. createpersonal(pao.getString("fname"), pao.getString("phone"));
  562. createintegralchange("A积分", result_cunt, pao.getString("phone"), pao.getString("fname"),
  563. calculationrules, pao.getInt("fvalue"), 0, 0, 0, result_cunt);
  564. }
  565. }
  566. }
  567. if (calculationrules.equals("丝扣嵌件")) {
  568. if (AtagentIntegralruleType != null && !AtagentIntegralruleType.isNull("fvalue2")
  569. && AtagentIntegralruleType.getInt("fvalue2") != 0) {
  570. int result_cunt = AtagentIntegralruleType == null ? 0
  571. : AtagentIntegralruleType.getInt("fvalue2") * pao.getInt("fvalue");
  572. if (result_cunt != 0 && !pao.isNull("phone") && !pao.isNull("fname")) {
  573. createpersonal(pao.getString("fname"), pao.getString("phone"));
  574. createintegralchange("A积分", result_cunt, pao.getString("phone"), pao.getString("fname"),
  575. calculationrules, pao.getInt("fvalue"), 0, 0, 0, result_cunt);
  576. }
  577. }
  578. }
  579. if (calculationrules.equals("户型")) {
  580. if (AtagentIntegralruleType != null) {
  581. Integer kitchen = pao.getInt("kitchen");
  582. Integer toilet = pao.getInt("toilet");
  583. Integer balcony = pao.getInt("balcony");
  584. int result_cunt = 0;
  585. result_cunt = kitchen * AtagentIntegralruleType.getInt("kitchen")
  586. + toilet * AtagentIntegralruleType.getInt("toilet")
  587. + balcony * AtagentIntegralruleType.getInt("balcony");
  588. if (result_cunt != 0 && !pao.isNull("phone") && !pao.isNull("fname")) {
  589. createpersonal(pao.getString("fname"), pao.getString("phone"));
  590. createintegralchange("A积分", result_cunt, pao.getString("phone"), pao.getString("fname"),
  591. calculationrules, 0, kitchen, toilet, balcony, result_cunt);
  592. }
  593. }
  594. }
  595. }
  596. }
  597. /** C积分设置 **/
  598. if (!cintegralrule.isEmpty()) {
  599. PaoRemote pao = cintegralrule.getPao(0);
  600. String calculationrules = pao.getString("CALCULATIONRULES");
  601. PaoRemote CtagentIntegralruleType = getTagentIntegralruleType("C积分");
  602. if (!pao.isNull("phone")) {
  603. if (calculationrules.equals("管材")) {
  604. if (CtagentIntegralruleType != null && !CtagentIntegralruleType.isNull("fvalue")
  605. && CtagentIntegralruleType.getInt("fvalue") != 0) {
  606. int result_cunt = CtagentIntegralruleType == null ? 0
  607. : CtagentIntegralruleType.getInt("fvalue") * pao.getInt("fvalue");
  608. if (result_cunt != 0 && !pao.isNull("phone") && !pao.isNull("fname")) {
  609. createpersonal(pao.getString("fname"), pao.getString("phone"));
  610. createintegralchange("C积分", result_cunt, pao.getString("phone"), pao.getString("fname"),
  611. calculationrules, pao.getInt("fvalue"), 0, 0, 0, result_cunt);
  612. }
  613. }
  614. }
  615. if (calculationrules.equals("丝扣嵌件")) {
  616. if (CtagentIntegralruleType != null && !CtagentIntegralruleType.isNull("fvalue2")
  617. && CtagentIntegralruleType.getInt("fvalue2") != 0) {
  618. int result_cunt = CtagentIntegralruleType == null ? 0
  619. : CtagentIntegralruleType.getInt("fvalue2") * pao.getInt("fvalue");
  620. if (result_cunt != 0 && !pao.isNull("phone") && !pao.isNull("fname")) {
  621. createpersonal(pao.getString("fname"), pao.getString("phone"));
  622. createintegralchange("C积分", result_cunt, pao.getString("phone"), pao.getString("fname"),
  623. calculationrules, pao.getInt("fvalue"), 0, 0, 0, result_cunt);
  624. }
  625. }
  626. }
  627. if (calculationrules.equals("户型")) {
  628. if (CtagentIntegralruleType != null) {
  629. Integer kitchen = pao.getInt("kitchen");
  630. Integer toilet = pao.getInt("toilet");
  631. Integer balcony = pao.getInt("balcony");
  632. int result_cunt = 0;
  633. if (CtagentIntegralruleType != null) {
  634. result_cunt = kitchen * CtagentIntegralruleType.getInt("kitchen")
  635. + toilet * CtagentIntegralruleType.getInt("toilet")
  636. + balcony * CtagentIntegralruleType.getInt("balcony");
  637. if (result_cunt != 0 && !pao.isNull("phone") && !pao.isNull("fname")) {
  638. createpersonal(pao.getString("fname"), pao.getString("phone"));
  639. createintegralchange("C积分", result_cunt, pao.getString("phone"),
  640. pao.getString("fname"), calculationrules, 0, kitchen, toilet, balcony,
  641. result_cunt);
  642. }
  643. }
  644. }
  645. }
  646. }
  647. }
  648. }
  649. }
  650. /** 拒绝 **/
  651. public void refuse() throws P2Exception {
  652. if (!getString("fstatus").equals("质保卡审批"))
  653. throw new P2AppException("", "非质保卡审批状态无法拒绝");
  654. setValue("fstatus", "进行中", 11l);
  655. }
  656. }