项目初始化

This commit is contained in:
2026-03-19 10:57:24 +08:00
commit ee94d420ad
3822 changed files with 582614 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
/**
* Copyright (c) 2013-Now https://jeesite.com All rights reserved.
* No deletion without permission, or be held responsible to law.
*/
package com.jeesite.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.test.context.ActiveProfiles;
/**
* JeeSite Web
* @author ThinkGem
* @version 2018-1-8
*/
@ActiveProfiles("test")
@SpringBootApplication
public class ApplicationTest {
public static void main(String[] args) {
SpringApplication.run(ApplicationTest.class, args);
}
}

View File

@@ -0,0 +1,534 @@
/**
* Copyright (c) 2013-Now https://jeesite.com All rights reserved.
* No deletion without permission, or be held responsible to law.
*/
package com.jeesite.test;
import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.collect.SetUtils;
import com.jeesite.common.entity.DataScope;
import com.jeesite.common.entity.Page;
import com.jeesite.common.idgen.IdGen;
import com.jeesite.common.lang.DateUtils;
import com.jeesite.common.lang.StringUtils;
import com.jeesite.common.mybatis.mapper.SqlMap;
import com.jeesite.common.mybatis.mapper.query.QueryType;
import com.jeesite.common.tests.BaseSpringContextTests;
import com.jeesite.modules.file.dao.FileUploadDao;
import com.jeesite.modules.file.entity.FileUpload;
import com.jeesite.modules.sys.dao.*;
import com.jeesite.modules.sys.entity.*;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import java.util.Date;
import java.util.List;
/**
* Mapper测试
* @author ThinkGem
* @version 2018-08-11
*/
@ActiveProfiles("test")
@SpringBootTest(classes = ApplicationTest.class)
public class DaoMapperTest extends BaseSpringContextTests {
private PostDao postDao;
private UserDao userDao;
private AreaDao areaDao;
private CompanyDao companyDao;
private FileUploadDao fileUploadDao;
private EmpUserDao empUserDao;
@Autowired
public void setDaoMapperTest(PostDao postDao, UserDao userDao, AreaDao areaDao, CompanyDao companyDao,
FileUploadDao fileUploadDao, EmpUserDao empUserDao) {
this.postDao = postDao;
this.userDao = userDao;
this.areaDao = areaDao;
this.companyDao = companyDao;
this.fileUploadDao = fileUploadDao;
this.empUserDao = empUserDao;
}
@Test
public void testTableAnnotation() throws Exception {
try{
System.out.println("============ 插入测试 ============");
Post post1 = new Post();
post1.setId("1");
post1.setPostName("test");
post1.setPostType("1");
post1.setPostSort(1);
long postInsertNum = postDao.insert(post1);
Assert.assertEquals("postDao.insert", 1, postInsertNum);
Assert.assertEquals("postDao.insert result", "1", postDao.get(post1).getId());
System.out.println("============ 批量插入测试 ============");
Post post2 = (Post)post1.clone();
post2.setId("2");
post2.setPostName("test2");
Post post3 = (Post)post1.clone();
post3.setId("3");
post3.setPostName("test3");
long postInsertBatchNum = postDao.insertBatch(ListUtils.newArrayList(post2, post3));
Assert.assertEquals("postDao.insertBatch", 2, postInsertBatchNum);
Assert.assertEquals("postDao.insertBatch result", "2", postDao.get(post2).getId());
Assert.assertEquals("postDao.insertBatch result", "3", postDao.get(post3).getId());
System.out.println("============ 按主键更新测试 ============");
Post post4 = new Post("2");
post4.setPostName("test4");
long postUpdateNum = postDao.update(post4);
Assert.assertEquals("postDao.update", 1, postUpdateNum);
Assert.assertEquals("postDao.update result", "test4", postDao.get(post2).getPostName());
System.out.println("============ 按主键删除测试 ============");
long postDeleteNum = postDao.phyDelete(post4);
Assert.assertEquals("postDao.delete", 1, postDeleteNum);
Assert.assertNull("postDao.delete result", postDao.get(post4));
System.out.println("============ 按树表更新测试 ============");
Area area = new Area();
area.setAreaCode("1");
area.setAreaName("你好");
area.setParentCode("0");
area.setParentCodes("0,");
area.setTreeSort(1);
area.setTreeSorts("1,");
area.setTreeLevel(0);
area.setTreeLeaf("1");
area.setTreeNames(area.getAreaName());
area.setStatus("0");
Area area2 = (Area) area.clone();
area2.setAreaCode("2");
Area area3 = (Area) area.clone();
area3.setAreaCode("3");
Area area4 = (Area) area.clone();
area4.setAreaCode("4");
Area area5 = (Area) area.clone();
area5.setAreaCode("5");
long areaInsertNum = areaDao.insertBatch(ListUtils.newArrayList(area, area2, area3, area4, area5));
Assert.assertEquals("areaDao.insert", 5, areaInsertNum);
Assert.assertEquals("areaDao.insertBatch result", "12345", areaDao
.get(area).getAreaCode()+areaDao.get(area2).getAreaCode()+areaDao.get(area3).getAreaCode()
+areaDao.get(area4).getAreaCode()+areaDao.get(area5).getAreaCode());
area.setAreaName("你好2");
long areaUpdateNum = areaDao.update(area);
Assert.assertEquals("areaDao.update", 1, areaUpdateNum);
Assert.assertEquals("areaDao.update result", "你好2", areaDao.get(area).getAreaName());
System.out.println("============ 按树表批量更新测试 ============");
long areaUpdateBatchNum = areaDao.updateBatch(ListUtils.newArrayList(area2, area3));
Assert.assertEquals("areaDao.updateBatch", 2, areaUpdateBatchNum);
Assert.assertEquals("areaDao.updateBatch result", "23",
areaDao.get(area2).getAreaCode()+areaDao.get(area3).getAreaCode());
System.out.println("============ 自定义更新条件测试 ============");
Area where = new Area();
where.setId_in(new String[]{area.getId(), area2.getId()});
where.setAreaName(area.getAreaName());
where.setStatus(area.getStatus());
area.setAreaName("你好3");
long areaUpdateByEntityNum = areaDao.updateByEntity(area, where);
Assert.assertEquals("areaDao.updateByEntity", 1, areaUpdateByEntityNum);
Assert.assertEquals("areaDao.updateByEntity result", "你好3", areaDao.get(area).getAreaName());
System.out.println("============ 更新数据状态测试 ============");
long areaStatusNum = areaDao.updateStatus(area);
Assert.assertEquals("areaDao.updateStatus", 1, areaStatusNum);
where.setAreaName(area.getAreaName());
long areaStatusByEntityNum = areaDao.updateStatusByEntity(area, where);
Assert.assertEquals("areaDao.updateStatusByEntity", 1, areaStatusByEntityNum);
System.out.println("============ 逻辑删除测试 ============");
long areaDeleteNum = areaDao.delete(area);
Assert.assertEquals("areaDao.delete", 1, areaDeleteNum);
where.setId(area2.getId());
where.setId_in(new String[]{area2.getId()});
where.setAreaName(area2.getAreaName());
where.setStatus(area2.getStatus());
long areaDeleteByEntityNum = areaDao.deleteByEntity(where);
Assert.assertEquals("areaDao.deleteByEntity", 1, areaDeleteByEntityNum);
System.out.println("============ 物理删除测试 ============");
long areaPhyDeleteNum = areaDao.phyDelete(area3);
Assert.assertEquals("areaDao.phyDelete", 1, areaPhyDeleteNum);
long areaPhyDeleteByEntityNum = areaDao.phyDeleteByEntity(area4);
Assert.assertEquals("areaDao.phyDeleteByEntity", 1, areaPhyDeleteByEntityNum);
System.out.println("============ 基本查询测试 ============");
List<Area> areaList = areaDao.findList(area5);
Assert.assertEquals("areaDao.findList", 1, areaList.size());
User user = new User();
user.setUserType(User.USER_TYPE_EMPLOYEE);
List<User> userList = userDao.findList(user);
Assert.assertFalse("userDao.findList", userList.isEmpty());
System.out.println("============ 条件嵌套日期范围自定义sqlMap测试 ============");
Company company = new Company("1");
company.setCompanyName("a");
company.setCreateDate_gte(new Date());
company.setCreateDate_lte(new Date());
company.setUpdateDate_between("2025-09-11 ~ 2025-09-12");
company.setArea(areaList.get(0));
company.getArea().setCreateDate_gte(company.getCreateDate_gte());
company.getArea().setCreateDate_lte(company.getCreateDate_gte());
company.setFullName(IdGen.nextId());
company.setViewCode("1");
company.setParentCode("0");
company.setParentCodes("0,");
company.setTreeSort(1);
company.setTreeSorts("1,");
company.setTreeLevel(0);
company.setTreeLeaf("1");
company.setTreeNames(company.getCompanyName());
Company company2 = (Company) company.clone();
company2.setParentCode(company.getCompanyCode());
company2.setParentCodes("0,1," + company.getCompanyCode());
company2.setCompanyCode("12");
Company company3 = (Company) company.clone();
company3.setParentCode(company.getCompanyCode());
company3.setParentCodes("0,1," + company.getCompanyCode());
company3.setCompanyCode("13");
company3.setCompanyName("b");
long companyInsertNum = companyDao.insertBatch(ListUtils.newArrayList(company, company2, company3));
Assert.assertEquals("advanced query init", 3, companyInsertNum);
Company companyWhere = (Company) company.clone();
companyWhere.setCompanyCode(null);
companyWhere.setParentCode(null);
long companyFindCount = companyDao.findCount(companyWhere);
Assert.assertEquals("advanced query list", 2, companyFindCount);
System.out.println("============ 分页测试,查询子节点 ============");
Company company4 = new Company("1");
company4.setFullName(company.getFullName());
company4.setPage(new Page<>(1, 2));
company4.setIsQueryChildren(true);
List<Company> companyListPage = companyDao.findList(company4);
Assert.assertEquals("find page list size", 2, companyListPage.size());
Assert.assertEquals("find page list get(1)", companyListPage.get(1).getCompanyCode(), company2.getCompanyCode());
Assert.assertEquals("find page count", 3, company4.getPage().getCount());
System.out.println("============ 扩展条件语句前带AND容错测试 ============");
Company company5 = new Company();
company5.sqlMap().getWhere().disableAutoAddStatusWhere();
company5.sqlMap().getDataScope().addFilter("dsf",
"Company", "a.`company_code`", DataScope.CTRL_PERMI_HAVE);
// 随意给权限过滤 sqlWhere 增加 and or 的容错结果相同key进行addFilter使用or不同使用and
company5.sqlMap().getDataScope().addFilter("dsf", "a.area_code = '123'");
company5.sqlMap().getDataScope().addFilter("dsf2", "and a.area_code = '456'");
company5.sqlMap().getDataScope().addFilter("dsf3", "or a.area_code = '789'");
List<Company> companyList = companyDao.findList(company5);
Assert.assertEquals("companyDao.findList extWhere", 0, companyList.size());
System.out.println("============ 联合查询未设定columns和attrName为this时测试 ============");
FileUpload fileUpload = new FileUpload();
fileUpload.sqlMap().getWhere().and("u.`user_code`", QueryType.EQ, "system123456");
List<FileUpload> fileUploadList = fileUploadDao.findList(fileUpload);
System.out.println(fileUploadList);
Assert.assertEquals("fileUploadDao.findList attrName this", 0, fileUploadList.size());
System.out.println("============ 树结构基本查询测试 ============");
Area area6 = new Area();
area6.setParentCodes("0,370000,%");
List<Area> area6List = areaDao.findByParentCodesLike(area6);
System.out.println(area6List);
Assert.assertFalse("areaDao.findByParentCodesLike", area6List.isEmpty());
Area area7 = new Area();
area7.setParentCodes_rightLike("0,370000,");
List<Area> area7List2 = areaDao.findList(area7);
System.out.println(area7List2);
Assert.assertEquals("areaDao.findByParentCodesRightLike", area6List.size(), area7List2.size());
System.out.println("============ 分页情况下foreach测试 ============");
EmpUser empUser = new EmpUser();
empUser.setCodes(new String[]{"SDJN01","SDJN02"});
empUser.setPage(new Page<>(1, 3));
empUser.sqlMap().getColumn().addExtSql("num", "COUNT(1) as num");
empUser.sqlMap().getGroup().setGroupBy("a.emp_id, a.emp_code");
List<EmpUser> empUserList = empUserDao.findUserListByOfficeCodes(empUser);
System.out.println(empUserList);
Assert.assertFalse("empUserDao.findUserListByOfficeCodes", empUserList.isEmpty());
System.out.println("============ 分组查询 5.14.0 ============");
Post postGroup = new Post();
SqlMap sqlMap = postGroup.sqlMap();
sqlMap.getColumn()
.setExcludeAttrNames(SetUtils.newHashSet("*"))
.addExtSql("column", "a.post_type, COUNT(a.post_type) AS typeNum");
sqlMap.getGroup().setGroupBy("a.post_type").setHaving("COUNT(a.post_type) > 0");
sqlMap.getOrder().setOrderBy(StringUtils.EMPTY);
List<Post> postGroupList = postDao.findList(postGroup);
System.out.println(postGroupList);
Assert.assertFalse("postDao.findList", postGroupList.isEmpty());
System.out.println("\n===========================================\n");
main(null);
}catch(Exception e){
e.printStackTrace();
throw new Exception(e);
}
}
public static void main(String[] args) {
String a, b;
System.out.println("============ 查询测试 ============");
a = new Post("1").sqlMap()
.getWhere().and("name", QueryType.EQ, "abc").toSql();
b = "a.`status` != #{STATUS_DELETE} AND a.`post_code` = #{sqlMap.where#post_code#EQ1}" +
" AND a.name = #{sqlMap.where.name#EQ1.val}";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
a = new Post("1").sqlMap().getWhere()
.and("name", QueryType.IN, new String[]{"1", "2", "3"}).toSql();
b = "a.`status` != #{STATUS_DELETE} AND a.`post_code` = #{sqlMap.where#post_code#EQ1}" +
" AND a.name IN ( #{sqlMap.where.name#IN1.val[0]}, #{sqlMap.where.name#IN1.val[1]}," +
" #{sqlMap.where.name#IN1.val[2]} )";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
a = new Post("1").sqlMap().getWhere()
.or("name", QueryType.IN, new String[]{"1", "2", "3"}).toSql();
b = "a.`status` != #{STATUS_DELETE} AND a.`post_code` = #{sqlMap.where#post_code#EQ1}" +
" OR a.name IN ( #{sqlMap.where.name#IN1.val[0]}, #{sqlMap.where.name#IN1.val[1]}," +
" #{sqlMap.where.name#IN1.val[2]} )";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
System.out.println("============ 重复赋值测试 ============");
a = new Post("1").sqlMap().getWhere()
.and("name", QueryType.LIKE, "abc")
.and("name", QueryType.LIKE, "def").toSql();
b = "a.`status` != #{STATUS_DELETE} AND a.`post_code` = #{sqlMap.where#post_code#EQ1}" +
" AND a.name LIKE #{sqlMap.where.name#LIKE1.val}";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
System.out.println("============ IN、NOT IN 测试 ============");
a = new Post("1").sqlMap().getWhere()
.and("name", QueryType.IN, new String[]{"abc","def"})
.and("name2", QueryType.NOT_IN, ListUtils.newArrayList("abc","def")).toSql();
b = "a.`status` != #{STATUS_DELETE} AND a.`post_code` = #{sqlMap.where#post_code#EQ1}" +
" AND a.name IN ( #{sqlMap.where.name#IN1.val[0]}, #{sqlMap.where.name#IN1.val[1]} )" +
" AND a.name2 NOT IN ( #{sqlMap.where.name2#NOT_IN1.val[0]}, #{sqlMap.where.name2#NOT_IN1.val[1]} )";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
a = new Post("1").sqlMap().getWhere()
.and("name", QueryType.IN, null)
.and("name2", QueryType.IN, new String[]{})
.and("name3", QueryType.NOT_IN, ListUtils.newArrayList()).toSql();
b = "a.`status` != #{STATUS_DELETE} AND a.`post_code` = #{sqlMap.where#post_code#EQ1}";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
System.out.println("============ BETWEEN、NOT BETWEEN 测试 ============");
Date[] ds = DateUtils.parseDateBetweenString("2025-09-11 ~ 2025-09-12");
a = new Post("1").sqlMap().getWhere()
.and("create_date", QueryType.BETWEEN, ds)
.and("update_date", QueryType.NOT_BETWEEN, ds).toSql();
b = "a.`status` != #{STATUS_DELETE} AND a.`post_code` = #{sqlMap.where#post_code#EQ1}" +
" AND a.create_date BETWEEN #{sqlMap.where.create_date#BETWEEN1.val[0]}" +
" AND #{sqlMap.where.create_date#BETWEEN1.val[1]}" +
" AND a.update_date NOT BETWEEN #{sqlMap.where.update_date#NOT_BETWEEN1.val[0]}" +
" AND #{sqlMap.where.update_date#NOT_BETWEEN1.val[1]}";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
System.out.println("============ 带括号测试 ============");
a = new Post("1").sqlMap().getWhere()
.andBracket("name", QueryType.EQ, "abc", 1)
.or("name", QueryType.EQ, "def", 2)
.or("name", QueryType.EQ, "ghi", 3).endBracket().toSql();
b = "a.`status` != #{STATUS_DELETE} AND a.`post_code` = #{sqlMap.where#post_code#EQ1}" +
" AND ( a.name = #{sqlMap.where.name#EQ1.val} OR a.name = #{sqlMap.where.name#EQ2.val}" +
" OR a.name = #{sqlMap.where.name#EQ3.val} )";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
a = new Post().sqlMap().getWhere()
.andBracket("name", QueryType.EQ, "val1", 1)
.and("name", QueryType.NE, "val2", 11).endBracket(1)
.orBracket("name", QueryType.NE, "val3", 2)
.and("name", QueryType.NE, "val4", 22).endBracket(2)
.orBracket("name", QueryType.NE, "val5", 3)
.and("name", QueryType.EQ, "val6", 33).endBracket(3)
.toSql();
b = "a.`status` != #{STATUS_DELETE}" +
" AND ( a.name = #{sqlMap.where.name#EQ1.val} AND a.name != #{sqlMap.where.name#NE11.val} )" +
" OR ( a.name != #{sqlMap.where.name#NE2.val} AND a.name != #{sqlMap.where.name#NE22.val} )" +
" OR ( a.name != #{sqlMap.where.name#NE3.val} AND a.name = #{sqlMap.where.name#EQ33.val} )";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
System.out.println("============ 带括号部分空值测试 ============");
a = new Post("1").sqlMap().getWhere()
.andBracket("name", QueryType.EQ, "", 1)
.or("name", QueryType.EQ, "def", 2)
.or("name", QueryType.EQ, "", 3).endBracket().toSql();
b = "a.`status` != #{STATUS_DELETE} AND a.`post_code` = #{sqlMap.where#post_code#EQ1}" +
" AND ( a.name = #{sqlMap.where.name#EQ2.val} )";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
a = new Post("1").sqlMap().getWhere()
.andBracket("name", QueryType.EQ, "abc", 1)
.or("name", QueryType.EQ, "def", 2)
.or("name", QueryType.EQ, "", 3).endBracket().toSql();
b = "a.`status` != #{STATUS_DELETE} AND a.`post_code` = #{sqlMap.where#post_code#EQ1}" +
" AND ( a.name = #{sqlMap.where.name#EQ1.val} OR a.name = #{sqlMap.where.name#EQ2.val} )";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
a = new Post("1").sqlMap().getWhere()
.andBracket("name", QueryType.EQ, "", 1)
.or("name", QueryType.EQ, "def", 2)
.or("name", QueryType.EQ, "ghi", 3).endBracket().toSql();
b = "a.`status` != #{STATUS_DELETE} AND a.`post_code` = #{sqlMap.where#post_code#EQ1}" +
" AND ( a.name = #{sqlMap.where.name#EQ2.val} OR a.name = #{sqlMap.where.name#EQ3.val} )";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
System.out.println("============ 带括号全部空值测试 ============");
a = new Post("1").sqlMap().getWhere()
.andBracket("name", QueryType.EQ, "", 1)
.or("name", QueryType.EQ, "", 2)
.or("name", QueryType.EQ, "", 3).endBracket().toSql();
b = "a.`status` != #{STATUS_DELETE} AND a.`post_code` = #{sqlMap.where#post_code#EQ1} ";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
a = new Post().sqlMap().getWhere()
.andBracket("name", QueryType.EQ, "", 1)
.or("name", QueryType.EQ, "", 2)
.or("name", QueryType.EQ, "", 3).endBracket().toSql();
b = "a.`status` != #{STATUS_DELETE} ";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
System.out.println("============ 实体嵌套测试 ============");
Company company = new Company("1");
company.setCreateDate_gte(new Date());
company.setCreateDate_lte(new Date());
company.setArea(new Area("2"));
company.getArea().setAreaName("a");
company.getArea().setCreateDate_gte(new Date());
company.getArea().setCreateDate_lte(new Date());
company.sqlMap().getWhere().disableAutoAddStatusWhere();
a = company.sqlMap().getWhere().toSql();
b = "a.`company_code` = #{sqlMap.where#company_code#EQ1}"
+ " AND a.`area_code` = #{sqlMap.where#area_code#EQ1}"
+ " AND a.create_date >= #{sqlMap.where.create_date#GTE1.val}"
+ " AND a.create_date <= #{sqlMap.where.create_date#LTE1.val}"
+ " AND b.`area_code` = #{area.sqlMap.where#area_code#EQ1}"
+ " AND b.create_date >= #{area.sqlMap.where.create_date#GTE1.val}"
+ " AND b.create_date <= #{area.sqlMap.where.create_date#LTE1.val}";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
System.out.println("============ 联合查询,属性名支持指定别名 ============");
a = new FileUpload().sqlMap().getWhere().and("u.`user_name`", QueryType.EQ, "user1").toSql();
b = "a.`status` != #{STATUS_DELETE} AND u.`user_name` = #{sqlMap.where.u#_user_name_#EQ1.val}";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
System.out.println("============ 联合查询,返回到当前实体测试 ============");
FileUpload fileUpload = new FileUpload();
fileUpload.sqlMap().getWhere().and("create_by", QueryType.IN, new String[]{"user1","user2"});
a = fileUpload.sqlMap().getWhere().toSql();
b = "a.`status` != #{STATUS_DELETE} AND a.create_by IN ( #{sqlMap.where.create_by#IN1.val[0]},"
+ " #{sqlMap.where.create_by#IN1.val[1]} )";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
System.out.println("============ 联合查询属性为this时也可作为查询条件 ============");
FileUpload fileUpload2 = new FileUpload();
fileUpload2.setCreateByName("ThinkGem/JeeSite");
fileUpload2.sqlMap().getWhere().and("create_by", QueryType.IN, new String[]{"user1","user2"});
a = fileUpload2.sqlMap().getWhere().toSql();
b = "a.`status` != #{STATUS_DELETE} AND a.create_by IN ( #{sqlMap.where.create_by#IN1.val[0]},"
+ " #{sqlMap.where.create_by#IN1.val[1]} ) AND u.`user_name` LIKE #{sqlMap.where#user_name#LIKE1}";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
System.out.println("============ 条件嵌套查询,可替代 andBracket、orBracket、endBracket v5.2.1+ ============");
a = new Post("1").sqlMap().getWhere()
.and("name", QueryType.EQ, "abc", 1)
.and((w) -> w
.or("name", QueryType.EQ, "def", 2)
.or("name", QueryType.EQ, "ghi", 3))
.and((w) -> w
.or((w2) -> w2
.and("name", QueryType.EQ, "def", 4)
.and("name", QueryType.EQ, "", 5)
.and("name", QueryType.EQ_FORCE, "", 6))
.or((w2) -> w2
.and("name", QueryType.EQ, "def", 7)
.and("name", QueryType.EQ, "ghi", 8)))
.toSql();
b = "a.`status` != #{STATUS_DELETE} AND a.`post_code` = #{sqlMap.where#post_code#EQ1} AND a.name = #{sqlMap.where.name#EQ1.val}" +
" AND (a.name = #{sqlMap.where.n#[0].name#EQ2.val} OR a.name = #{sqlMap.where.n#[0].name#EQ3.val})" +
" AND ((a.name = #{sqlMap.where.n#[1].n#[0].name#EQ4.val} AND a.name = #{sqlMap.where.n#[1].n#[0].name#EQ_FORCE6.val})" +
" OR (a.name = #{sqlMap.where.n#[1].n#[1].name#EQ7.val} AND a.name = #{sqlMap.where.n#[1].n#[1].name#EQ8.val}))";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
System.out.println("============ 插入测试,字段权限过滤 v5.11.1 ============");
Post insertPost = new Post("1");
insertPost.setPostName("这是岗位名称");
insertPost.currentUser(new User("system"));
insertPost.sqlMap().getInsert().setExcludeAttrNames(SetUtils.newHashSet("postName"));
insertPost.sqlMap().getInsert().setIncludeAttrNames(SetUtils.newHashSet("postCode"));
a = "INSERT INTO " + insertPost.sqlMap().getInsert().toTableSql();
a += " (" + insertPost.sqlMap().getInsert().toColumnSql() + ")";
a += " VALUES (" + insertPost.sqlMap().getInsert().toValuesSql() + ")";
b = "INSERT INTO `js_sys_post`" +
" (`status`, `create_by`, `create_date`, `update_by`, `update_date`, `post_code`)" +
" VALUES (#{status}, #{createBy}, #{createDate}, #{updateBy}, #{updateDate}, #{postCode})";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
System.out.println("============ 更新测试,字段权限过滤,扩展列,扩展条件 v5.11.1 ============");
Post updatePost = new Post("1");
updatePost.setPostName("这是岗位名称");
updatePost.setPostType("ceo");
updatePost.setPostSort(1);
updatePost.currentUser(new User("system"));
updatePost.sqlMap().getUpdate().setExcludeAttrNames(SetUtils.newHashSet("updateBy", "updateDate"));
updatePost.sqlMap().getUpdate().setIncludeAttrNames(SetUtils.newHashSet("postName", "postType"));
updatePost.sqlMap().getUpdate().addExtColumnSql("s1", "hot1 = hot1 + 1");
updatePost.sqlMap().getUpdate().addExtWhereSql("w1", "name1 = '123'");
a = "UPDATE " + updatePost.sqlMap().getUpdate().toTableSql();
a += " SET " + updatePost.sqlMap().getUpdate().toColumnSql();
a += " WHERE " + updatePost.sqlMap().getUpdate().toWhereSql();
b = "UPDATE `js_sys_post`" +
" SET `post_name` = #{postName}, `post_type` = #{postType}, hot1 = hot1 + 1" +
" WHERE `post_code` = #{postCode} AND name1 = '123'";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
System.out.println("============ 查询操作,字段权限过滤,扩展列,扩展表,扩展条件 v5.11.1 ============");
Post queryPost = new Post("1");
queryPost.currentUser(new User("system"));
queryPost.setPostType("ceo");
SqlMap sqlMap = queryPost.sqlMap();
sqlMap.getColumn()
.setExcludeAttrNames(SetUtils.newHashSet("postType",
"createBy", "createDate", "updateBy", "updateDate", "status", "corpCode", "corpName"))
.setIncludeAttrNames(SetUtils.newHashSet("postName"))
.addExtSql("c1", "b.column1 AS \"column1\"")
.addExtSql("c2", "COUNT(c.column2) AS \"column2\""); // 聚合函数
sqlMap.getTable()
.addExtSql("t1", "JOIN test1 b ON b.post_code = a.post_code")
.addExtSql("t2", "JOIN test2 c ON b.test_code = a.test_code");
sqlMap.getWhere()
.addExtSql("w1", "AND b.name1 = '123'");
sqlMap.getGroup()
.setGroupBy("c.name2") // 分组查询 v5.14.0
.setHaving("COUNT(c.column2) > 0"); // 分组条件 v5.14.0
a = "SELECT " + sqlMap.getColumn().toSql();
a += " FROM " + sqlMap.getTable().toSql();
a += " WHERE " + sqlMap.getWhere().toSql();
a += " GROUP BY " + sqlMap.getGroup().toSql();
a += " ORDER BY " + sqlMap.getOrder().toSql();
b = "SELECT a.`post_name` AS \"postName\", b.column1 AS \"column1\", COUNT(c.column2) AS \"column2\"" +
" FROM `js_sys_post` a" +
" JOIN test1 b ON b.post_code = a.post_code" +
" JOIN test2 c ON b.test_code = a.test_code" +
" WHERE a.`status` != #{STATUS_DELETE} AND a.`post_code` = #{sqlMap.where#post_code#EQ1}" +
" AND a.`post_type` = #{sqlMap.where#post_type#EQ1} AND b.name1 = '123'" +
" GROUP BY c.name2 HAVING COUNT(c.column2) > 0" +
" ORDER BY a.post_sort ASC";
System.out.println("a >> "+a);System.out.println("b >> "+b);Assert.assertEquals(b, a);
System.exit(0);
}
}

