com.pureinfo.srm.patent.domain.impl.PatentMgrImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.pureinfo.srm.patent.domain.impl.PatentMgrImpl.java

Source

/**
 * PureInfo Command
 * @(#)PatentMgrImpl.java   1.0 2006-9-5
 * 
 * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. 
 * All rights reserved, see the license file.
 * 
 * www.pureinfo.com.cn
 */

package com.pureinfo.srm.patent.domain.impl;

import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.pureinfo.ark.ArkExceptionTypes;
import com.pureinfo.ark.content.ArkContentHelper;
import com.pureinfo.ark.content.domain.impl.ContentMgrImpl;
import com.pureinfo.ark.content.model.ArkContent;
import com.pureinfo.common.sender.SenderHelper;
import com.pureinfo.common.sender.model.ISender;
import com.pureinfo.dolphin.DolphinHelper;
import com.pureinfo.dolphin.model.IObjects;
import com.pureinfo.dolphin.persister.IStatement;
import com.pureinfo.force.ForceConstants;
import com.pureinfo.force.PureSystem;
import com.pureinfo.force.exception.PureException;
import com.pureinfo.force.lang.DateTimeUtil;
import com.pureinfo.srm.SRMConstants;
import com.pureinfo.srm.SRMTypes;
import com.pureinfo.srm.auth.domain.IObjUserMappingMgr;
import com.pureinfo.srm.auth.domain.ISRMUserMgr;
import com.pureinfo.srm.auth.model.ObjUserMapping;
import com.pureinfo.srm.auth.model.SRMUser;
import com.pureinfo.srm.org.model.IHaveOrganization;
import com.pureinfo.srm.patent.PatentHelper;
import com.pureinfo.srm.patent.domain.IPatentFeeMgr;
import com.pureinfo.srm.patent.domain.IPatentFeeYearMgr;
import com.pureinfo.srm.patent.domain.IPatentMgr;
import com.pureinfo.srm.patent.model.Patent;
import com.pureinfo.srm.patent.model.PatentFee;
import com.pureinfo.srm.patent.model.PatentFeeYear;

/**
 * <P>
 * Created on 2006-9-5 16:28:40 <BR>
 * Last modified on 2006-9-5
 * </P>
 * 
 * @author wind
 * @version 1.0, 2006-9-5
 * @since Command 1.0
 */
public class PatentMgrImpl extends ContentMgrImpl implements IPatentMgr {
    private final static Logger logger = Logger.getLogger(PatentMgrImpl.class.getName());

    /**
     * @see com.pureinfo.ark.content.domain.IContentMgr#beforeSaving(com.pureinfo.ark.content.model.ArkContent,
     *      boolean)
     */
    public void beforeSaving(ArkContent _content, boolean _bToTemp) throws PureException {
        ((IHaveOrganization) _content).setCollegeByDepartment();
        if (!_bToTemp) {
            updatePatentFeeInfo((Patent) _content);
        }

        super.beforeSaving(_content, _bToTemp);
    }

    /**
     * 
     * 
     * @param _sPatent
     * @throws PureException
     */
    private void updatePatentFeeInfo(Patent _patent) throws PureException {
        String sql = "update {this} set {this.feeForward}=? where {this.patentId}=? "
                + "and {this.feeStatus}=? and {this.feeType}=?";
        IPatentFeeMgr feeMgr = (IPatentFeeMgr) ArkContentHelper.getContentMgrOf(SRMTypes.PATENT_FEE);
        IStatement query = null;
        try {
            query = feeMgr.createQuery(sql, 1);
            query.setString(0, (String) _patent.getFinalProperty("feeCardNo"));
            query.setInt(1, _patent.getId());
            query.setInt(2, SRMConstants.PATENT_FEE_STATUS_PLAN);
            query.setString(3, String.valueOf(SRMConstants.PATENT_FEE_TYPE_SCH_YEAR));
            query.executeUpdate();
        } finally {
            if (query != null)
                query.clear();
        }
    }

