Package clips.directory.editors.update.updaters.dlo

Source Code of clips.directory.editors.update.updaters.dlo.UpdaterDloCollaborators

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package clips.directory.editors.update.updaters.dlo;

import cli_fmw.delegate.directory.UpdaterDirectory;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.delegate.utils.TimeLocal;
import cli_fmw.main.ClipsException;
import clips.delegate.client.CollaboratorLocal;
import clips.delegate.config.ConfigLocal;
import clips.delegate.directory.ro.DirectoryCollaborator;
import clips.delegate.directory.ro.DirectoryCollaboratorItem;
import clips.login.UserInfo;
import clips.main.ClipsConfig;
import framework.utils.Comparator;
import framework.utils.ROList;
import java.io.File;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import org.xBaseJ.micro.DBF;
import org.xBaseJ.micro.fields.DateField;
import org.xBaseJ.micro.fields.Field;
import org.xBaseJ.micro.xBaseJException;

/**
*
* @author lacoste
*/
public class UpdaterDloCollaborators extends UpdaterDirectory {

    private DirectoryCollaborator dir;
    private Date nullDate;
    private HashMap<String, DirectoryCollaboratorItem> collMap;
    private String lpuCode;
    private String lpuOGRN;

    private enum Col {
        TF_OKATO,
        MCOD,
        PCOD,
        FAM_V,
        IM_V,
        OT_V,
        C_OGRN,
        PRVD,
        D_JOB,
        D_PRIK,
        D_SER,
        PRVS,
        KV_KAT,
        DATE_B,
        DATE_E,
        MSG_TEXT
  }

    @Override
    public String getFilename() {
        return "WR_DLO.DBF";
    }

    @Override
    public String getTitle() {
        return "Сотрудники, включенные в систему ДЛО";
    }

    @Override
    protected void updateImpl() throws ClipsException {
        dir = DirectoryLocator.getDirectory(DirectoryCollaborator.class, true);
        Calendar cal = new GregorianCalendar(9999, 99, 99);
        nullDate = cal.getTime();

        ConfigLocal conf = ConfigLocal.getInstance();
        lpuCode = UserInfo.get().getCollaborator().getLpu().getLpuCode();
        lpuOGRN = UserInfo.get().getCollaborator().getLpu().getOgrn();

        collMap = new HashMap<String, DirectoryCollaboratorItem>();
        ROList<DirectoryCollaboratorItem> list = dir.getItemsList();
        for (DirectoryCollaboratorItem item : list) {
            String code = lpuOGRN + " " + item.getCode();
            collMap.put(code, item);
        }

        ClipsConfig cfg = ClipsConfig.getInstance();

        File file = new File(cfg.getLastDBFImportPath(), getFilename());
        DBF dbf = createDBF(file);
        HashMap<Col, Field> fields = new HashMap<Col, Field>();
        try {
            for (int i = 0; i < Col.values().length; i++) {
                Col col = Col.values()[i];
                fields.put(col, dbf.getField(col.toString()));
            }
        } catch (xBaseJException ex) {
            throw new ClipsException("Ошибка при чтении данных из файла " + dbf.getName(), ex);
        }

        int recordCount = dbf.getRecordCount();

        for (int i = 0; i < recordCount; i++) {
            try {
                dbf.read();
                String ogrn = fields.get(Col.C_OGRN).get().trim();
                String tfLpuCode = fields.get(Col.MCOD).get().trim();
                if (ogrn.equals(lpuOGRN) && tfLpuCode.equals(lpuCode)) {
                    String collCode = fields.get(Col.PCOD).get().trim();
                    DirectoryCollaboratorItem coll = collMap.get(collCode);
                    if (coll != null) {
                        CollaboratorLocal collab = new CollaboratorLocal(coll.getID(), null);//NULL AL
                        Date begin;
                        String begStr = fields.get(Col.DATE_B).get().trim();
                        if (begStr.isEmpty()) {
                            begin = null;
                        }
                        else {
                            begin = ((DateField)fields.get(Col.DATE_B)).getCalendar().getTime();
                        }
                        Date end;
                        String endStr = fields.get(Col.DATE_E).get().trim();
                        if (endStr.isEmpty()) {
                            end = null;
                        }
                        else {
                            end = ((DateField)fields.get(Col.DATE_E)).getCalendar().getTime();
                        }
                        Date cur = TimeLocal.getCurrentTime().getTime();
                        if ((begin != null && begin.before(cur))
                                && (end != null && end.after(cur) || end == null || Comparator.dataEqual(end, nullDate))) {
                            collab.setDlo(true);
                            collab.save1();
                        }
                        else {
                            if (collab.isDlo()) {
                                collab.setDlo(false);
                                collab.save1();
                            }
                        }
                       
                    }
                }
            } catch (IOException ex) {
                closeDBF(dbf);
                throw new ClipsException("Ошибка при чтении данных из файла " + dbf.getName() + " (строка " + i + ")", ex);
            } catch (xBaseJException ex) {
                closeDBF(dbf);
                throw new ClipsException("Ошибка при чтении данных из файла " + dbf.getName() + " (строка " + i + ")", ex);
            }
        }
    }

}
TOP

Related Classes of clips.directory.editors.update.updaters.dlo.UpdaterDloCollaborators

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.