文件上传 bast64

This commit is contained in:
haozq 2024-11-13 13:23:42 +08:00
parent c7b8378b78
commit 06c02c5e24
9 changed files with 50 additions and 29 deletions

View File

@ -72,7 +72,6 @@ public class PartApplyController {
/** /**
* 图片文件上传 * 图片文件上传
* @return * @return

View File

@ -50,7 +50,7 @@ public class PartInputController {
* @return * @return
*/ */
@PostMapping("addInputData") @PostMapping("addInputData")
public ServerResponse addInputData(HttpServletRequest request, @RequestParam("file[]") MultipartFile[] files) { public ServerResponse addInputData(HttpServletRequest request, @RequestParam(value = "file[]",required = false) MultipartFile[] files) {
return service.addInputData(request,files); return service.addInputData(request,files);
} }
@ -61,7 +61,7 @@ public class PartInputController {
* @return * @return
*/ */
@PostMapping("updateInputData") @PostMapping("updateInputData")
public ServerResponse updateInputData(HttpServletRequest request, @RequestParam("file[]") MultipartFile[] files) { public ServerResponse updateInputData(HttpServletRequest request, @RequestParam(value = "file[]",required = false) MultipartFile[] files) {
return service.updateInputData(request,files); return service.updateInputData(request,files);
} }

View File

@ -91,5 +91,20 @@ public class PartInputVo {
* 文件上传 集合 * 文件上传 集合
*/ */
private List<FileUploadVo> fileList; private List<FileUploadVo> fileList;
/**
*
*/
private String type;
/**
*
*/
private String name;
/**
*
*/
private String model;
} }

View File

@ -76,7 +76,7 @@ public interface PartInputMapper {
* 修改 入库信息 * 修改 入库信息
* @param list * @param list
*/ */
int uploadDetails(List<PartInputDetails> list); int uploadDetails(PartInputDetails data);
/** /**
* 更新1数据 * 更新1数据

View File

@ -48,10 +48,6 @@ public class PartInputServiceImpl implements PartInputService{
public List<PartInputVo> findByPage(PartInputVo data) { public List<PartInputVo> findByPage(PartInputVo data) {
List<PartInputVo> list=new ArrayList<>(); List<PartInputVo> list=new ArrayList<>();
try{ try{
if(StringHelper.isNotEmpty(data.getInputDay())){
data.setStartDay(data.getInputDay().split(" ~ ")[0]);
data.setEndDay(data.getInputDay().split(" ~ ")[1]);
}
list=mapper.findByPage(data); list=mapper.findByPage(data);
}catch (Exception e){ }catch (Exception e){
@ -177,20 +173,23 @@ public class PartInputServiceImpl implements PartInputService{
detail.setTotalPrice(totalPrice.toString()); detail.setTotalPrice(totalPrice.toString());
}); });
//修改详情 //修改详情
int num2= mapper.uploadDetails(list); int num2=0;
for (int i = 0; i <list.size() ; i++) {
int num3= mapper.uploadDetails(list.get(i));
num2=num2+num3;
}
if(num2!=list.size()){ if(num2!=list.size()){
return ServerResponse.createErroe("修改失败"); return ServerResponse.createErroe("修改失败");
}else{ }else{
list.forEach(detail->{ list.forEach(detail->{
//更新 -及平准单价 //更新 -及平准单价
// String pzPrice=mapper.getPzPrice(detail); // String pzPrice=mapper.getPzPrice(detail);
mapper.updateTypeNum2(detail.getPartId(),detail.getPartPrice()); mapper.updateTypeNum2(detail.getPartId(),detail.getPartPrice());
}); });
} }
} }
//文件上传 //文件上传
if(files!=null || files.length>0){ if(files!=null && files.length>0){
List<FileUploadVo> fileList=uploadService.uploadImage(files,vo.getId(),"t_part_input",null); List<FileUploadVo> fileList=uploadService.uploadImage(files,vo.getId(),"t_part_input",null);
if(StringUtils.isEmpty(fileList) || fileList.size()!=files.length){ if(StringUtils.isEmpty(fileList) || fileList.size()!=files.length){
return ServerResponse.createErroe("入库失败"); return ServerResponse.createErroe("入库失败");
@ -198,18 +197,18 @@ public class PartInputServiceImpl implements PartInputService{
} }
List<PartInputDetails> childerList=mapper.getInputDetailList(vo); List<PartInputDetails> childerList=mapper.getInputDetailList(vo);
AtomicReference<String> isFlag= new AtomicReference<>("1"); AtomicReference<String> isFlag= new AtomicReference<>("1");
BigDecimal allPrice = new BigDecimal("0"); final BigDecimal[] allPrice = {new BigDecimal("0")};
childerList.forEach(data->{ childerList.forEach(data->{
BigDecimal price = new BigDecimal(data.getPartPrice()); BigDecimal price = new BigDecimal(data.getPartPrice());
BigDecimal num = new BigDecimal(data.getInputNum()); BigDecimal num = new BigDecimal(data.getInputNum());
BigDecimal totalPrice = price.multiply(num); BigDecimal totalPrice = price.multiply(num);
allPrice.add(totalPrice); allPrice[0] = allPrice[0].add(totalPrice);
if("0".equals(data.getPartPrice())){ if("0".equals(data.getPartPrice())){
isFlag.set("0"); isFlag.set("0");
} }
}); });
vo.setIsFlag(isFlag.get()); vo.setIsFlag(isFlag.get());
vo.setAllPrice(allPrice.toString()); vo.setAllPrice(allPrice[0].toString());
int num3= mapper.updateInputData(vo); int num3= mapper.updateInputData(vo);
if(num3>0){ if(num3>0){
return ServerResponse.createSuccess("修改成功","修改成功"); return ServerResponse.createSuccess("修改成功","修改成功");

View File

@ -42,11 +42,11 @@ public class FileUploadService {
try { try {
for (String bast64 : files) { for (String bast64 : files) {
String fileName=IDUtils.createID()+".png"; String fileName=IDUtils.createID()+".png";
String filePath= DateTimeHelper.getNowYMD()+"/"+ fileName; String filePath= "/"+DateTimeHelper.getNowYMD()+"/"+ fileName;
String newPath= SystemUtils.getUploadPath()+filePath; String newPath= SystemUtils.getUploadPath()+filePath;
// 解码Base64字符串 // 解码Base64字符串
byte[] decodedBytes = Base64.getDecoder().decode(bast64); byte[] decodedBytes = Base64.getDecoder().decode(bast64);
try (FileOutputStream fileOutputStream = new FileOutputStream(filePath)) { try (FileOutputStream fileOutputStream = new FileOutputStream(newPath)) {
// 将字节写入文件 // 将字节写入文件
fileOutputStream.write(decodedBytes); fileOutputStream.write(decodedBytes);
} catch (IOException e) { } catch (IOException e) {
@ -54,7 +54,7 @@ public class FileUploadService {
} }
FileUploadVo vo=new FileUploadVo(); FileUploadVo vo=new FileUploadVo();
vo.setFileName(fileName); vo.setFileName(fileName);
vo.setFileUrl(newPath); vo.setFileUrl(filePath);
vo.setOwnId(outId); vo.setOwnId(outId);
vo.setModelTable(table); vo.setModelTable(table);
vo.setSuffix(".png"); vo.setSuffix(".png");
@ -86,7 +86,7 @@ public class FileUploadService {
for (MultipartFile file : files) { for (MultipartFile file : files) {
String fileName = file.getOriginalFilename(); String fileName = file.getOriginalFilename();
String suffix=IDUtils.getSuffix(fileName); String suffix=IDUtils.getSuffix(fileName);
String path= DateTimeHelper.getNowYMD()+"/"+ IDUtils.createID()+suffix; String path="/"+DateTimeHelper.getNowYMD()+"/"+ IDUtils.createID()+suffix;
String newPath= SystemUtils.getUploadPath()+path; String newPath= SystemUtils.getUploadPath()+path;
File uploadFile = new File(newPath); File uploadFile = new File(newPath);
//生成文件夹 //生成文件夹

View File

@ -39,7 +39,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
String filePath= SystemUtils.getUploadPath();//获取文件上传路径 String filePath= SystemUtils.getUploadPath();//获取文件上传路径
/** 本地文件上传路径 */ /** 本地文件上传路径 */
registry.addResourceHandler("/statics/**") registry.addResourceHandler("/statics/**")
.addResourceLocations("file:" + filePath); .addResourceLocations("file:" + filePath+"/");
registry.addResourceHandler("/files/**") registry.addResourceHandler("/files/**")
.addResourceLocations("file:"+filePath); .addResourceLocations("file:"+filePath);
} }

