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"))
|
);
|
}
|
|
}
|
|
}
|