Java tutorial
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.viettel.hqmc.DAOHE; import com.google.gson.Gson; import com.viettel.common.util.Constants; import com.viettel.common.util.DateTimeUtils; import com.viettel.common.util.LogUtil; import com.viettel.common.util.StringUtils; import com.viettel.flow.DAOHE.FlowDAOHE; import com.viettel.hqmc.BO.Announcement; import com.viettel.hqmc.BO.AnnouncementReceiptPaper; import com.viettel.hqmc.BO.ConfirmImportSatistPaper; import com.viettel.hqmc.BO.CountNo; import com.viettel.hqmc.BO.DetailProduct; import com.viettel.hqmc.BO.EvaluationRecords; import com.viettel.hqmc.BO.Fee; import com.viettel.hqmc.BO.FeePaymentInfo; import com.viettel.hqmc.BO.FeeProcedure; import com.viettel.hqmc.BO.FileForSearch; import com.viettel.hqmc.BO.Files; import com.viettel.hqmc.BO.MainlyTarget; import com.viettel.hqmc.BO.Procedure; import com.viettel.hqmc.BO.ProcedureDepartment; import com.viettel.hqmc.BO.ProductInFile; import com.viettel.hqmc.BO.ProductTarget; import com.viettel.hqmc.BO.QualityControlPlan; import com.viettel.hqmc.BO.ReIssueForm; import com.viettel.hqmc.BO.ReceiveEmail; import com.viettel.hqmc.BO.RequestComment; import com.viettel.hqmc.BO.TestRegistration; import com.viettel.hqmc.DAO.EmailSmsDAO; import com.viettel.hqmc.FORM.AnnouncementForm; import com.viettel.hqmc.FORM.AnnouncementReceiptPaperForm; import com.viettel.hqmc.FORM.ConfirmImportSatistPaperForm; import com.viettel.hqmc.FORM.DetailProductForm; import com.viettel.hqmc.FORM.EvaluationRecordsForm; import com.viettel.hqmc.FORM.EvaluationRecordsFormOnGrid; import com.viettel.hqmc.FORM.FilesForm; import com.viettel.hqmc.FORM.ReIssueFormForm; import com.viettel.hqmc.FORM.TestRegistrationForm; import com.viettel.voffice.database.BO.Category; import com.viettel.voffice.database.BO.Process; import com.viettel.voffice.database.BO.VoAttachs; import com.viettel.voffice.database.DAO.GridResult; import com.viettel.voffice.database.DAOHibernate.CategoryDAOHE; import com.viettel.voffice.database.DAOHibernate.GenericDAOHibernate; import com.viettel.voffice.database.DAOHibernate.ProcessCommentDAOHE; import com.viettel.voffice.database.DAOHibernate.ProcessDAOHE; import com.viettel.vsaadmin.database.BO.Department; import com.viettel.vsaadmin.database.BO.Users; import com.viettel.vsaadmin.database.DAOHibernate.DepartmentDAOHE; import com.viettel.vsaadmin.database.DAOHibernate.UsersDAOHE; import com.viettel.ws.FORM.ANNOUCE_HANDLING; import com.viettel.ws.validateData.Validator; import java.io.StringWriter; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.ResourceBundle; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import org.apache.commons.lang.time.DateUtils; import org.hibernate.HibernateException; import org.hibernate.Query; /** * * @version 1.0 * @author havm2,binhnt53 */ public class FilesDAOHE extends GenericDAOHibernate<Files, Long> { //private static final Logger log = Logger.getLogger(FilesDAOHE.class); private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(FilesDAOHE.class); public FilesDAOHE() { super(Files.class); } /** * Lu h s * * @param createForm * @return */ public Files saveFiles(FilesForm createForm) { Files bo; // Files boRollBack; Long filesId = createForm.getFileId(); // Boolean isCreateNew; // Long status = 0L; Long announcementId = null; Long detailProductId = null; Long reIssueFormId = null; Long testRegistrationId = null; Long productTypeIdOld = null; // if (createForm.getStatus() != null) { // status = createForm.getStatus(); // } if (filesId != null) { String hql = "select dt.productType from DetailProduct dt " + "where " + "dt.detailProductId = (select f.detailProductId from Files f where f.fileId =?)"; Query query = getSession().createQuery(hql); query.setParameter(0, filesId); List<Long> lstProductType = query.list(); if (lstProductType.size() > 0) { productTypeIdOld = lstProductType.get(0); } } // // luu thong tin ho so // if (filesId == null) {//la them moi bo = createForm.convertToEntity(); } else {//la sua // isCreateNew = false; // boRollBack = findById(filesId); bo = findById(filesId); if (bo.getStatus().equals(Constants.FILE_STATUS.EVALUATED_TO_ADD)//binhnt update fix bug 16 09 20 && bo.getHaveTemp() != null && bo.getHaveTemp().equals(1l)) { // // Tao ban ghi backup // FilesForm cloneForm = getNewCloneFiles(filesId); cloneForm.setVersion(getCountVersion(bo.getFileId())); bo.setVersion(cloneForm.getVersion());//update version moi nhat cua ho so bo.setHaveTemp(null); saveFiles(cloneForm); //update toan bo process_comment cua lan tham dinh truoc thanh ProcessCommentDAOHE pcdhe = new ProcessCommentDAOHE(); pcdhe.updateVersion(filesId, cloneForm.getVersion()); } bo = createForm.updateToEntity(bo); } //*Luu thong tin cac form chinh cua ho so if (createForm.getAnnouncement() != null) { Announcement ann = createForm.getAnnouncement().convertToEntity(); ann.setIsTemp(0L); if (ann.getAnnouncementId() != null) { session.merge(ann); } else { session.save(ann); } announcementId = ann.getAnnouncementId(); } if (createForm.getDetailProduct() != null) { DetailProduct detail = createForm.getDetailProduct().convertToEntity(); detail.setIsTemp(0L); if (detail.getDetailProductId() != null) { session.merge(detail); } else { session.save(detail); } detailProductId = detail.getDetailProductId(); } if (createForm.getReIssueForm() != null) { ReIssueForm reissue = createForm.getReIssueForm().convertToEntity(); if (reissue.getReIssueFormId() != null) { session.merge(reissue); } else { session.save(reissue); } reIssueFormId = reissue.getReIssueFormId(); } if (createForm.getTestRegistration() != null) { TestRegistration testReg = createForm.getTestRegistration().convertToEntity(); if (testReg.getTestRegistrationId() != null) { getSession().merge(testReg); } else { getSession().save(testReg); } testRegistrationId = testReg.getTestRegistrationId(); } bo.setAnnouncementId(announcementId); bo.setDetailProductId(detailProductId); bo.setReIssueFormId(reIssueFormId); bo.setTestRegistrationId(testRegistrationId); bo.setDisplayStatus(getFileStatusName(bo.getStatus())); if (bo.getFileId() != null) { //khi sua xoa toan bo chu ki CA bo.setStaffRequest(""); bo.setLeaderRequest(""); bo.setLeaderStaffRequest(""); bo.setContentSigned(""); bo.setUserSigned(""); getSession().update(bo); } else { //update 15092015 binhnt cap nhat lay ma ho so if (createForm.getIsTemp() != null && createForm.getIsTemp().equals(Constants.ACTIVE_STATUS.ACTIVE)) { // // voi ho so clone thi ko can tao moi file code // } else { bo.setFileCode(getNewFileCode(createForm.getFileType())); } getSession().save(bo); } filesId = bo.getFileId(); // Luu thong tin cac danh sach chi tieu chinh saveMainlytarget(createForm.getLstMainlyTarget(), filesId); // Luu thong tin danh sach chi tieu san pham saveProductTarget(createForm.getLstBioTarget(), filesId, Constants.PRODUCT_TARGET_TYPE.BIO, createForm.getStatus()); saveProductTarget(createForm.getLstHeavyMetal(), filesId, Constants.PRODUCT_TARGET_TYPE.HEAVY_METAL, createForm.getStatus()); saveProductTarget(createForm.getLstChemical(), filesId, Constants.PRODUCT_TARGET_TYPE.CHEMICAL, createForm.getStatus()); // Luu thong tin danh sach tai lieu saveAttachs(createForm.getLstAttachs(), filesId, createForm.getLstAttachLabel()); // if ("".equals(createForm.getLstAttachLabel())) { // return null; // } // Luu thong tin danh sach ke hoach quan ly chat luong san pham saveQualityPlan(createForm.getLstQualityControl(), filesId); // Luu thong tin danh sach san pham nhap khau cho khach san 4 sao saveProductInFile(createForm.getLstProductInFile(), filesId); try {//lu ph thm nh h s if (createForm.getDetailProduct() != null && createForm.getDetailProduct().getProductType() != null && createForm.getDetailProduct().getProductTypeName() != null) { createForm.setProductType(createForm.getDetailProduct().getProductType()); createForm.setProductTypeName(createForm.getDetailProduct().getProductTypeName()); } ProcedureDAOHE pdheCheck = new ProcedureDAOHE(); Procedure pro = pdheCheck.getProcedureTypeFee(createForm.getFileType()); if (pro != null && (pro.getTypeFee() == 2 || pro.getTypeFee() == 3) && !pro.getDescription().equals(Constants.FILE_DESCRIPTION.ANNOUNCEMENT_4STAR) && !pro.getDescription().equals(Constants.FILE_DESCRIPTION.ANNOUNCEMENT_FILE05)) { if (!saveFee(filesId, createForm.getFileType(), createForm.getDetailProduct().getProductType(), pro, productTypeIdOld)) { return null; } } //Sua doi sua cong bo. Tao mot ban ghi trong FeePaymentInfo de VanThu nhin thay hoso cua loai nay else if (pro != null && pro.getDescription().equals(Constants.FILE_DESCRIPTION.ANNOUNCEMENT_FILE05)) { if (!saveFeeChangesAfterAnnounced(filesId, createForm.getFileType())) { return null; } } else if (pro != null && pro.getDescription().equals(Constants.FILE_DESCRIPTION.ANNOUNCEMENT_4STAR)) { if (!saveFee4Star(filesId, createForm.getFileType())) { return null; } } else if (pro != null && (pro.getTypeFee() == 7)) { if (!saveFeeTL(filesId, createForm.getFileType(), createForm.getDetailProduct().getProductType(), pro, productTypeIdOld)) { return null; } } else if (createForm.getDetailProduct() != null && createForm.getDetailProduct().getProductType() != null) { if (!saveFee(filesId, createForm.getFileType(), createForm.getDetailProduct().getProductType(), pro, productTypeIdOld)) { return null; } } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 return null; } if (createForm.getIsTemp() == null || (createForm.getIsTemp() != null && !createForm.getIsTemp().equals(1l))) { saveFileForSearch(filesId); } session.flush(); return bo; } /** * Get chi tit ca h sc * * @param fileId * @return */ public FilesForm getFilesDetail(Long fileId) { Files entity = findById(fileId); FilesForm form = null; try { if (entity != null) { form = new FilesForm(entity); if (entity.getAnnouncementId() != null) { Announcement ann = (Announcement) findById(Announcement.class, "announcementId", entity.getAnnouncementId()); form.setAnnouncement(new AnnouncementForm(ann)); form.setAnnouncementReceiptPaperForm(new AnnouncementReceiptPaperForm()); } if (entity.getReIssueFormId() != null) { ReIssueForm re = (ReIssueForm) findById(ReIssueForm.class, "reIssueFormId", entity.getReIssueFormId()); form.setReIssueForm(new ReIssueFormForm(re)); } if (entity.getDetailProductId() != null) { DetailProduct ann = (DetailProduct) findById(DetailProduct.class, "detailProductId", entity.getDetailProductId()); form.setDetailProduct(new DetailProductForm(ann)); } if (entity.getTestRegistrationId() != null) { TestRegistration ann = (TestRegistration) findById(TestRegistration.class, "testRegistrationId", entity.getTestRegistrationId()); form.setTestRegistration(new TestRegistrationForm(ann)); form.setConfirmImportSatistPaperForm(new ConfirmImportSatistPaperForm()); } //set contentXml // try { // Document document = CommonUtils.buildAllPublishDocument(entity.getFileId()); // form.setContentXml(StringUtils.escapeHtml(CommonUtils.convertDocument2String(document))); // } catch (Exception ex) { // LogUtil.addLog(ex);//binhnt sonar a160901 //// log.error(e); // } try { if (entity.getAnnouncementReceiptPaperId() != null) { AnnouncementReceiptPaper annp = (AnnouncementReceiptPaper) findById( AnnouncementReceiptPaper.class, "announcementReceiptPaperId", entity.getAnnouncementReceiptPaperId()); form.setAnnouncementReceiptPaperForm(new AnnouncementReceiptPaperForm(annp)); } if (entity.getConfirmImportSatistPaperId() != null) { ConfirmImportSatistPaper arp = (ConfirmImportSatistPaper) findById( AnnouncementReceiptPaper.class, "confirmImportSatistPaperId", entity.getAnnouncementReceiptPaperId()); form.setConfirmImportSatistPaperForm(new ConfirmImportSatistPaperForm(arp)); } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 // log.error(e); } } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 // log.error(e); } return form; } /** * * @param fileId * @return */ public FilesForm getFilesFullDetail(Long fileId) { Files entity = findById(fileId); FilesForm form = null; try { if (entity != null) { form = new FilesForm(entity); if (entity.getAnnouncementId() != null) { Announcement ann = (Announcement) findById(Announcement.class, "announcementId", entity.getAnnouncementId()); form.setAnnouncement(new AnnouncementForm(ann)); } if (entity.getReIssueFormId() != null) { ReIssueForm re = (ReIssueForm) findById(ReIssueForm.class, "reIssueFormId", entity.getReIssueFormId()); form.setReIssueForm(new ReIssueFormForm(re)); } if (entity.getDetailProductId() != null) { DetailProduct ann = (DetailProduct) findById(DetailProduct.class, "detailProductId", entity.getDetailProductId()); form.setDetailProduct(new DetailProductForm(ann)); } if (entity.getTestRegistrationId() != null) { TestRegistration ann = (TestRegistration) findById(TestRegistration.class, "testRegistrationId", entity.getTestRegistrationId()); form.setTestRegistration(new TestRegistrationForm(ann)); } form.setLstMainlyTarget(getMainlyTargetOfFile(fileId)); form.setLstBioTarget(getProductTargetOfFile(fileId, 1l)); form.setLstHeavyMetal(getProductTargetOfFile(fileId, 2l)); form.setLstChemical(getProductTargetOfFile(fileId, 3l)); form.setLstAttachs(getAttachsOfFile(fileId)); form.setLstQualityControl(getQualityControlOfFile(fileId)); } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 // log.error(e); } return form; } /** * Get clone files binhnt53 140417 * * @param fileId * @return */ public FilesForm getCloneFilesDetail(Long fileId) {// // Files entity = (Files) findById(Files.class, "originalId", fileId); Files entity = findIsItempObj(0L, fileId, 0L, true); FilesForm form = null; try { if (entity != null && entity.getFileId() != null && entity.getFileId() > 0L) { form = new FilesForm(entity); if (entity.getAnnouncementId() != null) { // Announcement objClone = (Announcement) findById(Announcement.class, "announcementId", entity.getAnnouncementId()); AnnouncementDAOHE objDaohe = new AnnouncementDAOHE(); Announcement objClone = objDaohe.findIsItempObj(entity.getAnnouncementId(), 0L, 0L, true); if (objClone != null && objClone.getAnnouncementId() != null) { form.setAnnouncement(new AnnouncementForm(objClone)); form.setAnnouncementReceiptPaperForm(new AnnouncementReceiptPaperForm()); } } if (entity.getReIssueFormId() != null) { // ReIssueForm objClone = (ReIssueForm) findById(ReIssueForm.class, "reIssueFormId", entity.getReIssueFormId()); ReIssueFormDAOHE objDaohe = new ReIssueFormDAOHE(); ReIssueForm objClone = objDaohe.findIsItempObj(entity.getReIssueFormId(), 0L, 0L, true); if (objClone != null && objClone.getReIssueFormId() != null) { form.setReIssueForm(new ReIssueFormForm(objClone)); } } if (entity.getDetailProductId() != null) { // DetailProduct objClone = (DetailProduct) findById(DetailProduct.class, "detailProductId", entity.getDetailProductId()); DetailProductDAOHE objDaohe = new DetailProductDAOHE(); DetailProduct objClone = objDaohe.findIsItempObj(entity.getDetailProductId(), 0L, 0L, true); if (objClone != null && objClone.getDetailProductId() != null) { form.setDetailProduct(new DetailProductForm(objClone)); } } if (entity.getTestRegistrationId() != null) { // TestRegistration objClone = (TestRegistration) findById(TestRegistration.class, "testRegistrationId", entity.getTestRegistrationId()); TestRegistrationDAOHE objDaohe = new TestRegistrationDAOHE(); TestRegistration objClone = objDaohe.findIsItempObj(entity.getTestRegistrationId(), 0L, 0L, true); if (objClone != null && objClone.getTestRegistrationId() != 0) { form.setTestRegistration(new TestRegistrationForm(objClone)); form.setConfirmImportSatistPaperForm(new ConfirmImportSatistPaperForm()); } } } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 // log.error(e); } return form; } /** * Gi h s cho c quan x l K ton xc nhn h s * * @param fileId * @param deptId * @param userId * @param userName * @param businessId * @param businessName * @return */ public boolean assignFileToDept(Long fileId, Long deptId, Long userId, String userName, Long businessId, String businessName) { boolean bReturn = true; try { Files bo = findById(fileId); DepartmentDAOHE ddhe = new DepartmentDAOHE(); Date dateNow = getSysdate(); Department dept = ddhe.findById(deptId); Long processStatus = bo.getStatus(); bo.setAgencyId(dept.getDeptId()); bo.setAgencyName(dept.getDeptName()); bo.setModifyDate(dateNow); ProcedureDAOHE pdhe = new ProcedureDAOHE(); Procedure pro = pdhe.findById(bo.getFileType()); if (pro != null && pro.getDeadline() != null) { Date dt = DateTimeUtils.getAddDate(dateNow, 0, pro.getDeadline().intValue()); bo.setDeadline(dt); } if (bo.getStatus().equals(Constants.FILE_STATUS.NEW_CREATE) || bo.getStatus().equals(Constants.FILE_STATUS.RECEIVED_REJECT)) { bo.setStatus(Constants.FILE_STATUS.NEW); bo.setDisplayStatus(getFileStatusName(Constants.FILE_STATUS.NEW)); if (processStatus.equals(Constants.FILE_STATUS.RECEIVED_REJECT)) { ProcessDAOHE psdhe = new ProcessDAOHE(); Process p = psdhe.getProcessByAction(fileId, Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, processStatus, Constants.FILE_STATUS.NEW_CREATE); if (p != null) { p.setStatus(bo.getStatus()); p.setLastestComment("Doanh nghip gi Sa i b sung"); getSession().update(p); } } } if (processStatus.equals(Constants.FILE_STATUS.EVALUATED_TO_ADD) || processStatus.equals(Constants.FILE_STATUS.RECEIVED_REJECT_TO_ADD)) { bo.setStatus(Constants.FILE_STATUS.NEW_TO_ADD); bo.setDisplayStatus(getFileStatusName(Constants.FILE_STATUS.NEW_TO_ADD)); //update process ProcessDAOHE psdhe = new ProcessDAOHE(); Process p = psdhe.getProcessByAction(fileId, Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, processStatus, Constants.FILE_STATUS.NEW_CREATE); if (p != null) { p.setStatus(bo.getStatus()); p.setLastestComment("Doanh nghip gi Sa i b sung"); getSession().update(p); } } bo.setSendDate(dateNow); //140623 THIET LAP HAN TIEP NHAN HO SO ResourceBundle rb = ResourceBundle.getBundle("config"); Procedure procedurebo; ProcedureDAOHE procedureDAOHE = new ProcedureDAOHE(); procedurebo = procedureDAOHE.findById(bo.getFileType()); int TN = 0; try { TN = Integer.parseInt(rb.getString(procedurebo.getDescription() + "_TN")); } catch (NumberFormatException ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } if (TN > 0) { bo.setDeadlineReceived(getDateWorkingTime(TN)); } //Hiepvv Set defalt TitleEditATTP = TitleEdit AND ContentsEditATTP = ContentsEdit if (bo.getTitleEdit() != null) { bo.setTitleEditATTP(bo.getTitleEdit()); } if (bo.getContentsEdit() != null) { bo.setContentsEditATTP(bo.getContentsEdit()); } //140623 THIET LAP HAN TIEP NHAN HO SO getSession().update(bo); // gui den cho co quan truoc Process p = new Process(); p.setObjectId(fileId); p.setObjectType(Constants.OBJECT_TYPE.FILES); p.setSendDate(dateNow); p.setSendGroup(businessName); p.setSendGroupId(businessId); p.setSendUserId(userId); p.setSendUser(userName); p.setReceiveDate(dateNow); // String deptCode = rb.getString("deptCode"); if (deptCode == null) { deptCode = "ATTP"; } DepartmentDAOHE dphe = new DepartmentDAOHE(); Department dep = dphe.findByDeptCode(deptCode); if (dep != null) { p.setReceiveGroup(dep.getDeptName()); p.setReceiveGroupId(dep.getDeptId()); } else { p.setReceiveGroup(dept.getDeptName()); p.setReceiveGroupId(dept.getDeptId()); } p.setProcessType(Constants.PROCESS_TYPE.MAIN); //140404 binhnt53 if (bo.getStatus().equals(Constants.FILE_STATUS.NEW) || bo.getStatus().equals(Constants.FILE_STATUS.RECEIVED_REJECT)) { p.setProcessStatus(Constants.FILE_STATUS.NEW); // De xu ly } else { p.setProcessStatus(Constants.FILE_STATUS.NEW_TO_ADD); // De xu ly } // p.setProcessStatus(Constants.FILE_STATUS.NEW); // De xu ly //!140404 binhnt53 // if (lst != null && lst.size() > 0) { //140405 if (bo.getStatus().equals(Constants.FILE_STATUS.EVALUATED_TO_ADD) == true) { p.setStatus(Constants.FILE_STATUS.ASSIGNED); } else { p.setStatus(Constants.FILE_STATUS.NEW_CREATE); } p.setIsActive(Constants.ACTIVE_STATUS.ACTIVE); getSession().save(p); } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; // log.error(en.getMessage()); } return bReturn; } /** * Tm h s k duyt * * @param form * @param deptId * @param userId * @param start * @param count * @param sortField * @return */ public GridResult searchFilesToSign(FilesForm form, Long deptId, Long userId, int start, int count, String sortField) { GridResult gr; try { String hql = " from Files f where f.isActive=1 and (f.isTemp = null or f.isTemp = 0 ) "; List lstParam = new ArrayList(); if (form != null) { if (form.getFileCode() != null && !"".equals(form.getFileCode().trim())) { hql += " AND lower(f.fileCode) like ? ESCAPE '/' "; lstParam.add(StringUtils.toLikeString(form.getFileCode().toLowerCase().trim())); } if (form.getAnnouncementNo() != null && !"".equals(form.getAnnouncementNo().trim())) { hql += " AND lower(f.announcementNo) like ? ESCAPE '/' "; lstParam.add(StringUtils.toLikeString(form.getAnnouncementNo().toLowerCase().trim())); } if (form.getBusinessName() != null && !"".equals(form.getBusinessName().trim())) { hql += " AND lower(f.businessName) like ? ESCAPE '/' "; lstParam.add(StringUtils.toLikeString(form.getBusinessName().toLowerCase().trim())); } if (form.getBusinessLicence() != null && !"".equals(form.getBusinessLicence().trim())) { hql += " AND lower(f.businessLicence) like ? ESCAPE '/' "; lstParam.add(StringUtils.toLikeString(form.getBusinessLicence().toLowerCase().trim())); } if (form.getBusinessAddress() != null && !"".equals(form.getBusinessAddress().trim())) { hql += " AND lower(f.businessAddress) like ? ESCAPE '/' "; lstParam.add(StringUtils.toLikeString(form.getBusinessAddress().toLowerCase().trim())); } if (form.getProductName() != null && !"".equals(form.getProductName().trim())) { hql += " AND lower(f.productName) like ? ESCAPE '/' "; lstParam.add(StringUtils.toLikeString(form.getProductName().toLowerCase().trim())); } if (form.getNationName() != null && !"".equals(form.getNationName().trim())) { hql += " AND lower(f.nationName) like ? ESCAPE '/' "; lstParam.add(StringUtils.toLikeString(form.getNationName().toLowerCase().trim())); } if (form.getManufactureName() != null && !"".equals(form.getManufactureName().trim())) { hql += " AND lower(f.manufactureName) like ? ESCAPE '/' "; lstParam.add(StringUtils.toLikeString(form.getManufactureName().toLowerCase().trim())); } if (form.getManufactureAddress() != null && !"".equals(form.getManufactureAddress().trim())) { hql += " AND lower(f.manufactureAddress) like ? ESCAPE '/' "; lstParam.add(StringUtils.toLikeString(form.getManufactureAddress().toLowerCase().trim())); } if (form.getMatchingTarget() != null && !"".equals(form.getMatchingTarget().trim())) { hql += " AND lower(f.matchingTarget) like ? ESCAPE '/' "; lstParam.add(StringUtils.toLikeString(form.getMatchingTarget().toLowerCase().trim())); } if (form.getFileType() != null && form.getFileType() != -1) { hql += " AND f.fileType = ? "; lstParam.add(form.getFileType()); } } hql += " and (f.status=? or f.status = ? or f.status = ? or f.status = ?)"; // lstParam.add(Constants.FILE_STATUS.APPROVED); // lstParam.add(Constants.FILE_STATUS.SIGNING); // lstParam.add(Constants.FILE_STATUS.LICENSING); // lstParam.add(Constants.FILE_STATUS.SIGNED); // lstParam.add(Constants.FILE_STATUS.REJECT); lstParam.add(Constants.FILE_STATUS.APPROVED); lstParam.add(Constants.FILE_STATUS.SIGNED); if (deptId != null) { hql += " AND f.agencyId = ? "; lstParam.add(deptId); } Query countQuery = getSession().createQuery("select count(f) " + hql); Query query = getSession().createQuery("select f " + hql + " order by f.modifyDate desc "); for (int i = 0; i < lstParam.size(); i++) { query.setParameter(i, lstParam.get(i)); countQuery.setParameter(i, lstParam.get(i)); } query.setFirstResult(start); query.setMaxResults(count); int total = Integer.parseInt(countQuery.uniqueResult().toString()); List lstResult = query.list(); gr = new GridResult(total, lstResult); return gr; } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 // log.error(ex.getMessage()); gr = new GridResult(0, null); } return gr; } /** * Tham dinh ho so - chuyen vien * * @param form * @param deptId ma don vi * @param deptName ten don vi * @param userId ma nguoi dung * @param userName ten nguoi dung * @return */ public boolean onEvaluateOld(FilesForm form, Long deptId, String deptName, Long userId, String userName) { boolean bReturn = true; try { Files file = findById(form.getFileId());//lay thong tin chi tiet ho so Date dateNow = getSysdate(); if (file == null) { bReturn = false; } else// Cap nhat trang thai ho so if ((file.getStatus() != null && form.getStatus() != null)//141225 binhnt update phan quyen ho so tham dinh && (file.getStatus().equals(Constants.FILE_STATUS.ASSIGNED)//da phan cong || file.getStatus().equals(Constants.FILE_STATUS.FEDBACK_TO_EVALUATE)//tra lai tham dinh lai || file.getStatus().equals(Constants.FILE_STATUS.EVALUATED)//tra lai tham dinh lai || file.getStatus().equals(Constants.FILE_STATUS.REVIEW_TO_ADD)// xem xt ni dung cv sbs LDC || file.getStatus().equals(Constants.FILE_STATUS.REVIEWED_TO_ADD)//? xem xt yu cu S?BS LDC || file.getStatus().equals(Constants.FILE_STATUS.APPROVE_TO_ADD)// ph duyt ni dung thng bo VT || file.getStatus().equals(Constants.FILE_STATUS.FEDBACK_TO_ADD)//da tra lai bo sung ho so || file.getStatus().equals(Constants.FILE_STATUS.RECEIVED_TO_ADD))) {//da tiep nhan ho so sdbs Long processStatus = file.getStatus(); if (form.getProductType() != null && form.getProductType() == 1L && form.getLeaderReviewId() != null) {//gui lanh dao tham dinh //150114 binhn53 add check TP k dc tham dinh ho so //new binhnt update 08102015 UsersDAOHE udaohe = new UsersDAOHE(); List<String> lstLeader = new ArrayList<String>(); lstLeader.add(Constants.POSITION.LEADER_OF_STAFF_T); lstLeader.add(Constants.POSITION.GDTT); List<Users> lstUser = udaohe.findLstUserByLstPosition(deptId, lstLeader); //!new binhnt update 08102015 //List<Users> lstUser = udaohe.findLstUserByPosition(deptId, Constants.POSITION.LEADER_OF_STAFF_T);//old 08102015 bbinhnt if (lstUser != null) { for (Users users : lstUser) { if (users.getUserId() != null && form.getLeaderReviewId().equals(users.getUserId())) { return false; } } } //!150114 binhn53 add check TP k dc tham dinh ho so file.setLeaderEvaluateId(form.getLeaderReviewId()); file.setLeaderEvaluateName(form.getLeaderReviewName()); file.setLeaderReviewId(null); file.setLeaderReviewName(null); file.setLeaderApproveId(null); file.setLeaderApproveName(null); } else if (form.getLeaderReviewId() != null) {//gui lanh dao de xem xet file.setLeaderReviewId(form.getLeaderReviewId()); file.setLeaderReviewName(form.getLeaderReviewName()); file.setLeaderEvaluateId(null); file.setLeaderEvaluateName(null); file.setLeaderApproveId(null); file.setLeaderApproveName(null); } else { //new binhnt update 08102015 UsersDAOHE udaohe = new UsersDAOHE(); List<String> lstLeader = new ArrayList<String>(); lstLeader.add(Constants.POSITION.LEADER_OF_STAFF_T); lstLeader.add(Constants.POSITION.GDTT); Users ubo; List<Users> lstLeaderOfDept = udaohe.findLstUserByLstPosition(deptId, lstLeader); if (lstLeaderOfDept != null && lstLeaderOfDept.size() > 0) { ubo = lstLeaderOfDept.get(0); file.setLeaderReviewId(ubo.getUserId()); file.setLeaderReviewName(ubo.getFullName()); file.setLeaderApproveId(null); file.setLeaderApproveName(null); } } file.setStatus(form.getStatus()); // neu tra lai de bo sung -> thiet lap bien have_temp = 1 de biet ma tao ra history khi sua doi if (form.getStatus().equals(Constants.FILE_STATUS.EVALUATED_TO_ADD)) { file.setHaveTemp(1l); } file.setDisplayStatus(getFileStatusName(form.getStatus())); String dateTime = DateTimeUtils.convertDateToString(dateNow, "dd/MM/yyyy HH:mm"); //file.setStaffRequest(userName + " " + dateTime + ":\n" + form.getStaffRequest()); // String prefix = userName + " " + dateTime + ":\n"; if (form.getStaffRequest() != null && form.getStaffRequest().trim().length() > 0) { file.setStaffRequest(form.getStaffRequest()); } file.setModifyDate(dateNow); if (form.getEffectiveDate() != null) { file.setEffectiveDate(form.getEffectiveDate()); } else { file.setEffectiveDate(Constants.EFFECTIVEDATE.THREE); } file.setIsTypeChange(form.getIsTypeChange()); file.setLastType(form.getLastType()); //Cap nhat process cu ProcessDAOHE pdhe = new ProcessDAOHE(); Process p = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, processStatus, Constants.FILE_STATUS.NEW_CREATE); if (p != null) { p.setStatus(form.getStatus()); p.setLastestComment(form.getStaffRequest()); getSession().update(p); } //!Cap nhat process cu if (form.getStatus().equals(Constants.FILE_STATUS.EVALUATED) || form.getStatus().equals(Constants.FILE_STATUS.FEDBACK_TO_ADD)) { //tham xet dat, tham xet khong dat deu gui len cho to truong to tham xet xem xet Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setReceiveDate(dateNow); if (form.getProductType() != null && form.getProductType() == 1L && file.getLeaderEvaluateId() != null) { newP.setReceiveUserId(file.getLeaderEvaluateId()); newP.setReceiveUser(file.getLeaderEvaluateName()); } else if (file.getLeaderReviewId() != null) { newP.setReceiveUserId(file.getLeaderReviewId()); newP.setReceiveUser(file.getLeaderReviewName()); } newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); newP.setProcessStatus(form.getStatus()); // De xu ly newP.setStatus(0l); // Moi den chua xu ly newP.setIsActive(1l); getSession().save(newP); } else { if (form.getStatus().equals(Constants.FILE_STATUS.EVALUATED_TO_ADD)) { //tao thong bao yeu cau sdbs gui toi doanh nghiep Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setReceiveDate(dateNow); ProcessDAOHE psdhe = new ProcessDAOHE(); Process pold = psdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.NEW, Constants.FILE_STATUS.RECEIVED); if (pold != null) { newP.setReceiveGroupId(pold.getSendGroupId()); newP.setReceiveGroup(pold.getSendGroup()); newP.setReceiveUserId(pold.getSendUserId()); newP.setReceiveUser(pold.getSendUser()); } else { newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); } newP.setProcessStatus(form.getStatus()); //De xu ly newP.setStatus(0l); //Moi den chua xu ly newP.setIsActive(1l); getSession().save(newP); //xa bn ghi temp trc nu c (lu vo vng lu tr) updateSetNotLastIsTemp(file.getFileId()); //xa bn ghi temp trc nu c (lu vo vng lu tr) ProcessCommentDAOHE pcdaohe = new ProcessCommentDAOHE(); pcdaohe.updateSetNotLastIsTemp(file.getFileId()); } if (form.getStatus().equals(Constants.FILE_STATUS.EVALUATE_TO_ADD)) {//da soan du thao thong bao sdbs ho so /* ho so sau khi da tra lai chuyen vien de soan du thao tb sdbs cv vao tao ban du thao sau khi tao xong luu gui noi dung cho lanh dao phong xem xet */ Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setProcessStatus(form.getStatus()); // De xu ly newP.setStatus(Constants.ACTIVE_STATUS.DEACTIVE);// Moi den chua xu ly-150120 newP.setIsActive(Constants.ACTIVE_STATUS.ACTIVE);//-150120 newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setReceiveDate(dateNow); if (form.getLeaderReviewId() != null) { newP.setReceiveUserId(form.getLeaderReviewId()); file.setLeaderReviewId(form.getLeaderReviewId()); } if (form.getLeaderReviewName() != null) { newP.setReceiveUser(form.getLeaderReviewName()); file.setLeaderReviewName(form.getLeaderReviewName()); } newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); getSession().save(newP); //cap nhat noi dung thong bao - tao noi dung thong bao RequestComment rcbo = new RequestComment(); if (form.getStaffRequest() != null) { rcbo.setContent(form.getStaffRequest()); } else { rcbo.setContent("Chuyn vin cha c ni dung."); } rcbo.setCreateBy(userId); rcbo.setCreateDate(dateNow); rcbo.setUserId(userId); rcbo.setUserName(userName); rcbo.setStatus(1L); rcbo.setIsActive(1L); rcbo.setGroupId(deptId); rcbo.setGroupName(deptName); rcbo.setObjectId(form.getFileId()); rcbo.setRequestType(Constants.REQUEST_COMMENT_TYPE.TBSDBS);//-150120 rcbo.setIsLastChange(Constants.ACTIVE_STATUS.ACTIVE);//-150120 //!luu noi dung du thao //u150119 binhnt53 update li ni dung thng tin. RequestCommentDAOHE rqdaohe = new RequestCommentDAOHE(); RequestComment lastRQBo = rqdaohe.findLastRequestComment(file.getFileId(), Constants.ACTIVE_STATUS.ACTIVE); if (lastRQBo != null) { rcbo.setLastContent(lastRQBo.getContent()); lastRQBo.setIsLastChange(Constants.ACTIVE_STATUS.DEACTIVE); getSession().update(lastRQBo); } getSession().save(rcbo); //!u150119 binhnt53 update li ni dung thng tin. } //hieptq update 230415 if ((form.getStatus()).equals(Constants.FILE_STATUS.FEDBACK_TO_EVALUATE)) { Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setProcessStatus(p.getStatus()); // De xu ly newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setStatus(Constants.FILE_STATUS.NEW_CREATE); // Moi den chua xu ly newP.setIsActive(Constants.ACTIVE_STATUS.ACTIVE); newP.setReceiveDate(dateNow); if (p != null) { //lay process tham dinh ho so ProcessDAOHE psdhe = new ProcessDAOHE(); Process pold = psdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.EVALUATED, p.getStatus()); if (pold != null) { newP.setReceiveGroup(pold.getSendGroup()); newP.setReceiveGroupId(pold.getSendGroupId()); if (file != null && file.getStaffProcess() != null && file.getNameStaffProcess() != null) { newP.setReceiveUser(file.getNameStaffProcess()); newP.setReceiveUserId(file.getStaffProcess()); } else { newP.setReceiveUser(pold.getSendUser()); newP.setReceiveUserId(pold.getSendUserId()); } } else {//141218u binhnt53 fix loi ho so lanh dao phong tra lai voi pold = psdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.FEDBACK_TO_ADD, p.getStatus()); if (pold != null) { newP.setReceiveGroup(pold.getSendGroup()); newP.setReceiveGroupId(pold.getSendGroupId()); if (file != null && file.getStaffProcess() != null && file.getNameStaffProcess() != null) { newP.setReceiveUser(file.getNameStaffProcess()); newP.setReceiveUserId(file.getStaffProcess()); } else { newP.setReceiveUser(pold.getSendUser()); newP.setReceiveUserId(pold.getSendUserId()); } } else if (p != null) {// Gui lai cho chinh nguoi gui newP.setReceiveGroup(p.getSendGroup()); newP.setReceiveGroupId(p.getSendGroupId()); newP.setReceiveUser(p.getSendUser()); newP.setReceiveUserId(p.getSendUserId()); } } } getSession().save(newP); } } //insert noi dung tham dinh if (form.getEvaluationRecordsForm() != null) { EvaluationRecordsForm evaRecordForm = new EvaluationRecordsForm(); evaRecordForm.setCreateDate(dateNow); evaRecordForm.setSendDate(file.getSendDate()); evaRecordForm.setBusinessName(file.getBusinessName()); evaRecordForm.setBusinessAddress(file.getBusinessAddress()); evaRecordForm.setProductName(file.getProductName()); evaRecordForm.setLegal(form.getEvaluationRecordsForm().getLegal()); evaRecordForm.setLegalContent(form.getEvaluationRecordsForm().getLegalContent()); evaRecordForm.setFoodSafetyQuality(form.getEvaluationRecordsForm().getFoodSafetyQuality()); evaRecordForm.setFoodSafetyQualityContent( form.getEvaluationRecordsForm().getFoodSafetyQualityContent()); evaRecordForm.setEffectUtility(form.getEvaluationRecordsForm().getEffectUtility()); evaRecordForm .setEffectUtilityContent(form.getEvaluationRecordsForm().getEffectUtilityContent()); evaRecordForm.setFilesStatus(file.getStatus()); evaRecordForm.setMainContent(file.getStaffRequest()); evaRecordForm.setFirstStaffId(userId); evaRecordForm.setFirstStaffName(userName); evaRecordForm.setSecondStaffId(userId); evaRecordForm.setSecondStaffName(userName); evaRecordForm.setThirdStaffId(userId); evaRecordForm.setThirdStaffName(userName); evaRecordForm.setLeederStaffId(userId); evaRecordForm.setLeederStaffName(userName); evaRecordForm.setFilesId(file.getFileId()); EvaluationRecords evaluationRecordsBo; evaluationRecordsBo = evaRecordForm.convertToEntity(); getSession().save(evaluationRecordsBo); insertRequestComment(file.getFileId(), form, userId, userName, deptId, deptName, dateNow);//binhnt53 150130 } else if (form.getEvaluationRecordsFormOnGrid() != null) { EvaluationRecordsFormOnGrid evaRecordForm = new EvaluationRecordsFormOnGrid(); evaRecordForm.setCreateDate(dateNow); evaRecordForm.setSendDate(file.getSendDate()); evaRecordForm.setBusinessName(file.getBusinessName()); evaRecordForm.setBusinessAddress(file.getBusinessAddress()); evaRecordForm.setProductName(file.getProductName()); evaRecordForm.setLegal(form.getEvaluationRecordsForm().getLegal()); evaRecordForm.setLegalContent(form.getEvaluationRecordsForm().getLegalContent()); evaRecordForm.setFoodSafetyQuality(form.getEvaluationRecordsForm().getFoodSafetyQuality()); evaRecordForm.setFoodSafetyQualityContent( form.getEvaluationRecordsForm().getFoodSafetyQualityContent()); evaRecordForm.setEffectUtility(form.getEvaluationRecordsForm().getEffectUtility()); evaRecordForm .setEffectUtilityContent(form.getEvaluationRecordsForm().getEffectUtilityContent()); evaRecordForm.setFilesStatus(file.getStatus()); evaRecordForm.setMainContent(file.getStaffRequest()); evaRecordForm.setFirstStaffId(userId); evaRecordForm.setFirstStaffName(userName); evaRecordForm.setSecondStaffId(userId); evaRecordForm.setSecondStaffName(userName); evaRecordForm.setThirdStaffId(userId); evaRecordForm.setThirdStaffName(userName); evaRecordForm.setLeederStaffId(userId); evaRecordForm.setLeederStaffName(userName); evaRecordForm.setFilesId(file.getFileId()); EvaluationRecords evaluationRecordsBo; evaluationRecordsBo = evaRecordForm.convertToEntity(); getSession().save(evaluationRecordsBo); insertRequestComment(file.getFileId(), form, userId, userName, deptId, deptName, dateNow);//binhnt53 150130 } if (form.getStatus().equals(Constants.FILE_STATUS.EVALUATED_TO_ADD)) {//140721 binhnt try {//140627 THIET LAP HAN SDBS HO SO ResourceBundle rb = ResourceBundle.getBundle("config"); Procedure procedurebo; ProcedureDAOHE procedureDAOHE = new ProcedureDAOHE(); procedurebo = procedureDAOHE.findById(file.getFileType()); int SD = 0; try { SD = Integer.parseInt(rb.getString(procedurebo.getDescription() + "_SD")); } catch (NumberFormatException ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } if (SD > 0) { file.setDeadlineAddition(getDateWorkingTime(SD)); } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } //!140627 THIET LAP HAN SDBS HO SO //sms /* disable send sms binhnt53 150205 MessageSmsDAOHE msdhe = new MessageSmsDAOHE(); String msg = "Ho so ma: " + file.getFileCode() + " cua doanh nghiep: " + file.getBusinessName() + " dang trong trang thai: da thong bao yeu cau sdbs"; msdhe.saveMessageSMS(userId, file.getUserCreateId(), msg); */ //email MessageEmailDAOHE msedhe = new MessageEmailDAOHE(); String msge = "H s m: " + file.getFileCode() + " ca doanh nghip: " + file.getBusinessName() + " ang trong trng thi: ? thng bo yu cu sa i b sung."; msedhe.saveMessageEmail(userId, file.getUserCreateId(), msge); } //!140721 update(file); } else { log.error("Li h thng: Phn quy?n x l h s: " + file.getFileCode()); return false; } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } return bReturn; } /** * 260214 doi chieu ho so -comparison -binhnt53 * * @param form * @param deptId * @param deptName * @param userId * @param userName * @return */ public boolean onComparison(FilesForm form, Long deptId, String deptName, Long userId, String userName) {//db140425 boolean bReturn = true; try { Files file = findById(form.getFileId()); Date dateNow = getSysdate(); if (file == null) { bReturn = false; } else { Long isComparison = form.getIsComparison(); if (isComparison.equals(1L)) { file.setStatus(Constants.FILE_STATUS.COMPARED); file.setDisplayStatus(getFileStatusName(Constants.FILE_STATUS.COMPARED)); form.setStatus(Constants.FILE_STATUS.COMPARED); } else { file.setStatus(Constants.FILE_STATUS.COMPARED_FAIL); file.setDisplayStatus(getFileStatusName(Constants.FILE_STATUS.COMPARED_FAIL)); form.setStatus(Constants.FILE_STATUS.COMPARED_FAIL); } file.setModifyDate(dateNow); file.setComparisonContent(form.getComparisonContent()); file.setIsComparison(form.getIsComparison()); //cap nhat noi dung thong bao - tao noi dung thong bao RequestComment rcbo = new RequestComment(); rcbo.setContent(form.getComparisonContent()); rcbo.setCreateBy(userId); rcbo.setCreateDate(dateNow); rcbo.setUserId(userId); rcbo.setUserName(userName); rcbo.setStatus(1L); rcbo.setIsActive(1L); rcbo.setGroupId(deptId); rcbo.setGroupName(deptName); rcbo.setObjectId(form.getFileId()); rcbo.setRequestType(Constants.REQUEST_COMMENT_TYPE.TBDC);//-150120 rcbo.setIsLastChange(Constants.ACTIVE_STATUS.ACTIVE);//-150120 //u150119 binhnt53 RequestCommentDAOHE rqdaohe = new RequestCommentDAOHE(); RequestComment lastRQBo = rqdaohe.findLastRequestComment(file.getFileId(), Constants.ACTIVE_STATUS.ACTIVE); if (lastRQBo != null) { rcbo.setLastContent(lastRQBo.getContent()); lastRQBo.setIsLastChange(Constants.ACTIVE_STATUS.DEACTIVE); getSession().update(lastRQBo); } getSession().save(rcbo); //!u150119 binhnt53 //cap nhat noi dung thong bao - tao noi dung thong bao //update process cu ProcessDAOHE pdhe = new ProcessDAOHE(); if (isComparison.equals(1L)) { Process oldP = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.ALERT_COMPARISON, Constants.FILE_STATUS.NEW_CREATE); if (oldP != null) { oldP.setStatus(form.getStatus()); if (form.getRequestCommentForm() != null) { oldP.setLastestComment(form.getRequestCommentForm().getContent()); } getSession().update(oldP); } else { oldP = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.COMPARED_FAIL, Constants.FILE_STATUS.NEW_CREATE); if (oldP != null) { oldP.setStatus(form.getStatus()); if (form.getRequestCommentForm() != null) { oldP.setLastestComment(form.getRequestCommentForm().getContent()); } getSession().update(oldP); } } } else { Process oldP = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.COMPARED_FAIL, Constants.FILE_STATUS.NEW_CREATE); if (oldP != null) { oldP.setStatus(form.getStatus()); if (form.getRequestCommentForm() != null) { oldP.setLastestComment(form.getRequestCommentForm().getContent()); } getSession().update(oldP); } else { oldP = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.ALERT_COMPARISON, Constants.FILE_STATUS.NEW_CREATE); if (oldP != null) { oldP.setStatus(form.getStatus()); if (form.getRequestCommentForm() != null) { oldP.setLastestComment(form.getRequestCommentForm().getContent()); } getSession().update(oldP); } } } //tao process moi Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setReceiveDate(dateNow); newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setProcessStatus(form.getStatus()); // De xu ly newP.setStatus(0L); // Moi den chua xu ly newP.setIsActive(1l); //tim lanh dao phan cong de gui if (isComparison.equals(1L)) { newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); } else { //tim doanh nghiep Process pReceive = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.NEW, Constants.FILE_STATUS.RECEIVED); if (pReceive != null) { newP.setReceiveUser(pReceive.getSendUser()); newP.setReceiveUserId(pReceive.getSendUserId()); newP.setReceiveGroup(pReceive.getSendGroup()); newP.setReceiveGroupId(pReceive.getSendGroupId()); } else { newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); } } getSession().save(newP); getSession().update(file); } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } return bReturn; } //!comparison /** * Nhp kt qu xem xt * * @param form * @param deptId * @param deptName * @param userId * @param userName * @return */ public boolean onReview(FilesForm form, Long deptId, String deptName, Long userId, String userName) { boolean bReturn = true; try { Files file = findById(form.getFileId()); Date dateNow = getSysdate(); if (file == null) { bReturn = false; } else { // Cap nhat trang thai ho so file.setStatus(form.getStatus()); file.setDisplayStatus(getFileStatusName(form.getStatus())); String dateTime = DateTimeUtils.convertDateToString(dateNow, "dd/MM/yyyy HH:mm"); file.setLeaderStaffRequest(userName + " " + dateTime + ":\n" + form.getLeaderStaffRequest()); file.setDisplayRequest(form.getLeaderStaffRequest()); file.setModifyDate(dateNow); file.setEvaluateAddDate(dateNow); // Cap nhat process ProcessDAOHE pdhe = new ProcessDAOHE(); Process p = pdhe.getWorkingProcess(form.getFileId(), Constants.OBJECT_TYPE.FILES, deptId, userId); if (p != null) { p.setStatus(form.getStatus()); p.setLastestComment(form.getLeaderStaffRequest()); getSession().update(p); } else { ProcessDAOHE psdhe = new ProcessDAOHE(); Process pold = psdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.FEDBACK_TO_ADD, Constants.FILE_STATUS.NEW_CREATE); if (pold != null) { pold.setStatus(form.getStatus()); pold.setLastestComment(form.getLeaderStaffRequest()); getSession().update(pold); } } // Neu co luong thi chay theo luong if (file.getFlowId() != null && file.getFlowId() > 0) { FlowDAOHE fdhe = new FlowDAOHE(); if (Constants.FILE_STATUS.REVIEWED.equals(form.getStatus())) { fdhe.moveDocumentToNextNodeByAction(deptId, deptName, userId, userName, file.getFileId(), "xem xt"); } else { //fdhe.moveDocumentToNextNodeByAction(deptId, deptName, userId, userName, file.getFileId(), "tr li"); //fdhe.moveDocumentToPreviousNode(deptId, deptName, userId, userName, file.getFileId(), file.getPreviousNodeId()); Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setProcessStatus(form.getStatus()); // De xu ly newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setStatus(0l); // Moi den chua xu ly newP.setIsActive(1l); if (form.getStatus().equals(Constants.FILE_STATUS.REVIEWED)) { newP.setReceiveDate(dateNow); newP.setReceiveGroup(file.getAgencyName()); newP.setReceiveGroupId(file.getAgencyId()); } else if (p != null) { if (form.getStatus().equals(Constants.FILE_STATUS.EVALUATED_TO_ADD)) {//140722 - da thong bao yeu cau sdbs newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); // newP.setReceiveDate(dateNow); newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); newP.setProcessStatus(form.getStatus()); //De xu ly newP.setStatus(0l); //Moi den chua xu ly newP.setIsActive(1l); //xa bn ghi temp trc nu c (lu vo vng lu tr) updateSetNotLastIsTemp(file.getFileId());// } else { //lay process tham dinh ho so ProcessDAOHE psdhe = new ProcessDAOHE(); Process pold = psdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.FEDBACK_TO_ADD, Constants.FILE_STATUS.NEW_CREATE); if (pold != null) { newP.setReceiveDate(dateNow); newP.setReceiveGroup(pold.getSendGroup()); newP.setReceiveGroupId(pold.getSendGroupId()); newP.setReceiveUser(pold.getSendUser()); newP.setReceiveUserId(pold.getSendUserId()); } else { newP.setReceiveDate(dateNow); newP.setReceiveGroup(p.getSendGroup()); newP.setReceiveGroupId(p.getSendGroupId()); newP.setReceiveUser(p.getSendUser()); newP.setReceiveUserId(p.getSendUserId()); } } } getSession().save(newP); } } else {// Neu khong co luong thi tu xu thoi :-) // Xem xet oke, gui tiep cho cho lanh dao co quan phe duyet Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setProcessStatus(form.getStatus()); // De xu ly newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setStatus(0l); // Moi den chua xu ly newP.setIsActive(1l); if (form.getStatus().equals(Constants.FILE_STATUS.REVIEWED)) { // Gui toi chinh don vi quan ly de phe duyet newP.setReceiveDate(dateNow); newP.setReceiveGroup(file.getAgencyName()); newP.setReceiveGroupId(file.getAgencyId()); } else { if (form.getStatus().equals(Constants.FILE_STATUS.EVALUATED_TO_ADD)) {//140722 - da thong bao yeu cau sdbs newP.setReceiveDate(dateNow); newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); //xa bn ghi temp trc nu c (lu vo vng lu tr) updateSetNotLastIsTemp(file.getFileId());// } if (form.getStatus().equals(Constants.FILE_STATUS.FEDBACK_TO_ADD)) {// Tra lai cho chuyen vien tham dinh if (p != null) { //lay process tham dinh ho so ProcessDAOHE psdhe = new ProcessDAOHE(); Process pold = psdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.FEDBACK_TO_ADD, Constants.FILE_STATUS.NEW_CREATE); if (pold != null) { newP.setReceiveDate(dateNow); newP.setReceiveGroup(pold.getSendGroup()); newP.setReceiveGroupId(pold.getSendGroupId()); newP.setReceiveUser(pold.getSendUser()); newP.setReceiveUserId(pold.getSendUserId()); } else { // Gui lai cho chinh nguoi gui newP.setReceiveDate(dateNow); newP.setReceiveGroup(p.getSendGroup()); newP.setReceiveGroupId(p.getSendGroupId()); newP.setReceiveUser(p.getSendUser()); newP.setReceiveUserId(p.getSendUserId()); } } } if (form.getStatus().equals(Constants.FILE_STATUS.FEDBACK_TO_EVALUATE)) {// Tra lai cho chuyen vien tham dinh if (p != null) { //lay process tham dinh ho so ProcessDAOHE psdhe = new ProcessDAOHE(); Process pold = psdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.EVALUATED, Constants.FILE_STATUS.NEW_CREATE); if (pold != null) { newP.setReceiveDate(dateNow); newP.setReceiveGroup(pold.getSendGroup()); newP.setReceiveGroupId(pold.getSendGroupId()); newP.setReceiveUser(pold.getSendUser()); newP.setReceiveUserId(pold.getSendUserId()); } else {//141218u binhnt53 update fix loi ho so khi cv tham dinh k dat tra lai cho chuyen vien pold = psdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.FEDBACK_TO_ADD, Constants.FILE_STATUS.NEW_CREATE); if (pold != null) { newP.setReceiveDate(dateNow); newP.setReceiveGroup(pold.getSendGroup()); newP.setReceiveGroupId(pold.getSendGroupId()); newP.setReceiveUser(pold.getSendUser()); newP.setReceiveUserId(pold.getSendUserId()); } else if (p != null) { // Gui lai cho chinh nguoi gui newP.setReceiveDate(dateNow); newP.setReceiveGroup(p.getSendGroup()); newP.setReceiveGroupId(p.getSendGroupId()); newP.setReceiveUser(p.getSendUser()); newP.setReceiveUserId(p.getSendUserId()); } } } } if (form.getStatus().equals(Constants.FILE_STATUS.REVIEWED_TO_ADD)) { //lay process tham dinh ho so ProcessDAOHE psdhe = new ProcessDAOHE(); Process pold = psdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.FEDBACK_TO_ADD, Constants.FILE_STATUS.NEW_CREATE); if (pold != null) { newP.setReceiveDate(dateNow); newP.setReceiveGroup(pold.getSendGroup()); newP.setReceiveGroupId(pold.getSendGroupId()); newP.setReceiveUser(pold.getSendUser()); newP.setReceiveUserId(pold.getSendUserId()); } else { newP.setReceiveDate(dateNow); newP.setReceiveGroup(p.getSendGroup()); newP.setReceiveGroupId(p.getSendGroupId()); newP.setReceiveUser(p.getSendUser()); newP.setReceiveUserId(p.getSendUserId()); } } } getSession().save(newP); } //insert noi dung tham dinh if (form.getEvaluationRecordsForm() != null) { EvaluationRecordsDAOHE evaluationRecordsDAOHE = new EvaluationRecordsDAOHE(); EvaluationRecords evaluationRecords = evaluationRecordsDAOHE.findFilesByFileId(file); if (evaluationRecords != null) { evaluationRecords.setSendDate(file.getSendDate()); evaluationRecords.setLegalL(form.getEvaluationRecordsForm().getLegalL()); evaluationRecords.setLegalContentL(form.getEvaluationRecordsForm().getLegalContentL()); evaluationRecords .setFoodSafetyQualityL(form.getEvaluationRecordsForm().getFoodSafetyQualityL()); evaluationRecords.setFoodSafetyQualityContentL( form.getEvaluationRecordsForm().getFoodSafetyQualityContentL()); evaluationRecords.setEffectUtilityL(form.getEvaluationRecordsForm().getEffectUtilityL()); evaluationRecords.setEffectUtilityContentL( form.getEvaluationRecordsForm().getEffectUtilityContentL()); evaluationRecords.setFilesStatusL(file.getStatus()); evaluationRecords.setMainContentL(file.getLeaderRequest()); getSession().update(evaluationRecords); } } //140721 binhnt if (form.getStatus().equals(Constants.FILE_STATUS.EVALUATED_TO_ADD)) { try {//140627 THIET LAP HAN SDBS HO SO ResourceBundle rb = ResourceBundle.getBundle("config"); Procedure procedurebo; ProcedureDAOHE procedureDAOHE = new ProcedureDAOHE(); procedurebo = procedureDAOHE.findById(file.getFileType()); int SD = 0; try { SD = Integer.parseInt(rb.getString(procedurebo.getDescription() + "_SD")); } catch (NumberFormatException ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } if (SD > 0) { file.setDeadlineAddition(getDateWorkingTime(SD)); } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } //!140627 THIET LAP HAN SDBS HO SO //sms MessageSmsDAOHE msdhe = new MessageSmsDAOHE(); String msg = "Ho so ma: " + file.getFileCode() + " cua doanh nghiep: " + file.getBusinessName() + " dang trong trang thai: da thong bao yeu cau sdbs"; msdhe.saveMessageSMS(userId, file.getUserCreateId(), msg); //email MessageEmailDAOHE msedhe = new MessageEmailDAOHE(); String msge = "H s m: " + file.getFileCode() + " ca doanh nghip: " + file.getBusinessName() + " ang trong trng thi: ? thng bo yu cu sa i b sung."; msedhe.saveMessageEmail(userId, file.getUserCreateId(), msge); } //!140721 update(file); } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } return bReturn; } /** * * @param form * @param deptId * @param deptName * @param userId * @param userName * @return */ public boolean onUpdateProcessToAddition(FilesForm form, Long deptId, String deptName, Long userId, String userName) { boolean bReturn = true; Files file = findById(form.getFileId()); if (file == null) { bReturn = false; } else { // Long objectId = file.getFileId(); // ProcessDAOHE psdhe = new ProcessDAOHE(); // List<Process> lstPs = psdhe.getProcessOfOffice(objectId, Constants.OBJECT_TYPE.FILES); // if (!lstPs.isEmpty()) { // for (Process process : lstPs) { // if (process.getStatus().equals(Constants.FILE_STATUS.ALERT_COMPARISON) // && process.getStatus().equals(Constants.FILE_STATUS.ALERT_COMPARISON)) { // } // } // } } return bReturn; } /** * Ph duyt h s * * @param form * @param deptId * @param deptName * @param userId * @param userName * @return */ public boolean onApprove(FilesForm form, Long deptId, String deptName, Long userId, String userName) { boolean bReturn = true; try { Files file = findById(form.getFileId()); Date dateNow = getSysdate(); if (file == null) { bReturn = false; } else { Long processStatus = file.getStatus(); /* REVIEWED = 5L;//? xem xt kt qu REVIEW_TO_ADD = 26L;// xem xt ni dung cv sbs REVIEW_TO_BOSS = 29L;//H s trnh cc trng xem xt APPROVE_TO_LEADER = 30L;//H s cc trng quyt nh APPROVE_TO_ADD ph duyt cng vn sa i b sung. EVALUATE_TO_ADD //Da soan du thao sua doi bo sung */ if (processStatus != null//141225 BINHNT update phan quyen ho so tham dinh && (processStatus.equals(Constants.FILE_STATUS.REVIEWED)//? xem xt kt qu || processStatus.equals(Constants.FILE_STATUS.REVIEW_TO_ADD)//? xem xt ni dung cv sbs || processStatus.equals(Constants.FILE_STATUS.APPROVE_TO_ADD)//? ph duyt ni dung thng bo VT || processStatus.equals(Constants.FILE_STATUS.REVIEW_TO_BOSS)//H s trnh cc trng xem xt || processStatus.equals(Constants.FILE_STATUS.APPROVE_TO_LEADER)//H s cc trng quyt nh || processStatus.equals(Constants.FILE_STATUS.EVALUATE_TO_ADD) //? son d tho sa i b sung || processStatus.equals(Constants.FILE_STATUS.FEDBACK_TO_ADD) //? tr li b sung h s || processStatus.equals(Constants.FILE_STATUS.EVALUATED) //? tr li b sung h s )) { file.setStatus(form.getStatus()); file.setDisplayStatus(getFileStatusName(form.getStatus())); String dateTime = DateTimeUtils.convertDateToString(dateNow, "dd/MM/yyyy HH:mm"); if (!form.getStatus().equals(Constants.FILE_STATUS.APPROVE_TO_ADD)) { file.setLeaderRequest(userName + " " + dateTime + ":\n" + form.getLeaderRequest()); file.setDisplayRequest(form.getLeaderRequest()); } else { file.setLeaderRequest(userName + " " + dateTime + ":\n" + "? ph duyt ni dung cng vn yu cu S?BS"); file.setDisplayRequest("? ph duyt ni dung cng vn yu cu S?BS"); } file.setModifyDate(dateNow); file.setLeaderStaffSignId(userId); file.setLeaderStaffSignName(userName); // Cap nhat process ProcessDAOHE pdhe = new ProcessDAOHE(); Process oldP = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, processStatus, Constants.FILE_STATUS.NEW_CREATE); if (oldP != null) { oldP.setStatus(form.getStatus()); oldP.setLastestComment(form.getLeaderRequest()); getSession().update(oldP); } //to process mi vi x l hin ti Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setProcessStatus(form.getStatus()); // De xu ly newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setStatus(0l); // Moi den chua xu ly newP.setIsActive(1l); newP.setReceiveDate(dateNow); if (form.getStatus().equals(Constants.FILE_STATUS.APPROVED)) {//tr v? cho vn th thng bo i chiu newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); //cap nhat noi dung thong bao - tao noi dung thong bao RequestComment rcbo = new RequestComment(); rcbo.setContent(form.getLeaderStaffRequest()); file.setComparisonContent(form.getLeaderStaffRequest()); rcbo.setCreateBy(userId); rcbo.setCreateDate(dateNow); rcbo.setUserId(userId); rcbo.setUserName(userName); rcbo.setStatus(1L); rcbo.setIsActive(1L); rcbo.setGroupId(deptId); rcbo.setGroupName(deptName); rcbo.setObjectId(form.getFileId()); rcbo.setRequestType(Constants.REQUEST_COMMENT_TYPE.TBDC); rcbo.setIsLastChange(Constants.ACTIVE_STATUS.ACTIVE); //150119 binhnt53 update bo sung last change RequestCommentDAOHE rqdaohe = new RequestCommentDAOHE(); RequestComment lastRQBo = rqdaohe.findLastRequestComment(file.getFileId(), Constants.ACTIVE_STATUS.ACTIVE); if (lastRQBo != null) { rcbo.setLastContent(lastRQBo.getContent()); lastRQBo.setIsLastChange(Constants.ACTIVE_STATUS.DEACTIVE); getSession().update(lastRQBo); } getSession().save(rcbo); //!binhnt53 update bo sung last change ProcedureDAOHE pdheNew = new ProcedureDAOHE(); Procedure pro = pdheNew.findById(file.getFileType()); //Hiepvv 0803 Khong xet lai phi cho SDBS sau cong bo if (!"01".equals(pro.getCode()) && !"02".equals(pro.getCode()) && !"announcementFile05".equals(pro.getDescription())) { file.setIsFee(0l); //update binhnt // if ("true".equals(ResourceBundleUtil.getString("send_service", "config"))) { // Helper h = new Helper(); // h.sendMs_340(file.getFileId(), "Ho so ma: " + file.getFileCode() + " Da duoc phe duyet yeu cau nop phi ho so."); // } } /* i lung binhnt53 140914 // Phe duyet oke, chuyen ho so xuong cho van thu tra ho so Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setProcessStatus(form.getStatus()); // De xu ly newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setStatus(0l); // Moi den chua xu ly newP.setIsActive(1l); newP.setReceiveDate(dateNow); //lay process cua VT tiep nhan Process pold = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.RECEIVED, Constants.FILE_STATUS.ASSIGNED); if (pold != null) { newP.setReceiveGroup(pold.getSendGroup()); newP.setReceiveGroupId(pold.getSendGroupId()); newP.setReceiveUser(pold.getSendUser()); newP.setReceiveUserId(pold.getSendUserId()); } else { newP.setReceiveUser(deptName); newP.setReceiveUserId(deptId); } RequestComment rcbo = new RequestComment(); rcbo.setContent(form.getLeaderRequest()); file.setComparisonContent(form.getLeaderRequest()); file.setIsFee(0L);//bay gio tinh phi giay cong bo rcbo.setCreateBy(userId); rcbo.setCreateDate(dateNow); rcbo.setUserId(userId); rcbo.setUserName(userName); rcbo.setStatus(1L); rcbo.setIsActive(1L); rcbo.setGroupId(deptId); rcbo.setGroupName(deptName); rcbo.setIsLastChange(Constants.ACTIVE_STATUS.ACTIVE); rcbo.setObjectId(form.getFileId()); rcbo.setRequestType("YKPD"); getSession().save(rcbo); getSession().save(newP); */ } else { if (form.getStatus().equals(Constants.FILE_STATUS.REVIEWED_TO_ADD)) {//da xem xet yc sdbs //lay process tham dinh ho so tra ve cho chuyen vien tham dinh chinh //gui den chuyen vien xu ly if (oldP != null) { newP.setReceiveGroup(oldP.getSendGroup()); newP.setReceiveGroupId(oldP.getSendGroupId()); } newP.setReceiveUser(file.getNameStaffProcess()); newP.setReceiveUserId(file.getStaffProcess()); //cap nhat noi dung thong bao - tao noi dung thong bao RequestComment rcbo = new RequestComment(); rcbo.setContent(file.getLeaderRequest()); rcbo.setCreateBy(userId); rcbo.setCreateDate(dateNow); rcbo.setUserId(userId); rcbo.setUserName(userName); rcbo.setStatus(1L); rcbo.setIsActive(1L); rcbo.setGroupId(deptId); rcbo.setGroupName(deptName); rcbo.setObjectId(form.getFileId()); rcbo.setRequestType(Constants.REQUEST_COMMENT_TYPE.TBSDBS); rcbo.setIsLastChange(Constants.ACTIVE_STATUS.ACTIVE); RequestCommentDAOHE rqdaohe = new RequestCommentDAOHE(); RequestComment lastRQBo = rqdaohe.findLastRequestComment(file.getFileId(), Constants.ACTIVE_STATUS.ACTIVE); if (lastRQBo != null) { rcbo.setLastContent(lastRQBo.getContent()); lastRQBo.setIsLastChange(Constants.ACTIVE_STATUS.DEACTIVE); getSession().update(lastRQBo); } getSession().save(rcbo); //cap nhat noi dung thong bao - tao noi dung thong bao } if (form.getStatus().equals(Constants.FILE_STATUS.APPROVE_TO_ADD)) {//ldc phe duyet noi dung chuyen cho vt gui cong van sdbs if (deptId.equals(file.getAgencyId())) { newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); } else { newP.setReceiveGroup(file.getAgencyName()); newP.setReceiveGroupId(file.getAgencyId()); } //cap nhat noi dung thong bao - tao noi dung thong bao RequestComment rcbo = new RequestComment(); if (file.getLeaderRequest() != null) { rcbo.setContent(form.getLeaderRequest()); } else { rcbo.setContent("Lnh o phng cha c ni dung."); } rcbo.setCreateBy(userId); rcbo.setCreateDate(dateNow); rcbo.setUserId(userId); rcbo.setUserName(userName); rcbo.setStatus(1L); rcbo.setIsActive(1L); rcbo.setGroupId(deptId); rcbo.setGroupName(deptName); rcbo.setIsLastChange(Constants.ACTIVE_STATUS.ACTIVE); rcbo.setObjectId(form.getFileId()); rcbo.setRequestType(Constants.REQUEST_COMMENT_TYPE.TBSDBS); //u150119 binhnt53 RequestCommentDAOHE rqdaohe = new RequestCommentDAOHE(); RequestComment lastRQBo = rqdaohe.findLastRequestComment(file.getFileId(), Constants.ACTIVE_STATUS.ACTIVE); if (lastRQBo != null) { rcbo.setLastContent(lastRQBo.getContent()); lastRQBo.setIsLastChange(Constants.ACTIVE_STATUS.DEACTIVE); getSession().update(lastRQBo); } getSession().save(rcbo); //!cap nhat noi dung thong bao - tao noi dung thong bao //tang so ho so di CountNoDAOHE cndaohe = new CountNoDAOHE(); CountNo cnbo = cndaohe.returnCountNoByDeptId(deptId); if (cnbo != null && cnbo.getSendNo() > 0L) { Long nCount = cnbo.getSendNo(); cnbo.setSendNo(nCount + 1); getSession().update(cnbo); } else if (file != null && file.getAgencyId() > 0L) { cnbo = cndaohe.returnCountNoByDeptId(file.getAgencyId()); Long nCount = cnbo.getSendNo(); cnbo.setSendNo(nCount + 1); getSession().update(cnbo); } } if (form.getStatus().equals(Constants.FILE_STATUS.FEDBACK_TO_REVIEW)) {//160406 //lanh dao cuc tu choi phe duyet cong van thong bao sdbs chuyen cho lanh dao phong xem xet lai if (oldP != null) { newP.setReceiveGroup(oldP.getSendGroup()); newP.setReceiveGroupId(oldP.getSendGroupId()); newP.setReceiveUser(oldP.getSendUser()); newP.setReceiveUserId(oldP.getSendUserId()); } //cap nhat noi dung thong bao - tao noi dung thong bao RequestComment rcbo = new RequestComment(); if (file.getLeaderRequest() != null) { rcbo.setContent(form.getLeaderRequest()); } else { rcbo.setContent("Lnh o phng cha c ni dung."); } rcbo.setCreateBy(userId); rcbo.setCreateDate(dateNow); rcbo.setUserId(userId); rcbo.setUserName(userName); rcbo.setStatus(1L); rcbo.setIsActive(1L); rcbo.setGroupId(deptId); rcbo.setGroupName(deptName); rcbo.setIsLastChange(Constants.ACTIVE_STATUS.ACTIVE); rcbo.setObjectId(form.getFileId()); rcbo.setRequestType(Constants.REQUEST_COMMENT_TYPE.TBSDBS); RequestCommentDAOHE rqdaohe = new RequestCommentDAOHE(); RequestComment lastRQBo = rqdaohe.findLastRequestComment(file.getFileId(), Constants.ACTIVE_STATUS.ACTIVE); if (lastRQBo != null) { rcbo.setLastContent(lastRQBo.getContent()); lastRQBo.setIsLastChange(Constants.ACTIVE_STATUS.DEACTIVE); getSession().update(lastRQBo); } getSession().save(rcbo); //!cap nhat noi dung thong bao - tao noi dung thong bao } if (form.getStatus().equals(Constants.FILE_STATUS.REVIEW_TO_BOSS)) {//- luong pho cuc truong gui trinh len lanh dao cuc //- tim cuc truong de gui UsersDAOHE udaohe = new UsersDAOHE(); Users ubo = udaohe.findUserByPosition(deptId, Constants.POSITION.LEADER_CT); if (ubo != null) { newP.setReceiveUser(ubo.getFullName()); newP.setReceiveUserId(ubo.getUserId()); } newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); //cap nhat noi dung thong bao - tao noi dung thong bao RequestComment rcbo = new RequestComment(); if (file.getLeaderRequest() != null) { rcbo.setContent(form.getLeaderRequest()); } else { rcbo.setContent("Lnh o phng cha c ni dung."); } rcbo.setCreateBy(userId); rcbo.setCreateDate(dateNow); rcbo.setUserId(userId); rcbo.setUserName(userName); rcbo.setStatus(1L); rcbo.setIsActive(1L); rcbo.setGroupId(deptId); rcbo.setGroupName(deptName); rcbo.setIsLastChange(Constants.ACTIVE_STATUS.ACTIVE); rcbo.setObjectId(form.getFileId()); rcbo.setRequestType(Constants.REQUEST_COMMENT_TYPE.TCT);//trinh cuc truong RequestCommentDAOHE rqdaohe = new RequestCommentDAOHE(); RequestComment lastRQBo = rqdaohe.findLastRequestComment(file.getFileId(), Constants.ACTIVE_STATUS.ACTIVE); if (lastRQBo != null) { rcbo.setLastContent(lastRQBo.getContent()); lastRQBo.setIsLastChange(Constants.ACTIVE_STATUS.DEACTIVE); getSession().update(lastRQBo); } getSession().save(rcbo); //!cap nhat noi dung thong bao - tao noi dung thong bao } } getSession().save(newP); update(file); //onCreatePaper(form, deptId, deptName, userId, userName); if (form.getStatus().equals(Constants.FILE_STATUS.APPROVED)) { ProcedureDAOHE pcdaohe = new ProcedureDAOHE(); Procedure procedure = pcdaohe.findById(file.getFileType()); if (procedure != null && procedure.getProcedureId() > 0) { if (!procedure.getDescription().equals(Constants.FILE_DESCRIPTION.ANNOUNCEMENT_FILE01) && !procedure.getDescription() .equals(Constants.FILE_DESCRIPTION.ANNOUNCEMENT_FILE03)) { //sms MessageSmsDAOHE msdhe = new MessageSmsDAOHE(); String msg = "Ho so ma: " + file.getFileCode() + " cua doanh nghiep: " + file.getBusinessName() + " dang trong trang thai: da phe duyet, doanh nghiep luu y dong le phi cap so de duoc cap ban cong bo"; msdhe.saveMessageSMS(userId, file.getUserCreateId(), msg); //email MessageEmailDAOHE msedhe = new MessageEmailDAOHE(); String msge = "H s m: " + file.getFileCode() + " ca doanh nghip: " + file.getBusinessName() + " ang trong trng thi: ph duyt, doanh nghip lu ng l ph cp s c cp bn cng b"; msedhe.saveMessageEmail(userId, file.getUserCreateId(), msge); } } //update binhnt // try { // if ("true".equals(ResourceBundleUtil.getString("send_service", "config"))) { // Helper h = new Helper(); // h.sendMs_340(file.getFileId(), "Ho so ma: " + file.getFileCode() + " Da duoc phe duyet yeu cau nop phi ho so."); // } // } catch (UnsupportedEncodingException ex) { // Logger.getLogger(FilesDAOHE.class.getName()).log(Level.SEVERE, null, ex); // } } } else { return false; } } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } return bReturn; } /** * to bn cng b * * @param form * @param deptId * @param deptName * @param userId * @param userName * @return */ public boolean onCreatePaper(FilesForm form, Long deptId, String deptName, Long userId, String userName) { try { Date dateNow = getSysdate(); Files file = findById(form.getFileId()); file.setModifyDate(dateNow); if (file != null) { if (form.getStatus().equals(Constants.FILE_STATUS.APPROVED)) { file.setApproveDate(dateNow); //Hiepvv 1403 Lay y kien cua LDC in len noi dung cong van if (form.getLeaderRequest() != null && !form.getLeaderRequest().isEmpty()) { file.setContentsEditATTP(form.getLeaderRequest()); } ProcedureDAOHE pcdaohe = new ProcedureDAOHE(); Procedure procedure = pcdaohe.findById(file.getFileType()); if (procedure != null && procedure.getProcedureId() > 0) { if (!procedure.getDescription().equals(Constants.FILE_DESCRIPTION.CONFIRM_SATISFACTORY)) {//tao giay tiep nhan cong bo if (file.getAnnouncementId() != null) { if (file.getAnnouncementReceiptPaperId() == null) { AnnouncementReceiptPaperForm arpForm = new AnnouncementReceiptPaperForm(); AnnouncementDAOHE announcementHE = new AnnouncementDAOHE(); Announcement announcement = announcementHE.findById(file.getAnnouncementId()); arpForm.setBusinessName(announcement.getBusinessName()); arpForm.setProductName(announcement.getProductName()); arpForm.setManufactureName(announcement.getManufactureName()); arpForm.setEmail(announcement.getBusinessEmail()); arpForm.setFax(announcement.getBusinessFax()); arpForm.setTelephone(announcement.getBusinessTelephone()); arpForm.setNationName(announcement.getNationName()); String strReceiptNo = getNewReceiptNo(file.getAgencyId(), file.getFileType()); arpForm.setReceiptNo(strReceiptNo); if (file.getEffectiveDate() != null) { if (file.getEffectiveDate() == 3) {//lay ngay ki + 3 nam arpForm.setEffectiveDate(DateUtils.addYears(dateNow, 3)); } else if (file.getEffectiveDate() == 5) {//lay ngay ki + 5 nam arpForm.setEffectiveDate(DateUtils.addYears(dateNow, 5)); } else { arpForm.setEffectiveDate(DateUtils.addYears(dateNow, 3)); } } arpForm.setReceiptDate(dateNow); arpForm.setReceiptDeptName(deptName);//ten co quan tiep nhan cong bo arpForm.setMatchingTarget(announcement.getMatchingTarget());//so hieu qui chuan ki thuat arpForm.setSignDate(dateNow);//ngay ki arpForm.setSignerName(userName);//nguoi ki //tao giay tiep nhan try { AnnouncementReceiptPaperDAOHE cthe = new AnnouncementReceiptPaperDAOHE(); if (cthe.isDuplicate(arpForm) == true) { return false; } else { // if (cthe.validateReceiptNo(arpForm.getReceiptNo())) { //validate so giay tiep nhan Long ObjId = arpForm.getAnnouncementReceiptPaperId(); AnnouncementReceiptPaper bo = arpForm.convertToEntity(); if (ObjId == null) { getSession().save(bo); file.setAnnouncementReceiptPaperId( bo.getAnnouncementReceiptPaperId()); getSession().update(file); } else { getSession().update(bo); file.setAnnouncementReceiptPaperId( bo.getAnnouncementReceiptPaperId()); getSession().update(file); } // } else { // return false; // } } getSession().beginTransaction().commit(); return true; } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 return false; } } else {//co so roi thuc hien update khong tao moi - binhnt53 14.11.12 AnnouncementReceiptPaperDAOHE arpdaohe = new AnnouncementReceiptPaperDAOHE(); AnnouncementReceiptPaper arpbo = arpdaohe .findById(file.getAnnouncementReceiptPaperId()); if (arpbo != null) { AnnouncementDAOHE announcementHE = new AnnouncementDAOHE(); Announcement announcement = announcementHE .findById(file.getAnnouncementId()); if (announcement != null) { arpbo.setBusinessName(announcement.getBusinessName()); arpbo.setProductName(announcement.getProductName()); arpbo.setManufactureName(announcement.getManufactureName()); arpbo.setEmail(announcement.getBusinessEmail()); arpbo.setFax(announcement.getBusinessFax()); arpbo.setTelephone(announcement.getBusinessTelephone()); arpbo.setNationName(announcement.getNationName()); if (file.getEffectiveDate() != null) { if (file.getEffectiveDate() == 3) {//lay ngay ki + 3 nam arpbo.setEffectiveDate(DateUtils.addYears(dateNow, 3)); } else if (file.getEffectiveDate() == 5) {//lay ngay ki + 5 nam arpbo.setEffectiveDate(DateUtils.addYears(dateNow, 5)); } else { arpbo.setEffectiveDate(DateUtils.addYears(dateNow, 3)); } } if (arpbo.getReceiptDate() != null) { arpbo.setReceiptDate(arpbo.getReceiptDate()); } else { arpbo.setReceiptDate(dateNow); } arpbo.setReceiptDeptName(deptName);//ten co quan tiep nhan cong bo arpbo.setMatchingTarget(announcement.getMatchingTarget());//so hieu qui chuan ki thuat arpbo.setSignDate(dateNow);//ngay ki arpbo.setSignerName(userName);//nguoi ki getSession().update(arpbo); getSession().update(file); getSession().beginTransaction().commit(); return true; } else { return false; } } else { return false; } } } else { return false; } //!tao giay tiep nhan } else if (file.getTestRegistrationId() != null) {//Giy xc nhn t yu cu nhp khu ca c quan kim tra Nh nc v? cht lng thc phm nhp khu ConfirmImportSatistPaperForm cispForm = new ConfirmImportSatistPaperForm(); cispForm.setTestAgencyName(form.getTestRegistration().getTestAgency()); cispForm.setTestAdd(form.getTestRegistration().getTestAdd()); cispForm.setExportBusinessName(form.getTestRegistration().getExportBusinessName()); cispForm.setExportBusinessAdd(form.getTestRegistration().getExportBusinessAdd()); cispForm.setExportBusinessMail(form.getTestRegistration().getExportBusinessMail()); cispForm.setExportBusinessTel(form.getTestRegistration().getExportBusinessTel()); cispForm.setExportBusinessFax(form.getTestRegistration().getExportBusinessFax()); cispForm.setExportContractCode(form.getTestRegistration().getExportContractCode()); cispForm.setExportContractDate(form.getTestRegistration().getExportContractDate()); cispForm.setExportLadingCode(form.getTestRegistration().getExportLadingCode()); cispForm.setExportLadingDate(form.getTestRegistration().getExportLadingDate()); cispForm.setExportPort(form.getTestRegistration().getExportPort()); cispForm.setImportBusinessName(form.getTestRegistration().getImportBusinessName()); cispForm.setImportBusinessAddress( form.getTestRegistration().getImportBusinessAddress()); cispForm.setImportBusinessEmail(form.getTestRegistration().getImportBusinessEmail()); cispForm.setImportBusinessTel(form.getTestRegistration().getImportBusinessTel()); cispForm.setImportBusinessFax(form.getTestRegistration().getImportBusinessFax()); cispForm.setImportPort(form.getTestRegistration().getImportPort()); cispForm.setImportDate(form.getTestRegistration().getImportDate()); cispForm.setProductName(form.getTestRegistration().getProductName()); cispForm.setProductDescription(form.getTestRegistration().getProductDescription()); cispForm.setProductCode(form.getTestRegistration().getProductCode()); cispForm.setProductOrigin(form.getTestRegistration().getProductOrigin()); cispForm.setProductAmount(form.getTestRegistration().getProductAmount()); cispForm.setProductWeight(form.getTestRegistration().getProductWeight()); cispForm.setProductValue(form.getTestRegistration().getProductValue()); cispForm.setGatheringAdd(form.getTestRegistration().getGatheringAdd()); cispForm.setTestDate(form.getTestRegistration().getTestDate()); cispForm.setBusinessRepresent(form.getTestRegistration().getBusinessRepresent()); cispForm.setBusinessSignAdd(form.getTestRegistration().getBusinessSignAdd()); cispForm.setBusinessSigndate(form.getTestRegistration().getBusinessSigndate()); cispForm.setAgencyRepresent(form.getTestRegistration().getAgencyRepresent()); cispForm.setAgencySignAdd(form.getTestRegistration().getAgencySignAdd()); cispForm.setAgencySigndate(form.getTestRegistration().getAgencySigndate()); cispForm.setStandardTargetNo(form.getTestRegistration().getStandardTargetNo()); cispForm.setStandardTargetDate(form.getTestRegistration().getStandardTargetDate()); cispForm.setReleaseDocumentNo(form.getTestRegistration().getReleaseDocumentNo()); cispForm.setReleaseDocumentDate(form.getTestRegistration().getReleaseDocumentDate()); try { ConfirmImportSatistPaperDAOHE cthe = new ConfirmImportSatistPaperDAOHE(); if (cthe.isDuplicate(cispForm) == true) { return false; } else { Long ObjId = cispForm.getConfirmImportSatistPaperId(); if (ObjId == null) { ConfirmImportSatistPaper bo = cispForm.convertToEntity(); getSession().save(bo); file.setConfirmImportSatistPaperId(bo.getConfirmImportSatistPaperId()); getSession().update(file); } else { ConfirmImportSatistPaper bo = cispForm.convertToEntity(); getSession().update(bo); file.setConfirmImportSatistPaperId(bo.getConfirmImportSatistPaperId()); getSession().update(file); } getSession().getTransaction().commit(); return true; } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 return false; } } } } } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 return false; } return true; } /** * Cp m h s * * @param fileType * @return */ public String getNewFileCode(Long fileType) { ProcedureDAOHE cdhe = new ProcedureDAOHE(); Procedure type = cdhe.findById(fileType); // String hql = "select count(f) from Files f where f.fileType = ? and (f.isTemp = null or f.isTemp = 0 ) "; // String hql = "select count(f) from Files f where (f.isTemp = null or f.isTemp = 0 ) ";//u150129 dund cap nhat ma ho so String hql = "select count(f) from Files f ";//u150129 dund cap nhat ma ho so // String hql = "select count(f) from Files f where f.fileType = ? "; Query query = getSession().createQuery(hql); // query.setParameter(0, fileType); int nCount = (int) (long) (Long) query.uniqueResult(); nCount += 1; Date currentDate = new Date(); try { currentDate = getSysdate(); } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } String fileCode = DateTimeUtils.convertDateToString(currentDate, "yy.MM.") + type.getCode() + "." + nCount; return fileCode; } /* * Thuc hien clone 1 ho so sang ho so khac de luu phien ban, clone tat ca thong tin lien quan den ho s */ /** * * @param fileId * @return */ public FilesForm getNewCloneFiles(Long fileId) { FilesForm originalFiles = getFilesFullDetail(fileId); FilesForm cloneFiles = new FilesForm(originalFiles.convertToEntity().cloneEntity()); if (originalFiles.getAnnouncement() != null) { Announcement cloneAnn = originalFiles.getAnnouncement().convertToEntity().cloneEntity(); cloneFiles.setAnnouncement(new AnnouncementForm(cloneAnn)); } if (originalFiles.getDetailProduct() != null) { DetailProduct cloneDetail = originalFiles.getDetailProduct().convertToEntity().cloneEntity(); cloneFiles.setDetailProduct(new DetailProductForm(cloneDetail)); } if (originalFiles.getReIssueForm() != null) { ReIssueForm cloneReIssue = originalFiles.getReIssueForm().convertToEntity().cloneEntity(); cloneFiles.setReIssueForm(new ReIssueFormForm(cloneReIssue)); } if (originalFiles.getTestRegistration() != null) { TestRegistration cloneTest = originalFiles.getTestRegistration().convertToEntity().cloneEntity(); cloneFiles.setTestRegistration(new TestRegistrationForm(cloneTest)); } List lstMainlyTarget = new ArrayList(); if (originalFiles.getLstMainlyTarget() != null && !originalFiles.getLstMainlyTarget().isEmpty()) { for (MainlyTarget item : originalFiles.getLstMainlyTarget()) { MainlyTarget cloneItem = item.cloneEntity(); lstMainlyTarget.add(cloneItem); } } cloneFiles.setLstMainlyTarget(lstMainlyTarget); List lstBioTarget = new ArrayList(); if (originalFiles.getLstBioTarget() != null && !originalFiles.getLstBioTarget().isEmpty()) { for (ProductTarget item : originalFiles.getLstBioTarget()) { ProductTarget cloneItem = item.cloneEntity(); lstBioTarget.add(cloneItem); } } cloneFiles.setLstBioTarget(lstBioTarget); List lstHeavyTarget = new ArrayList(); if (originalFiles.getLstHeavyMetal() != null && !originalFiles.getLstHeavyMetal().isEmpty()) { for (ProductTarget item : originalFiles.getLstHeavyMetal()) { ProductTarget cloneItem = item.cloneEntity(); lstHeavyTarget.add(cloneItem); } } cloneFiles.setLstHeavyMetal(lstHeavyTarget); List lstChemicalTarget = new ArrayList(); if (originalFiles.getLstChemical() != null && !originalFiles.getLstChemical().isEmpty()) { for (ProductTarget item : originalFiles.getLstChemical()) { ProductTarget cloneItem = item.cloneEntity(); lstChemicalTarget.add(cloneItem); } } cloneFiles.setLstChemical(lstChemicalTarget); String lstAttachLabel = ";"; List lstAttachs = new ArrayList(); if (originalFiles.getLstAttachs() != null && !originalFiles.getLstAttachs().isEmpty()) { int i = 0; for (VoAttachs item : originalFiles.getLstAttachs()) { VoAttachs cloneItem = item.cloneEntity(); lstAttachs.add(cloneItem); if (item.getObjectType().equals(Constants.OBJECT_TYPE.FILES_LABEL)) { lstAttachLabel += (i + ";"); } i++; } } cloneFiles.setLstAttachs(lstAttachs); cloneFiles.setLstAttachLabel(lstAttachLabel); List lstQualityPlan = new ArrayList(); if (originalFiles.getLstQualityControl() != null && !originalFiles.getLstQualityControl().isEmpty()) { for (QualityControlPlan item : originalFiles.getLstQualityControl()) { QualityControlPlan cloneItem = item.cloneEntity(); lstQualityPlan.add(cloneItem); } } cloneFiles.setLstQualityControl(lstQualityPlan); return cloneFiles; } private boolean checkMainlyTargetIsModify(MainlyTarget target, List<MainlyTarget> lstItem) { if (target.getMainlyTargetId() == null || target.getMainlyTargetId() <= 0l) { return false; } if (lstItem == null) { return false; } if (lstItem.isEmpty()) { return false; } for (MainlyTarget item : lstItem) { if (target.getMainlyTargetId().equals(item.getMainlyTargetId()) || target.getMainlyTargetId().equals(item.getOriginalId())) { if (item.getMeetLevel() != null && target.getMeetLevel() != null) { if (!item.getMeetLevel().equals(target.getMeetLevel())) { return true; } } if (item.getPublishLevel() != null && target.getPublishLevel() != null) { if (!item.getPublishLevel().equals(target.getPublishLevel())) { return true; } } if (item.getTargetName() != null && target.getTargetName() != null) { if (!item.getTargetName().equals(target.getTargetName())) { return true; } } if (item.getUnitId() != null && target.getUnitId() != null) { if (!item.getUnitId().equals(target.getUnitId())) { return true; } } } } return false; } private boolean checkProductTargetIsModify(ProductTarget target, List<ProductTarget> lstItem, Long status) { if (status.equals(Constants.FILE_STATUS.EVALUATED_TO_ADD)) { return false; } if (target.getProductTargetId() == null || target.getProductTargetId() <= 0l) { return true; } if (lstItem == null) { return false; } if (lstItem.isEmpty()) { return false; } for (ProductTarget item : lstItem) { if (target.getProductTargetId().equals(item.getProductTargetId()) || target.getProductTargetId().equals(item.getOriginalId())) { if (item.getMaxLevel() != null && target.getMaxLevel() != null) { if (!item.getMaxLevel().equals(target.getMaxLevel())) { return true; } } if (item.getTargetName() != null && target.getTargetName() != null) { if (!item.getTargetName().equals(target.getTargetName())) { return true; } } if (item.getUnitId() != null && target.getUnitId() != null) { if (!item.getUnitId().equals(target.getUnitId())) { return true; } } } } return false; } private boolean checkAttachIsModify(VoAttachs target, List<VoAttachs> lstItem) { if (target.getAttachId() == null || target.getAttachId() <= 0l) { return false; } if (lstItem == null) { return false; } if (lstItem.isEmpty()) { return false; } for (VoAttachs item : lstItem) { if (target.getAttachId().equals(item.getAttachId()) || target.getAttachId().equals(item.getOriginalId())) { if (item.getAttachDes() != null && target.getAttachDes() != null) { if (!item.getAttachDes().equals(target.getAttachDes())) { return true; } } if (item.getCategoryName() != null && target.getCategoryName() != null) { if (!item.getCategoryName().equals(target.getCategoryName())) { return true; } } } } return false; } /** * luu danh sach chi tieu chinh */ private void saveMainlytarget(List<MainlyTarget> lstItems, Long fileId) { List<Long> lstIdOfMainlyTargets = new ArrayList(); if (lstItems != null && !lstItems.isEmpty()) { Long previousVersionId = getLastVersionIdOfFile(fileId); List lstMainlyTarget = null; if (previousVersionId != null) { lstMainlyTarget = getMainlyTargetOfFile(previousVersionId); } for (MainlyTarget item : lstItems) { if (item == null) { continue; } item.setFileId(fileId);// if (checkMainlyTargetIsModify(item, lstMainlyTarget)) { item.setIsTemp(1l); } else { item.setIsTemp(0l); } if (item.getMainlyTargetId() != null) { getSession().merge(item); } else { getSession().save(item); } Long id = item.getMainlyTargetId(); lstIdOfMainlyTargets.add(id); } } String hql = "delete from MainlyTarget m where m.fileId = :fileId "; if (!lstIdOfMainlyTargets.isEmpty()) { hql += " and m.mainlyTargetId not in (:lstIdOfMainlyTargets)"; } Query query = getSession().createQuery(hql); query.setParameter("fileId", fileId); if (!lstIdOfMainlyTargets.isEmpty()) { query.setParameterList("lstIdOfMainlyTargets", lstIdOfMainlyTargets); } query.executeUpdate(); } /** * luu danh sach chi tieu san pham */ private void saveProductTarget(List<ProductTarget> lstItems, Long fileId, Long type, Long status) { List<Long> lstUpdateItems = new ArrayList(); Long previousVersionId = getLastVersionIdOfFile(fileId); List lstProductTarget = null; if (previousVersionId != null) { lstProductTarget = getProductTargetOfFile(previousVersionId); } if (lstItems != null && !lstItems.isEmpty()) { for (ProductTarget item : lstItems) { if (item == null) { continue; } item.setFileId(fileId); if (checkProductTargetIsModify(item, lstProductTarget, status)) { item.setIsTemp(1l); } else { item.setIsTemp(0l); } if (item.getProductTargetId() != null) { getSession().merge(item); } else { getSession().save(item); } Long id = item.getProductTargetId(); lstUpdateItems.add(id); } } String hql = "delete from ProductTarget m where m.fileId = :fileId and m.targetType=:type"; if (!lstUpdateItems.isEmpty()) { hql += " and m.productTargetId not in (:lstUpdateItems)"; } Query query = getSession().createQuery(hql); query.setParameter("type", type); query.setParameter("fileId", fileId); if (!lstUpdateItems.isEmpty()) { query.setParameterList("lstUpdateItems", lstUpdateItems); } query.executeUpdate(); } /** * Luu cac file attach */ private void saveAttachs(List<VoAttachs> lstItems, Long fileId, String lstAttachLabel) { List<Long> lstIdOfAttachs = new ArrayList();//danh sach id cua lst Attach if (lstItems != null && !lstItems.isEmpty()) { boolean isEdit = false;//la sua if (fileId != null && fileId > 0L) {//neu ton tai id la sua isEdit = true; } if (lstAttachLabel != null) {//danh sach nhan lstAttachLabel = ";" + lstAttachLabel; } else { lstAttachLabel = ""; } Long previousVersionId = getLastVersionIdOfFile(fileId);//tim version moi nhat cua attach List lstPreviousVersionAtt = null;//danh sach version if (previousVersionId != null) { lstPreviousVersionAtt = getAttachsOfFile(previousVersionId); } for (VoAttachs item : lstItems) { Long attachId = item.getAttachId(); if (attachId == null) { continue; } lstIdOfAttachs.add(attachId); } List<VoAttachs> lstOldAttachs = null; if (!lstIdOfAttachs.isEmpty()) { String hql = "select v from VoAttachs v where v.attachId in (:lstIdOfAttachs)"; Query query = getSession().createQuery(hql); query.setParameterList("lstIdOfAttachs", lstIdOfAttachs); lstOldAttachs = query.list(); } for (int i = 0; i < lstItems.size(); i++) { VoAttachs item = lstItems.get(i); Long attachId = item.getAttachId(); if (lstAttachLabel.indexOf(";" + i + ";") >= 0) { item.setObjectType(com.viettel.common.util.Constants.OBJECT_TYPE.FILES_LABEL); } else { item.setObjectType(com.viettel.common.util.Constants.OBJECT_TYPE.FILES); } item.setObjectId(fileId); if (attachId == null) { item.setIsActive(1l); getSession().save(item); } else { for (VoAttachs oldItem : lstOldAttachs) { if (oldItem.getAttachId().equals(attachId)) { oldItem.setCategoryName(item.getCategoryName()); oldItem.setAttachDes(item.getAttachDes()); oldItem.setObjectType(item.getObjectType()); item = oldItem; break; } } if (checkAttachIsModify(item, lstPreviousVersionAtt)) { item.setIsTemp(1l); } else { item.setIsTemp(0l); } item.setObjectId(fileId); if (item.getAttachId() != null && fileId != null && fileId > 0L) { getSession().merge(item); } else if (!isEdit) { getSession().save(item); } } Long id = item.getAttachId(); lstIdOfAttachs.add(id); } } if (fileId != null && fileId > 0L) {//sua ho so hay khong sua ho so FilesDAOHE fdaohe = new FilesDAOHE(); Files fbo = fdaohe.findById(fileId); if (fbo == null || !fbo.getStatus().equals(Constants.FILE_STATUS.EVALUATED_TO_ADD)) { //la sua moi thuc hien xoa khong thi k xoa gi ca String hql = "delete from VoAttachs m" + " where m.objectId = :filesId" + " and (m.objectType= :objectType1 or m.objectType= :objectType2) "; if (!lstIdOfAttachs.isEmpty()) { hql += " and m.attachId not in (:lstIdOfAttachs)"; } Query query = getSession().createQuery(hql); query.setParameter("filesId", fileId); query.setParameter("objectType1", com.viettel.common.util.Constants.OBJECT_TYPE.FILES); query.setParameter("objectType2", com.viettel.common.util.Constants.OBJECT_TYPE.FILES_LABEL); if (!lstIdOfAttachs.isEmpty()) { query.setParameterList("lstIdOfAttachs", lstIdOfAttachs); } query.executeUpdate(); } else { //la sua moi thuc hien xoa khong thi k xoa gi ca String hql = "update VoAttachs m set m.isActive = -1" + " where m.objectId = :filesId" + " and (m.objectType= :objectType1 or m.objectType= :objectType2) "; if (!lstIdOfAttachs.isEmpty()) { hql += " and m.attachId not in (:lstIdOfAttachs)"; } Query query = getSession().createQuery(hql); query.setParameter("filesId", fileId); query.setParameter("objectType1", com.viettel.common.util.Constants.OBJECT_TYPE.FILES); query.setParameter("objectType2", com.viettel.common.util.Constants.OBJECT_TYPE.FILES_LABEL); if (!lstIdOfAttachs.isEmpty()) { query.setParameterList("lstIdOfAttachs", lstIdOfAttachs); } query.executeUpdate(); } } } /* * Luu ke hoach quan ly chat luong */ private void saveQualityPlan(List<QualityControlPlan> lstItems, Long fileId) { List<Long> lstIdOfQualitys = new ArrayList(); if (lstItems != null && !lstItems.isEmpty()) { for (QualityControlPlan item : lstItems) { if (item.getQualityControlPlanId() != null) {//kiem tra ban tren form khac trong db k neu khach oanh dau co sua doi va luu ban goc // QualityControlPlan itemOnDB = (QualityControlPlan) findById(QualityControlPlan.class, "qualityControlPlanId", item.getQualityControlPlanId()); QualityControlPlanDAOHE qualityControlPlanDAOHE = new QualityControlPlanDAOHE(); QualityControlPlan itemOnDB = qualityControlPlanDAOHE .findIsItempObj(item.getQualityControlPlanId(), 0L, 0L, false); if (itemOnDB != null) { item.setIsTemp(itemOnDB.getIsTemp()); if (item.getControlTarget() != null && itemOnDB.getControlTarget() != null) { if (!item.getControlTarget().equals(itemOnDB.getControlTarget())) { item.setIsTemp(1L); } } if (item.getNote() != null && itemOnDB.getNote() != null) { if (!item.getNote().equals(itemOnDB.getNote())) { item.setIsTemp(1L); } } if (item.getNoteForm() != null && itemOnDB.getNoteForm() != null) { if (!item.getNoteForm().equals(itemOnDB.getNoteForm())) { item.setIsTemp(1L); } } if (item.getPatternFrequence() != null && itemOnDB.getPatternFrequence() != null) { if (!item.getPatternFrequence().equals(itemOnDB.getPatternFrequence())) { item.setIsTemp(1L); } } if (item.getProductProcessDetail() != null && itemOnDB.getProductProcessDetail() != null) { if (!item.getProductProcessDetail().equals(itemOnDB.getProductProcessDetail())) { item.setIsTemp(1L); } } if (item.getTechnicalRegulation() != null && itemOnDB.getTechnicalRegulation() != null) { if (!item.getTechnicalRegulation().equals(itemOnDB.getTechnicalRegulation())) { item.setIsTemp(1L); } } if (item.getTestDevice() != null && itemOnDB.getTestDevice() != null) { if (!item.getTestDevice().equals(itemOnDB.getTestDevice())) { item.setIsTemp(1L); } } if (item.getTestMethod() != null && itemOnDB.getTestMethod() != null) { if (!item.getTestMethod().equals(itemOnDB.getTestMethod())) { item.setIsTemp(1L); } } } } item.setFileId(fileId); if (item.getQualityControlPlanId() != null) { getSession().merge(item); } else { getSession().save(item); } Long id = item.getQualityControlPlanId(); lstIdOfQualitys.add(id); } } String hql = "delete from QualityControlPlan m where m.fileId = :fileId "; if (!lstIdOfQualitys.isEmpty()) { hql += " and m.qualityControlPlanId not in (:lstIdOfQualitys)"; } Query query = getSession().createQuery(hql); query.setParameter("fileId", fileId); if (!lstIdOfQualitys.isEmpty()) { query.setParameterList("lstIdOfQualitys", lstIdOfQualitys); } query.executeUpdate(); } /* * Luu danh sach san pham */ private void saveProductInFile(List<ProductInFile> lstItems, Long fileId) { List<Long> lstIdOfProducts = new ArrayList(); if (lstItems != null && lstItems.size() > 0) { for (ProductInFile item : lstItems) { item.setFileId(fileId); if (item.getProductInFileId() != null) { getSession().update(item); } else { getSession().save(item); } Long id = item.getProductInFileId(); lstIdOfProducts.add(id); } } String hql = "delete from ProductInFile m where m.fileId = :fileId "; if (!lstIdOfProducts.isEmpty()) { hql += " and m.productInFileId not in (:lstIdOfProducts)"; } Query query = getSession().createQuery(hql); query.setParameter("fileId", fileId); if (!lstIdOfProducts.isEmpty()) { query.setParameterList("lstIdOfProducts", lstIdOfProducts); } query.executeUpdate(); } /* * Luu fee cua ho so */ private Boolean saveFee(Long fileId, Long fileType, Long productType, Procedure pro, Long productTypeIdOld) { if (fileId != null) { Date dateNow = null; try { dateNow = getSysdate(); } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 return false; } String hql = "select fpif from FeePaymentInfo fpif" + " where" + " fpif.fileId =:fileId" + " and fpif.isActive = 1"; Query query = getSession().createQuery(hql); query.setParameter("fileId", fileId); List<FeePaymentInfo> lstFeePaymentInfo = query.list(); // // truong hop sao chep va luu tam productType co the = null, vi the phai set = -1 // if (lstFeePaymentInfo.isEmpty()) { FeeDAOHE fdhe = new FeeDAOHE(); List<FeeProcedure> feenew = fdhe.findAllFeeByProcedureId(fileType); // check le phi cap so theo loai ho so if (feenew != null && feenew.size() > 0) { for (int i = 0; i < feenew.size(); i++) { FeePaymentInfo fpif = new FeePaymentInfo(); fpif.setCreateDate(dateNow); fpif.setStatus(0l); fpif.setFileId(fileId); fpif.setIsActive(1l); fpif.setFeeId(feenew.get(i).getFeeId()); Fee feeTemp = (Fee) findById(Fee.class, "feeId", feenew.get(i).getFeeId()); fpif.setCost(feeTemp.getPrice()); getSession().save(fpif); } } // hieptq update 280515 set phi ho so cap lai if (pro != null && pro.getDescription() != null && (pro.getDescription().equals(Constants.FILE_DESCRIPTION.RE_ANNOUNCEMENT) || pro.getDescription().equals(Constants.FILE_DESCRIPTION.RE_CONFIRM_FUNC_IMP) || pro.getDescription().equals(Constants.FILE_DESCRIPTION.REC_CONFIRM_NORMAL_IMP) || pro.getDescription().equals(Constants.FILE_DESCRIPTION.RE_CONFIRM_FUNC_VN) || pro.getDescription().equals(Constants.FILE_DESCRIPTION.RE_CONFIRM_NORMAL_VN))) { if (pro != null && pro.getTypeFee() == 2l) { FeePaymentInfo fpif = new FeePaymentInfo(); Fee findfee1 = fdhe.findFeeByCode("CLT"); fpif.setCreateDate(dateNow); fpif.setStatus(0l); fpif.setFileId(fileId); if (findfee1 != null) { fpif.setFeeId(findfee1.getFeeId()); fpif.setCost(findfee1.getPrice()); fpif.setCostCheck(findfee1.getPrice()); } else { return false; } fpif.setIsActive(1l); getSession().save(fpif); return true; } else if (pro != null && pro.getTypeFee() == 3l) { FeePaymentInfo fpif = new FeePaymentInfo(); Fee findfee1 = fdhe.findFeeByCode("CLCN"); fpif.setCreateDate(dateNow); fpif.setStatus(0l); fpif.setFileId(fileId); if (findfee1 != null) { fpif.setFeeId(findfee1.getFeeId()); fpif.setCost(findfee1.getPrice()); fpif.setCostCheck(findfee1.getPrice()); } else { return false; } fpif.setIsActive(1l); getSession().save(fpif); return true; } else { return false; } } else { //check loai thuc pham (thuc pham dac biet) CategoryDAOHE ctdhe = new CategoryDAOHE(); Category cate = ctdhe.findCategoryByTypeAndCode("SP", "TPCN"); List<Category> cate1 = ctdhe.findCategoryByTypeAndCodeNew("SP", "DBT"); int check = 0; for (int i = 0; i < cate1.size(); i++) { if (productType.equals(cate1.get(i).getCategoryId())) { check = 1; break; } } if (check == 1) { FeePaymentInfo fpif = new FeePaymentInfo(); Fee findfee1 = fdhe.findFeeByCode("TPDB"); fpif.setCreateDate(dateNow); fpif.setStatus(0l); fpif.setFileId(fileId); if (findfee1 != null) { fpif.setFeeId(findfee1.getFeeId()); fpif.setCost(findfee1.getPrice()); fpif.setCostCheck(findfee1.getPrice()); fpif.setFeeIdOld(findfee1.getFeeId()); } else { return false; } fpif.setIsActive(1l); getSession().save(fpif); } else { // thuc pham chuc nang FeePaymentInfo fpif = new FeePaymentInfo(); if (productType.equals(cate.getCategoryId())) { Fee findfee2 = fdhe.findFeeByCode("TPCN"); fpif.setCreateDate(dateNow); fpif.setStatus(0l); fpif.setFileId(fileId); if (findfee2 != null) { fpif.setFeeId(findfee2.getFeeId()); fpif.setCost(findfee2.getPrice()); fpif.setCostCheck(findfee2.getPrice()); fpif.setFeeIdOld(findfee2.getFeeId()); } else { return false; } fpif.setIsActive(1l); getSession().save(fpif); } else { Fee findfee3 = fdhe.findFeeByCode("TPK"); fpif.setCreateDate(dateNow); fpif.setStatus(0l); fpif.setFileId(fileId); if (findfee3 != null) { fpif.setFeeId(findfee3.getFeeId()); fpif.setCost(findfee3.getPrice()); fpif.setCostCheck(findfee3.getPrice()); fpif.setFeeIdOld(findfee3.getFeeId()); } else { return false; } fpif.setIsActive(1l); getSession().save(fpif); } } } // } } // sua nhom san pham va chuyen loai ho so - map lai phi if ((productTypeIdOld != null) && (!productTypeIdOld.equals(productType))) { // hieptq update 310115 // tim lai feeId cu CategoryDAOHE ctdhe = new CategoryDAOHE(); FeeDAOHE fdhe = new FeeDAOHE(); Category cate = ctdhe.findCategoryByTypeAndCode("SP", "TPCN"); List<Category> cate1 = ctdhe.findCategoryByTypeAndCodeNew("SP", "DBT"); Long feeIdOld, feeIdNew; int check = 0, check1 = 0; FeePaymentInfo fpifOld; for (int i = 0; i < cate1.size(); i++) { if (productTypeIdOld.equals(cate1.get(i).getCategoryId())) { check = 1; break; } } if (check == 1) { Fee findfee1 = fdhe.findFeeByCode("TPDB"); feeIdOld = findfee1.getFeeId(); } else // thuc pham chuc nang if (productTypeIdOld.equals(cate.getCategoryId())) { Fee findfee2 = fdhe.findFeeByCode("TPCN"); feeIdOld = findfee2.getFeeId(); } else { Fee findfee3 = fdhe.findFeeByCode("TPK"); feeIdOld = findfee3.getFeeId(); } fpifOld = fdhe.findFeePaymentInfoFileIdFeeIdIsActive(fileId, feeIdOld, 1l); // lay feeid moi for (int i = 0; i < cate1.size(); i++) { if (productType.equals(cate1.get(i).getCategoryId())) { check1 = 1; break; } } Long costNew; if (check1 == 1) { Fee findfee1 = fdhe.findFeeByCode("TPDB"); feeIdNew = findfee1.getFeeId(); costNew = findfee1.getPrice(); } else // thuc pham chuc nang if (productType.equals(cate.getCategoryId())) { Fee findfee2 = fdhe.findFeeByCode("TPCN"); feeIdNew = findfee2.getFeeId(); costNew = findfee2.getPrice(); } else { Fee findfee3 = fdhe.findFeeByCode("TPK"); feeIdNew = findfee3.getFeeId(); costNew = findfee3.getPrice(); } //fpifNew = fdhe.findFeePaymentInfoFileIdFeeIdIsActive(fileId, feeIdNew, 1l); FilesDAOHE filesdhe = new FilesDAOHE(); Files filesnew = filesdhe.findById(fileId); // check gia cu va gia moi if (fpifOld.getCostCheck().equals(costNew) || fpifOld.getCostCheck() > costNew) { if (filesnew.getStatus() == 0l) { fpifOld.setCost(fpifOld.getCostCheck()); fpifOld.setFeeId(fpifOld.getFeeIdOld()); getSession().update(fpifOld); } else { //Long newCost = costNew - fpifOld.getCost(); fpifOld.setCost(fpifOld.getCostCheck()); fpifOld.setFeeId(fpifOld.getFeeIdOld()); fpifOld.setStatus(1l); filesnew.setIsFee(1l); getSession().update(filesnew); getSession().update(fpifOld); } return true; } else if (filesnew.getStatus() == 0l) { fpifOld.setCost(costNew); fpifOld.setFeeId(feeIdNew); getSession().update(fpifOld); } else { //Long newCost = costNew - fpifOld.getCost(); fpifOld.setCost(costNew); fpifOld.setFeeId(feeIdNew); fpifOld.setStatus(0l); //Hiepvv 0803 Khong tinh phi SDBS sau cong bo ProcedureDAOHE pHE = new ProcedureDAOHE(); Procedure pdu = pHE.findById(filesnew.getFileType()); if (pdu != null && pdu.getDescription() != null && "announcementFile05".equals(pdu.getDescription())) { filesnew.setIsFee(1l); } else { filesnew.setIsFee(0l); //update binhnt // try { // if ("true".equals(ResourceBundleUtil.getString("send_service", "config"))) { // Helper h = new Helper(); // h.sendMs_340(filesnew.getFileId(), "Ho so ma: " + filesnew.getFileCode() + " Da duoc phe duyet yeu cau nop phi ho so."); // } // } catch (UnsupportedEncodingException ex) { // Logger.getLogger(FilesDAOHE.class.getName()).log(Level.SEVERE, null, ex); // } } getSession().update(filesnew); getSession().update(fpifOld); } } } else { return false; } return true; } /* *Hiepvv 08/01 *Luu phi cua ho so sua doi bo sung sau cong bo */ private Boolean saveFeeChangesAfterAnnounced(Long fileId, Long fileType) { if (fileId != null) { Date dateNow = getSysdate(); String hql = "select fpif from FeePaymentInfo fpif" + " where fpif.fileId =:fileId" + " and fpif.isActive = 1"; Query query = getSession().createQuery(hql); query.setParameter("fileId", fileId); List<FeePaymentInfo> FeePaymentInfo = query.list(); // truong hop sao chep va luu tam productType co the = null, vi the phai set = -1 if (FeePaymentInfo.isEmpty()) { FeeDAOHE fdhe = new FeeDAOHE(); List<FeeProcedure> feenew = fdhe.findAllFeeByProcedureId(fileType); // check le phi cap so theo loai ho so if (feenew != null && feenew.size() > 0) { for (int i = 0; i < feenew.size(); i++) { FeePaymentInfo fpif = new FeePaymentInfo(); //Thong tin co ban, status=1 = da dong phi fpif.setCreateDate(dateNow); fpif.setStatus(1l); fpif.setFileId(fileId); fpif.setIsActive(1l); fpif.setFeeId(feenew.get(i).getFeeId()); Fee feeTemp = (Fee) findById(Fee.class, "feeId", feenew.get(i).getFeeId()); fpif.setCost(feeTemp.getPrice()); //Thong tin fix cung cho du du lieu fpif.setPaymentPerson("ATTP"); fpif.setPaymentDate(dateNow); fpif.setFeePaymentTypeId(3L); fpif.setBillPath(""); fpif.setPaymentConfirm("ATTP"); fpif.setDateConfirm(dateNow); fpif.setCostCheck(0L); getSession().save(fpif); } } } //Hiepvv 0803 Khong tinh phi SDBS sau cong bo FilesDAOHE filesdhe = new FilesDAOHE(); Files filesnew = filesdhe.findById(fileId); filesnew.setIsFee(Constants.Status.ACTIVE); getSession().update(filesnew); } else { return false; } return true; } private Boolean saveFileForSearch(Long fileId) { try { FilesForm viewForm = getFilesFullDetail(fileId); // // save json to search // Gson gson = new Gson(); String json = gson.toJson(viewForm); FileForSearch fs = new FileForSearch(fileId); fs.setContent(json); session.saveOrUpdate(fs); return true; } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 return false; } // // end save json to search // } public int getUpdateCount() { String hql = "select count(f) from Files f" + " where f.isActive = 1" + " and f.isTemp is null" + " and f.fileId not in (select ffs.fileId from FileForSearch ffs)"; Query query = session.createQuery(hql); Long count = (Long) query.uniqueResult(); return count.intValue(); } public Boolean updateIndex(int start, int length) { String hql = "select f.fileId from Files f" + " where f.isActive = 1" + " and f.isTemp is null" + " and f.fileId not in (select ffs.fileId from FileForSearch ffs)"; Query query = session.createQuery(hql); query.setFirstResult(start); query.setMaxResults(length); List<Long> lstIds = query.list(); for (int i = 0; i < lstIds.size(); i++) { Long id = lstIds.get(i); saveFileForSearch(id); } return true; } /** * * @param form * @return */ public String validateAnnouncementForm(AnnouncementForm form, Long fileId) { String error = null; if (form.getBusinessName() == null || form.getBusinessName().trim().isEmpty()) { error = "Cha nhp tn doanh nghip"; return error; } if (form.getBusinessAddress() == null || form.getBusinessAddress().trim().isEmpty()) { error = "Cha nhp a ch doanh nghip"; return error; } if (form.getBusinessTelephone() == null || form.getBusinessTelephone().trim().isEmpty()) { error = "Cha nhp s in thoi doanh nghip"; return error; } if (!Validator.validateMobileNumber(form.getBusinessTelephone())) { error = "S in thoi doanh nghip khng ng nh dng"; return error; } if (form.getBusinessFax() != null) { if (!Validator.validateMobileNumber(form.getBusinessFax())) { error = "S fax doanh nghip khng ng nh dng"; return error; } } if (form.getBusinessEmail() != null) { if (!Validator.validateEmail(form.getBusinessEmail())) { error = "Email doanh nghip khng ng nh dng"; return error; } } ////Hiepvv ngoai le validate Files file = findById(fileId); ProcedureDAOHE pdhe = new ProcedureDAOHE(); Procedure tthc = pdhe.findById(file.getFileType()); String typeFile = ""; if (tthc != null) { typeFile = tthc.getDescription(); } //Hiepvv Khong validate voi ks4s if ("announcement4star".equalsIgnoreCase(typeFile)) { } else if (form.getProductName() == null || form.getProductName().trim().isEmpty()) { error = "Cha nhp tn sn phm"; return error; } //Hiepvv Khong validate voi ho so sua doi sau cong bo if (!("announcementFile05".equalsIgnoreCase(typeFile)) && (form.getManufactureName() == null || form.getManufactureName().trim().isEmpty())) { error = "Cha nhp tn nh sn xut"; return error; } //Hiepvv Khong validate voi ho so sua doi sau cong bo if (!("announcementFile05".equalsIgnoreCase(typeFile)) && (form.getManufactureAddress() == null || form.getManufactureAddress().trim().isEmpty())) { error = "Cha nhp a ch nh sn xut"; return error; } if (form.getManufactureTel() != null) { if (!Validator.validateMobileNumber(form.getManufactureTel())) { error = "S in thoi nh sn xut khng ng nh dng"; return error; } } if (form.getManufactureFax() != null) { if (!Validator.validateMobileNumber(form.getManufactureFax())) { error = "S fax nh sn xut khng ng nh dng"; return error; } } if (form.getManufactureEmail() != null) { if (!Validator.validateEmail(form.getManufactureEmail())) { error = "Email nh sn xut khng ng nh dng"; return error; } } //Hiepvv Khong validate voi ho so sua doi sau cong bo if (!("announcementFile05".equalsIgnoreCase(typeFile)) && (form.getNationName() == null || form.getNationName().trim().isEmpty())) { error = "Cha nhp nc xut x"; return error; } if (form.getAnnouncementNo() == null || form.getAnnouncementNo().trim().isEmpty()) { error = "Cha nhp s bn cng b"; return error; } if (!("announcementFile05".equalsIgnoreCase(typeFile)) && (form.getMatchingTarget() == null || form.getMatchingTarget().trim().isEmpty())) { error = "Cha nhp ph hp vi QCKT/Q?ATTP"; return error; } return error; } /** * * @param form * @return */ public String validateProductDetail(DetailProductForm form) { String error = null; if (form.getProductType() == null || form.getProductType() <= 0) { error = "Cha nhp nhm sn phm"; return error; } if (form.getComponents() == null || form.getComponents().trim().isEmpty()) { error = "Cha nhp thnh phn cu to"; return error; } if (form.getTimeInUse() == null || form.getTimeInUse().trim().isEmpty()) { error = "Cha nhp th?i hn s dng"; return error; } if (form.getGuideline() == null || form.getGuideline().trim().isEmpty()) { error = "Cha nhp hng dn s dng v bo qun"; return error; } if (form.getPackateMaterial() == null || form.getPackateMaterial().trim().isEmpty()) { error = "Cha nhp cht liu bao b v quy cch ng gi"; return error; } if (form.getOrigin() == null || form.getOrigin().trim().isEmpty()) { error = "Cha nhp xut x v thng nhn chu trch nhim v? cht lng hng ha"; return error; } return error; } public String validateFiles(FilesForm createForm, Long fileId) { String error = null; if (createForm.getAnnouncement() != null) { // // validate thong tin ban cong bo // error = validateAnnouncementForm(createForm.getAnnouncement(), fileId); } if (error != null) { return error; } Files file = findById(fileId); ProcedureDAOHE pdhe = new ProcedureDAOHE(); Procedure tthc = pdhe.findById(file.getFileType()); //Hiepvv Khong validate voi ho so sua doi sau cong bo va KS4s if ("announcement4star".equalsIgnoreCase(tthc.getDescription()) || "announcementFile05".equalsIgnoreCase(tthc.getDescription()) || tthc.getDescription().equals(Constants.FILE_DESCRIPTION.RE_ANNOUNCEMENT) || tthc.getDescription().equals(Constants.FILE_DESCRIPTION.REC_CONFIRM_NORMAL_IMP) || tthc.getDescription().equals(Constants.FILE_DESCRIPTION.RE_CONFIRM_FUNC_IMP) || tthc.getDescription().equals(Constants.FILE_DESCRIPTION.RE_CONFIRM_FUNC_VN) || tthc.getDescription().equals(Constants.FILE_DESCRIPTION.RE_CONFIRM_NORMAL_VN)) { //do nothing } else if (createForm.getDetailProduct() != null) { // // validate thong tin chi tiet // error = validateProductDetail(createForm.getDetailProduct()); } //hieptq update check reset fee 100715 if (createForm.getUserSigned() != null && "reset".equals(createForm.getUserSigned())) { // // validate thong tin chi tiet // error = "Chuyn sang loi h s c ph cao hn phi ch?n li nhm sn phm"; } if (error != null) { return error; } if (createForm.getReIssueForm() != null) { // // validate cap lai, do chua su dung nen tam de trong // } // if (createForm.getTestRegistration() != null) { // // // // validate dang ky xet nghiem // // ko co thong tin can validate // // // } // // validate mainly target // if (createForm.getLstMainlyTarget() != null && !createForm.getLstMainlyTarget().isEmpty()) { for (MainlyTarget item : createForm.getLstMainlyTarget()) { if (item.getTargetName() == null || item.getTargetName().trim().isEmpty()) { error = "Cha nhp tn ch tiu cht lng chnh"; return error; } if (item.getUnitName() == null || "-- Ch?n --".equals(item.getUnitName())) { error = "Cha nhp n v ca ch tiu cht lng chnh"; return error; } if (item.getPublishLevel() == null || item.getPublishLevel().trim().isEmpty()) { error = "Cha nhp mc cng b ca ch tiu cht lng chnh"; return error; } } } // // validate product target // if (createForm.getLstBioTarget() != null && !createForm.getLstBioTarget().isEmpty()) { for (ProductTarget item : createForm.getLstBioTarget()) { if (item.getTargetName() == null || item.getTargetName().trim().isEmpty()) { error = "Cha nhp tn ch tiu vi sinh vt"; return error; } if (item.getUnitName() == null || "-- Ch?n --".equals(item.getUnitName())) { error = "Cha nhp n v ca ch tiu vi sinh vt"; return error; } if (item.getMaxLevel() == null || item.getMaxLevel().trim().isEmpty()) { error = "Cha nhp mc ti a ca ch tiu vi sinh vt"; return error; } } } if (createForm.getLstHeavyMetal() != null && !createForm.getLstHeavyMetal().isEmpty()) { for (ProductTarget item : createForm.getLstHeavyMetal()) { if (item.getTargetName() == null || item.getTargetName().trim().isEmpty()) { error = "Cha nhp tn ch tiu hm lng kim loi nng"; return error; } if (item.getUnitName() == null || "-- Ch?n --".equals(item.getUnitName())) { error = "Cha nhp n v ca ch tiu hm lng kim loi nng"; return error; } if (item.getMaxLevel() == null || item.getMaxLevel().trim().isEmpty()) { error = "Cha nhp mc ti a ca ch tiu hm lng kim loi nng"; return error; } } } if (createForm.getLstChemical() != null && !createForm.getLstChemical().isEmpty()) { for (ProductTarget item : createForm.getLstChemical()) { if (item.getTargetName() == null || item.getTargetName().trim().isEmpty()) { error = "Cha nhp tn ch tiu hm lng ha cht khng mong mun"; return error; } if (item.getUnitName() == null || "-- Ch?n --".equals(item.getUnitName())) { error = "Cha nhp n v ca ch tiu cht hm lng ha cht khng mong mun"; return error; } if (item.getMaxLevel() == null || item.getMaxLevel().trim().isEmpty()) { error = "Cha nhp mc ti a ca ch tiu hm lng ha cht khng mong mun"; return error; } } } // // validate attachs // Procedure pd = pdhe.findById(createForm.getFileType()); if (pd == null) { error = "Khng xc nh c loi h s"; return error; } int count = StringUtils.countMatches(pd.getFileList(), "(*)"); if (count > 0) { if (createForm.getLstAttachs() == null) { error = "Cha nhp y file nh km"; return error; } if (count > createForm.getLstAttachs().size()) { error = "Cha nhp y file nh km"; return error; } } count = 0;// dem so file la nhan if (createForm.getLstAttachs() != null && !createForm.getLstAttachs().isEmpty()) { for (VoAttachs item : createForm.getLstAttachs()) { if (item.getAttachName() == null || item.getAttachName().trim().isEmpty()) { error = "Cha nhp tn file nh km"; return error; } if (item.getCategoryName() == null || item.getCategoryName().trim().isEmpty()) { error = "Cha nhp tn ti liu"; return error; } if (item.getAttachPath() == null || item.getAttachPath().trim().isEmpty()) { error = "Cha nhp file nh km"; return error; } if (item.getObjectType().equals(Constants.OBJECT_TYPE.FILES_LABEL)) { count++; } } } //Hiepvv Khong validate voi ho so sua doi sau cong bo if (count == 0 && !("announcementFile05".equalsIgnoreCase(pd.getDescription()))) { error = "Cha ch?n nhn cho sn phm"; return error; } else//150709 binhnt53 add check max nhan duoc chon if (count > 3) { error = "Vt qu s lng tp c ch?n nh km cng bn cng b(Ti a 3 tp)"; return error; } //!150709 // // validate ke hoach kiem soat chat luong // if (createForm.getLstQualityControl() != null && !createForm.getLstQualityControl().isEmpty()) { for (QualityControlPlan item : createForm.getLstQualityControl()) { if (item.getProductProcessDetail() == null || item.getProductProcessDetail().trim().isEmpty()) { error = "Cha nhp cc qu trnh sn xut"; return error; } } } return error; } public String validateFiles(Long fileId) { String error; FilesForm form = getFilesFullDetail(fileId); if (form == null) { error = "Khng tn ti h s"; } else { error = validateFiles(form, fileId); } return error; } /** * * @param userId * @param businessId * @param fileId * @return 0 : xa thnh cng 1 : Khng c quy?n xa 2 : gi i k xa * c */ public int deleteFile(Long userId, Long businessId, Long fileId) { int iReturn = 0; Files file = findById(fileId); if (file.getDeptId() != null && businessId != null && file.getDeptId().equals(businessId)) { if (Constants.FILE_STATUS.NEW_CREATE.equals(file.getStatus()) || Constants.FILE_STATUS.FEDBACK_TO_ADD.equals(file.getStatus()) || Constants.FILE_STATUS.RECEIVED_REJECT.equals(file.getStatus())) { //hieptq update neu ho so bi ke toan tu choi xoa di is_active = 2 if (Constants.FILE_STATUS.RECEIVED_REJECT.equals(file.getStatus())) { file.setIsActive(2l); } else { file.setIsActive(0l); } getSession().update(file); } else { iReturn = 2; } } else { iReturn = 1; } return iReturn; } /** * ly danh sch n v gi h s n * * @param fileId * @param provinceId * @param start * @param count * @param sortField * @return */ public GridResult getAgencyToSendFile(Long fileId, Long provinceId, int start, int count, String sortField) { Files file = findById(fileId); if (file == null) { return null; } Long fileType = file.getFileType(); List lstParam = new ArrayList(); GridResult gr; // // Tim cac don vi dap ung vua thuoc tinh lai vua co luong xu ly // String hql = " from Flow f where f.isActive = 1 "; hql += " and f.flowType=?"; lstParam.add(fileType); if (provinceId != null) { hql += " and f.deptId in (select d from Department d where d.provinceId = ?) "; lstParam.add(provinceId); } Query countQuery = getSession().createQuery("select count(f) " + hql); Query query = getSession().createQuery("select f " + hql); for (int i = 0; i < lstParam.size(); i++) { query.setParameter(i, lstParam.get(i)); countQuery.setParameter(i, lstParam.get(i)); } query.setFirstResult(start); query.setMaxResults(count); int total = Integer.parseInt(countQuery.uniqueResult().toString()); if (total > 0) { List lstResult = query.list(); gr = new GridResult(total, lstResult); } else { // // Neu tim theo tinh ko co don vi nao dap ung thi chi tim cac don vi co luong thoi xu ly loai ho so thoi // lstParam.clear(); hql = " from Flow f where f.isActive = 1 "; hql += " and f.flowType=?"; lstParam.add(fileType); countQuery = getSession().createQuery("select count(f) " + hql); query = getSession().createQuery("select f " + hql); for (int i = 0; i < lstParam.size(); i++) { query.setParameter(i, lstParam.get(i)); countQuery.setParameter(i, lstParam.get(i)); } query.setFirstResult(start); query.setMaxResults(count); List lstResult = query.list(); gr = new GridResult(total, lstResult); } return gr; } /** * ly cc danh sch ca h s * * @param fileId * @return */ public List getMainlyTargetOfFile(Long fileId) { String hql = "select m from MainlyTarget m where m.fileId = ? order by m.mainlyTargetId"; Query query = getSession().createQuery(hql); query.setParameter(0, fileId); List lst = query.list(); return lst; } /** * ch tiu sn phm h s * * @param fileId * @return */ public List getProductTargetOfFile(Long fileId) { String hql = "select m from ProductTarget m where m.fileId = ? order by m.productTargetId "; Query query = getSession().createQuery(hql); query.setParameter(0, fileId); List lst = query.list(); return lst; } /** * thng tin ch tiu sn phm * * @param fileId * @param type * @return */ public List getProductTargetOfFile(Long fileId, Long type) { String hql = "select m from ProductTarget m where m.fileId = ? and m.targetType = ? order by m.productTargetId "; Query query = getSession().createQuery(hql); query.setParameter(0, fileId); query.setParameter(1, type); List lst = query.list(); return lst; } /** * ly file att h s * * @param fileId * @return */ public List getAttachsOfFile(Long fileId) { String hql = "select m from VoAttachs m where m.isActive = 1 and m.objectId = ? and (m.objectType=? or m.objectType=?) order by m.attachId "; Query query = getSession().createQuery(hql); query.setParameter(0, fileId); query.setParameter(1, com.viettel.common.util.Constants.OBJECT_TYPE.FILES); query.setParameter(2, com.viettel.common.util.Constants.OBJECT_TYPE.FILES_LABEL); List lst = query.list(); return lst; } /** * Hiepvv 11/03 ly file cong van sdbs sau cong bo * * @param fileId * @return */ public List getAttachsOfFileSDBS(Long fileId) { String hql = "select m from VoAttachs m where m.isActive = 1 and m.objectId = ? and (m.objectType=? or m.objectType=?) and m.attachName like 'CongvanSDBSsaucongbo%' order by m.attachId "; Query query = getSession().createQuery(hql); query.setParameter(0, fileId); query.setParameter(1, 40L); query.setParameter(2, 41L); List lst = query.list(); return lst; } /** * qun l cht lng * * @param fileId * @return */ public List getQualityControlOfFile(Long fileId) { String hql = "select m from QualityControlPlan m where m.fileId = ? order by m.qualityControlPlanId "; Query query = getSession().createQuery(hql); query.setParameter(0, fileId); List lst = query.list(); return lst; } /** * get danh sch sn phm * * @param fileId * @return */ public List getProductOfFile(Long fileId) { String hql = "select m from ProductInFile m where m.fileId = ? order by m.productInFileId "; Query query = getSession().createQuery(hql); query.setParameter(0, fileId); List lst = query.list(); return lst; } /** * tra ve true neu co ban ghi bi trung, tra ve false neu ko bi trung * * @param form * @return */ public boolean isDuplicate(FilesForm form) { if (form == null) { return false; } // List lstParam = new ArrayList(); // String hql = "select count(b) from Business b where b.isActive = 1 "; // if (form.getBusinessId() != null && form.getBusinessId() > 0l) { // hql += " and b.businessId <> ? "; // lstParam.add(form.getBusinessId()); // } // // if (form.getBusinessTaxCode() != null && form.getBusinessTaxCode().trim().length() > 0) { // hql += " and lower(b.businessTaxCode) = ?"; // lstParam.add(form.getBusinessTaxCode().toLowerCase()); // } // if (form.getBusinessLicense() != null && form.getBusinessLicense().trim().length() > 0) { // hql += " and lower(b.businessLicense) = ?"; // lstParam.add(form.getBusinessLicense().toLowerCase()); // } // // Query query = getSession().createQuery(hql); // for (int i = 0; i < lstParam.size(); i++) { // query.setParameter(i, lstParam.get(i)); // } // // Long count = Long.parseLong(query.uniqueResult().toString()); // boolean bReturn = false; // if (count >= 1l) { // bReturn = true; // } boolean bReturn = false; return bReturn; } /** * Tm tt c X l by FilesId * * @param fileId * @param deptId * @param userId * @param start * @param count * @param sortField * @return */ public GridResult findAllProcessByFileId(Long fileId, Long deptId, Long userId, int start, int count, String sortField) { String hql = " from Process p " // + "where p.isActive=1 and p.objectId=? and p.objectType=? and (( (p.sendUserId =? or p.sendGroupId =? ) and (p.processType=? or p.processType=?)) or p.processType=? ) ";//b? xut thm nh + "where p.isActive=1 and p.objectId=? and p.objectType=? and (( (p.sendUserId =? or p.sendGroupId =? ) and (p.processType=? or p.processType=?))) "; List lstParam = new ArrayList(); lstParam.add(fileId); lstParam.add(Constants.OBJECT_TYPE.FILES); lstParam.add(userId); lstParam.add(deptId); lstParam.add(Constants.PROCESS_TYPE.COOPERATE); lstParam.add(Constants.PROCESS_TYPE.MAIN); //lstParam.add(Constants.PROCESS_TYPE.PROPOSE); Query countQuery = getSession().createQuery("select count(p) " + hql); Query query = getSession().createQuery("select p " + hql); for (int i = 0; i < lstParam.size(); i++) { query.setParameter(i, lstParam.get(i)); countQuery.setParameter(i, lstParam.get(i)); } query.setFirstResult(start); query.setMaxResults(count); int total = Integer.parseInt(countQuery.uniqueResult().toString()); List<Files> lstResult = query.list(); GridResult gr = new GridResult(total, lstResult); return gr; } /** * tm lung x l h s fileId * * @param fileId * @param deptId * @param userId * @param start * @param count * @param sortField * @return */ public GridResult findAllCoProcessByFileId(Long fileId, Long deptId, Long userId, int start, int count, String sortField) { String hql = " from Process p " // + "where p.isActive=1 and p.objectId=? and p.objectType=? and (( (p.sendUserId =? or p.sendGroupId =? ) and (p.processType=? or p.processType=?)) or p.processType=? ) ";//b? xut thm nh + "where p.isActive=1 and p.objectId=? and p.objectType=? and (( (p.sendUserId =? or p.sendGroupId =? ) and p.processType=?)) "; List lstParam = new ArrayList(); lstParam.add(fileId); lstParam.add(Constants.OBJECT_TYPE.FILES); lstParam.add(userId); lstParam.add(deptId); lstParam.add(Constants.PROCESS_TYPE.COOPERATE); // lstParam.add(Constants.PROCESS_TYPE.MAIN); //lstParam.add(Constants.PROCESS_TYPE.PROPOSE); Query countQuery = getSession().createQuery("select count(p) " + hql); Query query = getSession().createQuery("select p " + hql); for (int i = 0; i < lstParam.size(); i++) { query.setParameter(i, lstParam.get(i)); countQuery.setParameter(i, lstParam.get(i)); } query.setFirstResult(start); query.setMaxResults(count); int total = Integer.parseInt(countQuery.uniqueResult().toString()); List<Files> lstResult = query.list(); GridResult gr = new GridResult(total, lstResult); return gr; } /** * tim h s theo email * * @param email * @param start * @param count * @param sortField * @return */ public Files findFilesByCodeEmail(ReceiveEmail email, int start, int count, String sortField) { String[] content = email.getContent().split(" "); String filesCode = content[0]; String hql = " from Files t where t.isActive = 1 and (f.isTemp = null or f.isTemp = 0 ) "; List lstParam = new ArrayList(); if (filesCode != null && filesCode.trim().length() > 0) { hql += " and lower(c.fileCode) = ? "; lstParam.add(filesCode); } Query countQuery = getSession().createQuery("select count(*) " + hql); Query query = getSession().createQuery("select t " + hql + " order by c.fileId desc"); for (int i = 0; i < lstParam.size(); i++) { query.setParameter(i, lstParam.get(i)); countQuery.setParameter(i, lstParam.get(i)); } query.setFirstResult(start); query.setMaxResults(count); // int total = Integer.parseInt(countQuery.uniqueResult().toString()); List<Files> lstResult = query.list(); if (!lstResult.isEmpty()) { return lstResult.get(0); } else { return null; } } /** * Lu trng thi H s vo Tin nhn * * @param files * @param content */ public void saveStatusFiles(Files files, String content) { UsersDAOHE userdao = new UsersDAOHE(); Users users = userdao.findById(files.getUserCreateId()); ReceiveEmail recEmail = new ReceiveEmail(); recEmail.setContent(content); recEmail.setEmail(users.getEmail()); recEmail.setIsProcess(-2); recEmail.setReceiveTime(new java.util.Date()); recEmail.setMsgType(2);//cont getSession().save(recEmail); } /** * Nhp ni dung trnh k * * @param form * @param userId * @param userName * @return */ public boolean onSendToSign(FilesForm form, Long userId, String userName) { boolean bReturn = true; try { Files file = findById(form.getFileId()); if (file == null) { bReturn = false; } else { file.setStatus(Constants.FILE_STATUS.SIGNING); file.setStaffSigningId(userId); file.setStaffSigningName(userName); file.setSigningDate(form.getSigningDate()); file.setSigningContent(form.getSigningContent()); getSession().update(file); bReturn = true; } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } return bReturn; } /** * k duyt * * @param form * @param userId * @param userName * @return */ public boolean onSign(FilesForm form, Long userId, String userName) { boolean bReturn = true; try { Files file = findById(form.getFileId()); if (file == null) { bReturn = false; } else { file.setStatus(Constants.FILE_STATUS.SIGNED); file.setLeaderStaffSignId(userId); file.setLeaderStaffSignName(userName); file.setSigningDate(form.getSignDate()); file.setSignContent(form.getSignContent()); getSession().update(file); bReturn = true; } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } return bReturn; } /** * T chi k duyt * * @param form * @param userId * @param userName * @return */ public boolean onReject(FilesForm form, Long userId, String userName) { boolean bReturn = true; try { Files file = findById(form.getFileId()); Date dateNow = getSysdate(); if (file == null) { bReturn = false; } else { file.setStatus(Constants.FILE_STATUS.REJECT); file.setLeaderStaffSignId(userId); file.setLeaderStaffSignName(userName); file.setSignDate(form.getSignDate()); file.setSignContent(form.getSignContent()); file.setModifyDate(dateNow); getSession().update(file); bReturn = true; } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } return bReturn; } /** * get Tn trng thi h s * * @param status * @return */ public static String getFileStatusName(Long status) { String statusName; switch (status.intValue()) { case 0: statusName = "Mi to"; break; case 1: statusName = "Mi np"; break; case 2: statusName = "? c ? xut x l"; break; case 3: statusName = "? phn cng"; break; case 4: statusName = "? thm nh"; break; case 5: statusName = "? xem xt"; break; case 6: statusName = "? ph duyt"; break; case 7: statusName = "Chuyn vin KL: S?BS"; break; case 8: statusName = "Tr thm nh li"; break; case 9: statusName = "Tr xem xt li"; break; case 10: statusName = "? to giy php"; break; case 11: statusName = "? trnh k giy php"; break; case 12: statusName = "? k giy php"; break; case 13: statusName = "? t chi giy php"; break; case 14: statusName = "? tip nhn"; break; case 15: statusName = "? i chiu"; break; case 16: statusName = "? i chiu, c sai lch"; break; case 17: statusName = "? tip nhn h s sa i b sung"; break; case 18: statusName = "Mi np ch? tip nhn S?BS"; break; case 19: statusName = "? xem xt yu cu S?BS"; break; case 20: statusName = "? gi cng vn yu cu S?BS"; break; case 21: statusName = "? t chi - C HD b sung"; break; case 22: statusName = "? tr bn cng b"; break; case 23: statusName = "? thng bo i chiu h s"; break; case 24: statusName = "? xem xt i chiu h s"; break; case 25: statusName = "? tr li xem xt i chiu li"; break; case 26: statusName = "? xem xt cng vn S?BS"; break; case 27: statusName = "? ph duyt cng vn S?BS"; break; case 28: statusName = "? son tho cng vn S?BS"; break; case 29: statusName = "? trnh cc trng xem xt h s"; break; case 30: statusName = "H s cc trng quyt nh"; break; case 31: statusName = "H s k ton xc nhn ph thm nh"; break; case 32: statusName = "H s k ton xc nhn l ph cp s"; break; case 33: statusName = "H s b VT t chi tip nhn S?BS"; break; default: statusName = ""; } return statusName; } /** * T chi Tip nhn h s - Vn th * * @param form * @param userId * @param userName * @return */ public boolean rejectReveived(FilesForm form, Long userId, String userName) { boolean bReturn = true; try { Files file = findById(form.getFileId()); Date dateNow = getSysdate(); if (file == null) { bReturn = false; } else { file.setStatus(Constants.FILE_STATUS.FEDBACK_TO_ADD); file.setModifyDate(dateNow); file.setStaffSigningId(userId); file.setStaffSigningName(userName); if (form.getSignDate() == null) { file.setSignDate(dateNow); } else { file.setSignDate(form.getSignDate()); } //file.setSignContent(form.getSignContent()); getSession().update(file); bReturn = true; } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } return bReturn; } /** * tiep nhan ho so - vai tro van thu binhnt53 * * @param form * @param deptId * @param deptName * @param userId * @param userName * @return */ public boolean onReceivedFile(FilesForm form, Long deptId, String deptName, Long userId, String userName) { boolean bReturn = true; try { Date dateNow = getSysdate(); Files file = findById(form.getFileId()); if (file == null) { bReturn = false; } else { //140404 Long processStatus = file.getStatus(); if (processStatus.equals(Constants.FILE_STATUS.NEW_TO_ADD) || processStatus.equals(Constants.FILE_STATUS.RECEIVED_REJECT_TO_ADD)) {//neu ho so la nop sdbs k tao so if (form.getStatus().equals(Constants.FILE_STATUS.RECEIVED_REJECT)) { file.setStatus(Constants.FILE_STATUS.RECEIVED_REJECT_TO_ADD); file.setDisplayStatus(getFileStatusName(Constants.FILE_STATUS.RECEIVED_REJECT_TO_ADD)); file.setClericalRequest(form.getClericalRequest()); } else { file.setStatus(Constants.FILE_STATUS.RECEIVED_TO_ADD); file.setDisplayStatus(getFileStatusName(Constants.FILE_STATUS.RECEIVED_TO_ADD)); } //file.setReceiveNo(getNewReceiveNo(deptId)); } else if (form.getStatus().equals(Constants.FILE_STATUS.RECEIVED_REJECT)) { file.setStatus(Constants.FILE_STATUS.RECEIVED_REJECT); file.setDisplayStatus(getFileStatusName(Constants.FILE_STATUS.RECEIVED_REJECT)); file.setClericalRequest(form.getClericalRequest()); } else { file.setStatus(Constants.FILE_STATUS.RECEIVED); file.setDisplayStatus(getFileStatusName(Constants.FILE_STATUS.RECEIVED)); if (file.getReceiveNo() == null || file.getReceiveNo().trim().length() == 0) { file.setReceiveNo(getNewReceiveNo(deptId)); } } file.setModifyDate(dateNow); // file.setIsFee(form.getIsFee()); file.setStaffSigningId(userId); file.setStaffSigningName(userName); if (form.getSignDate() == null) { file.setSignDate(dateNow); } else { file.setSignDate(form.getSignDate()); } //140627 UPDATE BO SUNG THOI GIAN HAN CONG BO, PHAN HOI HO SO if (!form.getStatus().equals(Constants.FILE_STATUS.RECEIVED_REJECT)) { file.setReceivedDate(dateNow); ResourceBundle rb = ResourceBundle.getBundle("config"); ProcedureDAOHE procedureDAOHE = new ProcedureDAOHE(); Procedure procedurebo = procedureDAOHE.findById(file.getFileType()); if ("announcement4star".equalsIgnoreCase(procedurebo.getDescription())) { file.setDeadlineApprove(getDateWorkingTime(15)); file.setDeadlineComment(getDateWorkingTime(15)); } else { int CB = 0, PH = 0; try { CB = Integer.parseInt(rb.getString(procedurebo.getDescription() + "_CB")); } catch (NumberFormatException ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } try { PH = Integer.parseInt(rb.getString(procedurebo.getDescription() + "_PH")); } catch (NumberFormatException ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } if (CB > 0) { file.setDeadlineApprove(getDateWorkingTime(CB)); } if (PH > 0) { file.setDeadlineComment(getDateWorkingTime(PH)); } } } ProcessDAOHE psdhe = new ProcessDAOHE(); Process ptmp = psdhe.getProcessByAction(file.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, processStatus, Constants.FILE_STATUS.NEW_CREATE); if (ptmp != null) { if (processStatus.equals(Constants.FILE_STATUS.NEW_TO_ADD)) { if (form.getStatus().equals(Constants.FILE_STATUS.RECEIVED_REJECT)) { ptmp.setStatus(Constants.FILE_STATUS.RECEIVED_REJECT_TO_ADD); } else { ptmp.setStatus(Constants.FILE_STATUS.RECEIVED_TO_ADD); } } else if (form.getStatus().equals(Constants.FILE_STATUS.RECEIVED_REJECT)) { ptmp.setStatus(form.getStatus()); } else { ptmp.setStatus(Constants.FILE_STATUS.RECEIVED); } ptmp.setLastestComment(form.getStaffRequest()); getSession().update(ptmp); } Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); // Neu khong co luong if (file.getStatus().equals(Constants.FILE_STATUS.RECEIVED)) { // Gui toi chinh don vi quan ly de tiep nhan newP.setReceiveDate(dateNow); if (form.getProcessDeptName() != null && form.getProcessDeptId() != null) { newP.setReceiveGroup(form.getProcessDeptName()); newP.setReceiveGroupId(form.getProcessDeptId()); } else { newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); } newP.setProcessStatus(file.getStatus()); // De xu ly newP.setStatus(0l); // Moi den chua xu ly newP.setIsActive(1l); } else { if (file.getStatus().equals(Constants.FILE_STATUS.RECEIVED_TO_ADD)) { //gui cho chuyen vien tham dinh ho so newP.setReceiveDate(dateNow); //140407 ProcessDAOHE processDAOHE = new ProcessDAOHE(); Process userAction = processDAOHE.findProcessByActionEvaluate(file.getFileId()); if (userAction != null) { newP.setReceiveUser(userAction.getReceiveUser()); newP.setReceiveUserId(userAction.getReceiveUserId()); newP.setReceiveGroup(userAction.getReceiveGroup()); newP.setReceiveGroupId(userAction.getReceiveGroupId()); } else { newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); } // newP.setProcessStatus(file.getStatus()); // De xu ly newP.setStatus(0l); // Moi den chua xu ly newP.setIsActive(1l); } if (file.getStatus().equals(Constants.FILE_STATUS.RECEIVED_REJECT)) { //tu choi tiep nhan newP.setReceiveDate(dateNow); ProcessDAOHE processDAOHE = new ProcessDAOHE();//140407 //Process userAction = processDAOHE.findProcessByActionEvaluate(file.getFileId());//141217u binhnt update thay lai luong tra lai doanh nghiep khi tu choi tiep nhan ho so Process userAction = processDAOHE.getProcessByAction(file.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.NEW, Constants.FILE_STATUS.NEW_CREATE); if (userAction != null) { //141217u binhnt update thay lai luong tra lai doanh nghiep khi tu choi tiep nhan ho so newP.setReceiveUser(userAction.getSendUser()); newP.setReceiveUserId(userAction.getSendUserId()); newP.setReceiveGroup(userAction.getSendGroup()); newP.setReceiveGroupId(userAction.getSendGroupId()); /* newP.setReceiveUser(userAction.getReceiveUser()); newP.setReceiveUserId(userAction.getReceiveUserId()); newP.setReceiveGroup(userAction.getReceiveGroup()); newP.setReceiveGroupId(userAction.getReceiveGroupId()); */ } else { newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); } // newP.setProcessStatus(file.getStatus()); // De xu ly newP.setStatus(0l); // Moi den chua xu ly newP.setIsActive(1l); } if (file.getStatus().equals(Constants.FILE_STATUS.RECEIVED_REJECT_TO_ADD)) {//tu choi tiep nhan sdbs newP.setReceiveDate(dateNow); if (ptmp != null) { //141217u binhnt update thay lai luong tra lai doanh nghiep khi tu choi tiep nhan ho so newP.setReceiveUser(ptmp.getSendUser()); newP.setReceiveUserId(ptmp.getSendUserId()); newP.setReceiveGroup(ptmp.getSendGroup()); newP.setReceiveGroupId(ptmp.getSendGroupId()); } else { newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); } newP.setProcessStatus(file.getStatus()); // De xu ly newP.setStatus(0l); // Moi den chua xu ly newP.setIsActive(1l); } } getSession().save(newP); // } getSession().update(file); MessageSmsDAOHE msdhe = new MessageSmsDAOHE(); String msg = "Ho so ma: " + file.getFileCode() + " cua doanh nghiep: " + file.getBusinessName() + " dang trong trang thai: da tiep nhan"; msdhe.saveMessageSMS(userId, file.getUserCreateId(), msg); //email MessageEmailDAOHE msedhe = new MessageEmailDAOHE(); String msge = "H s m: " + file.getFileCode() + " ca doanh nghip: " + file.getBusinessName() + " ang trong trng thi: ? tip nhn"; msedhe.saveMessageEmail(userId, file.getUserCreateId(), msge); //send group leader of dept 140915 binhnt53 EmailSmsDAO emdao = new EmailSmsDAO(); emdao.alertLeaderOfStaffAssignFiles(deptId, file.getFileCode(), file.getBusinessName()); // bReturn = true; } } catch (Exception ex) { bReturn = false; LogUtil.addLog(ex);//binhnt sonar a160901 } return bReturn; } public boolean onReceivedFileToStaff(FilesForm form, Long userId, String userName) { boolean bReturn = true; try { Date dateNow = getSysdate(); Files file = findById(form.getFileId()); if (file == null) { bReturn = false; } else { Long processStatus = file.getStatus(); file.setStatus(Constants.FILE_STATUS.RECEIVED_TO_ADD); file.setDisplayStatus(getFileStatusName(Constants.FILE_STATUS.RECEIVED_TO_ADD)); file.setReceivedDate(dateNow); ResourceBundle rb = ResourceBundle.getBundle("config"); ProcedureDAOHE procedureDAOHE = new ProcedureDAOHE(); Procedure procedurebo = procedureDAOHE.findById(file.getFileType()); if ("announcement4star".equalsIgnoreCase(procedurebo.getDescription())) { file.setDeadlineApprove(getDateWorkingTime(15)); file.setDeadlineComment(getDateWorkingTime(15)); } else { int CB = 0, PH = 0; try { CB = Integer.parseInt(rb.getString(procedurebo.getDescription() + "_CB")); } catch (NumberFormatException ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } try { PH = Integer.parseInt(rb.getString(procedurebo.getDescription() + "_PH")); } catch (NumberFormatException ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } if (CB > 0) { file.setDeadlineApprove(getDateWorkingTime(CB)); } if (PH > 0) { file.setDeadlineComment(getDateWorkingTime(PH)); } } ProcessDAOHE psdhe = new ProcessDAOHE(); Process ptmp = psdhe.getProcessByAction(file.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, processStatus, Constants.FILE_STATUS.NEW_CREATE); if (ptmp != null) { if (processStatus.equals(Constants.FILE_STATUS.EVALUATED_TO_ADD)) { ptmp.setStatus(Constants.FILE_STATUS.RECEIVED_TO_ADD); } ptmp.setLastestComment(form.getStaffRequest()); getSession().update(ptmp); } Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setSendDate(dateNow); newP.setSendGroup(ptmp.getReceiveGroup()); newP.setSendGroupId(ptmp.getReceiveGroupId()); newP.setSendUserId(userId); newP.setSendUser(userName); if (file.getStatus().equals(Constants.FILE_STATUS.RECEIVED_TO_ADD)) { //gui cho chuyen vien tham dinh ho so newP.setReceiveDate(dateNow); //140407 ProcessDAOHE processDAOHE = new ProcessDAOHE(); Process userAction = processDAOHE.findProcessByActionEvaluate(file.getFileId()); if (userAction != null) { newP.setReceiveUser(userAction.getReceiveUser()); newP.setReceiveUserId(userAction.getReceiveUserId()); newP.setReceiveGroup(userAction.getReceiveGroup()); newP.setReceiveGroupId(userAction.getReceiveGroupId()); } else { newP.setReceiveGroup(ptmp.getReceiveGroup()); newP.setReceiveGroupId(ptmp.getReceiveGroupId()); } // newP.setProcessStatus(file.getStatus()); // De xu ly newP.setStatus(0l); // Moi den chua xu ly newP.setIsActive(1l); } getSession().save(newP); getSession().update(file); MessageSmsDAOHE msdhe = new MessageSmsDAOHE(); String msg = "Ho so ma: " + file.getFileCode() + " cua doanh nghiep: " + file.getBusinessName() + " dang trong trang thai: da tiep nhan"; msdhe.saveMessageSMS(userId, file.getUserCreateId(), msg); MessageEmailDAOHE msedhe = new MessageEmailDAOHE(); String msge = "H s m: " + file.getFileCode() + " ca doanh nghip: " + file.getBusinessName() + " ang trong trng thi: ? tip nhn"; msedhe.saveMessageEmail(userId, file.getUserCreateId(), msge); EmailSmsDAO emdao = new EmailSmsDAO(); emdao.alertLeaderOfStaffAssignFiles(ptmp.getReceiveGroupId(), file.getFileCode(), file.getBusinessName()); // bReturn = true; } } catch (Exception ex) { bReturn = false; LogUtil.addLog(ex);//binhnt sonar a160901 } return bReturn; } /** * hieptq update 120114 * * @param form * @param deptId * @param deptName * @param userId * @param userName * @param lstObjectId * @return */ public boolean onReceivedMoreFile(FilesForm form, Long deptId, String deptName, Long userId, String userName, String lstObjectId) { boolean bReturn = true; boolean bCheckCount = true; String[] lstObjectIdSplit = lstObjectId.split(","); int countObj = lstObjectIdSplit.length; try {//form.setStatus(Constants.FILE_STATUS.RECEIVED); for (int i = 0; i < countObj; i++) { Long fileId = Long.parseLong(lstObjectIdSplit[i]); Files file = findById(fileId); if (file == null) { bReturn = false; } else { Long processStatus = file.getStatus(); ProcedureDepartmentDAOHE prodepdaohe = new ProcedureDepartmentDAOHE(); List lstCQXL = prodepdaohe.getAllProcedureDepartmentByProcedureId(file.getFileType()); //binhnt update 150918 if ((lstCQXL == null || lstCQXL.size() > 1) && !processStatus.equals(Constants.FILE_STATUS.NEW_TO_ADD)) { bCheckCount = false; continue; } //140404 if (processStatus.equals(Constants.FILE_STATUS.NEW_TO_ADD)) {//neu ho so la nop sdbs k tao so file.setStatus(Constants.FILE_STATUS.RECEIVED_TO_ADD); file.setDisplayStatus(getFileStatusName(Constants.FILE_STATUS.RECEIVED_TO_ADD)); } else { file.setStatus(Constants.FILE_STATUS.RECEIVED); file.setDisplayStatus(getFileStatusName(Constants.FILE_STATUS.RECEIVED)); if (file.getReceiveNo() == null || file.getReceiveNo().trim().length() == 0) { file.setReceiveNo(getNewReceiveNo(deptId)); } } file.setReceivedDate(getSysdate()); file.setStaffSigningId(userId); file.setStaffSigningName(userName); file.setSignDate(getSysdate()); //140627 UPDATE BO SUNG THOI GIAN HAN CONG BO, PHAN HOI HO SO ResourceBundle rb = ResourceBundle.getBundle("config"); Procedure procedurebo; ProcedureDAOHE procedureDAOHE = new ProcedureDAOHE(); procedurebo = procedureDAOHE.findById(file.getFileType()); int CB = 0, PH = 0; try { CB = Integer.parseInt(rb.getString(procedurebo.getDescription() + "_CB")); } catch (NumberFormatException ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } try { PH = Integer.parseInt(rb.getString(procedurebo.getDescription() + "_PH")); } catch (NumberFormatException ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } if (CB > 0) { file.setDeadlineApprove(getDateWorkingTime(CB)); } if (PH > 0) { file.setDeadlineComment(getDateWorkingTime(PH)); } ProcessDAOHE psdhe = new ProcessDAOHE(); Process ptmp = psdhe.getProcessByAction(file.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, processStatus, Constants.FILE_STATUS.NEW_CREATE); if (ptmp != null) { if (processStatus.equals(Constants.FILE_STATUS.NEW_TO_ADD)) { ptmp.setStatus(Constants.FILE_STATUS.RECEIVED_TO_ADD); } else { ptmp.setStatus(Constants.FILE_STATUS.RECEIVED); } getSession().update(ptmp); } Process newP = new Process(); newP.setObjectId(fileId); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setSendDate(getSysdate()); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); if (file.getStatus().equals(Constants.FILE_STATUS.RECEIVED)) { // Gui toi chinh don vi quan ly de tiep nhan newP.setReceiveDate(getSysdate()); if (form != null && form.getProcessDeptName() != null && form.getProcessDeptId() != null) { newP.setReceiveGroup(form.getProcessDeptName()); newP.setReceiveGroupId(form.getProcessDeptId()); } else if (!lstCQXL.isEmpty()) { ProcedureDepartment prodept = (ProcedureDepartment) lstCQXL.get(0); if (prodept != null && prodept.getProcessDeptId() != null && prodept.getProcessDeptName() != null) { newP.setReceiveGroup(prodept.getProcessDeptName()); newP.setReceiveGroupId(prodept.getProcessDeptId()); } } else { newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); } newP.setProcessStatus(file.getStatus()); // De xu ly newP.setStatus(0l); // Moi den chua xu ly newP.setIsActive(1l); } else {//neu la sdbs gui cho chuyen vien tham dinh ho so if (file.getStatus().equals(Constants.FILE_STATUS.RECEIVED_TO_ADD)) { newP.setReceiveDate(getSysdate()); //140407 ProcessDAOHE processDAOHE = new ProcessDAOHE(); Process userAction = processDAOHE.findProcessByActionEvaluate(file.getFileId()); if (userAction != null) { newP.setReceiveUser(userAction.getReceiveUser()); newP.setReceiveUserId(userAction.getReceiveUserId()); newP.setReceiveGroup(userAction.getReceiveGroup()); newP.setReceiveGroupId(userAction.getReceiveGroupId()); } else { newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); } // newP.setProcessStatus(file.getStatus()); // De xu ly newP.setStatus(0l); // Moi den chua xu ly newP.setIsActive(1l); getSession().save(newP); } if (file.getStatus().equals(Constants.FILE_STATUS.RECEIVED_REJECT)) { //tu choi tiep nhan newP.setReceiveDate(getSysdate()); ProcessDAOHE processDAOHE = new ProcessDAOHE();//140407 Process userAction = processDAOHE.getProcessByAction(file.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.NEW, Constants.FILE_STATUS.NEW_CREATE); if (userAction != null) { newP.setReceiveUser(userAction.getSendUser()); newP.setReceiveUserId(userAction.getSendUserId()); newP.setReceiveGroup(userAction.getSendGroup()); newP.setReceiveGroupId(userAction.getSendGroupId()); } else { newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); } newP.setProcessStatus(file.getStatus()); // De xu ly newP.setStatus(0l); // Moi den chua xu ly newP.setIsActive(1l); } // Tra lai cho doanh nghiep khong xu ly gi them } getSession().save(newP); getSession().update(file); MessageSmsDAOHE msdhe = new MessageSmsDAOHE(); String msg = "Ho so ma: " + file.getFileCode() + " cua doanh nghiep: " + file.getBusinessName() + " dang trong trang thai: da tiep nhan"; msdhe.saveMessageSMS(userId, file.getUserCreateId(), msg); //email MessageEmailDAOHE msedhe = new MessageEmailDAOHE(); String msge = "H s m: " + file.getFileCode() + " ca doanh nghip: " + file.getBusinessName() + " ang trong trng thi: ? tip nhn"; msedhe.saveMessageEmail(userId, file.getUserCreateId(), msge); //send group leader of dept 140915 binhnt53 EmailSmsDAO emdao = new EmailSmsDAO(); emdao.alertLeaderOfStaffAssignFiles(deptId, file.getFileCode(), file.getBusinessName()); bReturn = true; } } } catch (Exception ex) { bReturn = false; LogUtil.addLog(ex);//binhnt sonar a160901 } if (!bCheckCount) { return false; } return bReturn; } /** * 140815 tra ho so - vai tro van thu - binhnt53 * * @param form * @param deptId m n v * @param deptName tn n v * @param userId m tk ng nhp * @param userName tk ng nhp * @return */ public boolean onReturnFiles(FilesForm form, Long deptId, String deptName, Long userId, String userName) { boolean bReturn = true; List<Long> action = new ArrayList(); try { Files file = findById(form.getFileId()); Date dateNow = getSysdate(); if (file == null || file.getFileId() == null) { bReturn = false; } else { //140404 Long processStatus = file.getStatus(); file.setStatus(Constants.FILE_STATUS.GIVE_BACK); file.setDisplayStatus(getFileStatusName(Constants.FILE_STATUS.GIVE_BACK)); // file.setClericalRequest(form.getClericalRequest()); file.setClericalRequest("Vn th ng du s."); file.setModifyDate(dateNow); file.setStaffSigningId(userId); file.setStaffSigningName(userName); if (form.getSignDate() == null) { file.setSignDate(dateNow); } else { file.setSignDate(form.getSignDate()); } //Cap nhat process ProcessDAOHE pdhe = new ProcessDAOHE(); Process ptmp = pdhe.getProcessByAction(file.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, processStatus, Constants.FILE_STATUS.NEW_CREATE); if (ptmp != null) { ptmp.setStatus(Constants.FILE_STATUS.GIVE_BACK); ptmp.setLastestComment(form.getStaffRequest()); getSession().update(ptmp); } if (file.getStatus().equals(Constants.FILE_STATUS.GIVE_BACK)) { Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); // gui toi doanh nghiep nop ho so ProcessDAOHE processDAOHE = new ProcessDAOHE(); action.add(Constants.FILE_STATUS.NEW); Process userAction = processDAOHE.findProcessByAction(file.getFileId(), action); if (userAction != null) { newP.setReceiveUser(userAction.getSendUser()); newP.setReceiveUserId(userAction.getSendUserId()); newP.setReceiveGroup(userAction.getSendGroup()); newP.setReceiveGroupId(userAction.getSendGroupId()); } else { newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); } newP.setReceiveDate(dateNow); newP.setProcessStatus(Constants.FILE_STATUS.GIVE_BACK); // De xu ly newP.setStatus(0L); // ket thuc tra ho so cho doanh nghiep newP.setIsActive(1l); getSession().save(newP); } else { //do nothing } getSession().update(file); MessageSmsDAOHE msdhe = new MessageSmsDAOHE(); String msg = "Ho so ma: " + file.getFileCode() + " cua doanh nghiep: " + file.getBusinessName() + " dang trong trang thai: Da tra ban cong bo"; msdhe.saveMessageSMS(userId, file.getUserCreateId(), msg); //email MessageEmailDAOHE msedhe = new MessageEmailDAOHE(); String msge = "H s m: " + file.getFileCode() + " ca doanh nghip: " + file.getBusinessName() + " ang trong trng thi: ? tr bn cng b"; msedhe.saveMessageEmail(userId, file.getUserCreateId(), msge); // if ("true".equals(ResourceBundleUtil.getString("send_service", "config"))) { // Helper h = new Helper(); // h.sendMs_370(file.getFileId(), msge); // } getSession().update(file);//cap nhat ho so bReturn = true; } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } return bReturn; } /** * Cp s tip nhn/ xc nhn * * @param deptId * @param deptName * @param fileType * @return */ public String getNewReceiptNo(Long deptId, Long fileType) { //check file type ProcedureDAOHE procedurehe = new ProcedureDAOHE(); Procedure procedure = procedurehe.findById(fileType); //lay don vi DepartmentDAOHE departmentDaohe = new DepartmentDAOHE(); Department deptBo = departmentDaohe.findBOById(deptId); Long nCount = 1L; try {//lay so cong bo cua don vi if (deptBo != null && deptBo.getDeptCode() != null) { CountNoDAOHE cndaohe = new CountNoDAOHE(); CountNo cnbo = cndaohe.returnCountNoByCode(deptBo.getDeptCode()); if (cnbo != null && cnbo.getAnnouncementNo() > 0L) { nCount = cnbo.getAnnouncementNo(); cnbo.setAnnouncementNo(nCount + 1); getSession().update(cnbo); } } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 nCount = 1L; } String prefix; String fileTypeName; switch (procedure.getDescription()) { case "announcementFile01": fileTypeName = "TNCB"; break; case "announcementFile03": fileTypeName = "TNCB"; break; case "announcementFile05": fileTypeName = "BSCB"; break; case "announcement4star": fileTypeName = "SP"; break; case "confirmFuncImport": fileTypeName = "XNCB"; break; case "confirmFuncVN": fileTypeName = "XNCB"; break; case "confirmNormalVN": fileTypeName = "XNCB"; break; case "confirmNormalImport": fileTypeName = "XNCB"; break; default: fileTypeName = "XNCB"; } if (deptBo != null && deptBo.getDeptCode() != null) { if ("ATTP".equals(deptBo.getDeptCode())) { prefix = "ATTP-" + fileTypeName; } else { prefix = "YT" + deptBo.getDeptCode() + "-" + fileTypeName; } } else { prefix = "ATTP-" + fileTypeName; } Date currentDate = new Date(); try { currentDate = getSysdate(); } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } String fileCode = nCount + "/" + DateTimeUtils.convertDateToString(currentDate, "yyyy") + "/" + prefix; // String fileCode = nCount + " " + DateTimeUtils.convertDateToString(currentDate, "yyyy"); return fileCode; } /** * Cp s tip nhn * * @param deptId * @return */ public String getNewReceiveNo(Long deptId) { //check file type // ProcedureDAOHE procedurehe = new ProcedureDAOHE(); // Procedure procedure = procedurehe.findById(fileType); //lay don vi DepartmentDAOHE departmentDaohe = new DepartmentDAOHE(); Department deptBo = departmentDaohe.findBOById(deptId); Long nCount = 1L; try {//lay so cong bo cua don vi if (deptBo != null && deptBo.getDeptCode() != null) { CountNoDAOHE cndaohe = new CountNoDAOHE(); CountNo cnbo = cndaohe.returnCountNoByCode(deptBo.getDeptCode()); if (cnbo != null && cnbo.getAnnouncementNo() > 0L) { nCount = cnbo.getReceiveNo(); cnbo.setReceiveNo(nCount + 1); getSession().update(cnbo); } } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 nCount = 1L; } String fileCode = nCount.toString(); return fileCode; } /** * * @param deptId * @return */ public String getNewSendNo(Long deptId) { DepartmentDAOHE departmentDaohe = new DepartmentDAOHE(); Department deptBo = departmentDaohe.findBOById(deptId); Long nCount = 1L; try {//lay so cong bo cua don vi if (deptBo != null && deptBo.getDeptCode() != null) { CountNoDAOHE cndaohe = new CountNoDAOHE(); CountNo cnbo = cndaohe.returnCountNoByCode(deptBo.getDeptCode()); if (cnbo != null && cnbo.getSendNo() > 0L) { nCount = cnbo.getSendNo(); //cnbo.setSendNo(nCount + 1); //getSession().update(cnbo); } } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 nCount = 1L; } return nCount.toString(); } /** * Kim tra tn ti giy tip nhn xc nhn * * @param reIssueForm * @return */ public Announcement checkAnnouncementFilesExist(ReIssueForm reIssueForm) { if (reIssueForm == null) { return null; } if (reIssueForm.getFormNumber() != null && reIssueForm.getFormNumber().trim().length() > 0) { String hql = " from Announcement a where a.isActive = 1 "; List lstParam = new ArrayList(); hql += " and lower(a.announcementNo) = ? "; lstParam.add(reIssueForm.getFormNumber()); Query countQuery = getSession().createQuery("select count(*) " + hql); Query query = getSession().createQuery("select a " + hql + " order by a.announcementId desc"); for (int i = 0; i < lstParam.size(); i++) { query.setParameter(i, lstParam.get(i)); countQuery.setParameter(i, lstParam.get(i)); } List<Announcement> lstResult = query.list(); if (!lstResult.isEmpty()) { return lstResult.get(0); } else { return null; } } return null; } /** * #260214 binhnt53 lay thong tin trang thai * * @param statusCode * @return */ public Category getStatus(String statusCode) { Category bo = new Category(); return bo; } /** * Cp s tip nhn/ xc nhn cho Doanh nghip * * @param userId * @param userName * @param fileType * @return */ public String getReceiptNoNew(Long userId, String userName, Long fileType) { ProcedureDAOHE procedurehe = new ProcedureDAOHE(); Procedure procedure = procedurehe.findById(fileType); String hql = "select count(f) from Files f where userCreateId=? and (f.isTemp = null or f.isTemp = 0) and isActive=1"; Query query = getSession().createQuery(hql); query.setParameter(0, userId); int nCount = (int) (long) (Long) query.uniqueResult(); nCount += 1; String prefix = ""; if (userName != null && userName.trim().length() > 0) { if (procedure.getDescription().equals(Constants.FILE_DESCRIPTION.ANNOUNCEMENT_FILE01) || procedure.getDescription().equals(Constants.FILE_DESCRIPTION.ANNOUNCEMENT_FILE03) || procedure.getDescription().equals(Constants.FILE_DESCRIPTION.RE_ANNOUNCEMENT)) { prefix = userName + "-CBHQ"; } else { prefix = userName + "-CBPH"; } } Date currentDate = new Date(); try { currentDate = getSysdate(); } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } String fileCode = nCount + "/" + DateTimeUtils.convertDateToString(currentDate, "yyyy") + "/" + prefix; return fileCode; } /** * tr v? form h s * * @param entity * @return */ public FilesForm returnFilesForm(Files entity) { FilesForm form = null; if (entity != null) { form = new FilesForm(entity); if (entity.getAnnouncementId() != null) { Announcement ann = (Announcement) findById(Announcement.class, "announcementId", entity.getAnnouncementId()); form.setAnnouncement(new AnnouncementForm(ann)); form.setAnnouncementReceiptPaperForm(new AnnouncementReceiptPaperForm()); } if (entity.getReIssueFormId() != null) { ReIssueForm re = (ReIssueForm) findById(ReIssueForm.class, "reIssueFormId", entity.getReIssueFormId()); form.setReIssueForm(new ReIssueFormForm(re)); } if (entity.getDetailProductId() != null) { DetailProduct ann = (DetailProduct) findById(DetailProduct.class, "detailProductId", entity.getDetailProductId()); form.setDetailProduct(new DetailProductForm(ann)); } if (entity.getTestRegistrationId() != null) { TestRegistration ann = (TestRegistration) findById(TestRegistration.class, "testRegistrationId", entity.getTestRegistrationId()); form.setTestRegistration(new TestRegistrationForm(ann)); form.setConfirmImportSatistPaperForm(new ConfirmImportSatistPaperForm()); } try { if (entity.getAnnouncementReceiptPaperId() != null) { AnnouncementReceiptPaper annp = (AnnouncementReceiptPaper) findById( AnnouncementReceiptPaper.class, "announcementReceiptPaperId", entity.getAnnouncementReceiptPaperId()); form.setAnnouncementReceiptPaperForm(new AnnouncementReceiptPaperForm(annp)); } if (entity.getConfirmImportSatistPaperId() != null) { ConfirmImportSatistPaper arp = (ConfirmImportSatistPaper) findById( AnnouncementReceiptPaper.class, "confirmImportSatistPaperId", entity.getAnnouncementReceiptPaperId()); form.setConfirmImportSatistPaperForm(new ConfirmImportSatistPaperForm(arp)); } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } } return form; } //140404 /** * Nhp kt qu thm nh SDBS * * @param form * @param deptId * @param deptName * @param userId * @param userName * @return */ public boolean onFeedbackEvaluate(FilesForm form, Long deptId, String deptName, Long userId, String userName) { boolean bReturn = true; try { Files file = findById(form.getFileId());//lay thong tin chi tiet ho so Date dateNow = getSysdate(); if (file == null) { bReturn = false; } else { // Cap nhat trang thai ho so file.setStatus(form.getStatus()); file.setDisplayStatus(getFileStatusName(form.getStatus())); // String dateTime = DateTimeUtils.convertDateToString(dateNow, "dd/MM/yyyy HH:mm"); // file.setStaffRequest(userName + " " + dateTime + ":\n" + form.getStaffRequest()); file.setStaffRequest(form.getStaffRequest()); file.setDisplayRequest(form.getStaffRequest()); file.setModifyDate(dateNow); file.setEffectiveDate(form.getEffectiveDate()); // Cap nhat process ProcessDAOHE pdhe = new ProcessDAOHE(); Process p = pdhe.getWorkingProcess(form.getFileId(), Constants.OBJECT_TYPE.FILES, deptId, userId); if (p != null) { p.setStatus(form.getStatus()); p.setLastestComment(form.getStaffRequest()); getSession().update(p); } // Neu co luong thi chay theo luong if (file.getFlowId() != null && file.getFlowId() > 0) { FlowDAOHE fdhe = new FlowDAOHE(); if (Constants.FILE_STATUS.EVALUATED.equals(form.getStatus())) { fdhe.moveDocumentToNextNodeByAction(deptId, deptName, userId, userName, file.getFileId(), "thm nh"); } else { //fdhe.moveDocumentToPreviousNode(deptId, deptName, userId, userName, file.getFileId(), file.getPreviousNodeId()); } } else // Neu khong co luong thi tu xu thoi :-) if (form.getStatus().equals(Constants.FILE_STATUS.EVALUATED)) { // Tham dinh oke, gui tiep cho cho lanh dao don vi review Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); // Gui toi chinh don vi quan ly de xem xet newP.setReceiveDate(dateNow); newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); newP.setProcessStatus(form.getStatus()); // De xu ly newP.setStatus(0l); // Moi den chua xu ly newP.setIsActive(1l); getSession().save(newP); } else { // Tra lai cho doanh nghiep khong xu ly gi them } //insert noi dung tham dinh if (form.getEvaluationRecordsForm() != null) { EvaluationRecordsForm evaluationRecordsForm = new EvaluationRecordsForm(); evaluationRecordsForm.setCreateDate(dateNow); evaluationRecordsForm.setSendDate(file.getSendDate()); evaluationRecordsForm.setBusinessName(file.getBusinessName()); evaluationRecordsForm.setBusinessAddress(file.getBusinessAddress()); evaluationRecordsForm.setProductName(file.getProductName()); evaluationRecordsForm.setLegal(form.getEvaluationRecordsForm().getLegal()); evaluationRecordsForm.setLegalContent(form.getEvaluationRecordsForm().getLegalContent()); evaluationRecordsForm .setFoodSafetyQuality(form.getEvaluationRecordsForm().getFoodSafetyQuality()); evaluationRecordsForm.setFoodSafetyQualityContent( form.getEvaluationRecordsForm().getFoodSafetyQualityContent()); evaluationRecordsForm.setEffectUtility(form.getEvaluationRecordsForm().getEffectUtility()); evaluationRecordsForm .setEffectUtilityContent(form.getEvaluationRecordsForm().getEffectUtilityContent()); evaluationRecordsForm.setFilesStatus(form.getEvaluationRecordsForm().getFilesStatus()); // evaluationRecordsForm.setFilesStatusL(form.getEvaluationRecordsForm().getFilesStatusL()); evaluationRecordsForm.setMainContent(form.getEvaluationRecordsForm().getMainContent()); // evaluationRecordsForm.setMainContentL(form.getEvaluationRecordsForm().getMainContentL()); evaluationRecordsForm.setFirstStaffId(userId); evaluationRecordsForm.setFirstStaffName(userName); evaluationRecordsForm.setSecondStaffId(userId); evaluationRecordsForm.setSecondStaffName(userName); evaluationRecordsForm.setThirdStaffId(userId); evaluationRecordsForm.setThirdStaffName(userName); evaluationRecordsForm.setLeederStaffId(userId); evaluationRecordsForm.setLeederStaffName(userName); evaluationRecordsForm.setFilesId(file.getFileId()); EvaluationRecords evaluationRecordsBo; evaluationRecordsBo = evaluationRecordsForm.convertToEntity(); getSession().save(evaluationRecordsBo); } update(file); } } catch (Exception ex) { bReturn = false; LogUtil.addLog(ex);//binhnt sonar a160901 } return bReturn; } /** * Haitv21 Update repository of file via fileID * * @param fileId * @param repId * @return * @throws Exception */ public boolean updateRepository(Long fileId, Long repId) throws Exception { boolean result = false; Files file = findById(fileId); file.setRepositoriesId(repId); file.setRepDate(getSysdate()); getSession().update(file); return result; } /** * ly h s c tip nhn cng b * * @param id * @return */ public Files getFilesByAnnrpId(Long id) { List<Files> lstItem; Files item = null; try { if (id != null && id > 0) { StringBuilder stringBuilder = new StringBuilder(" from Files a "); stringBuilder.append(" where a.announcementReceiptPaperId=? "); Query query = getSession().createQuery(stringBuilder.toString()); query.setParameter(0, id); lstItem = query.list(); if (lstItem != null && lstItem.size() > 0) { item = lstItem.get(0); } } } catch (HibernateException ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } return item; } /** * 140616 - binhnt53 lay thong tin toan bo file ho so trong ho so ca nhan * * @param input * @param userId * @return */ public List getAttachsOfUserAttach(String input, Long userId) { String lstAttach[] = input.split(";"); String hql = "select u from UserAttachs u where "; hql += " u.createdBy =? "; hql += " and u.attachName in (:lstAttach) "; Query query = getSession().createQuery(hql); query.setParameter(0, userId); query.setParameterList("lstAttach", lstAttach); List lst = query.list(); return lst; } /** * function tra ve thong tin ket qua xu ly hop quy phu hop -- hieptq 040614 * * @param fileId * @return * @throws JAXBException */ public String prepareAnnouceHandling(Long fileId) throws JAXBException { StringBuilder stringBuilder = new StringBuilder(" from Files f "); stringBuilder.append(" where f.fileId=? "); Query query = getSession().createQuery(stringBuilder.toString()); query.setParameter(0, fileId); List<Files> lstItem = query.list(); Files item = null; if (lstItem != null && lstItem.size() > 0) { item = lstItem.get(0); } ANNOUCE_HANDLING ann = new ANNOUCE_HANDLING(); if (item.getStatus() == 2 || item.getStatus() == 3 || item.getStatus() == 4 || item.getStatus() == 5 || item.getStatus() == 8 || item.getStatus() == 9 || item.getStatus() == 10 || item.getStatus() == 11 || item.getStatus() == 12 || item.getStatus() == 13 || item.getStatus() == 15 || item.getStatus() == 16 || item.getStatus() == 19) { ann.setSTATUS(2l); } else if (item.getStatus() == 17) { ann.setSTATUS(14l); } else if (item.getStatus() == 18) { ann.setSTATUS(1l); } else if (item.getStatus() == 19) { ann.setSTATUS(2l); } else if (item.getStatus() == 20) { ann.setSTATUS(7l); } else { ann.setSTATUS(item.getStatus()); } ann.setSTATUS(item.getStatus()); ann.setCONFIRM_ANNOUNCE_NUMBER("1"); ann.setEFFECT_DATE(item.getSendDate()); ann.setFILE_ATTP_CODE(item.getFileCode()); ann.setFILE_CODE("3"); ann.setPROCESS_DATE(item.getApproveDate()); ann.setPROCESS_ID(3l); String result; java.io.StringWriter sw = new StringWriter(); JAXBContext jaxbContext = JAXBContext.newInstance(ANNOUCE_HANDLING.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(ann, sw); result = sw.toString(); return result; } /** * ly ngy lm vic * * @param numberDate * @return */ public Date getDateWorkingTime(int numberDate) { Date startDate = null; try { startDate = getSysdate(); } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } int balanceDay = numberDate % 5; int numberOfWeek = numberDate / 5; int numberDateWorking = numberOfWeek * 7; Calendar endCalendar = DateTimeUtils.DateToCalendar(startDate); //lay ra ngay lam viec nop ho so while (checkIsDayOff(DateTimeUtils.CalendarToDate(endCalendar)) == true || DateTimeUtils.checkIsWeekend(endCalendar) == true) { endCalendar.add(Calendar.DATE, 1); } //them ngay lam viec da tinh t7 cn endCalendar.add(Calendar.DATE, numberDateWorking); if (balanceDay > 0) {//neu co so du + phan du vao ngay endCalendar.add(Calendar.DATE, balanceDay); } endCalendar = DateTimeUtils.checkWeekend(endCalendar); Date endDate = DateTimeUtils.CalendarToDate(endCalendar); endCalendar.add(Calendar.DATE, findDateWorkOff(startDate, endDate)); endCalendar.add(Calendar.DATE, -findDateWork(startDate, endDate)); while (checkIsDayOff(endDate) == true || DateTimeUtils.checkIsWeekend(endCalendar) == true) { endCalendar.add(Calendar.DATE, 1); endDate = DateTimeUtils.CalendarToDate(endCalendar); } return DateTimeUtils.CalendarToDate(endCalendar); } /** * tm ngy ngh l * * @param start * @param end * @return */ public int findDateWorkOff(Date start, Date end) { String hql = " from TimeProcess t where t.isActive = 1 and t.isDayOff = 0 "; List lstParam = new ArrayList(); if (start != null) { hql += " and t.timeProcessDate > ?"; lstParam.add(start); } if (end != null) { hql += " and t.timeProcessDate <= ?"; lstParam.add(end); } Query countQuery = getSession().createQuery("select count(t.timeProcessId) " + hql); for (int i = 0; i < lstParam.size(); i++) { countQuery.setParameter(i, lstParam.get(i)); } int total = Integer.parseInt(countQuery.uniqueResult().toString()); return total; } /** * tm ngy lm vic b * * @param start * @param end * @return */ public int findDateWork(Date start, Date end) { String hql = " from TimeProcess t where t.isActive = 1 and t.isDayOff = 1 "; List lstParam = new ArrayList(); if (start != null) { hql += " and t.timeProcessDate > ?"; lstParam.add(start); } if (end != null) { hql += " and t.timeProcessDate <= ?"; lstParam.add(end); } Query countQuery = getSession().createQuery("select count(t.timeProcessId) " + hql); for (int i = 0; i < lstParam.size(); i++) { countQuery.setParameter(i, lstParam.get(i)); } int total = Integer.parseInt(countQuery.uniqueResult().toString()); return total; } /** * l ngy ngh * * @param dayCheck * @return */ public boolean checkIsDayOff(Date dayCheck) { String hql = " from TimeProcess t where t.isActive = 1 and t.isDayOff = 0"; List lstParam = new ArrayList(); if (dayCheck != null) { hql += " and t.timeProcessDate = ?"; lstParam.add(dayCheck); } Query countQuery = getSession().createQuery("select count(t.timeProcessId) " + hql); for (int i = 0; i < lstParam.size(); i++) { countQuery.setParameter(i, lstParam.get(i)); } int total = Integer.parseInt(countQuery.uniqueResult().toString()); if (total > 0) { return true; } else { return false; } } //140725 /** * dem phien ban * * @param objId * @return */ public Long getCountVersion(Long objId) { Long iresult; List lstParam = new ArrayList(); String hql = "select count(t) from Files t where t.originalId = ? "; lstParam.add(objId); Query query = getSession().createQuery(hql); for (int i = 0; i < lstParam.size(); i++) { query.setParameter(i, lstParam.get(i)); } iresult = Long.parseLong(query.uniqueResult().toString()) + 1L; return iresult; } /** * cap nhat khong phai la phien ban cuoi * * @param objId * @return */ public int updateSetNotLastIsTemp(Long objId) { try { String hql = " update Files t set t.lastIsTemp = 0 where t.originalId = ?"; Query query = getSession().createQuery(hql); query.setParameter(0, objId); return query.executeUpdate(); } catch (HibernateException ex) { LogUtil.addLog(ex);//binhnt sonar a160901 return 0; } }//!140725 /** * tim phien ban theo sua doi bo sung * * @param objId * @param originalId * @param version * @param isLastVersion * @return */ public Files findIsItempObj(Long objId, Long originalId, Long version, boolean isLastVersion) {//140726 Files bo = new Files(); try { List lstParam = new ArrayList(); String hql = "select t from Files t where 1=1"; if (objId != null && objId > 0L) { hql += " and t.fileId = ?"; lstParam.add(objId); } if (originalId != null && originalId > 0L) { hql += " and t.originalId = ?"; lstParam.add(originalId); } if (version != null && version > 0L) { hql += " and t.version = ?"; lstParam.add(version); } if (isLastVersion) { hql += " and t.lastIsTemp = ?"; lstParam.add(1L); } Query query = getSession().createQuery(hql); for (int i = 0; i < lstParam.size(); i++) { query.setParameter(i, lstParam.get(i)); } List<Files> lstObj; lstObj = query.list(); if (!lstObj.isEmpty()) { bo = lstObj.get(0); } } catch (HibernateException ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } return bo; } /** * * @param fileId * @return */ public Files getLastVersionOfFile(Long fileId) { String hql = "select f from Files f where f.originalId = ? order by f.version desc"; Query query = session.createQuery(hql); query.setParameter(0, fileId); List<Files> lstFiles = query.list(); if (lstFiles != null && !lstFiles.isEmpty()) { return lstFiles.get(0); } else { return null; } } /** * * @param fileId * @return */ public Long getLastVersionIdOfFile(Long fileId) { Files f = getLastVersionOfFile(fileId); if (f != null) { return f.getFileId(); } else { return null; } } /** * lay danh sach ho so phien ban truoc * * @param filesId * @return */ public List getLstOldVersionFiles(Long filesId) {//n140729 - get lst cac phien ban cua ho so List<Files> lstFiles; List<FilesForm> lstFilesForm; try { StringBuilder stringBuilder = new StringBuilder(" from Files a "); stringBuilder.append(" where a.originalId = ?" + " order by a.version DESC"); Query query = getSession().createQuery(stringBuilder.toString()); query.setParameter(0, filesId); lstFiles = query.list(); lstFilesForm = new ArrayList(); for (int i = 0; i < lstFiles.size(); i++) { lstFilesForm.add(new FilesForm(lstFiles.get(i))); } } catch (HibernateException ex) { LogUtil.addLog(ex);//binhnt sonar a160901 return null; } return lstFilesForm; } /** * luu ho so * * @param vo * @throws Exception */ public void saveDb(Files vo) throws Exception { getSession().update(vo); getSession().getTransaction().commit(); } /** * luu ho so * * @param vo * @throws Exception */ public void saveDbNoCommit(Files vo) throws Exception { getSession().update(vo); } /** * get loai ho so by Id ho so * * @param fileId * @return */ public Long getFileTypeByFileId(Long fileId) { // 11/11/2014 viethd //String a = " select f.fileType from Files f where f.fileId=" + fileId; String a = " select f.fileType from Files f where f.fileId=:fileId"; Query query = getSession().createQuery(a); query.setParameter("fileId", fileId); List<Long> result = query.list(); if (result != null && result.size() > 0) { return result.get(0); } return null; } /** * phe duyet tham dinh * * @param form * @param deptId * @param deptName * @param userId * @param userName * @return */ public boolean onApproveEvaluate(FilesForm form, Long deptId, String deptName, Long userId, String userName) { boolean bReturn = true; try { Files file = findById(form.getFileId()); Date dateNow = getSysdate(); if (file == null) { bReturn = false; } else { file.setStatus(form.getStatus()); file.setDisplayStatus(getFileStatusName(form.getStatus())); String dateTime = DateTimeUtils.convertDateToString(dateNow, "dd/MM/yyyy HH:mm"); file.setLeaderRequest(userName + " " + dateTime + ":\n" + form.getLeaderRequest()); file.setDisplayRequest(form.getLeaderRequest()); file.setModifyDate(dateNow); file.setLeaderStaffSignId(userId); file.setLeaderStaffSignName(userName); // // Cap nhat process // ProcessDAOHE pdhe = new ProcessDAOHE(); Process p = pdhe.getWorkingProcess(form.getFileId(), Constants.OBJECT_TYPE.FILES, deptId, userId); if (p != null) { p.setStatus(form.getStatus()); p.setLastestComment(form.getLeaderRequest()); getSession().update(p); } // Neu khong co luong thi tu xu thoi :-) if (form.getStatus().equals(Constants.FILE_STATUS.APPROVED)) { // Phe duyet oke, chuyen ho so xuong cho chuyen vien de thong bao doi chieu ho so Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setProcessStatus(form.getStatus()); // De xu ly newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setStatus(0l); // Moi den chua xu ly newP.setIsActive(1l); //lay process tham dinh ho so Process pold = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.ASSIGNED, Constants.FILE_STATUS.EVALUATED); if (pold != null) { newP.setReceiveDate(dateNow); newP.setReceiveGroup(pold.getSendGroup()); newP.setReceiveGroupId(pold.getSendGroupId()); newP.setReceiveUser(pold.getReceiveUser()); newP.setReceiveUserId(pold.getReceiveUserId()); } getSession().save(newP); //cap nhat noi dung thong bao - tao noi dung thong bao RequestComment rcbo = new RequestComment(); rcbo.setContent(form.getLeaderRequest()); file.setComparisonContent(form.getLeaderRequest()); file.setIsFee(0L);//bay gio tinh phi giay cong bo rcbo.setCreateBy(userId); rcbo.setCreateDate(dateNow); rcbo.setUserId(userId); rcbo.setUserName(userName); rcbo.setStatus(1L); rcbo.setIsActive(1L); rcbo.setGroupId(deptId); rcbo.setGroupName(deptName); rcbo.setIsLastChange(Constants.ACTIVE_STATUS.ACTIVE); rcbo.setObjectId(form.getFileId()); rcbo.setRequestType(Constants.REQUEST_COMMENT_TYPE.TBDC); //-150120 RequestCommentDAOHE rqdaohe = new RequestCommentDAOHE(); RequestComment lastRQBo = rqdaohe.findLastRequestComment(file.getFileId(), Constants.ACTIVE_STATUS.ACTIVE); if (lastRQBo != null) { rcbo.setLastContent(lastRQBo.getContent()); lastRQBo.setIsLastChange(Constants.ACTIVE_STATUS.DEACTIVE); getSession().update(lastRQBo); } //update binhnt // try { // if ("true".equals(ResourceBundleUtil.getString("send_service", "config"))) { // Helper h = new Helper(); // h.sendMs_340(file.getFileId(), "Ho so ma: " + file.getFileCode() + " Da duoc phe duyet yeu cau nop phi ho so."); // } // } catch (UnsupportedEncodingException ex) { // Logger.getLogger(FilesDAOHE.class.getName()).log(Level.SEVERE, null, ex); // } getSession().save(rcbo); //!cap nhat noi dung thong bao - tao noi dung thong bao //-150120 } else { if (form.getStatus().equals(Constants.FILE_STATUS.FEDBACK_TO_REVIEW)) { // Tra lai cho lanh dao don vi xem xet lai Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setProcessStatus(form.getStatus()); // De xu ly newP.setStatus(0l); // Moi den chua xu ly newP.setIsActive(1l); // Gui toi chinh don vi quan ly de xem xet if (p != null) { // Gui lai cho chinh nguoi gui newP.setReceiveDate(dateNow); newP.setReceiveGroup(p.getSendGroup()); newP.setReceiveGroupId(p.getSendGroupId()); newP.setReceiveUser(p.getSendUser()); newP.setReceiveUserId(p.getSendUserId()); } getSession().save(newP); } if (form.getStatus().equals(Constants.FILE_STATUS.EVALUATED_TO_ADD)) { // try { // if ("true".equals(ResourceBundleUtil.getString("send_service", "config"))) { // Helper h = new Helper(); // h.sendMs_330(file.getFileId(), "Da gui cong van yeu cau sdbs"); // } // } catch (UnsupportedEncodingException ex) { // Logger.getLogger(FilesDAOHE.class.getName()).log(Level.SEVERE, null, ex); // } // gui tra ho so cho doanh nghiep sua doi bo sung Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); // newP.setReceiveDate(dateNow); newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); newP.setProcessStatus(form.getStatus()); //De xu ly newP.setStatus(0l); //Moi den chua xu ly newP.setIsActive(1l); getSession().save(newP); //xa bn ghi temp trc nu c (lu vo vng lu tr) updateSetNotLastIsTemp(file.getFileId()); try { ResourceBundle rb = ResourceBundle.getBundle("config"); Procedure procedurebo; ProcedureDAOHE procedureDAOHE = new ProcedureDAOHE(); procedurebo = procedureDAOHE.findById(file.getFileType()); int SD = 0; try { SD = Integer.parseInt(rb.getString(procedurebo.getDescription() + "_SD")); } catch (NumberFormatException ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } if (SD > 0) { file.setDeadlineAddition(getDateWorkingTime(SD)); } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } //y kien lanh chuyen thanh y kien cua lanh dao } } if (form.getStatus().equals(Constants.FILE_STATUS.APPROVED)) { // try { // if ("true".equals(ResourceBundleUtil.getString("send_service", "config"))) { // Helper h = new Helper(); // h.sendMs_340(file.getFileId(), "Ho so ma: " + file.getFileCode() + " Da duoc phe duyet yeu cau nop phi ho so."); // } // } catch (UnsupportedEncodingException ex) { // Logger.getLogger(FilesDAOHE.class.getName()).log(Level.SEVERE, null, ex); // } //===============================tao giay cong bo=============== file.setApproveDate(dateNow); ProcedureDAOHE pcdaohe = new ProcedureDAOHE(); Procedure procedure = pcdaohe.findById(file.getFileType()); if (procedure != null && procedure.getProcedureId() > 0) { if (!"12".equals(procedure.getCode())) {//tao giay tiep nhan cong bo if (file.getAnnouncementId() != null) {//Cp giy tip nhn bn cng b hp quy (bn th nht) AnnouncementReceiptPaperForm arpForm = new AnnouncementReceiptPaperForm(); AnnouncementDAOHE announcementHE = new AnnouncementDAOHE(); Announcement announcement = announcementHE.findById(file.getAnnouncementId()); arpForm.setBusinessName(announcement.getBusinessName()); arpForm.setProductName(announcement.getProductName()); arpForm.setManufactureName(announcement.getManufactureName()); arpForm.setEmail(announcement.getBusinessEmail()); arpForm.setFax(announcement.getBusinessFax()); arpForm.setTelephone(announcement.getBusinessTelephone()); arpForm.setNationName(announcement.getNationName()); String strReceiptNo = getNewReceiptNo(file.getAgencyId(), file.getFileType()); arpForm.setReceiptNo(strReceiptNo); if (file.getEffectiveDate() == 3) {//lay ngay ki + 3 nam arpForm.setEffectiveDate(DateUtils.addYears(dateNow, 3)); } else if (file.getEffectiveDate() == 5) {//lay ngay ki + 5 nam arpForm.setEffectiveDate(DateUtils.addYears(dateNow, 5)); } arpForm.setReceiptDate(dateNow); arpForm.setReceiptDeptName(deptName);//ten co quan tiep nhan cong bo arpForm.setMatchingTarget(announcement.getMatchingTarget());//so hieu qui chuan ki thuat arpForm.setSignDate(dateNow);//ngay ki arpForm.setSignerName(userName);//nguoi ki //tao giay tiep nhan try { AnnouncementReceiptPaperDAOHE cthe = new AnnouncementReceiptPaperDAOHE(); if (cthe.isDuplicate(arpForm) == true) { bReturn = false; } else { Long ObjId = arpForm.getAnnouncementReceiptPaperId(); AnnouncementReceiptPaper bo = arpForm.convertToEntity(); if (ObjId == null) { getSession().save(bo); file.setAnnouncementReceiptPaperId(bo.getAnnouncementReceiptPaperId()); //getSession().update(file); } else { getSession().update(bo); file.setAnnouncementReceiptPaperId(bo.getAnnouncementReceiptPaperId()); //getSession().update(file); } } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } } //!tao giay tiep nhan } else if (file.getTestRegistrationId() != null) {//Giy xc nhn t yu cu nhp khu ca c quan kim tra Nh nc v? cht lng thc phm nhp khu ConfirmImportSatistPaperForm cispForm = new ConfirmImportSatistPaperForm(); cispForm.setTestAgencyName(form.getTestRegistration().getTestAgency()); cispForm.setTestAdd(form.getTestRegistration().getTestAdd()); cispForm.setExportBusinessName(form.getTestRegistration().getExportBusinessName()); cispForm.setExportBusinessAdd(form.getTestRegistration().getExportBusinessAdd()); cispForm.setExportBusinessMail(form.getTestRegistration().getExportBusinessMail()); cispForm.setExportBusinessTel(form.getTestRegistration().getExportBusinessTel()); cispForm.setExportBusinessFax(form.getTestRegistration().getExportBusinessFax()); cispForm.setExportContractCode(form.getTestRegistration().getExportContractCode()); cispForm.setExportContractDate(form.getTestRegistration().getExportContractDate()); cispForm.setExportLadingCode(form.getTestRegistration().getExportLadingCode()); cispForm.setExportLadingDate(form.getTestRegistration().getExportLadingDate()); cispForm.setExportPort(form.getTestRegistration().getExportPort()); cispForm.setImportBusinessName(form.getTestRegistration().getImportBusinessName()); cispForm.setImportBusinessAddress( form.getTestRegistration().getImportBusinessAddress()); cispForm.setImportBusinessEmail(form.getTestRegistration().getImportBusinessEmail()); cispForm.setImportBusinessTel(form.getTestRegistration().getImportBusinessTel()); cispForm.setImportBusinessFax(form.getTestRegistration().getImportBusinessFax()); cispForm.setImportPort(form.getTestRegistration().getImportPort()); cispForm.setImportDate(form.getTestRegistration().getImportDate()); cispForm.setProductName(form.getTestRegistration().getProductName()); cispForm.setProductDescription(form.getTestRegistration().getProductDescription()); cispForm.setProductCode(form.getTestRegistration().getProductCode()); cispForm.setProductOrigin(form.getTestRegistration().getProductOrigin()); cispForm.setProductAmount(form.getTestRegistration().getProductAmount()); cispForm.setProductWeight(form.getTestRegistration().getProductWeight()); cispForm.setProductValue(form.getTestRegistration().getProductValue()); cispForm.setGatheringAdd(form.getTestRegistration().getGatheringAdd()); cispForm.setTestDate(form.getTestRegistration().getTestDate()); cispForm.setBusinessRepresent(form.getTestRegistration().getBusinessRepresent()); cispForm.setBusinessSignAdd(form.getTestRegistration().getBusinessSignAdd()); cispForm.setBusinessSigndate(form.getTestRegistration().getBusinessSigndate()); cispForm.setAgencyRepresent(form.getTestRegistration().getAgencyRepresent()); cispForm.setAgencySignAdd(form.getTestRegistration().getAgencySignAdd()); cispForm.setAgencySigndate(form.getTestRegistration().getAgencySigndate()); cispForm.setStandardTargetNo(form.getTestRegistration().getStandardTargetNo()); cispForm.setStandardTargetDate(form.getTestRegistration().getStandardTargetDate()); cispForm.setReleaseDocumentNo(form.getTestRegistration().getReleaseDocumentNo()); cispForm.setReleaseDocumentDate(form.getTestRegistration().getReleaseDocumentDate()); try { ConfirmImportSatistPaperDAOHE cthe = new ConfirmImportSatistPaperDAOHE(); if (cthe.isDuplicate(cispForm) == true) { bReturn = false; } else { Long ObjId = cispForm.getConfirmImportSatistPaperId(); if (ObjId == null) { ConfirmImportSatistPaper bo = cispForm.convertToEntity(); getSession().save(bo); file.setConfirmImportSatistPaperId(bo.getConfirmImportSatistPaperId()); //getSession().update(file); } else { ConfirmImportSatistPaper bo = cispForm.convertToEntity(); getSession().update(bo); file.setConfirmImportSatistPaperId(bo.getConfirmImportSatistPaperId()); //getSession().update(file); } } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } } } //=======================================end==================== //sms MessageSmsDAOHE msdhe = new MessageSmsDAOHE(); String msg = "Ho so ma: " + file.getFileCode() + " cua doanh nghiep: " + file.getBusinessName() + " dang trong trang thai: da phe duyet"; msdhe.saveMessageSMS(userId, file.getUserCreateId(), msg); //email MessageEmailDAOHE msedhe = new MessageEmailDAOHE(); String msge = "H s m: " + file.getFileCode() + " ca doanh nghip: " + file.getBusinessName() + " ang trong trng thi: ph duyt."; msedhe.saveMessageEmail(userId, file.getUserCreateId(), msge); } update(file); } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } return bReturn; } /** * xem xt thm nh h s. * * @param form * @param deptId * @param deptName * @param userId * @param userName * @return */ public boolean onReviewEvaluate(FilesForm form, Long deptId, String deptName, Long userId, String userName) { boolean bReturn = true; try { Files file = findById(form.getFileId()); Date dateNow = getSysdate(); if (file == null) { bReturn = false; } else { Long processStatus = file.getStatus();//trang thai ho so truoc khi thay doi Long status = form.getStatus(); if (processStatus != null//141225 BINHNT update phan quyen ho so tham dinh && (processStatus.equals(Constants.FILE_STATUS.EVALUATED)//DA THAM DINH DAT || processStatus.equals(Constants.FILE_STATUS.FEDBACK_TO_REVIEW)//TRA LAI XEM XET LAI || processStatus.equals(Constants.FILE_STATUS.EVALUATE_TO_ADD)//TRA LAI XEM XET LAI || processStatus.equals(Constants.FILE_STATUS.FEDBACK_TO_ADD))) {//DA THAM DINH YEU CA SDBS // Cap nhat trang thai ho so file.setStatus(status); file.setDisplayStatus(getFileStatusName(status)); String dateTime = DateTimeUtils.convertDateToString(dateNow, "dd/MM/yyyy HH:mm"); if (!status.equals(Constants.FILE_STATUS.REVIEW_TO_ADD)) { file.setLeaderStaffRequest( userName + " " + dateTime + ":\n" + form.getLeaderStaffRequest()); file.setDisplayRequest(form.getLeaderStaffRequest()); } else { file.setLeaderStaffRequest("Trng phng xem xt cng vn S?BS"); file.setDisplayRequest("Trng phng xem xt cng vn S?BS"); } file.setModifyDate(dateNow); file.setEvaluateAddDate(dateNow); file.setLeaderApproveName(form.getLeaderApproveName()); file.setLeaderApproveId(form.getLeaderApproveId()); // Cap nhat process ProcessDAOHE pdhe = new ProcessDAOHE(); Process p = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, processStatus, Constants.FILE_STATUS.NEW_CREATE); Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setProcessStatus(status); // De xu ly newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setStatus(Constants.FILE_STATUS.NEW_CREATE); // Moi den chua xu ly newP.setIsActive(Constants.ACTIVE_STATUS.ACTIVE); newP.setReceiveDate(dateNow); if (status.equals(Constants.FILE_STATUS.REVIEWED)) { // Phe duyet oke, chuyen ho so cho lanh dao phe duyet newP.setReceiveUser(form.getLeaderApproveName()); newP.setReceiveUserId(form.getLeaderApproveId()); newP.setReceiveGroup(file.getAgencyName()); newP.setReceiveGroupId(file.getAgencyId()); } else { if (status.equals(Constants.FILE_STATUS.EVALUATED_TO_ADD)) { //140722 - da thong bao yeu cau sdbs ProcessDAOHE psdhe = new ProcessDAOHE(); Process pold = psdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.NEW, Constants.FILE_STATUS.RECEIVED); if (pold != null) { newP.setReceiveGroupId(pold.getSendGroupId()); newP.setReceiveGroup(pold.getSendGroup()); newP.setReceiveUserId(pold.getSendUserId()); newP.setReceiveUser(pold.getSendUser()); } else { newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); } //xa b?n ghi temp tr?c n?u c (lu vo vng lu tr?) updateSetNotLastIsTemp(file.getFileId());// ProcessCommentDAOHE pcdaohe = new ProcessCommentDAOHE(); pcdaohe.updateSetNotLastIsTemp(file.getFileId()); try {//140627 THIET LAP HAN SDBS HO SO ResourceBundle rb = ResourceBundle.getBundle("config"); Procedure procedurebo; ProcedureDAOHE procedureDAOHE = new ProcedureDAOHE(); procedurebo = procedureDAOHE.findById(file.getFileType()); int SD = 0; try { SD = Integer.parseInt(rb.getString(procedurebo.getDescription() + "_SD")); } catch (NumberFormatException ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } if (SD > 0) { file.setDeadlineAddition(getDateWorkingTime(SD)); } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } //!140627 THIET LAP HAN SDBS HO SO //sms MessageSmsDAOHE msdhe = new MessageSmsDAOHE(); String msg = "Ho so ma: " + file.getFileCode() + " cua doanh nghiep: " + file.getBusinessName() + " dang trong trang thai: da thong bao yeu cau sdbs"; msdhe.saveMessageSMS(userId, file.getUserCreateId(), msg); //email MessageEmailDAOHE msedhe = new MessageEmailDAOHE(); String msge = "H s m: " + file.getFileCode() + " ca doanh nghip: " + file.getBusinessName() + " ang trong trng thi: ? thng bo yu cu sa i b sung."; msedhe.saveMessageEmail(userId, file.getUserCreateId(), msge); // try { // if ("true".equals(ResourceBundleUtil.getString("send_service", "config"))) { // Helper h = new Helper(); // h.sendMs_330(file.getFileId(), msge); // } // } catch (UnsupportedEncodingException ex) { // Logger.getLogger(FilesDAOHE.class.getName()).log(Level.SEVERE, null, ex); // } } if (status.equals(Constants.FILE_STATUS.FEDBACK_TO_EVALUATE)) { // Tra lai cho chuyen vien tham dinh if (form.getLeaderStaffRequest() != null) { file.setLeaderStaffRequest( userName + " " + dateTime + ":\n" + form.getLeaderStaffRequest()); } if (p != null) { //lay process tham dinh ho so ProcessDAOHE psdhe = new ProcessDAOHE(); Process pold = psdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.EVALUATED, Constants.FILE_STATUS.NEW_CREATE); if (pold != null) { newP.setReceiveGroup(pold.getSendGroup()); newP.setReceiveGroupId(pold.getSendGroupId()); if (file != null && file.getStaffProcess() != null && file.getNameStaffProcess() != null) { newP.setReceiveUser(file.getNameStaffProcess()); newP.setReceiveUserId(file.getStaffProcess()); } else { newP.setReceiveUser(pold.getSendUser()); newP.setReceiveUserId(pold.getSendUserId()); } } else {//141218u binhnt53 fix loi ho so lanh dao phong tra lai voi pold = psdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.FEDBACK_TO_ADD, Constants.FILE_STATUS.NEW_CREATE); if (pold != null) { newP.setReceiveGroup(pold.getSendGroup()); newP.setReceiveGroupId(pold.getSendGroupId()); if (file != null && file.getStaffProcess() != null && file.getNameStaffProcess() != null) { newP.setReceiveUser(file.getNameStaffProcess()); newP.setReceiveUserId(file.getStaffProcess()); } else { newP.setReceiveUser(pold.getSendUser()); newP.setReceiveUserId(pold.getSendUserId()); } } else { pold = psdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.ASSIGNED, null); if (pold != null) { newP.setReceiveGroup(pold.getReceiveGroup()); newP.setReceiveGroupId(pold.getReceiveGroupId()); newP.setReceiveUser(pold.getReceiveUser()); newP.setReceiveUserId(pold.getReceiveUserId()); } else if (p != null) {// Gui lai cho chinh nguoi gui newP.setReceiveGroup(p.getSendGroup()); newP.setReceiveGroupId(p.getSendGroupId()); newP.setReceiveUser(p.getSendUser()); newP.setReceiveUserId(p.getSendUserId()); } } } } //hieptq update 080515 // xoa ban ghi lanh dao comment khi bi tra lai RequestCommentDAOHE rcdhe = new RequestCommentDAOHE(); RequestComment rc = rcdhe.findLeaderComment(form.getFileId(), 1l); if (rc != null && !"".equals(rc.getContent())) { rc.setIsActive(0l); getSession().update(rc); } } /* if (form.getStatus().equals(Constants.FILE_STATUS.REVIEWED_TO_ADD)) {//da xem xet yc sdbs newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); newP.setReceiveUser(file.getNameStaffProcess()); newP.setReceiveUserId(file.getStaffProcess()); }*/ if (status.equals(Constants.FILE_STATUS.REVIEW_TO_ADD)) { /* lanh dao phong vao xem xet noi dung thong bao sua doi bo sung chinh sua noi dung luu va gui len lanh dao cuc */ if (form.getIsTypeChange() != null) { file.setIsTypeChange(form.getIsTypeChange());//chuyen loai ho so hay khong } newP.setReceiveUser(form.getLeaderApproveName()); newP.setReceiveUserId(form.getLeaderApproveId()); newP.setReceiveGroup(file.getAgencyName()); newP.setReceiveGroupId(file.getAgencyId()); //cap nhat noi dung thong bao - tao noi dung thong bao RequestComment rcbo = new RequestComment(); if (form.getEvaluationRecordsForm() != null) { String content = ""; if (form.getLeaderStaffRequest() != null && !"null".equals(form.getLeaderStaffRequest())) { content += "* ? kin chung:" + "\n"; content += form.getLeaderStaffRequest() + "\n"; } if (form.getEvaluationRecordsForm().getLegalContentL() != null && !"null".equals(form.getEvaluationRecordsForm().getLegalContentL())) { content += "* V? php ch:" + "\n"; content += form.getEvaluationRecordsForm().getLegalContentL() + "\n"; } if (form.getEvaluationRecordsForm().getFoodSafetyQualityContentL() != null && !"null".equals( form.getEvaluationRecordsForm().getFoodSafetyQualityContentL())) { content += "* V? ch tiu cht lng an ton thc phm:" + "\n"; content += form.getEvaluationRecordsForm().getFoodSafetyQualityContentL() + "\n"; } if (form.getEvaluationRecordsForm().getEffectUtilityContentL() != null && !"null" .equals(form.getEvaluationRecordsForm().getEffectUtilityContentL())) { content += "* V? c ch tc dng, cng dng v hng dn s dng:" + "\n"; content += form.getEvaluationRecordsForm().getEffectUtilityContentL() + "\n"; } if (content != null && !"null".equals(content)) { rcbo.setContent(content); } else { rcbo.setContent("Khng c ni dung."); } } else if (file.getLeaderStaffRequest() != null) { rcbo.setContent(form.getLeaderStaffRequest()); } else { rcbo.setContent("Lnh o phng cha c ni dung."); } rcbo.setCreateBy(userId); rcbo.setCreateDate(dateNow); rcbo.setUserId(userId); rcbo.setUserName(userName); rcbo.setStatus(1L); rcbo.setIsActive(1L); rcbo.setGroupId(deptId); rcbo.setGroupName(deptName); rcbo.setIsLastChange(Constants.ACTIVE_STATUS.ACTIVE); rcbo.setObjectId(form.getFileId()); rcbo.setRequestType(Constants.REQUEST_COMMENT_TYPE.TBSDBS); //-150120 RequestCommentDAOHE rqdaohe = new RequestCommentDAOHE(); RequestComment lastRQBo = rqdaohe.findLastRequestComment(file.getFileId(), Constants.ACTIVE_STATUS.ACTIVE); if (lastRQBo != null) { rcbo.setLastContent(lastRQBo.getContent()); lastRQBo.setIsLastChange(Constants.ACTIVE_STATUS.DEACTIVE); getSession().update(lastRQBo); } getSession().save(rcbo); //!cap nhat noi dung thong bao - tao noi dung thong bao //-150120 //!luu noi dung du thao } } getSession().save(newP); //insert noi dung tham dinh if (form.getEvaluationRecordsForm() != null) { EvaluationRecordsDAOHE evaluationRecordsDAOHE = new EvaluationRecordsDAOHE(); EvaluationRecords evaluationRecords = evaluationRecordsDAOHE.findFilesByFileId(file); if (evaluationRecords != null) { evaluationRecords.setSendDate(file.getSendDate()); evaluationRecords.setLegalL(form.getEvaluationRecordsForm().getLegalL()); evaluationRecords.setLegalContentL(form.getEvaluationRecordsForm().getLegalContentL()); evaluationRecords .setFoodSafetyQualityL(form.getEvaluationRecordsForm().getFoodSafetyQualityL()); evaluationRecords.setFoodSafetyQualityContentL( form.getEvaluationRecordsForm().getFoodSafetyQualityContentL()); evaluationRecords .setEffectUtilityL(form.getEvaluationRecordsForm().getEffectUtilityL()); evaluationRecords.setEffectUtilityContentL( form.getEvaluationRecordsForm().getEffectUtilityContentL()); evaluationRecords.setFilesStatusL(status); evaluationRecords.setMainContentL(form.getLeaderStaffRequest()); getSession().update(evaluationRecords); } insertRequestCommentLeader(file.getFileId(), form, userId, userName, deptId, deptName, dateNow);//binhnt53 150130 } if (p != null) { p.setStatus(status); p.setLastestComment(form.getLeaderStaffRequest()); getSession().update(p); } else { ProcessDAOHE psdhe = new ProcessDAOHE(); Process pFeedbacktoAdd = psdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.FEDBACK_TO_ADD, Constants.FILE_STATUS.NEW_CREATE); if (pFeedbacktoAdd != null) { pFeedbacktoAdd.setStatus(status); pFeedbacktoAdd.setLastestComment(form.getLeaderStaffRequest()); getSession().update(pFeedbacktoAdd); } } // Hiepvv_Home Update Title And Content of File SDBS after announced if (form.getContentsEditATTP() != null && form.getTitleEditATTP() != null && (!"".equals(form.getContentsEditATTP().trim()) || !"".equals(form.getTitleEditATTP().trim())) && (file.getFilesSourceID() != null && file.getFilesSourceID() > 0 && file.getFileSourceCode() != null)) { if (form.getTitleEditATTP() != null) { file.setTitleEditATTP(form.getTitleEditATTP()); } if (form.getContentsEditATTP() != null) { file.setContentsEditATTP(form.getContentsEditATTP()); } } //End Hiepvv update(file); } else { return false; } } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } return bReturn; } public boolean onAssignApprove(FilesForm form, Long deptId, String deptName, Long userId, String userName) { boolean bReturn = true; try { Files file = findById(form.getFileId()); Date dateNow = getSysdate(); if (file == null) { bReturn = false; } else { ProcessDAOHE pdhe = new ProcessDAOHE(); Process oldP = pdhe.getProcessByAction(file.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.REVIEWED, Constants.FILE_STATUS.NEW_CREATE); if (oldP != null) { oldP.setReceiveUser(form.getLeaderApproveName()); oldP.setReceiveUserId(form.getLeaderApproveId()); getSession().update(oldP); } file.setModifyDate(dateNow); file.setLeaderApproveName(form.getLeaderApproveName()); file.setLeaderApproveId(form.getLeaderApproveId()); update(file); } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } return bReturn; } //cuc truong phan cong ho so sau khi co y kien cua public boolean onAssignApproveByCT(FilesForm form, Long deptId, String deptName, Long userId, String userName) { boolean bReturn = true; try { Files file = findById(form.getFileId()); Date dateNow = getSysdate(); if (file == null) { bReturn = false; } else { Long processStatus = file.getStatus(); file.setStatus(form.getStatus()); file.setDisplayStatus(getFileStatusName(form.getStatus())); String dateTime = DateTimeUtils.convertDateToString(dateNow, "dd/MM/yyyy HH:mm"); file.setLeaderStaffRequest(userName + " " + dateTime + ":\n" + form.getLeaderStaffRequest()); file.setDisplayRequest(form.getLeaderStaffRequest()); file.setModifyDate(dateNow); file.setLeaderApproveName(form.getLeaderApproveName()); file.setLeaderApproveId(form.getLeaderApproveId()); // Cap nhat process ProcessDAOHE pdhe = new ProcessDAOHE(); Process oldP = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, processStatus, Constants.FILE_STATUS.NEW_CREATE); if (oldP != null) { oldP.setStatus(form.getStatus()); oldP.setLastestComment(form.getLeaderStaffRequest()); getSession().update(oldP); } //to process mi vi x l hin ti Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setProcessStatus(form.getStatus()); // De xu ly newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setStatus(0l); // Moi den chua xu ly newP.setIsActive(1l); newP.setReceiveDate(dateNow); if (form.getStatus().equals(Constants.FILE_STATUS.REVIEWED)) {//tr v? cho vn th thng bo i chiu newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); newP.setReceiveUser(form.getLeaderApproveName()); newP.setReceiveUserId(form.getLeaderApproveId()); //cap nhat noi dung thong bao - tao noi dung thong bao RequestComment rcbo = new RequestComment(); if (file.getLeaderRequest() != null) { rcbo.setContent(form.getLeaderStaffRequest()); } else { rcbo.setContent("Cc trng khng c ni dung."); } rcbo.setCreateBy(userId); rcbo.setCreateDate(dateNow); rcbo.setUserId(userId); rcbo.setUserName(userName); rcbo.setStatus(1L); rcbo.setIsActive(1L); rcbo.setGroupId(deptId); rcbo.setGroupName(deptName); rcbo.setIsLastChange(Constants.ACTIVE_STATUS.ACTIVE); rcbo.setObjectId(form.getFileId()); rcbo.setRequestType(Constants.REQUEST_COMMENT_TYPE.YK);//trinh cuc truong //-150120 RequestCommentDAOHE rqdaohe = new RequestCommentDAOHE(); RequestComment lastRQBo = rqdaohe.findLastRequestComment(file.getFileId(), Constants.ACTIVE_STATUS.ACTIVE); if (lastRQBo != null) { rcbo.setLastContent(lastRQBo.getContent()); lastRQBo.setIsLastChange(Constants.ACTIVE_STATUS.DEACTIVE); getSession().update(lastRQBo); } getSession().save(rcbo); //-150120 //cap nhat noi dung thong bao - tao noi dung thong bao } getSession().save(newP); update(file); } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } return bReturn; } /** * phe duyet xem xet doi chieu * * @param form * @param deptId * @param deptName * @param userId * @param userName * @return */ public boolean onApproveReviewComparison(FilesForm form, Long deptId, String deptName, Long userId, String userName) { boolean bReturn = true; try { Files file = findById(form.getFileId()); Date dateNow = getSysdate(); if (file == null) { bReturn = false; } else { file.setStatus(form.getStatus()); file.setDisplayStatus(getFileStatusName(form.getStatus())); String dateTime = DateTimeUtils.convertDateToString(dateNow, "dd/MM/yyyy HH:mm"); file.setLeaderRequest(userName + " " + dateTime + ":\n" + form.getLeaderRequest()); file.setDisplayRequest(form.getLeaderRequest()); file.setModifyDate(dateNow); file.setLeaderStaffSignId(userId); file.setLeaderStaffSignName(userName); // Cap nhat process ProcessDAOHE pdhe = new ProcessDAOHE(); Process p = pdhe.getWorkingProcess(form.getFileId(), Constants.OBJECT_TYPE.FILES, deptId, userId); if (p != null) { p.setStatus(form.getStatus()); p.setLastestComment(form.getLeaderRequest()); getSession().update(p); } if (form.getStatus().equals(Constants.FILE_STATUS.APPROVED)) {// Tra lai cho lanh dao don vi xem xet lai file.setIsFee(0L);//bay gio tinh phi giay cong bo //update binhnt // try { // if ("true".equals(ResourceBundleUtil.getString("send_service", "config"))) { // Helper h = new Helper(); // h.sendMs_340(file.getFileId(), "Ho so ma: " + file.getFileCode() + " Da duoc phe duyet yeu cau nop phi ho so."); // } // } catch (UnsupportedEncodingException ex) { // Logger.getLogger(FilesDAOHE.class.getName()).log(Level.SEVERE, null, ex); // } Process pReviewComparison = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.REVIEW_COMPARISON, Constants.FILE_STATUS.NEW_CREATE); if (pReviewComparison != null) { pReviewComparison.setStatus(form.getStatus()); pReviewComparison.setLastestComment(form.getLeaderRequest()); getSession().update(pReviewComparison); } Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setReceiveDate(dateNow); newP.setProcessStatus(form.getStatus()); // De xu ly newP.setStatus(0l); // Moi den chua xu ly newP.setIsActive(1l); // chuyen xuong van thu tra ho so Process oldP = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.RECEIVED, Constants.FILE_STATUS.ASSIGNED); if (oldP != null) { newP.setReceiveGroup(oldP.getSendGroup()); newP.setReceiveGroupId(oldP.getSendGroupId()); newP.setReceiveUser(oldP.getSendUser()); newP.setReceiveUserId(oldP.getSendUserId()); } getSession().save(newP); //sms MessageSmsDAOHE msdhe = new MessageSmsDAOHE(); String msg = "Ho so ma: " + file.getFileCode() + " cua doanh nghiep: " + file.getBusinessName() + " dang trong trang thai: da phe duyet"; msdhe.saveMessageSMS(userId, file.getUserCreateId(), msg); //email MessageEmailDAOHE msedhe = new MessageEmailDAOHE(); String msge = "H s m: " + file.getFileCode() + " ca doanh nghip: " + file.getBusinessName() + " ang trong trng thi: ph duyt."; msedhe.saveMessageEmail(userId, file.getUserCreateId(), msge); } if (form.getStatus().equals(Constants.FILE_STATUS.FEDBACK_TO_REVIEW)) {// Tra lai cho lanh dao don vi xem xet lai Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); // Gui toi chinh don vi quan ly de xem xet if (p != null) { // Gui lai cho chinh nguoi gui newP.setReceiveDate(dateNow); newP.setReceiveGroup(p.getSendGroup()); newP.setReceiveGroupId(p.getSendGroupId()); newP.setReceiveUser(p.getSendUser()); newP.setReceiveUserId(p.getSendUserId()); } newP.setProcessStatus(form.getStatus()); // De xu ly newP.setStatus(0l); // Moi den chua xu ly newP.setIsActive(1l); getSession().save(newP); } if (form.getStatus().equals(Constants.FILE_STATUS.EVALUATED_TO_ADD)) {// gui tra ho so cho doanh nghiep sua doi bo sung Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); // newP.setReceiveDate(dateNow); newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); newP.setProcessStatus(form.getStatus()); //De xu ly newP.setStatus(0l); //Moi den chua xu ly newP.setIsActive(1l); getSession().save(newP); //xa bn ghi temp trc nu c (lu vo vng lu tr) updateSetNotLastIsTemp(file.getFileId()); try { ResourceBundle rb = ResourceBundle.getBundle("config"); Procedure procedurebo; ProcedureDAOHE procedureDAOHE = new ProcedureDAOHE(); procedurebo = procedureDAOHE.findById(file.getFileType()); int SD = 0; try { SD = Integer.parseInt(rb.getString(procedurebo.getDescription() + "_SD")); } catch (NumberFormatException ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } if (SD > 0) { file.setDeadlineAddition(getDateWorkingTime(SD)); } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } //y kien lanh chuyen thanh y kien cua lanh dao } } update(file); } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } return bReturn; } /** * xem xet doi chieu lanh dao phong * * @param form * @param deptId * @param deptName * @param userId * @param userName * @return */ public boolean onComparisonByLeaderOfStaff(FilesForm form, Long deptId, String deptName, Long userId, String userName) {//db140425 boolean bReturn = true; try { Files file = findById(form.getFileId()); Date dateNow = getSysdate(); if (file == null) { bReturn = false; } else { if (form.getIsComparison().equals(1L)) {//xem xet ok file.setStatus(Constants.FILE_STATUS.REVIEW_COMPARISON); file.setDisplayStatus(getFileStatusName(Constants.FILE_STATUS.REVIEW_COMPARISON)); form.setStatus(Constants.FILE_STATUS.REVIEW_COMPARISON); } else {//xem xet not ok file.setStatus(Constants.FILE_STATUS.COMPARED_FAIL); file.setDisplayStatus(getFileStatusName(Constants.FILE_STATUS.COMPARED_FAIL)); form.setStatus(Constants.FILE_STATUS.COMPARED_FAIL); } file.setModifyDate(dateNow); file.setComparisonContent(form.getComparisonContent()); file.setIsComparison(form.getIsComparison()); //cap nhat noi dung thong bao - tao noi dung thong bao RequestComment rcbo = new RequestComment(); rcbo.setContent(form.getComparisonContent()); rcbo.setCreateBy(userId); rcbo.setCreateDate(dateNow); rcbo.setUserId(userId); rcbo.setUserName(userName); rcbo.setStatus(1L); rcbo.setIsActive(1L); rcbo.setGroupId(deptId); rcbo.setGroupName(deptName); rcbo.setIsLastChange(Constants.ACTIVE_STATUS.ACTIVE); rcbo.setObjectId(form.getFileId()); rcbo.setRequestType(Constants.REQUEST_COMMENT_TYPE.TBDC); //-150120 RequestCommentDAOHE rqdaohe = new RequestCommentDAOHE(); RequestComment lastRQBo = rqdaohe.findLastRequestComment(file.getFileId(), Constants.ACTIVE_STATUS.ACTIVE); if (lastRQBo != null) { rcbo.setLastContent(lastRQBo.getContent()); lastRQBo.setIsLastChange(Constants.ACTIVE_STATUS.DEACTIVE); getSession().update(lastRQBo); } getSession().save(rcbo); //-150120 //!cap nhat noi dung thong bao - tao noi dung thong bao //update process cu ProcessDAOHE pdhe = new ProcessDAOHE(); Process oldP = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.COMPARED, Constants.FILE_STATUS.NEW_CREATE); Process approveFail = null; if (oldP != null) {//truong hop la chuyen vien gui len oldP.setStatus(form.getStatus()); if (form.getRequestCommentForm() != null) { oldP.setLastestComment(form.getRequestCommentForm().getContent()); } getSession().update(oldP); } else {//truong hop lanh dao cuc tra ve approveFail = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.REVIEW_COMPARISON_FAIL, Constants.FILE_STATUS.NEW_CREATE); if (approveFail != null) { approveFail.setStatus(form.getStatus()); if (form.getRequestCommentForm() != null) { approveFail.setLastestComment(form.getRequestCommentForm().getContent()); } getSession().update(approveFail); } } //tao process moi Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setReceiveDate(dateNow); newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setProcessStatus(form.getStatus()); // De xu ly newP.setStatus(0L); // Moi den chua xu ly newP.setIsActive(1l); newP.setReceiveDate(dateNow); //tim lanh dao co quan de phe duyet if (form.getIsComparison().equals(1L)) { //approveFail = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.REVIEW_COMPARISON_FAIL, Constants.FILE_STATUS.NEW_CREATE); if (approveFail != null) {//neu la lanh dao tra ve - tra lai luon cho lanh dao newP.setReceiveGroup(approveFail.getSendGroup()); newP.setReceiveGroupId(approveFail.getSendGroupId()); newP.setReceiveUser(approveFail.getSendUser()); newP.setReceiveUserId(approveFail.getSendUserId()); } else {//nop len lanh dao cuc - chua ro lanh dao newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); } } else { //tra lai cho chuyen vien de doi chieu Process pold = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.ASSIGNED, Constants.FILE_STATUS.EVALUATED); if (pold != null) { newP.setReceiveGroup(pold.getSendGroup()); newP.setReceiveGroupId(pold.getSendGroupId()); newP.setReceiveUser(pold.getReceiveUser()); newP.setReceiveUserId(pold.getReceiveUserId()); } else { newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); } } getSession().save(newP); getSession().update(file); } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } return bReturn; } /** * tao thong bao doi chieu ho so binhnt53 - 140817 * * @param form * @param deptId * @param deptName * @param userId * @param userName * @return */ public boolean onAlertComparison(FilesForm form, Long deptId, String deptName, Long userId, String userName) { boolean bReturn = true; try { Files file = findById(form.getFileId());//lay thong tin chi tiet ho so Date dateNow = getSysdate(); if (file == null) { bReturn = false; } else { // Cap nhat trang thai ho so Long lastProcess = file.getStatus(); file.setStatus(form.getStatus()); file.setDisplayStatus(getFileStatusName(form.getStatus())); file.setModifyDate(dateNow); // Cap nhat process ProcessDAOHE pdhe = new ProcessDAOHE(); Process oldP = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, lastProcess, Constants.FILE_STATUS.NEW_CREATE); if (oldP != null) { oldP.setStatus(form.getStatus()); if (form.getRequestCommentForm() != null) { oldP.setLastestComment(form.getRequestCommentForm().getContent()); } getSession().update(oldP); } if (form.getStatus().equals(Constants.FILE_STATUS.ALERT_COMPARISON)) { Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); // newP.setReceiveDate(dateNow); // newP.setReceiveGroup(deptName); // newP.setReceiveGroupId(deptId); //tim doanh nghiep Process pReceive = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.NEW, Constants.FILE_STATUS.RECEIVED); if (pReceive != null) { newP.setReceiveUser(pReceive.getSendUser()); newP.setReceiveUserId(pReceive.getSendUserId()); newP.setReceiveGroup(pReceive.getSendGroup()); newP.setReceiveGroupId(pReceive.getSendGroupId()); } newP.setProcessStatus(form.getStatus()); // De xu ly newP.setStatus(0l); // Moi den chua xu ly newP.setIsActive(1l); getSession().save(newP); //tao noi dung thong bao if (form.getComparisonContent() != null && form.getComparisonContent().trim().length() > 0) { //cap nhat noi dung thong bao - tao noi dung thong bao RequestComment rcbo = new RequestComment(); rcbo.setContent(form.getComparisonContent()); file.setComparisonContent(form.getComparisonContent()); rcbo.setCreateBy(userId); rcbo.setCreateDate(dateNow); rcbo.setUserId(userId); rcbo.setUserName(userName); rcbo.setStatus(1L); rcbo.setIsActive(1L); rcbo.setGroupId(deptId); rcbo.setGroupName(deptName); rcbo.setObjectId(form.getFileId()); rcbo.setRequestType(Constants.REQUEST_COMMENT_TYPE.TBDC);//-150120 rcbo.setIsLastChange(Constants.ACTIVE_STATUS.ACTIVE);//-150120 //-150120 RequestCommentDAOHE rqdaohe = new RequestCommentDAOHE(); RequestComment lastRQBo = rqdaohe.findLastRequestComment(file.getFileId(), Constants.ACTIVE_STATUS.ACTIVE); if (lastRQBo != null) { rcbo.setLastContent(lastRQBo.getContent()); lastRQBo.setIsLastChange(Constants.ACTIVE_STATUS.DEACTIVE); getSession().update(lastRQBo); } getSession().save(rcbo); //-150120 //!cap nhat noi dung thong bao - tao noi dung thong bao } } update(file); } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } return bReturn; } /** * insert requestComment binhnt53 add 150130 * * @param objectId * @param form * @param userId * @param dateNow * @param userName * @param deptName * @param deptId * @return */ public boolean insertRequestComment(Long objectId, FilesForm form, Long userId, String userName, Long deptId, String deptName, Date dateNow) { boolean result = false; RequestComment rcbo = new RequestComment(); if (form.getStatus() != null) { String staffContent = ""; if (form.getStatus().equals(Constants.FILE_STATUS.EVALUATED) || form.getStatus().equals(Constants.FILE_STATUS.FEDBACK_TO_ADD) || form.getStatus().equals(Constants.FILE_STATUS.FEDBACK_TO_EVALUATE)) { if (form.getStaffRequest() != null && !"null".equals(form.getStaffRequest())) { staffContent += "* ? kin chung:" + "\n"; staffContent += form.getStaffRequest() + "\n"; } // else { // staffContent += "Khng c ni dung." + "\n"; // } if (form.getEvaluationRecordsForm().getLegalContent() != null && !"null".equals(form.getEvaluationRecordsForm().getLegalContent())) { staffContent += "* V? php ch:" + "\n"; staffContent += form.getEvaluationRecordsForm().getLegalContent() + "\n"; } // else { // staffContent += "Khng c ni dung." + "\n"; // } if (form.getEvaluationRecordsForm().getFoodSafetyQualityContent() != null && !"null".equals(form.getEvaluationRecordsForm().getFoodSafetyQualityContent())) { staffContent += "* V? ch tiu cht lng an ton thc phm:" + "\n"; staffContent += form.getEvaluationRecordsForm().getFoodSafetyQualityContent() + "\n"; } // else { // staffContent += "Khng c ni dung." + "\n"; // } if (form.getEvaluationRecordsForm().getEffectUtilityContent() != null && !"null".equals(form.getEvaluationRecordsForm().getEffectUtilityContent())) { staffContent += "* V? c ch tc dng, cng dng v hng dn s dng:" + "\n"; staffContent += form.getEvaluationRecordsForm().getEffectUtilityContent() + "\n"; } // else { // staffContent += "Khng c ni dung." + "\n"; // } if (staffContent.trim().length() > 0) { rcbo.setContent(staffContent); } else { rcbo.setContent("Khng c ni dung."); } } else { rcbo.setContent("Khng c ni dung."); } rcbo.setCreateBy(userId); rcbo.setCreateDate(dateNow); rcbo.setUserId(userId); rcbo.setUserName(userName); rcbo.setStatus(1L); rcbo.setIsActive(1L); rcbo.setGroupId(deptId); rcbo.setGroupName(deptName); rcbo.setObjectId(form.getFileId()); rcbo.setRequestType(Constants.REQUEST_COMMENT_TYPE.TD);//-150120 rcbo.setIsLastChange(Constants.ACTIVE_STATUS.ACTIVE);//-150120 //!luu noi dung du thao RequestCommentDAOHE rqdaohe = new RequestCommentDAOHE(); RequestComment lastRQBo = rqdaohe.findLastRequestComment(objectId, Constants.ACTIVE_STATUS.ACTIVE); if (lastRQBo != null) { rcbo.setLastContent(lastRQBo.getContent()); lastRQBo.setIsLastChange(Constants.ACTIVE_STATUS.DEACTIVE); getSession().update(lastRQBo); } getSession().save(rcbo); } else { return false; } return result; } public boolean insertRequestCommentOnGrid(Long objectId, FilesForm form, Long userId, String userName, Long deptId, String deptName, Date dateNow) { boolean result = false; RequestComment rcbo = new RequestComment(); if (form.getStatus() != null) { String staffContent = ""; if (form.getStatus().equals(Constants.FILE_STATUS.EVALUATED) || form.getStatus().equals(Constants.FILE_STATUS.FEDBACK_TO_ADD) || form.getStatus().equals(Constants.FILE_STATUS.FEDBACK_TO_EVALUATE)) { if (form.getStaffRequest() != null && !"null".equals(form.getStaffRequest())) { staffContent += "* ? kin chung:" + "\n"; staffContent += form.getStaffRequest() + "\n"; } // else { // staffContent += "Khng c ni dung." + "\n"; // } if (form.getEvaluationRecordsFormOnGrid().getLegalContent() != null && !"null".equals(form.getEvaluationRecordsFormOnGrid().getLegalContent())) { staffContent += "* V? php ch:" + "\n"; staffContent += form.getEvaluationRecordsFormOnGrid().getLegalContent() + "\n"; } // else { // staffContent += "Khng c ni dung." + "\n"; // } if (form.getEvaluationRecordsFormOnGrid().getFoodSafetyQualityContent() != null && !"null".equals(form.getEvaluationRecordsFormOnGrid().getFoodSafetyQualityContent())) { staffContent += "* V? ch tiu cht lng an ton thc phm:" + "\n"; staffContent += form.getEvaluationRecordsFormOnGrid().getFoodSafetyQualityContent() + "\n"; } // else { // staffContent += "Khng c ni dung." + "\n"; // } if (form.getEvaluationRecordsFormOnGrid().getEffectUtilityContent() != null && !"null".equals(form.getEvaluationRecordsFormOnGrid().getEffectUtilityContent())) { staffContent += "* V? c ch tc dng, cng dng v hng dn s dng:" + "\n"; staffContent += form.getEvaluationRecordsFormOnGrid().getEffectUtilityContent() + "\n"; } // else { // staffContent += "Khng c ni dung." + "\n"; // } if (staffContent.trim().length() > 0) { rcbo.setContent(staffContent); } else { rcbo.setContent("Khng c ni dung."); } } else { rcbo.setContent("Khng c ni dung."); } rcbo.setCreateBy(userId); rcbo.setCreateDate(dateNow); rcbo.setUserId(userId); rcbo.setUserName(userName); rcbo.setStatus(1L); rcbo.setIsActive(1L); rcbo.setGroupId(deptId); rcbo.setGroupName(deptName); rcbo.setObjectId(form.getFileId()); rcbo.setRequestType(Constants.REQUEST_COMMENT_TYPE.TD);//-150120 rcbo.setIsLastChange(Constants.ACTIVE_STATUS.ACTIVE);//-150120 //!luu noi dung du thao RequestCommentDAOHE rqdaohe = new RequestCommentDAOHE(); RequestComment lastRQBo = rqdaohe.findLastRequestComment(objectId, Constants.ACTIVE_STATUS.ACTIVE); if (lastRQBo != null) { rcbo.setLastContent(lastRQBo.getContent()); lastRQBo.setIsLastChange(Constants.ACTIVE_STATUS.DEACTIVE); getSession().update(lastRQBo); } getSession().save(rcbo); } else { return false; } return result; } /** * insert requestComment binhnt53 add 150130 * * @param objectId * @param form * @param userId * @param dateNow * @param userName * @param deptName * @param deptId * @return */ public boolean insertRequestCommentLeader(Long objectId, FilesForm form, Long userId, String userName, Long deptId, String deptName, Date dateNow) { boolean result = false; RequestComment rcbo = new RequestComment(); if (form.getStatus() != null) { String leaderContent = ""; if (form.getStatus().equals(Constants.FILE_STATUS.REVIEWED) || form.getStatus().equals(Constants.FILE_STATUS.FEDBACK_TO_EVALUATE) || form.getStatus().equals(Constants.FILE_STATUS.REVIEW_TO_ADD)) { if (form.getLeaderStaffRequest() != null && !"null".equals(form.getLeaderStaffRequest())) { leaderContent += "* ? kin chung:" + "\n"; leaderContent += form.getLeaderStaffRequest() + "\n"; } // else { // leaderContent += "Khng c ni dung." + "\n"; // } if (form.getEvaluationRecordsForm().getLegalContentL() != null && !"null".equals(form.getEvaluationRecordsForm().getLegalContentL())) { leaderContent += "* V? php ch:" + "\n"; leaderContent += form.getEvaluationRecordsForm().getLegalContentL() + "\n"; } // else { // leaderContent += "Khng c ni dung." + "\n"; // } if (form.getEvaluationRecordsForm().getFoodSafetyQualityContentL() != null && !"null".equals(form.getEvaluationRecordsForm().getFoodSafetyQualityContentL())) { leaderContent += "* V? ch tiu cht lng an ton thc phm:" + "\n"; leaderContent += form.getEvaluationRecordsForm().getFoodSafetyQualityContentL() + "\n"; } // else { // leaderContent += "Khng c ni dung." + "\n"; // } if (form.getEvaluationRecordsForm().getEffectUtilityContentL() != null && !"null".equals(form.getEvaluationRecordsForm().getEffectUtilityContentL())) { leaderContent += "* V? c ch tc dng, cng dng v hng dn s dng:" + "\n"; leaderContent += form.getEvaluationRecordsForm().getEffectUtilityContentL() + "\n"; } // else { // leaderContent += "Khng c ni dung." + "\n"; // } if (leaderContent.trim().length() > 0) { rcbo.setContent(leaderContent); } else { rcbo.setContent("Khng c ni dung."); } } else { rcbo.setContent("Khng c ni dung."); } rcbo.setCreateBy(userId); rcbo.setCreateDate(dateNow); rcbo.setUserId(userId); rcbo.setUserName(userName); rcbo.setStatus(1L); rcbo.setIsActive(Constants.ACTIVE_STATUS.ACTIVE); rcbo.setGroupId(deptId); rcbo.setGroupName(deptName); rcbo.setObjectId(form.getFileId()); rcbo.setRequestType(Constants.REQUEST_COMMENT_TYPE.TD);//-150120 rcbo.setIsLastChange(Constants.ACTIVE_STATUS.ACTIVE);//-150120 //!luu noi dung du thao RequestCommentDAOHE rqdaohe = new RequestCommentDAOHE(); RequestComment lastRQBo = rqdaohe.findLastRequestComment(objectId, Constants.ACTIVE_STATUS.ACTIVE); if (lastRQBo != null) { rcbo.setLastContent(lastRQBo.getContent()); lastRQBo.setIsLastChange(Constants.ACTIVE_STATUS.DEACTIVE); getSession().update(lastRQBo); } getSession().save(rcbo); } else { return false; } return result; } /** * * @param objectId * @param form * @param deptId * @param deptName * @param userId * @param userName * @return */ public boolean validateRoleUser(Long objectId, FilesForm form, Long deptId, String deptName, Long userId, String userName) { Files fbo; FilesDAOHE fdaohe = new FilesDAOHE(); Long status; ProcessDAOHE psdaohe = new ProcessDAOHE(); Process pbo; if ((objectId == null && form == null) || deptId == null || userId == null) { return false; } if (objectId != null) { fbo = fdaohe.findById(objectId); } else if (form != null && form.getFileId() != null) { fbo = fdaohe.findById(form.getFileId()); } else { return false; } if (fbo == null) { return false; } else { objectId = fbo.getFileId(); status = fbo.getStatus(); } pbo = psdaohe.getProcessByAction(objectId, Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, status, Constants.FILE_STATUS.NEW_CREATE); if (pbo != null) { if (pbo.getReceiveUserId() != null && pbo.getReceiveUserId().equals(userId)) { return true; } else if (pbo.getReceiveUserId() == null) { return pbo.getReceiveGroupId().equals(deptId); //CHECK ROLE RETURN // UsersDAOHE udaohe = new UsersDAOHE(); // Users u = udaohe.findById(userId); // String roleUser = p.getPosCode(); } else { return false; } } else { return false; } } public boolean onReviewManyFiles(FilesForm form, Long deptId, String deptName, Long userId, String userName) { boolean bReturn = true; try { Files file = findById(form.getFileId()); Date dateNow = getSysdate(); if (file == null) { bReturn = false; } else { Long processStatus = file.getStatus();//trang thai ho so truoc khi thay doi Long status = form.getStatus(); if (processStatus != null//141225 BINHNT update phan quyen ho so tham dinh && (processStatus.equals(Constants.FILE_STATUS.EVALUATED)//DA THAM DINH DAT || processStatus.equals(Constants.FILE_STATUS.FEDBACK_TO_REVIEW)//TRA LAI XEM XET LAI || processStatus.equals(Constants.FILE_STATUS.EVALUATE_TO_ADD)//TRA LAI XEM XET LAI || processStatus.equals(Constants.FILE_STATUS.FEDBACK_TO_ADD))) {//DA THAM DINH YEU CA SDBS // Cap nhat trang thai ho so file.setStatus(status); file.setDisplayStatus(getFileStatusName(status)); String dateTime = DateTimeUtils.convertDateToString(dateNow, "dd/MM/yyyy HH:mm"); if (!status.equals(Constants.FILE_STATUS.REVIEW_TO_ADD)) { file.setLeaderStaffRequest( userName + " " + dateTime + ":\n" + form.getLeaderStaffRequest()); file.setDisplayRequest(form.getLeaderStaffRequest()); } file.setModifyDate(dateNow); file.setEvaluateAddDate(dateNow); file.setLeaderApproveName(form.getLeaderApproveName()); file.setLeaderApproveId(form.getLeaderApproveId()); // Cap nhat process ProcessDAOHE pdhe = new ProcessDAOHE(); Process p = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, processStatus, Constants.FILE_STATUS.NEW_CREATE); Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setProcessStatus(status); // De xu ly newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setStatus(Constants.FILE_STATUS.NEW_CREATE); // Moi den chua xu ly newP.setIsActive(Constants.ACTIVE_STATUS.ACTIVE); newP.setReceiveDate(dateNow); newP.setReceiveUser(form.getLeaderApproveName()); newP.setReceiveUserId(form.getLeaderApproveId()); newP.setReceiveGroup(file.getAgencyName()); newP.setReceiveGroupId(file.getAgencyId()); getSession().save(newP); if (p != null) { p.setStatus(status); p.setLastestComment(form.getLeaderStaffRequest()); getSession().update(p); } else { Process pFeedbacktoAdd = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.FEDBACK_TO_ADD, Constants.FILE_STATUS.NEW_CREATE); if (pFeedbacktoAdd != null) { pFeedbacktoAdd.setStatus(status); pFeedbacktoAdd.setLastestComment(form.getLeaderStaffRequest()); getSession().update(pFeedbacktoAdd); } } update(file); } else { return false; } } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } return bReturn; } //hieptq update 070515 public boolean saveDraftComment(FilesForm form, Long deptId, String deptName, Long userId, String userName) { boolean bReturn = true; try { Files file = findById(form.getFileId()); Date dateNow = getSysdate(); if (file == null) { bReturn = false; } else { RequestComment rcbo = new RequestComment(); rcbo.setContent(form.getLeaderStaffRequest()); file.setComparisonContent(form.getLeaderStaffRequest()); rcbo.setCreateBy(userId); rcbo.setCreateDate(dateNow); rcbo.setUserId(userId); rcbo.setUserName(userName); rcbo.setStatus(1L); rcbo.setIsActive(1L); rcbo.setGroupId(deptId); rcbo.setGroupName(deptName); rcbo.setObjectId(form.getFileId()); rcbo.setRequestType(Constants.REQUEST_COMMENT_TYPE.TPLN); rcbo.setIsLastChange(Constants.ACTIVE_STATUS.ACTIVE); RequestCommentDAOHE rqdaohe = new RequestCommentDAOHE(); RequestComment lastRQBo = rqdaohe.findLastRequestComment(file.getFileId(), Constants.ACTIVE_STATUS.ACTIVE); if (lastRQBo != null) { rcbo.setLastContent(lastRQBo.getContent()); lastRQBo.setIsLastChange(Constants.ACTIVE_STATUS.DEACTIVE); getSession().update(lastRQBo); } getSession().save(rcbo); } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } return bReturn; } //hieptq update phi thuoc la private Boolean saveFeeTL(Long fileId, Long fileType, Long productType, Procedure pro, Long productTypeIdOld) { if (fileId != null) { Date dateNow = null; try { dateNow = getSysdate(); } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 return false; } String hql = "select fpif from FeePaymentInfo fpif where fpif.fileId =:fileId and fpif.isActive = 1"; Query query = getSession().createQuery(hql); query.setParameter("fileId", fileId); List<FeePaymentInfo> FeePaymentInfo = query.list(); // // truong hop sao chep va luu tam productType co the = null, vi the phai set = -1 // if (FeePaymentInfo.isEmpty()) { FeeDAOHE fdhe = new FeeDAOHE(); List<FeeProcedure> feenew = fdhe.findAllFeeByProcedureId(fileType); // check le phi cap so theo loai ho so if (feenew != null && feenew.size() > 0) { FeePaymentInfo fpif; for (int i = 0; i < feenew.size(); i++) { fpif = new FeePaymentInfo(); fpif.setCreateDate(dateNow); fpif.setFeePaymentTypeId(3l); fpif.setPaymentConfirm("admin"); fpif.setPaymentDate(dateNow); fpif.setDateConfirm(dateNow); fpif.setPaymentPerson("admin"); fpif.setPaymentInfo("h s thuc l khng ng ph"); fpif.setStatus(1l); fpif.setFileId(fileId); fpif.setIsActive(1l); fpif.setFeeId(feenew.get(i).getFeeId()); Fee feeTemp = (Fee) findById(Fee.class, "feeId", feenew.get(i).getFeeId()); fpif.setCost(feeTemp.getPrice()); getSession().save(fpif); } } // hieptq update 280515 set phi ho so cap lai if (productType != null) { if (pro != null && pro.getTypeFee() == 7l) { FeePaymentInfo fpif = new FeePaymentInfo(); Fee findfee1 = fdhe.findFeeByCode("TL"); fpif.setCreateDate(dateNow); fpif.setStatus(1l); fpif.setFileId(fileId); fpif.setDateConfirm(dateNow); fpif.setFeePaymentTypeId(3l); fpif.setPaymentConfirm("admin"); fpif.setPaymentDate(dateNow); fpif.setPaymentPerson("admin"); fpif.setPaymentInfo("h s thuc l khng ng ph"); if (findfee1 != null) { fpif.setFeeId(findfee1.getFeeId()); fpif.setCost(findfee1.getPrice()); fpif.setCostCheck(findfee1.getPrice()); fpif.setFeeIdOld(findfee1.getFeeId()); } else { return false; } fpif.setIsActive(1l); getSession().save(fpif); } } FilesDAOHE filesdhe = new FilesDAOHE(); Files f = filesdhe.findById(fileId); f.setIsFee(1l); getSession().save(f); return true; } else { return true; } } else { return false; } } private Boolean saveFee4Star(Long fileId, Long fileType) { if (fileId != null) { Date dateNow = getSysdate(); String hql = "select fpif from FeePaymentInfo fpif " + "where fpif.fileId =:fileId " + "and fpif.isActive = 1"; Query query = getSession().createQuery(hql); query.setParameter("fileId", fileId); List<FeePaymentInfo> lstFeePaymentInfo = query.list(); // truong hop sao chep va luu tam productType co the = null, vi the phai set = -1 if (lstFeePaymentInfo.isEmpty()) { FeeDAOHE fdhe = new FeeDAOHE(); List<FeeProcedure> lstFee = fdhe.findAllFeeByProcedureId(fileType); //check le phi cap so theo loai ho so if (lstFee != null && lstFee.size() > 0) { FeePaymentInfo fpif; for (int i = 0; i < lstFee.size(); i++) { fpif = new FeePaymentInfo(); //Thong tin co ban, status=1 = da dong phi fpif.setCreateDate(dateNow); fpif.setStatus(0l); fpif.setFileId(fileId); fpif.setIsActive(1l); fpif.setFeeId(lstFee.get(i).getFeeId()); Fee feeTemp = (Fee) findById(Fee.class, "feeId", lstFee.get(i).getFeeId()); if (feeTemp.getFeeCode().equals(Constants.FEE_TYPE.KS4SLP)) { fpif.setCost(feeTemp.getPrice()); } else if (feeTemp.getFeeCode().equals(Constants.FEE_TYPE.KS4STD)) { String sql = "select count(*) from ProductInFile " + "where file_ID = :fileId"; Query qry1 = getSession().createQuery(sql); qry1.setParameter("fileId", fileId); int count = (int) (long) (Long) qry1.uniqueResult(); fpif.setCost(feeTemp.getPrice() * count); } else if (feeTemp.getPrice() != null) { fpif.setCost(feeTemp.getPrice()); } else { fpif.setCost(0L); } getSession().save(fpif); } } } } else { return false; } return true; } public boolean onEvaluate(FilesForm form, Long deptId, String deptName, Long userId, String userName) { boolean bReturn = true; try { Files file = findById(form.getFileId());//lay thong tin chi tiet ho so Date dateNow = getSysdate(); UsersDAOHE udaohe; if (file == null) { bReturn = false; } else// Cap nhat trang thai ho so if ((file.getStatus() != null && form.getStatus() != null)//141225 binhnt update phan quyen ho so tham dinh && (file.getStatus().equals(Constants.FILE_STATUS.ASSIGNED)//da phan cong || file.getStatus().equals(Constants.FILE_STATUS.FEDBACK_TO_EVALUATE)//tra lai tham dinh lai || file.getStatus().equals(Constants.FILE_STATUS.EVALUATED)//tham dinh || file.getStatus().equals(Constants.FILE_STATUS.REVIEW_TO_ADD)// xem xt ni dung cv sbs LDC || file.getStatus().equals(Constants.FILE_STATUS.REVIEWED_TO_ADD)//? xem xt yu cu S?BS LDC || file.getStatus().equals(Constants.FILE_STATUS.APPROVE_TO_ADD)// ph duyt ni dung thng bo VT || file.getStatus().equals(Constants.FILE_STATUS.FEDBACK_TO_ADD)//da tra lai bo sung ho so || file.getStatus().equals(Constants.FILE_STATUS.RECEIVED_TO_ADD))) {//da tiep nhan ho so sdbs Long processStatus = file.getStatus(); file.setStatus(form.getStatus()); /* khi tham dinh ho so cvien thuc hien tham dinh neu la cv chuyen pp hoac truong phong neu la pp chuyen tp hoac ldc */ boolean isReview = false; if (form.getLeaderReviewId() != null) {//gui lanh dao tham dinh udaohe = new UsersDAOHE(); Users uReceive = udaohe.findById(form.getLeaderReviewId()); if (form.getLeaderReviewName() == null || "".equals(form.getLeaderReviewName())) { form.setLeaderReviewName(uReceive.getFullName()); } List<String> lstStaff = new ArrayList<String>(); lstStaff.add(Constants.POSITION.VFA_CV); lstStaff.add(Constants.POSITION.NV); if (udaohe.checkRoleUserOfLst(deptId, userId, lstStaff)) { if (udaohe.checkTruongPhong(form.getLeaderReviewId())) { file.setLeaderReviewId(form.getLeaderReviewId()); file.setLeaderReviewName(form.getLeaderReviewName()); file.setLeaderApproveId(null); file.setLeaderApproveName(null); } else { file.setLeaderEvaluateId(form.getLeaderReviewId()); file.setLeaderEvaluateName(form.getLeaderReviewName()); file.setLeaderReviewId(null); file.setLeaderReviewName(null); file.setLeaderApproveId(null); file.setLeaderApproveName(null); } } else { List<String> lstTP = new ArrayList<String>(); lstTP.add(Constants.POSITION.LEADER_OF_STAFF_T); lstTP.add(Constants.POSITION.GDTT); if (udaohe.checkRoleUserOfLst(deptId, form.getLeaderReviewId(), lstTP)) { file.setLeaderReviewId(form.getLeaderReviewId()); file.setLeaderReviewName(form.getLeaderReviewName()); file.setLeaderApproveId(null); file.setLeaderApproveName(null); } else { file.setLeaderApproveId(form.getLeaderReviewId()); file.setLeaderApproveName(form.getLeaderReviewName()); if (file.getStatus().equals(Constants.FILE_STATUS.EVALUATED)) { file.setStatus(Constants.FILE_STATUS.REVIEWED); } else if (file.getStatus().equals(Constants.FILE_STATUS.FEDBACK_TO_ADD)) { file.setStatus(Constants.FILE_STATUS.REVIEW_TO_ADD); } isReview = true; } } } else { udaohe = new UsersDAOHE(); List<String> lstLeader = new ArrayList<String>(); lstLeader.add(Constants.POSITION.LEADER_OF_STAFF_T); lstLeader.add(Constants.POSITION.GDTT); Users ubo; List<Users> lstLeaderOfDept = udaohe.findLstUserByLstPosition(deptId, lstLeader); if (lstLeaderOfDept != null && lstLeaderOfDept.size() > 0) { ubo = lstLeaderOfDept.get(0); file.setLeaderReviewId(ubo.getUserId()); file.setLeaderReviewName(ubo.getFullName()); file.setLeaderApproveId(null); file.setLeaderApproveName(null); form.setLeaderReviewId(ubo.getUserId()); form.setLeaderReviewName(ubo.getFullName()); } } // neu tra lai de bo sung -> thiet lap bien have_temp = 1 de biet ma tao ra history khi sua doi if (file.getStatus().equals(Constants.FILE_STATUS.EVALUATED_TO_ADD)) { file.setHaveTemp(1l); } file.setDisplayStatus(getFileStatusName(file.getStatus())); // String dateTime = DateTimeUtils.convertDateToString(dateNow, "dd/MM/yyyy HH:mm"); //file.setStaffRequest(userName + " " + dateTime + ":\n" + form.getStaffRequest()); // String prefix = userName + " " + dateTime + ":\n"; if (form.getStaffRequest() != null && form.getStaffRequest().trim().length() > 0) { String strStaffRequest = form.getStaffRequest(); if (strStaffRequest.trim().length() < 1800) {//u 16 07 29 file.setStaffRequest(strStaffRequest.trim()); } } file.setModifyDate(dateNow); if (form.getEffectiveDate() != null) { file.setEffectiveDate(form.getEffectiveDate()); } else { file.setEffectiveDate(Constants.EFFECTIVEDATE.THREE); } file.setIsTypeChange(form.getIsTypeChange()); file.setLastType(form.getLastType()); //Cap nhat process cu ProcessDAOHE pdhe = new ProcessDAOHE(); Process p = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, processStatus, Constants.FILE_STATUS.NEW_CREATE); if (p != null) { p.setStatus(file.getStatus()); p.setLastestComment(form.getStaffRequest()); getSession().update(p); } //!Cap nhat process cu if (form.getStatus().equals(Constants.FILE_STATUS.EVALUATED) || form.getStatus().equals(Constants.FILE_STATUS.FEDBACK_TO_ADD)) { //tham xet dat, tham xet khong dat deu gui len cho to truong to tham xet xem xet Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setReceiveDate(dateNow); newP.setReceiveUserId(form.getLeaderReviewId()); newP.setReceiveUser(form.getLeaderReviewName()); if (!isReview) { newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); } else { Users leaderApprove = udaohe.findById(file.getLeaderApproveId()); newP.setReceiveGroup(leaderApprove.getDeptName()); newP.setReceiveGroupId(leaderApprove.getDeptId()); } newP.setProcessStatus(file.getStatus()); // De xu ly newP.setStatus(0l); // Moi den chua xu ly newP.setIsActive(1l); getSession().save(newP); } else if (form.getStatus().equals(Constants.FILE_STATUS.EVALUATED_TO_ADD)) { //tao thong bao yeu cau sdbs gui toi doanh nghiep Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setReceiveDate(dateNow); ProcessDAOHE psdhe = new ProcessDAOHE(); Process pold = psdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.NEW, Constants.FILE_STATUS.RECEIVED); if (pold != null) { newP.setReceiveGroupId(pold.getSendGroupId()); newP.setReceiveGroup(pold.getSendGroup()); newP.setReceiveUserId(pold.getSendUserId()); newP.setReceiveUser(pold.getSendUser()); } else { newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); } newP.setProcessStatus(file.getStatus()); //De xu ly newP.setStatus(0l); //Moi den chua xu ly newP.setIsActive(1l); getSession().save(newP); //xa bn ghi temp trc nu c (lu vo vng lu tr) updateSetNotLastIsTemp(file.getFileId()); //xa bn ghi temp trc nu c (lu vo vng lu tr) ProcessCommentDAOHE pcdaohe = new ProcessCommentDAOHE(); pcdaohe.updateSetNotLastIsTemp(file.getFileId()); } else if (form.getStatus().equals(Constants.FILE_STATUS.EVALUATE_TO_ADD)) {//da soan du thao thong bao sdbs ho so /* ho so sau khi da tra lai chuyen vien de soan du thao tb sdbs cv vao tao ban du thao sau khi tao xong luu gui noi dung cho lanh dao phong xem xet */ Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setProcessStatus(file.getStatus()); // De xu ly newP.setStatus(Constants.ACTIVE_STATUS.DEACTIVE);// Moi den chua xu ly-150120 newP.setIsActive(Constants.ACTIVE_STATUS.ACTIVE);//-150120 newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setReceiveDate(dateNow); if (form.getLeaderReviewId() != null) { newP.setReceiveUserId(form.getLeaderReviewId()); file.setLeaderReviewId(form.getLeaderReviewId()); } if (form.getLeaderReviewName() != null) { newP.setReceiveUser(form.getLeaderReviewName()); file.setLeaderReviewName(form.getLeaderReviewName()); } newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); getSession().save(newP); //cap nhat noi dung thong bao - tao noi dung thong bao RequestComment rcbo = new RequestComment(); if (form.getStaffRequest() != null) { rcbo.setContent(form.getStaffRequest()); } else { rcbo.setContent("Chuyn vin cha c ni dung."); } rcbo.setCreateBy(userId); rcbo.setCreateDate(dateNow); rcbo.setUserId(userId); rcbo.setUserName(userName); rcbo.setStatus(1L); rcbo.setIsActive(1L); rcbo.setGroupId(deptId); rcbo.setGroupName(deptName); rcbo.setObjectId(form.getFileId()); rcbo.setRequestType(Constants.REQUEST_COMMENT_TYPE.TBSDBS);//-150120 rcbo.setIsLastChange(Constants.ACTIVE_STATUS.ACTIVE);//-150120 //!luu noi dung du thao //u150119 binhnt53 update li ni dung thng tin. RequestCommentDAOHE rqdaohe = new RequestCommentDAOHE(); RequestComment lastRQBo = rqdaohe.findLastRequestComment(file.getFileId(), Constants.ACTIVE_STATUS.ACTIVE); if (lastRQBo != null) { rcbo.setLastContent(lastRQBo.getContent()); lastRQBo.setIsLastChange(Constants.ACTIVE_STATUS.DEACTIVE); getSession().update(lastRQBo); } getSession().save(rcbo); //!u150119 binhnt53 update li ni dung thng tin. } else if ((form.getStatus()).equals(Constants.FILE_STATUS.FEDBACK_TO_EVALUATE)) {//hieptq update 230415 Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setProcessStatus(p.getStatus()); // De xu ly newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setStatus(Constants.FILE_STATUS.NEW_CREATE); // Moi den chua xu ly newP.setIsActive(Constants.ACTIVE_STATUS.ACTIVE); newP.setReceiveDate(dateNow); if (p != null) { //lay process tham dinh ho so ProcessDAOHE psdhe = new ProcessDAOHE(); Process pold = psdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.EVALUATED, p.getStatus()); if (pold != null) { newP.setReceiveGroup(pold.getSendGroup()); newP.setReceiveGroupId(pold.getSendGroupId()); if (file != null && file.getStaffProcess() != null && file.getNameStaffProcess() != null) { newP.setReceiveUser(file.getNameStaffProcess()); newP.setReceiveUserId(file.getStaffProcess()); } else { newP.setReceiveUser(pold.getSendUser()); newP.setReceiveUserId(pold.getSendUserId()); } } else {//141218u binhnt53 fix loi ho so lanh dao phong tra lai voi pold = psdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, Constants.FILE_STATUS.FEDBACK_TO_ADD, p.getStatus()); if (pold != null) { newP.setReceiveGroup(pold.getSendGroup()); newP.setReceiveGroupId(pold.getSendGroupId()); if (file != null && file.getStaffProcess() != null && file.getNameStaffProcess() != null) { newP.setReceiveUser(file.getNameStaffProcess()); newP.setReceiveUserId(file.getStaffProcess()); } else { newP.setReceiveUser(pold.getSendUser()); newP.setReceiveUserId(pold.getSendUserId()); } } else if (p != null) {// Gui lai cho chinh nguoi gui newP.setReceiveGroup(p.getSendGroup()); newP.setReceiveGroupId(p.getSendGroupId()); newP.setReceiveUser(p.getSendUser()); newP.setReceiveUserId(p.getSendUserId()); } } } getSession().save(newP); } //insert noi dung tham dinh if (form.getEvaluationRecordsForm() != null) { EvaluationRecordsForm evaRecordForm = new EvaluationRecordsForm(); evaRecordForm.setCreateDate(dateNow); evaRecordForm.setSendDate(file.getSendDate()); evaRecordForm.setBusinessName(file.getBusinessName()); evaRecordForm.setBusinessAddress(file.getBusinessAddress()); evaRecordForm.setProductName(file.getProductName()); evaRecordForm.setLegal(form.getEvaluationRecordsForm().getLegal()); evaRecordForm.setLegalContent(form.getEvaluationRecordsForm().getLegalContent()); evaRecordForm.setFoodSafetyQuality(form.getEvaluationRecordsForm().getFoodSafetyQuality()); evaRecordForm.setFoodSafetyQualityContent( form.getEvaluationRecordsForm().getFoodSafetyQualityContent()); evaRecordForm.setEffectUtility(form.getEvaluationRecordsForm().getEffectUtility()); evaRecordForm .setEffectUtilityContent(form.getEvaluationRecordsForm().getEffectUtilityContent()); evaRecordForm.setFilesStatus(file.getStatus()); evaRecordForm.setMainContent(file.getStaffRequest()); evaRecordForm.setFirstStaffId(userId); evaRecordForm.setFirstStaffName(userName); evaRecordForm.setSecondStaffId(userId); evaRecordForm.setSecondStaffName(userName); evaRecordForm.setThirdStaffId(userId); evaRecordForm.setThirdStaffName(userName); evaRecordForm.setLeederStaffId(userId); evaRecordForm.setLeederStaffName(userName); evaRecordForm.setFilesId(file.getFileId()); EvaluationRecords evaluationRecordsBo; evaluationRecordsBo = evaRecordForm.convertToEntity(); getSession().save(evaluationRecordsBo); insertRequestComment(file.getFileId(), form, userId, userName, deptId, deptName, dateNow);//binhnt53 150130 } else if (form.getEvaluationRecordsFormOnGrid() != null) { EvaluationRecordsFormOnGrid evaRecordForm = new EvaluationRecordsFormOnGrid(); evaRecordForm.setCreateDate(dateNow); evaRecordForm.setSendDate(file.getSendDate()); evaRecordForm.setBusinessName(file.getBusinessName()); evaRecordForm.setBusinessAddress(file.getBusinessAddress()); evaRecordForm.setProductName(file.getProductName()); evaRecordForm.setLegal(form.getEvaluationRecordsFormOnGrid().getLegal()); evaRecordForm.setLegalContent(form.getEvaluationRecordsFormOnGrid().getLegalContent()); evaRecordForm .setFoodSafetyQuality(form.getEvaluationRecordsFormOnGrid().getFoodSafetyQuality()); evaRecordForm.setFoodSafetyQualityContent( form.getEvaluationRecordsFormOnGrid().getFoodSafetyQualityContent()); evaRecordForm.setEffectUtility(form.getEvaluationRecordsFormOnGrid().getEffectUtility()); evaRecordForm.setEffectUtilityContent( form.getEvaluationRecordsFormOnGrid().getEffectUtilityContent()); evaRecordForm.setFilesStatus(file.getStatus()); evaRecordForm.setMainContent(file.getStaffRequest()); evaRecordForm.setFirstStaffId(userId); evaRecordForm.setFirstStaffName(userName); evaRecordForm.setSecondStaffId(userId); evaRecordForm.setSecondStaffName(userName); evaRecordForm.setThirdStaffId(userId); evaRecordForm.setThirdStaffName(userName); evaRecordForm.setLeederStaffId(userId); evaRecordForm.setLeederStaffName(userName); evaRecordForm.setFilesId(file.getFileId()); EvaluationRecords evaluationRecordsBo; evaluationRecordsBo = evaRecordForm.convertToEntity(); getSession().save(evaluationRecordsBo); insertRequestCommentOnGrid(file.getFileId(), form, userId, userName, deptId, deptName, dateNow);//binhnt53 150130 } if (form.getStatus().equals(Constants.FILE_STATUS.EVALUATED_TO_ADD)) {//140721 binhnt try {//140627 THIET LAP HAN SDBS HO SO ResourceBundle rb = ResourceBundle.getBundle("config"); Procedure procedurebo; ProcedureDAOHE procedureDAOHE = new ProcedureDAOHE(); procedurebo = procedureDAOHE.findById(file.getFileType()); int SD = 0; try { SD = Integer.parseInt(rb.getString(procedurebo.getDescription() + "_SD")); } catch (NumberFormatException ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } if (SD > 0) { file.setDeadlineAddition(getDateWorkingTime(SD)); } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 } //!140627 THIET LAP HAN SDBS HO SO //sms /* disable send sms binhnt53 150205 MessageSmsDAOHE msdhe = new MessageSmsDAOHE(); String msg = "Ho so ma: " + file.getFileCode() + " cua doanh nghiep: " + file.getBusinessName() + " dang trong trang thai: da thong bao yeu cau sdbs"; msdhe.saveMessageSMS(userId, file.getUserCreateId(), msg); */ //email MessageEmailDAOHE msedhe = new MessageEmailDAOHE(); String msge = "H s m: " + file.getFileCode() + " ca doanh nghip: " + file.getBusinessName() + " ang trong trng thi: ? thng bo yu cu sa i b sung."; msedhe.saveMessageEmail(userId, file.getUserCreateId(), msge); } //!140721 // Hiepvv_Home Update Title And Content of File SDBS after announced if (form.getContentsEditATTP() != null && form.getTitleEditATTP() != null && (!"".equals(form.getContentsEditATTP().trim()) || !"".equals(form.getTitleEditATTP().trim())) && (file.getFilesSourceID() != null && file.getFilesSourceID() > 0 && file.getFileSourceCode() != null)) { if (form.getTitleEditATTP() != null) { file.setTitleEditATTP(form.getTitleEditATTP()); } if (form.getContentsEditATTP() != null) { file.setContentsEditATTP(form.getContentsEditATTP()); } } //End Hiepvv update(file); } else { log.error("Li h thng: Phn quy?n x l h s: " + file.getFileCode()); return false; } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } return bReturn; } public boolean onEvaluateByLeaderManyFiles(FilesForm form, Long deptId, String deptName, Long userId, String userName) { boolean bReturn = true; try { Files file = findById(form.getFileId()); Date dateNow = getSysdate(); boolean isReview = false; if (file == null) { bReturn = false; } else { Long processStatus = file.getStatus();//trang thai ho so truoc khi thay doi Long status = form.getStatus(); file.setStatus(status); file.setDisplayStatus(getFileStatusName(status)); String dateTime = DateTimeUtils.convertDateToString(dateNow, "dd/MM/yyyy HH:mm"); file.setLeaderStaffRequest(userName + " " + dateTime + ":\n" + form.getLeaderStaffRequest()); file.setDisplayRequest(form.getLeaderStaffRequest()); file.setModifyDate(dateNow); file.setEvaluateAddDate(dateNow); UsersDAOHE udaohe = new UsersDAOHE(); List<String> lstTP = new ArrayList<String>(); lstTP.add(Constants.POSITION.LEADER_OF_STAFF_T); lstTP.add(Constants.POSITION.GDTT); if (udaohe.checkRoleUserOfLst(deptId, form.getLeaderReviewId(), lstTP)) { file.setLeaderReviewId(form.getLeaderReviewId()); file.setLeaderReviewName(form.getLeaderReviewName()); file.setLeaderApproveId(null); file.setLeaderApproveName(null); } else { file.setLeaderApproveId(form.getLeaderReviewId()); file.setLeaderApproveName(form.getLeaderReviewName()); file.setStatus(Constants.FILE_STATUS.REVIEWED); file.setDisplayStatus(getFileStatusName(Constants.FILE_STATUS.REVIEWED)); isReview = true; } // Cap nhat process ProcessDAOHE pdhe = new ProcessDAOHE(); Process p = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, processStatus, Constants.FILE_STATUS.NEW_CREATE); p.setStatus(file.getStatus()); p.setLastestComment(form.getLeaderStaffRequest()); getSession().update(p); Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setProcessStatus(file.getStatus()); // De xu ly newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setStatus(Constants.FILE_STATUS.NEW_CREATE); // Moi den chua xu ly newP.setIsActive(Constants.ACTIVE_STATUS.ACTIVE); newP.setReceiveDate(dateNow); newP.setReceiveUser(form.getLeaderReviewName()); newP.setReceiveUserId(form.getLeaderReviewId()); if (isReview) { Users leaderApprove = udaohe.findById(file.getLeaderApproveId()); newP.setReceiveGroup(leaderApprove.getDeptName()); newP.setReceiveGroupId(leaderApprove.getDeptId()); } else { newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); } getSession().save(newP); update(file); } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } return bReturn; } public boolean onEvaluateByLeaderManyFilesToAdd(FilesForm form, Long deptId, String deptName, Long userId, String userName) { boolean bReturn = true; try { Files file = findById(form.getFileId()); Date dateNow = getSysdate(); boolean isReview = false; if (file == null) { bReturn = false; } else { Long processStatus = file.getStatus();//trang thai ho so truoc khi thay doi Long status = form.getStatus(); file.setStatus(status); file.setDisplayStatus(getFileStatusName(status)); String dateTime = DateTimeUtils.convertDateToString(dateNow, "dd/MM/yyyy HH:mm"); file.setLeaderStaffRequest(userName + " " + dateTime + ":\n" + form.getLeaderStaffRequest()); file.setDisplayRequest(form.getLeaderStaffRequest()); file.setModifyDate(dateNow); file.setEvaluateAddDate(dateNow); UsersDAOHE udaohe = new UsersDAOHE(); List<String> lstTP = new ArrayList<String>(); lstTP.add(Constants.POSITION.LEADER_OF_STAFF_T); lstTP.add(Constants.POSITION.GDTT); if (udaohe.checkRoleUserOfLst(deptId, form.getLeaderReviewId(), lstTP)) { file.setLeaderReviewId(form.getLeaderReviewId()); file.setLeaderReviewName(form.getLeaderReviewName()); file.setLeaderApproveId(null); file.setLeaderApproveName(null); } else { file.setLeaderApproveId(form.getLeaderReviewId()); file.setLeaderApproveName(form.getLeaderReviewName()); file.setStatus(Constants.FILE_STATUS.REVIEWED_TO_ADD); file.setDisplayStatus(getFileStatusName(Constants.FILE_STATUS.REVIEWED_TO_ADD)); isReview = true; } // Cap nhat process cu ProcessDAOHE pdhe = new ProcessDAOHE(); Process p = pdhe.getProcessByAction(form.getFileId(), Constants.Status.ACTIVE, Constants.OBJECT_TYPE.FILES, processStatus, Constants.FILE_STATUS.NEW_CREATE); p.setStatus(file.getStatus()); p.setLastestComment(form.getLeaderStaffRequest()); getSession().update(p); //them process mi Process newP = new Process(); newP.setObjectId(form.getFileId()); newP.setObjectType(Constants.OBJECT_TYPE.FILES); newP.setSendDate(dateNow); newP.setSendGroup(deptName); newP.setSendGroupId(deptId); newP.setSendUserId(userId); newP.setSendUser(userName); newP.setProcessStatus(file.getStatus()); // De xu ly newP.setProcessType(Constants.PROCESS_TYPE.MAIN); newP.setStatus(Constants.FILE_STATUS.NEW_CREATE); // Moi den chua xu ly newP.setIsActive(Constants.ACTIVE_STATUS.ACTIVE); newP.setReceiveDate(dateNow); newP.setReceiveUser(form.getLeaderReviewName()); newP.setReceiveUserId(form.getLeaderReviewId()); if (isReview) { Users leaderApprove = udaohe.findById(file.getLeaderApproveId()); newP.setReceiveGroup(leaderApprove.getDeptName()); newP.setReceiveGroupId(leaderApprove.getDeptId()); } else { newP.setReceiveGroup(deptName); newP.setReceiveGroupId(deptId); } getSession().save(newP); update(file); } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 bReturn = false; } return bReturn; } public Files saveFilesWS(FilesForm createForm) { Files bo; Files boRollBack; Long filesId = createForm.getFileId(); // Boolean isCreateNew; Long status = 0L; Long announcementId = null; Long detailProductId = null; Long reIssueFormId = null; Long testRegistrationId = null; Long productTypeIdOld = null; if (createForm.getStatus() != null) { status = createForm.getStatus(); } if (filesId != null) { String hql = "select dt.productType from DetailProduct dt " + "where " + "dt.detailProductId = (select f.detailProductId from Files f where f.fileId =?)"; Query query = getSession().createQuery(hql); query.setParameter(0, filesId); List<Long> lstProductType = query.list(); if (lstProductType.size() > 0) { productTypeIdOld = lstProductType.get(0); } } if (filesId == null) {//la them moi bo = createForm.convertToEntity(); } else {//la sua // isCreateNew = false; // boRollBack = findById(filesId); bo = findById(filesId); if (status.equals(Constants.FILE_STATUS.EVALUATED_TO_ADD) && bo.getHaveTemp() != null && bo.getHaveTemp().equals(1l)) { FilesForm cloneForm = getNewCloneFiles(filesId); cloneForm.setVersion(getCountVersion(bo.getFileId())); bo.setVersion(cloneForm.getVersion());//update version moi nhat cua ho so bo.setHaveTemp(null); saveFiles(cloneForm); //update toan bo process_comment cua lan tham dinh truoc thanh ProcessCommentDAOHE pcdhe = new ProcessCommentDAOHE(); pcdhe.updateVersion(filesId, cloneForm.getVersion()); } bo = createForm.updateToEntity(bo); } //*Luu thong tin cac form chinh cua ho so if (createForm.getAnnouncement() != null) { Announcement ann = createForm.getAnnouncement().convertToEntity(); ann.setIsTemp(0L); if (ann.getAnnouncementId() != null) { session.merge(ann); } else { session.save(ann); } announcementId = ann.getAnnouncementId(); } if (createForm.getDetailProduct() != null) { DetailProduct detail = createForm.getDetailProduct().convertToEntity(); detail.setIsTemp(0L); if (detail.getDetailProductId() != null) { session.merge(detail); } else { session.save(detail); } detailProductId = detail.getDetailProductId(); } if (createForm.getReIssueForm() != null) { ReIssueForm reissue = createForm.getReIssueForm().convertToEntity(); if (reissue.getReIssueFormId() != null) { session.merge(reissue); } else { session.save(reissue); } reIssueFormId = reissue.getReIssueFormId(); } if (createForm.getTestRegistration() != null) { TestRegistration testReg = createForm.getTestRegistration().convertToEntity(); if (testReg.getTestRegistrationId() != null) { getSession().merge(testReg); } else { getSession().save(testReg); } testRegistrationId = testReg.getTestRegistrationId(); } bo.setAnnouncementId(announcementId); bo.setDetailProductId(detailProductId); bo.setReIssueFormId(reIssueFormId); bo.setTestRegistrationId(testRegistrationId); bo.setDisplayStatus(getFileStatusName(bo.getStatus())); if (bo.getFileId() != null) { //khi sua xoa toan bo chu ki CA bo.setStaffRequest(""); bo.setLeaderRequest(""); bo.setLeaderStaffRequest(""); bo.setContentSigned(""); bo.setUserSigned(""); getSession().update(bo); } else { //update 15092015 binhnt cap nhat lay ma ho so if (createForm.getIsTemp() != null && createForm.getIsTemp().equals(Constants.ACTIVE_STATUS.ACTIVE)) { } else { bo.setFileCode(getNewFileCode(createForm.getFileType())); } getSession().save(bo); } filesId = bo.getFileId(); saveMainlytarget(createForm.getLstMainlyTarget(), filesId); saveProductTarget(createForm.getLstBioTarget(), filesId, Constants.PRODUCT_TARGET_TYPE.BIO, createForm.getStatus()); saveProductTarget(createForm.getLstHeavyMetal(), filesId, Constants.PRODUCT_TARGET_TYPE.HEAVY_METAL, createForm.getStatus()); saveProductTarget(createForm.getLstChemical(), filesId, Constants.PRODUCT_TARGET_TYPE.CHEMICAL, createForm.getStatus()); saveAttachs(createForm.getLstAttachs(), filesId, createForm.getLstAttachLabel()); saveQualityPlan(createForm.getLstQualityControl(), filesId); saveProductInFile(createForm.getLstProductInFile(), filesId);// Luu thong tin danh sach san pham nhap khau cho khach san 4 sao try {//lu ph thm nh h s ProcedureDAOHE pdheCheck = new ProcedureDAOHE(); Procedure pro = pdheCheck.getProcedureTypeFee(createForm.getFileType()); if (pro != null && (pro.getTypeFee() == 2 || pro.getTypeFee() == 3) && !pro.getDescription().equals(Constants.FILE_DESCRIPTION.ANNOUNCEMENT_4STAR) && !pro.getDescription().equals(Constants.FILE_DESCRIPTION.ANNOUNCEMENT_FILE05)) { if (!saveFeeForWS(filesId, createForm.getFileType(), null, pro, productTypeIdOld)) { return null; } } //Sua doi sua cong bo. Tao mot ban ghi trong FeePaymentInfo de VanThu nhin thay hoso cua loai nay else if (pro != null && pro.getDescription().equals(Constants.FILE_DESCRIPTION.ANNOUNCEMENT_FILE05)) { if (!saveFeeChangesAfterAnnounced(filesId, createForm.getFileType())) { return null; } } else if (pro != null && pro.getDescription().equals(Constants.FILE_DESCRIPTION.ANNOUNCEMENT_4STAR)) { if (!saveFee4StarForWS(filesId, createForm.getFileType())) { return null; } } else if (pro != null && pro.getDescription().equals(Constants.FILE_DESCRIPTION.ANNOUNCEMENT_TL01) && pro.getDescription().equals(Constants.FILE_DESCRIPTION.ANNOUNCEMENT_TL03) && pro.getDescription().equals(Constants.FILE_DESCRIPTION.CONFIRMTL)) { if (!saveFeeTLForWS(filesId, createForm.getFileType(), createForm.getDetailProduct().getProductType(), pro, productTypeIdOld)) { return null; } } else if (createForm.getDetailProduct() != null && createForm.getDetailProduct().getProductType() != null) { if (!saveFeeForWS(filesId, createForm.getFileType(), createForm.getDetailProduct().getProductType(), pro, productTypeIdOld)) { return null; } } } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 // if (isCreateNew) { // bo.setIsActive(Constants.Status.INACTIVE); // getSession().update(bo); // } else { // getSession().update(boRollBack); // // } return null; } if (createForm.getIsTemp() == null || (createForm.getIsTemp() != null && !createForm.getIsTemp().equals(1l))) { saveFileForSearch(filesId); } getSession().getTransaction().commit(); // session.flush(); return bo; } private Boolean saveFeeForWS(Long fileId, Long fileType, Long productType, Procedure pro, Long productTypeIdOld) { if (fileId != null) { Date dateNow = null; try { dateNow = getSysdate(); } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 return false; } String hql = "select fpif" + " from FeePaymentInfo fpif" + " where" + " fpif.fileId =:fileId" + " and fpif.isActive = 1"; Query query = getSession().createQuery(hql); query.setParameter("fileId", fileId); List<FeePaymentInfo> FeePaymentInfo = query.list(); // truong hop sao chep va luu tam productType co the = null, vi the phai set = -1 if (FeePaymentInfo.isEmpty()) { FeeDAOHE fdhe = new FeeDAOHE(); List<FeeProcedure> feenew = fdhe.findAllFeeByProcedureId(fileType); // check le phi cap so theo loai ho so if (feenew != null && feenew.size() > 0) { FeePaymentInfo fpif; for (int i = 0; i < feenew.size(); i++) { fpif = new FeePaymentInfo(); fpif.setCreateDate(dateNow); fpif.setStatus(0l); fpif.setFileId(fileId); fpif.setIsActive(1l); fpif.setFeeId(feenew.get(i).getFeeId()); Fee feeTemp = (Fee) findById(Fee.class, "feeId", feenew.get(i).getFeeId()); fpif.setCost(feeTemp.getPrice()); getSession().save(fpif); } } // hieptq update 280515 set phi ho so cap lai if (productType == null) { if (pro != null && pro.getTypeFee() == 2l) { FeePaymentInfo fpif = new FeePaymentInfo(); Fee findfee1 = fdhe.findFeeByCode("CLT"); fpif.setCreateDate(dateNow); fpif.setStatus(0l); fpif.setFileId(fileId); if (findfee1 != null) { fpif.setFeeId(findfee1.getFeeId()); fpif.setCost(findfee1.getPrice()); fpif.setCostCheck(findfee1.getPrice()); fpif.setFeeIdOld(findfee1.getFeeId()); } else { return false; } fpif.setIsActive(1l); getSession().save(fpif); return true; } else if (pro != null && pro.getTypeFee() == 3l) { FeePaymentInfo fpif = new FeePaymentInfo(); Fee findfee1 = fdhe.findFeeByCode("CLCN"); fpif.setCreateDate(dateNow); fpif.setStatus(0l); fpif.setFileId(fileId); if (findfee1 != null) { fpif.setFeeId(findfee1.getFeeId()); fpif.setCost(findfee1.getPrice()); fpif.setCostCheck(findfee1.getPrice()); fpif.setFeeIdOld(findfee1.getFeeId()); } else { return false; } fpif.setIsActive(1l); getSession().save(fpif); return true; } else { return false; } } //check loai thuc pham (thuc pham dac biet) CategoryDAOHE ctdhe = new CategoryDAOHE(); Category cate = ctdhe.findCategoryByTypeAndCode("SP", "TPCN"); List<Category> cate1 = ctdhe.findCategoryByTypeAndCodeNew("SP", "DBT"); int check = 0; for (int i = 0; i < cate1.size(); i++) { if (productType.equals(cate1.get(i).getCategoryId())) { check = 1; break; } } if (check == 1) { FeePaymentInfo fpif = new FeePaymentInfo(); Fee findfee1 = fdhe.findFeeByCode("TPDB"); fpif.setCreateDate(dateNow); fpif.setStatus(0l); fpif.setFileId(fileId); if (findfee1 != null) { fpif.setFeeId(findfee1.getFeeId()); fpif.setCost(findfee1.getPrice()); fpif.setCostCheck(findfee1.getPrice()); fpif.setFeeIdOld(findfee1.getFeeId()); } else { return false; } fpif.setIsActive(1l); getSession().save(fpif); } else { // thuc pham chuc nang FeePaymentInfo fpif = new FeePaymentInfo(); if (productType.equals(cate.getCategoryId())) { Fee findfee2 = fdhe.findFeeByCode("TPCN"); fpif.setCreateDate(dateNow); fpif.setStatus(0l); fpif.setFileId(fileId); if (findfee2 != null) { fpif.setFeeId(findfee2.getFeeId()); fpif.setCost(findfee2.getPrice()); fpif.setCostCheck(findfee2.getPrice()); fpif.setFeeIdOld(findfee2.getFeeId()); } else { return false; } fpif.setIsActive(1l); getSession().save(fpif); } else { Fee findfee3 = fdhe.findFeeByCode("TPK"); fpif.setCreateDate(dateNow); fpif.setStatus(0l); fpif.setFileId(fileId); if (findfee3 != null) { fpif.setFeeId(findfee3.getFeeId()); fpif.setCost(findfee3.getPrice()); fpif.setCostCheck(findfee3.getPrice()); fpif.setFeeIdOld(findfee3.getFeeId()); } else { return false; } fpif.setIsActive(1l); getSession().save(fpif); } } // } } // sua nhom san pham va chuyen loai ho so - map lai phi if ((productTypeIdOld != null) && (!productTypeIdOld.equals(productType))) { // hieptq update 310115 // tim lai feeId cu CategoryDAOHE ctdhe = new CategoryDAOHE(); FeeDAOHE fdhe = new FeeDAOHE(); Category cate = ctdhe.findCategoryByTypeAndCode("SP", "TPCN"); List<Category> cate1 = ctdhe.findCategoryByTypeAndCodeNew("SP", "DBT"); Long feeIdOld, feeIdNew; int check = 0, check1 = 0; FeePaymentInfo fpifOld; for (int i = 0; i < cate1.size(); i++) { if (productTypeIdOld.equals(cate1.get(i).getCategoryId())) { check = 1; break; } } if (check == 1) { Fee findfee1 = fdhe.findFeeByCode("TPDB"); feeIdOld = findfee1.getFeeId(); } else // thuc pham chuc nang if (productTypeIdOld.equals(cate.getCategoryId())) { Fee findfee2 = fdhe.findFeeByCode("TPCN"); feeIdOld = findfee2.getFeeId(); } else { Fee findfee3 = fdhe.findFeeByCode("TPK"); feeIdOld = findfee3.getFeeId(); } fpifOld = fdhe.findFeePaymentInfoFileIdFeeIdIsActive(fileId, feeIdOld, 1l); // lay feeid moi for (int i = 0; i < cate1.size(); i++) { if (productType.equals(cate1.get(i).getCategoryId())) { check1 = 1; break; } } Long costNew; if (check1 == 1) { Fee findfee1 = fdhe.findFeeByCode("TPDB"); feeIdNew = findfee1.getFeeId(); costNew = findfee1.getPrice(); } else // thuc pham chuc nang if (productType.equals(cate.getCategoryId())) { Fee findfee2 = fdhe.findFeeByCode("TPCN"); feeIdNew = findfee2.getFeeId(); costNew = findfee2.getPrice(); } else { Fee findfee3 = fdhe.findFeeByCode("TPK"); feeIdNew = findfee3.getFeeId(); costNew = findfee3.getPrice(); } FilesDAOHE filesdhe = new FilesDAOHE(); Files filesnew = filesdhe.findById(fileId); // check gia cu va gia moi if (fpifOld.getCostCheck().equals(costNew) || fpifOld.getCostCheck() > costNew) { if (filesnew.getStatus() == 0l) { fpifOld.setCost(fpifOld.getCostCheck()); fpifOld.setFeeId(fpifOld.getFeeIdOld()); getSession().update(fpifOld); } else { fpifOld.setCost(fpifOld.getCostCheck()); fpifOld.setFeeId(fpifOld.getFeeIdOld()); fpifOld.setStatus(1l); filesnew.setIsFee(1l); getSession().update(filesnew); getSession().update(fpifOld); } return true; } else if (filesnew.getStatus() == 0l) { fpifOld.setCost(costNew); fpifOld.setFeeId(feeIdNew); getSession().update(fpifOld); } else { fpifOld.setCost(costNew); fpifOld.setFeeId(feeIdNew); fpifOld.setStatus(0l); //Hiepvv 0803 Khong tinh phi SDBS sau cong bo ProcedureDAOHE pHE = new ProcedureDAOHE(); Procedure pdu; pdu = pHE.findById(filesnew.getFileType()); if (pdu != null && pdu.getDescription() != null && pdu.getDescription().equals(Constants.FILE_DESCRIPTION.ANNOUNCEMENT_FILE05)) { filesnew.setIsFee(1l); } else { filesnew.setIsFee(0l); } getSession().update(filesnew); getSession().update(fpifOld); } } } else { return false; } return true; } private Boolean saveFeeTLForWS(Long fileId, Long fileType, Long productType, Procedure pro, Long productTypeIdOld) { if (fileId != null) { Date dateNow = null; try { dateNow = getSysdate(); } catch (Exception ex) { LogUtil.addLog(ex);//binhnt sonar a160901 return false; } String hql = "select fpif from FeePaymentInfo fpif where fpif.fileId =:fileId and fpif.isActive = 1"; Query query = getSession().createQuery(hql); query.setParameter("fileId", fileId); List<FeePaymentInfo> FeePaymentInfo = query.list(); // truong hop sao chep va luu tam productType co the = null, vi the phai set = -1 if (FeePaymentInfo.isEmpty()) { FeeDAOHE fdhe = new FeeDAOHE(); List<FeeProcedure> feenew = fdhe.findAllFeeByProcedureId(fileType); // check le phi cap so theo loai ho so if (feenew != null && feenew.size() > 0) { FeePaymentInfo fpif; for (int i = 0; i < feenew.size(); i++) { fpif = new FeePaymentInfo(); fpif.setCreateDate(dateNow); fpif.setFeePaymentTypeId(3l); fpif.setPaymentConfirm("admin"); fpif.setPaymentDate(dateNow); fpif.setDateConfirm(dateNow); fpif.setPaymentPerson("admin"); fpif.setPaymentInfo("h s thuc l khng ng ph"); fpif.setStatus(1l); fpif.setFileId(fileId); fpif.setIsActive(1l); fpif.setFeeId(feenew.get(i).getFeeId()); Fee feeTemp = (Fee) findById(Fee.class, "feeId", feenew.get(i).getFeeId()); fpif.setCost(feeTemp.getPrice()); getSession().save(fpif); } } // hieptq update 280515 set phi ho so cap lai if (productType != null) { if (pro != null && pro.getTypeFee() == 7l) { FeePaymentInfo fpif = new FeePaymentInfo(); Fee findfee1 = fdhe.findFeeByCode("TL"); fpif.setCreateDate(dateNow); fpif.setStatus(1l); fpif.setFileId(fileId); fpif.setDateConfirm(dateNow); fpif.setFeePaymentTypeId(3l); fpif.setPaymentConfirm("admin"); fpif.setPaymentDate(dateNow); fpif.setPaymentPerson("admin"); fpif.setPaymentInfo("h s thuc l khng ng ph"); if (findfee1 != null) { fpif.setFeeId(findfee1.getFeeId()); fpif.setCost(findfee1.getPrice()); fpif.setCostCheck(findfee1.getPrice()); fpif.setFeeIdOld(findfee1.getFeeId()); } else { return false; } fpif.setIsActive(1l); getSession().save(fpif); } } FilesDAOHE filesdhe = new FilesDAOHE(); Files f = filesdhe.findById(fileId); f.setIsFee(1l); getSession().save(f); return true; } else { return true; } } else { return false; } } private Boolean saveFee4StarForWS(Long fileId, Long fileType) { if (fileId != null) { Date dateNow = getSysdate(); String hql = "select fpif from FeePaymentInfo fpif " + "where fpif.fileId =:fileId " + "and fpif.isActive = 1"; Query query = getSession().createQuery(hql); query.setParameter("fileId", fileId); List<FeePaymentInfo> lstFeePaymentInfo = query.list(); // truong hop sao chep va luu tam productType co the = null, vi the phai set = -1 if (lstFeePaymentInfo.isEmpty()) { FeeDAOHE fdhe = new FeeDAOHE(); List<FeeProcedure> lstFee = fdhe.findAllFeeByProcedureId(fileType); //check le phi cap so theo loai ho so if (lstFee != null && lstFee.size() > 0) { FeePaymentInfo fpif; for (int i = 0; i < lstFee.size(); i++) { fpif = new FeePaymentInfo(); //Thong tin co ban, status=1 = da dong phi fpif.setCreateDate(dateNow); fpif.setStatus(0l); fpif.setFileId(fileId); fpif.setIsActive(1l); fpif.setFeeId(lstFee.get(i).getFeeId()); Fee feeTemp = (Fee) findById(Fee.class, "feeId", lstFee.get(i).getFeeId()); if (feeTemp.getFeeCode().equals(Constants.FEE_TYPE.KS4SLP)) { fpif.setCost(feeTemp.getPrice()); } else if (feeTemp.getFeeCode().equals(Constants.FEE_TYPE.KS4STD)) { String sql = "select count(*) from ProductInFile " + "where file_ID = :fileId"; Query qry1 = getSession().createQuery(sql); qry1.setParameter("fileId", fileId); int count = (int) (long) (Long) qry1.uniqueResult(); fpif.setCost(feeTemp.getPrice() * count); } else if (feeTemp.getPrice() != null) { fpif.setCost(feeTemp.getPrice()); } else { fpif.setCost(0L); } getSession().save(fpif); } } } } else { return false; } return true; } private Boolean saveFeeChangesAfterAnnouncedForWS(Long fileId, Long fileType) { if (fileId != null) { Date dateNow = getSysdate(); String hql = "select fpif from FeePaymentInfo fpif" + " where fpif.fileId =:fileId" + " and fpif.isActive = 1"; Query query = getSession().createQuery(hql); query.setParameter("fileId", fileId); List<FeePaymentInfo> FeePaymentInfo = query.list(); // truong hop sao chep va luu tam productType co the = null, vi the phai set = -1 if (FeePaymentInfo.isEmpty()) { FeeDAOHE fdhe = new FeeDAOHE(); List<FeeProcedure> feenew = fdhe.findAllFeeByProcedureId(fileType); // check le phi cap so theo loai ho so if (feenew != null && feenew.size() > 0) { FeePaymentInfo fpif; for (int i = 0; i < feenew.size(); i++) { fpif = new FeePaymentInfo(); //Thong tin co ban, status=1 = da dong phi fpif.setCreateDate(dateNow); fpif.setStatus(1l); fpif.setFileId(fileId); fpif.setIsActive(1l); fpif.setFeeId(feenew.get(i).getFeeId()); Fee feeTemp = (Fee) findById(Fee.class, "feeId", feenew.get(i).getFeeId()); fpif.setCost(feeTemp.getPrice()); //Thong tin fix cung cho du du lieu fpif.setPaymentPerson("ATTP"); fpif.setPaymentDate(dateNow); fpif.setFeePaymentTypeId(3L); fpif.setBillPath(""); fpif.setPaymentConfirm("ATTP"); fpif.setDateConfirm(dateNow); fpif.setCostCheck(0L); getSession().save(fpif); } } } } else { return false; } return true; } public void rollBack() { getSession().getTransaction().rollback(); } public Files findByNswCode(String code) { Query query = getSession().createQuery("Select f from Files f where f.fileCode = :code "); query.setParameter("code", code); List result = query.list(); if (result.isEmpty()) { return null; } else { return (Files) result.get(0); } } }