diff --git a/sgzb-modules/sgzb-base/pom.xml b/sgzb-modules/sgzb-base/pom.xml index 67ee6982..39f009a8 100644 --- a/sgzb-modules/sgzb-base/pom.xml +++ b/sgzb-modules/sgzb-base/pom.xml @@ -23,6 +23,9 @@ spring-cloud-starter-alibaba-nacos-discovery + + + com.alibaba.cloud @@ -117,4 +120,4 @@ - \ No newline at end of file + diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/controller/MaPartTypeController.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/controller/MaPartTypeController.java index 6bf802a2..9a175038 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/controller/MaPartTypeController.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/controller/MaPartTypeController.java @@ -1,19 +1,30 @@ package com.bonus.sgzb.base.controller; import com.bonus.sgzb.base.domain.MaPartType; +import com.bonus.sgzb.base.service.ExcelService; import com.bonus.sgzb.base.service.IPartTypeService; import com.bonus.sgzb.common.core.utils.poi.ExcelUtil; import com.bonus.sgzb.common.core.web.controller.BaseController; import com.bonus.sgzb.common.core.web.domain.AjaxResult; -import com.bonus.sgzb.common.core.web.page.TableDataInfo; import com.bonus.sgzb.common.security.utils.SecurityUtils; -import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; 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.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.List; +import java.util.Map; ; @@ -32,25 +43,32 @@ public class MaPartTypeController extends BaseController { @Autowired private IPartTypeService maPartTypeService; + @Autowired + private ExcelService excelService; + + private static final String UPLOAD_DIR = "D:/work/wcy"; + + /** * 查询配件类型列表 + * * @param maPartType * @return */ @GetMapping("/list") - public AjaxResult list(MaPartType maPartType) - { + public AjaxResult list(MaPartType maPartType) { List list = maPartTypeService.selectMaPartList(maPartType); return AjaxResult.success(list); } /** * 新增配件管理 + * * @param maPartType * @return */ @PostMapping - public AjaxResult add(@Validated @RequestBody MaPartType maPartType){ + public AjaxResult add(@Validated @RequestBody MaPartType maPartType) { if (!maPartTypeService.checkPaNameUnique(maPartType)) { return error("新增配件名称'" + maPartType.getPaName() + "'失败,配件名称已存在"); } @@ -60,53 +78,84 @@ public class MaPartTypeController extends BaseController { /** * 导出配件类型管理 + * * @param response * @param maPartType */ @PostMapping("/export") - public void export(HttpServletResponse response, MaPartType maPartType) - { + public void export(HttpServletResponse response, MaPartType maPartType) { List list = maPartTypeService.selectMyPartTypeList(maPartType); ExcelUtil util = new ExcelUtil(MaPartType.class); util.exportExcel(response, list, "配件类型管理数据"); } - /** - * 删除配件管理类型 - * @param paId - * @return - */ - @DeleteMapping("/{paId}") - public AjaxResult delete(@PathVariable("paId") Long paId){ - if (maPartTypeService.hasChildBypaId(paId)) - { - return warn("存在下级仓库列表,不允许删除"); + @PostMapping("/readExcel") + public AjaxResult readExcelFile(@RequestParam("file") MultipartFile file) throws IOException { + // 创建上传目录,如果不存在的话 + File dir = new File(UPLOAD_DIR); + if (!dir.exists()) { + dir.mkdirs(); } - return toAjax(maPartTypeService.deletePaById(paId)); + + // 获取文件名 + String fileName = file.getOriginalFilename(); + + // 定义文件路径 + Path filePath = Paths.get(UPLOAD_DIR, fileName); + + // 保存文件 + file.transferTo(filePath.toFile()); + + Map>> stringMapMap = excelService.readExcelFile(filePath.toString()); + return AjaxResult.success(); } - /** - * 根据id获取数据 - * @param paId - * @return - */ - @GetMapping("/{paId}") - public AjaxResult getById(@PathVariable("paId") Long paId){ - MaPartType bean = maPartTypeService.getById(paId); - return AjaxResult.success(bean); - } - - /** - * 根据id修改数据 - * @param maPartType - * @return - */ - @PostMapping("/updateById") - public AjaxResult updateById(@RequestBody MaPartType maPartType){ - maPartType.setUpdateBy(SecurityUtils.getUsername()); - return toAjax(maPartTypeService.updateById(maPartType)); + @PostMapping("/downLoad") + public void downLoadExcelFile() throws IOException { + HttpServletResponse resp = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse(); + maPartTypeService.downLoadTemplate(resp); } -} + /** + * poi + * 删除配件管理类型 + * + * @param paId + * @return + */ + @DeleteMapping("/{paId}") + public AjaxResult delete (@PathVariable("paId") Long paId){ + if (maPartTypeService.hasChildBypaId(paId)) { + return warn("存在下级仓库列表,不允许删除"); + } + return toAjax(maPartTypeService.deletePaById(paId)); + } + + /** + * 根据id获取数据 + * + * @param paId + * @return + */ + @GetMapping("/{paId}") + public AjaxResult getById (@PathVariable("paId") Long paId){ + MaPartType bean = maPartTypeService.getById(paId); + return AjaxResult.success(bean); + } + + /** + * 根据id修改数据 + * + * @param maPartType + * @return + */ + @PostMapping("/updateById") + public AjaxResult updateById (@RequestBody MaPartType maPartType){ + maPartType.setUpdateBy(SecurityUtils.getUsername()); + return toAjax(maPartTypeService.updateById(maPartType)); + } + + + } diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/MaPartType.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/MaPartType.java index 16515b46..495c4646 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/MaPartType.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/MaPartType.java @@ -88,5 +88,7 @@ public class MaPartType extends BaseEntity { private String firstLevel; + + } diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/IPartTypeService.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/IPartTypeService.java index 34e844aa..42762b63 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/IPartTypeService.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/IPartTypeService.java @@ -3,6 +3,8 @@ package com.bonus.sgzb.base.service; import com.bonus.sgzb.base.domain.MaPartType; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.util.List; /** @@ -58,6 +60,9 @@ public interface IPartTypeService { MaPartType getById(Long paId); int updateById(MaPartType maPartType); + + + void downLoadTemplate(HttpServletResponse resp) throws IOException; } diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/MaPartTypeServiceImpl.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/MaPartTypeServiceImpl.java index 64d4c25b..fbf5648d 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/MaPartTypeServiceImpl.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/MaPartTypeServiceImpl.java @@ -5,10 +5,20 @@ import com.bonus.sgzb.base.mapper.MaPartTypeMapper; import com.bonus.sgzb.base.service.IPartTypeService; import com.bonus.sgzb.common.core.constant.UserConstants; import com.bonus.sgzb.common.core.utils.StringUtils; +import org.apache.commons.io.IOUtils; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.system.ApplicationHome; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; -import java.util.List; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.util.*; /** * 配件类型管理ma_part_type(MaPartType)表服务实现类 @@ -21,8 +31,10 @@ public class MaPartTypeServiceImpl implements IPartTypeService { @Autowired private MaPartTypeMapper maPartTypeMapper; + /** * 校验配件名称唯一性 + * * @param maPartType * @return */ @@ -30,8 +42,7 @@ public class MaPartTypeServiceImpl implements IPartTypeService { public boolean checkPaNameUnique(MaPartType maPartType) { Long paId = StringUtils.isNull(maPartType.getPaId()) ? -1L : maPartType.getPaId(); MaPartType info = maPartTypeMapper.checkPartNameUnique(maPartType.getPaId()); - if (StringUtils.isNotNull(info) && info.getPaId().longValue() != paId.longValue()) - { + if (StringUtils.isNotNull(info) && info.getPaId().longValue() != paId.longValue()) { return UserConstants.NOT_UNIQUE; } return UserConstants.UNIQUE; @@ -39,6 +50,7 @@ public class MaPartTypeServiceImpl implements IPartTypeService { /** * 新增配件管理 + * * @param maPartType * @return */ @@ -50,6 +62,7 @@ public class MaPartTypeServiceImpl implements IPartTypeService { /** * 查询配件类型列表 + * * @param maPartType * @return */ @@ -60,6 +73,7 @@ public class MaPartTypeServiceImpl implements IPartTypeService { /** * 导出配件管理类型 + * * @param maPartType * @return */ @@ -70,6 +84,7 @@ public class MaPartTypeServiceImpl implements IPartTypeService { /** * 查询是否含有子集 + * * @param paId * @return */ @@ -81,6 +96,7 @@ public class MaPartTypeServiceImpl implements IPartTypeService { /** * 删除配件类型 + * * @param paId * @return */ @@ -98,5 +114,38 @@ public class MaPartTypeServiceImpl implements IPartTypeService { public int updateById(MaPartType maPartType) { return maPartTypeMapper.updateById(maPartType); } -} + @Override + public void downLoadTemplate(HttpServletResponse response) throws IOException { + //模板名称 + String templateName = "template.xlsx"; + OutputStream out = null; + InputStream input =null; + try { + ApplicationHome h = new ApplicationHome(getClass()); + String dirPath = h.getSource().toString(); + String fileName = dirPath+"/template/"+templateName; + File outFile = new File(fileName); + input = new BufferedInputStream(new FileInputStream(outFile)); + 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) { + throw new IOException("模板下载失败"); + } finally { + IOUtils.closeQuietly(input); + IOUtils.closeQuietly(out); + } + } + + +} diff --git a/sgzb-modules/sgzb-base/src/main/resources/template/template.xlsx b/sgzb-modules/sgzb-base/src/main/resources/template/template.xlsx new file mode 100644 index 00000000..157483b2 Binary files /dev/null and b/sgzb-modules/sgzb-base/src/main/resources/template/template.xlsx differ diff --git a/sgzb-modules/sgzb-material/src/main/resources/mapper/material/SecondaryWarehouseMapper.xml b/sgzb-modules/sgzb-material/src/main/resources/mapper/material/SecondaryWarehouseMapper.xml index a06434ca..35ec6a13 100644 --- a/sgzb-modules/sgzb-material/src/main/resources/mapper/material/SecondaryWarehouseMapper.xml +++ b/sgzb-modules/sgzb-material/src/main/resources/mapper/material/SecondaryWarehouseMapper.xml @@ -204,7 +204,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" left join ma_type mt on rd.type_id = mt.type_id left join ma_type mt2 on mt.parent_id = mt2.type_id left join sys_user su on rd.out_name = su.user_id - where 1=1 + where rd.type = 1 and mt2.type_id = #{typeId} diff --git a/sgzb-ui/src/api/system/upload.js b/sgzb-ui/src/api/system/upload.js index 4560e702..7b26e643 100644 --- a/sgzb-ui/src/api/system/upload.js +++ b/sgzb-ui/src/api/system/upload.js @@ -23,6 +23,25 @@ export function fileUpLoad(param){ }) } +// excel文件上传 +export function excelUpLoad(param){ + const formData = new FormData() + formData.append('file', param.file) + return request({ + url: '/base/maPartType/readExcel', + method: 'post', + data: formData, + }) +} + +// excel文件下载 +export function downloadExcel(param){ + return request({ + url: '/base/maPartType/downLoad', + method: 'post', + param + }) +} diff --git a/sgzb-ui/src/views/claimAndRefund/secondStore/secondStore.vue b/sgzb-ui/src/views/claimAndRefund/secondStore/secondStore.vue index 9471c366..72c9b3af 100644 --- a/sgzb-ui/src/views/claimAndRefund/secondStore/secondStore.vue +++ b/sgzb-ui/src/views/claimAndRefund/secondStore/secondStore.vue @@ -310,7 +310,7 @@ @@ -427,14 +427,14 @@ width="1200px" append-to-body > - - + –> @@ -465,8 +465,7 @@ >重置 - - + --> 删除 - - - - - - - - - - - + + 导入 + 下载导入模板 @@ -265,6 +266,8 @@ accept=".xlsx, .xls" :limit="1" :file-list="fileList" + :on-remove="handleRemoveExcel" + :on-exceed="excelExceed" > 点击上传 @@ -308,7 +311,7 @@ import { updatePartTypeById, delPartType, } from '@/api/store/tools' -import { fileUpLoad } from '@/api/system/upload' +import { excelUpLoad, downloadExcel } from '@/api/system/upload' import Treeselect from '@riophae/vue-treeselect' import '@riophae/vue-treeselect/dist/vue-treeselect.css' @@ -384,7 +387,7 @@ export default { isEdit: false, // excel文件列表 fileList: [], - excelList: {} + excelList: undefined } }, created() { @@ -393,25 +396,50 @@ export default { methods: { /** 确认上传excel */ confirmUpload() { - console.log(this.fileList) - fileUpLoad(this.excelList).then(res => { - console.log(res) - if (res.code == 200) { - this.$modal.msgSuccess(res.msg) - this.openUpload = false - this.reset() - this.getList() + if (this.excelList != undefined) { + let ifSize = this.excelList.file.size / 1024 / 1024 < 20; + if (!ifSize) { + this.$modal.msgError('上传文件大于20M,请重新选择文件上传!') } else { - this.$modal.msgError(res.msg) + console.log(this.excelList) + excelUpLoad(this.excelList).then(res => { + console.log(res) + if (res.code == 200) { + this.$modal.msgSuccess(res.msg) + this.openUpload = false + this.reset() + this.getList() + } else { + this.$modal.msgError(res.msg) + } + }).catch(err => { + console.log(err) + }) } - }).catch(err => { - console.log(err) - }) + } else { + this.$modal.msgError('请选择上传文件!') + } + }, + /** 点击下载excel导入模板 */ + downloadExcelTemplate() { + this.download( + 'base/maPartType/downLoad', + {}, + `配件模板.xlsx`, + ) }, /** 上传excel文件 */ uploadExcel(obj) { this.excelList = obj }, + /** 移除excel文件 */ + handleRemoveExcel() { + this.excelList = undefined + }, + /** 上传的excel数超出限制 */ + excelExceed(files, fileList) { + this.$modal.msgError('上传的excel文件数量超出限制!') + }, /** 上传excel文件前 */ beforeExcelUpload(file) { console.log(file)