踩坑记录_八月篇_1

2018-8-14 星期二

1.部门管理和菜单管理中的初始化表格:当前采用的方法为注释id所在字段列初始化代码

存在问题:
    1. id字段所在列的visible设置不可见无效
    2. 将该字段置于默认单选框{field: 'selectItem', radio: true}上后,发现复选框按钮不存在
    3. 删除初始化列的时候,所影响后面的字段列的align配置

2.用户管理

2.1 添加/修改用户信息的出生日期字段不应该超过当前时间,需要加入出生日期判断逻辑

定位到指定模块User,添加出生日期判断逻辑
坐标:user_info.js
    /*
    * 日期格式化方法
    * */
    Date.prototype.format = function(format) {
        var args = {
            "M+": this.getMonth() + 1,
            "d+": this.getDate(),
            "h+": this.getHours(),
            "m+": this.getMinutes(),
            "s+": this.getSeconds(),
            "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
            "S": this.getMilliseconds()
        };
        if (/(y+)/.test(format))
            format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var i in args) {
            var n = args[i];
            if (new RegExp("(" + i + ")").test(format))
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? n : ("00" + n).substr(("" + n).length));
        }
        return format;
    };

    /*
    * 出生日期与当前时间比对
    * */
    UserInfoDlg.validateBir = function () {
        //获取表单中所填入日期并格式化
        var userBir = new Date(Date.parse(this.get("birthday"))).format("yyyy-MM-dd");
        //获取当前时间并格式化
        var nowTime = new Date().format("yyyy-MM-dd");
        if (nowTime >= userBir) {
            return true;
        } else {
            return false;
        }
    };
    /*
     * 添加用户/编辑用户提交时添加
     **/
    //出生日期判断
    if (!this.validateBir()) {
        Feng.error("请填入正确的出生日期");
        return;
    }

2.2 出生日期添加时采用H+自带的时间组件,原本输入框的type=”date”去除

3.字典管理

3.1 完善字典管理备注字段的使用

1. dict_add.html、dict_edit.html表单内容填充
    <div class="col-sm-12">
        <div class="form-group" id="tipsArea">
            <label class="col-sm-2 control-label">字典备注</label>
            <div class="col-sm-2">
                <input class="form-control" id="tips" type="text">
            </div>
        </div>
    </div>
2. dict_info.js获取字典表单的数据
    初始化对话框加入:tips: '',        
    /**
     * 收集添加字典的数据
     */
    DictInfoDlg.collectData = function () {
        this.clearNullDom();
        var mutiString = "";
        //键值对组合获取
        $("[name='dictItem']").each(function(){
            var num = $(this).find("[name='itemNum']").val();
            var name = $(this).find("[name='itemName']").val();
            mutiString = mutiString + (num + ":" + name + ";");
        });

        this.dictName = $("#dictName").val();
        this.mutiString = mutiString;
        //获取字段备注输入框中的内容
        this.tips = $("#tips").val();

        // console.log(this.dictName)
        // console.log(this.mutiString)
        // console.log(this.tips)
    };
    //添加和编辑表单提交
    //传入字典备注信息
    ajax.set('tips', this.tips);
3. dict_edit.html:注意区分dict和subDicts
    dict:为字典外部类
    subDicts:为内部的键值对,这里后续介绍字典的存储结构。
    //获取字典中的tips字段
    <input class="form-control" id="tips" type="text" value="${dict.tips}">
    //循环遍历内部的键值对组合,并显示到页面上
    @for(item in subDicts){
        <div class="form-group" name="dictItem" id="dictItem${itemLP.index}">
            <label class="col-sm-2 control-label">值</label>
            <div class="col-sm-2">
                <input class="form-control" type="text" name="itemNum" value="${item.num}">
            </div>
            <label class="col-sm-2 control-label" style="width: 8%;">名称</label>
            <div class="col-sm-2">
                <input class="form-control" type="text" name="itemName" value="${item.name}">
            </div>
            <div class="col-sm-4">
                <#button btnCss="danger" name="删除" id="cancel" icon="fa-remove" clickFun="DictInfoDlg.deleteItem(event)"/>
           </div>
        </div>
   @}
4. DictServiceImpl.java
    addDict、editDict,参数添加String tips
    addDict(String dictName, String dictValues, String tips){
        //解析dictValues
        List<Map<String, String>> items = parseKeyValue(dictValues);

        //添加字典
        Dict dict = new Dict();
        dict.setName(dictName);
        //添加字典备注
        dict.setTips(tips);
        dict.setNum(0);
        dict.setPid(0);
        this.dictMapper.insert(dict);

        //添加字典条目
        for (Map<String, String> item : items) {
            String num = item.get(MUTI_STR_KEY);
            String name = item.get(MUTI_STR_VALUE);
            Dict itemDict = new Dict();
            itemDict.setPid(dict.getId());
            itemDict.setName(name);
            try {
                itemDict.setNum(Integer.valueOf(num));
            }catch (NumberFormatException e){
                throw new BussinessException(BizExceptionEnum.DICT_MUST_BE_NUMBER);
            }
            this.dictMapper.insert(itemDict);
        }
    }
