Search in sources :

Example 1 with NCDivision

use of jp.co.nexus.crm.db.NCDivision in project CRMWebApp by jshioya0506.

the class DBDataSetExecutor method createDivisionMap.

private static Map<Integer, NCDivision> createDivisionMap(ObjectContext context, Map<Integer, Area> areaMap, Map<Integer, Employee> employeeMap) throws IOException {
    File csvFile = new File(CSV_DIR, DBConstants.NC_DIVISION + ".csv");
    if (!csvFile.exists()) {
        throw new FileNotFoundException("CSVファイルが存在しません。[" + csvFile.getName() + "]");
    }
    // CSVからサンプルデータを読み込み
    LOGGER.info("部署テーブルのcsvファイルからサンプルデータをロード開始。");
    CSVFileReader reader = new CSVFileReader();
    List<Map<String, Object>> dataMaps = reader.readData(csvFile);
    LOGGER.info("dataMaps=" + dataMaps);
    // テーブルオブジェクトにデータを設定し、テーブルにデータを登録
    LOGGER.info("サンプルデータを部署テーブルのモデルに設定。");
    int id = 1;
    Map<Integer, NCDivision> divisionMap = new HashMap<Integer, NCDivision>();
    for (Map<String, Object> dataMap : dataMaps) {
        // データ登録対象のテーブルオブジェクトを取得
        NCDivision dataObj = context.newObject(NCDivision.class);
        // テーブルオブジェクトにデータを設定
        for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
            if ("area".equals(entry.getKey())) {
                Integer areaCd = (Integer) entry.getValue();
                Area area = areaMap.get(areaCd);
                dataObj.setArea(area);
                area.getDivisions().add(dataObj);
            } else if ("employee".equals(entry.getKey())) {
                Integer empNo = (Integer) entry.getValue();
                Employee employee = employeeMap.get(empNo);
                dataObj.setEmployee(employee);
                employee.getDivisions().add(dataObj);
            } else {
                dataObj.writeProperty(entry.getKey(), entry.getValue());
            }
        }
        divisionMap.put(Integer.valueOf(id), dataObj);
    }
    return divisionMap;
}
Also used : NCDivision(jp.co.nexus.crm.db.NCDivision) HashMap(java.util.HashMap) FileNotFoundException(java.io.FileNotFoundException) Area(jp.co.nexus.crm.db.Area) Employee(jp.co.nexus.crm.db.Employee) CayenneDataObject(org.apache.cayenne.CayenneDataObject) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with NCDivision

use of jp.co.nexus.crm.db.NCDivision in project CRMWebApp by jshioya0506.

the class CustomersFacade method doAction.

/**
 * 顧客の一覧情報を取得してモデルに設定
 * @param model SpringFrameworkのモデルクラス
 * @return 正常に処理できた場合はtrue
 */
