Java Code Examples for org.nutz.dao.Cnd#cri()

The following examples show how to use org.nutz.dao.Cnd#cri() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RoleServiceImpl.java    From NutzSite with Apache License 2.0 6 votes vote down vote up
/**
 * 新增角色
 *
 * @param data
 * @return
 */
@Override
public Role insert(Role data) {
    List<String> ids = new ArrayList<>();
    if (data != null && data.getMenuIds() != null) {
        if (Strings.isNotBlank(data.getMenuIds())) {
            ids = Arrays.asList(data.getMenuIds().split(","));
        }
    }
    if (ids != null && ids.size() > 0) {
        Criteria cri = Cnd.cri();
        cri.where().andInStrList("id", ids);
        List<Menu> menuList = menuService.query(cri);
        data.setMenus(menuList);
    }
    dao().insert(data);
    dao().insertRelation(data, "menus");
    return data;
}
 
Example 2
Source File: RoleServiceImpl.java    From NutzSite with Apache License 2.0 6 votes vote down vote up
/**
 * 更新角色
 *
 * @param data
 * @return
 */
@Override
public int update(Role data) {
    List<String> ids = new ArrayList<>();
    if (data != null && data.getMenuIds() != null) {
        if (Strings.isNotBlank(data.getMenuIds())) {
            ids = Arrays.asList(data.getMenuIds().split(","));
        }
        //清除已有关系
        Role tmpData = this.fetch(data.getId());
        this.fetchLinks(tmpData, "menus");
        dao().clearLinks(tmpData, "menus");
    }
    if (ids != null && ids.size() > 0) {
        Criteria cri = Cnd.cri();
        cri.where().andInStrList("id", ids);
        List<Menu> menuList = menuService.query(cri);
        data.setMenus(menuList);
    }
    int count = dao().update(data);
    dao().insertRelation(data, "menus");
    return count;
}
 
Example 3
Source File: AreaDao.java    From DAFramework with MIT License 6 votes vote down vote up
public EArea allArea(WMap query) {
	//处理查询条件
	Criteria cnd = Cnd.cri();
	cnd.where().andEquals("del_flag", Constans.POS_NEG.NEG);
	if (query.get("extId") != null && StringUtil.isNotBlank(query.get("extId").toString())) {
		cnd.where().andNotIn("id", query.get("extId").toString());
		cnd.where().andNotLike("parent_ids", "%," + query.get("extId").toString() + ",%");
	}
	cnd.getOrderBy().asc("sort");
	List<EArea> allAreas = query(cnd);
	List<ITreeNode<EArea>> allNodes = new ArrayList<>();
	EArea root = new EArea();
	root.setId(0L);
	allNodes.add(root);
	if (allAreas != null && !allAreas.isEmpty()) {
		allNodes.addAll(allAreas);
	}
	return (EArea) root.buildTree(allNodes);
}
 
Example 4
Source File: UserServiceImpl.java    From NutzSite with Apache License 2.0 6 votes vote down vote up
/**
 * 更新角色
 *
 * @param data
 */
@Override
public void updataRelation(User data) {
    List<String> ids = new ArrayList<>();
    if (data != null && Strings.isNotBlank(data.getRoleIds())) {
        if (Strings.isNotBlank(data.getRoleIds())) {
            ids = Arrays.asList(data.getRoleIds().split(","));
        }
        //清除已有关系
        User tmpData = this.fetch(data.getId());
        this.fetchLinks(tmpData, "roles");
        dao().clearLinks(tmpData, "roles");
    }
    if (ids != null && ids.size() > 0) {
        Criteria cri = Cnd.cri();
        cri.where().andInStrList("id", ids);
        List<Role> roleList = roleService.query(cri);
        data.setRoles(roleList);
    }
    //更新关系
    dao().insertRelation(data, "roles");
}
 