5. DictController.java 添加参数String tips,@BusinessLog中key加入tips
6. 关于数据表dict:划分为两部分 dict + subDicts
    CREATE TABLE `dict` (
      `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键id',
      `num` int(11) DEFAULT NULL COMMENT '排序',
      `pid` int(11) DEFAULT NULL COMMENT '父级字典',
      `name` varchar(255) DEFAULT NULL COMMENT '名称',
      `tips` varchar(255) DEFAULT NULL COMMENT '提示',
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=92 DEFAULT CHARSET=utf8 COMMENT='字典表';
    字段对应关系对象结构:
    'id'、'tips' --> dict
    'num'、'pid'、'name' --> subDicts --> List<Map<String, String>>       

3.2 Warpper对字典status字段进行包装:通知管理模块代码完善

包装的含义在于对数据库中存在的简化存储字段进行解释说明,这部分工作从Controller层实现,结合map+warpper。
/**
 * 获取通知列表
 */
@RequestMapping(value = "/list")
@ResponseBody
public Object list(String condition) {
    List<Map<String, Object>> list = this.noticeDao.list(condition);
    return super.warpObject(new NoticeWrapper(list));
}
可以看出,在对象返回之前进行了warpper包装处理:NoticeWrapper继承BaseControllerWarpper
//实现抽象方法
protected abstract void warpTheMap(Map<String, Object> map);
NoticeWrapper.java中:
@Override
public void warpTheMap(Map<String, Object> map) {
    Integer creater = (Integer) map.get("creater");
    map.put("createrName", ConstantFactory.me().getUserNameById(creater));
    //根据Controller返回的通知信息列表数据进行字段包装
    map.put("statusName", ConstantFactory.me().getNoticeStatusName((Integer) map.get("status")));
}
这里我们看到了ConstantFactory这个类:常量的生产工厂类,继承IConstantFactory。
我们要在IConstantFactory添加:
    /*
    * 获取通知状态
    * */
    String getNoticeStatusName(Integer status);
在ConstantFactory实现getNoticeStatusName方法:
    /*
    * 获取通知状态
    * */
    @Override
    public String getNoticeStatusName(Integer status) {
        return NoticeStatus.valueOf(status);
    }
重点来了:NoticeStatus 自定义枚举类 对status进行处理
/**
 * description:通知状态枚举
 * author:jiangyanfei
 * date:2018/8/14
 * time:16:28
 */
public enum NoticeStatus {

    NOTICED(1, "已发送"),
    DISABLE(0, "未发送");

    int code;
    String message;

    NoticeStatus(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    //主要方法,对status进行解释说明并返回
    public static String valueOf(Integer status) {
        if (status == null) {
            return "";
        } else {
            for (NoticeStatus s : NoticeStatus.values()) {
                if (s.getCode() == status) {
                    return s.getMessage();
                }
            }
            return "";
        }
    }
}
最后将进行处理后的字段返回页面:此时显示的就是我们预先定义好的字典内容了
    {title: '状态',field: 'statusName', align: 'center', valign: 'middle' }

2018-8-16 星期四

1.字典管理:字典管理最重要的功能是对数据表中的可读性较差的字段进行解释说明,使得用户可以通过web端形式对这些字段进行操作。

字典管理:包装可读性较差的字段
ConstantFactory.me().getStatusName((Integer) map.get("status")),通用的warpper调用方式。
第一次调整:
    ConstantFactory中采用的方案是枚举类XxxStatus覆写valueOf方法,这样写的确可以对Controller中返回的数据进行包装展示。
    OK(1, "启用"), FREEZED(2, "冻结"), DELETED(3, "被删除"); 例如这样的枚举类定义格式。
    但是若超级管理员进行修改后(例:修改了key对应的value),不生效,这是必然的,因为warpper此时只对Controller中返回的结果,根本上就是字典dict没有与对应的Controller建立联系。
    所以更改是无效的。而且枚举类中定义的常量key-value对,若修改了字典中的value,也是无法进行对应。
第二次调整:ConstantFactory类中存在getDictsByName(String name, Integer val)方法
    根据字典名称和status值,查询字典dict表中对应status(key)的value值,这样在Controller中需要返回的数据中进行了与dict表的联系,并包装了字段,实现了字典修改同步。
    但是,在调用此方法时候,name字段一定要和字典管理中的dictname对应,即:当进行字典修改时,修改字典的名称字段会导致字典无法进行字段包装及字典同步。

2.用户管理:用户管理中的删除操作时逻辑删除,即不删除user表中数据,只是将用户的状态置为”已删除”。

3.角色管理:保留字段变更为角色描述字段,页面更改,添加、编辑逻辑。

4.新添模块:交易管理:dealMgr、策略管理:strategyMgr

5.BaseJunit:单元测试父类@Transactional注解开启默认单元测试执行完毕之后数据回滚!

猜你喜欢

转载自blog.csdn.net/Nerver_77/article/details/82380845