klxedu / blog

2 stars 0 forks source link

用户字段扩展方案 #21

Open songhuiqing88 opened 7 years ago

songhuiqing88 commented 7 years ago

注册用户字段扩展

数据库

在用户主表中增加要扩展的字段,例如:增加从业年份字段(EMPLOY_YEAR),SQL如下。

ALTER TABLE `gt_user` ADD COLUMN `EMPLOY_YEAR`  varchar(50)

代码扩展

dao扩展

  1. 覆盖org.gtiles.components.userinfo.baseuser.extension.dao.IUserExtensionDao.xml。
  2. 调整resultMap、queryFields、sqlValue、sqlQuery、updateSetSql,增加扩展字段,代码如下。
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper
    PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="org.gtiles.components.userinfo.baseuser.extension.dao.IUserExtensionDao">
    <!-- BaseUserBean 对应字段映射 -->
    <resultMap type="org.gtiles.components.userinfo.baseuser.bean.BaseUserBean" id="baseUser">
    <!-- ...产品内容 -->
    <result column="EMPLOY_YEAR" property="employYear"/>
    </resultMap>
    <!-- 用户表字段 -->
    <sql id="queryFields">
    <!-- ...产品内容 -->
    EMPLOY_YEAR
    </sql>
    <!-- 用户对象属性 -->
    <sql id="sqlValue">
    <!-- ...产品内容 -->
    #{employYear}
    </sql>
    <!-- 用户通用查询条件,用户ID in的查询条件在产品中进行了实现 -->
    <sql id="sqlQuery">
    <!-- ...产品内容 -->
    <if test="query.queryEmployYear!=null and query.queryEmployYear!=''">
    and u.EMPLOY_YEAR = #{query.queryEmployYear}
    </if>
    </sql>
    <!-- 用户更新SQL -->
    <sql id="updateSetSql">
    <!-- ...产品内容 -->
    <if test="employYear !=null and employYear !=''">EMPLOY_YEAR = #{employYear}</if>
    </sql>
    </mapper>

    结果对象扩展

    覆盖 org.gtiles.components.userinfo.baseuser.bean.BaseUserBean

    public class BaseUserBean extends UserResult{
    public BaseUserBean() {
    super();
    }
    public BaseUserBean(BaseUserEntity baseUserEntity) {
    super(baseUserEntity);
    }
    // 增加扩展字段及getter and setter
    private String employYear;
    public String getEmployYear() {
    return employYear;
    }
    public void setEmployYear(String employYear) {
    this.employYear = employYear;
    }
    }

    查询对象扩展

    覆盖 org.gtiles.components.userinfo.baseuser.bean.BaseUserQuery

    public class BaseUserQuery extends BaseUserAbstractQuery<BaseUserBean> {
    //增加扩展字段查询及gettter setter
    private String queryEmployYear;
    public String getQueryEmployYear() {
    return queryEmployYear;
    }
    public void setQueryEmployYear(String queryEmployYear) {
    this.queryEmployYear = queryEmployYear;
    }
    }

    界面扩展

    覆盖org.gtiles.components.userinfo.workbench.userinfo.list.html,在html中增加要扩展的内容。

    <option value="queryEmployYear">从业年份</option><!--查询, 增加扩展 -->
    <th class="font-4">从业年份</th><!-- 列表增加扩展字段 -->
    <td class="text-ellipsis">{{row.employYear}}</td><!-- 增加扩展字段 -->
    <!--表单增加扩展字段-->
    <div class="form-group">
    <label class="col-sm-2 control-label"><span class="text-danger" ng-if="!isFormDisabled">*</span>从业年份</label>
    <div class="col-sm-10">
    <input name="employYear" ng-model="baseUserInfo.employYear" type="text" class="form-control" validation="required|max_len:18" placeholder="请输入正确的从业年份">
    </div>
    </div>

    扩展界面如图: baseuser-list baseuser_form

songhuiqing88 commented 7 years ago

机构用户字段扩展方案

数据库

在用户主表中增加要扩展的字段,例如:增加从业年份字段(EMPLOY_YEAR),SQL如下。

ALTER TABLE `gt_user` ADD COLUMN `EMPLOY_YEAR`  varchar(50)

代码扩展