    /**
     * @see com.pureinfo.srm.patent.domain.IPatentMgr#needRemindYearFeePatent(int)
     */
    public List needRemindYearFeePatent(int _nNumDays) throws PureException {
        IStatement query = null;
        IObjects result = null;
        try {
            final String strSQL = "SELECT * FROM {this} WHERE {this.patentType} <> " + SRMConstants.PATENT_TYPE_RJDJ
                    + " AND {this.yearFeeDate}=? AND {this.status}=" + SRMConstants.PATENT_STATUS_HAS_RIGHT
                    + " and {this.pkType} <> 1";
            query = this.createQuery(strSQL, 0);
            query.setDate(0, PatentHelper.getDateOfNumDays(new Date(), _nNumDays));
            result = query.executeQuery();
            return result.toList();
        } finally {
            DolphinHelper.clear(result, query);
        }
    }

    /**
     * @see com.pureinfo.srm.patent.domain.IPatentMgr#sendEmailForAutoRemind(int)
     */
    public void sendEmailForAutoRemind(int _nNumDays) throws PureException {
        sendEmailForAutoRemind(this.needRemindYearFeePatent(_nNumDays), _nNumDays);
    }

    /**
     * @see com.pureinfo.srm.patent.domain.IPatentMgr#sendEmailForAutoRemind(java.util.List,
     *      int)
     */
    public void sendEmailForAutoRemind(List _patents, int _nNumDays) throws PureException {
        try {
            ISender sender = SenderHelper.getSender(SenderHelper.TYPE_MAIL);
            String sFromAddress = PureSystem.getRequiredProperty("mail.system.user");
            for (Iterator iter = _patents.iterator(); iter.hasNext();) {
                Patent patent = (Patent) iter.next();
                SRMUser administrator = patent.getAdministrator();
                String toAddress = patent.getAdministratorEmail();
                if (toAddress == null)
                    toAddress = administrator.getEmail();
                if (administrator != null && toAddress != null) {
                    sender.send(sFromAddress, "", toAddress, administrator.getTrueName(),
                            "" + patent.getName() + "",
                            getEmailContent(patent, _nNumDays, false));
                    patent.setEmailReminded(true);
                    patent.setLastEmailTime(new Date());
                    this.save(patent);
                }
            }
        } finally {
            if (_patents != null)
                _patents.clear();
        }
    }

    /**
     * @see com.pureinfo.srm.patent.domain.IPatentMgr#sendEmailForAutoRemind(int[],
     *      int)
     */
    public String[] sendEmailForHandRemind(String _sPatentIds) throws PureException {
        IObjects patents = null;
        try {
            patents = this.lookupByIds(_sPatentIds);
            String[] msgs = new String[patents.getSize()];
            ISender sender = SenderHelper.getSender(SenderHelper.TYPE_MAIL);
            String sFromAddress = PureSystem.getRequiredProperty("mail.system.user");
            int i = 0;
            for (Iterator iter = patents.iterator(); iter.hasNext(); i++) {
                Patent patent = (Patent) iter.next();
                int nNumDays = (int) DateTimeUtil.diff(patent.getYearFeeDate(), new Date(), DateTimeUtil.DAY);
                String sPatentName = patent.getName();
                SRMUser administrator = patent.getAdministrator();
                if (administrator == null) {
                    msgs[i] = (i + 1)
                            + "&nbsp;&nbsp;&nbsp;&nbsp;<font color='#FF0000'><font color=\"#000000\">"
                            + sPatentName + "</font></font>";
                } else {
                    String toAddress = patent.getAdministratorEmail();
                    if (toAddress == null)
                        toAddress = administrator.getEmail();
                    if (toAddress == null) {
                        msgs[i] = (i + 1)
                                + "&nbsp;&nbsp;&nbsp;&nbsp;<font color='#FF0000'><font color=\"#000000\">"
                                + sPatentName + "</font>\"" + administrator.getTrueName()
                                + "\"Email</font>";
                    } else {
                        try {
                            sender.send(sFromAddress, "", toAddress, administrator.getTrueName(),
                                    "" + sPatentName + "",
                                    getEmailContent(patent, nNumDays, false));
                            msgs[i] = getEmailMsg(i + 1, sPatentName, true);
                            patent.setEmailReminded(true);
                            patent.setLastEmailTime(new Date());
                            this.save(patent);
                        } catch (PureException ex) {
                            msgs[i] = getEmailMsg(i + 1, sPatentName, false);
                        }
                    }
                }
            }
            return msgs;
        } finally {
            if (patents != null)
                patents.clear();
        }
    }