View File

@@ -0,0 +1,73 @@
/**
* Copyright (c) 2013-Now https://jeesite.com All rights reserved.
* No deletion without permission, or be held responsible to law.
*/
package com.jeesite.test;
import com.jeesite.common.config.Global;
import com.jeesite.common.lang.StringUtils;
import com.jeesite.common.tests.BaseSpringContextTests;
import com.jeesite.modules.gen.entity.GenTable;
import com.jeesite.modules.gen.entity.GenTableColumn;
import com.jeesite.modules.gen.service.GenTableService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ActiveProfiles;
/**
* 代码生成工具API
* @author ThinkGem
* @version 2020-2-1
*/
@ActiveProfiles("test")
@SpringBootTest(classes = ApplicationTest.class)
@Rollback(false)
public class GenTableToolTest extends BaseSpringContextTests {
private GenTableService genTableService;
@Autowired
public void setGenTableToolTest(GenTableService genTableService) {
this.genTableService = genTableService;
}
@Test
public void execute() throws Exception {
GenTable genTable = new GenTable();
genTable.setIsNewRecord(true);
genTable.setTableName("test_data_demo"); // 表名
genTable = genTableService.getFromDb(genTable);
genTable.setClassName(StringUtils.capCamelCase(genTable.getTableName())); // 实体类名
genTable.setFunctionAuthor("ThinkGem"); // 作者名称
genTable.setTplCategory("crud"); // 生成模板crud、treeGrid、service、dao、query
genTable.setPackageName("com.jeesite.modules");// 生成包路径
genTable.setModuleName("test"); // 生成模块名
genTable.setSubModuleName(""); // 生成子模块名
genTable.setFunctionName(genTable.getComments()); // 生成功能名
genTable.setFunctionNameSimple(genTable.getComments()); // 功能名(简称)
genTable.getOptionMap().put("isHaveDisableEnable", Global.NO); // 是否有停用启用
genTable.getOptionMap().put("isHaveDelete", Global.YES); // 是否有删除功能
genTable.getOptionMap().put("isFileUpload", Global.NO); // 是否有上传附件
genTable.getOptionMap().put("isImageUpload", Global.NO); // 是否有上传图片
for(GenTableColumn column : genTable.getColumnList()){
// 字段配置(下拉框)
if ("trade_type".equals(column.getColumnName())){
column.setShowType("select");
column.getOptionMap().put("dictType", "sys_menu_type");
}
}
// 删除旧配置
genTableService.delete(genTable);
// 保存新配置
genTable.setIsNewRecord(true);
genTableService.save(genTable);
// 编译并生成代码
genTable.setGenFlag("1"); // 1编译输出2生成文件
genTable.setReplaceFile(Global.YES); // 如果存在则替换
String result = genTableService.generateCode(genTable);
System.out.println(result);
}
}

