|
|
@@ -28,18 +28,23 @@ import com.fs.hisStore.service.IFsUserInformationCollectionService;
|
|
|
import com.fs.hisStore.vo.FsStoreOrderVO;
|
|
|
import com.fs.hisStore.vo.FsUserInformationCollectionOverviewVo;
|
|
|
import com.fs.qw.domain.FsCompanyCustomer;
|
|
|
+import com.fs.qw.dto.ImportCustomerDTO;
|
|
|
import com.fs.qw.service.IFsCompanyCustomerService;
|
|
|
import com.fs.qw.vo.CompanyUserAndDoctorVO;
|
|
|
+import com.fs.qw.vo.ImportResult;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -155,7 +160,68 @@ public class FsCompanyCustomerController extends BaseController {
|
|
|
log.error("导出客户信息数据异常",e);
|
|
|
throw new CustomException("客户信息数据异常");
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入客户数据(Excel)
|
|
|
+ * @param file 上传的 Excel 文件
|
|
|
+ * @return 导入结果
|
|
|
+ */
|
|
|
+ @PostMapping("/import")
|
|
|
+ public AjaxResult importCustomers(@RequestParam("file") MultipartFile file) {
|
|
|
+ try {
|
|
|
+ // 1. 解析 Excel
|
|
|
+ List<ImportCustomerDTO> list = parseExcel(file);
|
|
|
+ if (list.isEmpty()) {
|
|
|
+ return AjaxResult.error("未解析到有效数据,请检查文件格式(第3行起 B=姓名,C=手机,D=地址)");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 获取当前登录销售
|
|
|
+ LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
+ CompanyUser companyUser = loginUser.getUser();
|
|
|
+
|
|
|
+ // 3. 执行导入
|
|
|
+ ImportResult result = fsCompanyCustomerService.importCustomers(list, companyUser);
|
|
|
+
|
|
|
+ // 4. 返回结果
|
|
|
+ String msg = String.format("成功导入 %d 条,失败 %d 条", result.getSuccess(), result.getErrors().size());
|
|
|
+ return AjaxResult.success(msg, result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("导入客户数据异常", e);
|
|
|
+ return AjaxResult.error("导入失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析 Excel 文件(从第3行开始读取 A、B、C 列)
|
|
|
+ */
|
|
|
+ private List<ImportCustomerDTO> parseExcel(MultipartFile file) throws Exception {
|
|
|
+ List<ImportCustomerDTO> list = new ArrayList<>();
|
|
|
+ Workbook workbook = WorkbookFactory.create(file.getInputStream());
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ DataFormatter formatter = new DataFormatter();
|
|
|
+ int startRow = 2; // 第3行(0-based)
|
|
|
+
|
|
|
+ for (int i = startRow; i <= sheet.getLastRowNum(); i++) {
|
|
|
+ Row row = sheet.getRow(i);
|
|
|
+ if (row == null) continue;
|
|
|
+
|
|
|
+ String name = formatter.formatCellValue(row.getCell(0)); // A列
|
|
|
+ String phone = formatter.formatCellValue(row.getCell(1)); // B列
|
|
|
+ String address = formatter.formatCellValue(row.getCell(2)); // C列
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(name) || StringUtils.isEmpty(phone) || StringUtils.isEmpty(address)) {
|
|
|
+ continue; // 跳过空行
|
|
|
+ }
|
|
|
|
|
|
+ ImportCustomerDTO dto = new ImportCustomerDTO();
|
|
|
+ dto.setCustomerName(name);
|
|
|
+ dto.setPhone(phone);
|
|
|
+ dto.setAddress(address);
|
|
|
+ list.add(dto);
|
|
|
+ }
|
|
|
+ workbook.close();
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -359,30 +425,6 @@ public class FsCompanyCustomerController extends BaseController {
|
|
|
return toAjax( result);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 修改商城处方表的制单状态
|
|
|
- * */
|
|
|
- @PostMapping("/updateScrmPrescriptionDocumentSuccess")
|
|
|
- public AjaxResult updateScrmPrescriptionDocumentSuccess(@RequestBody FsCompanyCustomer fsCompanyCustomer){
|
|
|
- LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
- Long companyUserId = loginUser.getUser().getUserId();
|
|
|
- if (companyUserId == null){
|
|
|
- throw new CustomException("登录信息已过期,请重新登录");
|
|
|
- }
|
|
|
- FsCompanyCustomer companyCustomer = fsCompanyCustomerService.selectFsCompanyCustomerById(fsCompanyCustomer.getId());
|
|
|
- if (companyCustomer == null){
|
|
|
- return AjaxResult.error("未找到客户信息");
|
|
|
- }
|
|
|
- //重置客户信息表的流程状态为"待完善"
|
|
|
- companyCustomer.setProcessStatus(0);
|
|
|
- fsCompanyCustomerService.updateFsCompanyCustomer(companyCustomer);
|
|
|
- FsPrescribeDataScrm fsPrescribeDataScrm=new FsPrescribeDataScrm();
|
|
|
- fsPrescribeDataScrm.setPrescribeId(companyCustomer.getPrescribeId());
|
|
|
- fsPrescribeDataScrm.setIsDocument(1);//1-销售已制单
|
|
|
- int result=prescribeDataScrmService.updateFsPrescribeDataScrm(fsPrescribeDataScrm);
|
|
|
- return toAjax( result);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 生成客户信息表制单二维码
|
|
|
* */
|