    private String getEmailMsg(int _nSerial, String _sPatentName, boolean _bIsSuccess) {
        StringBuffer sbuff = new StringBuffer();
        try {
            sbuff.append(_nSerial).append("&nbsp;&nbsp;&nbsp;&nbsp;<font color=\"");
            sbuff.append(_bIsSuccess ? "#009900" : "#FF0000");
            sbuff.append("\"><font color=\"#000000\">").append(_sPatentName);
            sbuff.append("</font>").append(_bIsSuccess ? "" : "").append("</font>");
            return sbuff.toString();
        } finally {
            sbuff.setLength(0);
        }
    }

    /**
     * @see com.pureinfo.srm.patent.domain.IPatentMgr#sendEmailForHandRemind(com.pureinfo.srm.patent.model.Patent)
     */
    public void sendEmailForHandRemind(Patent _patent) throws PureException {
        try {
            ISender sender = SenderHelper.getSender(SenderHelper.TYPE_MAIL);
            String sFromAddress = PureSystem.getRequiredProperty("mail.system.user");
            SRMUser administrator = _patent.getAdministrator();
            String toAddress = _patent.getAdministratorEmail();
            if (toAddress == null)
                toAddress = administrator.getEmail();
            if (administrator != null && toAddress != null) {
                sender.send(sFromAddress, "", toAddress, administrator.getTrueName(),
                        "" + _patent.getName() + "", getEmailContent(_patent, 0, true));
                _patent.setEmailReminded(true);
                _patent.setLastEmailTime(new Date());
                this.save(_patent);
            }
        } catch (Exception e) {
            logger.debug("send email failure!");
            return;
        }
    }

    /**
     * 
     * 
     * @param _patent
     * @param _nNumDays
     * @param _bIsAuth
     *            
     * @return
     * @throws PureException
     */
    private String getEmailContent(Patent _patent, int _nNumDays, boolean _bIsAuth) throws PureException {
        if (_patent == null) {
            throw new PureException(PureException.INVALID_VALUE, "");
        }
        StringBuffer sbuff = new StringBuffer();
        try {
            sbuff.append(_patent.getAdministratorName()).append(":\n");
            sbuff.append("    !\n");
            sbuff.append("    ").append(_patent.getName()).append("");
            if (_bIsAuth) {
                sbuff.append("");
            } else {
                sbuff.append("");
                sbuff.append(_nNumDays).append("");
            }
            sbuff.append("\n");
            if (!_bIsAuth) {
                IPatentFeeYearMgr feeYearMgr = (IPatentFeeYearMgr) ArkContentHelper
                        .getContentMgrOf(PatentFeeYear.class);
                PatentFeeYear feeYear = feeYearMgr.getLatestOf(_patent.getId());
                if (feeYear == null) {
                    sbuff.append("    ");
                } else {
                    sbuff.append("    ");
                    if (feeYear.getPayDate() != null) {
                        sbuff.append(ForceConstants.DATE_FORMAT.format(feeYear.getPayDate()));
                    }
                }
                sbuff.append("")
                        .append(ForceConstants.DATE_FORMAT.format(_patent.getYearFeeDate()));
                sbuff.append("\n");
            }
            sbuff.append("\n").append(_patent.getName()).append("").append("\n");
            sbuff.append("").append(_patent.getPatentSid()).append('\n');
            sbuff.append("").append(_patent.getName()).append('\n');
            sbuff.append("").append(ForceConstants.DATE_FORMAT.format(_patent.getApplyDate()))
                    .append('\n');
            sbuff.append("");
            if (!this.openIsAuth(_patent.getPatentType())) {
                sbuff.append(ForceConstants.DATE_FORMAT.format(_patent.getWarrantDate()));
            } else {
                sbuff.append(ForceConstants.DATE_FORMAT.format(
                        (_patent.getPublicDate() != null) ? _patent.getPublicDate() : _patent.getWarrantDate()));
            }
            sbuff.append('\n');
            sbuff.append("").append(_patent.getAdministratorName()).append("\n\n");
            sbuff.append("\n");
            String sPatentOfficer = PureSystem.getProperty("patent.officer", "");
            String sTelePhone = PureSystem.getProperty("product.office.telephone", "");
            if (sPatentOfficer != null && sPatentOfficer.length() > 0)
                sbuff.append(sPatentOfficer);
            if (sTelePhone != null && sTelePhone.length() > 0)
                sbuff.append("    ").append(sTelePhone);
            return sbuff.toString();
        } finally {
            sbuff.setLength(0);
        }
    }

