Browse Source

邀请注册记录增加编辑删除功能

hejq 7 years ago
parent
commit
d2c7569911

+ 31 - 0
src/main/java/com/uas/platform/b2bManage/controller/InviteController.java

@@ -6,14 +6,18 @@ import com.uas.platform.b2bManage.model.UseType;
 import com.uas.platform.b2bManage.service.InviteService;
 import com.uas.platform.b2bManage.service.UseLogService;
 import com.uas.platform.b2bManage.support.JxlsExcelView;
+import com.uas.platform.b2bManage.support.MyException;
 import com.uas.platform.b2bManage.web.BaseController;
 import com.uas.platform.core.model.PageInfo;
 import com.uas.platform.core.model.PageParams;
 import com.uas.platform.core.util.AgentUtils;
+import javassist.NotFoundException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Sort;
+import org.springframework.ui.ModelMap;
 import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
@@ -85,4 +89,31 @@ public class InviteController extends BaseController {
         useLogService.appendLog(UseType.EXPROT_INVITE_DATA.code(), keyword, AgentUtils.getIp(request));
         return modelAndView;
     }
+
+    /**
+     * 通过企业UU,填写的邀请用户信息,企业信息更新邀请记录
+     *
+     * @param enUU 注册的企业UU
+     * @param userMessage 邀请人信息(姓名、手机、UU号等)
+     * @param enterMessage 邀请企业信息(名称、UU号、营业执照等)
+     * @return
+     */
+    @RequestMapping(value = "/edit", method = RequestMethod.POST)
+    public ModelMap editInvite(Long enUU, String userMessage, String enterMessage) throws MyException {
+        useLogService.appendLog(UseType.EDIT_INVITE.code(), "UU:" + enUU + ";邀请人: " + userMessage + "; 邀请企业: " + enterMessage, AgentUtils.getIp(request));
+        return inviteService.editInvite(enUU, userMessage, enterMessage);
+    }
+
+    /**
+     * 清除邀请记录
+     *
+     * @param enUU 注册的企业UU
+     * @return
+     */
+    @RequestMapping(value = "/delete/{enUU}", method = RequestMethod.POST)
+    public ModelMap editInvite(@PathVariable("enUU") Long enUU) throws MyException {
+        useLogService.appendLog(UseType.DELETE_INVITE.code(), "UU:" + enUU, AgentUtils.getIp(request));
+        inviteService.deleteByUU(enUU);
+        return success("清除成功");
+    }
 }

+ 21 - 1
src/main/java/com/uas/platform/b2bManage/dao/EnterpriseBaseInfoDao.java

@@ -5,11 +5,31 @@ import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.stereotype.Repository;
 
+import java.util.List;
+
 /**
  * 企业信息
  *
- * Created by hejq on 2018-04-23.
+ *
+ * @author hejq
+ * @date 2018-04-23
  */
 @Repository
 public interface EnterpriseBaseInfoDao extends JpaRepository<EnterpriseBaseInfo, Long>, JpaSpecificationExecutor<EnterpriseBaseInfo> {
+
+    /**
+     * 通过企业名称查询企业是否存在
+     *
+     * @param name 企业名称
+     * @return
+     */
+    List<EnterpriseBaseInfo> findByEnName(String name);
+
+    /**
+     * 通过营业执照查询企业是否存在
+     *
+     * @param businessCode 营业执照
+     * @return
+     */
+    List<EnterpriseBaseInfo> findByEnBussinessCode(String businessCode);
 }

+ 42 - 0
src/main/java/com/uas/platform/b2bManage/dao/UserBaseInfoDao.java

