List of usage examples for java.util GregorianCalendar setTime
public final void setTime(Date date)
Date
. From source file:fr.cls.atoll.motu.library.misc.intfce.Organizer.java
/** * Date to XML gregorian calendar./*from ww w.j a va 2s.c om*/ * * @param date the date * * @return the XML gregorian calendar * * @throws MotuException the motu exception */ public static XMLGregorianCalendar dateToXMLGregorianCalendar(Date date) throws MotuException { GregorianCalendar gCalendar = new GregorianCalendar(); gCalendar.setTime(date); XMLGregorianCalendar xmlGregorianCalendar; try { xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gCalendar); } catch (DatatypeConfigurationException e) { throw new MotuException("ERROR in dateToXMLGregorianCalendar", e); } return xmlGregorianCalendar; }
From source file:ru.apertum.qsystem.client.forms.FAdmin.java
private void buttonExportToCSVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExportToCSVActionPerformed final JFileChooser fc = new JFileChooser(); fc.setDialogTitle(getLocaleMessage("save.statictic")); fc.setFileFilter(new FileFilter() { @Override/*from w w w.jav a 2 s .c om*/ public boolean accept(File f) { return !f.isFile() || f.getAbsolutePath().toLowerCase().endsWith(".csv"); } @Override public String getDescription() { return getLocaleMessage("files.type.csv"); } }); //fc.setCurrentDirectory(new File("config")); //fc.setSelectedFile(new File(configuration.getSystemName())); fc.setDialogType(JFileChooser.SAVE_DIALOG); if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { final File file; //This is where a real application would open the file. if (!fc.getSelectedFile().getAbsolutePath().toLowerCase().endsWith(".csv")) { file = new File(fc.getSelectedFile().getAbsoluteFile() + ".csv"); } else { file = fc.getSelectedFile(); } Spring.getInstance().getHt().getSessionFactory().openSession().doWork((Connection connection) -> { final GregorianCalendar gc = new GregorianCalendar(); gc.setTime(dateChooserStartCsv.getDate()); gc.set(GregorianCalendar.HOUR_OF_DAY, 0); gc.set(GregorianCalendar.MINUTE, 0); gc.set(GregorianCalendar.SECOND, 0); gc.set(GregorianCalendar.MILLISECOND, 0); final String std = Uses.format_for_rep.format(gc.getTime()); gc.setTime(dateChooserFinishCsv.getDate()); gc.set(GregorianCalendar.HOUR_OF_DAY, 0); gc.set(GregorianCalendar.MINUTE, 0); gc.set(GregorianCalendar.SECOND, 0); gc.set(GregorianCalendar.MILLISECOND, 0); gc.add(GregorianCalendar.HOUR, 24); final String find = Uses.format_for_rep.format(gc.getTime()); final String sql = " SELECT " + " s.client_id as id, " + " concat(c.service_prefix , c.number) as num, " + " c.input_data as inp, " + " DATE_FORMAT(s.client_stand_time, '%d.%m.%y %H:%i') as stnd, " + " sv.name as srv, " + " DATE_FORMAT(s.user_start_time, '%d.%m.%y %H:%i') as strt, " + " DATE_FORMAT(s.user_finish_time, '%d.%m.%y %H:%i') as fin, " + " u.name as usr, " + " s.client_wait_period as wt, " + " s.user_work_period as wrk, " + " IFNULL(r.name, '') as res " + " FROM statistic s left join results r on s.results_id=r.id, clients c, users u, services sv " + " WHERE s.client_id=c.id and s.user_id=u.id and s.service_id=sv.id " + " and s.client_stand_time>='" + std + "' and s.client_stand_time<='" + find + "'"; try (ResultSet set = connection.createStatement().executeQuery(sql)) { final Writer writer; try { writer = new OutputStreamWriter(new FileOutputStream(file), "cp1251").append(""); writer.append(""); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.number")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.data")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.stand_time")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.service_name")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.start_time")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.finish_time")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.user")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.wait")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.work")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(getLocaleMessage("csv.result")); writer.append('\n'); while (set.next()) { writer.append(set.getString("id")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("num")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("inp")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("stnd")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append( set.getString("srv").replace(cbSeparateCSV.getSelectedItem().toString(), " ")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("strt")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("fin")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("usr")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("wt")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("wrk")); writer.append(cbSeparateCSV.getSelectedItem().toString()); writer.append(set.getString("res")); writer.append('\n'); } //generate whatever data you want writer.flush(); writer.close(); } catch (IOException ex) { throw new ClientException(ex); } } JOptionPane.showMessageDialog(fc, getLocaleMessage("stat.saved"), getLocaleMessage("stat.saving"), JOptionPane.INFORMATION_MESSAGE); }); } }
From source file:com.flexive.core.storage.genericSQL.GenericHierarchicalStorage.java
/** * Set a properties data for inserts or updates * * @param insert perform insert or update? * @param prop current property * @param allData all data of the instance (might be needed to buld references, etc.) * @param con an open and valid connection * @param data current property data * @param ps prepared statement for the data table * @param ft fulltext indexer * @param upperColumnPos position of the uppercase column (if present, else <code>-1</code>) * @param includeFullText add fulltext entries? Will be skipped for position only changes * @throws SQLException on errors * @throws FxUpdateException on errors * @throws FxDbException on errors * @throws FxNoAccessException for FxNoAccess values *//* ww w .j a v a 2 s . c o m*/ private void setPropertyData(boolean insert, FxProperty prop, List<FxData> allData, Connection con, FxPropertyData data, PreparedStatement ps, FulltextIndexer ft, int upperColumnPos, boolean includeFullText) throws SQLException, FxUpdateException, FxDbException, FxNoAccessException { FxValue value = data.getValue(); if (value instanceof FxNoAccess) throw new FxNoAccessException("ex.content.value.noaccess"); if (value.isMultiLanguage() != ((FxPropertyAssignment) data.getAssignment()).isMultiLang()) { if (((FxPropertyAssignment) data.getAssignment()).isMultiLang()) throw new FxUpdateException("ex.content.value.invalid.multilanguage.ass.multi", data.getXPathFull()); else throw new FxUpdateException("ex.content.value.invalid.multilanguage.ass.single", data.getXPathFull()); } int pos_lang = insert ? INSERT_LANG_POS : UPDATE_ID_POS + 2; int pos_isdef_lang = insert ? INSERT_ISDEF_LANG_POS : UPDATE_MLDEF_POS; final FxEnvironment env = CacheAdmin.getEnvironment(); if (prop.getDataType().isSingleRowStorage()) { //Data types that just use one db row can be handled in a very similar way Object translatedValue; GregorianCalendar gc = null; final long[] translatedLanguages = value.getTranslatedLanguages(); for (long translatedLanguage : translatedLanguages) { translatedValue = value.getTranslation(translatedLanguage); if (translatedValue == null) { LOG.warn("Translation for " + data.getXPath() + " is null!"); } ps.setLong(pos_lang, translatedLanguage); if (!value.isMultiLanguage()) ps.setBoolean(pos_isdef_lang, true); else ps.setBoolean(pos_isdef_lang, value.isDefaultLanguage(translatedLanguage)); if (upperColumnPos != -1) { final Locale locale = value.isMultiLanguage() ? env.getLanguage(translatedLanguage).getLocale() : Locale.getDefault(); ps.setString(upperColumnPos, translatedValue.toString().toUpperCase(locale)); } int[] pos = insert ? getColumnPosInsert(prop) : getColumnPosUpdate(prop); switch (prop.getDataType()) { case Double: checkDataType(FxDouble.class, value, data.getXPathFull()); ps.setDouble(pos[0], (Double) translatedValue); break; case Float: checkDataType(FxFloat.class, value, data.getXPathFull()); ps.setFloat(pos[0], (Float) translatedValue); break; case LargeNumber: checkDataType(FxLargeNumber.class, value, data.getXPathFull()); ps.setLong(pos[0], (Long) translatedValue); break; case Number: checkDataType(FxNumber.class, value, data.getXPathFull()); ps.setInt(pos[0], (Integer) translatedValue); break; case HTML: checkDataType(FxHTML.class, value, data.getXPathFull()); boolean useTidy = ((FxHTML) value).isTidyHTML(); ps.setBoolean(pos[1], useTidy); final String extractorInput = doTidy(data.getXPathFull(), (String) translatedValue); if (useTidy) { translatedValue = extractorInput; } final HtmlExtractor result = new HtmlExtractor(extractorInput, true); setBigString(ps, pos[2], result.getText()); setBigString(ps, pos[0], (String) translatedValue); break; case String1024: case Text: checkDataType(FxString.class, value, data.getXPathFull()); setBigString(ps, pos[0], (String) translatedValue); break; case Boolean: checkDataType(FxBoolean.class, value, data.getXPathFull()); ps.setBoolean(pos[0], (Boolean) translatedValue); break; case Date: checkDataType(FxDate.class, value, data.getXPathFull()); if (gc == null) gc = new GregorianCalendar(); gc.setTime((Date) translatedValue); //strip all time information, this might not be necessary since ps.setDate() strips them //for most databases but won't hurt either ;) gc.set(GregorianCalendar.HOUR, 0); gc.set(GregorianCalendar.MINUTE, 0); gc.set(GregorianCalendar.SECOND, 0); gc.set(GregorianCalendar.MILLISECOND, 0); ps.setDate(pos[0], new java.sql.Date(gc.getTimeInMillis())); break; case DateTime: checkDataType(FxDateTime.class, value, data.getXPathFull()); if (gc == null) gc = new GregorianCalendar(); gc.setTime((Date) translatedValue); ps.setTimestamp(pos[0], new Timestamp(gc.getTimeInMillis())); break; case DateRange: checkDataType(FxDateRange.class, value, data.getXPathFull()); if (gc == null) gc = new GregorianCalendar(); gc.setTime(((DateRange) translatedValue).getLower()); gc.set(GregorianCalendar.HOUR, 0); gc.set(GregorianCalendar.MINUTE, 0); gc.set(GregorianCalendar.SECOND, 0); gc.set(GregorianCalendar.MILLISECOND, 0); ps.setDate(pos[0], new java.sql.Date(gc.getTimeInMillis())); gc.setTime(((DateRange) translatedValue).getUpper()); gc.set(GregorianCalendar.HOUR, 0); gc.set(GregorianCalendar.MINUTE, 0); gc.set(GregorianCalendar.SECOND, 0); gc.set(GregorianCalendar.MILLISECOND, 0); ps.setDate(pos[1], new java.sql.Date(gc.getTimeInMillis())); break; case DateTimeRange: checkDataType(FxDateTimeRange.class, value, data.getXPathFull()); if (gc == null) gc = new GregorianCalendar(); gc.setTime(((DateRange) translatedValue).getLower()); ps.setTimestamp(pos[0], new Timestamp(gc.getTimeInMillis())); gc.setTime(((DateRange) translatedValue).getUpper()); ps.setTimestamp(pos[1], new Timestamp(gc.getTimeInMillis())); break; case Binary: checkDataType(FxBinary.class, value, data.getXPathFull()); BinaryDescriptor binary = (BinaryDescriptor) translatedValue; if (!binary.isNewBinary()) { ps.setLong(pos[0], binary.getId()); } else { try { //transfer the binary from the transit table to the binary table BinaryDescriptor created = binaryStorage.binaryTransit(con, binary); ps.setLong(pos[0], created.getId()); //check all other properties if they contain the same handle //and replace with the data of the new binary for (FxData _curr : allData) { if (_curr instanceof FxPropertyData && !_curr.isEmpty() && ((FxPropertyData) _curr).getValue() instanceof FxBinary) { FxBinary _val = (FxBinary) ((FxPropertyData) _curr).getValue(); _val._replaceHandle(binary.getHandle(), created); } } } catch (FxApplicationException e) { throw new FxDbException(e); } } break; case SelectOne: checkDataType(FxSelectOne.class, value, data.getXPathFull()); ps.setLong(pos[0], ((FxSelectListItem) translatedValue).getId()); break; case SelectMany: checkDataType(FxSelectMany.class, value, data.getXPathFull()); SelectMany sm = (SelectMany) translatedValue; for (int i1 = 0; i1 < sm.getSelected().size(); i1++) { FxSelectListItem item = sm.getSelected().get(i1); if (i1 > 0) { if (batchContentDataChanges()) ps.addBatch(); else ps.executeUpdate(); } ps.setLong(pos[0], item.getId()); ps.setString(pos[1], sm.getSelectedIdsList()); ps.setLong(pos[2], sm.getSelectedIds().size()); } if (sm.getSelected().size() == 0) ps.setLong(pos[0], 0); //write the virtual item as a marker to have a valid row break; case Reference: //reference integrity check is done prior to saving ps.setLong(pos[0], ((FxPK) translatedValue).getId()); break; case InlineReference: default: throw new FxDbException(LOG, "ex.db.notImplemented.store", prop.getDataType().getName()); } int valueDataPos = insert ? getValueDataInsertPos(prop.getDataType()) : getValueDataUpdatePos(prop.getDataType()); if (value.hasValueData(translatedLanguage)) { ps.setInt(valueDataPos, value.getValueDataRaw(translatedLanguage)); } else ps.setNull(valueDataPos, Types.NUMERIC); if (batchContentDataChanges()) ps.addBatch(); else { try { ps.executeUpdate(); } catch (SQLException e) { LOG.error(prop.getName(), e); throw e; } } } } else { switch (prop.getDataType()) { //TODO: implement datatype specific insert default: throw new FxDbException(LOG, "ex.db.notImplemented.store", prop.getDataType().getName()); } } if (ft != null && prop.isFulltextIndexed() && includeFullText) ft.index(data); }
From source file:gov.llnl.lustre.lwatch.PlotFrame2.java
/** * Update the control widgets to reflect the current time settings. *///from w w w . java 2s .co m public void updateControlValues() { int tindx = ovIDX / nCurvesSelected; int[] daysInMonth = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; //long xstart = rawTimes[tindx][startIndex]; //long xstop = rawTimes[tindx][stopIndex]; /*** if (localDebug) { Debug.out("\nxstart before = " + (new Date(xstart)).toString() + " stopIndex = " + startIndex); Debug.out("xstop before = " + (new Date(xstop)).toString() + " stopIndex = " + stopIndex); } if (xstop < (3600000*48)) { // Invalid time value while ((stopIndex > 0) && ((rawTimes[ovIDX][stopIndex]) < (3600000*48))) { if (localDebug) Debug.out(stopIndex + " " + xstop); xstop = rawTimes[tindx][--stopIndex]; } } ***/ if (limitedDebug) { Debug.out("dataPointCount[0] = " + dataPointCount[0]); Debug.out("tsStartPlot after = " + tsStartPlot); Debug.out("tsEndPlot after = " + tsEndPlot + "\n"); } Date dstart = new Date(tsStartPlot.getTime()); //xstart); Date dstop = new Date(tsEndPlot.getTime()); //xstop); GregorianCalendar cal = new GregorianCalendar(); if (localDebug) Debug.out("dstart = " + dstart.toString() + "\ndstop = " + dstop.toString()); // Set the Start widgets. cal.setTime(dstart); int yrstart = cal.get(Calendar.YEAR); yrChooser.setSelectedYear(yrstart); int mnthstart = cal.get(Calendar.MONTH); monthChooser.setSelectedMonth(mnthstart); int daystart = cal.get(Calendar.DAY_OF_MONTH); dayChooser.setSelectedDay(daystart); int hrstart = cal.get(Calendar.HOUR_OF_DAY); hourChooser.setSelectedHour(hrstart); int minstart = cal.get(Calendar.MINUTE); minuteChooser.setSelectedMinute(minstart); // Set the End widgets. cal.setTime(dstop); int yrstop = cal.get(Calendar.YEAR); yrEndChooser.setSelectedYear(yrstop); int mnthstop = cal.get(Calendar.MONTH); monthEndChooser.setSelectedMonth(mnthstop); int daystop = cal.get(Calendar.DAY_OF_MONTH); dayEndChooser.setSelectedDay(daystop); int hrstop = cal.get(Calendar.HOUR_OF_DAY); hourEndChooser.setSelectedHour(hrstop); int minstop = cal.get(Calendar.MINUTE); minuteEndChooser.setSelectedMinute(minstop); // Set the Duration widgets. long durationhours = (tsEndPlot.getTime() - tsStartPlot.getTime()) / HOUR; //Debug.out("Length of chart plot interval = " + durationhours + " hours"); int yrDur = yrstop - yrstart; //Debug.out("yrDur = " + yrDur); int mnthDur = mnthstop - mnthstart; //Debug.out("mnthDur = " + mnthDur); if (mnthDur < 0) { yrDur = Math.max(0, yrDur - 1); mnthDur = 12 - mnthstart + mnthstop; //Debug.out("Adjusted mnthDur = " + mnthDur); } int dayDur = daystop - daystart; //Debug.out("dayDur = " + dayDur); if (dayDur < 0) { mnthDur = Math.max(0, mnthDur - 1); dayDur = daysInMonth[mnthstart] - daystart + daystop; //Debug.out("Adjusted dayDur = " + dayDur); } int hrDur = hrstop - hrstart; //Debug.out("hrDur = " + hrDur); if (hrDur < 0) { dayDur = Math.max(0, dayDur - 1); hrDur = 24 - hrstart + hrstop; //Debug.out("Adjusted hrDur = " + hrDur); } int minDur = minstop - minstart; //Debug.out("minDur = " + minDur + "\n"); if (minDur < 0) { hrDur = Math.max(0, hrDur - 1); minDur = 60 - minstart + minstop; //Debug.out("Adjusted minDur = " + minDur + "\n"); } yrDurChooser.setSelected(yrDur); monthDurChooser.setSelected(mnthDur); dayDurChooser.setSelected(dayDur); hourDurChooser.setSelected(hrDur); minuteDurChooser.setSelected(minDur); }
From source file:com.lp.server.fertigung.ejbfac.FertigungFacBean.java
@TransactionAttribute(TransactionAttributeType.NEVER) public KapazitaetsvorschauDto getKapazitaetsvorschau(TheClientDto theClientDto) throws EJBExceptionLP { KapazitaetsvorschauDto kapDto = null; Session session = null;/* w w w .j a va 2s . co m*/ try { // ------------------------------------------------------------------ // ----- // Benoetigte Parameter holen // ------------------------------------------------------------------ // ----- // Default Sicht nach Wochen // final int iSicht = FertigungFac.KAPAZITAETSVORSCHAU_NACH_WOCHEN; // Anzahl der angezeigten Vatergruppen. Alles andere wird nach // "Sonstige" verdichtet final ParametermandantDto parameterAnzahlGruppen = getParameterFac().getMandantparameter( theClientDto.getMandant(), ParameterFac.KATEGORIE_FERTIGUNG, ParameterFac.PARAMETER_FERTIGUNG_KAPAZITAETSVORSCHAU_ANZAHL_GRUPPEN); final int iParamAnzahlGruppen = (Integer) parameterAnzahlGruppen.getCWertAsObject(); // Angezeigter Zeitraum = Anzahl der Spalten final ParametermandantDto parameterZeitraum = getParameterFac().getMandantparameter( theClientDto.getMandant(), ParameterFac.KATEGORIE_FERTIGUNG, ParameterFac.PARAMETER_FERTIGUNG_KAPAZITAETSVORSCHAU_ZEITRAUM); final int iParamZeitraum = (Integer) parameterZeitraum.getCWertAsObject(); // ------------------------------------------------------------------ // ----- // Hibernate-Session erstellen // ------------------------------------------------------------------ // ----- SessionFactory factory = FLRSessionFactory.getFactory(); session = factory.openSession(); // ------------------------------------------------------------------ // ----- // Artikel- / Maschinen-Vatergruppen holen // ------------------------------------------------------------------ // ----- // Alle Artikel-Vatergruppen Criteria cArtikelVatergruppen = session.createCriteria(FLRArtikelgruppe.class); cArtikelVatergruppen.add(Restrictions.isNull(ArtikelFac.FLR_ARTIKELGRUPPE_FLRARTIKELGRUPPE)); List<?> listArtikelgruppen = cArtikelVatergruppen.list(); // Alle Maschinen-Vatergruppen Criteria cMaschinengruppen = session.createCriteria(FLRMaschinengruppe.class); List<?> listMaschinengruppen = cMaschinengruppen.list(); // ------------------------------------------------------------------ // ----- // Anzahl der sub-Diagramme bestimmen // das ist grundsaetzlich (iParamAnzahlGruppen + 1) x 2 ... // (Anzahl d. anzuzeigenden Vatergruppen + Sonstige) f. AZ und // Maschinen // wenn es weniger Vatergruppen als anzuzeigende gibt, reduziert // sich das aber // Gibt es keine Vatergruppe, wird daher alles nach "Sonstige" // verdichtet // ------------------------------------------------------------------ // ----- final int iAnzuzeigendeArtikelgruppen = Math.min(iParamAnzahlGruppen, listArtikelgruppen.size()); final int iAnzuzeigendeMaschinengruppen = Math.min(iParamAnzahlGruppen, listMaschinengruppen.size()); final int iAnzahlZeilen = iAnzuzeigendeArtikelgruppen + 1 + iAnzuzeigendeMaschinengruppen + 1; // ------------------------------------------------------------------ // ----- // Dto initialisieren // ------------------------------------------------------------------ // ----- kapDto = new KapazitaetsvorschauDto(iAnzahlZeilen, iParamZeitraum); // ------------------------------------------------------------------ // ----- // Beschriftung der x-Achse ermitteln. das sind die Kalenderwochen // ------------------------------------------------------------------ // ----- HashMap<Integer, Integer> hmKWIndizes = new HashMap<Integer, Integer>(); String[] kw = new String[iParamZeitraum]; GregorianCalendar gc = new GregorianCalendar(); for (int i = 0; i < kw.length; i++) { int iKw = gc.get(GregorianCalendar.WEEK_OF_YEAR); kw[i] = "" + iKw; kapDto.setISpaltenueberschrift(i, kw[i]); hmKWIndizes.put(gc.get(GregorianCalendar.WEEK_OF_YEAR), i); gc.setTimeInMillis(gc.getTimeInMillis() + 7 * 24 * 60 * 60 * 1000); // 1 Woche dazu } // ------------------------------------------------------------------ // ----- // Beschriftung der y-Achse ermitteln. das sind die Namen der // Vatergruppen bzw. 2 x "Sonstige". // Weiters werden die Indizes im Daten-Array fuer die jeweiligen // Gruppen festgelegt. // ------------------------------------------------------------------ // ----- String sSonstige = getTextRespectUISpr("lp.sonstige", theClientDto.getMandant(), theClientDto.getLocUi()); HashMap<Integer, Integer> hmArtikelGruppenIndizes = new HashMap<Integer, Integer>(); HashMap<Integer, Integer> hmMaschinenGruppenIndizes = new HashMap<Integer, Integer>(); // zuerst die Artikelvatergruppen for (int i = 0; i < iAnzuzeigendeArtikelgruppen; i++) { FLRArtikelgruppe item = (FLRArtikelgruppe) listArtikelgruppen.get(i); kapDto.setIZeilenueberschrift(i, item.getC_nr()); hmArtikelGruppenIndizes.put(item.getI_id(), i); } // Dann Sonstige Artikelgruppen final int indexSonstigeArtikelGruppen = iAnzuzeigendeArtikelgruppen; kapDto.setIZeilenueberschrift(indexSonstigeArtikelGruppen, sSonstige); // Maschinengruppen for (int i = 0; i < iAnzuzeigendeMaschinengruppen; i++) { FLRMaschinengruppe item = (FLRMaschinengruppe) listMaschinengruppen.get(i); int index = iAnzuzeigendeArtikelgruppen + 1 + i; kapDto.setIZeilenueberschrift(index, item.getC_bez()); hmMaschinenGruppenIndizes.put(item.getI_id(), index); } // zuletzt Sonstige Maschinengruppen final int indexSonstigeMaschinenGruppen = iAnzuzeigendeArtikelgruppen + 1 + iAnzuzeigendeMaschinengruppen; kapDto.setIZeilenueberschrift(indexSonstigeMaschinenGruppen, sSonstige); // ------------------------------------------------------------------ // ----- // Lose holen // ------------------------------------------------------------------ // ----- Criteria cLose = session.createCriteria(FLRLos.class); // Filter nach Mandant cLose.add(Restrictions.eq(FertigungFac.FLR_LOS_MANDANT_C_NR, theClientDto.getMandant())); // Alle Stati ausser Erledigt, Gestoppt, Storniert Collection<String> cLoseStati = new LinkedList<String>(); cLoseStati.add(FertigungFac.STATUS_ERLEDIGT); cLoseStati.add(FertigungFac.STATUS_GESTOPPT); cLoseStati.add(FertigungFac.STATUS_STORNIERT); cLose.add(Restrictions.not(Restrictions.in(FertigungFac.FLR_LOS_STATUS_C_NR, cLoseStati))); List<?> listLose = cLose.list(); // ------------------------------------------------------------------ // ----- // Auswertungszeitraum und verfuegbare Kapazitaeten ermitteln // ------------------------------------------------------------------ // ----- // 3 Monate in die zukunft Calendar c = Calendar.getInstance(); c.setTimeInMillis(System.currentTimeMillis()); c.set(Calendar.MONTH, c.get(Calendar.MONTH) + 3); java.util.Date dMax = Helper.cutDate(new java.sql.Date(c.getTimeInMillis())); java.sql.Timestamp tVon = Helper.cutTimestamp(new java.sql.Timestamp(System.currentTimeMillis())); java.sql.Timestamp tBis = Helper.cutTimestamp(new java.sql.Timestamp(dMax.getTime())); // Verfuegbare Zeiten holen SollverfuegbarkeitDto[] oVerfuegbar = getZeiterfassungFac().getVerfuegbareSollzeit(tVon, tBis, theClientDto); // diese nun aufteilen for (int i = 0; i < oVerfuegbar.length; i++) { SollverfuegbarkeitDto svDto = oVerfuegbar[i]; // "normale" AZ if (svDto.isBMannarbeitszeit()) { // die sind einer Artikelgruppe zugeordnet if (svDto.getIGruppeid() != null) { Integer iZeile = hmArtikelGruppenIndizes.get(svDto.getIGruppeid()); // ist das eine sichtbare Gruppe if (iZeile != null) { for (int iSpalte = 0; iSpalte < kapDto.getDetails()[iZeile].length; iSpalte++) { // mal 5 Tage kapDto.addBdVerfuegbareStunden(iZeile, iSpalte, svDto.getNSollstunden().multiply(new BigDecimal(5))); } } // wenn nicht, dann zu den sonstigen else { for (int iSpalte = 0; iSpalte < kapDto .getDetails()[indexSonstigeArtikelGruppen].length; iSpalte++) { // mal 5 Tage kapDto.addBdVerfuegbareStunden(indexSonstigeArtikelGruppen, iSpalte, svDto.getNSollstunden().multiply(new BigDecimal(5))); } } } // Rest = Sonstige Artikelgruppen else { if (svDto.getTDatum() != null) { // Die KW dieses Datums ermitteln, damit das // zugeordnet werden kann GregorianCalendar gcSV = new GregorianCalendar(); gcSV.setTime(svDto.getTDatum()); int kwSV = gcSV.get(Calendar.WEEK_OF_YEAR); Integer iIndexDerKW = hmKWIndizes.get(kwSV); if (iIndexDerKW != null) { // Hier nicht mit 5 multiplizieren, da es fuer // jeden Tag einen eigenen Eintrag gibt kapDto.addBdVerfuegbareStunden(indexSonstigeArtikelGruppen, iIndexDerKW, svDto.getNSollstunden()); } else { // diese KW wird nicht mehr angezeigt - brauch // ich nicht einrechnen } } } } // Maschinenzeit - die Verfuegbarkeit ist jeden Tag gleich else { Integer iZeile = hmMaschinenGruppenIndizes.get(svDto.getIGruppeid()); // ist das eine sichtbare Gruppe if (iZeile != null) { for (int iSpalte = 0; iSpalte < kapDto.getDetails()[iZeile].length; iSpalte++) { // mal 5 Tage kapDto.addBdVerfuegbareStunden(iZeile, iSpalte, svDto.getNSollstunden().multiply(new BigDecimal(5))); } } // wenn nicht, dann zu den sonstigen else { for (int iSpalte = 0; iSpalte < kapDto .getDetails()[indexSonstigeMaschinenGruppen].length; iSpalte++) { // mal 5 Tage kapDto.addBdVerfuegbareStunden(indexSonstigeMaschinenGruppen, iSpalte, svDto.getNSollstunden().multiply(new BigDecimal(5))); } } } } // ------------------------------------------------------------------ // ----- // Offene Zeiten ermitteln // ------------------------------------------------------------------ // ----- for (Iterator<?> iter = listLose.iterator(); iter.hasNext();) { FLRLos los = (FLRLos) iter.next(); // Offene Menge ermitteln BigDecimal bdOffen = los.getN_losgroesse(); for (Iterator<?> iterAblieferung = los.getAblieferungset().iterator(); iterAblieferung.hasNext();) { FLRLosablieferung item = (FLRLosablieferung) iterAblieferung.next(); bdOffen = bdOffen.subtract(item.getN_menge()); } // nur Lose mit tatsaechlich offener Menge>0 if (bdOffen.compareTo(new BigDecimal(0)) > 0) { // Faktor zur Berechnung der offenen Zeiten = offene Menge / // Losgroesse. 2 Nachkommastellen sollten reichen. BigDecimal bdFaktor = bdOffen.divide(los.getN_losgroesse(), 2, BigDecimal.ROUND_HALF_EVEN); // Arbeitsplan holen Criteria cLosAZ = session.createCriteria(FLRLossollarbeitsplan.class); cLosAZ.add(Restrictions.eq(FertigungFac.FLR_LOSSOLLARBEITSPLAN_LOS_I_ID, los.getI_id())); List<?> listLosAZ = cLosAZ.list(); // fuer alle Taetigkeiten for (Iterator<?> iterAZ = listLosAZ.iterator(); iterAZ.hasNext();) { FLRLossollarbeitsplan losAZ = (FLRLossollarbeitsplan) iterAZ.next(); BigDecimal bdOffeneStunden = losAZ.getN_gesamtzeit().multiply(bdFaktor); // ------------------------------------------------------ // ----------------- // Index der Gruppe bestimmen, der ich das zuordnen muss // ------------------------------------------------------ // ----------------- int iZeilenIndex; // 1. nach Maschinengruppe // 2. nach Artikelgruppe der Taetigkeit FLRMaschine flrMaschine = losAZ.getFlrmaschine(); Integer iMaschinengruppeIId = null; Integer iArtikelgruppeIId = null; if (flrMaschine != null) { FLRMaschinengruppe flrMaschinengruppe = flrMaschine.getFlrmaschinengruppe(); if (flrMaschinengruppe != null) { // Wenn diese Maschinengruppe dargestellt wird, // dann kommt hier der index raus. Integer i = hmMaschinenGruppenIndizes.get(flrMaschinengruppe.getI_id()); iMaschinengruppeIId = flrMaschinengruppe.getI_id(); if (i != null) { iZeilenIndex = i; } // wenn nicht -> sonstige. else { iZeilenIndex = indexSonstigeMaschinenGruppen; } } // Maschinen ohne Maschinengruppe werden nach // "Sonstige" verdichtet. else { iZeilenIndex = indexSonstigeMaschinenGruppen; } } else { FLRArtikel flrArtikel = losAZ.getFlrartikel(); FLRArtikelgruppe flrArtikelgruppe = flrArtikel.getFlrartikelgruppe(); if (flrArtikelgruppe != null) { // Wenn diese Artikelgruppe dargestellt wird, // dann kommt hier der index raus. Integer i = hmArtikelGruppenIndizes.get(flrArtikelgruppe.getI_id()); iArtikelgruppeIId = flrArtikelgruppe.getI_id(); if (i != null) { iZeilenIndex = i; } // wenn nicht -> sonstige. else { iZeilenIndex = indexSonstigeArtikelGruppen; } } // Taetigkeiten ohne Artikelgruppe werden nach // "Sonstige" verdichtet. else { iZeilenIndex = indexSonstigeArtikelGruppen; } } // ------------------------------------------------------ // ----------------- // Jetzt hab ich die Gruppe, der ich das zuordnen muss // nun muss die Zeit aufgeteilt werden // ------------------------------------------------------ // ----------------- java.util.Date tLosStarttermin = los.getT_produktionsbeginn(); java.util.Date tLosEndetermin = los.getT_produktionsende(); // beide Termine duerfen nicht vor heute liegen if (tLosStarttermin.before(getDate())) { tLosStarttermin = getDate(); } if (tLosEndetermin.before(getDate())) { tLosEndetermin = getDate(); } // Anzahl der betroffenen Kalenderwochen bestimmen GregorianCalendar gcStart = new GregorianCalendar(); gcStart.setTime(tLosStarttermin); GregorianCalendar gcEnde = new GregorianCalendar(); gcEnde.setTime(tLosEndetermin); int iStartKW = gcStart.get(Calendar.WEEK_OF_YEAR); int iEndeKW = gcEnde.get(Calendar.WEEK_OF_YEAR); int iAnzahlKW = 1 + iEndeKW - iStartKW; // nun auf die Wochen aufteilen BigDecimal bdOffeneStundenJeWoche = bdOffeneStunden; if (iAnzahlKW > 0) { bdOffeneStundenJeWoche = bdOffeneStunden.divide(new BigDecimal(iAnzahlKW), 2, RoundingMode.HALF_UP); } for (int iAktuelleKW = iStartKW; iAktuelleKW <= iEndeKW; iAktuelleKW++) { Integer indexDerKW = hmKWIndizes.get(iAktuelleKW); // wird diese Woche auch angezeigt? if (indexDerKW != null) { KapazitaetsvorschauDetailDto detailDto = new KapazitaetsvorschauDetailDto(); detailDto.setArtikelgruppeIId(iArtikelgruppeIId); detailDto.setArtikelIIdTaetigkeit(losAZ.getFlrartikel().getI_id()); detailDto.setBdDauer(bdOffeneStundenJeWoche); detailDto.setLosIId(los.getI_id()); detailDto.setLossollarbeitsplanIId(losAZ.getI_id()); detailDto.setMaschinengruppeIId(iMaschinengruppeIId); kapDto.addDetail(iZeilenIndex, indexDerKW, detailDto); } } } } } // ------------------------------------------------------------------ // ----- // Diagramm aus den Daten erstellen // ------------------------------------------------------------------ // ----- SymbolAxis xAchse = new SymbolAxis("KW", kw); CombinedDomainXYPlot plot = new CombinedDomainXYPlot(xAchse); for (int iZeile = 0; iZeile < kapDto.getDetails().length; iZeile++) { XYSeries datenZeile = new XYSeries(kapDto.getIZeilenueberschrift(iZeile)); // Balkenfarben festlegen ( >100% = rot, sonst hellgrau) // fuer jede zeile und jede spalte Paint[][] paints = new Paint[1][kapDto.getDetails()[iZeile].length]; for (int iSpalte = 0; iSpalte < kapDto.getDetails()[iZeile].length; iSpalte++) { BigDecimal bdVerfuegbar = kapDto.getBdVerfuegbareStunden()[iZeile][iSpalte]; BigDecimal bdBenoetigt = new BigDecimal(0); // Benoetigte Zeit jet Gruppe je Woche ermitteln for (Iterator<?> iter = kapDto.getDetails()[iZeile][iSpalte].iterator(); iter.hasNext();) { KapazitaetsvorschauDetailDto item = (KapazitaetsvorschauDetailDto) iter.next(); bdBenoetigt = bdBenoetigt.add(item.getBdDauer()); } BigDecimal value = new BigDecimal(0); if (bdVerfuegbar.compareTo(new BigDecimal(0)) > 0) { value = (bdBenoetigt.multiply(new BigDecimal(100))).divide(bdVerfuegbar, 4, BigDecimal.ROUND_HALF_EVEN); if (value.doubleValue() > 100.0) { paints[0][iSpalte] = Color.red; } else { paints[0][iSpalte] = Color.lightGray; } } // tage ohne Verfuegbarkeit mach ich 100% und weisz else { value = new BigDecimal(100.0); // Wochen ohne Kapazitaet aber mit geplanter Zeit if (bdBenoetigt.compareTo(new BigDecimal(0)) > 0) { paints[0][iSpalte] = Color.MAGENTA; } // Wenn nichts verfuegbar aber auch nichts benoetigt -> // weiss else { paints[0][iSpalte] = Color.white; } } XYDataItem data = new XYDataItem(iSpalte, value.doubleValue()); datenZeile.add(data); } // Zur Collection XYSeriesCollection xyDataset = new XYSeriesCollection(); xyDataset.addSeries(datenZeile); // subplot erstellen XYItemRenderer renderer1 = new CustomXYBarRenderer(paints); // renderer1.setItemLabelsVisible(true); // Legende nicht anzeigen renderer1.setBaseSeriesVisibleInLegend(false); NumberAxis zeilenAchse = new NumberAxis(kapDto.getIZeilenueberschrift(iZeile)); // Beschriftung der Y-Achse um 90 grad drehen zeilenAchse.setLabelAngle(Math.PI / 2.0); zeilenAchse.setAutoRange(true); XYPlot subplot1 = new XYPlot(xyDataset, null, zeilenAchse, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // Markierung bei 100% final Marker target = new ValueMarker(100.0); target.setPaint(Color.darkGray); // target.setLabel("100 %"); // Label // target.setLabelAnchor(RectangleAnchor.TOP_RIGHT); // target.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); subplot1.addRangeMarker(target); plot.add(subplot1); // plot.add(subplot1, 1); } JFreeChart lStackedBarChart = new JFreeChart(plot); kapDto.setJfcKapazitaetsvorschau(lStackedBarChart); } catch (RemoteException ex) { throwEJBExceptionLPRespectOld(ex); } finally { if (session != null) { session.close(); } } return kapDto; }
From source file:com.aimluck.eip.schedule.util.ScheduleUtils.java
public static boolean isDuplicateFacilitySchedule(EipTSchedule schedule, List<Integer> facilityIdList, Integer _old_scheduleid, Date _old_viewDate) { /* *///w w w . j a v a 2 s. c o m GregorianCalendar cald = new GregorianCalendar(); boolean result = false; { Date start_date; Date end_date; String repeat_pattern; String repeat_type; String repeat_week = null; boolean week_0; boolean week_1; boolean week_2; boolean week_3; boolean week_4; boolean week_5; boolean week_6; boolean day_of_week_in_month_1; boolean day_of_week_in_month_2; boolean day_of_week_in_month_3; boolean day_of_week_in_month_4; boolean day_of_week_in_month_5; boolean[] day_of_week_in_month_array = new boolean[5]; String limit_flag; int month_day = -1; int year_month = -1; int year_day = -1; Integer db_scheduleid = null; boolean[] week_array = new boolean[7]; boolean unlimited_repeat = false; try { start_date = schedule.getStartDate(); end_date = schedule.getEndDate(); repeat_pattern = schedule.getRepeatPattern(); repeat_type = repeat_pattern.substring(0, 1); day_of_week_in_month_1 = repeat_pattern.matches("W.......1.?"); day_of_week_in_month_2 = repeat_pattern.matches("W.......2.?"); day_of_week_in_month_3 = repeat_pattern.matches("W.......3.?"); day_of_week_in_month_4 = repeat_pattern.matches("W.......4.?"); day_of_week_in_month_5 = repeat_pattern.matches("W.......5.?"); if (repeat_type.equals("W")) { if (repeat_pattern.length() == 9) { repeat_week = "0"; day_of_week_in_month_1 = true; day_of_week_in_month_2 = true; day_of_week_in_month_3 = true; day_of_week_in_month_4 = true; day_of_week_in_month_5 = true; } else { repeat_week = repeat_pattern.substring(8, 9); } } limit_flag = repeat_pattern.substring(repeat_pattern.length() - 1); week_0 = repeat_pattern.matches("W1........?"); week_1 = repeat_pattern.matches("W.1.......?"); week_2 = repeat_pattern.matches("W..1......?"); week_3 = repeat_pattern.matches("W...1.....?"); week_4 = repeat_pattern.matches("W....1....?"); week_5 = repeat_pattern.matches("W.....1...?"); week_6 = repeat_pattern.matches("W......1..?"); if (repeat_pattern.startsWith("M")) { month_day = Integer.parseInt(repeat_pattern.substring(1, 3)); } if (repeat_pattern.startsWith("Y")) { year_month = Integer.parseInt(repeat_pattern.substring(1, 3)); year_day = Integer.parseInt(repeat_pattern.substring(3, 5)); } // ???1?????? if (repeat_pattern.startsWith("N")) { Calendar cal = Calendar.getInstance(); cal.setTime(start_date); int dow = cal.get(Calendar.DAY_OF_WEEK); week_0 = (dow == Calendar.SUNDAY); week_1 = (dow == Calendar.MONDAY); week_2 = (dow == Calendar.TUESDAY); week_3 = (dow == Calendar.WEDNESDAY); week_4 = (dow == Calendar.THURSDAY); week_5 = (dow == Calendar.FRIDAY); week_6 = (dow == Calendar.SATURDAY); month_day = cal.get(Calendar.DAY_OF_MONTH); int dowim = cal.get(Calendar.DAY_OF_WEEK_IN_MONTH); day_of_week_in_month_1 = (dowim == 1); day_of_week_in_month_2 = (dowim == 2); day_of_week_in_month_3 = (dowim == 3); day_of_week_in_month_4 = (dowim == 4); day_of_week_in_month_5 = (dowim == 5); year_month = cal.get(Calendar.MONTH) + 1; year_day = cal.get(Calendar.DAY_OF_MONTH); } else if (repeat_pattern.endsWith("N")) { unlimited_repeat = true; } week_array[0] = week_0; week_array[1] = week_1; week_array[2] = week_2; week_array[3] = week_3; week_array[4] = week_4; week_array[5] = week_5; week_array[6] = week_6; day_of_week_in_month_array[0] = day_of_week_in_month_1; day_of_week_in_month_array[1] = day_of_week_in_month_2; day_of_week_in_month_array[2] = day_of_week_in_month_3; day_of_week_in_month_array[3] = day_of_week_in_month_4; day_of_week_in_month_array[4] = day_of_week_in_month_5; } catch (RuntimeException e) { logger.error("schedule", e); return false; } catch (Exception e) { logger.error("schedule", e); return false; } if (repeat_type.equals("S")) { // ??0:00:00?????23:59:59?? Calendar cal = Calendar.getInstance(); cal.setTime(end_date); cal.add(Calendar.DATE, 1); cal.add(Calendar.MINUTE, -1); end_date = cal.getTime(); } // ??? if (facilityIdList.size() > 0) {// List<Integer> fids = facilityIdList; SelectQuery<EipTScheduleMap> fquery = Database.query(EipTScheduleMap.class); Expression fexp1 = ExpressionFactory.inExp(EipTScheduleMap.USER_ID_PROPERTY, fids); fquery.setQualifier(fexp1); Expression fexp2 = ExpressionFactory.matchExp(EipTScheduleMap.TYPE_PROPERTY, ScheduleUtils.SCHEDULEMAP_TYPE_FACILITY); fquery.andQualifier(fexp2); Expression oneexp = null;// 1 Expression spanexp = null;// Expression rdexp = null;// Expression rwexp = null;// Expression rwexp2 = null; // Expression rwlexp = null; Expression rmexp = null;// Expression ryexp = null; { // ? Expression exp100 = ExpressionFactory.matchExp( EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "N"); try { if (!unlimited_repeat) { Expression exp101 = ExpressionFactory.lessOrEqualExp( EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.START_DATE_PROPERTY, end_date);// EipTSchedule.START_DATE_PROPERTY <= end_date Expression exp102 = ExpressionFactory.greaterExp( EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.END_DATE_PROPERTY, start_date);// EipTSchedule.END_DATE_PROPERTY > start_date oneexp = exp100.andExp(exp101.andExp(exp102)); } else { oneexp = exp100; } } catch (Exception e) { } } { // ? Expression exp200 = ExpressionFactory.matchExp( EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "S"); try { if (!unlimited_repeat) { // ??00:00?????? Calendar cal_end = Calendar.getInstance(); cal_end.setTime(end_date); cal_end = DateUtils.truncate(cal_end, Calendar.DAY_OF_MONTH); Expression exp201 = ExpressionFactory.lessOrEqualExp( EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.START_DATE_PROPERTY, cal_end.getTime()); // EipTSchedule.START_DATE_PROPERTY <= end_date Calendar cal_start = Calendar.getInstance(); cal_start.setTime(start_date); cal_start = DateUtils.truncate(cal_start, Calendar.DAY_OF_MONTH); Expression exp202 = ExpressionFactory.greaterOrEqualExp( EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.END_DATE_PROPERTY, cal_start.getTime()); // EipTSchedule.END_DATE_PROPERTY >= start_date spanexp = exp200.andExp(exp201.andExp(exp202)); } else { spanexp = exp200; } } catch (Exception e) { } } { // ?? // char lim = 'N'; if ("ON".equals(limit_flag)) { // lim = 'L'; } { // "D".equals(repeat_type.getValue()) Expression dexp01 = ExpressionFactory.likeExp( EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "D_"); rdexp = dexp01; } { // "W".equals(repeat_type.getValue()) Expression wexp = null; List<Expression> wexps = new ArrayList<Expression>(); if (week_0 == true) { wexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W1_______"); wexps.add(wexp); } if (week_1 == true) { wexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_1______"); wexps.add(wexp); } if (week_2 == true) { wexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W__1_____"); wexps.add(wexp); } if (week_3 == true) { wexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W___1____"); wexps.add(wexp); } if (week_4 == true) { wexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W____1___"); wexps.add(wexp); } if (week_5 == true) { wexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_____1__"); wexps.add(wexp); } if (week_6 == true) { wexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W______1_"); wexps.add(wexp); } if (wexps.size() > 0) { rwexp = wexps.get(0); int wexpssize = wexps.size(); for (int k = 1; k < wexpssize; k++) { rwexp = rwexp.orExp(wexps.get(k)); } } else { rwexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W________"); } } { Expression wexp2 = null; List<Expression> wexps2 = new ArrayList<Expression>(); Expression wnexp = null; List<Expression> wnexp2 = new ArrayList<Expression>(); if (week_0 == true) { wexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W1________"); wexps2.add(wexp2); } if (week_1 == true) { wexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_1_______"); wexps2.add(wexp2); } if (week_2 == true) { wexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W__1______"); wexps2.add(wexp2); } if (week_3 == true) { wexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W___1_____"); wexps2.add(wexp2); } if (week_4 == true) { wexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W____1____"); wexps2.add(wexp2); } if (week_5 == true) { wexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_____1___"); wexps2.add(wexp2); } if (week_6 == true) { wexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W______1__"); wexps2.add(wexp2); } if (repeat_week != null && repeat_week.equals("1") || day_of_week_in_month_1) { wnexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_______1_"); wnexp2.add(wnexp); } if (repeat_week != null && repeat_week.equals("2") || day_of_week_in_month_2) { wnexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_______2_"); wnexp2.add(wnexp); } if (repeat_week != null && repeat_week.equals("3") || day_of_week_in_month_3) { wnexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_______3_"); wnexp2.add(wnexp); } if (repeat_week != null && repeat_week.equals("4") || day_of_week_in_month_4) { wnexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_______4_"); wnexp2.add(wnexp); } if (repeat_week != null && repeat_week.equals("5") || day_of_week_in_month_5) { wnexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_______5_"); wnexp2.add(wnexp); } if (wexps2.size() > 0 && wnexp2.size() > 0) { for (int k = 0; k < wexps2.size(); k++) { for (int l = 0; l < wnexp2.size(); l++) { if (k == 0 && l == 0) { rwexp2 = wexps2.get(k).andExp(wnexp2.get(l)); } else { rwexp2 = rwexp2.orExp(wexps2.get(k).andExp(wnexp2.get(l))); } } } } else { rwexp2 = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "W_________"); } } { // "M".equals(repeat_type.getValue()) if (month_day > 0) { // ???????? DecimalFormat exF = new DecimalFormat("00"); String md_str = exF.format(month_day); rmexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "M" + md_str + "_"); } else if (year_day > 0 && year_month > 0) { // ?? DecimalFormat exG = new DecimalFormat("00"); String yd_str = exG.format(year_day); rmexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "M" + yd_str + "_"); } else { rmexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "M___"); } } { // "Y".equals(repeat_type.getValue()) if (year_day > 0 && year_month > 0) { // ???????? DecimalFormat exG = new DecimalFormat("00"); String ym_str = exG.format(year_month); String yd_str = exG.format(year_day); ryexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "Y" + ym_str + yd_str + "_"); } else if (month_day > 0) { // ?? DecimalFormat exF = new DecimalFormat("00"); String md_str = exF.format(month_day); ryexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "Y__" + md_str + "_"); } else { ryexp = ExpressionFactory.likeExp(EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.REPEAT_PATTERN_PROPERTY, "Y_____"); } } Expression repeatexp = oneexp; if (rdexp != null) { repeatexp = repeatexp.orExp(rdexp); } if (rwexp != null) { repeatexp = repeatexp.orExp(rwexp); } if (rwexp2 != null) { repeatexp = repeatexp.orExp(rwexp2); } if (rmexp != null) { repeatexp = repeatexp.orExp(rmexp); } if (spanexp != null) { repeatexp = repeatexp.orExp(spanexp); } if (ryexp != null) { repeatexp = repeatexp.orExp(ryexp); } fquery.andQualifier(repeatexp); } db_scheduleid = schedule.getScheduleId(); if (db_scheduleid != null && db_scheduleid >= 0) { Expression exp00 = ExpressionFactory.noMatchDbExp( EipTScheduleMap.EIP_TSCHEDULE_PROPERTY + "." + EipTSchedule.SCHEDULE_ID_PK_COLUMN, db_scheduleid); fquery.andQualifier(exp00); } fquery.distinct(true); List<EipTScheduleMap> f_list = fquery.fetchList(); if (f_list != null && f_list.size() > 0) { // ????? boolean existFacility = false; int f_list_size = f_list.size(); for (int i = 0; i < f_list_size; i++) { EipTScheduleMap map = f_list.get(i); Date dbStartDate = map.getEipTSchedule().getStartDate(); Date dbEndDate = map.getEipTSchedule().getEndDate(); boolean containtsRs = false; // ?????? String ptn = map.getEipTSchedule().getRepeatPattern(); if (ptn.charAt(0) == 'S') { // try { // ??0:00:00?????23:59:59?? Calendar cal = Calendar.getInstance(); cal.setTime(dbEndDate); cal.add(Calendar.DATE, 1); cal.add(Calendar.MINUTE, -1); dbEndDate = cal.getTime(); if ((end_date.after(dbStartDate) && start_date.before(dbEndDate)) || unlimited_repeat) { containtsRs = true; } } catch (Exception e) { containtsRs = false; } } else if (ptn.charAt(0) == 'N') { // ? if ("D".equals(repeat_type) || "N".equals(repeat_type)) { // or // ? try { if ((dbStartDate.before(end_date) && dbEndDate.after(start_date)) || unlimited_repeat) { containtsRs = true; } } catch (Exception e) { containtsRs = false; } } else { if ((dbStartDate.before(end_date) && dbEndDate.after(start_date)) || unlimited_repeat) { containtsRs = true; } } } else if (ptn.charAt(0) == 'D') {// if (ptn.charAt(1) == 'L') { try { if ((dbStartDate.before(end_date) && dbEndDate.after(start_date)) || unlimited_repeat) { containtsRs = true; } } catch (Exception e) { containtsRs = false; } } else { containtsRs = true; } } else if (ptn.charAt(0) == 'W') { if (ptn.length() == 9) { if (ptn.charAt(8) == 'L') { try { if ((dbStartDate.before(end_date) && dbEndDate.after(start_date)) || unlimited_repeat) { containtsRs = true; } } catch (Exception e) { containtsRs = false; } } else { containtsRs = true; } } else if (ptn.length() == 10) { if (ptn.charAt(9) == 'L') { try { if ((dbStartDate.before(end_date) && dbEndDate.after(start_date)) || unlimited_repeat) { containtsRs = true; } } catch (Exception e) { containtsRs = false; } } else { containtsRs = true; } } } else if (ptn.charAt(0) == 'M') { if (ptn.charAt(3) == 'L') { try { if ((dbStartDate.before(end_date) && dbEndDate.after(start_date)) || unlimited_repeat) { containtsRs = true; } } catch (Exception e) { containtsRs = false; } } else { containtsRs = true; } } else if (ptn.charAt(0) == 'Y') { if (ptn.charAt(5) == 'L') { try { if ((dbStartDate.before(end_date) && dbEndDate.after(start_date)) || unlimited_repeat) { containtsRs = true; } } catch (Exception e) { containtsRs = false; } } else { containtsRs = true; } } else { containtsRs = true; } if (containtsRs) { /* ?????? */ int ss_flg = ScheduleUtils.compareTime(start_date, dbEndDate); int se_flg = ScheduleUtils.compareTime(end_date, dbStartDate); if (ss_flg > 0 && se_flg < 0) { /* ???????????? */ if (!"N".equals(ptn) && ptn.endsWith("N") && unlimited_repeat) {// ?(?????&&???)&&???? existFacility = true; } else { Date _start_date = null; Date _end_date = null; if (!"N".equals(ptn) && ptn.endsWith("N") && !unlimited_repeat) {// ?(??&&???)&&??? _start_date = (Date) start_date.clone(); _end_date = (Date) end_date.clone(); } else if (("N".equals(ptn) || !ptn.endsWith("N")) && unlimited_repeat) {// ?(?||??)&&???? _start_date = (Date) dbStartDate.clone(); _end_date = (Date) dbEndDate.clone(); } else if (("N".equals(ptn) || !ptn.endsWith("N")) && !unlimited_repeat) {// ?(?||??)&&??? if (dbStartDate.after(start_date)) { _start_date = (Date) dbStartDate.clone(); } else { _start_date = (Date) start_date.clone(); } if (dbEndDate.before(end_date)) { _end_date = (Date) dbEndDate.clone(); } else { _end_date = (Date) end_date.clone(); } } if ((_start_date == null) || (_end_date == null)) { continue; } /* ??? */ Expression dexp1 = ExpressionFactory.matchExp(EipTSchedule.NAME_PROPERTY, "dummy");// Expression dexp2 = ExpressionFactory.matchExp(EipTSchedule.PARENT_ID_PROPERTY, map.getScheduleId()); if (db_scheduleid != null) { Expression dexp21 = ExpressionFactory .matchExp(EipTSchedule.PARENT_ID_PROPERTY, db_scheduleid); dexp2 = dexp2.orExp(dexp21); } Expression dexp3 = null; cald.setTime(_start_date); cald.set(Calendar.MILLISECOND, 0); cald.set(Calendar.SECOND, 0); cald.set(Calendar.MINUTE, 0); cald.set(Calendar.HOUR_OF_DAY, 0); Date ddate = cald.getTime();// _start_date? List<EipTSchedule> temp = null; if ("N".equals(repeat_pattern)) { /* ?????????????? */ if ((_old_scheduleid != null) && (_old_viewDate != null)) { if ((_old_scheduleid.intValue() == map.getScheduleId().intValue()) && compareToDate(_start_date, _old_viewDate) == 0) { continue; } } try { dexp3 = ExpressionFactory.matchExp(EipTSchedule.START_DATE_PROPERTY, ddate); temp = Database .query(EipTSchedule.class, dexp1.andExp(dexp2).andExp(dexp3)) .fetchList(); if (temp == null || temp.size() <= 0) { existFacility = true; break; } } catch (Exception e) { logger.error("[DuplicateFacilityCheck]: ", e); existFacility = true; break; } } else if (repeat_pattern.startsWith("D")) { while (!ddate.after(_end_date)) { if (matchDay(cald, ptn)) { try { dexp3 = ExpressionFactory .matchExp(EipTSchedule.START_DATE_PROPERTY, ddate); temp = Database.query(EipTSchedule.class, dexp1.andExp(dexp2).andExp(dexp3)).fetchList(); if (temp == null || temp.size() <= 0) { existFacility = true; break; } } catch (Exception e) { logger.error("[DuplicateFacilityCheck]: ", e); existFacility = true; break; } } cald.add(Calendar.DATE, 1); ddate = cald.getTime(); } } else if (repeat_pattern.startsWith("S")) { while (!ddate.after(_end_date)) { try { dexp3 = ExpressionFactory.matchExp(EipTSchedule.START_DATE_PROPERTY, ddate); temp = Database.query(EipTSchedule.class, dexp1.andExp(dexp2).andExp(dexp3)).fetchList(); if (temp == null || temp.size() <= 0) { existFacility = true; break; } } catch (Exception e) { logger.error("[DuplicateFacilityCheck]: ", e); existFacility = true; break; } cald.add(Calendar.DATE, 1); ddate = cald.getTime(); } } else if (repeat_pattern.startsWith("W")) { /* ? */ int wlen = week_array.length; int wlen2 = day_of_week_in_month_array.length; if (wlen < 1 || wlen2 < 1) { continue; } int k; int l; while (!ddate.after(_end_date)) { k = (cald.get(Calendar.DAY_OF_WEEK) - 1) % wlen; l = (cald.get(Calendar.DAY_OF_WEEK_IN_MONTH) - 1) % wlen2; if ((week_array[k] == true) && (day_of_week_in_month_array[l] == true) && matchDay(cald, ptn)) { try { dexp3 = ExpressionFactory .matchExp(EipTSchedule.START_DATE_PROPERTY, ddate); temp = Database.query(EipTSchedule.class, dexp1.andExp(dexp2).andExp(dexp3)).fetchList();// SQL if (temp == null || temp.size() <= 0) { existFacility = true;// true???? break; } } catch (Exception e) { logger.error("[DuplicateFacilityCheck]: ", e); existFacility = true; break; } } cald.add(Calendar.DATE, 1); ddate = cald.getTime(); } } else if (repeat_pattern.startsWith("M")) { /* ?? */ cald.setTime(dbStartDate); cald.set(Calendar.MILLISECOND, 0); cald.set(Calendar.SECOND, 0); cald.set(Calendar.MINUTE, 0); cald.set(Calendar.HOUR_OF_DAY, 0); if (month_day > 0) { cald.set(Calendar.DAY_OF_MONTH, month_day); } else { continue; } Date tmp_date = cald.getTime(); while (tmp_date.before(ddate)) { cald.add(Calendar.MONTH, 1); /* ???????????????? */ while (month_day > cald.getActualMaximum(Calendar.DAY_OF_MONTH)) { cald.add(Calendar.MONTH, 1); cald.set(Calendar.DAY_OF_MONTH, month_day); if (tmp_date.before(tmp_date)) { break; } } tmp_date = cald.getTime(); } ddate = tmp_date; /* */ while (!ddate.after(_end_date)) { if (matchDay(cald, ptn)) { try { dexp3 = ExpressionFactory .matchExp(EipTSchedule.START_DATE_PROPERTY, ddate); temp = Database.query(EipTSchedule.class, dexp1.andExp(dexp2).andExp(dexp3)).fetchList(); if (temp == null || temp.size() <= 0) { existFacility = true; break; } } catch (Exception e) { logger.error("[DuplicateFacilityCheck]: ", e); existFacility = true; break; } } cald.add(Calendar.MONTH, 1); /* ???????????????? */ while (month_day > cald.getActualMaximum(Calendar.DAY_OF_MONTH)) { cald.add(Calendar.MONTH, 1); cald.set(Calendar.DAY_OF_MONTH, month_day); if (!ddate.after(_end_date)) { break; } } ddate = cald.getTime(); } } else if (repeat_pattern.startsWith("Y")) { /* ?? */ cald.setTime(dbStartDate); cald.set(Calendar.MILLISECOND, 0); cald.set(Calendar.SECOND, 0); cald.set(Calendar.MINUTE, 0); cald.set(Calendar.HOUR_OF_DAY, 0); if (year_month > 0 && year_day > 0) { cald.set(Calendar.MONTH, year_month - 1); cald.set(Calendar.DAY_OF_MONTH, year_day); } else { continue; } Date tmp_date = cald.getTime(); while (tmp_date.before(ddate)) { cald.add(Calendar.MONTH, 1); /* ???????????????? */ while (year_day > cald.getActualMaximum(Calendar.DAY_OF_MONTH)) { cald.add(Calendar.MONTH, 1); cald.set(Calendar.DAY_OF_MONTH, year_day); if (tmp_date.before(tmp_date)) { break; } } tmp_date = cald.getTime(); } ddate = tmp_date; /* */ while (!ddate.after(_end_date)) { if (matchDay(cald, ptn)) { try { dexp3 = ExpressionFactory .matchExp(EipTSchedule.START_DATE_PROPERTY, ddate); temp = Database.query(EipTSchedule.class, dexp1.andExp(dexp2).andExp(dexp3)).fetchList(); if (temp == null || temp.size() <= 0) { existFacility = true; break; } } catch (Exception e) { logger.error("[DuplicateFacilityCheck]: ", e); existFacility = true; break; } } cald.add(Calendar.MONTH, 1); /* ???????????????? */ while (year_day > cald.getActualMaximum(Calendar.DAY_OF_MONTH)) { cald.add(Calendar.MONTH, 1); cald.set(Calendar.DAY_OF_MONTH, year_day); if (!ddate.after(_end_date)) { break; } } ddate = cald.getTime(); } } else { continue; } } } } if (existFacility) { break; } } if (existFacility) { return existFacility; } } } } return result; }