    /**
     * @see com.pureinfo.srm.patent.domain.IPatentMgr#findAllAuthorizedOf(int)
     */
    public List findAllAuthorizedOf(int _nYear) throws PureException {
        IStatement query = null;
        IObjects result = null;
        StringBuffer sbuff = new StringBuffer();
        try {
            String sYear = String.valueOf(_nYear);
            String firstDate = sYear + "-01-01";
            String endDate = sYear + "-12-31";
            sbuff.append("SELECT * FROM {this} WHERE {this.status}=");
            sbuff.append(SRMConstants.PATENT_STATUS_HAS_RIGHT);
            sbuff.append(" AND {this.pkType}<>1 AND {this.warrantDate}>='").append(firstDate);
            sbuff.append("' AND {this.warrantDate}<='").append(endDate).append('\'');
            sbuff.append(" ORDER BY {this.department}");
            String strSQL = sbuff.toString();
            query = this.createQuery(strSQL, 0);
            result = query.executeQuery();
            return result.toList();
        } finally {
            sbuff.setLength(0);
            DolphinHelper.clear(result, query);
        }
    }

    /**
     * @see com.pureinfo.srm.patent.domain.IPatentMgr#findAllAuthorizedOfThisYear()
     */
    public List findAllAuthorizedOfThisYear() throws PureException {
        return findAllAuthorizedOf(DateTimeUtil.get(new Date(), DateTimeUtil.YEAR));
    }

    /**
     * @see com.pureinfo.srm.patent.domain.IPatentMgr#sendEmailForCheck(com.pureinfo.srm.patent.model.Patent,
     *      boolean)
     */
    public void sendEmailForCheck(Patent _patent, boolean bIsPass) throws PureException {
        SRMUser inputUser = _patent.getInputUser();
        if (inputUser != null) {
            if (inputUser.getEmail() != null) {
                StringBuffer sbuff = new StringBuffer();
                try {
                    sbuff.append(inputUser.getTrueName()).append("\n    ");
                    if (bIsPass) {
                        sbuff.append("");
                    } else {
                        sbuff.append("");
                    }
                    sbuff.append("").append(_patent.getName()).append("");
                    if (bIsPass) {
                        sbuff.append("");
                    } else {
                        sbuff.append("\n");
                        sbuff.append("    :\n\n    ").append(_patent.getCheckSuggestion());
                    }
                    String sFromAddress = PureSystem.getRequiredProperty("mail.system.user");
                    ISender sender = SenderHelper.getSender(SenderHelper.TYPE_MAIL);
                    sender.send(sFromAddress, "", inputUser.getEmail(), inputUser.getTrueName(),
                            "" + _patent.getName() + "", sbuff.toString());
                } catch (PureException ex) {
                    ex.printStackTrace();
                } finally {
                    sbuff.setLength(0);
                }
            }
        }
    }

    /**
     * 
     * @see com.pureinfo.srm.patent.domain.IPatentMgr#openIsAuth(int)
     */
    public boolean openIsAuth(int _nPatentType) throws PureException {
        switch (_nPatentType) {
        case SRMConstants.PATENT_TYPE_FMZL:
        case SRMConstants.PATENT_TYPE_ZWXPZ:
        case SRMConstants.PATENT_TYPE_GWQT:
        case SRMConstants.PATENT_TYPE_RJDJ:
        case SRMConstants.PATENT_TYPE_OTHER:
            return false;
        case SRMConstants.PATENT_TYPE_SYXX:
        case SRMConstants.PATENT_TYPE_WGSJ:
            return true;
        default:
            return false;
        // throw new PureException(PureException.INVALID_VALUE,
        // "" +
        // _nPatentType);
        }
    }

