Commit 7cb0d3d5 by levphon

代码优化

1 parent 69edb447
...@@ -4,7 +4,6 @@ import cn.com.glsx.admin.modules.model.param.BasicSearch; ...@@ -4,7 +4,6 @@ import cn.com.glsx.admin.modules.model.param.BasicSearch;
import cn.com.glsx.usercenter.api.dto.request.FindUserRequest; import cn.com.glsx.usercenter.api.dto.request.FindUserRequest;
import cn.com.glsx.usercenter.api.dto.response.User; import cn.com.glsx.usercenter.api.dto.response.User;
import cn.com.glsx.usercenter.api.feign.ApiUserService; import cn.com.glsx.usercenter.api.feign.ApiUserService;
import com.alibaba.fastjson.JSON;
import com.glsx.plat.common.utils.StringUtils; import com.glsx.plat.common.utils.StringUtils;
import com.glsx.plat.core.web.R; import com.glsx.plat.core.web.R;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
...@@ -76,13 +75,15 @@ public class UserApiService { ...@@ -76,13 +75,15 @@ public class UserApiService {
* @return * @return
*/ */
public Map<Long, User> getSuperiorUserMapByIds(Collection<Long> userIds) { public Map<Long, User> getSuperiorUserMapByIds(Collection<Long> userIds) {
Map<Long, User> userMap = Maps.newHashMap();
R<List<User>> listR = userService.getSuperiorUserByIds(userIds); R<List<User>> listR = userService.getSuperiorUserByIds(userIds);
if (listR == null) { if (listR == null) {
return null; return userMap;
} }
List<User> userList = listR.getDataList(new TypeToken<List<User>>() { List<User> userList = listR.getDataList(new TypeToken<List<User>>() {
}.getType()); }.getType());
Map<Long, User> userMap = Maps.newHashMap();
if (CollectionUtils.isNotEmpty(userList)) { if (CollectionUtils.isNotEmpty(userList)) {
userMap = userList.stream().collect(Collectors.toMap(User::getMid, Function.identity())); userMap = userList.stream().collect(Collectors.toMap(User::getMid, Function.identity()));
} }
...@@ -96,12 +97,10 @@ public class UserApiService { ...@@ -96,12 +97,10 @@ public class UserApiService {
* @return * @return
*/ */
public Long getUserIdByUsername(String username) { public Long getUserIdByUsername(String username) {
log.info("username===" + username);
if (StringUtils.isNullOrEmpty(username)) { if (StringUtils.isNullOrEmpty(username)) {
return null; return null;
} }
R<List<User>> userR = apiUserService.findByUsername(username); R<List<User>> userR = apiUserService.findByUsername(username);
log.info("userR===" + JSON.toJSONString(userR));
if (userR == null) { if (userR == null) {
return null; return null;
} }
...@@ -123,7 +122,7 @@ public class UserApiService { ...@@ -123,7 +122,7 @@ public class UserApiService {
public List<User> findByUser(Set<Long> userIds) { public List<User> findByUser(Set<Long> userIds) {
R<List<User>> userR = userService.findByUser(new FindUserRequest().setUserIds(userIds)); R<List<User>> userR = userService.findByUser(new FindUserRequest().setUserIds(userIds));
if (userR == null || !userR.isSuccess()) { if (userR == null || !userR.isSuccess()) {
return null; return Lists.newArrayList();
} }
List<User> userList = userR.getDataList(new TypeToken<List<User>>() { List<User> userList = userR.getDataList(new TypeToken<List<User>>() {
}.getType()); }.getType());
...@@ -145,6 +144,9 @@ public class UserApiService { ...@@ -145,6 +144,9 @@ public class UserApiService {
*/ */
public List<User> findAllByOrg(List<Long> orgIds) { public List<User> findAllByOrg(List<Long> orgIds) {
R<List<User>> byOrg = userService.findAllByOrg(new FindUserRequest().setOrgIds(orgIds)); R<List<User>> byOrg = userService.findAllByOrg(new FindUserRequest().setOrgIds(orgIds));
if (byOrg == null || !byOrg.isSuccess()) {
return Lists.newArrayList();
}
List<User> userList = byOrg.getDataList(new TypeToken<List<User>>() { List<User> userList = byOrg.getDataList(new TypeToken<List<User>>() {
}.getType()); }.getType());
return userList; return userList;
...@@ -158,6 +160,9 @@ public class UserApiService { ...@@ -158,6 +160,9 @@ public class UserApiService {
*/ */
public List<User> findByOrg(List<Long> orgIds) { public List<User> findByOrg(List<Long> orgIds) {
R<List<User>> byOrg = userService.findByOrg(new FindUserRequest().setOrgIds(orgIds)); R<List<User>> byOrg = userService.findByOrg(new FindUserRequest().setOrgIds(orgIds));
if (byOrg == null || !byOrg.isSuccess()) {
return Lists.newArrayList();
}
List<User> userList = byOrg.getDataList(new TypeToken<List<User>>() { List<User> userList = byOrg.getDataList(new TypeToken<List<User>>() {
}.getType()); }.getType());
return userList; return userList;
...@@ -171,7 +176,7 @@ public class UserApiService { ...@@ -171,7 +176,7 @@ public class UserApiService {
public List<User> findAllUser() { public List<User> findAllUser() {
R<List<User>> listR = userService.findAll(); R<List<User>> listR = userService.findAll();
if (listR == null || !listR.isSuccess()) { if (listR == null || !listR.isSuccess()) {
return null; return Lists.newArrayList();
} }
List<User> userList = listR.getDataList(new TypeToken<List<User>>() { List<User> userList = listR.getDataList(new TypeToken<List<User>>() {
}.getType()); }.getType());
...@@ -179,18 +184,35 @@ public class UserApiService { ...@@ -179,18 +184,35 @@ public class UserApiService {
} }
/** /**
* 封装用户信息 key:门店编码 value:id * 封装用户信息 key:用户账号 value:用户对象
*
* @return
*/
public Map<String, User> findUserMapByAccount() {
Map<String, User> userMap = new HashedMap();
List<User> userList = this.findAllUser();
if (userList == null) {
return userMap;
}
for (User user : userList) {
userMap.put(user.getAccount(), user);
}
return userMap;
}
/**
* 封装用户信息 key:用户id value:用户对象
* *
* @return * @return
*/ */
public Map<String, Long> findUserIdMapByAccount() { public Map<Long, User> findUserMapByUserId() {
Map<String, Long> userMap = new HashedMap(); Map<Long, User> userMap = new HashedMap();
List<User> userList = this.findAllUser(); List<User> userList = this.findAllUser();
if (userList == null) { if (userList == null) {
return userMap; return userMap;
} }
for (User user : userList) { for (User user : userList) {
userMap.put(user.getAccount(), user.getId()); userMap.put(user.getId(), user);
} }
return userMap; return userMap;
} }
......
...@@ -1437,10 +1437,6 @@ public class VehicleService { ...@@ -1437,10 +1437,6 @@ public class VehicleService {
log.info("激活设备成功===设备号" + vehicleInfoImport.getSn()); log.info("激活设备成功===设备号" + vehicleInfoImport.getSn());
} }
public List<User> findAllUser() {
return userApiService.findAllUser();
}
public PageInfo<TestVehicleDTO> listTestDriveVehicle(TestVehicleSearch testVehicleSearch) { public PageInfo<TestVehicleDTO> listTestDriveVehicle(TestVehicleSearch testVehicleSearch) {
PageHelper.startPage(testVehicleSearch.getPageNumber(), testVehicleSearch.getPageSize()); PageHelper.startPage(testVehicleSearch.getPageNumber(), testVehicleSearch.getPageSize());
List<TestVehicleDTO> testVehicleVoList = vehicleMapper.listTestDriveVehicle(testVehicleSearch); List<TestVehicleDTO> testVehicleVoList = vehicleMapper.listTestDriveVehicle(testVehicleSearch);
......
package cn.com.glsx.admin.modules.service;
import cn.com.glsx.admin.modules.entity.TenantVehicleType;
import cn.com.glsx.admin.modules.mapper.TenantVehicleTypeMapper;
import com.glsx.biz.common.base.entity.CarInfoSelected;
import com.glsx.plat.core.enums.SysConstants;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Date;
import java.util.List;
@Slf4j
//@RunWith(SpringRunner.class)
//@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class VehicleTypeServiceTest {
@Autowired
private TenantVehicleTypeMapper tenantVehicleTypeMapper;
// @Test
public void test() throws IOException {
String testPath = "C:\\Users\\liuyu\\Desktop\\cartype_test.json";
String proPath = "C:\\Users\\liuyu\\Desktop\\cartype_pro.json";
JsonReader reader = new JsonReader(new FileReader(proPath));
Gson gson = new GsonBuilder().serializeNulls().create();
Long tenantId = 43L;
List<CarInfoSelected> allBrand = gson.fromJson(reader, new TypeToken<List<CarInfoSelected>>() {
}.getType());
Path path = Paths.get("C:\\Users\\liuyu\\Desktop\\cartype_pro.sql");
//创建文件
if (!Files.exists(path)) {
Files.createFile(path);
}
BufferedWriter bfw = Files.newBufferedWriter(path);
List<TenantVehicleType> tvTypeList = Lists.newArrayList();
allBrand.forEach(brand -> {
log.info("{} {}", brand.getId(), brand.getName());
if (CollectionUtils.isNotEmpty(brand.getChilds())) {
brand.getChilds().forEach(subBrand -> {
log.info("\t{} {}", subBrand.getId(), subBrand.getName());
if (CollectionUtils.isNotEmpty(subBrand.getChilds())) {
subBrand.getChilds().forEach(series -> {
log.info("\t\t" + series.getName());
if (CollectionUtils.isNotEmpty(series.getChilds())) {
series.getChilds().forEach(type -> {
if (type.getName().contains("2020") || type.getName().contains("2021") || type.getName().contains("2022")) {
log.info("\t\t\t" + type.getName());
TenantVehicleType tvType = new TenantVehicleType();
tvType.setTenantId(tenantId);
tvType.setTenantName("仲利国际");
tvType.setName(tvType.getTenantName() + "车型库");
tvType.setBrandId(brand.getId());
tvType.setBrandName(brand.getName());
tvType.setSubBrandId(subBrand.getId());
tvType.setSubBrandName(subBrand.getName());
tvType.setSeriesId(series.getId());
tvType.setSeriesName(series.getName());
tvType.setTypeId(type.getId());
tvType.setTypeName(type.getName());
tvType.setEnableStatus(SysConstants.EnableStatus.enable.getCode());
tvType.setCreatedBy(1L);
tvType.setCreatedDate(new Date());
tvTypeList.add(tvType);
String sql = "INSERT INTO t_tenant_vehicle_type (tenant_id, tenant_name, name, brand_id, brand_name, sub_brand_id, sub_brand_name, series_id, series_name, type_id, type_name, enable_status, del_flag, created_date, created_by) "
+ "VALUES ("
+ tvType.getTenantId() + ", '"
+ tvType.getTenantName() + "', '"
+ tvType.getName() + "', "
+ tvType.getBrandId() + ", '"
+ tvType.getBrandName() + "', "
+ tvType.getSubBrandId() + ", '"
+ tvType.getSubBrandName() + "', "
+ tvType.getSeriesId() + ", '"
+ tvType.getSeriesName() + "', " + tvType.getTypeId() + ", '" + tvType.getTypeName() + "', 1, 0, sysdate(), 1);\n";
try {
bfw.write(sql);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
});
}
});
}
});
bfw.flush();
bfw.close();
}
public static void main(String[] args) throws IOException {
VehicleTypeServiceTest serviceTest = new VehicleTypeServiceTest();
serviceTest.test();
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!