public boolean doAction(Model model) {
    // DBの設定情報を取得
    ServerRuntime cayenneRuntime = new ServerRuntime("cayenne-NexusCRM.xml");
    ObjectContext context = cayenneRuntime.getContext();
    // 顧客情報Beanのインスタンスを生成
    CustomerListBean bean = new CustomerListBean();
    // ************************************
    // 1.職員テーブルの検索条件を設定
    // ************************************
    // 検索条件1:失効日=0
    SelectQuery empQuery = new SelectQuery(Employee.class);
    Expression empExpr = ExpressionFactory.matchExp(Employee.LOST_YMD_PROPERTY, Integer.valueOf(0));
    empQuery.setQualifier(empExpr);
    // ************************************
    // 2.職員テーブルを検索
    // ************************************
    // 検索結果を担当者のコンボボックスに設定
    List<Employee> employees = (List<Employee>) context.performQuery(empQuery);
    for (Employee employee : employees) {
        // 社員番号=社員名
        bean.getEmployees().put(String.valueOf(employee.getEmpNo()), employee.getName());
    }
    // ************************************
    // 3.顧客管理テーブルの検索条件を設定
    // ************************************
    // 検索条件1:失効日=0
    SelectQuery customerQuery = new SelectQuery(NCCustomer.class);
    Expression exprExpireDate = ExpressionFactory.matchExp(NCCustomer.LOST_YMD_PROPERTY, Integer.valueOf(0));
    customerQuery.setQualifier(exprExpireDate);
    // ************************************
    // 4.顧客管理テーブルを検索
    // ************************************
    List<NCCustomer> customers = (List<NCCustomer>) context.performQuery(customerQuery);
    // 検索結果を社名のコンボボックスに設定
    if (customers != null && !customers.isEmpty()) {
        for (NCCustomer customer : customers) {
            // 顧客コード
            Integer customerCode = getCustomerCode(customer);
            // 会社名
            String companyName = customer.getName();
            // 検索結果を社名のコンボボックスに設定
            bean.getCompanies().put(String.valueOf(customerCode), companyName);
        }
    }
    // 検索結果を顧客情報のモデルに設定
    for (NCCustomer customer : customers) {
        CustomerInfoBean infoBean = new CustomerInfoBean();
        // エリア情報
        Area area = customer.getArea();
        // 営業担当情報
        Employee employee = customer.getEmployee();
        // 顧客コード
        Integer customerCode = getCustomerCode(customer);
        //  担当者情報から顧客情報を作成して、一覧情報として追加する
        List<NCPerson> persons = getPersons(context, customerCode);
        for (NCPerson person : persons) {
            // 顧客番号[エリアコード+顧客コード]
            String customerNo = DataFormatUtil.formatCustomerNumber(area.getAreaCd(), customerCode);
            infoBean.setCustomerNo(customerNo);
            // 担当営業
            infoBean.setStaffName(employee.getName());
            // ランク
            String rank = getRank(customer);
            infoBean.setRank(rank);
            // 社名
            infoBean.setCompanyName(customer.getName());
            // 住所
            infoBean.setPostAddress(customer.getAddress());
            // 担当者
            infoBean.setPersonnelName(person.getName());
            // 部署名
            NCDivision division = getDivision(context, customerCode, person.getDivisioncd());
            infoBean.setDepartmentName(division.getName());
            // TODO 役職(テーブルのカラムがないので表示保留)
            infoBean.setPositionName("");
            // 前回訪問日
            NCCalldoc calldoc = getLastVisitInfo(context, customerCode, person.getDivisioncd());
            String lastVisitDate = DataFormatUtil.formatDate(String.valueOf(calldoc.getCallYmd()));
            infoBean.setLastVisitDate(lastVisitDate);
            // 
            // TODO 関係性(テーブルのカラムがないので表示保留)
            infoBean.setRelationship("");
            // 顧客の一覧情報として追加
            bean.getCustomers().add(infoBean);
        }
    }
    // 顧客の一覧情報をモデルへ設定
    model.addAttribute("bean", bean);
    return !customers.isEmpty();
}
Also used : CustomerInfoBean(jp.co.nexus.crm.bean.CustomerInfoBean) NCDivision(jp.co.nexus.crm.db.NCDivision) ServerRuntime(org.apache.cayenne.configuration.server.ServerRuntime) NCPerson(jp.co.nexus.crm.db.NCPerson) SelectQuery(org.apache.cayenne.query.SelectQuery) NCCalldoc(jp.co.nexus.crm.db.NCCalldoc) Area(jp.co.nexus.crm.db.Area) Employee(jp.co.nexus.crm.db.Employee) Expression(org.apache.cayenne.exp.Expression) NCCustomer(jp.co.nexus.crm.db.NCCustomer) CustomerListBean(jp.co.nexus.crm.bean.CustomerListBean) List(java.util.List) ObjectContext(org.apache.cayenne.ObjectContext)

Example 3 with NCDivision