    /**
     * 
     * @see com.pureinfo.srm.patent.domain.IPatentMgr#getNeedRemindYearFeePatentOfUserNo(int,
     *      com.pureinfo.srm.auth.model.SRMUser)
     */
    public int getNeedRemindYearFeePatentOfUserNo(int _nNumDays, SRMUser _user) throws PureException {
        IStatement query = null;
        StringBuffer sbuff = new StringBuffer();
        try {
            sbuff.append("SELECT COUNT(*) FROM {this} WHERE {this.patentType}<>" + SRMConstants.PATENT_TYPE_RJDJ);
            sbuff.append(" AND {this.pkType}<>1 AND {this.yearFeeDate}<=? ");
            sbuff.append(" AND {this.status}=" + SRMConstants.PATENT_STATUS_HAS_RIGHT);
            sbuff.append(" AND {this.administrator}=?");

            query = this.createQuery(sbuff.toString(), 1);
            query.setDate(0, PatentHelper.getDateOfNumDays(new Date(), _nNumDays));
            query.setInt(1, _user.getId());
            return ((Number) query.executeStat()).intValue();
        } catch (Exception e) {
            throw new PureException(ArkExceptionTypes.CONTENT_MANAGEMENT,
                    "failed to get need remind year fee patent NO Of UserId- " + _user.getId(), e);
        } finally {
            if (query != null)
                query.clear(true);
            sbuff.setLength(0);
        }
    }

    /**
     * 
     * @see com.pureinfo.srm.patent.domain.IPatentMgr#getPatentNeedMgrNo(com.pureinfo.srm.auth.model.SRMUser)
     */
    public int getPatentNeedMgrNo(SRMUser _user) throws PureException {
        final String SQL = "SELECT COUNT(*) FROM {this}0 WHERE {this.college}=? and {this.pkType}<>1";

        IStatement query = null;
        try {
            query = this.createQuery(SQL, 1);
            query.setInt(0, _user.getCollegeId());
            return ((Number) query.executeStat()).intValue();
        } catch (Exception ex) {
            throw new PureException(ArkExceptionTypes.CONTENT_MANAGEMENT,
                    "failed to getPatentNeedMgrNo Of User- " + _user.getId(), ex);
        } finally {
            if (query != null) {
                query.clear(true);
            }
        }
    }

    public int getLessDaysYearFeePatentNum(int _nNumDays) throws PureException {
        IStatement query = null;
        try {
            final String strSQL = "SELECT COUNT(*) AS _COUNT FROM {this} WHERE {this.patentType} <> "
                    + SRMConstants.PATENT_TYPE_RJDJ + " AND {this.yearFeeDate}<=? AND {this.status}="
                    + SRMConstants.PATENT_STATUS_HAS_RIGHT + " AND {this.pkType}<>1";
            query = this.createQuery(strSQL, 1);
            query.setDate(0, PatentHelper.getDateOfNumDays(new Date(), _nNumDays));
            return ((Number) query.executeStat()).intValue();
        } catch (Exception e) {
            throw new PureException(ArkExceptionTypes.CONTENT_MANAGEMENT,
                    "failed to getLessDaysYearFeePatentNum OF days- " + _nNumDays, e);
        } finally {
            if (query != null) {
                query.clear();
            }
        }
    }

    /**
     * @see com.pureinfo.srm.patent.domain.IPatentMgr#lookupByPatentSid(java.lang.String,
     *      boolean)
     */
    public Patent lookupByPatentSid(String _sPatentSid, boolean _bIsFromTemp) throws PureException {
        IStatement query = null;
        IObjects result = null;
        try {
            String strSQL = "SELECT * FROM {this} WHERE {this.patentSid}=?";
            if (_bIsFromTemp) {
                strSQL = "SELECT * FROM {this}0 WHERE {this.patentSid}=?";
            }
            query = this.createQuery(strSQL, 1);
            query.setString(0, _sPatentSid);
            result = query.executeQuery(false);
            return (Patent) result.next();
        } finally {
            DolphinHelper.clear(result, query);
        }
    }