View File

@@ -0,0 +1,96 @@
package com.jeesite.test;
import com.jeesite.common.codec.DesUtils;
import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.collect.MapUtils;
import com.jeesite.common.mapper.JsonMapper;
import com.jeesite.common.web.http.HttpClientUtils;
import java.util.List;
import java.util.Map;
/**
* 手机接入测试类
* @author ThinkGem
* @version 2016-10-21
*/
public class MobileAppTest {
public static void main(String[] args) {
// 获取权限信息
String url = "/index";
System.out.println("========== 获取状态 ==========");
System.out.println("result: " + post(url, null));
// 获取部门列表数据
url = "/sys/office/treeData";
System.out.println("========== 部门列表 ==========");
System.out.println("result: " + post(url, null));
// 获取用户列表数据
url = "/sys/empUser/treeData";
System.out.println("========== 用户列表 ==========");
System.out.println("result: " + post(url, null));
}
/**
* 服务器地址
*/
private static final String servUrl = "http://127.0.0.1:8980/js/a";
/**
* 登录地址及登录信息
*/
private static final String loginUrl = "/login"
+ "?username=" + DesUtils.encode("system", "Base64")
+ "&password=" + DesUtils.encode("admin", "Base64")
+ "&param_deviceType=mobileApp&param_lang=zh_CN&__sid=";
/**
* 存储的会话编号则通过getSid()获取。
*/
private static String __sid = "";
/**
* 获取有效的会话编号
*/
public static void refreshSid(){
System.out.println("========== 登录系统 ==========");
List<Map<String, Object>> result = post(loginUrl, null);
if (result.size() == 1){
Map<String, Object> res = result.get(0);
if ("true".equals(res.get("result"))){
__sid = (String)res.get("sessionid");
System.out.println("========== 登录成功 ==========");
}else{
throw new RuntimeException("操作失败!错误信息:" + res.get("message"));
}
}
}
/**
* 发送post请求
*/
public static List<Map<String, Object>> post(String url, Map<String, String> data){
List<Map<String, Object>> result = ListUtils.newArrayList();
for (int i = 0; i < 2; i++){
if (data == null){
data = MapUtils.newHashMap();
}
data.put("__sid", __sid); // 设置 SessionID
String body = HttpClientUtils.ajaxPost(servUrl + url, data);
System.out.println("post: " + servUrl + url + ", param: " + data + " , body: " + body);
result = JsonMapper.fromJsonForMapList(body);
if (result.size() == 1 && "login".equals(result.get(0).get("result"))){
refreshSid(); // 刷新SessionID再重新尝试
}else{
break;
}
}
return result;
}
}

