AdminUserService.java.svn-base 3.37 KB
Newer Older
Kim Gyeongeun committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
package jp.agentec.sinaburocast.service;

import java.util.List;

import jp.agentec.sinaburocast.common.SinaburoConstant;
import jp.agentec.sinaburocast.entity.AdminUser;
import jp.agentec.sinaburocast.form.admin.setting.AdminRegistForm;
import jp.agentec.sinaburocast.form.admin.setting.AdminSearchForm;

import org.seasar.extension.jdbc.where.SimpleWhere;
import org.seasar.framework.container.annotation.tiger.Component;
import org.seasar.framework.container.annotation.tiger.InstanceType;
import org.seasar.framework.util.StringUtil;

@Component(instance=InstanceType.SINGLETON)
public class AdminUserService  extends AbstractService<AdminUser> {
	public static final String ID_SEQ_NAME = "admin_user_id_seq";

	/**
	 * IDを発行して、登録する。
	 */
	public int insertAdminUser(AdminUser adminUser, String insId) {
		adminUser.adminUserId = getSeqNextVal(Integer.class, ID_SEQ_NAME);
		return super.insert(adminUser, insId);
	}
	
	public AdminUser findById(Integer adminUserId) {
        return select().id(adminUserId).getSingleResult();
    }
	
	
	public AdminUser findByLoginId(String adminLoginId) {
        return select().where(new SimpleWhere().eq("loginId", adminLoginId).eq("delFlg", SinaburoConstant.DelFlg.NOT_DEL)).getSingleResult();
    }
	
	public List<AdminUser> findAllOrderById() {
        return select().orderBy("adminUserId asc").getResultList();
    }
    
	public List<AdminUser> findAllOrderByIdNotDel() {
    	
        return select().where(new SimpleWhere().eq("delFlg", SinaburoConstant.DelFlg.NOT_DEL)).orderBy("adminUserId asc").getResultList();
    }
    
    
    public List<AdminUser> findAllOrderByIdPaging(String pageKey,Integer curPage,AdminSearchForm adminSearchForm) {
    	adminSearchForm.setPaging(null, curPage, select().where(new SimpleWhere().eq("delFlg", SinaburoConstant.DelFlg.NOT_DEL)).getCount());

        return select().where(new SimpleWhere().eq("delFlg", SinaburoConstant.DelFlg.NOT_DEL)).orderBy("adminUserId asc").offset(adminSearchForm.getOffSet(pageKey)).limit(adminSearchForm.getLimit(pageKey)).getResultList();
    }
    
    /**
     * 
     * @param adminRegistForm 画面入力値
     * @param adminUser       ログインユーザー情報
     * @return 更新、登録件数
     */
    public int registOrUpdateAdminUser(AdminRegistForm adminRegistForm,AdminUser loginAdminUser){
    	
    	AdminUser adminUserEntity=null;
    	//新規登録の場合
    	if(StringUtil.isBlank(adminRegistForm.adminUserId)){
    		adminUserEntity = new AdminUser();
    		adminUserEntity.loginId = adminRegistForm.loginId;
        	adminUserEntity.password  = adminRegistForm.password;
        	adminUserEntity.adminUserName  = adminRegistForm.adminUserName;
        	adminUserEntity.email  = adminRegistForm.email;
        	adminUserEntity.delFlg  = Integer.parseInt(SinaburoConstant.DelFlg.NOT_DEL);
        	return insertAdminUser(adminUserEntity, loginAdminUser.loginId);
    	}
    	
    	//更新の場合    	
    	adminUserEntity =  findById(Integer.parseInt(adminRegistForm.adminUserId));
    	adminUserEntity.loginId = adminRegistForm.loginId;
    	adminUserEntity.password  = adminRegistForm.password;
    	adminUserEntity.adminUserName  = adminRegistForm.adminUserName;
    	adminUserEntity.email  = adminRegistForm.email;
    	adminUserEntity.delFlg  = Integer.parseInt(adminRegistForm.delFlg);
    	return update(adminUserEntity, loginAdminUser.loginId);
    	
    }
    
}