Java tutorial
package com.org.dms.action.service.claimmng; import java.text.SimpleDateFormat; import java.util.HashMap; import java.util.Map; import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory; import org.apache.log4j.Logger; import org.dom4j.Document; import org.dom4j.DocumentFactory; import org.dom4j.Element; import com.org.dms.common.DicConstant; import com.org.dms.dao.service.claimmng.SeBuWorkDispatchDao; import com.org.dms.vo.service.SeBuWorkDispatchUerRlVO; import com.org.dms.vo.service.SeBuWorkDispatchVO; import com.org.dms.vo.service.SeBuWorkOrderVO; import com.org.framework.Globals; import com.org.framework.common.BaseResultSet; import com.org.framework.common.PageManager; import com.org.framework.common.QuerySet; import com.org.framework.common.User; import com.org.framework.log.LogManager; import com.org.framework.params.ParaManager; import com.org.framework.params.UserPara.UserParaConfigureVO; import com.org.framework.util.Pub; import com.org.framework.util.RequestUtil; import com.org.mvc.context.ActionContext; import com.org.mvc.context.RequestWrapper; /** * ? * <p>Company: szq</p> * @author baixiaoliang * @version 1.0 2014-7-14 */ public class WorkDispatchMngAction { private Logger logger = com.org.framework.log.log.getLogger("WorkDispatchMngAction"); private ActionContext atx = ActionContext.getContext(); private SeBuWorkDispatchDao dao = SeBuWorkDispatchDao.getInstance(atx); /** * @auther baixiaoliang * ? * @return void */ public void searchWorkOrder() throws Exception { RequestWrapper request = atx.getRequest(); User user = (User) atx.getSession().get(Globals.USER_KEY); PageManager page = new PageManager(); String conditions = RequestUtil.getConditionsWhere(request, page); try { BaseResultSet bs = dao.searchWorkOrder(page, user, conditions); atx.setOutData("bs", bs); } catch (Exception e) { atx.setException(e); logger.error(e); } } /** * * @throws Exception */ public void searchOemWorkOrder() throws Exception { RequestWrapper request = atx.getRequest(); User user = (User) atx.getSession().get(Globals.USER_KEY); PageManager page = new PageManager(); String conditions = RequestUtil.getConditionsWhere(request, page); try { BaseResultSet bs = dao.searchOemWorkOrder(page, user, conditions); atx.setOutData("bs", bs); } catch (Exception e) { atx.setException(e); logger.error(e); } } /** * @auther baixiaoliang * ? * @return void */ public void insert() throws Exception { RequestWrapper request = atx.getRequest(); User user = (User) atx.getSession().get(Globals.USER_KEY); try { SeBuWorkDispatchVO vo = new SeBuWorkDispatchVO(); HashMap<String, String> hm; hm = RequestUtil.getValues(request); vo.setValue(hm); vo.setCreateUser(user.getAccount()); vo.setCreateTime(Pub.getCurrentDate()); vo.setOrgId(user.getOrgId()); dao.insert(vo); vo.bindFieldToDic("STATUS", "YXBS"); atx.setOutMsg(vo.getRowXml(), "???"); } catch (Exception e) { atx.setException(e); logger.error(e); } } /** * @auther baixiaoliang * ? ? * @return void */ public void updatesertWorkOrder() throws Exception { RequestWrapper request = atx.getRequest(); User user = (User) atx.getSession().get(Globals.USER_KEY); try { SeBuWorkOrderVO vo = new SeBuWorkOrderVO(); HashMap<String, String> hm; hm = RequestUtil.getValues(request); vo.setValue(hm); vo.setCreateUser(user.getAccount()); vo.setCreateTime(Pub.getCurrentDate()); dao.updatesertWorkOrder(vo); vo.setFieldDateFormat("APPLY_DATE", "yyyy-MM-dd"); vo.setFieldDateFormat("ARRIVE_DATE", "yyyy-MM-dd"); vo.setFieldDateFormat("COMPLETE_DATE", "yyyy-MM-dd"); vo.setFieldDateFormat("CREATE_TIME", "yyyy-MM-dd"); vo.setFieldDateFormat("GO_DATE", "yyyy-MM-dd"); vo.setFieldDateFormat("REJECTION_DATE", "yyyy-MM-dd"); vo.setFieldDateFormat("REPAIR_DATE", "yyyy-MM-dd"); vo.setFieldDateFormat("UPDATE_TIME", "yyyy-MM-dd"); vo.bindFieldToDic("STATUS", "YXBS"); vo.bindFieldToDic("WORK_STATUS", "PGDZT"); atx.setOutMsg(vo.getRowXml(), "."); } catch (Exception e) { atx.setException(e); logger.error(e); } } /** * @auther baixiaoliang * ??? * @return void */ public void insertWorkDispatch() throws Exception { RequestWrapper request = atx.getRequest(); User user = (User) atx.getSession().get(Globals.USER_KEY); try { SeBuWorkDispatchVO vo = new SeBuWorkDispatchVO(); SeBuWorkOrderVO workOrderVo = new SeBuWorkOrderVO(); HashMap<String, String> hm; hm = RequestUtil.getValues(request); String workId = hm.get("WORK_ID"); String ifOut = hm.get("IF_OUT"); String ifVehicle = hm.get("IF_VEHICLE"); String flagIf = hm.get("FLAGIF"); String flagId = hm.get("FLAGID"); vo.setValue(hm); workOrderVo.setValue(hm); vo.setCreateUser(user.getAccount()); vo.setCreateTime(Pub.getCurrentDate()); vo.setStatus(DicConstant.YXBS_01); workOrderVo.setUpdateUser(user.getAccount()); workOrderVo.setUpdateTime(Pub.getCurrentDate()); workOrderVo.setDispatchTime(Pub.getCurrentDate());//? String userIds = hm.get("USER_IDS"); String userName = hm.get("USER_NAMES"); workOrderVo.setRepairUser(userName);// == String[] userIdArr = userIds.split(","); dao.insertWorkDispatch(vo, workOrderVo); for (int i = 0; i < userIdArr.length; i++) { SeBuWorkDispatchUerRlVO wUserVo = new SeBuWorkDispatchUerRlVO(); wUserVo.setDispatchId(vo.getDispatchId()); wUserVo.setUserId(userIdArr[i]); wUserVo.setStatus(DicConstant.YXBS_01); if (flagId.equals(userIdArr[i])) {//ID // wUserVo.setIfMain(flagIf); } else { //? wUserVo.setIfMain(DicConstant.SF_02); } dao.insertWorkUser(wUserVo); } QuerySet qs = dao.getWorkOrderImp(workId); String joborderPk = "";//400? String joborderCoe = "";//?? if (qs.getRowCount() > 0) { joborderPk = qs.getString(1, "JOBORDER_PK"); joborderCoe = qs.getString(1, "JOBORDER_CODE"); } Map<String, String> map = new HashMap<String, String>(); map.put("workId", workId); map.put("userName", userName);// map.put("licensePlate", hm.get("LICENSE_PLATE"));//? map.put("orgCode", user.getAccount());//???() if (DicConstant.SF_01.equals(ifOut)) {//? map.put("ifout", "1");// } else { map.put("ifout", "0");//? } if (DicConstant.SF_01.equals(ifVehicle)) {//?? map.put("ifVehicle", "1");// } else { map.put("ifVehicle", "0");//? } map.put("mobils", hm.get("MOBILS"));//? map.put("remarks", hm.get("REMARKS"));//?? map.put("joborderPk", joborderPk);//400? map.put("joborderCoe", joborderCoe);//?? SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dtime = format.format(Pub.getCurrentDate()); map.put("dtime", dtime);// // ???? //dao.updateDispatchUser(userIds); //String result= dispatchResult("1",map); UserParaConfigureVO userVo = (UserParaConfigureVO) ParaManager.getInstance().getUserParameter("201301"); String url = ""; if (userVo != null) { url = userVo.getParavalue1();//400webservice } else { url = "http://172.16.8.26/Interface/DMSService.asmx?wsdl"; } System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"); JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); org.apache.cxf.endpoint.Client client = dcf.createClient(url); Object[] objects = client.invoke("getServiceStationBack", dispatchResult("1", map)); if (!"1#".equals(objects[0])) { logger.info("#?" + objects[0]); throw new Exception("?:" + objects[0]); } //?? dao.updateWorkImp(workId); atx.setOutMsg(workOrderVo.getRowXml(), "??."); } catch (Exception e) { atx.setException(e); logger.error(e); } } /** * ? * @throws Exception */ public void updateWorkOrder() throws Exception { RequestWrapper request = atx.getRequest(); User user = (User) atx.getSession().get(Globals.USER_KEY); try { SeBuWorkOrderVO vo = new SeBuWorkOrderVO(); HashMap<String, String> hm; hm = RequestUtil.getValues(request); String workId = hm.get("WORK_ID"); vo.setValue(hm); vo.setUpdateTime(Pub.getCurrentDate()); vo.setUpdateUser(user.getAccount()); vo.setRejectionDate(Pub.getCurrentDate());//?? dao.updateWorkOrder(vo); QuerySet qs = dao.getWorkOrderImp(workId); String joborderPk = "";//400? String joborderCoe = "";//?? if (qs.getRowCount() > 0) { joborderPk = qs.getString(1, "JOBORDER_PK"); joborderCoe = qs.getString(1, "JOBORDER_CODE"); } Map<String, String> map = new HashMap<String, String>(); map.put("workId", workId); map.put("remarks", hm.get("REMARKS"));//?? map.put("joborderPk", joborderPk);//400? map.put("joborderCoe", joborderCoe);//?? map.put("orgCode", user.getAccount());//???() // ???? //dao.updatedisPatch(workId); //String result= dispatchResult("2",map); UserParaConfigureVO userVo = (UserParaConfigureVO) ParaManager.getInstance().getUserParameter("201301"); String url = ""; if (userVo != null) { url = userVo.getParavalue1();//400webservice } else { url = "http://172.16.8.26/Interface/DMSService.asmx?wsdl"; } System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"); JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); org.apache.cxf.endpoint.Client client = dcf.createClient(url); Object[] objects = client.invoke("getServiceStationBack", dispatchResult("2", map)); if (!"1#".equals(objects[0])) { logger.info("#?webservice?" + objects[0]); throw new Exception("??:" + objects[0]); } //?? dao.updateWorkImp(workId); atx.setOutMsg(vo.getRowXml(), "??"); } catch (Exception e) { atx.setException(e); logger.error(e); } } /** * @auther baixiaoliang * ? * @return void */ public void update() throws Exception { RequestWrapper request = atx.getRequest(); User user = (User) atx.getSession().get(Globals.USER_KEY); try { SeBuWorkDispatchVO vo = new SeBuWorkDispatchVO(); //SeBuWorkDispatchVO_Ext voExt=new SeBuWorkDispatchVO_Ext(); HashMap<String, String> hm; hm = RequestUtil.getValues(request); vo.setValue(hm); //voExt.setValue(hm); vo.setUpdateUser(user.getAccount()); vo.setUpdateTime(Pub.getCurrentDate()); dao.update(vo); atx.setOutMsg(vo.getRowXml(), "???"); /*LogManager.writeUserLog("","",Globals.OPERATION_TYPE_INSERT,LogManager.RESULT_SUCCESS , " [" + vo.getDispatchId() + " ?", user);*/ } catch (Exception e) { atx.setException(e); logger.error(e); LogManager.writeUserLog("", "", Globals.OPERATION_TYPE_INSERT, LogManager.RESULT_FAILURE, "?" + e.toString(), user); } } /** * @auther baixiaoliang * ? * @return void */ public void delete() throws Exception { RequestWrapper request = atx.getRequest(); String status = Pub.val(request, "status"); String dispatchId = Pub.val(request, "dispatchId"); try { if (DicConstant.YXBS_02.equals(status)) { dao.delete(dispatchId); atx.setOutMsg("", "????"); } else { atx.setOutMsg("", "?????"); } } catch (Exception e) { atx.setException(e); logger.error(e); } } /** * @auther baixiaoliang * ? * @return void */ public void search() throws Exception { RequestWrapper request = atx.getRequest(); User user = (User) atx.getSession().get(Globals.USER_KEY); PageManager page = new PageManager(); String conditions = RequestUtil.getConditionsWhere(request, page); try { BaseResultSet bs = dao.search(page, user, conditions); atx.setOutData("bs", bs); } catch (Exception e) { atx.setException(e); logger.error(e); } } /** * @auther baixiaoliang * ? * @return void */ public void resetStatus() throws Exception { RequestWrapper request = atx.getRequest(); User user = (User) atx.getSession().get(Globals.USER_KEY); String status = Pub.val(request, "status"); String dispatchId = Pub.val(request, "dispatchId"); try { SeBuWorkDispatchVO vo = new SeBuWorkDispatchVO(); vo.setDispatchId(dispatchId); vo.setUpdateUser(user.getAccount()); vo.setUpdateTime(Pub.getCurrentDate()); vo.setStatus(status); dao.update(vo); atx.setOutMsg("", "???"); } catch (Exception e) { atx.setException(e); logger.error(e); } } /** * * @param type 2? 1 * @param remark * @param type workId * @return */ public String dispatchResult(String type, Map<String, String> map) { Document domresult = DocumentFactory.getInstance().createDocument(); Element root = domresult.addElement("DBSET"); Element r = root.addElement("R"); Element c01 = r.addElement("C"); c01.addAttribute("N", "BACK_ID");//???ID if (map.get("workId") != null && !"".equals(map.get("workId"))) { c01.addText(map.get("workId")); } Element c02 = r.addElement("C"); c02.addAttribute("N", "JOBORDER_PK");//400? if (map.get("joborderPk") != null && !"".equals(map.get("joborderPk"))) { c02.addText(map.get("joborderPk")); } Element c03 = r.addElement("C"); c03.addAttribute("N", "JOBORDER_CODE");//400?? if (map.get("joborderCoe") != null && !"".equals(map.get("joborderCoe"))) { c03.addText(map.get("joborderCoe")); } Element c04 = r.addElement("C"); c04.addAttribute("N", "BACK_TYPE");//??12 c04.addText(type); Element c05 = r.addElement("C"); c05.addAttribute("N", "BACK_MSG");// if (map.get("remarks") != null && !"".equals(map.get("remarks"))) { c05.addText(map.get("remarks")); } Element c06 = r.addElement("C"); c06.addAttribute("N", "JOBORDER_DNAME");//???(??) if (map.get("orgCode") != null && !"".equals(map.get("orgCode"))) { c06.addText(map.get("orgCode")); } Element c07 = r.addElement("C"); c07.addAttribute("N", "JOBORDER_OUT");//? if (map.get("ifout") != null && !"".equals(map.get("ifout"))) { c07.addText(map.get("ifout")); } Element c08 = r.addElement("C"); c08.addAttribute("N", "REPAIRER_NAME");//?? if (map.get("userName") != null && !"".equals(map.get("userName"))) { c08.addText(map.get("userName")); } Element c09 = r.addElement("C"); c09.addAttribute("N", "REPAIRER_CONTACT");//?? if (map.get("mobils") != null && !"".equals(map.get("mobils"))) { c09.addText(map.get("mobils")); } Element c10 = r.addElement("C"); c10.addAttribute("N", "VEHICLE_FLAG");//VEHICLE_FLAG ??10? if (map.get("ifVehicle") != null && !"".equals(map.get("ifVehicle"))) { c10.addText(map.get("ifVehicle")); } Element c11 = r.addElement("C"); c11.addAttribute("N", "VEHICLE_NUMBER");//? if (map.get("licensePlate") != null && !"".equals(map.get("licensePlate"))) { c11.addText(map.get("licensePlate")); } Element c12 = r.addElement("C"); c12.addAttribute("N", "JOBORDER_DTIME");//(YYYY-MM-DD HH24:MI:SS) if (map.get("dtime") != null && !"".equals(map.get("dtime"))) { c12.addText(Pub.getCurrentDate().toLocaleString()); } else { c12.addText(Pub.getCurrentDate().toLocaleString()); } Element c13 = r.addElement("C"); c13.addAttribute("N", "REMARK");// if (map.get("remarks") != null && !"".equals(map.get("remarks"))) { c13.addText(map.get("remarks")); } return domresult.getRootElement().asXML(); } /** * ? * @throws Exception */ public void searchWorkOrderDispatch() throws Exception { RequestWrapper request = atx.getRequest(); User user = (User) atx.getSession().get(Globals.USER_KEY); PageManager page = new PageManager(); String conditions = RequestUtil.getConditionsWhere(request, page); try { BaseResultSet bs = dao.searchWorkOrderDispatch(page, user, conditions); atx.setOutData("bs", bs); } catch (Exception e) { atx.setException(e); logger.error(e); } } }