Service:
package com.jinyatu.chicken.global.service;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.nutz.dao.Cnd;
import org.nutz.dao.entity.Record;
import org.nutz.ioc.loader.annotation.IocBean;
import com.jinyatu.base.po.Menu;
import com.jinyatu.base.utils.MD5Utils;
import com.jinyatu.chicken.global.base.BaseController;
import com.jinyatu.chicken.global.po.ChickenUser;
@IocBean(name="userService", singleton=false)
public class UserService extends BaseController {
private Logger logger = Logger.getLogger(getClass());
public Record queryUserByAccount(String userName, String password) {
Record recordUser = dao.fetch("sys_user",
Cnd.where("user_name", "=", userName).and("user_password", "=", MD5Utils.getMD5(password)),
"user_id,role_id,employee_id,isuse");
return recordUser;
}
public ChickenUser queryUserByUserRecord(Record recordUser) {
String tableName = "sys_user su LEFT JOIN sys_employee se ON su.employee_id=se.employee_id "
+ "LEFT JOIN sys_member sm on se.member_id=sm.member_id "
+ "LEFT JOIN sys_member_type smt on sm.member_type_id=smt.member_type_id";
Record userRecord = dao.fetch(tableName, Cnd.where("su.user_id", "=", recordUser.getString("user_id")),
"se.employee_id,sm.member_regin,sm.member_id,smt.member_type_id");
ChickenUser user = new ChickenUser();
user.setEmployeeID(userRecord.getString("employee_id"));
user.setMemberID(userRecord.getString("member_id"));
user.setMemberTypeID(userRecord.getString("member_type_id"));
user.setRoleID(recordUser.getString("role_id"));
user.setMemberRegin(userRecord.getString("member_regin"));
user.setUserId(recordUser.getString("user_id"));
List<Record> rolMenuList = dao.query("role_menu rm LEFT JOIN sys_menu sm on rm.menu_id=sm.menu_id", Cnd
.where("role_id", "=", recordUser.getString("role_id")).and("sm.isshow", "=", "1").asc("menu_priority"),
"sm.*");
List<Menu> menulist = new ArrayList<Menu>();
for (int i = 0; i < rolMenuList.size(); i++) {
Menu menu = new Menu(rolMenuList.get(i));
menulist.add(menu);
}
user.setMenu(menulist);
return user;
}
}
Controller:
/**
*
* @author oyg 用户登录管理类逻辑
*
*
*/
@At("/sys")
public class UserAction extends BaseController {
@Inject
private UserService userService;
@At
@Ok("json")
public CommRes login(@Param("account") String userName, @Param("password") String password,
@Param("authCode") String authCode, HttpServletRequest request, HttpServletResponse response) {
CommRes res = new CommRes();
if (!examineParam(userName, authCode, password)) {
除了dao,没有任何js配置