Example 5
Source File: MenuController.java    From DAFramework with MIT License 6 votes vote down vote up
@RequestMapping(value = "/allMenu", method = RequestMethod.POST)
public ActionResultObj findAllmenu(@RequestBody SearchQueryJS queryJs) {
	ActionResultObj result = new ActionResultObj();
	try {
		WMap query = queryJs.getQuery();
		//处理查询条件
		Criteria cnd = Cnd.cri();
		cnd.where().andEquals("del_flag", Constans.POS_NEG.NEG);
		if (query.get("extId") != null && StringUtil.isNotBlank(query.get("extId").toString())) {
			cnd.where().andNotIn("id", query.get("extId").toString());
			cnd.where().andNotLike("parent_ids", "%," + query.get("extId").toString() + ",%");
		}
		cnd.getOrderBy().asc("sort");
		List<EMenu> allMenus = menuDao.query(cnd);
		EMenu menu = menuDao.buildMenuTree(allMenus);
		WMap map = new WMap();
		map.put("data", menu.getItems());
		result.setData(map);
		result.okMsg("查询成功!");
	} catch (Exception e) {
		e.printStackTrace();
		LOG.error("查询失败,原因:" + e.getMessage());
		result.error(e);
	}
	return result;
}
 
Example 6
Source File: MenuController.java    From DAFramework with MIT License 6 votes vote down vote up
@RequestMapping(value = "/list")
public ActionResultObj list(@RequestBody SearchQueryJS queryJs) {
	ActionResultObj result = new ActionResultObj();
	try {

		//处理查询条件
		Criteria cnd = Cnd.cri();
		cnd.where().andEquals("del_flag", Constans.POS_NEG.NEG);
		cnd.getOrderBy().asc("sort");

		List<EMenu> allMenus = menuDao.query(cnd);
		EMenu menu = menuDao.buildMenuTree(allMenus);

		//处理返回值
		WMap map = new WMap();
		map.put("data", menu.getItems());
		result.ok(map);
		result.okMsg("查询成功!");
	} catch (Exception e) {
		e.printStackTrace();
		LOG.error("查询失败,原因:" + e.getMessage());
		result.error(e);
	}
	return result;
}
 
Example 7
Source File: UserController.java    From DAFramework with MIT License 6 votes vote down vote up
@RequestMapping(value = "/roleList")
public ActionResultObj getAllRoleList() {
	ActionResultObj result = new ActionResultObj();
	try {
		Criteria cnd = Cnd.cri();
		//			cnd.where().andNotEquals("name", "Admin");
		List<ERole> roles = roleDao.query(cnd);
		WMap map = new WMap();
		map.put("data", roles);
		result.ok(map);
		result.okMsg("查询角色列表成功!");
	} catch (Exception e) {
		LOG.error("获取角色列表失败:" + e.getMessage());
		result.error(e);
	}
	return result;
}
 
Example 8
Source File: FileController.java    From DAFramework with MIT License 5 votes vote down vote up
@RequestMapping(value="/list")
public ActionResultObj list(@RequestBody SearchQueryJS queryJs){
	ActionResultObj result = new ActionResultObj();
	try{
		Pager pager = queryJs.toPager();
		WMap query = queryJs.getQuery();
		
		//处理查询条件
		Criteria cnd = Cnd.cri();
		if(query.get("type") != null && StringUtil.isNotBlank(query.get("type").toString())){
			cnd.where().andEquals("type", query.get("type").toString());
		}
		cnd.getGroupBy().groupBy("type");
		cnd.getOrderBy().desc("sort");
		//分页查询
		List<EFile> projectList = fileDao.query(cnd, pager);
		
		//处理返回值
		WMap map = new WMap();
		if(queryJs.getQuery() != null){
			map.putAll(queryJs.getQuery());
		}
		map.put("data", projectList);
		map.put("page", queryJs.toWPage(pager));
		result.ok(map);
		result.okMsg("查询成功!");
	}catch(Exception e){
		e.printStackTrace();
		LOG.error("查询失败,原因:"+e.getMessage());
		result.error(e);
	}
	return result;
}
 
