1. 程式人生 > 實用技巧 >考試複習

考試複習

考試複習

  • 查詢所有角色
SELECT r.*
FROM employee_role e
LEFT JOIN role r
ON e.role_id=r.id
WHERE e.employee_id = #{id}
  • 查詢許可權列表
select p.expression
from employee_role er
left JOIN role_permission rp
ON er.role_id = rp.role_id
LEFT JOIN permission p
ON rp.permission_id = p.id
WHERE er.employee_id = #{id}
  • 重新載入前臺處理
function permissionset(){
    alert(1111);
    $.post('/permission/reload.do', function (obj){
        if(obj.success){
            $.messager.alert("溫馨提示","儲存成功1s後關閉");
            window.setTimeout(function (){
                window.location.reload();
            },1000);
        }else {
            alert(obj.msg);
        }
    });
}
  • 重新載入後臺
@RequestMapping("/reload")
@ResponseBody
public JsonResult reload() {
    try {
        //查詢資料庫中所有的許可權表示式
        List<String> list = permissionService.selectAllExperssion();
        //找IOC要所有含有@controller註解的bean
        Map<String, Object> beans = ctx.getBeansWithAnnotation(Controller.class);
        //把map中所有的bean提取到collection中
        Collection<Object> controllercglisb = beans.values();
        for (Object controller : controllercglisb) {
            if (AopUtils.isCglibProxy(controllercglisb)) {
                continue;
            }
            Class clazz = controllercglisb.getClass().getSuperclass();
            Method[] methods = clazz.getDeclaredMethods();
            for (Method method : methods) {
                RequiresPermissions requiresPermissions = method.getAnnotation(RequiresPermissions.class);
                if (requiresPermissions != null) {
                    String[] expandname = requiresPermissions.value();
                    String expression = expandname[0];
                    String name = expandname[1];
                    if (list.contains(expandname)) {
                        Permission permission = new Permission();
                        permission.setName(name);
                        permission.setExpression(expression);
                        permissionService.insert(permission);
                    }
                }
            }
        }
        return new JsonResult(true, "重新載入成功");
    } catch (Exception e) {
        return new JsonResult(false,"重新載入失敗");
    }
}
  • 潛在客戶報表sql
<select id="selectCustomerReport" resultType="java.util.HashMap">
    select ${groupType} groupType,count(c.id) number,c.gender from customer c
    left join employee e on c.seller_id = e.id

    <where>
        c.status = 0
        <if test="keyword != null">
            and e.name like concat('%',#{keyword},'%')
        </if>
        <if test="beginDate != null">
            and c.input_time &gt;= #{beginDate}
        </if>
        <if test="endDate != null">
            and c.input_time &lt;= #{endDate}
        </if>
    </where>


    group by ${groupType}
</select>
  • 柱狀圖後臺
@RequestMapping("/listByBar")
private String listByBar(@ModelAttribute("qo") customerReportQuery qo, Model model){
    List<HashMap> list = customerReportService.listALL(qo);
    ArrayList xList = new ArrayList();
    ArrayList yList = new ArrayList();
    Iterator iterator = list.iterator();
    while (iterator.hasNext()){
        Map map = (Map) iterator.next();
        xList.add(map.get("groupType"));
        yList.add(map.get("number"));
    }
    model.addAttribute("xList", JSON.toJSONString(xList));
    model.addAttribute("yList", JSON.toJSONString(yList));
    model.addAttribute("groupTypeName", MessageUtil.changMsg(qo));
    return "customerReport/listByBar";
}