委托方导入
This commit is contained in:
+60
@@ -359,6 +359,66 @@ public class UserShipperApplicationService {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 Excel 导入委托方
|
||||
* 模版列:登录账号、公司名称、联系人、联系电话、地址、详细地址、备注、结算币种
|
||||
*/
|
||||
public com.mhd.common.core.web.domain.AjaxResult importShipperFromExcel(org.springframework.web.multipart.MultipartFile file) {
|
||||
if (file == null || file.isEmpty()) {
|
||||
return com.mhd.common.core.web.domain.AjaxResult.error("文件不能为空");
|
||||
}
|
||||
try {
|
||||
org.apache.poi.ss.usermodel.Workbook workbook = org.apache.poi.ss.usermodel.WorkbookFactory.create(file.getInputStream());
|
||||
org.apache.poi.ss.usermodel.Sheet sheet = workbook.getSheetAt(0);
|
||||
int total = 0, success = 0, failed = 0;
|
||||
java.util.List<String> errors = new java.util.ArrayList<>();
|
||||
for (int i = 1; i <= sheet.getLastRowNum(); i++) {
|
||||
org.apache.poi.ss.usermodel.Row row = sheet.getRow(i);
|
||||
if (row == null) continue;
|
||||
String userAccount = getCellStr(row.getCell(0));
|
||||
String companyName = getCellStr(row.getCell(1));
|
||||
if (org.springframework.util.StringUtils.isEmpty(companyName)) continue;
|
||||
total++;
|
||||
try {
|
||||
UserShipperDO shipperDO = new UserShipperDO();
|
||||
shipperDO.setShipperType(2);
|
||||
shipperDO.setDataSource(2);
|
||||
shipperDO.setUserAccount(userAccount);
|
||||
shipperDO.setShipperEnterpriseName(companyName);
|
||||
shipperDO.setEmergencyContactName(getCellStr(row.getCell(2)));
|
||||
shipperDO.setEmergencyContactPhone(getCellStr(row.getCell(3)));
|
||||
shipperDO.setArea(getCellStr(row.getCell(4)));
|
||||
shipperDO.setDetailAddress(getCellStr(row.getCell(5)));
|
||||
shipperDO.setRemark(getCellStr(row.getCell(6)));
|
||||
shipperDO.setSettlementCurrency(getCellStr(row.getCell(7)));
|
||||
addShipper(shipperDO);
|
||||
success++;
|
||||
} catch (Exception e) {
|
||||
failed++;
|
||||
errors.add("第" + (i + 1) + "行[" + companyName + "]导入失败:" + e.getMessage());
|
||||
log.error("导入委托方第{}行失败", i + 1, e);
|
||||
}
|
||||
}
|
||||
workbook.close();
|
||||
java.util.Map<String, Object> result = new java.util.HashMap<>();
|
||||
result.put("total", total);
|
||||
result.put("success", success);
|
||||
result.put("failed", failed);
|
||||
result.put("errorMessages", errors);
|
||||
return com.mhd.common.core.web.domain.AjaxResult.success("导入完成", result);
|
||||
} catch (Exception e) {
|
||||
log.error("解析Excel失败", e);
|
||||
return com.mhd.common.core.web.domain.AjaxResult.error("解析Excel失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private String getCellStr(org.apache.poi.ss.usermodel.Cell cell) {
|
||||
if (cell == null) return null;
|
||||
cell.setCellType(org.apache.poi.ss.usermodel.CellType.STRING);
|
||||
String v = cell.getStringCellValue();
|
||||
return v == null ? null : v.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 个人货主认证
|
||||
*
|
||||
|
||||
@@ -352,8 +352,20 @@ public class UserShipperAPI extends BaseController {
|
||||
@PostMapping("/wxGetPhoneNumber")
|
||||
public AjaxResult wxGetPhoneNumber(@RequestBody com.mhd.user.interfaces.dto.wechat.WxPhoneNumberDTO dto) {
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
Long organizationId = (loginUser != null && loginUser.getUserPo() != null)
|
||||
Long organizationId = (loginUser != null && loginUser.getUserPo() != null)
|
||||
? loginUser.getUserPo().getOrganizationId() : null;
|
||||
return wechatMiniAppService.wxGetPhoneNumber(dto, organizationId);
|
||||
}
|
||||
|
||||
@Log(title = "托运人管理-导入", description = "从Excel导入委托方", businessType = BusinessType.IMPORT)
|
||||
@ApiOperation("导入委托方(Excel批量)")
|
||||
@PostMapping("/import")
|
||||
public AjaxResult importShipper(@RequestParam("file") org.springframework.web.multipart.MultipartFile file) {
|
||||
try {
|
||||
return userShipperApplicationService.importShipperFromExcel(file);
|
||||
} catch (Exception e) {
|
||||
log.error("导入委托方失败", e);
|
||||
return AjaxResult.error("导入失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,9 @@
|
||||
AND b.del_flag = 1
|
||||
</sql>
|
||||
<sql id="selectShipperVo1">
|
||||
SELECT b.shipper_id,
|
||||
SELECT b.area,
|
||||
b.detail_address,
|
||||
b.shipper_id,
|
||||
a.user_id,
|
||||
b.parent_shipper_id,
|
||||
b.shipper_type,
|
||||
|
||||
Reference in New Issue
Block a user