供应商的导入导出功能

This commit is contained in:
yinjinlu-pc\尹金路 2024-01-08 17:56:03 +08:00
parent 060d347933
commit e804d20b07
3 changed files with 88 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ktg.common.constant.UserConstants;
import com.ktg.common.core.domain.entity.SysUser;
import com.ktg.mes.wm.utils.WmBarCodeUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
@ -23,6 +24,7 @@ import com.ktg.mes.md.domain.MdVendor;
import com.ktg.mes.md.service.IMdVendorService;
import com.ktg.common.utils.poi.ExcelUtil;
import com.ktg.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;
/**
* 供应商Controller
@ -64,6 +66,26 @@ public class MdVendorController extends BaseController
util.exportExcel(response, list, "供应商数据");
}
@PostMapping("/importTemplate")
public void importTemplate(HttpServletResponse response)
{
ExcelUtil<MdVendor> util = new ExcelUtil<MdVendor>(MdVendor.class);
util.importTemplateExcel(response, "供应商数据");
}
@Log(title = "供应商", businessType = BusinessType.IMPORT)
@PreAuthorize("@ss.hasPermi('system:user:import')")
@PostMapping("/importData")
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
{
ExcelUtil<MdVendor> util = new ExcelUtil<MdVendor>(MdVendor.class);
List<MdVendor> vendorList = util.importExcel(file.getInputStream());
String operName = getUsername();
String message = mdVendorService.importVendor(vendorList, updateSupport, operName);
return AjaxResult.success(message);
}
/**
* 获取供应商详细信息
*/

View File

@ -31,6 +31,16 @@ public interface IMdVendorService
public String checkVendorNameUnique(MdVendor mdVendor);
public String checkVendorNickUnique(MdVendor mdVendor);
/**
* 导入供应商信息
* @param vendorList
* @param isUpdateSupport
* @param operName
* @return
*/
public String importVendor(List<MdVendor> vendorList, Boolean isUpdateSupport, String operName);
/**
* 新增供应商
*

View File

@ -3,8 +3,11 @@ package com.ktg.mes.md.service.impl;
import java.util.List;
import com.ktg.common.constant.UserConstants;
import com.ktg.common.core.domain.entity.SysUser;
import com.ktg.common.exception.ServiceException;
import com.ktg.common.utils.DateUtils;
import com.ktg.common.utils.StringUtils;
import com.ktg.common.utils.bean.BeanValidators;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -12,6 +15,8 @@ import com.ktg.mes.md.mapper.MdVendorMapper;
import com.ktg.mes.md.domain.MdVendor;
import com.ktg.mes.md.service.IMdVendorService;
import javax.validation.Validator;
/**
* 供应商Service业务层处理
*
@ -24,6 +29,9 @@ public class MdVendorServiceImpl implements IMdVendorService
@Autowired
private MdVendorMapper mdVendorMapper;
@Autowired
protected Validator validator;
/**
* 查询供应商
*
@ -78,6 +86,54 @@ public class MdVendorServiceImpl implements IMdVendorService
return UserConstants.UNIQUE;
}
@Override
public String importVendor(List<MdVendor> vendorList, Boolean isUpdateSupport, String operName) {
if (StringUtils.isNull(vendorList) || vendorList.size() == 0)
{
throw new ServiceException("导入供应商数据不能为空!");
}
int successNum = 0;
int failureNum = 0;
StringBuilder successMsg = new StringBuilder();
StringBuilder failureMsg = new StringBuilder();
for (MdVendor vendor : vendorList)
{
try{
//是否存在
MdVendor v = mdVendorMapper.checkVendorCodeUnique(vendor);
if(StringUtils.isNull(v)){
BeanValidators.validateWithException(validator, vendor);
this.insertMdVendor(vendor);
successNum++;
}else if (isUpdateSupport){
BeanValidators.validateWithException(validator, vendor);
vendor.setUpdateBy(operName);
vendor.setVendorId(v.getVendorId());
this.updateMdVendor(vendor);
successNum++;
}else {
failureNum++;
failureMsg.append("<br/>" + failureNum + "、供应商 " + vendor.getVendorName() + " 已存在");
}
}catch (Exception e){
failureNum++;
String msg = "<br/>" + failureNum + "、供应商 " + vendor.getVendorName() + " 导入失败:";
failureMsg.append(msg + e.getMessage());
}
if (failureNum > 0)
{
failureMsg.insert(0, "导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
throw new ServiceException(failureMsg.toString());
}
else
{
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
}
}
return successMsg.toString();
}
/**
* 新增供应商
*