Example 9
Source File: AreaController.java    From DAFramework with MIT License 5 votes vote down vote up
@RequestMapping(value = "/list")
public ActionResultObj list(@RequestBody SearchQueryJS queryJs) {
	ActionResultObj result = new ActionResultObj();
	try {
		Pager pager = queryJs.toPager();
		WMap query = queryJs.getQuery();

		//处理查询条件
		Criteria cnd = Cnd.cri();
		cnd.where().andEquals("del_flag", Constans.POS_NEG.NEG);
		if (query.get("name") != null && StringUtil.isNotBlank(query.get("name").toString())) {
			cnd.where().andLike("name", query.get("name").toString()).orLike("full_name", query.get("name").toString());
		}
		cnd.getOrderBy().asc("sort");

		//分页查询
		List<EArea> areaList = areaDao.query(cnd, pager);
		pager.setRecordCount(areaDao.count(cnd));

		//处理返回值
		WMap map = new WMap();
		if (queryJs.getQuery() != null) {
			map.putAll(queryJs.getQuery());
		}
		map.put("data", areaList);
		map.put("page", queryJs.toWPage(pager));
		result.ok(map);
		result.okMsg("查询成功!");
	} catch (Exception e) {
		e.printStackTrace();
		LOG.error("查询失败,原因:" + e.getMessage());
		result.error(e);
	}
	return result;
}
 
Example 10
Source File: DictController.java    From DAFramework with MIT License 5 votes vote down vote up
@RequestMapping(value="list")
public ActionResultObj list(@RequestBody SearchQueryJS queryJs){
	ActionResultObj result = new ActionResultObj();
	try{
		Pager pager = queryJs.toPager();
		WMap query = queryJs.getQuery();
		
		//处理查询条件
		Criteria cnd = Cnd.cri();
		if(query.get("type") != null && StringUtil.isNotBlank(query.get("type").toString())){
			cnd.where().andEquals("type", query.get("type").toString());
		}
		cnd.getGroupBy().groupBy("type");
		cnd.getOrderBy().desc("sort");
		//分页查询
		List<EDict> projectList = dictDao.query(cnd, pager);
		
		//处理返回值
		WMap map = new WMap();
		if(queryJs.getQuery() != null){
			map.putAll(queryJs.getQuery());
		}
		map.put("data", projectList);
		map.put("page", queryJs.toWPage(pager));
		result.ok(map);
		result.okMsg("查询成功!");
	}catch(Exception e){
		e.printStackTrace();
		LOG.error("查询失败,原因:"+e.getMessage());
		result.error(e);
	}
	return result;
}
 
Example 11
Source File: OrgController.java    From DAFramework with MIT License 5 votes vote down vote up
@RequestMapping(value = "/getOrgs/{type}")
public ActionResultObj getOrgsByListByType(@PathVariable String type) {
	ActionResultObj result = new ActionResultObj();
	try {
		if (StringUtil.isNotBlank(type)) {
			// 处理查询条件
			Criteria cnd = Cnd.cri();
			if(!type.equals("all")){
				cnd.where().andEquals("type", type);
			}
			cnd.getOrderBy().desc("id");

			// 分页查询
			List<EOrg> orgList = orgDao.query(cnd);

			// 处理返回值
			WMap map = new WMap();
			map.put("data", orgList);
			result.ok(map);
			result.okMsg("查询成功!");
		} else {
			result.errorMsg("删除失败,链接不存在!");
		}
	} catch (Exception e) {
		e.printStackTrace();
		LOG.error("查询失败,原因:" + e.getMessage());
		result.error(e);
	}
	return result;
}
 
Example 12
Source File: SysUserDetailsService.java    From DAFramework with MIT License 5 votes vote down vote up
/**
 * 根据用户ID,获取用户对应的角色列表
 * @param userId
 * @return
 * @throws Exception
 */
public List<ERole> getUserRoles(Long userId) throws Exception {
	List<ERole> userRoles = null;
	if (userId != null) {
		Criteria cnd = Cnd.cri();
		cnd.where().and("id", "in", "select roleid from sys_user_role where userid=" + userId + "");
		userRoles = roleDao.query(cnd);
	}
	return userRoles;
}
 
Example 13
Source File: MenuService.java    From DAFramework with MIT License 5 votes vote down vote up
public boolean delete(long id) {
	EMenu menu = menuDao.fetch(id);
	if (menu == null) { return false; }
	Criteria cnd = Cnd.cri();
	cnd.where().andEquals("id", menu.getId());
	cnd.where().orLike("parent_ids", "%," + menu.getId() + ",%");

	Chain chain = Chain.make("del_flag", Constans.POS_NEG.POS);

	return menuDao.update(chain, cnd) > 0 ? true : false;
}
 
