208 lines
8.4 KiB
Java
208 lines
8.4 KiB
Java
package gb;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import net.shapelight.AdminApplication;
|
|
import net.shapelight.common.utils.Constant;
|
|
import net.shapelight.common.utils.SnowflakeIdWorker;
|
|
import net.shapelight.common.utils.UUIDUtil;
|
|
import net.shapelight.modules.sys.entity.SysUserEntity;
|
|
import net.shapelight.modules.sys.service.SysUserService;
|
|
import net.shapelight.modules.ten.dao.TenPersonDao;
|
|
import net.shapelight.modules.ten.dao.TenRoomDao;
|
|
import net.shapelight.modules.ten.entity.*;
|
|
import net.shapelight.modules.ten.service.*;
|
|
import net.shapelight.modules.vo.TenRoomDeptVo;
|
|
import net.shapelight.modules.xian.service.XaApi;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
@Slf4j
|
|
@RunWith(SpringRunner.class)
|
|
@SpringBootTest(classes = AdminApplication.class)
|
|
public class PersonBatchAdd {
|
|
|
|
@Autowired
|
|
private TenPersonDao personDao;
|
|
@Autowired
|
|
private TenPersonService tenPersonService;
|
|
@Autowired
|
|
private TenPersonSyncService tenPersonSyncService;
|
|
@Autowired
|
|
private TenRoomService tenRoomService;
|
|
@Autowired
|
|
private TenRoomDao tenRoomDao;
|
|
@Autowired
|
|
private TenCellDeptService tenCellDeptService;
|
|
@Autowired
|
|
private SysUserService sysUserService;
|
|
@Autowired
|
|
private TenCellService tenCellService;
|
|
@Autowired
|
|
private TenLabelService tenLabelService;
|
|
|
|
@Test
|
|
public void test1() {
|
|
|
|
//1145677664724451334
|
|
TenPersonEntity tenPerson = tenPersonService.getById(1146037854288216067l,1146037238358867968l);
|
|
|
|
for(int i = 1;i<=10000;i++){
|
|
// TenPersonEntity tenPerson = new TenPersonEntity();
|
|
tenPerson.setMemberId(null);
|
|
long id = new SnowflakeIdWorker().nextId();
|
|
tenPerson.setPersonId(id);
|
|
tenPerson.setUuid(UUIDUtil.uuid());
|
|
tenPerson.setName("Wy-"+i);
|
|
tenPerson.setIdCard("61013"+(new Date()).getTime());
|
|
personDao.insert(tenPerson);
|
|
|
|
}
|
|
}
|
|
|
|
@Test
|
|
public void runAllData() {
|
|
List<SysUserEntity> allSysTenUser = sysUserService.findAllSysTenUser();
|
|
//1. 获取所有运营商
|
|
List<TenCellEntity> cellList = new ArrayList<>();
|
|
for (SysUserEntity sysTenUser : allSysTenUser) {
|
|
List<TenCellEntity> allCells = this.tenCellService.list((Wrapper) (new QueryWrapper())
|
|
.eq("tenant_id", sysTenUser.getTenantId()));
|
|
//2.在运营商下加入标签
|
|
//保存标签
|
|
TenLabelEntity labelEntity = new TenLabelEntity();
|
|
labelEntity.setTenantId(sysTenUser.getTenantId());
|
|
labelEntity.setType(5000);
|
|
labelEntity.setName("业主");
|
|
tenLabelService.save(labelEntity);
|
|
|
|
TenLabelEntity lable2 = new TenLabelEntity();
|
|
lable2.setTenantId(sysTenUser.getTenantId());
|
|
lable2.setType(5001);
|
|
lable2.setName("家属");
|
|
tenLabelService.save(lable2);
|
|
|
|
TenLabelEntity lable3 = new TenLabelEntity();
|
|
lable3.setTenantId(sysTenUser.getTenantId());
|
|
lable3.setType(5002);
|
|
lable3.setName("租户");
|
|
tenLabelService.save(lable3);
|
|
|
|
|
|
//3.迁移部门数据
|
|
for (TenCellEntity cellEntity : allCells) {
|
|
cellList.add(cellEntity);
|
|
roomToDept(cellEntity.getCellId(),sysTenUser.getTenantId());
|
|
|
|
//4.人员表填充dept字段
|
|
personDept(cellEntity.getCellId(),sysTenUser.getTenantId());
|
|
System.out.println(cellEntity.getName()+":小区数据转换完成。。。。。。。。。。。。。。。。。。。。。。。。。。");
|
|
}
|
|
System.out.println(sysTenUser.getUsername()+":运营商转换完成。。。。。。。。。。。。。。。。。。。。。。。。。。");
|
|
}
|
|
System.out.println("所有数据转换完成。。。。。。。。。。。。小区数量:"+cellList.size());
|
|
for(TenCellEntity cellEntity: cellList){
|
|
System.out.println(cellEntity.getCellId()+":"+cellEntity.getName());
|
|
}
|
|
}
|
|
|
|
@Test
|
|
public void runCellData() {
|
|
Long cellId = 1131959113794715655l;
|
|
Long tenantId = 1131959113794715655l;
|
|
roomToDept(cellId,tenantId);
|
|
personDept(cellId,tenantId);
|
|
}
|
|
|
|
|
|
|
|
// @Test
|
|
public void roomToDept(Long cellId, Long tenantId) {
|
|
// long cellId = 842043084869992448l;
|
|
// long cellId = 854357229950730242l;
|
|
|
|
List<TenRoomDeptVo> buildNameList = tenRoomDao.getDistinctBuild(cellId);
|
|
//插入楼栋信息
|
|
for(TenRoomDeptVo buildName: buildNameList){
|
|
TenCellDeptEntity build = new TenCellDeptEntity();
|
|
build.setCellId(cellId);
|
|
build.setParentId(cellId);
|
|
build.setName(buildName.getName());
|
|
build.setLable("楼栋");
|
|
build.setTenantId(tenantId);
|
|
tenCellDeptService.save(build);
|
|
|
|
//单元信息
|
|
List<TenRoomDeptVo> unitList = tenRoomDao.getDistinctUnit(cellId,buildName.getName());
|
|
for(TenRoomDeptVo unitName: unitList){
|
|
TenCellDeptEntity unit = new TenCellDeptEntity();
|
|
unit.setCellId(cellId);
|
|
unit.setParentId(build.getDeptId());
|
|
unit.setName(unitName.getUnit()+"单元");
|
|
unit.setLable("单元");
|
|
unit.setTenantId(tenantId);
|
|
tenCellDeptService.save(unit);
|
|
|
|
//楼层
|
|
List<TenRoomDeptVo> layerList = tenRoomDao.getDistinctLayer(cellId,buildName.getName(),unitName.getUnit());
|
|
for(TenRoomDeptVo layerName: layerList){
|
|
TenCellDeptEntity layer = new TenCellDeptEntity();
|
|
layer.setCellId(cellId);
|
|
layer.setParentId(unit.getDeptId());
|
|
layer.setName(layerName.getLayer()+"层");
|
|
layer.setLable("楼层");
|
|
layer.setTenantId(tenantId);
|
|
tenCellDeptService.save(layer);
|
|
|
|
//房间
|
|
List<TenRoomDeptVo> roomList = tenRoomDao.getDistinctRoom(cellId,buildName.getName(),unitName.getUnit(),layerName.getLayer());
|
|
for(TenRoomDeptVo roomName: roomList){
|
|
TenCellDeptEntity room = new TenCellDeptEntity();
|
|
room.setCellId(cellId);
|
|
room.setParentId(layer.getDeptId());
|
|
room.setName(roomName.getRoomName());
|
|
room.setLable("房间");
|
|
room.setOther(roomName.getRoomId());
|
|
room.setTenantId(tenantId);
|
|
tenCellDeptService.save(room);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// @Test
|
|
public void personDept(Long cellId,Long tenantId) {
|
|
// long cellId = 842043084869992448l;
|
|
// long cellId = 854357229950730242l;
|
|
List<TenCellDeptEntity> roomDeptList = tenCellDeptService.list(new QueryWrapper<TenCellDeptEntity>()
|
|
.eq("cell_id",cellId)
|
|
.eq("lable","房间"));
|
|
for(TenCellDeptEntity cellDeptEntity: roomDeptList){
|
|
List<TenPersonEntity> personList = tenPersonService.getByRoomId(Long.parseLong(cellDeptEntity.getOther()),cellId,null);
|
|
for(TenPersonEntity personEntity: personList){
|
|
personEntity.setDeptId(cellDeptEntity.getDeptId());
|
|
if(personEntity.getPersonType() == 5000 || personEntity.getPersonType() == 5001 || personEntity.getPersonType() == 5002){
|
|
TenLabelEntity labelEntity = tenLabelService.getOne(new QueryWrapper<TenLabelEntity>()
|
|
.eq("type",personEntity.getPersonType())
|
|
.eq("tenant_id",tenantId));
|
|
if(labelEntity!=null){
|
|
personEntity.setLabelId(labelEntity.getLabelId().intValue());
|
|
}
|
|
}
|
|
tenPersonService.updateNonal(personEntity);
|
|
}
|
|
}
|
|
}
|
|
}
|