Browse Source

[fix]工程管理:

修复产品型号管理的bug
修改添加缺少文件上传功能,修改不能实现修改功能,按照原型去掉删除功能。
dev
liuxiaoxu 7 months ago
parent
commit
d0da006e26
  1. 6
      ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysProductModelController.java
  2. 32
      ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysProductModel.java
  3. 2
      ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysProductModelService.java
  4. 35
      ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysProductModelServiceImpl.java
  5. 27
      ruoyi-admin/src/main/resources/mapper/system/SysProductModelMapper.xml
  6. 91
      ruoyi-admin/src/main/resources/templates/system/model/add.html
  7. 116
      ruoyi-admin/src/main/resources/templates/system/model/edit.html
  8. 3
      ruoyi-admin/src/main/resources/templates/system/model/model.html

6
ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysProductModelController.java

@ -89,10 +89,10 @@ public class SysProductModelController extends BaseController
/**
* 修改产品型号管理
*/
@GetMapping("/edit/{Pid}")
public String edit(@PathVariable("Pid") Long Pid, ModelMap mmap)
@GetMapping("/edit/{pid}")
public String edit(@PathVariable("pid") Long pid, ModelMap mmap)
{
SysProductModel sysProductModel = sysProductModelService.selectSysProductModelById(Pid);
SysProductModel sysProductModel = sysProductModelService.selectSysProductModelById(pid);
mmap.put("sysProductModel", sysProductModel);
return prefix + "/edit";
}

32
ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysProductModel.java

@ -44,9 +44,14 @@ public class SysProductModel extends BaseEntity
@Excel(name = "使用状态")
private String useStatus;
/** 图片地址 */
@Excel(name = "图片地址")
private Long photoAttachId;
/** 照片 */
private String photoUrl;
private String fileIdStr;
private String removeFileIdStr;
public void setPid(Long pid)
{
@ -129,6 +134,30 @@ public class SysProductModel extends BaseEntity
return photoUrl;
}
public String getFileIdStr() {
return fileIdStr;
}
public void setFileIdStr(String fileIdStr) {
this.fileIdStr = fileIdStr;
}
public Long getPhotoAttachId() {
return photoAttachId;
}
public void setPhotoAttachId(Long photoAttachId) {
this.photoAttachId = photoAttachId;
}
public String getRemoveFileIdStr() {
return removeFileIdStr;
}
public void setRemoveFileIdStr(String removeFileIdStr) {
this.removeFileIdStr = removeFileIdStr;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
@ -146,6 +175,7 @@ public class SysProductModel extends BaseEntity
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.append("photoUrl", getPhotoUrl())
.append("fileIdStr",getFileIdStr())
.toString();
}
}

2
ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysProductModelService.java