View File

@ -40,8 +40,8 @@ zhly:
file: file:
upload_path: upload_path:
windows: D://files/zg_gqj/ windows: D://files/zg_gqj
linux: /home/zg_gqj/files/ linux: /home/zg_gqj/files

View File

@ -29,11 +29,9 @@
</update> </update>
<update id="uploadDetails"> <update id="uploadDetails">
<foreach close="" collection="list" index="index" item="item" open="" separator=";"> update t_part_put_details set part_price=#{partPrice}, vender_id=#{vendId},
update t_part_put_details set part_price=#{item.partPrice}, vender_id=#{item.vendId}, total_price=#{totalPrice},vender_name=#{vendName}
total_price=#{item.totalPrice}, set vender_name=#{item.vendName} where id=#{id}
where id=#{item.id}
</foreach>
</update> </update>
<update id="updateInputData"> <update id="updateInputData">
update t_part_input set updater=#{updater},update_time=now(),all_price=#{allPrice}, update t_part_input set updater=#{updater},update_time=now(),all_price=#{allPrice},
@ -49,15 +47,16 @@
<where> <where>
<if test="keyWord!=null and keyWord!=''"> <if test="keyWord!=null and keyWord!=''">
and (tpi.code like concat('%',#{keyWord},'%') or and (tpi.code like concat('%',#{keyWord},'%') or
tpi.creator like concat('%',#{keyWord},'%') or tpi.input_user like concat('%',#{keyWord},'%') or
tpi.input_day like concat('%',#{keyWord},'%') or tpi.input_day like concat('%',#{keyWord},'%') or
tpi.remark like concat('%',#{keyWord},'%') tpi.remark like concat('%',#{keyWord},'%')
) )
</if> </if>
<if test="inputDay!=null and inputDay!='' and startDay!=null and endDay!=null "> <if test="startDay!=null and startDay!='' and endDay!=null and endDay!='' ">
and STR_TO_DATE(tpi.input_day, '%Y-%m-%d') between STR_TO_DATE(#{startDay} ,'%Y-%m-%d') AND STR_TO_DATE(#{endDay},'%Y-%m-%d') and STR_TO_DATE(tpi.input_day, '%Y-%m-%d') between STR_TO_DATE(#{startDay} ,'%Y-%m-%d') AND STR_TO_DATE(#{endDay},'%Y-%m-%d')
</if> </if>
</where> </where>
order by tpi.create_time desc
</select> </select>
<!--入库数量--> <!--入库数量-->
<select id="getInputNum" resultType="java.lang.Integer"> <select id="getInputNum" resultType="java.lang.Integer">
@ -87,9 +86,18 @@
select ppd.id, ppd.put_id inputId,ppd.part_id partId, ppd.part_type partType, select ppd.id, ppd.put_id inputId,ppd.part_id partId, ppd.part_type partType,
ppd.part_name partName, ppd.part_model partModel, ppd.part_unit partUnit, ppd.input_num inputNum, ppd.part_name partName, ppd.part_model partModel, ppd.part_unit partUnit, ppd.input_num inputNum,
ppd.part_price partPrice, ppd.total_price totalPrice, ppd.vender_id vendId, ppd.part_price partPrice, ppd.total_price totalPrice, ppd.vender_id vendId,
ppd.vender_name vendName ppd.vender_name vendName,remark
FROM t_part_put_details ppd FROM t_part_put_details ppd
where ppd.put_id=#{id} where ppd.put_id=#{id}
<if test="type!=null and type!=''">
and ppd.part_type like concat('%',#{type},'%')
</if>
<if test="name!=null and name!=''">
and ppd.part_name like concat('%',#{name},'%')
</if>
<if test="model!=null and model!=''">
and ppd.part_model like concat('%',#{model},'%')
</if>
</select> </select>
<select id="getPzPrice" resultType="java.lang.String"> <select id="getPzPrice" resultType="java.lang.String">
select ROUND(IFNULL(AVG(part_price),0),2) price select ROUND(IFNULL(AVG(part_price),0),2) price