@@ -0,0 +1,42 @@
+package com.uas.platform.b2bManage.dao;
+
+import com.uas.platform.b2bManage.model.UserBaseInfo;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+/**
+ * 平台用户信息
+ *
+ * @author hejq
+ * @date 2018-07-12 18:24
+ */
+@Repository
+public interface UserBaseInfoDao extends JpaSpecificationExecutor<UserBaseInfo>, JpaRepository<UserBaseInfo, Long> {
+
+    /**
+     * 通过姓名查询用户信息
+     *
+     * @param name 用户姓名
+     * @return
+     */
+    List<UserBaseInfo> findByName(String name);
+
+    /**
+     * 通过电话查询用户信息
+     *
+     * @param tel 电话
+     * @return
+     */
+    List<UserBaseInfo> findByTel(String tel);
+
+    /**
+     * 通过邮箱查询用户信息
+     *
+     * @param email 邮箱
+     * @return
+     */
+    List<UserBaseInfo> findByEmail(String email);
+}

+ 2 - 0
src/main/java/com/uas/platform/b2bManage/model/Invite.java

@@ -6,6 +6,8 @@ import java.io.Serializable;
 import java.util.Date;
 
 /**
+ * 邀请记录
+ *
  * @author hejq
  * @date 2018-07-10 16:18
  */

+ 10 - 0
src/main/java/com/uas/platform/b2bManage/model/UseType.java

@@ -72,6 +72,16 @@ public enum UseType {
      */
     EXPROT_INVITE_DATA("导出邀请注册数据"),
 
+    /**
+     * 编辑邀请注册信息
+     */
+    EDIT_INVITE("编辑邀请注册信息"),
+
+    /**
+     * 清除邀请记录
+     */
+    DELETE_INVITE("清除邀请记录"),
+
     /**
      * 空状态
      */

+ 77 - 0
src/main/java/com/uas/platform/b2bManage/model/UserBaseInfo.java

@@ -0,0 +1,77 @@
+package com.uas.platform.b2bManage.model;
+
+import javax.persistence.*;
+import java.io.Serializable;
+
+/**
+ * 平台人员信息
+ *
+ * @author hejq
+ * @date 2018-07-12 18:21
+ */
+@Table(name = "sec$users")
+@Entity
+public class UserBaseInfo implements Serializable {
+
+    /**
+     * 序列号
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 用户UU号
+     */
+    @Id
+    @Column(name = "user_uu")
+    private Long uu;
+
+    /**
+     * 用户姓名
+     */
+    @Column(name = "user_name")
+    private String name;
+
+    /**
+     * 用户电话
+     */
+    @Column(name = "user_tel")
+    private String tel;
+
+    /**
+     * 用户邮箱
+     */
+    @Column(name = "user_email")
+    private String email;
+
+    public Long getUu() {
+        return uu;
+    }
+
+    public void setUu(Long uu) {
+        this.uu = uu;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getTel() {
+        return tel;
+    }
+
+    public void setTel(String tel) {
+        this.tel = tel;
+    }
+
+    public String getEmail() {
+        return email;
+    }
+
+    public void setEmail(String email) {
+        this.email = email;
+    }
+}

+ 21 - 0
src/main/java/com/uas/platform/b2bManage/service/InviteService.java

@@ -1,8 +1,11 @@
 package com.uas.platform.b2bManage.service;
 
 import com.uas.platform.b2bManage.model.Invite;
+import com.uas.platform.b2bManage.support.MyException;
 import com.uas.platform.core.model.PageInfo;
+import javassist.NotFoundException;
 import org.springframework.data.domain.Page;
+import org.springframework.ui.ModelMap;
 
 import java.text.ParseException;
 
@@ -25,4 +28,22 @@ public interface InviteService {
      * @throws ParseException
      */
     Page<Invite> findInviteByPageInfo(PageInfo info, String keyword, String fromDate, String endDate) throws ParseException;
+
+    /**
+     * 通过企业UU,填写的邀请用户信息,企业信息更新邀请记录
+     *
+     * @param enUU 注册的企业UU
+     * @param userMessage 邀请人信息(姓名、手机、UU号等)
+     * @param enterMessage 邀请企业信息(名称、UU号、营业执照等)
+     * @return
+     * @throws MyException 抛出异常
+     */
+    ModelMap editInvite(Long enUU, String userMessage, String enterMessage) throws MyException;
+
+    /**
+     * 清除邀请记录
+     *
+     * @param enUU 企业UU
+     */
+    void deleteByUU(Long enUU);
 }

+ 20 - 0
src/main/java/com/uas/platform/b2bManage/service/impl/BaseService.java

@@ -18,6 +18,16 @@ public class BaseService {
      */
     static final String UU_REGEXP = "^\\d{4,}$";
 
+    /**
+     * 手机号正则表达式
+     */
+    static final String TEL_REGEXP = "0?(13|14|15|18)[0-9]{9}";
+
+    /**
+     * 邮箱正则表达式
+     */
+    static final String EMAIL_REGEXP = "\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}";
+
     /**
      * jdbc方法调用
      */
@@ -29,4 +39,14 @@ public class BaseService {
      */
     static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
 
+    /**
+     * 服务器错误
+     */
+    static final String SERVER_CODE = "500";
+
+    /**
+     * 未找到错误
+     */
+    static final String NOT_FOUND_CODE = "404";
+
 }

+ 128 - 0
src/main/java/com/uas/platform/b2bManage/service/impl/InviteServiceImpl.java

@@ -1,9 +1,15 @@
 package com.uas.platform.b2bManage.service.impl;
 
 import com.uas.platform.b2bManage.core.util.StringUtils;
+import com.uas.platform.b2bManage.dao.EnterpriseBaseInfoDao;
 import com.uas.platform.b2bManage.dao.InviteDao;
+import com.uas.platform.b2bManage.dao.UserBaseInfoDao;
+import com.uas.platform.b2bManage.model.EnterpriseBaseInfo;
 import com.uas.platform.b2bManage.model.Invite;
+import com.uas.platform.b2bManage.model.UserBaseInfo;
+import com.uas.platform.b2bManage.page.exception.IllegalOperatorException;
 import com.uas.platform.b2bManage.service.InviteService;
+import com.uas.platform.b2bManage.support.MyException;
 import com.uas.platform.core.model.PageInfo;
 import com.uas.platform.core.persistence.criteria.CriterionExpression;
 import com.uas.platform.core.persistence.criteria.LogicalExpression;
@@ -13,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
+import org.springframework.ui.ModelMap;
 
 import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
@@ -36,6 +43,12 @@ public class InviteServiceImpl extends BaseService implements InviteService {
     @Autowired
     private InviteDao inviteDao;
 
+    @Autowired
+    private EnterpriseBaseInfoDao enterpriseBaseInfoDao;
+
+    @Autowired
+    private UserBaseInfoDao userBaseInfoDao;
+
     /**
      * 通过分页信息获取邀请注册记录
      *
@@ -95,4 +108,119 @@ public class InviteServiceImpl extends BaseService implements InviteService {
         }
         return invites;
     }
+
+    /**
+     * 通过企业UU,填写的邀请用户信息,企业信息更新邀请记录
+     *
+     * @param enUU 注册的企业UU
+     * @param userMessage 邀请人信息(姓名、手机、UU号等)
+     * @param enterMessage 邀请企业信息(名称、UU号、营业执照等)
+     * @return
+     * @throws MyException 抛出异常
+     */
+    @Override
+    public ModelMap editInvite(Long enUU, String userMessage, String enterMessage) throws MyException {
+        if (StringUtils.isEmpty(userMessage) || StringUtils.isEmpty(enterMessage)) {
+            throw new MyException("邀请人或邀请企业信息不能为空");
+        }
+        // 校验用户信息
+        Long userUU = invalidUserInfo(userMessage);
+        Long inviteUU = invalidEnterpriseInfo(enterMessage);
+        String sql = "update sec$enterprises set en_inviteuu = " + inviteUU +
+                ", en_inviteuseruu = " + userUU + " where en_uu = " + enUU;
+        jdbcTemplate.execute(sql);
+        return new ModelMap("content", inviteDao.findOne(enUU));
+    }
+
+    /**
+     * 校验用户信息
+     *
+     * @param userMessage 用户关键字
+     * @return
+     * @throws MyException
+     */
+    private Long invalidUserInfo(String userMessage) throws MyException {
+        UserBaseInfo userBaseInfo = new UserBaseInfo();
+        List<UserBaseInfo> userList = userBaseInfoDao.findByEmail(userMessage.trim());
+        if (userMessage.matches(UU_REGEXP) && !userMessage.matches(TEL_REGEXP)) {
+            userBaseInfo = userBaseInfoDao.findOne(Long.valueOf(userMessage));
+            if (null == userBaseInfo) {
+                throw new MyException(NOT_FOUND_CODE, "未找到关于[" + userMessage + "]的用户信息");
+            }
+        }
+        if (null == userBaseInfo.getUu() && userMessage.matches(EMAIL_REGEXP)) {
+            if (userList.size() > 1) {
+                throw new MyException("[" + userMessage + "]存在多条用户信息,请更新邀请用户信息");
+            } else if (userList.size() == 1) {
+                userBaseInfo = userList.get(0);
+            }
+        }
+        if (null == userBaseInfo.getUu() && userMessage.matches(TEL_REGEXP)) {
+            userList = userBaseInfoDao.findByTel(userMessage.trim());
+            if (userList.size() > 1) {
+                throw new MyException("[" + userMessage + "]存在多条用户信息,请更新邀请用户信息");
+            } else if (userList.size() == 1) {
+                userBaseInfo = userList.get(0);
+            }
+        }
+        if (null == userBaseInfo.getUu()) {
+            userList = userBaseInfoDao.findByName(userMessage.trim());
+            if (userList.size() > 1) {
+                throw new MyException("[" + userMessage + "]存在多条用户信息,请更新邀请用户信息");
+            } else if (userList.size() == 1) {
+                userBaseInfo = userList.get(0);
+            }
+        }
+        if (null == userBaseInfo.getUu()) {
+            throw new MyException(NOT_FOUND_CODE, "未找到关于[" + userMessage + "]的用户信息");
+        }
+        return userBaseInfo.getUu();
+    }
+
+    /**
+     * 校验企业信息
+     *
+     * @param enterMessage 企业关键字
+     * @return
+     */
+    private Long invalidEnterpriseInfo(String enterMessage) throws MyException {
+        EnterpriseBaseInfo baseInfo = new EnterpriseBaseInfo();
+        if (enterMessage.matches(UU_REGEXP)) {
+            baseInfo = enterpriseBaseInfoDao.findOne(Long.valueOf(enterMessage));
+            if (null == baseInfo.getUu()) {
+                throw new MyException(NOT_FOUND_CODE, "未找到关于[" + enterMessage + "]的企业信息");
+            }
+        }
+        if (null == baseInfo.getUu()) {
+            List<EnterpriseBaseInfo> baseInfoList = enterpriseBaseInfoDao.findByEnBussinessCode(enterMessage.trim());
+            if (baseInfoList.size() > 1) {
+                throw new MyException("[" + enterMessage + "]存在多条企业信息,请更新邀请企业信息");
+            } else if (baseInfoList.size() == 1) {
+                baseInfo = baseInfoList.get(0);
+            }
+            if (null == baseInfo.getUu()) {
+                baseInfoList = enterpriseBaseInfoDao.findByEnName(enterMessage.trim());
+                if (baseInfoList.size() > 1) {
+                    throw new MyException("[" + enterMessage + "]存在多条企业信息,请更新邀请企业信息");
+                } else if (baseInfoList.size() == 1) {
+                    baseInfo = baseInfoList.get(0);
+                }
+            }
+        }
+        if (null == baseInfo.getUu()) {
+            throw new MyException("未找到关于[" + enterMessage + "]的企业信息");
+        }
+        return baseInfo.getUu();
+    }
+
+    /**
+     * 清除邀请记录
+     *
+     * @param enUU 企业UU
+     */
+    @Override
+    public void deleteByUU(Long enUU) {
+        String sql = "update sec$enterprises set en_inviteuu = null, en_inviteuseruu = null where en_uu = " + enUU;
+        jdbcTemplate.execute(sql);
+    }
 }

+ 57 - 0
src/main/java/com/uas/platform/b2bManage/support/MyException.java

@@ -0,0 +1,57 @@
+package com.uas.platform.b2bManage.support;
+
+/**
+ * 自定义异常
+ *
+ * @author hejq
+ * @date 2018-07-12 20:07
+ */
+public class MyException extends RuntimeException {
+
+    /**
+     * default serialVersionUID
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 服务器错误
+     */
+    static final String SERVER_CODE = "500";
+
+    /**
+     * 默认异常信息
+     */
+    static final String ERROR_MSG = "程序异常";
+
+    /**
+     * 错误编码
+     */
+     private String errCode = SERVER_CODE;
+
+    /**
+     * 异常信息
+     */
+    private String errMsg = ERROR_MSG;
+
+    /**
+     * 自定义异常信息
+     *
+     * @param message 异常描述
+     */
+    public MyException(String message) {
+        super(message);
+        this.errMsg = message;
+    }
+
+    /**
+     * 自定义异常信息
+     *
+     * @param errCode 编号
+     * @param message 描述
+     */
+    public MyException(String errCode, String message) {
+        super(message);
+        this.errCode = errCode;
+        this.errMsg = message;
+    }
+}

+ 46 - 3
src/main/webapp/WEB-INF/views/normal/inviteList.html

@@ -74,6 +74,30 @@
         float: right;
         margin-left: 20px;
     }
+
+    .modal-dialog .modal-header {
+        height: 45px;
+    }
+    .modal-dialog .modal-body {
+        height: 175px;
+    }
+    .modal-dialog .modal-footer {
+        height: 60px;
+        margin-top: -25px;
+    }
+    .modal-body input {
+        border-bottom: #dccaca 1px solid !important;
+        height: 34px;
+        line-height: 34px;
+        border: none;
+        width: 400px;
+        margin-left: 30px;
+        text-align: left;
+        color: #1f1f1f;
+    }
+    .modal-body label {
+        width: 100px;
+    }
 </style>
 <div id="loadingDiv">
 	<div id="loadingImg">
@@ -142,6 +166,7 @@
             <th class="text-center" width="50">联系人</th>
             <th class="text-center" width="50">物料数</th>
             <th class="text-center" width="100">上传时间</th>
+            <th class="text-center" width="50">编辑</th>
 		</thead>
         <tbody id="inviteList-body">
         </tbody>
@@ -152,15 +177,33 @@
 <!-- section end -->
 
 <!-- 参数详情 -->
-<div class="modal fade" id="paraDetail" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
+<div class="modal fade" id="inviteInfo" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
     <div class="modal-dialog">
         <div class="modal-content" id="para-main">
             <div class="modal-header" id="para-title">
             </div>
-            <div class="modal-body" id="para-content">
-                <!--<p id="para-content" readonly placeholder="暂无详情"></p>-->
+            <div class="modal-body">
+                <table>
+                    <tbody>
+                    <tr>
+                        <td><label class="text-right">企业名称</label></td>
+                        <td><input type="text" autocomplete="off" id="in_name" readonly></td>
+                    </tr>
+                    <tr>
+                        <td><label class="text-right">邀请企业</label></td>
+                        <td><input type="text" autocomplete="off" id="in_inviteName"></td>
+                    </tr>
+                    <tr>
+                        <td><label class="text-right">邀请人</label></td>
+                        <td><input type="text" autocomplete="off" id="in_inviteUserName"></td>
+                    </tr>
+                    </tbody>
+                </table>
             </div>
             <div class="modal-footer">
+                <a type="button" class="btn btn-success" data-dismiss="modal" id="okay">
+                    确认
+                </a>
                 <a type="button" class="btn btn-default" data-dismiss="modal">
                     关闭
                 </a>

BIN
src/main/webapp/resources/images/calendar.png


+ 83 - 5
src/main/webapp/resources/js/common/invite.js

@@ -43,11 +43,16 @@ function getinviteList(count, page, keyword) {
             for (var i = 0; i < inviteList.length; i++) {
                 var trow = getDataRow(inviteList[i], i); //定义一个方法,返回tr数据
                 tbody.appendChild(trow);
-                // 查询错误详情
+                // 编辑
                 (function(i) {
-                    $("#para_detail_" + inviteList[i].id ).click(function () {
-                        getPara(inviteList[i].id, inviteList[i].enName, inviteList[i].url);
-                        $('#loadingDiv').show();
+                    $("#edit_" + inviteList[i].uu).click(function () {
+                        editInfo(inviteList[i]);
+                    });
+                })(i);
+                // 删除
+                (function(i) {
+                    $("#delete_" + inviteList[i].uu).click(function () {
+                        deleteInfo(inviteList[i].uu);
                     });
                 })(i);
             }
@@ -90,6 +95,63 @@ function getinviteList(count, page, keyword) {
     })
 }
 
+/**
+ * 编辑
+ *
+ * @param invite 邀请信息
+ */
+var uu = null;
+function editInfo(invite) {
+    $('#para-title').empty();
+    $("<p style='font-size: 16px; font-weight: bold'>").text(invite.enName).appendTo("#para-title");
+    $('#inviteInfo').modal('show');
+    $("#in_name").val(invite.enName);
+    $("#in_inviteName").val(invite.inviteEnName);
+    $("#in_inviteUserName").val(invite.inviteUserName);
+    uu = invite.uu;
+}
+
+/**
+ * 清除邀请记录
+ *
+ * @param uu uu号
+ */
+function deleteInfo(enUU) {
+    $.ajax('invite/delete/' + enUU, {
+        method: 'POST',
+        async: false,
+        success: function(data) {
+            if (data.success) {
+                alert(data.content);
+                getinviteList(20, 1, $('#keyword').val());
+            }
+        },
+        error: function (error) {
+           alert('清除失败');
+        }
+    });
+}
+/**
+ * 确定修改
+ */
+$('#okay').click(function () {
+    var data = { enUU: uu, userMessage: $('#in_inviteUserName').val(), enterMessage: $('#in_inviteName').val()};
+    $.ajax('invite/edit', {
+        data: data,
+        method: 'POST',
+        async: false,
+        success: function(data) {
+            if (data.content) {
+                alert('更新成功');
+                getinviteList(20, 1, $('#keyword').val());
+            }
+        },
+        error: function (error) {
+            alert('更新失败');
+        }
+    });
+})
+
 /**
  * 导出数据
  */
@@ -156,12 +218,28 @@ function getDataRow(invite, i) {
     countCell.innerHTML = invite.productCount;
     row.appendChild(countCell);
 
-    // 物料
+    // 物料最近上传时间
     var prodDateCell = document.createElement('td');
     prodDateCell.setAttribute("class", "text-center");
     prodDateCell.innerHTML = invite.lastProductDate == null ? '-' : formatDateTime(invite.lastProductDate);
     row.appendChild(prodDateCell);
 
+    // 编辑按钮
+    var handleCell = document.createElement('td'); //msg
+    handleCell.setAttribute("class", "text-center");
+    var editButton = document.createElement("button");
+    editButton.setAttribute("class", "btn btn-info btn-sm");
+    editButton.setAttribute("id", 'edit_' + invite.uu);
+    editButton.innerHTML = '编辑';
+    handleCell.appendChild(editButton);
+    var deleteButton = document.createElement("button");
+    deleteButton.setAttribute("class", "btn btn-danger btn-sm");
+    deleteButton.setAttribute("id", 'delete_' + invite.uu);
+    deleteButton.setAttribute("style", "margin-left: 5px");
+    deleteButton.innerHTML = '清除';
+    handleCell.appendChild(deleteButton);
+    row.appendChild(handleCell);
+
     return row;
 }