Browse Source

新增角色,机构等部分重要字段校验

LiTaohong 6 years ago
parent
commit
19d10ead73

+ 8 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/base/user/UserDO.java

@ -56,6 +56,14 @@ public class UserDO extends UuidIdentityEntityWithOperator {
    //登陆失败次数
    private Integer loginFailureCount;
    public UserDO(){}
    public UserDO(String username,String password,String mobile){
        this.username = username;
        this.password = password;
        this.mobile = mobile;
    }
    @Column(name = "username", nullable = false)
    public String getUsername() {
        return username;

+ 2 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/base/BaseRequestMapping.java

@ -135,6 +135,7 @@ public class BaseRequestMapping {
    public static class User extends Basic {
        public static final String PREFIX  = "/user";
        public static final String CHECK_USERNAME = "/check_username";
        public static final String CHECK_MOBILE = "/check_mobile";
    }
    /**
@ -376,6 +377,7 @@ public class BaseRequestMapping {
    public static class BaseOrg extends Basic {
        public static final String PREFIX  = "/baseOrg";
        public static final String baseInfoList  = "/baseInfoList";
        public static final String check_code  = "/check_code";
    }

+ 13 - 1
sql/init.sql

@ -752,4 +752,16 @@ create table `base_role_module`
  `module_id` varchar(50) not null COMMENT '业务模块id',
  primary key (id)
)
  ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='业务模块角色表';
  ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='业务模块角色';
-- 机构区域树形结构表
drop table IF EXISTS `org_tree`;
create table `org_tree`
(
  `id` int(11) NOT NULL AUTO_INCREMENT  COMMENT '表id,自增长',
  `parent_code` varchar(50) not null COMMENT '父级行政区域code',
  `code` varchar(100) DEFAULT NULL COMMENT '行政区域code',
  `name` varchar(50) not null COMMENT '行政区域名称',
  primary key (id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='机构区域树形结构';

+ 2 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/org/BaseOrgDao.java

@ -44,4 +44,6 @@ public interface BaseOrgDao extends PagingAndSortingRepository<BaseOrgDO, String
    @Query("select new BaseOrgDO(provinceCode,provinceName,cityCode,cityName,townCode,townName,code,name) from BaseOrgDO")
    List<BaseOrgDO> findOrgByArea();
    boolean existsByCode(String code);
}

+ 8 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/user/UserDao.java

@ -13,4 +13,12 @@ import java.util.List;
public interface UserDao extends PagingAndSortingRepository<UserDO, String>, JpaSpecificationExecutor<UserDO> {
    List<UserDO> findByEnabled(boolean enabled);
    UserDO findByMobile(String mobile);
    UserDO findById(String id);
    boolean existsByMobile(String mobile);
    boolean existsByUsername(String username);
}

+ 22 - 4
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/org/BaseOrgEndpoint.java

@ -1,6 +1,8 @@
package com.yihu.jw.base.endpoint.org;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.base.service.org.BaseOrgService;
import com.yihu.jw.base.util.ConstantUtils;
import com.yihu.jw.restmodel.base.org.BaseOrgVO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ListEnvelop;
@ -13,6 +15,7 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -40,12 +43,16 @@ public class BaseOrgEndpoint extends EnvelopRestEndpoint {
    @PostMapping(value = BaseRequestMapping.BaseOrg.CREATE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建")
    public ObjEnvelop<BaseOrgVO> create(
    public Envelop create(
            @ApiParam(name = "json_data", value = "Json数据", required = true)
            @RequestBody String jsonData) throws Exception {
        BaseOrgDO baseOrg = toEntity(jsonData, BaseOrgDO.class);
        baseOrg = baseOrgService.save(baseOrg);
        return success(baseOrg, BaseOrgVO.class);
        JSONObject jsonObject = JSONObject.parseObject(jsonData);
        BaseOrgDO baseOrg = toEntity(jsonObject.getJSONObject("org").toJSONString(), BaseOrgDO.class);
        String  msg = baseOrgService.createOrUpdateOrg(baseOrg,jsonObject.getJSONObject("admin"));
        if(StringUtils.endsWithIgnoreCase(msg, ConstantUtils.SUCCESS)){
            return success(msg);
        }
        return failed(msg);
    }
    @PostMapping(value = BaseRequestMapping.BaseOrg.DELETE)
@ -121,4 +128,15 @@ public class BaseOrgEndpoint extends EnvelopRestEndpoint {
        return success(list);
    }
    @GetMapping(value = BaseRequestMapping.BaseOrg.check_code)
    @ApiOperation(value = "检查代码是否可用(message=1代表可用,message=0代表不可用)")
    public Envelop checkCode (
            @ApiParam(name = "code", value = "机构代码", required = true)
            @RequestParam(value = "code", required = false) String code) throws Exception {
        if (baseOrgService.existCode(code)) {
            return success("1");
        } else {
            return success("0");
        }
    }
}

+ 13 - 1
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/user/UserEndpoint.java

@ -98,7 +98,19 @@ public class UserEndpoint extends EnvelopRestEndpoint {
    public Envelop checkName (
            @ApiParam(name = "username", value = "用户名", required = true)
            @RequestParam(value = "username", required = false) String username) throws Exception {
        if (userService.search("username=" + username).size() == 0) {
        if (userService.existUserName(username)) {
            return success("1");
        } else {
            return success("0");
        }
    }
    @GetMapping(value = BaseRequestMapping.User.CHECK_MOBILE)
    @ApiOperation(value = "检查手机号是否可用(message=1代表可用,message=0代表不可用)")
    public Envelop checkMobile (
            @ApiParam(name = "mobile", value = "手机号", required = true)
            @RequestParam(value = "mobile", required = false) String mobile) throws Exception {
        if (userService.existMobile(mobile)) {
            return success("1");
        } else {
            return success("0");

+ 71 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/service/org/BaseOrgService.java

@ -7,12 +7,20 @@ import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
import com.google.gson.JsonObject;
import com.yihu.jw.base.dao.org.BaseOrgDao;
import com.yihu.jw.base.dao.org.OrgTreeDao;
import com.yihu.jw.base.dao.user.UserDao;
import com.yihu.jw.base.dao.user.UserRoleDao;
import com.yihu.jw.base.service.org.tree.SimpleTree;
import com.yihu.jw.base.service.org.tree.SimpleTreeNode;
import com.yihu.jw.base.service.org.tree.Tree;
import com.yihu.jw.base.service.org.tree.TreeNode;
import com.yihu.jw.base.service.user.UserRoleService;
import com.yihu.jw.base.service.user.UserService;
import com.yihu.jw.base.util.ConstantUtils;
import com.yihu.jw.entity.base.user.UserDO;
import com.yihu.jw.entity.base.user.UserRoleDO;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.mysql.query.BaseJpaService;
import com.yihu.utils.security.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yihu.jw.entity.base.org.BaseOrgDO;
@ -41,6 +49,12 @@ public class BaseOrgService extends BaseJpaService<BaseOrgDO, BaseOrgDao> {
    @Autowired
    private OrgTreeDao orgTreeDao;
    @Autowired
    private UserService userService;
    @Autowired
    private UserRoleService userRoleService;
    /**
@ -72,6 +86,63 @@ public class BaseOrgService extends BaseJpaService<BaseOrgDO, BaseOrgDao> {
        return result;
    }
    /**
     * 新增/修改机构
     * @param baseOrgDO
     * @param orgAdminJson
     */
    public String createOrUpdateOrg(BaseOrgDO baseOrgDO,JSONObject orgAdminJson){
        UserDO userDO = null;
        String mobile = orgAdminJson.getString("mobile");
        String adminName = orgAdminJson.getString("orgAdmin");
        if(StringUtils.isEmpty(mobile)){
            return "paramter for admin is null";
        }
        //id为空表示新增
        if(StringUtils.isEmpty(baseOrgDO.getId())){
            baseOrgDao.save(baseOrgDO);
            //新增用户(管理员)
            userDO = new UserDO();
            userDO.setUsername(adminName);
            userDO.setMobile(mobile);
            userService.register(userDO);
            // 新增用户角色关联关系
            UserRoleDO userRoleDO = new UserRoleDO();
            userRoleDO.setRoleId("");
            userRoleDO.setUserId("");
            userRoleService.save(userRoleDO);
        }else{
            String id = orgAdminJson.getString("id");
            if(StringUtils.isEmpty(id)){
                return "paramter id for admin is null when update";
            }
            baseOrgDao.save(baseOrgDO);
            userDO = userService.findById(id);
            //没有修改就不保存
            if(StringUtils.endsWithIgnoreCase(adminName,userDO.getUsername()) && StringUtils.endsWithIgnoreCase(mobile,userDO.getMobile())){
                return ConstantUtils.SUCCESS;
            }
            userDO.setUsername(adminName);
            userDO.setMobile(mobile);
            userService.save(userDO);
        }
        return ConstantUtils.SUCCESS;
    }
    /**
     * 判断机构代码是否存在
     * @param code
     * @return
     */
    public Boolean existCode(String code){
        if(StringUtils.isEmpty(code)) {
            return null;
        }
        return baseOrgDao.existsByCode(code);
    }
    /**
     * 构建机构区域树形结构

+ 18 - 22
svr/svr-base/src/main/java/com/yihu/jw/base/service/org/OrgTree.java

@ -1,49 +1,47 @@
package com.yihu.jw.base.service.org;
import com.yihu.jw.base.service.org.tree.TreeNode;
import com.yihu.jw.entity.IntegerIdentityEntity;
public class OrgTree implements TreeNode {
    private Integer id;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(name = "org_tree")
public class OrgTree extends IntegerIdentityEntity implements TreeNode {
    private String code;
    private String parentCode;
    private String name;
    private Integer orderNum;
    public OrgTree(){}
    public OrgTree(String code, String parentCode, String name, Integer orderNum){
    public OrgTree(String code, String parentCode, String name){
        this.code = code;
        this.parentCode = parentCode;
        this.name = name;
        this.orderNum = orderNum;
    }
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    @Override
    public String getNodeId() {
    public String extractNodeId() {
        return this.code;
    }
    @Override
    public String getNodeName() {
    public String extractNodeName() {
        return this.name;
    }
    @Override
    public String getNodeParentId() {
    public String extractNodeParentId() {
        return this.parentCode;
    }
    @Override
    public Integer getOrderNum() {
        return this.orderNum;
    public Integer extractOrderNum() {
        return null;
    }
    @Column(name = "code", nullable = false)
    public String getCode() {
        return code;
    }
@ -52,6 +50,7 @@ public class OrgTree implements TreeNode {
        this.code = code;
    }
    @Column(name = "parent_code", nullable = false)
    public String getParentCode() {
        return parentCode;
    }
@ -60,6 +59,7 @@ public class OrgTree implements TreeNode {
        this.parentCode = parentCode;
    }
    @Column(name = "name", nullable = false)
    public String getName() {
        return name;
    }
@ -68,8 +68,4 @@ public class OrgTree implements TreeNode {
        this.name = name;
    }
    public void setOrderNum(Integer orderNum) {
        this.orderNum = orderNum;
    }
}

+ 4 - 4
svr/svr-base/src/main/java/com/yihu/jw/base/service/org/tree/SimpleTreeNode.java

@ -29,10 +29,10 @@ public class SimpleTreeNode {
    private List<SimpleTreeNode> allChildren = new ArrayList<>();
    public SimpleTreeNode(TreeNode obj){
        this.nodeId = obj.getNodeId();
        this.nodeName = obj.getNodeName();
        this.parentNodeId = obj.getNodeParentId();
        this.orderNum = obj.getOrderNum();
        this.nodeId = obj.extractNodeId();
        this.nodeName = obj.extractNodeName();
        this.parentNodeId = obj.extractNodeParentId();
        this.orderNum = obj.extractOrderNum();
    }
    public void addChild(SimpleTreeNode treeNode){
        this.children.add(treeNode);

+ 4 - 4
svr/svr-base/src/main/java/com/yihu/jw/base/service/org/tree/TreeNode.java

@ -1,8 +1,8 @@
package com.yihu.jw.base.service.org.tree;
public interface TreeNode {
    String getNodeId();
    String getNodeName();
    String getNodeParentId();
    Integer getOrderNum();
    String extractNodeId();
    String extractNodeName();
    String extractNodeParentId();
    Integer extractOrderNum();
}

+ 1 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/service/user/UserRoleService.java

@ -11,4 +11,5 @@ import org.springframework.stereotype.Service;
 */
@Service
public class UserRoleService extends BaseJpaService<UserRoleDO, UserRoleDao> {
}

+ 45 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/service/user/UserService.java

@ -35,6 +35,49 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
        return userDao.save(userDO);
    }
    /**
     * 根据用户手机号查找(手机号为登录账号)
     * @param mobile
     * @return
     */
    public UserDO findByMobile(String mobile) {
        return userDao.findByMobile(mobile);
    }
    /**
     * 根据id查找用户
     * @param id
     * @return
     */
    public UserDO findById(String id) {
        return userDao.findById(id);
    }
    /**
     * 判断手机号是否存在
     * @param mobile
     * @return
     */
    public Boolean existMobile(String mobile){
        if(StringUtils.isEmpty(mobile)) {
            return null;
        }
        return userDao.existsByMobile(mobile);
    }
    /**
     * 判断手机号是否存在
     * @param username
     * @return
     */
    public Boolean existUserName(String username){
        if(StringUtils.isEmpty(username)) {
            return null;
        }
        return userDao.existsByUsername(username);
    }
    /**
     * 用户管理,获取用户基本信息列表
     * @param name 模糊查询
@ -46,4 +89,6 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
        List<Map<String,Object>> result = new ArrayList<>();
        return result;
    }
}