dao扩展

  1. 覆盖org.gtiles.components.userinfo.baseuser.extension.dao.IUserExtensionDao.xml。 调整resultMap、queryFields、sqlValue、updateSetSql,增加扩展字段,代码如下。
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper
    PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="org.gtiles.components.userinfo.baseuser.extension.dao.IUserExtensionDao">
    <!-- BaseUserBean 对应字段映射 -->
    <resultMap type="org.gtiles.components.userinfo.baseuser.bean.BaseUserBean" id="baseUser">
    <!-- ...产品内容 -->
    <result column="EMPLOY_YEAR" property="employYear"/>
    </resultMap>
    <!-- 用户表字段 -->
    <sql id="queryFields">
    <!-- ...产品内容 -->
    EMPLOY_YEAR
    </sql>
    <!-- 用户对象属性 -->
    <sql id="sqlValue">
    <!-- ...产品内容 -->
    #{employYear}
    </sql>
    <!-- 用户通用查询条件,用户ID in的查询条件在产品中进行了实现 -->
    <sql id="sqlQuery">
    <!-- ...产品内容 -->
    </sql>
    <!-- 用户更新SQL -->
    <sql id="updateSetSql">
    <!-- ...产品内容 -->
    <if test="employYear !=null and employYear !=''">EMPLOY_YEAR = #{employYear}</if>
    </sql>
    </mapper>
  2. 覆盖org.gtiles.components.organization.orguser.extension.dao.IOrgUserExtensionDao.xml,增加对应的查询条件。 orguserxml

    结果对象扩展

    覆盖 org.gtiles.components.userinfo.baseuser.bean.BaseUserBean

    public class BaseUserBean extends UserResult{
    public BaseUserBean() {
    super();
    }
    public BaseUserBean(BaseUserEntity baseUserEntity) {
    super(baseUserEntity);
    }
    // 增加扩展字段及getter and setter
    private String employYear;
    public String getEmployYear() {
    return employYear;
    }
    public void setEmployYear(String employYear) {
    this.employYear = employYear;
    }
    }

    查询对象扩展

    覆盖 org.gtiles.components.organization.orguser.bean.OrgUserQuery

    public class BaseUserQuery extends BaseUserAbstractQuery<BaseUserBean> {
    //增加扩展字段查询及gettter setter
    private String queryEmployYear;
    public String getQueryEmployYear() {
    return queryEmployYear;
    }
    public void setQueryEmployYear(String queryEmployYear) {
    this.queryEmployYear = queryEmployYear;
    }
    }

    界面扩展

    覆盖org.gtiles.components.organization.workbench.organizationuser.organizationuser.html,在html中增加要扩展的内容。

    <option value="queryEmployYear">从业年份</option><!--查询, 增加扩展 -->
    <th class="font-4">从业年份</th><!-- 列表增加扩展字段 -->
    <td class="text-ellipsis">{{row.employYear}}</td><!-- 增加扩展字段 -->
    <!--表单增加扩展字段-->
    <div class="form-group">
    <label class="col-sm-2 control-label"><span class="text-danger" ng-if="!isFormDisabled">*</span>从业年份</label>
    <div class="col-sm-10">
    <input name="employYear" ng-model="baseUserInfo.employYear" type="text" class="form-control" validation="required|max_len:18" placeholder="请输入正确的从业年份">
    </div>
    </div>

    扩展界面如图: list form

songhuiqing88 commented 7 years ago

管理员用户字段扩展

数据库

在用户主表中增加要扩展的字段,例如:增加位置字段(LOCATION),SQL如下。

ALTER TABLE `gt_swb_user` ADD COLUMN `LOCATION`  varchar(255) NULL ;

代码扩展

dao扩展

  1. 覆盖org.gtiles.components.securityworkbench.extension.dao.ISwbUserExtensionDao.xml。
  2. 调整resultMap、queryFields、sqlValue、sqlQuery、updateSetSql,增加扩展字段,代码如下。
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper
    PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="org.gtiles.components.securityworkbench.extension.dao.ISwbUserExtensionDao">
    <resultMap type="org.gtiles.components.securityworkbench.bean.SwbUserEntity" id="swbUser_resultMap">
    <!-- ...产品内容 -->
    <result column="LOCATION" property="location"/>
    </resultMap>
    <sql id="filed_list">
    <!-- ...产品内容 -->,LOCATION
    </sql>
    <sql id="value_list">
    <!-- ...产品内容 -->,#{location}
    </sql>
    <sql id="update_set">
    <!-- ...产品内容 -->
    <if test="activeState!=null">LOCATION = #{location}</if>
    </sql>
    <sql id="pagelist_query">
    <!-- ...产品内容 -->
    <if test="queryLocation!=null and queryLocation!=''">and LOCATION=#{queryLocation}</if>
    </sql>
    </mapper>

    结果对象扩展

    覆盖 org.gtiles.components.securityworkbench.bean.SwbUserEntity

    public class SwbUserEntity extends SwbUserBase{
    private String location;
    public String getLocation() {
    return location;
    }
    public void setLocation(String location) {
    this.location = location;
    }
    }

    查询对象扩展

    覆盖 org.gtiles.components.securityworkbench.bean.SwbUserQuery

    public class SwbUserQuery extends SwbUserAbstractQuery<SwbUserEntity> {
    private String queryLocation;
    public String getQueryLocation() {
    return queryLocation;
    }
    public void setQueryLocation(String queryLocation) {
    this.queryLocation = queryLocation;
    }
    }

    界面扩展

    界面扩展包括:分级权限管理界面及不带分级权限界面调整。具体界面修改方式就不再赘述了,附覆盖文件路径。

    • 带分级权限功能调整,请覆盖 org.gtiles.components.organization.workbench.organizationswbuser.organizationswbuser.html
    • 不带分级权限功能调整,请覆盖 org.gtiles.components.securityworkbench.workbench.swbuser.list.html