Jeesite4's filtering of authority control based on departmental company

In development, it is very common to display corresponding data according to different departments or companies, but how to filter in jeesite4? In fact, the author has also considered in this respect. The official documents are directly encapsulated. Please refer to: Data Permission Call . The document also clearly points out that this is to give access permissions by checking in the background management system. This is a comparison. It's easy, create roles, set access permissions, assign users... What you need in the Java code is also mentioned in the documentation. Below I put my code map below
In the controller, add the filter before dropping the findList or get method (you have to add each):

Insert picture description here

Rewrite the addDataSccopeFilter method in the service:

Insert picture description here

In entity

Insert picture description here

It can be seen that he is associated with js_sys_employee. The associated key is the create_by field and emp_code in js_sys_employee. At the same time, js_sys_employee is also associated with js_sys_office and js_sys_company. The organization table and company table can be filtered according to these two. Here I give an example for the company to remember (create_by, update_by, create_time, update_time, status, remarks must be added when creating the table, and then generate the code) when you save the data, the framework will automatically automatically Save it in the create_by field. After the code is written like this, return to the management system, create a company or organization, create a role, assign users, and give user data permissions (our company or this organization). it is helpful for you
controller
/**
	 * 查询列表数据
	 */
	@RequiresPermissions("goods:goods:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<Goods> listData(Goods goods, HttpServletRequest request, HttpServletResponse response) {
		goods.setPage(new Page<>(request, response));
		goodsService.addDataScopeFilter(goods);
		Page<Goods> page = goodsService.findPage(goods);
		return page;
	}
service
/**
	 * 根据公司进行过滤
	 * @param goods
	 */
	@Override
	public void addDataScopeFilter(Goods goods){
		goods.getSqlMap().getDataScope().addFilter("dsf", "Company",
				"e.company_code", UserDataScope.CTRL_PERMI_HAVE);
	}
entity
@Column(name="school_id", attrName="schoolId", label="学校id", isUpdate=false),
	@Column(name="school_name", attrName="schoolName", label="学校名称", isUpdate=false, queryType=QueryType.LIKE),
}, joinTable={
	@JoinTable(type=JoinTable.Type.JOIN, entity=Employee.class, alias="e",
			on="e.emp_code = a.create_by",attrName = "employee",
			columns={@Column(includeEntity=Employee.class)}),
},extWhereKeys="dsf", orderBy="a.goods_id DESC"
)

Guess you like

Origin blog.csdn.net/qq_44212951/article/details/100217772