单位类型
This commit is contained in:
parent
9ddaa2d7b8
commit
36ea481926
|
|
@ -13,6 +13,16 @@ public class MaterialConstants
|
||||||
*/
|
*/
|
||||||
public static final String UTF8 = "UTF-8";
|
public static final String UTF8 = "UTF-8";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xls
|
||||||
|
*/
|
||||||
|
public static final String XLS = "xls";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XLSX
|
||||||
|
*/
|
||||||
|
public static final String XLSX = "xlsx";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 身份证正则表达式
|
* 身份证正则表达式
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,116 @@
|
||||||
|
package com.bonus.material.basic.controller;
|
||||||
|
|
||||||
|
import com.bonus.common.core.utils.poi.ExcelUtil;
|
||||||
|
import com.bonus.common.core.web.controller.BaseController;
|
||||||
|
import com.bonus.common.core.web.domain.AjaxResult;
|
||||||
|
import com.bonus.common.core.web.page.TableDataInfo;
|
||||||
|
import com.bonus.common.log.annotation.SysLog;
|
||||||
|
import com.bonus.common.log.enums.OperaType;
|
||||||
|
import com.bonus.common.security.annotation.RequiresPermissions;
|
||||||
|
import com.bonus.material.basic.domain.BmUnit;
|
||||||
|
import com.bonus.material.basic.domain.BmUnitType;
|
||||||
|
import com.bonus.material.basic.service.IBmUnitTypeService;
|
||||||
|
import com.bonus.material.common.annotation.PreventRepeatSubmit;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ma_sh
|
||||||
|
* @create 2024/10/14 15:25
|
||||||
|
*/
|
||||||
|
@Api(tags = "往来单位管理接口")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/bm_unit_type")
|
||||||
|
public class BmUnitTypeController extends BaseController {
|
||||||
|
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IBmUnitTypeService bmUnitTypeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询往来单位类型管理列表
|
||||||
|
*/
|
||||||
|
@ApiOperation(value = "查询往来单位类型管理列表")
|
||||||
|
@RequiresPermissions("basic:unitType:list")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public TableDataInfo list(BmUnitType bmUnitType)
|
||||||
|
{
|
||||||
|
startPage();
|
||||||
|
List<BmUnitType> list = bmUnitTypeService.selectBmUnitList(bmUnitType);
|
||||||
|
return getDataTable(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "获取往来单位类型详细信息")
|
||||||
|
@RequiresPermissions("basic:unitType:query")
|
||||||
|
@GetMapping(value = "/{typeId}")
|
||||||
|
public AjaxResult getInfo(@PathVariable("id") Long typeId)
|
||||||
|
{
|
||||||
|
return AjaxResult.success(bmUnitTypeService.selectListByID(typeId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "新增往来单位类型管理")
|
||||||
|
@RequiresPermissions("basic:unitType:add")
|
||||||
|
@PostMapping
|
||||||
|
public AjaxResult add(@RequestBody BmUnitType bmUnitType)
|
||||||
|
{
|
||||||
|
return bmUnitTypeService.insertBmUnitType(bmUnitType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "修改往来单位类型管理")
|
||||||
|
@RequiresPermissions("basic:unitType:edit")
|
||||||
|
@PutMapping
|
||||||
|
public AjaxResult edit(@RequestBody BmUnitType bmUnitType)
|
||||||
|
{
|
||||||
|
return bmUnitTypeService.updateBmUnitType(bmUnitType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "删除往来单位类型管理")
|
||||||
|
@RequiresPermissions("basic:unitType:remove")
|
||||||
|
@DeleteMapping("/{typeId}")
|
||||||
|
public AjaxResult remove(@PathVariable Long typeId)
|
||||||
|
{
|
||||||
|
return bmUnitTypeService.deleteBmUnitTypeByUnitTypeIds(typeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入模版下载
|
||||||
|
*/
|
||||||
|
@PostMapping("/downLoad")
|
||||||
|
public void downLoadExcelFile(){
|
||||||
|
HttpServletResponse resp = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
|
||||||
|
bmUnitTypeService.downLoadTemplate(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "导入往来单位类型管理列表")
|
||||||
|
@PreventRepeatSubmit
|
||||||
|
@RequiresPermissions("basic:unitType:importData")
|
||||||
|
@SysLog(title = "往来单位类型管理导入", businessType = OperaType.EXPORT, logType = 1,module = "仓储管理->导入往来单位类型管理列表")
|
||||||
|
@PostMapping("/importData")
|
||||||
|
public AjaxResult importData(MultipartFile file)
|
||||||
|
{
|
||||||
|
return bmUnitTypeService.importData(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出往来单位类型管理列表
|
||||||
|
*/
|
||||||
|
@ApiOperation(value = "导出往来单位类型管理列表")
|
||||||
|
@PreventRepeatSubmit
|
||||||
|
@RequiresPermissions("basic:unitType:export")
|
||||||
|
@SysLog(title = "往来单位管理", businessType = OperaType.EXPORT, logType = 1,module = "仓储管理->导出往来单位类型管理")
|
||||||
|
@PostMapping("/export")
|
||||||
|
public void export(HttpServletResponse response, BmUnitType bmUnitType)
|
||||||
|
{
|
||||||
|
List<BmUnitType> list = bmUnitTypeService.selectBmUnitList(bmUnitType);
|
||||||
|
ExcelUtil<BmUnitType> util = new ExcelUtil<BmUnitType>(BmUnitType.class);
|
||||||
|
util.exportExcel(response, list, "往来单位管理数据");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.bonus.material.basic.domain;
|
||||||
|
|
||||||
|
import com.bonus.common.core.web.domain.BaseEntity;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ma_sh
|
||||||
|
* @create 2024/10/14 15:29
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class BmUnitType extends BaseEntity {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "主键id")
|
||||||
|
private Long typeId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "单位类型名称")
|
||||||
|
private String typeName;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "数据所属组织")
|
||||||
|
private String companyId;
|
||||||
|
|
||||||
|
/** 删除标志(0代表存在 2代表删除) */
|
||||||
|
private String delFlag;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "单位类型状态 0代表启用,1代表不启用")
|
||||||
|
private int status;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
package com.bonus.material.basic.mapper;
|
||||||
|
|
||||||
|
import com.bonus.material.basic.domain.BmUnitType;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ma_sh
|
||||||
|
* @create 2024/10/14 15:27
|
||||||
|
*/
|
||||||
|
public interface BmUnitTypeMapper {
|
||||||
|
/**
|
||||||
|
* 查询单位类型列表
|
||||||
|
* @param bmUnitType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<BmUnitType> selectBmUnitList(BmUnitType bmUnitType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据主键查询单位类型
|
||||||
|
* @param typeId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
BmUnitType selectListByID(Long typeId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据类型名称查询单位类型
|
||||||
|
* @param typeName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
BmUnitType selectBmUnitTypeByTypeName(String typeName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增单位类型
|
||||||
|
* @param bmUnitType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int insertBmUnitType(BmUnitType bmUnitType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改单位类型
|
||||||
|
* @param bmUnitType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int updateBmUnitType(BmUnitType bmUnitType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除单位类型
|
||||||
|
* @param typeId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int deleteBmUnitTypeByUnitTypeIds(Long typeId);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,64 @@
|
||||||
|
package com.bonus.material.basic.service;
|
||||||
|
|
||||||
|
import com.bonus.common.core.web.domain.AjaxResult;
|
||||||
|
import com.bonus.material.basic.domain.BmUnit;
|
||||||
|
import com.bonus.material.basic.domain.BmUnitType;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ma_sh
|
||||||
|
* @create 2024/10/14 15:26
|
||||||
|
*/
|
||||||
|
public interface IBmUnitTypeService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询单位类型列表
|
||||||
|
* @param bmUnitType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<BmUnitType> selectBmUnitList(BmUnitType bmUnitType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询单位类型
|
||||||
|
* @param typeId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
BmUnitType selectListByID(Long typeId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增单位类型
|
||||||
|
* @param bmUnitType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
AjaxResult insertBmUnitType(BmUnitType bmUnitType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改单位类型
|
||||||
|
* @param bmUnitType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
AjaxResult updateBmUnitType(BmUnitType bmUnitType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除单位类型
|
||||||
|
* @param typeId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
AjaxResult deleteBmUnitTypeByUnitTypeIds(Long typeId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入模板
|
||||||
|
* @param resp
|
||||||
|
*/
|
||||||
|
void downLoadTemplate(HttpServletResponse resp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入数据
|
||||||
|
* @param file
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
AjaxResult importData(MultipartFile file);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,256 @@
|
||||||
|
package com.bonus.material.basic.service.impl;
|
||||||
|
|
||||||
|
import com.bonus.common.biz.constant.MaterialConstants;
|
||||||
|
import com.bonus.common.biz.enums.HttpCodeEnum;
|
||||||
|
import com.bonus.common.core.utils.StringUtils;
|
||||||
|
import com.bonus.common.core.utils.poi.ExcelUtil;
|
||||||
|
import com.bonus.common.core.web.domain.AjaxResult;
|
||||||
|
import com.bonus.material.basic.domain.BmUnitType;
|
||||||
|
import com.bonus.material.basic.mapper.BmUnitTypeMapper;
|
||||||
|
import com.bonus.material.basic.service.IBmUnitTypeService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.poi.ss.usermodel.*;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ma_sh
|
||||||
|
* @create 2024/10/14 15:26
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class BmUnitTypeServiceImpl implements IBmUnitTypeService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private BmUnitTypeMapper bmUnitTypeMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询单位类型关联单位列表
|
||||||
|
* @param bmUnitType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<BmUnitType> selectBmUnitList(BmUnitType bmUnitType) {
|
||||||
|
return bmUnitTypeMapper.selectBmUnitList(bmUnitType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询单位类型关联单位
|
||||||
|
* @param typeId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public BmUnitType selectListByID(Long typeId) {
|
||||||
|
return bmUnitTypeMapper.selectListByID(typeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增单位类型列表
|
||||||
|
* @param bmUnitType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public AjaxResult insertBmUnitType(BmUnitType bmUnitType) {
|
||||||
|
//根据单位类型名称查询,去重
|
||||||
|
BmUnitType unitType = bmUnitTypeMapper.selectBmUnitTypeByTypeName(bmUnitType.getTypeName());
|
||||||
|
if (unitType != null) {
|
||||||
|
return AjaxResult.error(HttpCodeEnum.NAME_DUPLICATE.getCode(), HttpCodeEnum.NAME_DUPLICATE.getMsg());
|
||||||
|
}
|
||||||
|
int result = bmUnitTypeMapper.insertBmUnitType(bmUnitType);
|
||||||
|
if (result > 0) {
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改单位类型列表
|
||||||
|
* @param bmUnitType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public AjaxResult updateBmUnitType(BmUnitType bmUnitType) {
|
||||||
|
//根据单位类型名称查询,去重
|
||||||
|
BmUnitType unitType = bmUnitTypeMapper.selectBmUnitTypeByTypeName(bmUnitType.getTypeName());
|
||||||
|
if (unitType != null) {
|
||||||
|
if (!Objects.equals(unitType.getTypeName(), bmUnitType.getTypeName())) {
|
||||||
|
return AjaxResult.error(HttpCodeEnum.NAME_DUPLICATE.getCode(), HttpCodeEnum.NAME_DUPLICATE.getMsg());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int result = bmUnitTypeMapper.updateBmUnitType(bmUnitType);
|
||||||
|
if (result > 0) {
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除单位类型列表
|
||||||
|
* @param typeId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public AjaxResult deleteBmUnitTypeByUnitTypeIds(Long typeId) {
|
||||||
|
//首先根据单位类型查询是否关联单位
|
||||||
|
int result = bmUnitTypeMapper.deleteBmUnitTypeByUnitTypeIds(typeId);
|
||||||
|
if (result > 0) {
|
||||||
|
return AjaxResult.success(HttpCodeEnum.SUCCESS.getMsg(), result);
|
||||||
|
}
|
||||||
|
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downLoadTemplate(HttpServletResponse response) {
|
||||||
|
//模板名称
|
||||||
|
String templateName = "BmUnitTypeTemplate.xlsx";
|
||||||
|
OutputStream out = null;
|
||||||
|
InputStream input = null;
|
||||||
|
try {
|
||||||
|
input = this.getClass().getClassLoader().getResourceAsStream("template/BmUnitTypeTemplate.xlsx");
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.setHeader("content-Type", "application/vnd.ms-excel");
|
||||||
|
response.setHeader("Content-Disposition",
|
||||||
|
"attachment;filename=" + new String((templateName).getBytes(), "iso-8859-1"));
|
||||||
|
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||||
|
out = response.getOutputStream();
|
||||||
|
// 缓冲区
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int bytesToRead = -1;
|
||||||
|
// 通过循环将读入内容输出到浏览器中
|
||||||
|
while ((bytesToRead = input.read(buffer)) != -1) {
|
||||||
|
out.write(buffer, 0, bytesToRead);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
} finally {
|
||||||
|
IOUtils.closeQuietly(input);
|
||||||
|
IOUtils.closeQuietly(out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入单位类型列表
|
||||||
|
* @param file
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public AjaxResult importData(MultipartFile file) {
|
||||||
|
String fileName = file.getOriginalFilename();
|
||||||
|
if (fileName != null) {
|
||||||
|
String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||||
|
if (!MaterialConstants.XLSX.equalsIgnoreCase(fileExtension)) {
|
||||||
|
// 文件后缀名不符合要求
|
||||||
|
return AjaxResult.error("导入失败:文件后缀名不符合要求,必须为xlsx结尾");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
InputStream inputStream = file.getInputStream();
|
||||||
|
Workbook workbook = new XSSFWorkbook(inputStream);
|
||||||
|
|
||||||
|
Sheet sheet = workbook.getSheetAt(0);
|
||||||
|
// 得到Excel的行数
|
||||||
|
int totalRows = sheet.getPhysicalNumberOfRows();
|
||||||
|
|
||||||
|
// 检查是否有行数
|
||||||
|
if (totalRows <= 1) {
|
||||||
|
throw new IllegalArgumentException("导入失败:Excel文件中没有数据,请检查后重新导入");
|
||||||
|
}
|
||||||
|
// 读取第一行表头
|
||||||
|
Row headerRow = sheet.getRow(0);
|
||||||
|
|
||||||
|
if (headerRow == null) {
|
||||||
|
throw new IllegalArgumentException("导入失败:文件中没有表头");
|
||||||
|
}
|
||||||
|
// 获取表头的列数
|
||||||
|
int totalCells = headerRow.getPhysicalNumberOfCells();
|
||||||
|
// 假设预期的表头列数为2列,可以根据实际需求修改这个条件
|
||||||
|
if (totalCells != 2) {
|
||||||
|
throw new IllegalArgumentException("导入失败:表头列数与预期不符,请检查导入模板");
|
||||||
|
}
|
||||||
|
// 读取表头内容并验证每一列,看是否符合模版要求
|
||||||
|
for (int cellNum = 0; cellNum < totalCells; cellNum++) {
|
||||||
|
Cell cell = headerRow.getCell(cellNum);
|
||||||
|
// 获取单元格内容并去除首尾空格
|
||||||
|
String headerValue = cell.getStringCellValue().trim();
|
||||||
|
// 根据列索引进行验证
|
||||||
|
switch (cellNum) {
|
||||||
|
case 0:
|
||||||
|
if (!"单位类型".equals(headerValue)) {
|
||||||
|
throw new IllegalArgumentException("第 " + (cellNum + 1) + " 列表头列名与预期不符,请检查导入模板");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
if (!"状态(0 启用 1 不启用)".equals(headerValue)) {
|
||||||
|
throw new IllegalArgumentException("第 " + (cellNum + 1) + " 列表头列名与预期不符,请检查导入模板");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//读取Excel表格数据,做非空判断
|
||||||
|
// 循环Excel行数
|
||||||
|
DataFormatter dataFormatter = new DataFormatter();
|
||||||
|
for (int r = 1; r < totalRows; r++) {
|
||||||
|
Row row = sheet.getRow(r);
|
||||||
|
// 循环Excel列数
|
||||||
|
for (int c = 0; c < totalCells; c++) {
|
||||||
|
String cellValue = dataFormatter.formatCellValue(row.getCell(c));
|
||||||
|
switch (c) {
|
||||||
|
case 0:
|
||||||
|
checkCellNotEmpty(cellValue, r, c);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
checkCellNotEmpty(cellValue, r, c);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
String.format("第 %d 行,第 %d 列超出范围,请检查后重新导入", r + 1, c + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ExcelUtil<BmUnitType> util = new ExcelUtil<>(BmUnitType.class);
|
||||||
|
List<BmUnitType> bmUnitTypeList = util.importExcel(file.getInputStream());
|
||||||
|
int result = 0;
|
||||||
|
for (BmUnitType bmUnitType : bmUnitTypeList) {
|
||||||
|
//根据单位类型名称查询,去重
|
||||||
|
BmUnitType unitType = bmUnitTypeMapper.selectBmUnitTypeByTypeName(bmUnitType.getTypeName());
|
||||||
|
if (unitType != null) {
|
||||||
|
//进行更新操作
|
||||||
|
result += bmUnitTypeMapper.updateBmUnitType(unitType);
|
||||||
|
} else {
|
||||||
|
result += bmUnitTypeMapper.insertBmUnitType(bmUnitType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (result > 0) {
|
||||||
|
return AjaxResult.success(HttpCodeEnum.SUCCESS.getMsg(), result);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提取方法用于检查单元格内容是否为空,并抛出异常
|
||||||
|
* @param cellValue
|
||||||
|
* @param rowNum
|
||||||
|
* @param colNum
|
||||||
|
*/
|
||||||
|
private void checkCellNotEmpty(String cellValue, int rowNum, int colNum) {
|
||||||
|
if (StringUtils.isBlank(cellValue)) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
String.format("第 %d 行,第 %d 列数据为空,请检查后重新导入", rowNum + 1, colNum + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,64 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.bonus.material.basic.mapper.BmUnitTypeMapper">
|
||||||
|
<insert id="insertBmUnitType">
|
||||||
|
insert into bm_unit_type
|
||||||
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="typeName != null and typeName != ''">type_name,</if>
|
||||||
|
<if test="status != null">status,</if>
|
||||||
|
<if test="companyId != null">company_id,</if>
|
||||||
|
del_flag,
|
||||||
|
<if test="createBy != null">create_by,</if>
|
||||||
|
<if test="createTime != null">create_time,</if>
|
||||||
|
<if test="updateBy != null">update_by,</if>
|
||||||
|
<if test="updateTime != null">update_time,</if>
|
||||||
|
</trim>
|
||||||
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="typeName != null and typeName != ''">#{typeName},</if>
|
||||||
|
<if test="status != null">#{status},</if>
|
||||||
|
<if test="companyId != null">#{companyId},</if>
|
||||||
|
0,
|
||||||
|
<if test="createBy != null">#{createBy},</if>
|
||||||
|
<if test="createTime != null">#{createTime},</if>
|
||||||
|
<if test="updateBy != null">#{updateBy},</if>
|
||||||
|
<if test="updateTime != null">#{updateTime},</if>
|
||||||
|
</trim>
|
||||||
|
</insert>
|
||||||
|
<update id="updateBmUnitType">
|
||||||
|
update bm_unit_type
|
||||||
|
<trim prefix="SET" suffixOverrides=",">
|
||||||
|
<if test="typeName != null and typeName != ''">type_name = #{typeName},</if>
|
||||||
|
<if test="status != null">status = #{status},</if>
|
||||||
|
<if test="companyId != null">company_id = #{companyId},</if>
|
||||||
|
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||||
|
<if test="updateTime !=null">update_time = #{updateTime},</if>
|
||||||
|
</trim>
|
||||||
|
where type_id = #{typeId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<delete id="deleteBmUnitTypeByUnitTypeIds">
|
||||||
|
update bm_unit_type set del_flag = 2 where type_id = #{typeId}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<select id="selectBmUnitList" resultType="com.bonus.material.basic.domain.BmUnitType">
|
||||||
|
select type_id as typeId, type_name as typeName, company_id as companyId, del_flag as delFlag, status as status
|
||||||
|
from bm_unit_type
|
||||||
|
where
|
||||||
|
del_flag = '0'
|
||||||
|
<if test="typeName != null and typeName != ''">
|
||||||
|
AND type_name like concat('%', #{typeName}, '%')
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectListByID" resultType="com.bonus.material.basic.domain.BmUnitType">
|
||||||
|
select type_id as typeId, type_name as typeName, company_id as companyId, del_flag as delFlag, status as status from bm_unit_type
|
||||||
|
where del_flag = '0' and type_id = #{typeId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectBmUnitTypeByTypeName" resultType="com.bonus.material.basic.domain.BmUnitType">
|
||||||
|
select type_id as typeId, type_name as typeName, company_id as companyId, del_flag as delFlag, status as status from bm_unit_type
|
||||||
|
where del_flag = '0' and type_name = #{typeName}
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
Binary file not shown.
Loading…
Reference in New Issue