Browse Source

[feat]新增供应商页面上传图片文件管理功能,编辑供应商页面上传文件显示功能。

dev
zhangsiqi 6 months ago
parent
commit
41f250e71c
  1. 40
      ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysSupplier.java
  2. 43
      ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSupplierServiceImpl.java
  3. 70
      ruoyi-admin/src/main/resources/mapper/system/SysSupplierMapper.xml
  4. 84
      ruoyi-admin/src/main/resources/templates/system/supplier/edit.html

40
ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysSupplier.java

@ -155,6 +155,46 @@ public class SysSupplier extends BaseEntity
private String updateInfoTime;
private Long photoAttachId;
/** 照片 */
private String photoUrl;
private String fileIdStr;
private String removeFileIdStr;
public Long getPhotoAttachId() {
return photoAttachId;
}
public void setPhotoAttachId(Long photoAttachId) {
this.photoAttachId = photoAttachId;
}
public String getPhotoUrl() {
return photoUrl;
}
public void setPhotoUrl(String photoUrl) {
this.photoUrl = photoUrl;
}
public String getFileIdStr() {
return fileIdStr;
}
public void setFileIdStr(String fileIdStr) {
this.fileIdStr = fileIdStr;
}
public String getRemoveFileIdStr() {
return removeFileIdStr;
}
public void setRemoveFileIdStr(String removeFileIdStr) {
this.removeFileIdStr = removeFileIdStr;
}
public String getAuditStatus() {
return auditStatus;

43
ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSupplierServiceImpl.java

@ -2,12 +2,20 @@ package com.ruoyi.system.service.impl;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.service.ICommonService;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.SysAttach;
import com.ruoyi.system.domain.SysSupplier;
import com.ruoyi.system.mapper.SysSupplierMapper;
import com.ruoyi.system.service.ISysAttachFileService;
import com.ruoyi.system.service.ISysAttachService;
import com.ruoyi.system.service.ISysSupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
@ -24,6 +32,16 @@ public class SysSupplierServiceImpl implements ISysSupplierService
@Autowired
private RedisCache redisCache;
@Autowired
private ISysAttachFileService attachFileService;
@Autowired
private ISysAttachService attachService;
@Autowired
private ICommonService commonService;
/**
* 查询供应商资料
*
@ -69,6 +87,31 @@ public class SysSupplierServiceImpl implements ISysSupplierService
@Override
public int updateSysSupplier(SysSupplier sysSupplier)
{
String loginName = ShiroUtils.getLoginName();
Long id = sysSupplier.getSupplierId();
String fileIdStr = sysSupplier.getFileIdStr();
Long photoAttachId = sysSupplier.getPhotoAttachId();
String removeFileIdStr = sysSupplier.getRemoveFileIdStr();
sysSupplier.setUpdateTime(new Date());
if(StringUtils.isNotBlank(removeFileIdStr)){
List<String> removeFileIdList = Arrays.asList(removeFileIdStr.split(";"));
commonService.deleteByIds(removeFileIdList);
}
if(StringUtils.isNotBlank(fileIdStr)) {
List<String> fileIdList = Arrays.asList(fileIdStr.split(";"));
if (photoAttachId == null) {
SysAttach attach = new SysAttach();
attach.setCreateBy(loginName);
attach.setCreateTime(new Date());
attach.setSourceType("erpMaterial");
attach.setSourceSubType("photo");
attach.setRelId(id);
attachService.insertSysAttach(attach);
photoAttachId = attach.getId();
}
attachFileService.updateAttachIdByIdList(photoAttachId, fileIdList);
}
return sysSupplierMapper.updateSysSupplier(sysSupplier);
}

70
ruoyi-admin/src/main/resources/mapper/system/SysSupplierMapper.xml

@ -43,6 +43,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="taxRate" column="tax_rate" />
<result property="firstAddTime" column="first_add_time" />
<result property="updateInfoTime" column="update_info_time" />
<result property="photoAttachId" column="photo_attach_id" />
<result property="photoUrl" column="photo_url" />
</resultMap>
<sql id="selectSysSupplierVo">
@ -59,24 +61,66 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql>
<select id="selectSysSupplierList" parameterType="SysSupplier" resultMap="SysSupplierResult">
<include refid="selectSysSupplierVo"/>
select sup.supplier_id, sup.supplier_code, sup.supplier_name, sup.export_sales,
sup.supplier_type, sup.use_status, sup.audit_status, sup.supplier_qualification, sup.purchase_buyer,
sup.enterprise_name, sup.enterprise_nature, sup.customer_address, sup.manufacturer_category,
sup.postal_code, sup.business_scope, sup.customer_country, sup.established_time,
sup.legal_representative, sup.customer_contact, sup.contact_number, sup.customer_fax,
sup.customer_email, sup.website, sup.payment_terms, sup.supplier_days, sup.actual_payment_days,
sup.settlement_bank, sup.exchange_settlement_account, sup.deposit_bank, sup.bank_account,
sup.rmb_registered_capital, sup.Industry_code, sup.merchandiser, sup.merchandiser_telephone,
sup.financial_contact, sup.confirm_tax, sup.tax_rate, sup.first_add_time, sup.update_info_time
from sys_supplier as sup
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 = 'supplier' and att.source_sub_type = 'photo'
group by att.rel_id
)file
on sup.supplier_id = file.rel_id
<where>
<if test="supplierCode != null and supplierCode != ''"> and supplier_code like concat('%', #{supplierCode}, '%')</if>
<if test="supplierName != null and supplierName != ''"> and supplier_name like concat('%', #{supplierName}, '%')</if>
<if test="supplierType != null and supplierType != ''"> and supplier_type = #{supplierType}</if>
<if test="useStatus != null and useStatus != ''"> and use_status = #{useStatus}</if>
<if test="auditStatus != null and auditStatus != ''"> and audit_status = #{auditStatus}</if>
<if test="purchaseBuyer != null and purchaseBuyer != ''"> and purchase_buyer = #{purchaseBuyer}</if>
<if test="exportSales != null and exportSales != ''"> and export_sales = #{exportSales}</if>
<if test="enterpriseName != null and enterpriseName != ''"> and enterprise_name like concat('%', #{enterpriseName}, '%')</if>
<if test="customerContact != null and customerContact != ''"> and customer_contact like concat('%', #{customerContact}, '%')</if>
<if test="merchandiser != null and merchandiser != ''"> and merchandiser like concat('%', #{merchandiser}, '%')</if>
<if test="supplierCode != null and supplierCode != ''"> and sup.supplier_code like concat('%', #{supplierCode}, '%')</if>
<if test="supplierName != null and supplierName != ''"> and sup.supplier_name like concat('%', #{supplierName}, '%')</if>
<if test="supplierType != null and supplierType != ''"> and sup.supplier_type = #{supplierType}</if>
<if test="useStatus != null and useStatus != ''"> and sup.use_status = #{useStatus}</if>
<if test="auditStatus != null and auditStatus != ''"> and sup.audit_status = #{auditStatus}</if>
<if test="purchaseBuyer != null and purchaseBuyer != ''"> and sup.purchase_buyer = #{purchaseBuyer}</if>
<if test="exportSales != null and exportSales != ''"> and sup.export_sales = #{exportSales}</if>
<if test="enterpriseName != null and enterpriseName != ''"> and sup.enterprise_name like concat('%', #{enterpriseName}, '%')</if>
<if test="customerContact != null and customerContact != ''"> and sup.customer_contact like concat('%', #{customerContact}, '%')</if>
<if test="merchandiser != null and merchandiser != ''"> and sup.merchandiser like concat('%', #{merchandiser}, '%')</if>
</where>
</select>
<select id="selectSysSupplierById" parameterType="Long" resultMap="SysSupplierResult">
<include refid="selectSysSupplierVo"/>
where supplier_id = #{supplierId}
select sup.supplier_id, sup.supplier_code, sup.supplier_name, sup.export_sales,
sup.supplier_type, sup.use_status, sup.audit_status, sup.supplier_qualification, sup.purchase_buyer,
sup.enterprise_name, sup.enterprise_nature, sup.customer_address, sup.manufacturer_category,
sup.postal_code, sup.business_scope, sup.customer_country, sup.established_time,
sup.legal_representative, sup.customer_contact, sup.contact_number, sup.customer_fax,
sup.customer_email, sup.website, sup.payment_terms, sup.supplier_days, sup.actual_payment_days,
sup.settlement_bank, sup.exchange_settlement_account, sup.deposit_bank, sup.bank_account,
sup.rmb_registered_capital, sup.Industry_code, sup.merchandiser, sup.merchandiser_telephone,
sup.financial_contact, sup.confirm_tax, sup.tax_rate, sup.first_add_time, sup.update_info_time
from sys_supplier as sup
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 = 'supplier' and att.source_sub_type = 'photo'
group by att.rel_id
)file
on sup.supplier_id = file.rel_id
where sup.supplier_id = #{supplierId}
</select>
<select id="selectSysSupplierBycode" resultMap="SysSupplierResult">
select supplier_id,supplier_code,supplier_name from sys_supplier where audit_status = 1

84
ruoyi-admin/src/main/resources/templates/system/supplier/edit.html

@ -4,7 +4,7 @@
<th:block th:include="include :: header('修改供应商资料')" />
</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-supplier-edit" th:object="${sysSupplier}">
<div class="form-group">
<label class="col-sm-3 control-label is-required">供应商编号:</label>
@ -196,7 +196,8 @@
<div class="form-group">
<label class="col-sm-3 control-label">采购员:</label>
<div class="col-sm-8">
<select id="purchaseBuyer_add" th:field="${purchaseBuyer}" name="purchaseBuyer" class="form-control" ></select>
<select id="purchaseBuyer_add" name="purchaseBuyer" class="form-control" >
</select>
</div>
</div>
<div class="form-group">
@ -215,21 +216,27 @@
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">证件:</label>
<div class="col-sm-10">
<label class="col-sm-3 control-label">证件:</label>
<div class="form-group">
<label class="col-sm-3 control-label">照片:</label>
<div class="col-sm-8">
<el-upload
:action="fileUploadUrl"
:on-success="uploadSuccess"
:on-remove="uploadRemove"
:file-list="fileList"
list-type="picture"
limit="5"
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>
<input id="photoAttachId" name = "photoAttachId" hidden th:field="*{photoAttachId}" />
<input id="fileIdStr" type="text" name="fileIdStr" th:field="*{fileIdStr}" hidden />
<input id="removeFileIdStr" type="text" name="removeFileIdStr" hidden />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">供应商:</label>
@ -245,17 +252,71 @@
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: bootstrap-table-editable-js"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: bootstrap-fileinput-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">
var prefix = ctx + "system/supplier";
var sysSupplier = [[${supplier}]];
$("#form-supplier-edit").validate({
focusCleanup: true
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("删除附件失败。");
}
});
},
}
})
function submitHandler() {
if ($.validate.form()) {
$.operate.save(prefix + "/edit", $('#form-supplier-edit').serialize());
}
}
$("#form-supplier-edit").validate({focusCleanup: true});
$(function(){
$.ajax({
url: ctx + 'system/user/list',
@ -277,11 +338,6 @@
$("input[name='supplierType']").val(sysSupplier.supplierType);
$("input[name='supplierQualification']").val(sysSupplier.supplierQualification);
})
function submitHandler() {
if ($.validate.form()) {
$.operate.save(prefix + "/edit", $('#form-supplier-edit').serialize());
}
}
</script>
</body>
</html>
Loading…
Cancel
Save