IBM实习工作(一)

2019.1.21

  今天的任务是完成会计是否在岗配置表格增加操作记录,任务描述:1.  【会计是否在岗配置】 查询结果界面: 修改人编码/修改人/修改时间 字段;2.      字段取值为【会计是否在岗配置】 新增/修改操作记录,更改坐席状态,添加记录。

 结果界面:

 

  • 第一步 通过界面寻找任务相关代码,分析功能逻辑。
    • 将鼠标放到【会计是否在岗配置表】,确定当前页面为getTprocAccountantteamUserStateList.jsp,在eclipse中通过快捷键Ctrl+H找到jsp页面。jsp代码如下:
    • <form id="queryForm" name="queryForm" method="post" action="commonbizajax2report.do?requestId=FindTodoList">
          <div id="wrapper" class="gray-bg">
              <%--<div id="page-wrapper" class="gray-bg">--%>
              <div class="">
                  <div class="p-w-md m-t-sm">
                      <div class="row">
                          <div class="row" style="margin: 10px 0px"><!--面包屑开始-->
                              <ol class="breadcrumb">
                                  <li class="active"><a style="color: #232323;">会计是否在岗配置表</a></li>
                              </ol>
                          </div><!--面包屑结束-->
                          <div class="ibox">
                              <div class="ibox-content">
                                  <div id="tt" style="display: block;">
                                      <div class="row">
                                          <div class="col-sm-3">
                                              <div class="form-group">
                                                  <label class="font-noraml">会计组名称</label>
                                                  <input type="text" id="teamname"  name="teamname" class="form-control" style="width: 100%;height: auto">
                                              </div>
                                              <div class="display-none">
                                                  <div class="form-group">
                                                      <label class="font-noraml">坐席状态</label>
                                                      <select name="seatstate" id="seatstate" class="form-control">
                                                          <option value="">请选择</option>
                                                          <option value="1">在岗</option>
                                                          <option value="0">不在岗</option>
                                                      </select>
                                                  </div>
                                              </div>
                                          </div>
      
                                          <div class="col-sm-3">
                                              <div class="form-group">
                                                  <label class="font-noraml">会计组编号</label>
                                                  <input type="text" id="teamid"  name="teamid" class="form-control" style="width: 100%;height: auto">
                                              </div>
                                          </div>
                                          <div class="col-sm-3">
                                              <div class="form-group">
                                                  <label class="font-noraml">员工姓名</label>
                                                  <input type="text" id="fullname"  name="fullname" class="form-control" style="width: 100%;height: auto">
                                              </div>
                                          </div>
                                          <div class="col-sm-3">
                                              <div class="form-group">
                                                  <label class="font-noraml">员工编号</label>
                                                  <input type="text" id="userid"  name="userid" class="form-control" style="width: 100%;height: auto">
                                              </div>
                                          </div>
                                      </div>
                                      <div class="row">
                                          <div class="col-sm-12">
                                              <div class="text-center"
                                                   style="border-bottom: 1px solid rgba(183,212,246,0.50); padding-bottom: 20px">
                                                  <button id="showAndHide" type="button"
                                                          style="background-color: #48A0FF;height: 28px;width: 28px;border: 0px;  background: url(${pageContext.request.contextPath}/newstatic/img/icon/group_12.png) 50% 50%;  border-radius: 2px;color: #FFFFFF;font-size: 14px;">
                                                      &nbsp;</button>
                                                  <button style="background-color: #48A0FF;height: 28px;width: 100px;border: 0px;border-radius: 2px;color: #FFFFFF;font-size: 14px;" type="button" onclick="onQuery()">查询 </button>
                                                  <button type="button" onclick="reset001()" style="background-color: #B7B9BB;height: 28px;width: 100px;border: 0px;border-radius: 2px;color: #FFFFFF;font-size: 14px;">重置</button>
                                              </div>
                                          </div>
                                      </div>
      
                                  </div>
                                  <div style="margin: 10px 0px 20px 0px; padding-top: 10px">
                                      <span style="border: 1px solid #48A0FF;margin-left: -20px;"></span>
                                      <span style="font-family: MicrosoftYaHei;font-size: 15px;color: #0B112A;margin-left: 13px;">查询结果</span>
                                  </div>
                                  <div class="checkListDiv q_mpsdc_body" style="margin-top: -20px;">
                                      <table id="dtClaimTodo"
                                             class="table table-striped table-hover q_table table_td_left"
                                             data-classes="table-no-bordered"
                                             data-id-field="" data-click-to-select="true" data-striped="true"
                                             data-ajax="claimTodoListSearchAjax"
                                             data-side-pagination="server" data-pagination="true" data-page-size="10"
                                             data-height="480" data-show-jumpto="true" data-resizable="false">
                                          <thead>
                                          <tr>
                                              <th data-width="150" data-field="str0" data-formatter="createTdTitle">
                                                  员工姓名
                                              </th>
                                              <th data-width="150" data-field="str1" data-formatter="createTdTitle">
                                                  员工编号
                                              </th>
                                              <th data-width="150" data-field="str2" data-formatter="createTdTitle">
                                                  会计组编号
                                              </th>
                                              <th data-width="250" data-field="str3" data-formatter="createTdTitle">
                                                  会计组名称
                                              </th>
                                              <th data-width="100" data-field="str7" data-formatter="createTdTitle">
                                                  修改人编码                            
                                              </th>
                                              <th data-width="100" data-field="str6" data-formatter="createTdTitle">
                                                  修改人
                                              </th>
                                              <th data-width="100" data-field="str8" data-formatter="createTdTitle">
                                                  修改时间
                                              </th>
                                                  <th data-width="100" data-field="str4" data-formatter="renderOption">
                                                  座席状态
                                              </th>
                                          </tr>
                                          </thead>
                                      </table>
                                  </div>
                              </div>
                          </div>
                      </div>
                  </div>
              </div>
              <br/><br/><br/>
              <div class="navbar-fixed-bottom"
                   style="height: 80px;width:100%;background: #FFFFFF;box-shadow: 0 -2px 10px 0 #C0DFFF;padding: 20px 60px;z-index: 10000;">
              </div>
              <%-- </div>--%>
          </div>
      </form>
      getTprocAccountantteamUserStateList.jsp
      <script>
          var curPortalUserGroupId = "";
          var user;
          var commonUiDataBindService4QueryList = new CommonUiDataBindService4QueryList("myTodo");
          $(function () {
              $("#showAndHide").click(function () {
                  $(".display-none").slideToggle(function () {
                  });
                  $(this).toggleClass('showAndHide-active');
      
              });
              $('#hh').click(function () {
                  $('#tt').slideToggle();
              });
              $("#seatstate").chosen();
              $("#dtClaimTodo").bootstrapTable();//初始化表格
          });
          //=================================================查询条件========================================================================
          function onQuery(){
              $('#dtClaimTodo').bootstrapTable('refresh');
          }
          function reset001(){
              $("#queryForm input").val("");
              $("#queryForm select").val("");
              $("#queryForm select").trigger("chosen:updated");
          }
          //====================================================列表=======================================================
          function claimTodoListSearchAjax(params) {//数据查询ajax
              var paramUrl = contextPath + "/commonbizajax2report.do?requestId=listProcAccountantStateService";
              var queryResultModel = "str0,str1,str2,str3,str4,str5,str7,str6,str8";
              var data ={queryResultModel : queryResultModel};
              data = generateSearchConditionAndUpd2Ui(commonUiDataBindService4QueryList,this,"queryForm",data);
              loadBootstrapTableData(this, paramUrl, params, $('#queryForm'),data,setParam);//ajax加载表格
          }
          function setParam(data) {
              curPortalUserGroupId = JSON.parse(data.user).curGroupId;
              user = data.user;
          }
          function renderOption(value, row, index, field) {
              var result="";
              if(value =='1'){
                  result += '<input type="radio" name=\"'+index+'\" checked="checked" onclick="update(\''+row.str5+'\',1);" value="1" /><label class="font-noraml">在岗</label>&nbsp;&nbsp;&nbsp;';
                  result += '<input type="radio" name=\"'+index+'\" onclick="update(\''+row.str5+'\',0);" value="0" /><label class="font-noraml">不在岗</label>';
              }else{
                  result += '<input type="radio" name=\"'+index+'\" onclick="update(\''+row.str5+'\',1);" value="1" /><label class="font-noraml">在岗</label>&nbsp;&nbsp;&nbsp;';
                  result += '<input type="radio" name=\"'+index+'\" checked="checked" onclick="update(\''+row.str5+'\',0);" value="0" /><label class="font-noraml">不在岗</label>';
              }
              return result;
          }
      
          function update(id,obj){
              var url=doProcessUrl(contextPath +"/commonbizajax.do?requestId=updateTprocAccountantteamUserState&id="+id+"&seatstate="+obj);
              return ajaxService.post({ url: url, data: null}).done(function (ajaxResponse) {
                  if (ajaxResponse.result == AjaxResultFlag.OK) {
                       MessageBox.notice("更新坐席状态成功!");
                       $('#dtClaimTodo').bootstrapTable('refresh');
                  }else{
                      MessageBox.error("更新坐席状态失败!");
                  }
              });
          }
      </script>
      getTprocAccountantteamUserStateList.jsp的js代码
    • 要完成这个功能需要对两个功能做修改,【更新】和【查询】,对应jsp方法为update(id,obj)claimTodoListSearchAjax(params),可以看到两个方法拼接了URL,"/commonbizajax2report.do?requestId=listProcAccountantStateService",因为项目使用Struts1,通过requestId寻找控制器xxxaction.xml,相关代码如下:
      <!-- 会计是否在岗配置表  开始 -->
          <action requestId="listProcAccountantStateService" service="tprocAccountantteamService" method="getTprocAccountantteamUserStateList" path="/pages/workflow/getTprocAccountantteamUserStateList.jsp" />
          <action requestId="updateTprocAccountantteamUserState" service="tprocAccountantteamService" method="updateTprocAccountantteamUserState" >
              <result name="SUCCESS" type="redirect" path="/service.do?requestId=listProcAccountantStateService"/>
              <result name="ERROR" path="/newPages/efinance/common/errors.jsp" />
          </action>
          <!-- 会计是否在岗配置表  结束 -->
      Action-config-workflow.xml
    • 通过service以及method找到对应的serviceImpl:tprocAccountantteamServiceImpl,相关内容如下:
      public void getTprocAccountantteamUserStateList(IMessageObject mo)
                  throws BusinessException, UnsupportedEncodingException {
              Map inputMap = mo.getInputMap();
              PageModel pm = PageUtil.getPageModel(mo);
              try {
                  tprocAccountantteamDAO.getTprocAccountantteamUserStateList(pm, mo);
              } catch (DBException e) {
                  e.printStackTrace();
                  throw new BusinessException(e.getMessage());
              }
              mo.setOutput(pm);
          }
          
          public void updateTprocAccountantteamUserState (IMessageObject mo)  throws BusinessException {
              String  id =(String) mo.getInput("id");
              TProcAccountantteamUser user =tprocAccountantteamDAO.get(TProcAccountantteamUser.class, Long.parseLong(id));
              String seatstate =(String) mo.getInput("seatstate");
              String modifierName = mo.getUser().getFullname();
              String modifierId = mo.getUser().getUsername();
              
              
              tprocAccountantteamDAO.updateComsegcodeStatus(id,seatstate,modifierId,modifierName);
              if(seatstate!=null&&seatstate.equals("1")){
                  
                     Long handleCount=tprocAccountantteamDAO.matchCurrentOrder(String.valueOf(user.getTeamId()));
                     user.setHandleCount(handleCount);
                     user.setModifierName(modifierName);
                     user.setModifierId(modifierId);
                     tprocAccountantteamDAO.update(user);
                    
                  }
               SysLogUtils.saveSysLog("T_PROC_ACCOUNTANTTEAM_USER", "会计组人员", mo.getUser().getUserid(), modifierId, mo.getUser().getFullname(), 
                       new Date(), "修改", mo.getUser().getUserid()+"","会计组Id:"+ user.getTeamId()+"人员Id:"+user.getUserId()+" 改在岗状态为"+seatstate);
          }
      tprocAccountantteamServiceImpl.java

       相应的实体类和数据层为:TProcAccountantteamUser和tprocAccountantteamDAOImpl,相关代码如下:

      import java.io.Serializable;
      import java.util.Date;
      
      @SuppressWarnings("serial")
      public class TProcAccountantteamUser implements Serializable {
      
          private Long id;
          private Long compId;
          private Long teamId;
          private String teamName;
          private Long userId;
          private String userName;
          private String fullName;
          private Long groupId;
          private String groupName;
          private Long order;
          
          private String operatorUsername;
          private Date operatorDate;
          private String operatorIp;
          
          private String modifierId;
          private String modifierName;
          private Date modifierTime;
          
          
          private String seatState;
          private String groupLeader;
          private String userNo;
          private String teamNo;
          
          private String isReviewAccount;
          private String reviewAccountNo;
          private String reviewAccount;
          private Long   handleCount;
          
          private Long   index;
      TProcAccountantteamUser.java
      public void getTprocAccountantteamUserStateList(PageModel pageModel, IMessageObject mo) throws DBException{
              try{
                  Map inputMap = mo.getInputMap();
                  String compId = mo.getUser().getCurCompId();
                  StringBuffer sql = new StringBuffer("");
                  sql.append("select tu.full_name  as  fullname, ");//0
                  sql.append(" tu.user_name as  username,            ");//1
                  sql.append(" t.team_no   as  teamno,");//2
                  sql.append(" t.team_name  as  teamname, ");//3
                  sql.append(" tu.seatstate  as  seatstate, ");//4
                  sql.append(" tu.id  as  id ,");//5
                  sql.append(" tu.modifier_Id  as  modifierId ,");//6
                  sql.append(" tu.modifier_Name  as  modifierName ,");//7
                  sql.append(" tu.modifier_Time  as  modifierTime");//8
                  
                  sql.append(" from t_Proc_Accountantteam_user tu");
                  sql.append(" left join t_proc_accountantteam t ");
                  sql.append(" on tu.team_id = t.id ");
                  sql.append(" where   t.comp_id =  "+compId);
                  sql.append("   and t.isenable = '1' ");
                  
                  String fullname = (String)inputMap.get("fullname");
                  if (fullname!=null && !"".equals(fullname)){
                      sql.append(" and tu.full_name like '%"+fullname.trim()+"%' ");
                  }
                  String userid = (String)inputMap.get("userid");
                  if (userid!=null && !"".equals(userid)){
                      sql.append(" and tu.user_name = '"+userid.trim()+"' ");
                  }
                  String teamid = (String)inputMap.get("teamid");
                  if (teamid!=null && !"".equals(teamid)){
                      sql.append(" and t.team_no like '%"+teamid.trim()+"%'  ");
                  }
                  String teamname = (String)inputMap.get("teamname");
                  if (teamname!=null && !"".equals(teamname)){
                      sql.append(" and t.team_name like  '%"+teamname.trim()+"%' ");
                  }
                  String seatstate = (String)inputMap.get("seatstate");
                  if (seatstate!=null && !"".equals(seatstate)){
                      sql.append(" and tu.seatstate =  '"+seatstate+"' ");
                  }
                  sql.append(" order by  t.id");
                  System.out.println(sql);
                  this.findsqlPageModel(pageModel, sql.toString());
              }catch(Exception e){
                  e.printStackTrace();
              }
          }
          
          
          
          
          public boolean updateComsegcodeStatus(String id,String status,String modifierId,String modifierName) {
              boolean ret = true;
                  StringBuilder sql = new StringBuilder();
                  sql.append("update t_Proc_Accountantteam_user set ");
                  sql.append(" seatstate = ?, ");
                  sql.append(" modifier_Name = ?, ");
                  sql.append(" modifier_Id = ?, ");
                  sql.append(" modifier_Time = sysdate ");
                  sql.append(" where id = ? ");
                  try {
                      this.excuteSql(sql.toString(),new Object[]{status,modifierId,modifierName,id});
                  } catch (DBException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
              return  ret;
          }
      tprocAccountantteamDAOImpl.java
    • 任务相关主要代码查找完毕,分析业务逻辑知,需要的工作为对service层、Dao层和前台代码做相应的修改,将用户的修改操作记录到数据库,并且通过list方法从数据库将信息取出,同时在点击【在岗】/【不在岗】刷新页面显示结果。简单的来说,首先在数据库、实体类【TProcAccountantteamUser】和jsp【getTprocAccountantteamUserStateList.jsp】分别增加关于操作记录的三条字段。然后在tprocAccountantteamDAOImpl对查询和更新方法修改sql语句。最后关于修改【坐席状态】时页面刷新,在jsp做相应的修改。
  • 第二步 根据需求修改代码
    • 在数据库(oracle数据库)增加三条字段
      alter table t_Proc_Accountantteam_user add(MODIFIER_ID varchar2(50));
      alter table t_Proc_Accountantteam_user add(MODIFIER_NAME varchar2(50));
      alter table t_Proc_Accountantteam_user add(MODIFIER_TIME timestamp);
    • 在实体类(TProcAccountantteamUser)增加三条字段
      private String modifierId;//修改人
          private String modifierName;//修改人编码
          private Date modifierTime;//修改时间
    • 在jsp(getTprocAccountantteamUserStateList)增加三条信息
      <th data-width="100" data-field="str6" data-formatter="createTdTitle">
        修改人编码                            
                   </th>
                   <th data-width="100" data-field="str7" data-formatter="createTdTitle">
        修改人
                   </th>
                   <th data-width="100" data-field="str8" data-formatter="createTdTitle">
        修改时间
                   </th>
    • tprocAccountantteamDAOImpl修改sql代码,并在tprocAccountantteamServiceImpl进行相应的修改,修改【更新】方法时,【修改人操作时间】使用的是数据库提供的时间sysdate,所以在serviceImpl也就不需要提取用户的当前时间,
      String modifierName = mo.getUser().getFullname(); String modifierId = mo.getUser().getUsername();
      public boolean updateComsegcodeStatus(String id,String status,String modifierId,String modifierName) {
              boolean ret = true;
                  StringBuilder sql = new StringBuilder();
                  sql.append("update t_Proc_Accountantteam_user set ");
                  sql.append(" seatstate = ?, ");
                  sql.append(" modifier_Name = ?, ");
                  sql.append(" modifier_Id = ?, ");
                  sql.append(" modifier_Time = sysdate ");
                  sql.append(" where id = ? ");
                  try {
                      this.excuteSql(sql.toString(),new Object[]{status,modifierName,modifierId,id});
                  } catch (DBException e) {
                      e.printStackTrace();
                  }
              return  ret;
      TprocAccountantteamDAOImpl

       拼接三条更新字段的sql

      sql.append(" modifier_Name = ?, "); sql.append(" modifier_Id = ?, "); sql.append(" modifier_Time = sysdate ");

       修改【查询】方法,拼接select三条字段的sql

      public void getTprocAccountantteamUserStateList(PageModel pageModel, IMessageObject mo) throws DBException{
              try{
                  Map inputMap = mo.getInputMap();
                  String compId = mo.getUser().getCurCompId();
                  StringBuffer sql = new StringBuffer("");
                  sql.append("select tu.full_name  as  fullname, ");//0
                  sql.append(" tu.user_name as  username,            ");//1
                  sql.append(" t.team_no   as  teamno,");//2
                  sql.append(" t.team_name  as  teamname, ");//3
                  sql.append(" tu.seatstate  as  seatstate, ");//4
                  sql.append(" tu.id  as  id ,");//5
                  sql.append(" tu.modifier_Id  as  modifierId ,");//6
                  sql.append(" tu.modifier_Name  as  modifierName ,");//7
                  sql.append(" tu.modifier_Time  as  modifierTime");//8
                  
                  sql.append(" from t_Proc_Accountantteam_user tu");
                  sql.append(" left join t_proc_accountantteam t ");
                  sql.append(" on tu.team_id = t.id ");
                  sql.append(" where   t.comp_id =  "+compId);
                  sql.append("   and t.isenable = '1' ");
                  
                  String fullname = (String)inputMap.get("fullname");
                  if (fullname!=null && !"".equals(fullname)){
                      sql.append(" and tu.full_name like '%"+fullname.trim()+"%' ");
                  }
                  String userid = (String)inputMap.get("userid");
                  if (userid!=null && !"".equals(userid)){
                      sql.append(" and tu.user_name = '"+userid.trim()+"' ");
                  }
                  String teamid = (String)inputMap.get("teamid");
                  if (teamid!=null && !"".equals(teamid)){
                      sql.append(" and t.team_no like '%"+teamid.trim()+"%'  ");
                  }
                  String teamname = (String)inputMap.get("teamname");
                  if (teamname!=null && !"".equals(teamname)){
                      sql.append(" and t.team_name like  '%"+teamname.trim()+"%' ");
                  }
                  String seatstate = (String)inputMap.get("seatstate");
                  if (seatstate!=null && !"".equals(seatstate)){
                      sql.append(" and tu.seatstate =  '"+seatstate+"' ");
                  }
                  sql.append(" order by  t.id");
                  System.out.println(sql);
                  this.findsqlPageModel(pageModel, sql.toString());
              }catch(Exception e){
                  e.printStackTrace();
              }
          }
      TprocAccountantteamDAOImpl
      sql.append(" tu.modifier_Id  as  modifierId ,");//6
      sql.append(" tu.modifier_Name  as  modifierName ,");//7
      sql.append(" tu.modifier_Time  as  modifierTime");//8
    • 这里可以看到使用的是典型的MVC设计模式思想,orm框架使用的是hibernate,通过Struts的action.xml耦合前台页面和后台系统。

    • 该需求还有一个功能是当操作人修改【坐席状态】要求页面响应,刷新出操作记录,这个功能需要对jsp页面的js代码进行修改,更新坐席状态成功时,使用bootstrap更新页面
      function update(id,obj){
              var url=doProcessUrl(contextPath +"/commonbizajax.do?requestId=updateTprocAccountantteamUserState&id="+id+"&seatstate="+obj);
              return ajaxService.post({ url: url, data: null}).done(function (ajaxResponse) {
                  if (ajaxResponse.result == AjaxResultFlag.OK) {
                       MessageBox.notice("更新坐席状态成功!");
                       $('#dtClaimTodo').bootstrapTable('refresh');
                  }else{
                      MessageBox.error("更新坐席状态失败!");
                  }
              });
          }
      update
      $('#dtClaimTodo').bootstrapTable('refresh');
  •  

     第三步 测试代码

全部评论

相关推荐

杨柳哥:这不是普通人,那这个钱的是天才
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务