@ -18,7 +18,7 @@ public interface ISysProductModelService
* @param Pid 产品型号管理ID
* @return 产品型号管理
*/
public SysProductModel selectSysProductModelById(Long Pid);
public SysProductModel selectSysProductModelById(Long pid);
/**
* 查询产品型号管理列表

35
ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysProductModelServiceImpl.java

@ -4,12 +4,20 @@ import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.SysAttach;
import com.ruoyi.system.domain.SysProductModel;
import com.ruoyi.system.mapper.SysProductModelMapper;
import com.ruoyi.system.service.ISysAttachFileService;
import com.ruoyi.system.service.ISysAttachService;
import com.ruoyi.system.service.ISysProductModelService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
@ -23,8 +31,15 @@ public class SysProductModelServiceImpl implements ISysProductModelService
{
@Autowired
private SysProductModelMapper sysProductModelMapper;
@Autowired
private RedisCache redisCache;
@Autowired
private ISysAttachService attachService;
@Autowired
private ISysAttachFileService attachFileService;
/**
* 查询产品型号管理
*
@ -55,6 +70,7 @@ public class SysProductModelServiceImpl implements ISysProductModelService
* @param sysProductModel 产品型号管理
* @return 结果
*/
@Transactional
@Override
public int insertSysProductModel(SysProductModel sysProductModel)
{
@ -62,7 +78,24 @@ public class SysProductModelServiceImpl implements ISysProductModelService
sysProductModel.setCreateBy(loginName);
sysProductModel.setPcode(redisCache.generateNo("CPXH"));
sysProductModel.setCreateTime(DateUtils.getNowDate());
return sysProductModelMapper.insertSysProductModel(sysProductModel);
int result = sysProductModelMapper.insertSysProductModel(sysProductModel);
Long pid = sysProductModel.getPid();
String fileIdStr = sysProductModel.getFileIdStr();
if (StringUtils.isNotBlank(fileIdStr)){
//保存附件关联
SysAttach sysAttach = new SysAttach();
sysAttach.setCreateBy(ShiroUtils.getLoginName());
sysAttach.setCreateTime(new Date());
sysAttach.setSourceType("sysProductModel");
sysAttach.setSourceSubType("photo");
sysAttach.setRelId(pid);
attachService.insertSysAttach(sysAttach);
//更新附件与文件关联
Long attachId = sysAttach.getId();
List<String> fileIdList = Arrays.asList(fileIdStr.split(";"));
attachFileService.updateAttachIdByIdList(attachId,fileIdList);
}
return result;
}
/**

27
ruoyi-admin/src/main/resources/mapper/system/SysProductModelMapper.xml

@ -17,7 +17,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<result property="useStatus" column="use_status" />
<result property="photoUrl" column="photoUrl" />
<result property="photoAttachId" column="photo_attach_id" />
<result property="photoUrl" column="photo_url" />
</resultMap>
<sql id="selectSysProductModelVo">
@ -26,7 +27,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update_time,remark, photoUrl from sys_product_model
</sql>
<select id="selectSysProductModelList" parameterType="SysProductModel" resultMap="SysProductModelResult">
<include refid="selectSysProductModelVo"/>
select s.pid, s.pcode, s.equipModel, s.equipName,s.engineer,s.use_status,
s.specification, s.differences, s. create_by, s.create_time, s.udpate_by,
s.update_time,s.remark, s.photoUrl,file.url as photo_url from sys_product_model as s
left join (
select
att.rel_id
,file.url
,min(file.create_time) as create_time
from sys_attach as att
left join sys_attach_file as file
on att.id = file.attach_id
where att.source_type = 'sysProductModel' and att.source_sub_type = 'photo'
group by att.rel_id
)file
on s.pid = file.rel_id
<where>
<if test="pcode != null and pcode != ''"> and Pcode = #{pcode}</if>
<if test="createBy != null and createBy != ''"> and create_by = #{createBy}</if>
@ -44,8 +59,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectSysProductModelById" parameterType="Long" resultMap="SysProductModelResult">
<include refid="selectSysProductModelVo"/>
where pid = #{pid}
select s.pid, s.pcode, s.equipModel, s.equipName,s.engineer,s.use_status,
s.specification, s.differences, s. create_by, s.create_time, s.udpate_by,
s.update_time,s.remark, s.photoUrl,att.id as photo_attach_id from sys_product_model as s
left join sys_attach as att
on s.pid = att.rel_id and att.source_type = 'sysProductModel' and att.source_sub_type = 'photo'
where s.pid = #{pid}
</select>
<insert id="insertSysProductModel" parameterType="SysProductModel" useGeneratedKeys="true" keyProperty="pid">

91
ruoyi-admin/src/main/resources/templates/system/model/add.html

@ -2,9 +2,11 @@
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
<th:block th:include="include :: header('新增产品型号管理')" />
<th:block th:include="include :: select2-css" />
<link th:href="@{/ajax/libs/element-ui/element-ui.css}" rel="stylesheet"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<div id="app" class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-model-add">
<div class="form-group">
<label class="col-sm-3 control-label">设备型号:</label>
@ -37,15 +39,85 @@
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">图片地址:</label>
<div class="col-sm-8">
<input name="photoUrl" class="form-control" type="text">
<label class="col-sm-2 control-label">照片:</label>
<div class="col-sm-10">
<el-upload
:action="fileUploadUrl"
:on-success="uploadSuccess"
:on-remove="uploadRemove"
:file-list="fileList"
:limit="5"
list-type="picture"
accept=".jpg,.png"
multiple>
<el-button size="small" type="primary">点击上传</el-button>
<div slot="tip" class="el-upload__tip">只能上传jpg/png文件,第一张图片为主图</div>
</el-upload>
</div>
<input id="fileIdStr" type="text" name="fileIdStr" hidden>
</div>
</form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<script th:src="@{/ajax/libs/vue/vue.js}"></script>
<script th:src="@{/ajax/libs/element-ui/element-ui.js}"></script>
<script th:inline="javascript">
new Vue({
el: '#app',
data: function() {
return {
fileList: [],
fileUploadUrl: ctx + "common/uploadSingleFile",
fileDeleteUrl: ctx + "common/deleteFile",
fileIdList:[],
}
},
methods: {
uploadSuccess(response, file, fileList) {
console.log(response);
if(response.code == web_status.SUCCESS){
var attachFileId = response.data.id;
file.attachFileId = attachFileId;
this.fileIdList.push(attachFileId);
$("#fileIdStr").val(this.fileIdList.join(";"));
$.modal.msgSuccess("上传成功");
}else{
$.modal.alertError(response.msg);
}
},
uploadRemove(file, fileList) {
console.log(file, fileList);
var attachFileId = file.attachFileId;
$.ajax({
type: "get",
url: this.fileDeleteUrl,
data: {id:attachFileId},
cache: false,
async: false, // 设置成同步
dataType: 'json',
success: function(result) {
if (result.code == web_status.SUCCESS) {
var index = this.fileIdList.indexOf(attachFileId);
if(index!=-1){
this.fileIdList.splice(index,1);
$("#fileIdStr").val(this.fileIdList.join(";"));
}
$.modal.msgSuccess("删除附件成功。");
} else {
$.modal.alertError(result.msg);
}
},
error: function(error) {
$.modal.alertError("删除附件失败。");
}
});
},
}
})
var prefix = ctx + "system/model"
$("#form-model-add").validate({
focusCleanup: true
@ -56,6 +128,17 @@
$.operate.save(prefix + "/add", $('#form-model-add').serialize());
}
}
index = 0; //图片数量
const imageArray = new Map(); //保存的图片数量
// 删除图片
function delate(val) {
imageArray.delete(val);
index--;
if (index <= 4) {
$(".shangchuan").parent().parent().css("display", "block");
}
}
</script>
</body>
</html>

116
ruoyi-admin/src/main/resources/templates/system/model/edit.html

@ -2,9 +2,11 @@
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
<th:block th:include="include :: header('修改产品型号管理')" />
<th:block th:include="include :: select2-css" />
<link th:href="@{/ajax/libs/element-ui/element-ui.css}" rel="stylesheet"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<div id="app" class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-model-edit" th:object="${sysProductModel}">
<input name="pid" th:field="*{pid}" type="hidden">
<div class="form-group">
@ -56,10 +58,122 @@
<input id="fileIdStr" type="text" name="fileIdStr" th:field="*{fileIdStr}" hidden>
<input id="removeFileIdStr" type="text" name="removeFileIdStr" hidden>
</div>
</form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script th:src="@{/ajax/libs/vue/vue.js}"></script>
<script th:src="@{/ajax/libs/element-ui/element-ui.js}"></script>
<script th:inline="javascript">
new Vue({
el: '#app',
data: function() {
return {
fileList: [],
fileUploadUrl: ctx + "common/uploadSingleFile",
fileDeleteUrl: ctx + "common/deleteFile",
getListByAttachIdUrl: ctx + "system/attach/file/getListByAttachId",
fileIdList:[],
removeFileIdList:[],
}
},
mounted() {
// 控制下拉框选中
// var materialType = $("#materialType").val();
// $("#selectMaterialType").val(materialType).trigger("change");
var that = this;
// 页面渲染完成,可以执行需要的操作
console.log('页面已渲染完成');
console.log($("#id").val());
console.log($("#photoAttachId").val());
var attachId = $("#photoAttachId").val();
if(attachId){
$.ajax({
type: "get",
url: that.getListByAttachIdUrl,
data: {attachId:attachId},
cache: false,
async: false, // 设置成同步
dataType: 'json',
success: function(result) {
if (result.code == web_status.SUCCESS) {
result.data.forEach((item) => {
that.fileIdList.push(item.id);
that.fileList.push({name: item.name, url: item.url, attachFileId: item.id,isBind:true});
});
} else {
$.modal.msgError(result.msg);
}
},
error: function(error) {
$.modal.msgError("获取附件失败。");
}
});
}
},
methods: {
uploadSuccess(response, file, fileList) {
console.log(response);
if(response.code == web_status.SUCCESS){
var attachFileId = response.data.id;
file.attachFileId = attachFileId;
file.isBind = false;
this.fileIdList.push(attachFileId);
$("#fileIdStr").val(this.fileIdList.join(";"));
$.modal.msgSuccess("上传成功");
}else{
$.modal.alertError(response.msg);
}
},
uploadRemove(file, fileList) {
console.log(file, fileList);
var attachFileId = file.attachFileId;
var isBind = file.isBind;
if(isBind==false){
$.ajax({
type: "get",
url: this.fileDeleteUrl,
data: {id:attachFileId},
cache: false,
async: false, // 设置成同步
dataType: 'json',
success: function(result) {
if (result.code == web_status.SUCCESS) {
var index = this.fileIdList.indexOf(attachFileId);
if(index!=-1){
this.fileIdList.splice(index,1);
$("#fileIdStr").val(this.fileIdList.join(";"));
}
$.modal.msgSuccess("删除附件成功。");
} else {
$.modal.alertError(result.msg);
}
},
error: function(error) {
$.modal.alertError("删除附件失败。");
}
});
}else{
var index = this.fileIdList.indexOf(attachFileId);
if(index!=-1){
this.fileIdList.splice(index,1);
$("#fileIdStr").val(this.fileIdList.join(";"));
// 保存的时候才删除
this.removeFileIdList.push(attachFileId);
$("#removeFileIdStr").val(this.removeFileIdList.join(";"));
}
}
},
}
})
var prefix = ctx + "system/model";
$("#form-model-edit").validate({
focusCleanup: true

3
ruoyi-admin/src/main/resources/templates/system/model/model.html

@ -100,8 +100,7 @@
align: 'center',
formatter: function(value, row, index) {
var actions = [];
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.Pid + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.Pid + '\')"><i class="fa fa-remove"></i>删除</a> ');
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.pid + '\')"><i class="fa fa-edit"></i>编辑</a> ');
if(row.useStatus == '0'){
actions.push('<a class="btn btn-danger btn-xs ' + cancelFlag + '" href="javascript:void(0)" onclick="$.operate.cancel(\'' + row.id + '\')"><i class="fa fa-remove"></i>作废</a> ');
}else{

Loading…
Cancel
Save