View File

@@ -0,0 +1,156 @@
/**
* Copyright (c) 2013-Now https://jeesite.com All rights reserved.
* No deletion without permission, or be held responsible to law.
*/
package com.jeesite.test;
import com.jeesite.common.config.Global;
import com.jeesite.common.lang.DateUtils;
import com.jeesite.common.tests.BaseSpringContextTests;
import com.jeesite.common.utils.SpringUtils;
import com.jeesite.modules.msg.entity.MsgPush;
import com.jeesite.modules.msg.entity.MsgTemplate;
import com.jeesite.modules.msg.entity.content.AppMsgContent;
import com.jeesite.modules.msg.entity.content.EmailMsgContent;
import com.jeesite.modules.msg.entity.content.PcMsgContent;
import com.jeesite.modules.msg.entity.content.SmsMsgContent;
import com.jeesite.modules.msg.service.MsgTemplateService;
import com.jeesite.modules.msg.task.impl.MsgLocalMergePushTask;
import com.jeesite.modules.msg.task.impl.MsgLocalPushTask;
import com.jeesite.modules.msg.utils.MsgPushUtils;
import com.jeesite.modules.sys.entity.User;
import com.jeesite.modules.sys.service.UserService;
import com.jeesite.modules.sys.utils.UserUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ActiveProfiles;
import java.util.Date;
import java.util.List;
/**
* 消息推送测试类
* @author ThinkGem
* @version 2018-5-11
*/
@ActiveProfiles("test")
@SpringBootTest(classes = ApplicationTest.class, properties = {"msg.enabled=true"})
@Rollback(false)
public class MsgPushTest extends BaseSpringContextTests {
private UserService userService;
private MsgTemplateService msgTemplateService;
@Autowired
public void setMsgPushTest(UserService userService, MsgTemplateService msgTemplateService) {
this.userService = userService;
this.msgTemplateService = msgTemplateService;
}
@Test
public void testSend(){
User user = UserUtils.get("system");
if (StringUtils.isAnyBlank(user.getMobile(), user.getEmail())){
user.setMobile("18555555555");
user.setEmail("test@163.com");
userService.updateUserInfo(user);
}
for (int i=0; i<1; i++){
testPc();
// testApp();
// testSMS();
// testMail();
// testMailTpl();
}
for (int j=0; j<3; j++){
testTaskPush();
testTaskMergePush();
}
}
public void testPc(){
PcMsgContent msgContent = new PcMsgContent();
msgContent.setTitle("提示信息");
msgContent.setContent("您有1条新的任务");
msgContent.addButton("办理", "/a/task/execute?id=123");
logger.info("即时推送消息");
MsgPushUtils.push(msgContent, "BizKey", "BizType", "system");
logger.info("定时推送消息");
MsgPushUtils.push(msgContent, "BizKey", "BizType", "system", DateUtils.parseDate("2018-05-05 08:30"));
logger.info("合并推送消息");
MsgPushUtils.push(msgContent, "BizKey", "BizType", "system", new Date(), Global.YES);
logger.info("读取消息");
MsgPushUtils.readMsgByBiz("BizKey", "BizType", "system");
}
public void testApp(){
AppMsgContent msgContent = new AppMsgContent();
msgContent.setTitle("提示信息");
msgContent.setContent("您有1条新的任务");
logger.info("即时推送消息");
MsgPushUtils.push(msgContent, "BizKey", "BizType", "system");
logger.info("定时推送消息");
MsgPushUtils.push(msgContent, "BizKey", "BizType", "system", DateUtils.parseDate("2018-05-05 08:30"));
logger.info("合并推送消息");
MsgPushUtils.push(msgContent, "BizKey", "BizType", "system", new Date(), Global.YES);
}
public void testSMS(){
SmsMsgContent msgContent = new SmsMsgContent();
msgContent.setTitle("提示信息");
msgContent.setContent("您好您的验证码是123456请勿透露给其他人感谢您的使用。");
logger.info("即时推送消息");
MsgPushUtils.push(msgContent, "BizKey", "BizType", "system");
logger.info("定时推送消息");
MsgPushUtils.push(msgContent, "BizKey", "BizType", "system", DateUtils.parseDate("2018-05-05 08:30"));
logger.info("合并推送消息");
MsgPushUtils.push(msgContent, "BizKey", "BizType", "system", new Date(), Global.YES);
}
public void testMail(){
EmailMsgContent msgContent = new EmailMsgContent();
msgContent.setTitle("提示信息");
msgContent.setContent("这是一条测试邮件内容");
logger.info("即时推送消息");
MsgPushUtils.push(msgContent, "BizKey", "BizType", "system");
logger.info("定时推送消息");
MsgPushUtils.push(msgContent, "BizKey", "BizType", "system", DateUtils.parseDate("2018-05-05 08:30"));
logger.info("合并推送消息");
MsgPushUtils.push(msgContent, "BizKey", "BizType", "system", new Date(), Global.YES);
}
public void testMailTpl(){
// 创建消息模板
MsgTemplate msgTemplate = new MsgTemplate();
msgTemplate.setTplKey("mail_send_test");
List<MsgTemplate> tplList = msgTemplateService.findList(msgTemplate);
if (tplList.isEmpty()){
msgTemplate.setTplName("邮件提示信息");
msgTemplate.setTplContent("你好,${keyword1},请于 ${keyword2},准时参加${keyword3}");
msgTemplate.setTplType(MsgPush.TYPE_EMAIL);
msgTemplateService.save(msgTemplate);
}
logger.info("根据模板发送消息");
EmailMsgContent msgContent = new EmailMsgContent();
msgContent.setTitle("邮件提示信息");
msgContent.setTplKey("mail_send_test");
msgContent.addTplData("keyword1", "小王");
msgContent.addTplData("keyword2", "2018-8-28 20:00");
msgContent.addTplData("keyword3", "OA项目方案讨论视频会议");
msgContent.setCc("thinkgem@163.com"); // 抄送地址,模板附加参数
// 即时推送模板消息,模板内容:你好,${keyword1},请于 ${keyword2},准时参加${keyword3}
MsgPushUtils.push(msgContent, "BizKey", "BizType", "system");
}
public void testTaskPush(){
SpringUtils.getBean(MsgLocalPushTask.class).execute();
}
public void testTaskMergePush(){
SpringUtils.getBean(MsgLocalMergePushTask.class).execute();
}
}

