代码提交

This commit is contained in:
zhengzheng 2022-03-20 14:25:27 +08:00
parent f3e48f62ea
commit 8c1ad942d4
9 changed files with 84 additions and 41 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

View File

@ -1,6 +1,7 @@
package com.wuzhen.web.controller.busi;
import com.wuzhen.common.annotation.Log;
import com.wuzhen.common.config.RuoYiConfig;
import com.wuzhen.common.core.controller.BaseController;
import com.wuzhen.common.core.domain.AjaxResult;
import com.wuzhen.common.core.page.TableDataInfo;
@ -15,6 +16,10 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.List;
/**
@ -79,14 +84,29 @@ public class ActiveInfoController extends BaseController
@ResponseBody
public AjaxResult addSave(@Validated ActiveInfo activeInfo)
{
// if (UserConstants.ROLE_NAME_NOT_UNIQUE.equals(activeInfoService.checkNameUnique(role)))
// {
// return error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
// }
// else if (UserConstants.ROLE_KEY_NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
// {
// return error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
// }
MultipartFile file = activeInfo.getActivePic();
// 获取上传文件名
String filename = file.getOriginalFilename();
if (!"".equals(filename)){
// 定义上传文件保存路径
String path = RuoYiConfig.getUploadPath();
// 新建文件
File filepath = new File(path, filename);
// 判断路径是否存在如果不存在就创建一个
if (!filepath.getParentFile().exists()) {
filepath.getParentFile().mkdirs();
}
String picUrl = path + File.separator + filename;
try {
// 写入文件
file.transferTo(new File(picUrl));
} catch (IOException e) {
e.printStackTrace();
}
activeInfo.setActivePicUrl(picUrl);
}
activeInfo.setCreateBy(getLoginName());
AuthorizationUtils.clearAllCachedAuthorizationInfo();
return toAjax(activeInfoService.insertActive(activeInfo));

View File

@ -28,7 +28,7 @@ import com.wuzhen.common.utils.file.FileUtils;
* @author zhengzheng
*/
@Controller
@RequestMapping("/common")
@RequestMapping("/common/upload")
public class CommonController
{
private static final Logger log = LoggerFactory.getLogger(CommonController.class);

View File

@ -1,5 +1,5 @@
# 项目相关配置
ruoyi:
wuzhen:
# 名称
name: 乌镇展厅小程序
# 版本
@ -7,7 +7,7 @@ ruoyi:
# 版权年份
copyrightYear: 2022
# 实例演示开关
demoEnabled: true
demoEnabled: false
# 文件路径 示例( Windows配置D:/ruoyi/uploadPathLinux配置 /home/ruoyi/uploadPath
profile: D:/ruoyi/uploadPath
# 获取ip地址开关

View File

@ -7,7 +7,7 @@
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-role-add">
<form class="form-horizontal m" id="form-role-add" enctype="multipart/form-data">
<div class="form-group">
<label class="col-sm-3 control-label is-required">活动标题:</label>
<div class="col-sm-8">
@ -33,8 +33,11 @@
<div class="form-group">
<label class="col-sm-3 control-label is-required">活动图片:</label>
<div class="col-sm-8">
<input class="form-control" type="text" name="activePic" id="activePic" required>
<!-- <label for="uploadFile">或者 上传本地文件</label>-->
<input type="file" class="form-control-file" id="activePic" name="activePic">
<!-- <input class="form-control" type="text" name="activePic" id="activePic" required>-->
</div>
</div>
<div class="form-group draggable">
@ -93,28 +96,30 @@
}
function add() {
var activeTitle = $("input[name='activeTitle']").val();
var activeDesc =$("textarea[name='activeDesc']").val();
var activeType = $("select[name='activeType']").val();
var activePic = $("input[name='activePic']").val();
var activeStartDate = $("input[name='activeStartDate']").val();
var activeEndDate = $("input[name='activeEndDate']").val();
var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
var remark = $("input[name='remark']").val();
<!-- var activeTitle = $("input[name='activeTitle']").val();-->
<!-- var activeDesc =$("textarea[name='activeDesc']").val();-->
<!-- var activeType = $("select[name='activeType']").val();-->
<!-- var activeStartDate = $("input[name='activeStartDate']").val();-->
<!-- var activeEndDate = $("input[name='activeEndDate']").val();-->
<!-- var status = $("input[id='status']").is(':checked') == true ? 0 : 1;-->
<!-- var remark = $("input[name='remark']").val();-->
<!-- var activePic = $('#activePic')[0].files[0];-->
var formData = new FormData($("#form-role-add")[0])
formData.append('activePic', activePic);
<!-- formData.append('activeDesc', activeDesc);-->
<!-- formData.append('activeType', activeType);-->
<!-- formData.append('activeStartDate', activeStartDate);-->
<!-- formData.append('activeEndDate', activeEndDate);-->
<!-- formData.append('status', status);-->
<!-- formData.append('remark', remark);-->
$.ajax({
cache : true,
cache: false,
contentType: false,
processData: false,
type : "POST",
url : ctx + "active/info/add",
data : {
"activeTitle": activeTitle,
"activeDesc": activeDesc,
"activeType": activeType,
"activePic": activePic,
"activeStartDate": activeStartDate,
"activeEndDate": activeEndDate,
"status": status,
"remark": remark
},
data : formData,
async : false,
error : function(request) {
$.modal.alertError("系统错误");

View File

@ -59,7 +59,7 @@
<div class="form-group">
<label class="col-sm-3 control-label is-required">活动图片:</label>
<div class="col-sm-8">
<input class="form-control" type="text" name="activePic" id="activePic" th:field="*{activePic}" required>
<input class="form-control" type="text" name="activePicUrl" id="activePicUrl" th:field="*{activePicUrl}" disabled required>
</div>
</div>
<div class="form-group">

View File

@ -6,6 +6,7 @@ import com.wuzhen.common.annotation.Excel.ColumnType;
import com.wuzhen.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.springframework.web.multipart.MultipartFile;
/**
* 活动信息 active_info
@ -59,7 +60,15 @@ public class ActiveInfo extends BaseEntity {
* 活动图片
*/
@Excel(name = "活动图片")
private String activePic;
private MultipartFile activePic;
/**
* 活动图片地址
*/
@Excel(name = "活动图片地址")
private String activePicUrl;
/**
* 推荐人编号
@ -126,11 +135,11 @@ public class ActiveInfo extends BaseEntity {
this.activeType = activeType;
}
public String getActivePic() {
public MultipartFile getActivePic() {
return activePic;
}
public void setActivePic(String activePic) {
public void setActivePic(MultipartFile activePic) {
this.activePic = activePic;
}
@ -142,6 +151,15 @@ public class ActiveInfo extends BaseEntity {
this.status = status;
}
public String getActivePicUrl() {
return activePicUrl;
}
public void setActivePicUrl(String activePicUrl) {
this.activePicUrl = activePicUrl;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)

View File

@ -11,7 +11,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="activeStartDate" column="active_start_date" />
<result property="activeEndDate" column="active_end_date" />
<result property="activeType" column="active_type" />
<result property="activePic" column="active_pic" />
<result property="activePicUrl" column="active_pic_url" />
<result property="status" column="status" />
<result property="delFlag" column="del_flag" />
<result property="createBy" column="create_by" />
@ -23,7 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectActiveVo">
select r.id, r.active_title, r.active_desc,r.active_start_date,r.active_end_date, r.active_pic, r.active_type, r.status, r.del_flag, r.create_time, r.remark
select r.id, r.active_title, r.active_desc,r.active_start_date,r.active_end_date, r.active_pic_url, r.active_type, r.status, r.del_flag, r.create_time, r.remark
from active_info r
</sql>
@ -84,7 +84,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="activeStartDate != null and activeStartDate != ''">active_start_date = #{activeStartDate},</if>
<if test="activeEndDate != null and activeEndDate != ''">active_end_date = #{activeEndDate},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="activePic != null and activePic != ''">active_pic = #{activePic},</if>
<if test="activePicUrl != null and activePicUrl != ''">active_pic = #{active_pic_url},</if>
<if test="activeType != null and activeType != ''">active_type = #{activeType},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
@ -100,7 +100,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="activeStartDate != null and activeStartDate != ''">active_start_date,</if>
<if test="activeEndDate != null and activeEndDate != ''">active_end_date,</if>
<if test="activeType != null and activeType != ''">active_type,</if>
<if test="activePic != null and activePic != ''">active_pic,</if>
<if test="activePicUrl != null and activePicUrl != ''">active_pic_url,</if>
<if test="status != null and status != ''">status,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
@ -111,7 +111,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="activeStartDate != null and activeStartDate != ''">#{activeStartDate},</if>
<if test="activeEndDate != null and activeEndDate != ''">#{activeEndDate},</if>
<if test="activeType != null and activeType != ''">#{activeType},</if>
<if test="activePic != null and activeType != ''">#{activePic},</if>
<if test="activePicUrl != null and activePicUrl != ''">#{activePicUrl},</if>
<if test="status != null and status != ''">#{status},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>