    /**
     * 
     * @see com.pureinfo.srm.patent.domain.IPatentMgr#getMyPatentNum(com.pureinfo.srm.auth.model.SRMUser)
     */
    public int getMyPatentNum(SRMUser _user) throws PureException {
        IStatement query = null;
        try {
            final String strSQL = "SELECT COUNT(*) FROM srm_prj_patent this, srm_prj_patent_person_map patentPerson "
                    + "WHERE this.L_STATUS=" + SRMConstants.PATENT_STATUS_AUDITED + " AND patentPerson.OBJ_TYPE ="
                    + SRMTypes.PATENT
                    + " AND patentPerson.USER_ID=? AND patentPerson.OBJ_ID=this.PRODUCT_ID AND this.PK_TYPE<>1";
            query = this.createQuery(strSQL, 1);
            query.setInt(0, _user.getId());
            return ((Number) query.executeStat()).intValue();
        } finally {
            if (query != null) {
                query.clear(true);
            }
        }
    }

    /**
     * 
     * @see com.pureinfo.srm.patent.domain.IPatentMgr#changePatentIsSupportStatus(int,
     *      int)
     */
    public void changePatentIsSupportStatus(int _nPatentId) throws PureException {
        IPatentFeeMgr patentFeeMgr;
        Patent patent;
        int[] nTypes = { SRMConstants.PATENT_FEE_TYPE_SCH_APPLY, SRMConstants.PATENT_FEE_TYPE_SCH_YEAR };

        int totalRecordOfSpecialType = 0;
        patentFeeMgr = (IPatentFeeMgr) ArkContentHelper.getContentMgrOf(PatentFee.class);

        for (int i = 0; i < nTypes.length; i++) {
            totalRecordOfSpecialType = patentFeeMgr.getNumOfSpecialType(_nPatentId, nTypes[i]);

            patent = (Patent) this.lookupById(_nPatentId);

            if (patent == null) {
                throw new PureException(PureException.INVALID_VALUE, "-" + _nPatentId);
            }

            if (nTypes[i] == SRMConstants.PATENT_FEE_TYPE_SCH_APPLY) {// 
                if (totalRecordOfSpecialType >= 1) {
                    patent.setIsSchoolApply(1);
                } else {
                    patent.setIsSchoolApply(0);
                }
            } else if (nTypes[i] == SRMConstants.PATENT_FEE_TYPE_SCH_YEAR) {// 
                if (totalRecordOfSpecialType >= 1) {
                    patent.setIsSchoolAuthorization(true);
                } else {
                    patent.setIsSchoolAuthorization(false);
                }
            }
            this.save(patent);
            patent = null;
        }
    }

    /**
     * @see com.pureinfo.srm.patent.domain.IPatentMgr#sendMessge4NoInstitute(java.lang.String[])
     */
    public void sendMessge4NoInstitute(String[] _sIds) throws PureException {
        if (_sIds == null)
            return;
        ISender sender = SenderHelper.getSender(SenderHelper.TYPE_SYSTEM);
        ISRMUserMgr userMgr = (ISRMUserMgr) ArkContentHelper.getContentMgrOf(SRMUser.class);
        boolean bFromFormal = true;
        for (int i = 0; i < _sIds.length; i++) {
            int nId = Integer.parseInt(_sIds[i]);
            Patent patent = (Patent) this.lookupById(nId);
            if (patent == null) {
                patent = (Patent) this.lookupTempById(nId);
                bFromFormal = false;
            }
            if (patent == null) {
                throw new PureException(PureException.INVALID_VALUE, "ID" + nId);
            }
            SRMUser toUser = null;
            int nInputUserId = patent.getInputUserId();
            if (nInputUserId != 0) {
                toUser = (SRMUser) userMgr.lookupById(nInputUserId);
            }
            if (toUser == null) {
                toUser = patent.getAdministrator();
            }
            if (toUser == null) {
                toUser = this.getFirstInsideAuthor(nId, bFromFormal);
            }
            if (toUser == null)
                return;
            sender.send("1", "system", String.valueOf(toUser.getId()), toUser.getTrueName(), "",
                    "" + patent.getName() + "");
        }
    }