View File

@@ -0,0 +1,47 @@
/**
* Copyright (c) 2013-Now https://jeesite.com All rights reserved.
* No deletion without permission, or be held responsible to law.
*/
package com.jeesite.test.codec;
import com.jeesite.common.codec.EncodeUtils;
import com.jeesite.common.codec.SM2Utils;
import java.nio.charset.StandardCharsets;
import java.security.PrivateKey;
import java.security.PublicKey;
/**
* 国密 SM2 加密解密工具类,非对称加密
* @author ThinkGem
* @version 2024-07-22
*/
public class SM2UtilsTest {
public static void main(String[] args) {
String s = "Hello word! 你好,中文!";
System.out.println(s);
String[] keys = SM2Utils.genKeys();
System.out.println("公钥:" + keys[0]);
PublicKey publicKey = SM2Utils.toPublicKey(keys[0]);
System.out.println("私钥:" + keys[1]);
PrivateKey privateKey = SM2Utils.toPrivateKey(keys[1]);
byte[] data = SM2Utils.encode(s.getBytes(), publicKey);
String dataString = EncodeUtils.encodeBase64(data);
System.out.println("加密数据:" + dataString);
byte[] data2 = SM2Utils.decode(data, privateKey);
String dataString2 = new String(data2, StandardCharsets.UTF_8);
System.out.println("解密数据:" + dataString2);
byte[] sign = SM2Utils.sign(s.getBytes(), privateKey);
System.out.println("数据签名:" + EncodeUtils.encodeBase64(sign));
boolean b = SM2Utils.verify(s.getBytes(), publicKey, sign);
System.out.println("数据验签:" + b);
}
}

