Commit feb79afb by levphon

工单标准接口-数据迁移

1 parent dcb7bde5
...@@ -6,6 +6,7 @@ import com.glsx.plat.mybatis.mapper.CommonBaseMapper; ...@@ -6,6 +6,7 @@ import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List; import java.util.List;
@Mapper @Mapper
...@@ -13,8 +14,12 @@ public interface VehicleMapper extends CommonBaseMapper<Vehicle> { ...@@ -13,8 +14,12 @@ public interface VehicleMapper extends CommonBaseMapper<Vehicle> {
Vehicle selectByWorkOrderId(@Param("workOrderId") Long workOrderId); Vehicle selectByWorkOrderId(@Param("workOrderId") Long workOrderId);
List<Vehicle> selectAllByNoNullRefVehicleId(); List<Vehicle> selectAllByNotNullRefVehicleId();
List<Vehicle> selectByNullCreateBy();
Vehicle selectByRefVehicleId(@Param("refVehicleId") Long refVehicleId); Vehicle selectByRefVehicleId(@Param("refVehicleId") Long refVehicleId);
int updateCreateByByRefVehicleIds(@Param("userId") Long userId, @Param("refVehicleIds") Collection<Long> refVehicleIds);
} }
\ No newline at end of file \ No newline at end of file
...@@ -6,6 +6,7 @@ import lombok.Data; ...@@ -6,6 +6,7 @@ import lombok.Data;
public class ZhongliAccountModel { public class ZhongliAccountModel {
private String level; private String level;
private Long userId;//新系统id
private String account; private String account;
private String username; private String username;
private String department; private String department;
......
...@@ -39,7 +39,11 @@ public class ZhongliVehicleService { ...@@ -39,7 +39,11 @@ public class ZhongliVehicleService {
public void linkVehicle2Account() { public void linkVehicle2Account() {
List<ZhongliAccountModel> accountModelList = zhongliAccountMapper.selectByLevel(null); List<ZhongliAccountModel> accountModelList = zhongliAccountMapper.selectByLevel(null);
Map<String, List<ZhongliAccountModel>> accountMapByRoleName = accountModelList.stream().collect(Collectors.groupingBy(ZhongliAccountModel::getRoleName)); Map<String, ZhongliAccountModel> accountMap = accountModelList.stream().collect(Collectors.toMap(ZhongliAccountModel::getAccount, v -> v));
Map<String, List<ZhongliAccountModel>> accountMapByRoleName = accountModelList.stream()
.filter(zam -> zam.getRoleName().equals("仲利法务") || zam.getRoleName().equals("仲利收车"))
.collect(Collectors.groupingBy(ZhongliAccountModel::getRoleName));
Map<String, List<ZhongliAccountModel>> accountMapByLevel = accountModelList.stream() Map<String, List<ZhongliAccountModel>> accountMapByLevel = accountModelList.stream()
.filter(zam -> !zam.getRoleName().equals("仲利法务") && !zam.getRoleName().equals("仲利收车")) .filter(zam -> !zam.getRoleName().equals("仲利法务") && !zam.getRoleName().equals("仲利收车"))
...@@ -47,46 +51,87 @@ public class ZhongliVehicleService { ...@@ -47,46 +51,87 @@ public class ZhongliVehicleService {
.collect(Collectors.groupingBy(ZhongliAccountModel::getLevel)); .collect(Collectors.groupingBy(ZhongliAccountModel::getLevel));
//全部同步车辆 //全部同步车辆
List<Vehicle> vehicleList = vehicleMapper.selectAllByNoNullRefVehicleId(); List<Vehicle> vehicleList = vehicleMapper.selectAllByNotNullRefVehicleId();
Map<Long, Vehicle> vehicleMap = vehicleList.stream().collect(Collectors.toMap(Vehicle::getRefVehicleId, v -> v)); Map<Long, Vehicle> vehicleMap = vehicleList.stream().collect(Collectors.toMap(Vehicle::getRefVehicleId, v -> v));
log.info("绝对授权方式"); ZhongliAccountModel zlgj = accountMap.get("zlgj");
accountMapByRoleName.forEach((k, v) -> {
v.forEach(account -> { log.info("绝对授权方式===============================================");
accountMapByRoleName.forEach((k, v) -> v.forEach(account -> {
List<ZhongliVehicle> zhongliVehicleList = zhongliVehicleMapper.selectByAccount(account.getAccount());
log.info("账号{}(角色为:{})的车辆数:{}", account.getAccount(), k, zhongliVehicleList.size());
List<VehiclePermit> permitList = Lists.newArrayList();
zhongliVehicleList.forEach(zv -> {
Vehicle vehicle = vehicleMap.get(zv.getVehicleId());
if (vehicle == null) {
return;
}
VehiclePermit vp = new VehiclePermit();
vp.setContentId(vehicle.getId());
vp.setAccorderId(zlgj.getUserId());
vp.setReceiverId(account.getUserId());
vp.setContentType(0);
vp.setPermitType(1);
vp.setCreatedDate(new Date());
permitList.add(vp);
});
if (CollectionUtils.isNotEmpty(permitList)) {
vehiclePermitMapper.insertList(permitList);
}
}));
log.info("相对授权方式=================================================");
List<ZhongliAccountModel> accountModels1 = accountMapByLevel.get("一级");
if (CollectionUtils.isNotEmpty(accountModels1)) {
accountModels1.forEach(account -> {
List<ZhongliVehicle> zhongliVehicleList = zhongliVehicleMapper.selectByAccount(account.getAccount()); List<ZhongliVehicle> zhongliVehicleList = zhongliVehicleMapper.selectByAccount(account.getAccount());
log.info("账号{}(角色为:{})的车辆数:{}", account.getAccount(), k, zhongliVehicleList.size()); log.info("一级账号{}的车辆数:{}", account.getAccount(), zhongliVehicleList.size());
if (k.equals("仲利法务") || k.equals("仲利收车")) {
List<VehiclePermit> permitList = Lists.newArrayList(); List<Long> vehicleIds = Lists.newArrayList();
zhongliVehicleList.forEach(zv -> { zhongliVehicleList.forEach(zv -> vehicleIds.add(zv.getVehicleId()));
Vehicle vehicle = vehicleMap.get(zv.getVehicleId()); if (CollectionUtils.isNotEmpty(vehicleIds)) {
if (vehicle == null) { vehicleMapper.updateCreateByByRefVehicleIds(account.getUserId(), vehicleIds);
return;
}
VehiclePermit vp = new VehiclePermit();
vp.setContentId(vehicle.getId());
vp.setAccorderId(0L);
vp.setReceiverId(1L);
vp.setContentType(0);
vp.setPermitType(1);
vp.setCreatedDate(new Date());
permitList.add(vp);
});
if (CollectionUtils.isNotEmpty(permitList)) {
//vehiclePermitMapper.insertList(permitList);
}
} }
}); });
}); }
log.info("相对授权方式"); List<ZhongliAccountModel> accountModels2 = accountMapByLevel.get("二级");
accountMapByLevel.forEach((k, v) -> { if (CollectionUtils.isNotEmpty(accountModels2)) {
v.forEach(account -> { accountModels2.forEach(account -> {
List<ZhongliVehicle> zhongliVehicleList = zhongliVehicleMapper.selectByAccount(account.getAccount()); List<ZhongliVehicle> zhongliVehicleList = zhongliVehicleMapper.selectByAccount(account.getAccount());
log.info("{}账号{}(角色为:{})的车辆数:{}", k, account.getAccount(), k, zhongliVehicleList.size()); log.info("二级账号{}的车辆数:{}", account.getAccount(), zhongliVehicleList.size());
List<Long> vehicleIds = Lists.newArrayList();
zhongliVehicleList.forEach(zv -> vehicleIds.add(zv.getVehicleId()));
if (CollectionUtils.isNotEmpty(vehicleIds)) {
vehicleMapper.updateCreateByByRefVehicleIds(account.getUserId(), vehicleIds);
}
}); });
}); }
List<ZhongliAccountModel> accountModels3 = accountMapByLevel.get("三级");
if (CollectionUtils.isNotEmpty(accountModels3)) {
accountModels3.forEach(account -> {
List<ZhongliVehicle> zhongliVehicleList = zhongliVehicleMapper.selectByAccount(account.getAccount());
log.info("三级账号{}的车辆数:{}", account.getAccount(), zhongliVehicleList.size());
List<Long> vehicleIds = Lists.newArrayList();
zhongliVehicleList.forEach(zv -> vehicleIds.add(zv.getVehicleId()));
if (CollectionUtils.isNotEmpty(vehicleIds)) {
vehicleMapper.updateCreateByByRefVehicleIds(account.getUserId(), vehicleIds);
}
});
}
//最后还没有创建人的直接丢到仲利国际上面
List<Vehicle> noCreateByVehicles = vehicleMapper.selectByNullCreateBy();
if (CollectionUtils.isNotEmpty(noCreateByVehicles)) {
List<Long> vehicleIds = Lists.newArrayList();
noCreateByVehicles.forEach(vehicle -> vehicleIds.add(vehicle.getRefVehicleId()));
if (CollectionUtils.isNotEmpty(vehicleIds)) {
vehicleMapper.updateCreateByByRefVehicleIds(zlgj.getUserId(), vehicleIds);
}
}
} }
} }
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
and workorder_id = #{workOrderId} and workorder_id = #{workOrderId}
</select> </select>
<select id="selectAllByNoNullRefVehicleId" resultMap="BaseResultMap"> <select id="selectAllByNotNullRefVehicleId" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List"/> <include refid="Base_Column_List"/>
from t_vehicle from t_vehicle
...@@ -88,4 +88,23 @@ ...@@ -88,4 +88,23 @@
and ref_vehicle_id = #{refVehicleId} and ref_vehicle_id = #{refVehicleId}
limit 1 limit 1
</select> </select>
<select id="selectByNullCreateBy" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_vehicle
where del_flag = 0
and ref_vehicle_id is not null
and created_by is null
</select>
<update id="updateCreateByByRefVehicleIds">
update t_vehicle
set created_by = #{userId}
where ref_vehicle_id is not null
and ref_vehicle_id in
<foreach collection="refVehicleIds" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</update>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
</sql> </sql>
<select id="selectByLevel" resultType="cn.com.glsx.stdinterface.modules.model.ZhongliAccountModel"> <select id="selectByLevel" resultType="cn.com.glsx.stdinterface.modules.model.ZhongliAccountModel">
select `level`, account, username, department, role_name roleName select `level`, created_by userId, account, username, department, role_name roleName
from t_zhongli_account from t_zhongli_account
where del_flag = 0 where del_flag = 0
<if test="level != null and level != ''"> <if test="level != null and level != ''">
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!