配件模块前后端代码修改

This commit is contained in:
76164 2024-07-25 15:56:07 +08:00
parent 805f69de95
commit 6d93d570f5
11 changed files with 231 additions and 77 deletions

View File

@ -23,6 +23,9 @@
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos Config -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
@ -117,4 +120,4 @@
</plugins>
</build>
</project>
</project>

View File

@ -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<MaPartType> 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<MaPartType> list = maPartTypeService.selectMyPartTypeList(maPartType);
ExcelUtil<MaPartType> util = new ExcelUtil<MaPartType>(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<String, Map<String, List<String>>> 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));
}
}

View File

@ -88,5 +88,7 @@ public class MaPartType extends BaseEntity {
private String firstLevel;
}

View File

@ -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;
}

View File

@ -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);
}
}
}

View File

@ -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
<if test="typeId != null and typeId != ''">
and mt2.type_id = #{typeId}
</if>

View File

@ -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
})
}

View File

@ -310,7 +310,7 @@
</el-form-item>
<el-form-item label="在库数量" prop="kcNum">
<el-input
v-model="form.kcNum"
v-model="form.zkNum"
placeholder="请输入在库数量"
disabled
/>
@ -427,14 +427,14 @@
width="1200px"
append-to-body
>
<el-form
<!-- <el-form
:model="dialogQuery"
ref="dialogQuery"
size="small"
:inline="true"
label-width="80px"
>
<!-- <el-form-item label="记录时间" prop="startTime">
&lt;!&ndash; <el-form-item label="记录时间" prop="startTime">
<el-date-picker
v-model="dialogQuery.startTime"
style="width: 240px"
@ -442,7 +442,7 @@
type="date"
placeholder="记录时间"
></el-date-picker>
</el-form-item>-->
</el-form-item>&ndash;&gt;
<el-form-item label="类型名称" prop="typeName">
<el-input v-model="dialogQuery.typeName" disabled />
</el-form-item>
@ -465,8 +465,7 @@
>重置</el-button
>
</el-form-item>
</el-form>
</el-form>-->
<el-table v-loading="loading" :data="dialogList">
<el-table-column
label="序号"
@ -848,7 +847,7 @@ export default {
//
openRecords(row, type) {
this.title = undefined
this.title = '领用记录'
this.openRecord = true
/*this.queryType = type
this.dialogQuery.typeName = row.typeName

View File

@ -135,17 +135,17 @@
>删除</el-button
>
</el-col>
<!-- <el-col :span="1.5">-->
<!-- <el-button-->
<!-- type="info"-->
<!-- plain-->
<!-- icon="el-icon-upload2"-->
<!-- size="mini"-->
<!-- @click="handleImport"-->
<!-- v-hasPermi="['system:user:import']"-->
<!-- >导入</el-button-->
<!-- >-->
<!-- </el-col>-->
<el-col :span="1.5">
<el-button
type="info"
plain
icon="el-icon-upload2"
size="mini"
@click="handleImport"
v-hasPermi="['system:user:import']"
>导入</el-button
>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"

View File

@ -77,6 +77,7 @@
plain
icon="el-icon-top"
size="mini"
@click="downloadExcelTemplate"
>下载导入模板</el-button
>
</el-col>
@ -265,6 +266,8 @@
accept=".xlsx, .xls"
:limit="1"
:file-list="fileList"
:on-remove="handleRemoveExcel"
:on-exceed="excelExceed"
>
<el-button size="small" type="primary">点击上传</el-button>
</el-upload>
@ -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)