com.cosmosource.common.service.CAMgrManager.java Source code

Java tutorial

Introduction

Here is the source code for com.cosmosource.common.service.CAMgrManager.java

Source

/**
* <p>??: CAMgrManager.java</p>
* <p>???Manager</p>
* <p>?: Copyright (c) 2010 Beijing Cosmosource Co. Ltd.</p>
* <p>?: Cosmosource Beijing Office</p>
* <p>All right reserved.</p>
* @ 2011-11-23 ?03:21:23 
* @ WXJ
* @ V1.0
* <p>                   </p>   
* 
*/
package com.cosmosource.common.service;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.hibernate.HibernateException;

import com.cosmosource.base.service.BaseManager;
import com.cosmosource.base.service.Page;
import com.cosmosource.base.util.ConvertUtils;
import com.cosmosource.base.util.DateUtil;
import com.cosmosource.common.entity.TAcCaaction;
import com.cosmosource.common.entity.TAcCaapply;
import com.cosmosource.common.entity.TAcCauser;
import com.cosmosource.common.entity.TAcCauseraction;
import com.cosmosource.common.entity.TAcCauserapply;
import com.cosmosource.common.model.CALicenseModel;
import com.cosmosource.common.model.CAUserActionModel;
import com.cosmosource.common.model.CAUserLicenseModel;
import com.cosmosource.common.model.CaModel;
import com.cosmosource.common.model.CaapplyAuditQueryModel;
import com.cosmosource.common.model.CafunctionQueryModel;

