Commit 73a78212 by zhaoxiaolei

上传校验

parent c4d2be67
......@@ -23,6 +23,8 @@ import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;
/**
......@@ -115,9 +117,9 @@ public class CharacteristicController {
* @param dto
* @param response
*/
@PostMapping("/exportCharacteristic")
@ApiOperation(value = "特征管理 导出特征", notes = "特征管理 导出特征", httpMethod = "POST")
public void exportCharacteristic(@RequestBody CharacteristicRequestParamDto dto, HttpServletResponse response){
@GetMapping("/exportCharacteristic")
@ApiOperation(value = "特征管理 导出特征", notes = "特征管理 导出特征", httpMethod = "GET")
public void exportCharacteristic(CharacteristicRequestParamDto dto, HttpServletResponse response) throws ParseException, IOException {
characteristicService.exportCharacteristic(dto,response);
}
......
......@@ -103,9 +103,9 @@ public class CharacteristicValueController {
* @param dto
* @param response
*/
@PostMapping("/exportCharacteristicValue")
@ApiOperation(value = "特征值管理 导出特征值", notes = "特征值管理 导出特征值", httpMethod = "GPOSTET")
public void exportCharacteristicValue(@RequestBody CharacteristicValueRequestParamDto dto, HttpServletResponse response){
@GetMapping("/exportCharacteristicValue")
@ApiOperation(value = "特征值管理 导出特征值", notes = "特征值管理 导出特征值", httpMethod = "GET")
public void exportCharacteristicValue(CharacteristicValueRequestParamDto dto, HttpServletResponse response){
characteristicValueService.exportCharacteristicValue(dto,response);
}
......
......@@ -75,9 +75,9 @@ public class SuperBomPriceCalculateController {
* @param dto
* @param response
*/
@PostMapping("/exportCharacteristicValuePrice")
@ApiOperation(value = "特征值价格管理 导出特征值价格", notes = "特征值价格管理 导出特征值价格", httpMethod = "POST")
public void exportCharacteristicValuePrice(@RequestBody CharacteristicValueExportDto dto, HttpServletResponse response){
@GetMapping("/exportCharacteristicValuePrice")
@ApiOperation(value = "特征值价格管理 导出特征值价格", notes = "特征值价格管理 导出特征值价格", httpMethod = "GET")
public void exportCharacteristicValuePrice( CharacteristicValueExportDto dto, HttpServletResponse response){
superBomPriceCalculateService.exportCharacteristicValuePrice(dto,response);
}
......
......@@ -27,6 +27,8 @@ public class CharacteristicExportDto implements Serializable {
*/
@FieldNameMapping(name = "superBomCode", value = "SuperBOM")
private String superBomCode;
@FieldNameMapping(name = "superBomName", value = "superBomName")
private String superBomName;
/**
* 特征编码
*/
......
......@@ -23,6 +23,8 @@ public class CharacteristicValueExportDto implements Serializable{
*/
@FieldNameMapping(name = "superBomCode", value = "SuperBOM")
private String superBomCode;
@FieldNameMapping(name = "superBomName", value = "superBomName")
private String superBomName;
/**
* 特征编码
......
......@@ -8,6 +8,9 @@ import com.github.pagehelper.PageInfo;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.List;
/**
......@@ -57,7 +60,7 @@ public interface CharacteristicService {
Object updateCharacteristicIsH3C(CharacteristicRequestParamDto dto);
void exportCharacteristic(CharacteristicRequestParamDto dto, HttpServletResponse response);
void exportCharacteristic(CharacteristicRequestParamDto dto, HttpServletResponse response) throws ParseException, IOException;
Object batchUpdateByUpload(MultipartFile file);
}
......@@ -72,7 +72,7 @@ public interface CharacteristicValueService {
* @param file
* @return
*/
String batchUpdateByUpload(MultipartFile file);
Object batchUpdateByUpload(MultipartFile file);
/**
* @desc 询配询价 导出可用配置和OD关系表
......
......@@ -4,6 +4,7 @@ import cn.com.uitech.authorization.exception.BizException;
import cn.com.uitech.authorization.mapper.CharacteristicMapper;
import cn.com.uitech.authorization.pojo.dto.CharacteristicExportDto;
import cn.com.uitech.authorization.pojo.dto.CharacteristicRequestParamDto;
import cn.com.uitech.authorization.pojo.dto.GetProductOutDto;
import cn.com.uitech.authorization.pojo.entity.Characteristic;
import cn.com.uitech.authorization.service.CharacteristicService;
import cn.com.uitech.authorization.service.CtoBomService;
......@@ -29,8 +30,11 @@ import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.*;
/**
......@@ -131,9 +135,8 @@ public class CharacteristicServiceImpl implements CharacteristicService {
}
@Override
public void exportCharacteristic(CharacteristicRequestParamDto dto, HttpServletResponse response) {
public void exportCharacteristic(CharacteristicRequestParamDto dto, HttpServletResponse response) throws ParseException, IOException {
//根据页面输入框查询要导出的数据
try {
Date date = DateUitl.getNowAll();
String format = DateUitl.format(date, "yyyy-MM-dd");
String[] split = format.split("-");
......@@ -146,11 +149,11 @@ public class CharacteristicServiceImpl implements CharacteristicService {
List<CharacteristicExportDto> excelDtos = new ArrayList<>();
HSSFWorkbook wb = new HSSFWorkbook();
file = dto.getSuperBomCode() + worktableTitle + ".xls";
//根据页面输入框查询要导出的数据
priceModelList = characteristicMapper.exportCharacteristic(dto);
excelDtos = exportStandBom(priceModelList);
wb = exportExcelBom(excelDtos);
file = dto.getSuperBomCode() + priceModelList.get(0).getSuperBomName() + "特征信息" + ".xls";
String filename = null;
filename = new String(file.getBytes("GBK"), StandardCharsets.ISO_8859_1);
......@@ -160,9 +163,6 @@ public class CharacteristicServiceImpl implements CharacteristicService {
ServletOutputStream outputStream = response.getOutputStream();
wb.write(outputStream);
outputStream.close();
} catch (Exception e) {
throw new BizException(ApiResult.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
private List<CharacteristicExportDto> exportStandBom(List<CharacteristicExportDto> priceModelList) {
......@@ -299,26 +299,37 @@ public class CharacteristicServiceImpl implements CharacteristicService {
* @desc 特征管理 上传文件更新
*/
@Override
public String batchUpdateByUpload(MultipartFile file) {
int result = 0;
//判断文件是否为空
if (null == file || file.isEmpty()) {
throw new BizException(ApiResult.API_REQ_DATA_IS_FAIL, "特征上传文件批量更新-上传文件为空");
}
//读取文件内容
List<CharacteristicExportDto> list = uploadExcl(file);
//非空校验
if (!CollectionUtils.isEmpty(list)) {
ArrayList<String> checkFileIsNull = checkFileIsNull(list);
if (!CollectionUtils.isEmpty(checkFileIsNull)) {
return String.valueOf(checkFileIsNull);
public GetProductOutDto batchUpdateByUpload(MultipartFile file) {
GetProductOutDto result = new GetProductOutDto();
try {
//判断文件是否为空
if (null == file || file.isEmpty()) {
throw new BizException(ApiResult.API_REQ_DATA_IS_FAIL, "特征上传文件批量更新-上传文件为空");
}
} else {
//读取文件内容
List<CharacteristicExportDto> list = uploadExcl(file);
//非空校验
if (!CollectionUtils.isEmpty(list)) {
ArrayList<String> checkFileIsNull = checkFileIsNull(list);
if (!CollectionUtils.isEmpty(checkFileIsNull)) {
result.setData(null);
result.setMsg(String.valueOf(checkFileIsNull));
result.setCode(500);
return result;
}
} else {
}
updateData(list);
result.setData(null);
result.setMsg("更新附件内容成功");
result.setCode(200);
return result;
} catch (Exception e) {
result.setData(null);
result.setMsg("特征上传文件批量更新-请检查上传文件");
result.setCode(500);
return result;
}
updateData(list);
return "更新附件内容成功";
}
/**
......@@ -379,12 +390,11 @@ public class CharacteristicServiceImpl implements CharacteristicService {
* @return List<CharacteristicExportDto>
* @desc 解析上传文件
*/
public List<CharacteristicExportDto> uploadExcl(MultipartFile file) {
long startDate = Calendar.getInstance().getTimeInMillis();
List<CharacteristicExportDto> list = Lists.newArrayList();
Workbook wook = null;
public List<CharacteristicExportDto> uploadExcl(MultipartFile file) throws IOException {
List<CharacteristicExportDto> list = Lists.newArrayList();
try {
Workbook wook = null;
String filename = file.getOriginalFilename();
if (filename.endsWith("xls")) {
ZipSecureFile.setMinInflateRatio(-1.0d);
......@@ -400,16 +410,21 @@ public class CharacteristicServiceImpl implements CharacteristicService {
int rows = sheetAt.getPhysicalNumberOfRows();
for (int j = 1; j < rows; j++) {
Row row = sheetAt.getRow(j);
int cells = row.getPhysicalNumberOfCells();
//把每条数据封装进对象里
CharacteristicExportDto dto = setCharacteristicExportDto(row, cells);
list.add(dto);
Integer cells = row.getPhysicalNumberOfCells();
if (cells.equals(6)) {
//把每条数据封装进对象里
CharacteristicExportDto dto = setCharacteristicExportDto(row, cells);
list.add(dto);
} else {
throw new BizException(ApiResult.API_REQ_DATA_IS_FAIL, "特征上传文件批量更新-请检查上传文件");
}
}
}
} catch (Exception e) {
e.printStackTrace();
}catch (Exception e){
throw new BizException(ApiResult.API_REQ_DATA_IS_FAIL, "特征上传文件批量更新-请检查上传文件");
}
long endDate = Calendar.getInstance().getTimeInMillis();
return list;
}
......
......@@ -218,11 +218,11 @@ public class CharacteristicValueServiceImpl implements CharacteristicValueServic
List<CharacteristicValueExportDto> excelDtos = new ArrayList<>();
HSSFWorkbook wb = new HSSFWorkbook();
file = dto.getSuperBomCode() + worktableTitle + ".xls";
//根据页面输入框查询要导出的数据
priceModelList = characteristicValueMapper.exportCharacteristicValue(dto);
excelDtos = exportStandBom(priceModelList);
wb = exportExcelBom(excelDtos);
file = dto.getSuperBomCode() + priceModelList.get(0).getSuperBomName() + "特征值信息" + ".xls";
String filename = null;
filename = new String(file.getBytes("GBK"), StandardCharsets.ISO_8859_1);
......@@ -444,8 +444,9 @@ public class CharacteristicValueServiceImpl implements CharacteristicValueServic
* @desc 特征值管理 上传文件更新
*/
@Override
public String batchUpdateByUpload(MultipartFile file) {
int result = 0;
public GetProductOutDto batchUpdateByUpload(MultipartFile file) {
GetProductOutDto result = new GetProductOutDto();
try {
//判断文件是否为空
if (null == file || file.isEmpty()) {
throw new BizException(ApiResult.API_REQ_DATA_IS_FAIL, "特征值上传文件批量更新-上传文件为空");
......@@ -456,13 +457,23 @@ public class CharacteristicValueServiceImpl implements CharacteristicValueServic
if (!CollectionUtils.isEmpty(list)) {
ArrayList<String> checkFileIsNull = checkFileIsNull(list);
if (!CollectionUtils.isEmpty(checkFileIsNull)) {
return String.valueOf(checkFileIsNull);
result.setData(null);
result.setMsg(String.valueOf(checkFileIsNull));
result.setCode(500);
return result;
}
} else {
}
updateData(list);
return "更新附件内容成功";
result.setData(null);
result.setMsg("更新附件内容成功");
result.setCode(200);
return result;
} catch (Exception e) {
result.setData(null);
result.setMsg("特征值上传文件批量更新-请检查上传文件");
result.setCode(500);
return result;
}
}
......@@ -528,7 +539,6 @@ public class CharacteristicValueServiceImpl implements CharacteristicValueServic
* @desc 解析上传文件
*/
public List<CharacteristicValueExportDto> uploadExcl(MultipartFile file) {
long startDate = Calendar.getInstance().getTimeInMillis();
List<CharacteristicValueExportDto> list = Lists.newArrayList();
Workbook wook = null;
......@@ -548,16 +558,19 @@ public class CharacteristicValueServiceImpl implements CharacteristicValueServic
int rows = sheetAt.getPhysicalNumberOfRows();
for (int j = 1; j < rows; j++) {
Row row = sheetAt.getRow(j);
int cells = row.getPhysicalNumberOfCells();
//把每条数据封装进对象里
CharacteristicValueExportDto dto = setCharacteristicValueExportDto(row, cells);
list.add(dto);
Integer cells = row.getPhysicalNumberOfCells();
if (cells.equals(12)) {
//把每条数据封装进对象里
CharacteristicValueExportDto dto = setCharacteristicValueExportDto(row, cells);
list.add(dto);
} else {
throw new BizException(ApiResult.API_REQ_DATA_IS_FAIL, "特征值上传文件批量更新-请检查上传文件");
}
}
}
} catch (Exception e) {
e.printStackTrace();
throw new BizException(ApiResult.API_REQ_DATA_IS_FAIL, "特征值上传文件批量更新-请检查上传文件");
}
long endDate = Calendar.getInstance().getTimeInMillis();
return list;
}
......
......@@ -275,7 +275,6 @@ public class SuperBomPriceCalculateServiceImpl implements SuperBomPriceCalculate
List<SuperCharacterPriceInfoDto> excelDtos = new ArrayList<>();
HSSFWorkbook wb = new HSSFWorkbook();
file = "特征值价格" + worktableTitle + ".xls";
//根据页面输入框查询要导出的数据
priceModelList = superBomPriceCalculateMapper.exportCharacteristicValuePrice(dto);
if (ObjectUtils.isEmpty(priceModelList)) {
......@@ -313,6 +312,7 @@ public class SuperBomPriceCalculateServiceImpl implements SuperBomPriceCalculate
excelDtos = exportStandBom(priceModelList);
wb = exportExcelBom(excelDtos);
file = priceModelList.get(0).getSuperBomCode() + priceModelList.get(0).getSuperBomName() + "特征值价格信息" + ".xls";
String filename = null;
filename = new String(file.getBytes("GBK"), StandardCharsets.ISO_8859_1);
response.setContentType("APPLICATION/OCTET-STREAM");
......@@ -548,8 +548,9 @@ public class SuperBomPriceCalculateServiceImpl implements SuperBomPriceCalculate
* @desc 特征值价格管理 上传文件更新
*/
@Override
public String batchUpdateByUpload(MultipartFile file) {
int result = 0;
public GetProductOutDto batchUpdateByUpload(MultipartFile file) {
GetProductOutDto result = new GetProductOutDto();
try {
//判断文件是否为空
if (null == file || file.isEmpty()) {
throw new BizException(ApiResult.API_REQ_DATA_IS_FAIL, "特征值价格上传文件批量更新-上传文件为空");
......@@ -560,13 +561,23 @@ public class SuperBomPriceCalculateServiceImpl implements SuperBomPriceCalculate
if (!CollectionUtils.isEmpty(list)) {
ArrayList<String> checkFileIsNull = checkFileIsNull(list);
if (!CollectionUtils.isEmpty(checkFileIsNull)) {
return String.valueOf(checkFileIsNull);
result.setData(null);
result.setMsg(String.valueOf(checkFileIsNull));
result.setCode(500);
return result;
}
} else {
}
updateData(list);
return "更新附件内容成功";
result.setData(null);
result.setMsg("更新附件内容成功");
result.setCode(200);
return result;
} catch (Exception e) {
result.setData(null);
result.setMsg("特征值价格上传文件批量更新-请检查上传文件");
result.setCode(500);
return result;
}
}
......@@ -645,7 +656,6 @@ public class SuperBomPriceCalculateServiceImpl implements SuperBomPriceCalculate
* @desc 解析上传文件
*/
public List<SuperCharacterPriceInfoDto> uploadExcl(MultipartFile file) {
long startDate = Calendar.getInstance().getTimeInMillis();
List<SuperCharacterPriceInfoDto> list = Lists.newArrayList();
Workbook wook = null;
......@@ -665,16 +675,19 @@ public class SuperBomPriceCalculateServiceImpl implements SuperBomPriceCalculate
int rows = sheetAt.getPhysicalNumberOfRows();
for (int j = 1; j < rows; j++) {
Row row = sheetAt.getRow(j);
int cells = row.getPhysicalNumberOfCells();
//把每条数据封装进对象里
SuperCharacterPriceInfoDto dto = setCharacteristicPriceExportDto(row, cells);
list.add(dto);
Integer cells = row.getPhysicalNumberOfCells();
if (cells.equals(14)) {
//把每条数据封装进对象里
SuperCharacterPriceInfoDto dto = setCharacteristicPriceExportDto(row, cells);
list.add(dto);
} else {
throw new BizException(ApiResult.API_REQ_DATA_IS_FAIL, "特征值价格上传文件批量更新-请检查上传文件");
}
}
}
} catch (Exception e) {
e.printStackTrace();
throw new BizException(ApiResult.API_REQ_DATA_IS_FAIL, "特征值价格上传文件批量更新-请检查上传文件");
}
long endDate = Calendar.getInstance().getTimeInMillis();
return list;
}
......
......@@ -238,6 +238,7 @@
select
sort,
a.super_bom_code as superBomCode,
b.super_bom_name as superBomName,
characteristic_code as characteristicCode,
characteristic_name as characteristicName,
unis_sales_c_name as unisSalesCName,
......
......@@ -164,6 +164,7 @@
resultType="cn.com.uitech.authorization.pojo.dto.CharacteristicValueExportDto">
SELECT DISTINCT
a.super_bom_code as superBomCode,
c.super_bom_name as superBomName,
a.Characteristic_Code as CharacteristicCode,
b.unis_Sales_C_Name as CharacteristicName,
A.Characteristic_Value_Code AS CharacteristicValueCode,
......@@ -180,7 +181,7 @@
b.sort
FROM
super_characteristic_value_info
A LEFT JOIN super_characteristic_info b ON A.Characteristic_Code = b.Characteristic_Code
A LEFT JOIN super_characteristic_info b ON A.Characteristic_Code = b.Characteristic_Code AND A.super_bom_code = B.super_bom_code
LEFT JOIN super_bom_info C ON b.super_BOM_Code = c.super_BOM_Code
<where>
<if test="productClassCode!=null and productClassCode!=''">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment