From 510b40573ae09e4fa1a7064766e5cd202caa8457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=93=E7=84=B1?= Date: Wed, 31 Jul 2019 01:49:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E9=83=A8=E9=97=A8=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- .../controller/BssDeptController.java | 1 - .../controller/BssPlatformController.java | 34 +++++++++---------- .../admin/system/validator/UserValid.java | 4 +++ .../templates/business/dept/index.html | 2 -- .../templates/business/platform/add.html | 2 +- .../com/cwhelp/common/enums/ResultEnum.java | 7 ++++ .../modules/business/domain/BssPlatform.java | 4 +++ .../repository/BssPlatformRepository.java | 6 +++- .../business/service/BssPlatformService.java | 5 +++ .../service/impl/BssPlatformServiceImpl.java | 18 ++++++++++ .../cwhelp/modules/system/domain/User.java | 4 ++- .../repository/ActionLogRepository.java | 2 +- .../system/repository/BaseRepository.java | 4 +-- .../system/repository/DeptRepository.java | 8 ++--- .../system/repository/DictRepository.java | 4 +-- .../system/repository/MenuRepository.java | 14 ++++---- .../system/repository/RoleRepository.java | 14 ++++---- .../system/repository/UploadRepository.java | 2 +- .../system/repository/UserRepository.java | 8 ++--- 20 files changed, 93 insertions(+), 53 deletions(-) diff --git a/.gitignore b/.gitignore index a91e0dd..fabd4e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /.idea -/upload \ No newline at end of file +/upload +**/target \ No newline at end of file diff --git a/admin/src/main/java/com/cwhelp/admin/business/controller/BssDeptController.java b/admin/src/main/java/com/cwhelp/admin/business/controller/BssDeptController.java index ad60ec4..2e62d00 100644 --- a/admin/src/main/java/com/cwhelp/admin/business/controller/BssDeptController.java +++ b/admin/src/main/java/com/cwhelp/admin/business/controller/BssDeptController.java @@ -27,7 +27,6 @@ import java.util.List; * @author yan.y * @date 2019/07/29 */ -@Controller("bssDeptController") @RequestMapping("/bss/dept") public class BssDeptController { diff --git a/admin/src/main/java/com/cwhelp/admin/business/controller/BssPlatformController.java b/admin/src/main/java/com/cwhelp/admin/business/controller/BssPlatformController.java index 1d597cd..f4ba1e3 100644 --- a/admin/src/main/java/com/cwhelp/admin/business/controller/BssPlatformController.java +++ b/admin/src/main/java/com/cwhelp/admin/business/controller/BssPlatformController.java @@ -1,6 +1,7 @@ package com.cwhelp.admin.business.controller; import com.cwhelp.admin.business.validator.BssPlatformValid; +import com.cwhelp.common.enums.ResultEnum; import com.cwhelp.common.enums.StatusEnum; import com.cwhelp.common.utils.EntityBeanUtil; import com.cwhelp.common.utils.ResultVoUtil; @@ -58,24 +59,6 @@ public class BssPlatformController { return "/business/platform/index"; } - - /** - * 部门数据列表 - */ - @GetMapping("/list") - @RequiresPermissions(value = {"bss:platform:index", "bss:dept:index"}, logical = Logical.OR) - @ResponseBody - public ResultVo list(BssPlatform bssPlatform) { - // 创建匹配器,进行动态查询匹配 - ExampleMatcher matcher = ExampleMatcher.matching() - .withMatcher("name", match -> match.contains()); - // 获取部门列表 - Example example = Example.of(bssPlatform, matcher); - Sort sort = new Sort(Sort.Direction.DESC, "createDate"); - List list = bssPlatformService.getListByExample(example, sort); - return ResultVoUtil.success(list); - } - /** * 跳转到添加页面 */ @@ -108,6 +91,21 @@ public class BssPlatformController { BssPlatform beBssPlatform = bssPlatformService.getById(bssPlatform.getId()); EntityBeanUtil.copyProperties(beBssPlatform, bssPlatform); } + // 校验手机号 + boolean repeatByContactTel = bssPlatformService.repeatByContactTel(bssPlatform); + if (repeatByContactTel) { + return ResultVoUtil.error(ResultEnum.PLATFORM_EXIST_CONTACT_TEL.getCode(),ResultEnum.PLATFORM_EXIST_CONTACT_TEL.getMessage()); + } + // 校验身份证号 + boolean repeatByContactCard = bssPlatformService.repeatByContactCard(bssPlatform); + if (repeatByContactCard) { + return ResultVoUtil.error(ResultEnum.PLATFORM_EXIST_CONTACT_CARD.getCode(),ResultEnum.PLATFORM_EXIST_CONTACT_CARD.getMessage()); + } + // 校验邮箱 + boolean repeatByEmail = bssPlatformService.repeatByEmail(bssPlatform); + if (repeatByEmail) { + return ResultVoUtil.error(ResultEnum.PLATFORM_EXIST_EMAIL.getCode(),ResultEnum.PLATFORM_EXIST_EMAIL.getMessage()); + } // 保存数据 bssPlatformService.save(bssPlatform); diff --git a/admin/src/main/java/com/cwhelp/admin/system/validator/UserValid.java b/admin/src/main/java/com/cwhelp/admin/system/validator/UserValid.java index 2db3c4d..ab59b93 100644 --- a/admin/src/main/java/com/cwhelp/admin/system/validator/UserValid.java +++ b/admin/src/main/java/com/cwhelp/admin/system/validator/UserValid.java @@ -5,6 +5,7 @@ import lombok.Data; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; import java.io.Serializable; @@ -19,6 +20,9 @@ public class UserValid implements Serializable { @Size(min = 2, message = "用户昵称:请输入至少2个字符") private String nickname; private String confirm; + @Pattern(regexp = "^((17[0-9])|(14[0-9])|(13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$", message = "手机号码格式不正确") + @NotEmpty(message = "联系人电话不能为空") + private String phone; @NotNull(message = "所在部门不能为空") private Dept dept; } diff --git a/admin/src/main/resources/templates/business/dept/index.html b/admin/src/main/resources/templates/business/dept/index.html index bdd4530..66633f1 100644 --- a/admin/src/main/resources/templates/business/dept/index.html +++ b/admin/src/main/resources/templates/business/dept/index.html @@ -44,7 +44,6 @@ - 主键ID 名称 所属 创建时间 @@ -57,7 +56,6 @@ - 主键ID 名称 所属平台 创建时间 diff --git a/admin/src/main/resources/templates/business/platform/add.html b/admin/src/main/resources/templates/business/platform/add.html index b9dacdd..7e3a439 100644 --- a/admin/src/main/resources/templates/business/platform/add.html +++ b/admin/src/main/resources/templates/business/platform/add.html @@ -39,7 +39,7 @@
- +
diff --git a/common/src/main/java/com/cwhelp/common/enums/ResultEnum.java b/common/src/main/java/com/cwhelp/common/enums/ResultEnum.java index 95d57a4..a63bbc3 100644 --- a/common/src/main/java/com/cwhelp/common/enums/ResultEnum.java +++ b/common/src/main/java/com/cwhelp/common/enums/ResultEnum.java @@ -27,6 +27,13 @@ public enum ResultEnum implements ResultInterface { USER_CAPTCHA_ERROR(406, "验证码错误"), USER_PWD_STRENGTH_ERROR(407, "密码强度不够"), + /** + * 平台 + */ + PLATFORM_EXIST_CONTACT_TEL(1001,"联系人手机号码已存在"), + PLATFORM_EXIST_CONTACT_CARD(1002,"联系人证件号码已存在"), + PLATFORM_EXIST_EMAIL(1003,"邮箱已存在"), + /** * 角色问题 */ diff --git a/modules/business/src/main/java/com/cwhelp/modules/business/domain/BssPlatform.java b/modules/business/src/main/java/com/cwhelp/modules/business/domain/BssPlatform.java index 3e7166a..455c539 100644 --- a/modules/business/src/main/java/com/cwhelp/modules/business/domain/BssPlatform.java +++ b/modules/business/src/main/java/com/cwhelp/modules/business/domain/BssPlatform.java @@ -3,7 +3,9 @@ package com.cwhelp.modules.business.domain; import com.cwhelp.common.enums.StatusEnum; import com.cwhelp.common.utils.StatusUtil; import com.cwhelp.modules.system.domain.User; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; import lombok.Data; import org.hibernate.annotations.NotFound; import org.hibernate.annotations.NotFoundAction; @@ -56,6 +58,7 @@ public class BssPlatform implements Serializable { private Date updateDate; // 创建者 @CreatedBy + @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class,property = "@id") @ManyToOne(fetch= FetchType.LAZY) @NotFound(action=NotFoundAction.IGNORE) @JoinColumn(name="create_by") @@ -63,6 +66,7 @@ public class BssPlatform implements Serializable { private User createBy; // 更新者 @LastModifiedBy + @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class,property = "@id") @ManyToOne(fetch=FetchType.LAZY) @NotFound(action=NotFoundAction.IGNORE) @JoinColumn(name="update_by") diff --git a/modules/business/src/main/java/com/cwhelp/modules/business/repository/BssPlatformRepository.java b/modules/business/src/main/java/com/cwhelp/modules/business/repository/BssPlatformRepository.java index e7e44be..f6a9c1f 100644 --- a/modules/business/src/main/java/com/cwhelp/modules/business/repository/BssPlatformRepository.java +++ b/modules/business/src/main/java/com/cwhelp/modules/business/repository/BssPlatformRepository.java @@ -8,5 +8,9 @@ import com.cwhelp.modules.system.repository.BaseRepository; * @author yan.y * @date 2019/07/28 */ -public interface BssPlatformRepository extends BaseRepository { +public interface BssPlatformRepository extends BaseRepository{ + + BssPlatform findByContactTelAndIdNot(String contactTel,Long id); + BssPlatform findByContactCardAndIdNot(String contactCard,Long id); + BssPlatform findByEmailAndIdNot(String email,Long id); } \ No newline at end of file diff --git a/modules/business/src/main/java/com/cwhelp/modules/business/service/BssPlatformService.java b/modules/business/src/main/java/com/cwhelp/modules/business/service/BssPlatformService.java index 4b6a967..b309076 100644 --- a/modules/business/src/main/java/com/cwhelp/modules/business/service/BssPlatformService.java +++ b/modules/business/src/main/java/com/cwhelp/modules/business/service/BssPlatformService.java @@ -47,4 +47,9 @@ public interface BssPlatformService { * @param sort 排序对象 */ List getListByExample(Example example, Sort sort); + + boolean repeatByContactTel(BssPlatform bssPlatform); + boolean repeatByContactCard(BssPlatform bssPlatform); + boolean repeatByEmail(BssPlatform bssPlatform); + } \ No newline at end of file diff --git a/modules/business/src/main/java/com/cwhelp/modules/business/service/impl/BssPlatformServiceImpl.java b/modules/business/src/main/java/com/cwhelp/modules/business/service/impl/BssPlatformServiceImpl.java index dd67ded..19624e1 100644 --- a/modules/business/src/main/java/com/cwhelp/modules/business/service/impl/BssPlatformServiceImpl.java +++ b/modules/business/src/main/java/com/cwhelp/modules/business/service/impl/BssPlatformServiceImpl.java @@ -75,4 +75,22 @@ public class BssPlatformServiceImpl implements BssPlatformService { public List getListByExample(Example example, Sort sort) { return bssPlatformRepository.findAll(example, sort); } + + @Override + public boolean repeatByContactTel(BssPlatform bssPlatform) { + Long id = bssPlatform.getId() != null ? bssPlatform.getId() : Long.MIN_VALUE; + return bssPlatformRepository.findByContactTelAndIdNot(bssPlatform.getContactTel(), id) != null; + } + + @Override + public boolean repeatByContactCard(BssPlatform bssPlatform) { + Long id = bssPlatform.getId() != null ? bssPlatform.getId() : Long.MIN_VALUE; + return bssPlatformRepository.findByContactCardAndIdNot(bssPlatform.getContactCard(), id) != null; + } + + @Override + public boolean repeatByEmail(BssPlatform bssPlatform) { + Long id = bssPlatform.getId() != null ? bssPlatform.getId() : Long.MIN_VALUE; + return bssPlatformRepository.findByEmailAndIdNot(bssPlatform.getEmail(), id) != null; + } } \ No newline at end of file diff --git a/modules/system/src/main/java/com/cwhelp/modules/system/domain/User.java b/modules/system/src/main/java/com/cwhelp/modules/system/domain/User.java index b56c983..80b8277 100644 --- a/modules/system/src/main/java/com/cwhelp/modules/system/domain/User.java +++ b/modules/system/src/main/java/com/cwhelp/modules/system/domain/User.java @@ -1,10 +1,12 @@ package com.cwhelp.modules.system.domain; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.JsonIgnore; import com.cwhelp.common.enums.StatusEnum; import com.cwhelp.common.utils.StatusUtil; import com.cwhelp.component.excel.annotation.Excel; import com.cwhelp.component.excel.enums.ExcelType; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; import lombok.Getter; import lombok.Setter; import org.hibernate.annotations.SQLDelete; @@ -59,7 +61,7 @@ public class User implements Serializable { @Excel(value = "状态", dict = "DATA_STATUS") private Byte status = StatusEnum.OK.getCode(); - @ManyToOne(fetch=FetchType.EAGER) + @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="dept_id") @JsonIgnore private Dept dept; diff --git a/modules/system/src/main/java/com/cwhelp/modules/system/repository/ActionLogRepository.java b/modules/system/src/main/java/com/cwhelp/modules/system/repository/ActionLogRepository.java index 5959489..d7706f0 100644 --- a/modules/system/src/main/java/com/cwhelp/modules/system/repository/ActionLogRepository.java +++ b/modules/system/src/main/java/com/cwhelp/modules/system/repository/ActionLogRepository.java @@ -12,5 +12,5 @@ public interface ActionLogRepository extends JpaRepository { * @param model 模型(表名) * @param recordId 数据ID */ - public List findByModelAndRecordId(String model, Long recordId); + List findByModelAndRecordId(String model, Long recordId); } diff --git a/modules/system/src/main/java/com/cwhelp/modules/system/repository/BaseRepository.java b/modules/system/src/main/java/com/cwhelp/modules/system/repository/BaseRepository.java index b733cd7..084dc4b 100644 --- a/modules/system/src/main/java/com/cwhelp/modules/system/repository/BaseRepository.java +++ b/modules/system/src/main/java/com/cwhelp/modules/system/repository/BaseRepository.java @@ -20,7 +20,7 @@ public interface BaseRepository extends JpaRepository { * @param id 主键ID * @param status 状态 */ - public T findByIdAndStatus(Long id, Byte status); + T findByIdAndStatus(Long id, Byte status); /** * 批量更新数据状态 @@ -32,5 +32,5 @@ public interface BaseRepository extends JpaRepository { @Modifying @Transactional @Query("update #{#entityName} set status = ?1 where id in ?2 and status <> " + StatusConst.DELETE) - public Integer updateStatus(Byte status, List id); + Integer updateStatus(Byte status, List id); } diff --git a/modules/system/src/main/java/com/cwhelp/modules/system/repository/DeptRepository.java b/modules/system/src/main/java/com/cwhelp/modules/system/repository/DeptRepository.java index 6cad12d..1e1c41a 100644 --- a/modules/system/src/main/java/com/cwhelp/modules/system/repository/DeptRepository.java +++ b/modules/system/src/main/java/com/cwhelp/modules/system/repository/DeptRepository.java @@ -16,20 +16,20 @@ public interface DeptRepository extends BaseRepository { * 查找多个部门 * @param ids id列表 */ - public List findByIdIn(List ids); + List findByIdIn(List ids); /** * 获取排序最大值 * @param pid 父部门ID */ @Query("select max(sort) from Menu m where m.pid = ?1 and m.status <> " + StatusConst.DELETE) - public Integer findSortMax(long pid); + Integer findSortMax(long pid); /** * 根据父ID查找子孙部门 * @param pids pid列表 */ - public List findByPidsLikeAndStatus(String pids, Byte status); + List findByPidsLikeAndStatus(String pids, Byte status); /** * 根据父级部门ID获取本级全部部门 @@ -37,6 +37,6 @@ public interface DeptRepository extends BaseRepository { * @param pid 父部门ID * @param notId 需要排除的部门ID */ - public List findByPidAndIdNot(Sort sort, long pid, long notId); + List findByPidAndIdNot(Sort sort, long pid, long notId); } diff --git a/modules/system/src/main/java/com/cwhelp/modules/system/repository/DictRepository.java b/modules/system/src/main/java/com/cwhelp/modules/system/repository/DictRepository.java index 4f159f7..a4a7d67 100644 --- a/modules/system/src/main/java/com/cwhelp/modules/system/repository/DictRepository.java +++ b/modules/system/src/main/java/com/cwhelp/modules/system/repository/DictRepository.java @@ -12,12 +12,12 @@ public interface DictRepository extends BaseRepository { * @param name 字典标识 * @param status 状态 */ - public Dict findByNameAndStatus(String name, Byte status); + Dict findByNameAndStatus(String name, Byte status); /** * 根据标识查询字典数据,且排查指定ID的字典 * @param name 字典标识 * @param id 字典ID */ - public Dict findByNameAndIdNot(String name, Long id); + Dict findByNameAndIdNot(String name, Long id); } diff --git a/modules/system/src/main/java/com/cwhelp/modules/system/repository/MenuRepository.java b/modules/system/src/main/java/com/cwhelp/modules/system/repository/MenuRepository.java index d4ebc20..03c4d62 100644 --- a/modules/system/src/main/java/com/cwhelp/modules/system/repository/MenuRepository.java +++ b/modules/system/src/main/java/com/cwhelp/modules/system/repository/MenuRepository.java @@ -18,32 +18,32 @@ public interface MenuRepository extends BaseRepository { * 查找多个菜单 * @param ids id列表 */ - public List findByIdIn(List ids); + List findByIdIn(List ids); /** * 查找响应状态的菜单 * @param sort 排序对象 */ - public List findAllByStatus(Sort sort, Byte status); + List findAllByStatus(Sort sort, Byte status); /** * 查询菜单URL * @param url id列表 */ - public Menu findByUrl(String url); + Menu findByUrl(String url); /** * 根据父ID查找子菜单 * @param pids pid列表 */ - public List findByPidsLikeAndStatus(String pids, Byte status); + List findByPidsLikeAndStatus(String pids, Byte status); /** * 获取排序最大值 * @param pid 父菜单ID */ @Query("select max(sort) from Menu m where m.pid = ?1 and m.status <> " + StatusConst.DELETE) - public Integer findSortMax(long pid); + Integer findSortMax(long pid); /** * 根据父级菜单ID获取本级全部菜单 @@ -51,7 +51,7 @@ public interface MenuRepository extends BaseRepository { * @param pid 父菜单ID * @param notId 需要排除的菜单ID */ - public List findByPidAndIdNot(Sort sort, long pid, long notId); + List findByPidAndIdNot(Sort sort, long pid, long notId); /** * 取消菜单与角色之间的关系 @@ -60,5 +60,5 @@ public interface MenuRepository extends BaseRepository { @Modifying @Transactional @Query(value = "DELETE FROM sys_role_menu WHERE menu_id = ?1", nativeQuery = true) - public Integer cancelRoleJoin(Long id); + Integer cancelRoleJoin(Long id); } diff --git a/modules/system/src/main/java/com/cwhelp/modules/system/repository/RoleRepository.java b/modules/system/src/main/java/com/cwhelp/modules/system/repository/RoleRepository.java index d5d26f9..7827020 100644 --- a/modules/system/src/main/java/com/cwhelp/modules/system/repository/RoleRepository.java +++ b/modules/system/src/main/java/com/cwhelp/modules/system/repository/RoleRepository.java @@ -18,34 +18,34 @@ public interface RoleRepository extends BaseRepository { * 查找多个角色 * @param ids id列表 */ - public List findByIdIn(List ids); + List findByIdIn(List ids); /** * 查找相应状态的角色 * @param sort 排序对象 */ - public List findAllByStatus(Sort sort, Byte status); + List findAllByStatus(Sort sort, Byte status); /** * 查询指定用户的角色列表 * @param id 用户ID * @param status 角色状态 */ - public Set findByUsers_IdAndStatus(Long id, Byte status); + Set findByUsers_IdAndStatus(Long id, Byte status); /** * 根据标识查询角色数据,且排查指定ID的角色 * @param name 角色标识 * @param id 角色ID */ - public Role findByNameAndIdNot(String name, Long id); + Role findByNameAndIdNot(String name, Long id); /** * 判断指定的用户是否存在角色 * @param id 用户ID * @param status 角色状态 */ - public Boolean existsByUsers_IdAndStatus(Long id, Byte status); + Boolean existsByUsers_IdAndStatus(Long id, Byte status); /** * 取消角色与用户之间的关系 @@ -54,7 +54,7 @@ public interface RoleRepository extends BaseRepository { @Modifying @Transactional @Query(value = "DELETE FROM sys_user_role WHERE role_id in ?1", nativeQuery = true) - public Integer cancelUserJoin(List ids); + Integer cancelUserJoin(List ids); /** * 取消角色与菜单之间的关系 @@ -63,6 +63,6 @@ public interface RoleRepository extends BaseRepository { @Modifying @Transactional @Query(value = "DELETE FROM sys_role_menu WHERE role_id in ?1", nativeQuery = true) - public Integer cancelMenuJoin(List ids); + Integer cancelMenuJoin(List ids); } diff --git a/modules/system/src/main/java/com/cwhelp/modules/system/repository/UploadRepository.java b/modules/system/src/main/java/com/cwhelp/modules/system/repository/UploadRepository.java index 4e3e9b5..5ef31c3 100644 --- a/modules/system/src/main/java/com/cwhelp/modules/system/repository/UploadRepository.java +++ b/modules/system/src/main/java/com/cwhelp/modules/system/repository/UploadRepository.java @@ -12,6 +12,6 @@ public interface UploadRepository extends JpaRepository { * 查找指定文件sha1记录 * @param sha1 文件sha1值 */ - public Upload findBySha1(String sha1); + Upload findBySha1(String sha1); } diff --git a/modules/system/src/main/java/com/cwhelp/modules/system/repository/UserRepository.java b/modules/system/src/main/java/com/cwhelp/modules/system/repository/UserRepository.java index c4d6b3e..64d94ce 100644 --- a/modules/system/src/main/java/com/cwhelp/modules/system/repository/UserRepository.java +++ b/modules/system/src/main/java/com/cwhelp/modules/system/repository/UserRepository.java @@ -16,7 +16,7 @@ public interface UserRepository extends BaseRepository, JpaSpecifica * @param username 用户名 * @return 用户数据 */ - public User findByUsername(String username); + User findByUsername(String username); /** * 根据用户名查询用户数据,且排查指定ID的用户 @@ -24,16 +24,16 @@ public interface UserRepository extends BaseRepository, JpaSpecifica * @param id 排除的用户ID * @return 用户数据 */ - public User findByUsernameAndIdNot(String username, Long id); + User findByUsernameAndIdNot(String username, Long id); /** * 查找多个相应部门的用户列表 */ - public List findByDept(Dept dept); + List findByDept(Dept dept); /** * 删除多条数据 * @param ids ID列表 */ - public Integer deleteByIdIn(List ids); + Integer deleteByIdIn(List ids); }