use of jp.co.nexus.crm.db.NCDivision in project CRMWebApp by jshioya0506.

the class CustomersFacade method getDivision.

private NCDivision getDivision(ObjectContext context, int customerCd, int divisionCode) {
    SelectQuery divisionQuery = new SelectQuery(NCDivision.class);
    Expression conditionExpr = ExpressionFactory.matchExp(NCPerson.LOST_YMD_PROPERTY, Integer.valueOf(0));
    conditionExpr = conditionExpr.andExp(ExpressionFactory.matchExp(NCDivision.CUSTOMERCD_PROPERTY, Integer.valueOf(customerCd)));
    divisionQuery.setQualifier(conditionExpr);
    List<NCDivision> divisions = (List<NCDivision>) context.performQuery(divisionQuery);
    // }
    return divisions.get(0);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) NCDivision(jp.co.nexus.crm.db.NCDivision) Expression(org.apache.cayenne.exp.Expression) List(java.util.List)

Example 4 with NCDivision

use of jp.co.nexus.crm.db.NCDivision in project CRMWebApp by jshioya0506.

the class DBDataSetExecutor method main.

public static void main(String[] args) {
    try {
        // DBの設定情報を取得
        ServerRuntime cayenneRuntime = new ServerRuntime("cayenne-NexusCRM.xml");
        ObjectContext context = cayenneRuntime.getContext();
        // エリアテーブル
        Map<Integer, Area> areaMap = createAreaMap(context);
        // 職員テーブル
        Map<Integer, Employee> employeeMap = createEmployeeMap(context, areaMap);
        // 顧客管理テーブル
        Map<Integer, NCCustomer> customerMap = createCustomerMap(context, areaMap, employeeMap);
        // 担当テーブル
        Map<Integer, NCPerson> personMap = createPersonMap(context, areaMap, employeeMap);
        // 部署テーブル
        Map<Integer, NCDivision> divisionMap = createDivisionMap(context, areaMap, employeeMap);
        // 訪問記録テーブル
        Map<Integer, NCCalldoc> callDocMap = createCallDocMap(context, areaMap, employeeMap);
        // 各テーブルにデータ登録
        context.commitChanges();
    } catch (IOException e) {
        LOGGER.error("エラーが発生しました。[" + e.getMessage() + "]");
        e.printStackTrace();
    }
}
Also used : NCDivision(jp.co.nexus.crm.db.NCDivision) ServerRuntime(org.apache.cayenne.configuration.server.ServerRuntime) IOException(java.io.IOException) NCPerson(jp.co.nexus.crm.db.NCPerson) NCCalldoc(jp.co.nexus.crm.db.NCCalldoc) Area(jp.co.nexus.crm.db.Area) Employee(jp.co.nexus.crm.db.Employee) NCCustomer(jp.co.nexus.crm.db.NCCustomer) ObjectContext(org.apache.cayenne.ObjectContext)

Aggregations

NCDivision (jp.co.nexus.crm.db.NCDivision)4 Area (jp.co.nexus.crm.db.Area)3 Employee (jp.co.nexus.crm.db.Employee)3 List (java.util.List)2 NCCalldoc (jp.co.nexus.crm.db.NCCalldoc)2 NCCustomer (jp.co.nexus.crm.db.NCCustomer)2 NCPerson (jp.co.nexus.crm.db.NCPerson)2 ObjectContext (org.apache.cayenne.ObjectContext)2 ServerRuntime (org.apache.cayenne.configuration.server.ServerRuntime)2 Expression (org.apache.cayenne.exp.Expression)2 SelectQuery (org.apache.cayenne.query.SelectQuery)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CustomerInfoBean (jp.co.nexus.crm.bean.CustomerInfoBean)1 CustomerListBean (jp.co.nexus.crm.bean.CustomerListBean)1 CayenneDataObject (org.apache.cayenne.CayenneDataObject)1