Newer
Older
irisDatabase / src / com / casic / birmm / UpdatePersonIdCard.java
TAN YUE on 9 Oct 2020 6 KB 20201008 初始建立
package com.casic.birmm;

import com.casic.birmm.util.ConnectionManager;
import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ArrayListHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author TAN YUE
 * 更新院本部人员身份证号
 */
public class UpdatePersonIdCard {
    public Map<String, Long> deptMap = new HashMap<>();
    public static void main(String[] args) {
        Connection conn = null;
        UpdatePersonIdCard upi = new UpdatePersonIdCard();
        upi.initDept();

        String queryStr = "select p.id, name, fullname, id_card_no from sys_person p, sys_dept d where p.DEPTID = d.id";
        try {
            conn = ConnectionManager.getMySQLConnectionFromC3P0();
            conn.setAutoCommit(false);

            QueryRunner runner = new QueryRunner();
            List<Object[]> personList = runner.query(conn, queryStr, new ArrayListHandler());

            // 正确更新列表
            List<String> correctList = new ArrayList<>();

            // 没有照片列表
            List<String> noPhotoList = new ArrayList<>();

            // 重名列表
            List<String> renameList = new ArrayList<>();

            for (int i = 0; i < personList.size(); i++) {
                Long personId = (Long) personList.get(i)[0];
                String name = (String) personList.get(i)[1];
                String deptname = (String) personList.get(i)[2];
                String id_card_no = (String) personList.get(i)[3];

                String queryIdStr = "select name, comp, dept, idcard from sys_person_idcard where name = ?";
                Object[] param = new Object[1];
                param[0] = name;
                List<Object[]> idList = runner.query(conn, queryIdStr, new ArrayListHandler(), param);

                if (null == idList || idList.size() == 0) {
                    noPhotoList.add(name);
                } else if (idList.size() == 1) {
                    // 部门
                    String comp = (String) idList.get(0)[1];
                    // 身份证号
                    String idcard = (String) idList.get(0)[3];

                    // 更新员工编号
                    String updateStr = "update sys_person set deptid = ?, id_card_no = ? where id = ?";
                    Object[] uParams = new Object[3];
                    uParams[0] = upi.deptMap.get(comp);
                    uParams[1] = idcard;
                    uParams[2] = personId;
                    runner.update(conn, updateStr, uParams);

                    correctList.add(name);
                } else {
                    renameList.add(name);
                }
            }

            System.out.println("正常更新:" + correctList.size());
            for(int i = 0; i < correctList.size(); i++) {
                System.out.println(correctList.get(i));
            }

            System.out.println("没有找到:" + noPhotoList.size());
            for(int i = 0; i < noPhotoList.size(); i++) {
                System.out.println(noPhotoList.get(i));
            }

            System.out.println("重名:" + renameList.size());
            for(int i = 0; i < renameList.size(); i++) {
                System.out.println(renameList.get(i));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            try {
                DbUtils.commitAndClose(conn);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public void initDept() {
        deptMap.put("部办公室", 1273594159444766722L);
        deptMap.put("党委办公室", 1273594221398831106L);
        deptMap.put("二部领导", 1273596061125423106L);
        deptMap.put("发展计划处", 1273596168180838401L);
        deptMap.put("科技委", 1273596218474737666L);
        deptMap.put("质量技术处", 1273596278751080450L);
        deptMap.put("科研处", 1273596324095700993L);
        deptMap.put("生产处", 1273596364189052930L);
        deptMap.put("技安处", 1273596404676669441L);
        deptMap.put("产业发展处", 1273596444228956162L);
        deptMap.put("人力资源处", 1273596496372543490L);
        deptMap.put("财务处", 1273596539259301889L);
        deptMap.put("保密处", 1273596591742627841L);
        deptMap.put("行政处", 1273596632884555778L);
        deptMap.put("保卫处", 1273596673338617858L);
        deptMap.put("纪检审计风险处", 1273596714157584386L);
        deptMap.put("工会办公室", 1273596757409247233L);
        deptMap.put("离退休办公室", 1273596802867113986L);
        deptMap.put("801办公室", 1273596848991875074L);
        deptMap.put("805、810办公室", 1273596892813963266L);
        deptMap.put("军贸代表室", 1273596937978228738L);
        deptMap.put("精导/军仿专业组秘书", 1273596977723453441L);
        deptMap.put("一室", 1273597017661616129L);
        deptMap.put("二室", 1273597057184542722L);
        deptMap.put("三室", 1273597093884702721L);
        deptMap.put("四室", 1273597136117149697L);
        deptMap.put("五室", 1273597179431727105L);
        deptMap.put("六室", 1273597226969968642L);
        deptMap.put("七室", 1273597266669056002L);
        deptMap.put("八室", 1273597305634140161L);
        deptMap.put("九室", 1273597344792162306L);
        deptMap.put("十室", 1273597398907072513L);
        deptMap.put("十一室", 1273597442120986625L);
        deptMap.put("十三室", 1273597482361139201L);
        deptMap.put("十五室", 1273597527693176834L);
        deptMap.put("十六室", 1273597565945229314L);
        deptMap.put("技术保障中心", 1273597608643244033L);
        deptMap.put("档案情报资料室", 1273597649445433346L);
        deptMap.put("售后服务保障事业部", 1273597687651348481L);
        deptMap.put("空间工程技术研究室", 1273597726213779457L);
        deptMap.put("仿真公司", 1273597790575374338L);
        deptMap.put("仿真", 1273597790575374338L);
        deptMap.put("其他", 1273597832560357377L);
    }
}