Skip to content

Commit

Permalink
+行政区绑定测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
JerryMa1024 committed Oct 21, 2020
1 parent 2f0c76a commit a9af3c3
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
import com.diboot.core.util.JSON;
import com.diboot.core.util.V;
import diboot.core.test.StartupApplication;
import diboot.core.test.binder.entity.CcCityInfo;
import diboot.core.test.binder.entity.Sysuser;
import diboot.core.test.binder.service.DepartmentService;
import diboot.core.test.binder.service.SysuserService;
import diboot.core.test.binder.vo.CcCityInfoVO;
import diboot.core.test.binder.vo.FieldBinderVO;
import diboot.core.test.binder.vo.TestDictVo;
import diboot.core.test.binder.vo.UserVO;
import diboot.core.test.config.SpringMvcConfig;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -49,6 +52,7 @@
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {SpringMvcConfig.class})
@SpringBootTest(classes = {StartupApplication.class})
@Slf4j
public class TestFieldBinder {

@Autowired
Expand Down Expand Up @@ -112,4 +116,14 @@ public void testDictVoBind(){
}
}

@Test
public void testCity(){
CcCityInfo ccCityInfo = new CcCityInfo();
ccCityInfo.setRegionId(10020L).setParentId(10010L);

CcCityInfoVO ccCityInfoVO = Binder.convertAndBindRelations(ccCityInfo, CcCityInfoVO.class);
System.out.println(ccCityInfoVO.getProvenceName());
Assert.assertTrue(ccCityInfoVO.getProvenceName() != null);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2015-2020, www.dibo.ltd ([email protected]).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package diboot.core.test.binder.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableField;
import com.diboot.core.entity.BaseEntity;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.Date;

/**
* @author [email protected]
* @version v2.0
* @date 2019/1/30
*/
@Getter
@Setter
@Accessors(chain = true)
public class CcCityInfo extends BaseEntity {
private static final long serialVersionUID = 3701095453152116088L;

private Long parentId;

private Long regionId;

private String regionName;

@TableField(exist = false)
private Date createTime;

@TableField(exist = false)
private boolean deleted;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2015-2020, www.dibo.ltd ([email protected]).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package diboot.core.test.binder.mapper;

import com.diboot.core.mapper.BaseCrudMapper;
import diboot.core.test.binder.entity.CcCityInfo;
import diboot.core.test.binder.entity.Role;
import org.apache.ibatis.annotations.Mapper;

/**
* 员工Mapper
* @author [email protected]
* @version 2018/12/22
*/
@Mapper
public interface CcCityInfoMapper extends BaseCrudMapper<CcCityInfo> {

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2015-2020, www.dibo.ltd ([email protected]).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package diboot.core.test.binder.service;

import com.baomidou.mybatisplus.extension.service.IService;
import diboot.core.test.binder.entity.CcCityInfo;
import diboot.core.test.binder.entity.Role;

/**
* 角色相关Service
* @author [email protected]
* @version v2.0
* @date 2019/1/5
*/
public interface CcCityInfoService extends IService<CcCityInfo> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2015-2020, www.dibo.ltd ([email protected]).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package diboot.core.test.binder.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import diboot.core.test.binder.entity.CcCityInfo;
import diboot.core.test.binder.entity.Role;
import diboot.core.test.binder.mapper.CcCityInfoMapper;
import diboot.core.test.binder.mapper.RoleMapper;
import diboot.core.test.binder.service.CcCityInfoService;
import diboot.core.test.binder.service.RoleService;
import org.springframework.stereotype.Service;

/**
* 员工相关Service
* @author [email protected]
* @version 2018/12/23
*/
@Service
public class CcCityInfoServiceImpl extends ServiceImpl<CcCityInfoMapper, CcCityInfo> implements CcCityInfoService {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package diboot.core.test.binder.vo;

import com.diboot.core.binding.annotation.BindField;
import diboot.core.test.binder.entity.CcCityInfo;
import lombok.Data;

/**
* <Description>
*
* @author mazc
* @version v1.0
* @date 2020/09/29
*/
@Data
public class CcCityInfoVO extends CcCityInfo {

@BindField(entity = CcCityInfo.class, field = "regionName", condition = "this.parent_id=cc_city_info.region_id AND cc_city_info.parent_id=region_id")
private String provenceName;

}
11 changes: 10 additions & 1 deletion diboot-core-starter/src/test/resources/init-mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,20 @@ create table user_role
primary key (user_id, role_id)
) comment '用户角色' charset=utf8mb4;

create table cc_city_info
(
id int auto_increment primary key,
parent_id int null,
region_id int not null,
region_name varchar(100) null
) comment '行政区划' charset=utf8mb4;

-- 初始化样例数据
INSERT INTO department (id, parent_id, org_id, name) VALUES (10001, 0, 100001, '产品部'), (10002, 10001, 100001, '研发组'), (10003, 10001, 100001, '测试组'),
(10004, 10001, 100001, 'UI组'), (10005, 10003, 100001, '自动化测试'), (10006, 10003, 100001, '功能测试');
INSERT INTO dictionary (id, parent_id, type, item_name, item_value) VALUES (1, 0, 'GENDER', '性别', null), (2, 1, 'GENDER', '', 'M'), (3, 1, 'GENDER', '', 'F');
INSERT INTO organization (id, parent_id, name, telphone) VALUES (100001, 0, '苏州帝博', '0512-62988949'), (100002, 0, '成都帝博', null);
INSERT INTO role (id, name, code) VALUES (101, '管理员', 'ADMIN'), (102, '操作员', 'OPERATOR');
INSERT INTO sysuser (id, department_id, username, gender) VALUES (1001, 10002, '张三', 'M'), (1002, 10002, '李四', 'F');
INSERT INTO user_role (user_type, user_id, role_id) VALUES ('SysUser', 1001, 101),('SysUser', 1001, 102),('OrgUser', 1002, 102);
INSERT INTO user_role (user_type, user_id, role_id) VALUES ('SysUser', 1001, 101),('SysUser', 1001, 102),('OrgUser', 1002, 102);
INSERT INTO cc_city_info (id, parent_id, region_id, region_name) VALUES (10000, 0, 10000, '江苏省'), (10010, 10000, 10010, '苏州市'), (10020, 10010, 10020, '园区');

0 comments on commit a9af3c3

Please sign in to comment.