新增、修改和删除接口完成流程

- 编辑:admin - 点击数:967

新增、修改和删除接口完成流程

新增和修改接口

需求:通过案件编码判断是更新还是新增,如果有这个案件编码就更新数据,没有这个案件编码就新增数据。

第一步

创建实体类和接收类

实体类

;;;;*;;@Data@Entity@Table(name="T_UMSM_EVENT_")//表名与实体名不一致todo@Cache(usage=_WRITE)publicclassTUmEvent_{//@SequenceGenerator(name="generator",allocationSize=1,initialValue=1,sequenceName="SEQ")//@GeneratedValue(strategy=,generator="generator")@Id@SequenceGenerator(name="generator",allocationSize=1,initialValue=1,sequenceName="test2_autoinc")@GeneratedValue(strategy=,generator="generator")@Column(name="EVENT_ID")privateLongeventId;@Column(name="INS_ID")privateLonginsId;@Column(name="DEF_ID")privateIntegerdefId;//@Where(clause="EVENTCODE=EVENTCODE")@Column(name="EVENTCODE")privateStringeventCode;@Column(name="EVENT_CLASS")privateStringeventClass;@Column(name="EVENT_DESC")privateStringeventDesc;@Column(name="LOCATION_DESC")privateStringlocationDesc;@Column(name="LOCATIONX")privateDoublelocationX;@Column(name="LOCATIONY")privateDoublelocationY;@Column(name="KEYWORD")privateStringkeyWord;@Column(name="NOTE")privateStringnote;@Column(name="CREATETIME")privateDatecreateTime;@Column(name="CREATOR")privateLongcreator;@Column(name="CREATEDEPT")privateLongcreateDept;@Column(name="SUPERVISOR")privateIntegersupervisor;@Column(name="SUPERVISEDEPT")privateIntegersuperviseDept;@Column(name="VERSION")privateIntegerversion;@Column(name="ISDONE")privateStringisDone;@Column(name="STATUS")privateStringstatus;@Column(name="EVENTSOURCE_CODE")privateStringeventSourceCode;@Column(name="COMPLAINANT")privateStringcomplainant;@Column(name="CONTACTMODE")privateStringcontactMode;@Column(name="MOBILEEVENT_CODE")privateStringmobileEventCode;@Column(name="DELAY")privateStringdelay;@Column(name="ISSCORE")privateIntegerisSCore;@Column(name="ADVERT_ID")privateIntegeradvertId;@Column(name="ISSPECIAL")privateStringisSpecial;@Column(name="SPECIALPLACE_ID")privateIntegerspecialPlaceId;@Column(name="SPECIALPLACE_XZQYID")privateIntegerspecialPlaceXzqyId;@Column(name="IS_SWAP")privateIntegerisSwap;@Column(name="SWAP_OBJECT")privateStringswapObject;@Column(name="MODIFY_TIME")privateDatemodifyTime;@Column(name="XZQY_ID")privateIntegerxzqyId;@Column(name="CURRENT_STEP_NAME")privateStringcurrentStepName;@Column(name="CURRENT_DEPT")privateStringcurrentDept;@Column(name="CURRENT_DEAL_PEOPLE")privateStringcurrentDealPeople;}

接收类

;;;@DatapublicclassShowUmEvent{privateIntegerdefId;privateStringeventCode;privateStringeventClass;privateStringeventDesc;privateIntegerxzqyId;privateStringstatus;privateDatecreateTime;privateStringcurrentStepName;privateStringcurrentDept;privateStringcurrentDealPeople;}
第二步

创建EventService类、BaseService类、BaseDao类,并创建saveOrUpdate方法

EventService类

