cy
2022-06-21 129904537f66509f97b285e7eb4f42b3dc349dd0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package cn.ksource.test.test;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
import org.apache.commons.lang.StringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
import cn.ksource.core.dao.BaseDao;
import cn.ksource.core.dao.SqlParameter;
import cn.ksource.core.test.TestUtil;
import cn.ksource.core.util.ConvertUtil;
import cn.ksource.core.util.StringUtil;
import cn.ksource.core.web.PasswordEncoder;
 
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/applicationContext_core.xml")
public class InsertCompany {
 
    
    /**
     * 获取随机数
     * @param max
     * @return
     * @version V1.0.0
     * @author 杨凯
     * @date Jun 8, 2014 4:33:44 PM
     */
    private int getRandom(int max){
        for (int i = 0; i < 1000; i++) {
            double random = Math.random();
            int num = ConvertUtil.obj2Int(String.valueOf(random * max));
            if (num < max && num > 0) {
                return num;
            }
        }
        return 0;
    }
    
    
    @Autowired
    private BaseDao baseDao;
    
    @Test
    public void insertCompany(){
        List<Map> list = baseDao.queryForList("select * from COMPANY_CATEGORY where STATE=1");
        
        List<Map> arealist = baseDao.queryForList("select * from GG_CONFIG_AREA where STATE=1");
        
        String sql = "insert into COMPANY_INFO(ID,LOGINNAME,PWD,COMPANY_NAME,CATEGORY_ID,CATEGORY_NAME,ADDRESS,TELPHONE,PERSON_NAME," +
                "PERSMON_MOBILE,EMAIL,STATE,BEIZ,TYPE,AREA_ID,AREA_NAME) " +
                "VALUES(:ID,:LOGINNAME,:PWD,:COMPANY_NAME,:CATEGORY_ID,:CATEGORY_NAME,:ADDRESS,:TELPHONE,:PERSON_NAME,:PERSMON_MOBILE,:EMAIL,:STATE,:BEIZ,:TYPE,:AREA_ID,:AREA_NAME)";
        List<SqlParameter> paramList = new ArrayList<SqlParameter>();
        for (int i = 0; i < 300; i++) {
            String companyName = TestUtil.getRandomChineseCharacters(6, 26);
            Map area = arealist.get(getRandom(arealist.size()));
            Map category = list.get(getRandom(list.size()));
            paramList.add(new SqlParameter("ID",StringUtil.getUUID())
            .addValue("LOGINNAME",companyName)
            .addValue("PWD", PasswordEncoder.encode("88888888"))
            .addValue("COMPANY_NAME", companyName)
            .addValue("CATEGORY_ID", category.get("ID"))
            .addValue("CATEGORY_NAME", category.get("CATEGORY_NAME"))
            );
        }
        
    }
    
}