Example 14
Source File: OrgService.java    From DAFramework with MIT License 5 votes vote down vote up
public boolean delete(long id) {
	EOrg org = orgDao.fetch(id);
	if(org ==null){
		return false;
	}
	Criteria cnd = Cnd.cri();
	cnd.where().andEquals("id", org.getId());
	cnd.where().orLike("parent_ids", "%,"+org.getId()+",%");
	
	Chain chain = Chain.make("del_flag", Constans.POS_NEG.POS);
	
	return orgDao.update(chain, cnd)>0 ? true : false;
}
 
Example 15
Source File: AreaService.java    From DAFramework with MIT License 5 votes vote down vote up
public boolean delete(long id) {
	EArea area = areaDao.fetch(id);
	if(area ==null){
		return false;
	}
	Criteria cnd = Cnd.cri();
	cnd.where().andEquals("id", area.getId());
	cnd.where().orLike("parent_ids", "%,"+area.getId()+",%");
	
	Chain chain = Chain.make("del_flag", Constans.POS_NEG.POS);
	
	return areaDao.update(chain, cnd)>0 ? true : false;
}
 
Example 16
Source File: DictDao.java    From DAFramework with MIT License 5 votes vote down vote up
/**
 * 获取具体类型数据字典列表
 * @param type
 * @return
 */
public List<EDict> getDictListByType(String type){
	SimpleCriteria simpleCr=Cnd.cri();
	simpleCr.where().and("type", "=", type);
	simpleCr.asc("sort");
	return query(simpleCr);
	
}
 
Example 17
Source File: AreaDao.java    From DAFramework with MIT License 5 votes vote down vote up
/**
 * 根据一个parentId,得到其下级的地区
 * @param parentId
 * @return
 */
public List<EArea> getAreaByParentId(Long parentId){
	//处理查询条件
	Criteria cnd = Cnd.cri();
	cnd.where().andEquals("del_flag", Constans.POS_NEG.NEG);
	cnd.where().andEquals("parent_id", parentId);
	cnd.getOrderBy().asc("sort");
	List<EArea> areas = query(cnd);
	return areas;
}
 
Example 18
Source File: OrgController.java    From DAFramework with MIT License 4 votes vote down vote up
@RequestMapping(value = "/list")
public ActionResultObj list(@RequestBody SearchQueryJS queryJs) {
	ActionResultObj result = new ActionResultObj();
	try {
		Pager pager = queryJs.toPager();
		WMap query = queryJs.getQuery();

		// 处理查询条件
		Criteria cnd = Cnd.cri();
		cnd.where().andEquals("del_flag", Constans.POS_NEG.NEG);
		if (query.get("queryArea") != null && StringUtil.isNotBlank(query.get("queryArea").toString())) {
			cnd.where().andEquals("area_id", query.get("queryArea").toString());
		}
		if (query.get("queryType") != null && StringUtil.isNotBlank(query.get("queryType").toString())) {
			cnd.where().andEquals("type", query.get("queryType").toString());
		}
		if (query.get("queryName") != null && StringUtil.isNotBlank(query.get("queryName").toString())) {
			cnd.where().andLike("name", "%" + query.get("queryName").toString() + "%");
		}
		cnd.getOrderBy().asc("id");

		// 分页查询
		List<EOrg> orgList = orgDao.query(cnd, pager);
		pager.setRecordCount(orgDao.count(cnd));
		for (EOrg eOrg : orgList) {
			EArea area = areaDao.fetch(eOrg.getAreaId());
			if (area != null) {
				eOrg.setArea(area);
			}
		}

		// 处理返回值
		WMap map = new WMap();
		if (queryJs.getQuery() != null) {
			map.putAll(queryJs.getQuery());
		}
		map.put("data", orgList);
		map.put("page", queryJs.toWPage(pager));
		result.ok(map);
		result.okMsg("查询成功!");
	} catch (Exception e) {
		e.printStackTrace();
		LOG.error("查询失败,原因:" + e.getMessage());
		result.error(e);
	}
	return result;
}