    /**
     * @see com.pureinfo.srm.patent.domain.IPatentMgr#getFirstInsideAuthor(int,
     *      boolean)
     */
    public SRMUser getFirstInsideAuthor(int _nId, boolean _bFromFormal) throws PureException {
        IObjUserMappingMgr mgr = (IObjUserMappingMgr) ArkContentHelper.getContentMgrOf(SRMTypes.OBJ_USER_MAPPING);
        ObjUserMapping pp = null;
        List list = mgr.getAllOfObj(SRMTypes.PATENT, _nId, !_bFromFormal);
        if (list == null || list.size() == 0) {
            return null;
        }
        pp = (ObjUserMapping) list.get(0);
        if (pp == null)
            return null;
        ISRMUserMgr userMgr = (ISRMUserMgr) ArkContentHelper.getContentMgrOf(SRMUser.class);
        return (SRMUser) userMgr.lookupById(pp.getUserId());
    }

    /**
     * @see com.pureinfo.srm.patent.domain.IPatentMgr#isPatentReady2CreatePlanFee(com.pureinfo.srm.patent.model.Patent)
     */
    public boolean isPatentReady2CreatePlanFee(Patent _transObj) throws PureException {
        int patentStatus = _transObj.getStatus();
        int patentType = _transObj.getPatentType();
        if (patentStatus == SRMConstants.PATENT_STATUS_HAS_RIGHT && "1".equals(_transObj.getZjuPlace())) {
            if (_transObj.getAuditStatus() == 0 && _transObj.isFromFormal()) {
                if (patentType == SRMConstants.PATENT_TYPE_FMZL) {
                    if (StringUtils.isNotEmpty(_transObj.getCerSid())) {
                        IPatentFeeMgr feeMgr = (IPatentFeeMgr) ArkContentHelper
                                .getContentMgrOf(SRMTypes.PATENT_FEE);
                        int num = feeMgr.getNumOfSpecialType(_transObj.getId(),
                                SRMConstants.PATENT_FEE_TYPE_SCH_YEAR);
                        return num <= 0;
                    }
                }
            }
        }
        return false;
    }

    /**
     * @see com.pureinfo.srm.patent.domain.IPatentMgr#isPatentEnd(com.pureinfo.srm.patent.model.Patent)
     */
    public boolean isPatentEnd(Patent _transObj) throws PureException {
        if (_transObj == null)
            return false;

        int patentStatus = _transObj.getStatus();
        if (patentStatus == SRMConstants.PATENT_STATUS_TURNED || SRMConstants.isPatentClose(patentStatus)) {
            return true;
        }
        return false;
    }

    /**
     * @see com.pureinfo.srm.patent.domain.IPatentMgr#findAllOfApplyYear(int)
     */
    public IObjects findAllOfApplyYear(int _year) throws PureException {
        IStatement query = null;
        String sql = "select * from {this} where year({this.applyDate})=? and {this.pkType}<>1";
        try {
            query = this.createQuery(sql, 0);
            query.setInt(0, _year);
            return query.executeQuery();
        } finally {
            DolphinHelper.clear(null, query);
        }
    }

    /**
     * @throws PureException
     * @see com.pureinfo.srm.patent.domain.IPatentMgr#findAllOfWeightYear(int)
     */
    public IObjects findAllOfWeightYear(int _nYear) throws PureException {
        IStatement query = null;
        String sql = "select {this.*} from {this} where  {this.pkType}<>1 and (year({this.warrantDate})=?) "
                + "or ( year({this.applyDate})=? and {this.warrantDate} is null)";
        try {
            query = this.createQuery(sql, 0);
            query.setInt(0, _nYear);
            query.setInt(1, _nYear);
            return query.executeQuery();
        } finally {
            DolphinHelper.clear(null, query);
        }
    }

    public boolean isExitsInKnowLedge(int otherName, String no) throws PureException {
        // TODO Auto-generated method stub

        IStatement query = null;
        IObjects result = null;
        try {
            final String strSQL = "SELECT * FROM {this} WHERE {this.otherName} =? and {this.desginNO}=? and {this.pkType}=1";

            query = this.createQuery(strSQL, 0);
            query.setInt(0, otherName);
            query.setString(1, no);
            result = query.executeQuery();
            if (result.toList().size() == 0) {
                return false;
            } else {
                return true;
            }

        } finally {
            DolphinHelper.clear(result, query);
        }
    }
}