View File

@@ -0,0 +1,34 @@
/**
* Copyright (c) 2013-Now https://jeesite.com All rights reserved.
* No deletion without permission, or be held responsible to law.
*/
package com.jeesite.test.codec;
import com.jeesite.common.codec.SM3Utils;
/**
* 国密 SM3 加密工具类,散列加密,不可逆加密
* @author ThinkGem
* @version 2024-07-22
*/
public class SM3UtilsTest {
public static void main(String[] args) {
String s = "Hello word! 你好,中文!";
System.out.println(s);
String s1 = SM3Utils.sm3(s);
System.out.println(s1);
String key = SM3Utils.genSaltString(8);
System.out.println(key);
String s3 = SM3Utils.sm3(s, key);
System.out.println(s3);
String s4 = SM3Utils.hmacSm3(s, key);
System.out.println(s4);
}
}

View File

@@ -0,0 +1,39 @@
/**
* Copyright (c) 2013-Now https://jeesite.com All rights reserved.
* No deletion without permission, or be held responsible to law.
*/
package com.jeesite.test.codec;
import com.jeesite.common.codec.EncodeUtils;
import com.jeesite.common.codec.SM4Utils;
import java.nio.charset.StandardCharsets;
/**
* 国密 SM4 加密解密工具类,对称加密
* @author ThinkGem
* @version 2024-07-22
*/
public class SM4UtilsTest {
public static void main(String[] args) {
String s = "Hello word! 你好,中文!";
System.out.println(s);
String k = SM4Utils.genKeyString();
System.out.println(k);
String s1 = SM4Utils.encode(s, k);
System.out.println(s1);
String s2 = SM4Utils.decode(s1, k);
System.out.println(s2);
byte[] key = SM4Utils.genKey();
byte[] iv = SM4Utils.genIV();
byte[] data = SM4Utils.encode(s.getBytes(StandardCharsets.UTF_8), key, iv);
System.out.println(EncodeUtils.encodeBase64(data));
byte[] data2 = SM4Utils.decode(data, key, iv);
System.out.println(new String(data2, StandardCharsets.UTF_8));
}
}

View File

@@ -0,0 +1,15 @@
# 数据库连接
jdbc:
# Mysql 数据库配置
type: mysql
driver: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/jeesite_v5?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=Asia/Shanghai
username: root
password: 123456
testSql: SELECT 1
# 日志配置
logging:
config: classpath:logback-test.xml

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="false">
<!-- Logger level setting -->
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<include resource="config/logger-default.xml" />
<!-- Console log output -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} %clr(%-5p) %clr([%-39logger{39}]){cyan} - %m%n%wEx</pattern>
</encoder>
</appender>
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
<root level="WARN">
<appender-ref ref="console" />
</root>
</configuration>