/**
 * @??:  CA?
 * 
 * @ WXJ
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public class CAMgrManager extends BaseManager {
    /**
     * @??: CA
     * @ yc
     * @2011-11-22
     * @param page 
     * @param model ?
     * @param subModel??
     * @param pMap??
     * @return
     */
    public Page<TAcCaapply> findCaList(final Page<TAcCaapply> page, final TAcCaapply model, final CaModel subModel,
            final Map pMap) {
        String sql = "CommonSQL.caQryList";
        Map<String, Object> map = new HashMap<String, Object>();
        if (subModel != null) {
            map.putAll(ConvertUtils.pojoToMap(subModel));
        }
        if (model != null) {
            map.putAll(ConvertUtils.pojoToMap(model));
        }
        if (pMap != null) {
            map.putAll(pMap);
        }
        logger.info(map.toString());
        return sqlDao.findPage(page, sql, map);

    }

    /**
     * caapply
     * @param page
     * @param entity
     * @param caapplyQueryModel
     * @param nmap
     * @return
     * ffj 2011-11-23
     */
    public Page<TAcCaapply> findCaapplyList(Page<TAcCaapply> page, TAcCaapply entity,
            CaapplyAuditQueryModel caapplyQueryModel, Map nmap) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.putAll(ConvertUtils.pojoToMap(entity));
        if (caapplyQueryModel != null)
            map.putAll(ConvertUtils.pojoToMap(caapplyQueryModel));
        if (nmap != null)
            map.putAll(nmap);
        return sqlDao.findPage(page, "CommonSQL.findCaapplyAuditList", map);
    }

    /**
     * 
     * @param id
     * @return
     * ffj 2011-11-24
     */
    public TAcCaapply findById(Long id) {
        return (TAcCaapply) dao.findById(TAcCaapply.class, id);
    }

    /**
     * CA
     * @param entity
     * ffj 2011-11-24
     */
    public void update(TAcCaapply entity) {
        dao.update(entity);
    }

    /*
     * ??
     */
    public TAcCaapply findCaById(Long id) {
        return (TAcCaapply) dao.get(TAcCaapply.class, id);
    }

    /**
     * @??: ?Ca?ID  CA? ?
     * @ yc
     * @2011-11-24
     * @param deleteUser ??
     * @param caIds Ca?ID
     * @return
     * @throws Exception 
     */
    public String deleteCaByIds(String deleteUser, long... caIds) {
        // ?CA??????CA?
        String changeCaNos = "";
        for (long caId : caIds) {

            TAcCaapply caApply = (TAcCaapply) this.findById(TAcCaapply.class, caId);
            if (caApply != null) {
                String auditstatus = caApply.getAuditstatus();
                String delstatus = caApply.getDelstatus();
                //?(0? 1? 2??)?0  , ?
                if ((!auditstatus.trim().equals("0")) || (delstatus.trim().equals("1"))) {
                    changeCaNos = changeCaNos + caApply.getCaid() + ";";
                    continue;
                }

                //CA??
                caApply.setDelstatus("1");//

                //?CA
                this.dao.update(caApply);
            }
        }
        return changeCaNos;

    }

    //   /**
    //    * caapply
    //    * @param page
    //    * @param entity
    //    * @param caapplyQueryModel
    //    * @param nmap
    //    * @return
    //    * ffj 2011-11-23
    //    */
    //   @SuppressWarnings("unchecked")
    //   public Page<TAcCaapply> findCaapplyList(Page<TAcCaapply> page,
    //         TAcCaapply entity, CaapplyAuditQueryModel caapplyQueryModel,
    //         Map nmap) {
    //      Map<String, Object> map = new HashMap<String, Object>();
    //      map.putAll(ConvertUtils.pojoToMap(entity));
    //      if (caapplyQueryModel != null)
    //         map.putAll(ConvertUtils.pojoToMap(caapplyQueryModel));
    //      if (nmap != null)
    //         map.putAll(nmap);
    //      return sqlDao.findPage(page, "CommonSQL.findCaapplyAuditList", map);
    //   }

    //   /**
    //    * CA
    //    * @param entity
    //    * ffj 2011-11-24
    //    */
    //   public void update(TAcCaapply entity){
    //      dao.update(entity);
    //   }

    /**
     * caapply
     * 
     * @param page
     * @param paraMap
     */
    public Page<TAcCaapply> findCaApply4LicenseList(Page<TAcCaapply> page, TAcCaapply entity,
            CALicenseModel caLicenseModel, Map paraMap) {

        Map<String, Object> map = new HashMap<String, Object>();
        map.putAll(ConvertUtils.pojoToMap(entity));
        if (caLicenseModel != null) {
            map.putAll(ConvertUtils.pojoToMap(caLicenseModel));
        }
        if (paraMap != null) {
            map.putAll(paraMap);
        }
        return sqlDao.findPage(page, "CommonSQL.findCaApply4LicenseList", map);
    }

    //   /**
    //    * @param id
    //    */
    //   public TAcCaapply findById(Long id) {
    //      return (TAcCaapply) dao.findById(TAcCaapply.class, id);
    //   }
    /**
     * ??
     * @param applyno
     * @return
     */
    public List<TAcCauserapply> findCaUserApplayByNo(String applyno) {

        List<TAcCauserapply> tAcCauserapplies = dao.findByProperty(TAcCauserapply.class, "applyno", applyno);
        return tAcCauserapplies;
    }

    /**
     * ?keycaapply???
     * @param caUserLicenseModels
     * @param entity
     * @throws Exception 
     */
    public void saveTAcCaapplyAndUser(List<CAUserLicenseModel> caUserLicenseModels, TAcCaapply entity)
            throws Exception {

        for (CAUserLicenseModel caUserLicenseModel : caUserLicenseModels) {
            String loginname = caUserLicenseModel.getLoginname();
            String[] loginnames = loginname.split(",");
            for (String sloginname : loginnames) {
                TAcCauser tAcCauser = new TAcCauser();
                tAcCauser.setLoginname(sloginname);
                tAcCauser.setCano(caUserLicenseModel.getCano());
                //2012.04.05  applyno
                tAcCauser.setApplyno(entity.getApplyno());
                Long causerid = dao.getSeqNextVal("SEQ_AC_CAUSER");
                tAcCauser.setCauserid(causerid);
                try {
                    dao.saveOrUpdate(tAcCauser);
                } catch (HibernateException e) {
                    logger.error("?CAUSER", e);
                    throw new Exception();
                }
            }
        }
        //??(0?? 1?)
        entity.setIsgenca("1");
        try {
            dao.saveOrUpdate(entity);
        } catch (HibernateException e) {
            logger.error("CAAPPLY", e);
            throw new Exception();
        }
    }

    public TAcCaapply findApplyById(String caid) {
        return (TAcCaapply) dao.load(TAcCaapply.class, new Long(caid));
    }

    public Page<?> findCaUserByNo(Page<?> page, Map<String, ?> values) {
        String hql = "from TAcCauserapply where applyno=:applyno";
        return dao.findPage(page, hql, values);
    }

    //--csq add start

    /**
     * ?
     * @param entity
     * @throws Exception
     */
    public void saveApply(TAcCaapply entity) throws Exception {
        if (entity.getCaid() == null) {
            Long caid = dao.getSeqNextVal("SEQ_AC_CAAPPLY");
            logger.info("caid : " + caid);
            entity.setCaid(caid);
        }
        entity.setApplyno(this.makeApplyno(entity.getCaid().toString()));

        dao.saveOrUpdate(entity);
    }

    /**
     * ?CA?
     * @param code
     * @return
     */
    private String formatCode(String code) {
        StringBuffer formatCode = new StringBuffer();
        int fullCount = 4;
        if (StringUtils.isNotEmpty(code)) {
            int appendCount = fullCount - code.length();
            for (int i = 0; i < appendCount; i++) {
                formatCode.append("0");
            }
            formatCode.append(code);
        }

        return formatCode.toString();
    }

    /**
     * ?CA?
     * @param caid
     * @return
     */
    private String makeApplyno(String caid) {
        StringBuffer applyno = new StringBuffer();
        applyno.append(DateUtil.getDateTime("yyyyMMdd")).append(this.formatCode(caid));
        logger.info("?" + applyno);

        return applyno.toString();
    }

    /**
     * ??
     * @param entity
     * @throws Exception
     */
    public void saveApplyStamp(TAcCaapply entity) throws Exception {
        TAcCaapply loadEntity = (TAcCaapply) dao.load(TAcCaapply.class, entity.getCaid());
        loadEntity.setHandlerstamp(entity.getHandlerstamp());
        loadEntity.setStepcode(entity.getStepcode());
        dao.merge(loadEntity);
    }

    /**
     * ???
     * @param map
     * @return
     */
    public List<?> findUsersWithTaxno(final Map map) {
        return sqlDao.findList("CommonSQL.findUsersWithTaxno", map);
    }

    /**
     * ?CA???
     * @param userApplyList
     * @throws Exception
     */
    public void saveUserApplyList(List<TAcCauserapply> userApplyList) throws Exception {
        for (TAcCauserapply userApply : userApplyList) {
            Long causerapplyid = dao.getSeqNextVal("SEQ_AC_CAUSERAPPLY");
            userApply.setCauserapplyid(causerapplyid);
            dao.saveOrUpdate(userApply);
        }
    }

    /**
     * ?
     * @param userApply
     */
    public void saveUserApply(TAcCauserapply userApply) {
        Long causerapplyid = dao.getSeqNextVal("SEQ_AC_CAUSERAPPLY");
        userApply.setCauserapplyid(causerapplyid);
        dao.saveOrUpdate(userApply);
    }

    /**
     * ?
     * @param map
     * @return
     * @throws SQLException
     */
    public Long countUserApply(final Map map) throws SQLException {
        return (Long) sqlDao.getSqlMapClientTemplate().queryForObject("CommonSQL.countUserApply", map);
    }

    /**
     * ??
     * @param map
     * @return
     */
    public List<?> findCurrentApplyStep(final Map map) {
        return sqlDao.findList("CommonSQL.currentApplyStep", map);
    }

    /**
     * ????hql?
     * @return
     */
    private String makeUpdateApplyHql() {
        StringBuffer updateApplyHql = new StringBuffer();
        updateApplyHql.append("update TAcCaapply set ").append("stepcode='relation', ").append("issubmit='1'")
                .append("where caid=:caid");

        return updateApplyHql.toString();
    }

    /**
     * ????
     * @param values
     */
    public void updateApplySubmit(Map<String, ?> values) {
        dao.batchExecute(this.makeUpdateApplyHql(), values);
    }

    public Page<?> findCaUserActionList(Page<?> page, CAUserActionModel userActionModel, Map paraMap) {
        Map<String, Object> map = new HashMap<String, Object>();
        if (userActionModel != null) {
            map.putAll(ConvertUtils.pojoToMap(userActionModel));
        }

        if (paraMap != null) {
            map.putAll(paraMap);
        }
        return sqlDao.findPage(page, "CommonSQL.findUserActionList", map);
    }

    public void deleteCaUserAction(String[] ids) {
        dao.deleteByIds(TAcCauseraction.class, ids);
    }

    public List<TAcCaaction> getAllCaAction() {
        return (List<TAcCaaction>) dao.find(TAcCaaction.class);
    }

    public void saveCaUserActions(List<TAcCauseraction> userActionList) {
        for (TAcCauseraction userAction : userActionList) {
            Long causeractionid = dao.getSeqNextVal("SEQ_AC_CAUSERACTION");
            logger.info("causeractionid : " + causeractionid);
            userAction.setCauseractionid(causeractionid);
            dao.save(userAction);
        }
    }

    public List<TAcCauseraction> findCaUserActionByLoginname(String loginname) throws Exception {
        return dao.findByProperty(TAcCauseraction.class, "loginname", loginname);
    }

    /**
     * CA?
     * @param entity
     */
    public void update(TAcCauseraction entity) {
        dao.update(entity);
    }

    /**
     * CA??
     * @param loginname
     * @return
     * @throws Exception
     */
    public List<?> findUserNotHaveActionList(final String loginname) throws Exception {
        Map<String, String> paramMap = new HashMap<String, String>();
        paramMap.put("loginname", loginname);
        String sql = "CommonSQL.findUserNotHaveActionList";
        return sqlDao.findList(sql, paramMap);
    }

    /**
     * ?
     * @param loginname
     * @return
     * @throws Exception
     */
    public boolean isUserExist(final String loginname) throws Exception {
        Map<String, String> paramMap = new HashMap<String, String>();
        paramMap.put("loginname", loginname);

        return (Long) sqlDao.getSqlMapClientTemplate().queryForObject("CommonSQL.countUser", paramMap) > 0 ? true
                : false;
    }

    public List<?> findCaaction4Mem() throws Exception {
        return sqlDao.findList("CommonSQL.findCaaction4Mem", null);
    }

    public List<?> findCauser4Mem() throws Exception {
        return sqlDao.findList("CommonSQL.findCauser4Mem", null);
    }

    //--csq add end

    public Page<TAcCauser> findCauserList(Page<TAcCauser> page, TAcCauser entity, CaModel caModel,
            Map<String, Object> pMap) {
        String sql = "CommonSQL.causerQryList";
        Map<String, Object> map = new HashMap<String, Object>();
        if (caModel != null) {
            map.putAll(ConvertUtils.pojoToMap(caModel));
        }
        if (entity != null) {
            map.putAll(ConvertUtils.pojoToMap(entity));
        }
        if (pMap != null) {
            map.putAll(pMap);
        }
        return sqlDao.findPage(page, sql, map);
    }

    public TAcCauser findCauserById(Long causerid) {
        return (TAcCauser) dao.load(TAcCauser.class, new Long(causerid));
    }

    /**
     * CA?
     * @param entity
     * yc 2011-12-14
     */
    public void update(TAcCauser entity) {
        dao.update(entity);
    }

    /**
     * CA?
     * @param entity
     * yc 2011-12-14
     */
    public void delete(TAcCauser entity) {
        dao.deleteById(TAcCauser.class, entity.getCauserid());
    }

    /* ca? ffj add start 20111214 */
    /**
     * ca
     * 
     * @param page
     * @param entity
     * @param cafunctionQueryModel
     * @param nmap
     * @return ffj 2011-12-14
     */
    public Page<TAcCaaction> findCaFunctionList(Page<TAcCaaction> page, TAcCaaction entity,
            CafunctionQueryModel cafunctionQueryModel, Map nmap) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.putAll(ConvertUtils.pojoToMap(entity));
        if (cafunctionQueryModel != null)
            map.putAll(ConvertUtils.pojoToMap(cafunctionQueryModel));
        if (nmap != null)
            map.putAll(nmap);
        return sqlDao.findPage(page, "CommonSQL.findCaFunctionList", map);
    }

    /**
     * ca
     * 
     * @param actionid
     * @return ffj 2011-12-14
     */
    public TAcCaaction findByActionId(long actionid) throws Exception {
        return (TAcCaaction) dao.findById(TAcCaaction.class, actionid);
    }

    /**
     * ca
     * 
     * @param entity
     *            ffj 2011-12-14
     * @throws Exception
     */
    public void saveCaFunction(TAcCaaction entity) throws Exception {
        dao.saveOrUpdate(entity);
    }

    /**
     * ca
     * 
     * @param ids
     *            ffj 2011-12-14
     */
    public void deleteCaFunction(String[] ids) throws Exception {
        dao.deleteByIds(TAcCaaction.class, ids);
    }

    /**
     * ca
     * 
     * @param ids
     *            ffj 2011-12-14
     */
    public void deleteCaFunction(Long id) throws Exception {
        dao.deleteById(TAcCaaction.class, id);
    }

    public void updateCaFunction(TAcCaaction entity) {
        dao.update(entity);
    }

    /**
     * ?actioncode?
     * @param actioncode
     * @return
     * ffj 2011-12-19
     */
    public boolean isActionCodeUnique(String actioncode) {
        return dao.isPropertyUnique(TAcCaaction.class, "actioncode", actioncode, null);
    }

    /**
     * actioncodeT_AC_CAUSERACTION?
     * @param actioncode
     * @return
     * ffj 2011-12-19
     */
    public TAcCauseraction findCauseractionByactioncode(String actioncode) {
        List<TAcCauseraction> entity = dao.findByProperty(TAcCauseraction.class, "actioncode", actioncode);
        if (entity != null && entity.size() > 0) {
            TAcCauseraction n = entity.get(0);
            return n;
        }
        return null;
    }

    /* ca? end */

    /**
     * @??:????
     * @fjy
     * @2012-03-31
     * ???ca???applyno
     * @param loginname
     * @return
     */
    public String getCauserApplyNoByLoginname(String loginname) {
        List applyList = dao
                .createSQLQuery("select t.applyno from t_ac_causer t where t.loginname='" + loginname + "'").list();
        if (applyList.size() == 0) {
            return "";
        } else
            return applyList.get(0) == null ? "" : applyList.get(0).toString();
    }

    /**
     * @??:applyno?ca?
     * @fjy
     * @2012-03-31
     * @param applyno
     * @return
     */
    public TAcCaapply getCaapplyByApplyno(String applyno) {
        List<TAcCaapply> caapplyList = dao.findByProperty(TAcCaapply.class, "applyno", applyno);
        if (caapplyList.isEmpty() || caapplyList == null) {
            return null;
        } else
            return (TAcCaapply) caapplyList.get(0);
    }

}