_;;;;;publicclassEventServiceextsBaseService{publicvoidsaveOrUpdate(TUmEvent_event)throwsException{Stringsql2="fromTUmEvent_whereEVENTCODE='"+()+"'";ListTUmEvent_list=(sql2);//根据案件编号去查出案件if((list)){//存在就更新for(TUmEvent_tUmEvent_:list){//if((tUmEvent_))continue;LongeventId=tUmEvent_.getEventId();//if((eventId))continue;(event,tUmEvent_);tUmEvent_.setEventId(eventId);(tUmEvent_);//有主键才会更新}}else{//不存在就新增(event);}}}

BaseService类

;;;;;;;;;;publicclassBaseService{@AutowiredprotectedBaseDaobaseDao;/***参数获取及设置服务**@paramcode:参数代码*@paramdefaultValue:若找不到记录,则返回该默认值**/publicStringgetSysConfig(Stringcode,StringdefaultValue)throwsException{TSysConfigconfig=(TSysConfig)("TSysConfig","configCode=?",newObject[]{code});if(config!=null)();returndefaultValue;}publicMapString,StringgetSysConfig(Object[]codeArray,StringdefaultValue)throwsException{ListTSysConfigconfigList=null;MapString,Stringmap=newHashMapString,String();if(codeArray!=){StringBufferwhere=newStringBuffer();for(inti=0;;i++){if(i!=){("configCode=?or");}else{("configCode=?");}}configList=("TSysConfig",(),codeArray);if(configList!=()0){for(inti=0;();i++){StringconfigValue=(i).getConfigValue()==null?defaultValue:(i).getConfigValue();((i).getConfigCode(),configValue);}}}returnmap;}publicStringgetKey(Stringkeyname)throwsException{Object[]inParams=newObject[]{keyname};Object[]outParams=newObject[]{""};int[]outParamtypes=newint[]{};Object[]results=("SP_KEYGENERATOR(?,?)",inParams,outParams,outParamtypes);if(results!=)returnresults[0].toString();returnnull;}/***保存输入报文**/publicvoidinLog(StringlogAction,HttpServletRequestrequest)throwsException{TSysLoglog=newTSysLog();(null);("01");(newDate());(());(logAction);(log);}/***保存输出报文**/publicvoidoutLog(StringlogAction,HttpServletRequestrequest)throwsException{TSysLoglog=newTSysLog();(null);("02");(newDate());(());(logAction);(log);}/***保存输入报文时发生异常,则将报文信息保存到日志文件当中**/publicvoidinLogForException(Stringmethod,StringlogAction,HttpServletRequestrequest,Loggerlog){StringBufferlogError=newStringBuffer("手机端调用接口-").app(method).app(":保存输入报文时发生异常。");("IP:").app(()).app(",");("时间:").app(newDate());("报文:").app(logAction);(());}/***保存输出报文时发生异常,则将报文信息保存到日志文件当中**/publicvoidoutLogForException(Stringmethod,StringlogAction,HttpServletRequestrequest,Loggerlog){StringBufferlogError=newStringBuffer("手机端调用接口-").app(method).app(":保存输出报文时发生异常。");("IP:").app(()).app(",");("时间:").app(newDate());("报文:").app(logAction);(());}publicvoidsaveOrUpdateByMerge(Objectobject)throwsException{(object);}publicvoidflush()throwsException{();}publicvoidclear()throwsException{();}}

BaseDao类

publicclassBaseDaoextsHibernateDaoSupport{privateLoggerlog=(());publicvoidsaveOrUpdate(Objectobject){("saveOrUpdate"+().getName()+"instance");try{getHibernateTemplate().saveOrUpdate(object);("saveOrUpdatesuccessful");}catch(RuntimeExceptionre){("saveOrUpdatefailed",re);throwre;}}publicvoidexecBySql(Stringsql){("execbysql:"+sql);try{Sessionsession=getSession();SQLQueryquery=(sql);();("execsuccessful");}catch(RuntimeExceptionre){("execfailed",re);throwre;}}}
第三步

创建LogEventAnnotation接口、EventController类

LogEventAnnotation接口

;;;;;;;@Target({,})@Retention()@Documented@Inheritedpublic@interfaceLogEventAnnotation{/***菜单名*/publicStringEventmenuName()default"";/***要执行的操作类型,比如:增加操作*/publicUEventTypeuEventType();/***要执行的具体操作*/publicStringuEventName()default"";}

EventController类

@Slf4jpublicclassEventControllerextsBaseController{@AutowiredprivateEventServiceeventService;/***添加或更新*/@LogEventAnnotation(EventmenuName="事件详情",uEventType=,uEventName="新增修改事件")publicvoidaddEvent(HttpServletRequestrequest,HttpServletResponseresponse,ShowUmEventform)throwsException{booleanflag=true;try{TUmEvent_event_=newTUmEvent_();event_.setModifyTime(newDate());event_.setDefId(());event_.setEventCode(());event_.setEventClass(());event_.setEventDesc(());event_.setXzqyId(());event_.setStatus(());if(()!=null){event_.setCreateTime(());}else{event_.setCreateTime(newDate());}event_.setCurrentStepName(());event_.setCurrentDept(());event_.setCurrentDealPeople(());(event_);}catch(Exceptione){flag=false;();}}}
第四步

测试

删除接口

需求:根据案件编码删除案件

第一步

在EventService类创建delete方法

publicvoiddelete(StringeventCode)throwsException{Stringsql="deletefromT_UMSM_EVENT_whereeventCode="+eventCode;(sql);}
第二步

在EventController类创建delEvent方法

@LogEventAnnotation(EventmenuName="事件详情",uEventType=,uEventName="删除事件")publicvoiddelEvent(HttpServletRequestrequest,HttpServletResponseresponse)throwsException{booleanflag=true;try{StringeventCode=(("eventCode"));(eventCode);}catch(Exceptione){flag=false;();}}
第三步

测试

文章网址:
新增、修改和删除接口完成流程 http://www.daiyqd.com/suzhouzuizhengguizhuyunjigou/20240426/8913.html