|
|
@@ -5,6 +5,10 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.fs.FSAdminApplication;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.exception.CustomException;
|
|
|
+import com.fs.company.domain.Company;
|
|
|
+import com.fs.company.domain.CompanyUser;
|
|
|
+import com.fs.company.mapper.CompanyMapper;
|
|
|
+import com.fs.company.mapper.CompanyUserMapper;
|
|
|
import com.fs.erp.dto.*;
|
|
|
import com.fs.erp.http.JstErpHttpService;
|
|
|
import com.fs.erp.service.FsJstAftersalePushService;
|
|
|
@@ -46,18 +50,22 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
|
|
|
-@RunWith(SpringRunner.class)
|
|
|
+
|
|
|
+@RunWith(org.springframework.test.context.junit4.SpringRunner.class)
|
|
|
@SpringBootTest(classes = FSAdminApplication.class)
|
|
|
-@RequiredArgsConstructor
|
|
|
@Slf4j
|
|
|
public class FsStorePaymentControllerTest {
|
|
|
|
|
|
@@ -104,6 +112,93 @@ public class FsStorePaymentControllerTest {
|
|
|
@Autowired
|
|
|
private FsJstAftersalePushService fsJstAftersalePushService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CompanyUserMapper companyUserMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CompanyMapper companyMapper;
|
|
|
+
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void generatePwd(){
|
|
|
+ BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
|
|
+ String encode = passwordEncoder.encode("123456");
|
|
|
+ log.info(encode);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void fixData(){
|
|
|
+
|
|
|
+
|
|
|
+ String csvPath = "C:\\Users\\Administrator\\Desktop\\无标题.csv";
|
|
|
+
|
|
|
+ // 统计变量
|
|
|
+ int totalRecords = 0;
|
|
|
+ int successCount = 0;
|
|
|
+ int userNotFoundCount = 0;
|
|
|
+ int companyNotFoundCount = 0;
|
|
|
+ int errorCount = 0;
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 读取CSV文件
|
|
|
+ List<String> lines = Files.readAllLines(Paths.get(csvPath));
|
|
|
+ totalRecords = lines.size();
|
|
|
+
|
|
|
+ log.info("开始处理CSV数据,共{}条记录", totalRecords);
|
|
|
+
|
|
|
+ for (String line : lines) {
|
|
|
+ try {
|
|
|
+ // 跳过空行
|
|
|
+ if (line == null || line.trim().isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String[] split1 = line.split(",");
|
|
|
+
|
|
|
+ String username = split1[2].trim().replace("\"","").replaceAll("[$\\\\]", "");
|
|
|
+ String companyName = split1[4].trim().replace("\"","").replaceAll("[$\\\\]", "");
|
|
|
+
|
|
|
+ // 查找用户
|
|
|
+ CompanyUser companyUser = companyUserMapper.selectCompanyUserByUsername(username);
|
|
|
+ if (companyUser == null) {
|
|
|
+ log.info("用户 {} 没有找到,已经跳过!", username);
|
|
|
+ userNotFoundCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查找公司
|
|
|
+ Company company = companyMapper.selectCompanyByCompanyName(companyName);
|
|
|
+ if (company == null) {
|
|
|
+ log.info("公司 {} 找不到,跳过更新用户 {} 的公司关联!", companyName, username);
|
|
|
+ companyNotFoundCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新用户公司关联
|
|
|
+ companyUser.setCompanyId(company.getCompanyId());
|
|
|
+ companyUser.setPassword(null);
|
|
|
+ companyUserMapper.updateCompanyUser(companyUser);
|
|
|
+ log.info("成功更新用户 {} 的公司关联为 {}", username, companyName);
|
|
|
+ successCount++;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("处理行数据时发生错误: {}", line, e);
|
|
|
+ errorCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("读取CSV文件时发生错误", e);
|
|
|
+ } finally {
|
|
|
+ // 输出统计结果
|
|
|
+ log.info("数据修复完成,统计结果如下:");
|
|
|
+ log.info("总记录数: {}", totalRecords);
|
|
|
+ log.info("成功更新: {}", successCount);
|
|
|
+ log.info("用户不存在: {}", userNotFoundCount);
|
|
|
+ log.info("公司不存在: {}", companyNotFoundCount);
|
|
|
+ log.info("处理错误: {}", errorCount);
|
|
|
+ }
|
|
|
+ }
|
|
|
@Test
|
|
|
public void pushJstTest(){
|
|
|
fsJstAftersalePushService.pushJst();
|