导航,附件,拦截器

This commit is contained in:
Zhang Liguo 2023-12-22 22:07:53 +08:00
parent cffa534f2c
commit 3bf4a8e793
19 changed files with 434 additions and 41 deletions

View File

@ -8,7 +8,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
public class MyWebConfigurer implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new UserInterceptor()).addPathPatterns("/*/**").excludePathPatterns("/error","/login","/register","/findThePassword","/verifyCode","/sendActiveCode");
// registry.addInterceptor(new UserInterceptor()).addPathPatterns("/*/**").excludePathPatterns("/error","/login","/register","/findThePassword","/verifyCode","/sendActiveCode");
WebMvcConfigurer.super.addInterceptors(registry);
}
}

View File

@ -0,0 +1,32 @@
package com.lovenav.controller;
import com.lovenav.entity.Config;
import com.lovenav.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ConfigController {
@Autowired
ConfigService configService;
@RequestMapping("/updateConfig")
public String updateConfig(Config config){
if (configService.updateConfis(config)==1){
return "更新成功";
}
else {
return "更新配置失败";
}
}
@RequestMapping("/addConfig")
public String addConfig(Config config){
if (config.getName()==null||config.getValue()==null){
return "属性值不能为空";
}else {
return configService.addConfig(config);
}
}
}

View File

@ -0,0 +1,41 @@
package com.lovenav.controller;
import com.lovenav.entity.Nav;
import com.lovenav.service.NavService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class NavController {
@Autowired
NavService navService;
@RequestMapping("/updateNav")
public String updateNav(Nav nav){
if (nav==null){
return "选择更新的导航标签!";
}
return navService.updateNav(nav);
}
@RequestMapping("/addNav")
public String addNav(Nav nav){
if (nav==null){
return "添加的导航不能为空";
}
return navService.addNav(nav);
}
@RequestMapping("/deleteNav")
public String deleteNav(Nav nav){
if (nav==null){
return "删除的导航不能为空";
}
return navService.deleteNav(nav);
}
@RequestMapping("/selectAllNav")
public String selectAllNav(){
return navService.selectAllNav();
}
}

View File

@ -0,0 +1,23 @@
package com.lovenav.controller;
import com.lovenav.entity.UrlList;
import com.lovenav.service.UrlListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class UrlListController {
@Autowired
UrlListService urlListService;
//后台修改网站状态
@RequestMapping("/admin/weblist/alterUrlStatus")
public String setUrlStatus(UrlList urlList){
int result=urlListService.updateUrlStatusListById(urlList);
if (result==1){
return "修改成功";
}else {
return "修改失败";
}
}
}

View File

@ -1,6 +1,7 @@
package com.lovenav.controller;
import com.alibaba.fastjson2.JSONObject;
import com.lovenav.entity.UrlList;
import com.lovenav.entity.User;
import com.lovenav.service.UserService;
import com.lovenav.utils.MD5Utils;
@ -146,4 +147,5 @@ public class UserController {
}
}

View File

@ -1,9 +1,11 @@
package com.lovenav.dao;
import com.lovenav.entity.Config;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
@Repository
@Mapper
public interface ConfigDao {
int deleteByPrimaryKey(Integer id);
@ -16,4 +18,8 @@ public interface ConfigDao {
int updateByPrimaryKeySelective(Config record);
int updateByPrimaryKey(Config record);
int updateByName(Config config);
Config selectByName(String name);
}

View File

@ -1,38 +1,63 @@
package com.lovenav.entity;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
* 配置项
* ln_config
*/
@Data
public class Config implements Serializable {
/**
* id
*/
private Integer id;
/**
* 类型
*/
private Object type;
/**
* 名称
*/
private String name;
/**
*
*/
private String value;
/**
* 更新时间
*/
private Date updatetime;
private Integer updatetime;
private static final long serialVersionUID = 1L;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Object getType() {
return type;
}
public void setType(Object type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public Integer getUpdatetime() {
return updatetime;
}
public void setUpdatetime(Integer updatetime) {
this.updatetime = updatetime;
}
}

View File

@ -0,0 +1,9 @@
package com.lovenav.service;
import org.springframework.web.multipart.MultipartFile;
import java.util.HashMap;
public interface AttachmentService {
// public HashMap<String,String>storeFile(MultipartFile multipartFile);
}

View File

@ -0,0 +1,12 @@
package com.lovenav.service;
import com.lovenav.entity.Config;
import java.util.HashMap;
public interface ConfigService {
public HashMap<String,Object>getAllConfig();
public int updateConfis(Config config);
public String addConfig(Config config);
}

View File

@ -0,0 +1,12 @@
package com.lovenav.service;
import com.lovenav.entity.Nav;
public interface NavService {
public String deleteNav(Nav nav);
public String updateNav(Nav nav);
public String selectNav(Nav nav);
public String addNav(Nav nav);
String selectAllNav();
}

View File

@ -10,4 +10,8 @@ public interface UrlListService {
public List<UrlList> selectUrList();
public UrlList selectUrListByInput(String input);
public UrlList selectUrlListByUrlId(Long urlId);
public int updateUrlStatusListById(UrlList urlList);
}

View File

@ -0,0 +1,58 @@
package com.lovenav.service.serviceImpl;
import com.lovenav.service.AttachmentService;
import org.springframework.util.ResourceUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class AttachmentServiceImpl implements AttachmentService {
// @Override
// public HashMap<String, String> storeFile(MultipartFile multipartFile) {
// HashMap<String,String> map = new HashMap<>();
// }
// File path = null;
//// try {
// path = new File(ResourceUtils.getURL("classpath:").getPath());
// File upload = new File(path.getAbsolutePath(),"static/img/");
// Date date=new Date();
//
// DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// String date1=format.format(date);
// String fileName = multipartFile.getOriginalFilename();//文件全名
// File parentDir = new File(upload.getAbsolutePath()+"/" + date1);
// System.out.println(upload.getAbsolutePath());
// System.out.println(fileName);
// map
// return
// if(!upload.exists()){
// upload.mkdirs();
// }
// if(!parentDir.exists()){
// parentDir.mkdirs();
// }
// String suffix = suffix(fileName);//文件后缀
// String relPath = "/" + yearMonth + "/" + "-" + UUID.randomUUID().toString().replaceAll("-","") + suffix;
// File fileUp = new File(upload.getAbsolutePath()+ relPath);
// file.transferTo(fileUp);
// Map<String, String> map = new HashMap();
// map.put("url", "/img" + relPath);
// log.info(relPath);
// return map;
// } catch (FileNotFoundException e) {
// throw e;
// } catch (IOException e) {
// throw e;
// }
// }
}

View File

@ -0,0 +1,39 @@
package com.lovenav.service.serviceImpl;
import com.lovenav.dao.ConfigDao;
import com.lovenav.entity.Config;
import com.lovenav.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
@Service
public class ConfigServiceImpl implements ConfigService {
@Autowired
ConfigDao configDao;
@Override
public HashMap<String, Object> getAllConfig() {
return null;
}
@Override
public int updateConfis(Config config) {
return configDao.updateByName(config);
}
@Override
public String addConfig(Config config) {
if(configDao.selectByName(config.getName())!=null){
return "该配置文件已经存在!";
}else {
int result=configDao.insertSelective(config);
if (result==1){
return "添加成功!";
}else {
return "添加失败!";
}
}
}
}

View File

@ -0,0 +1,63 @@
package com.lovenav.service.serviceImpl;
import com.alibaba.fastjson2.JSON;
import com.lovenav.dao.NavDao;
import com.lovenav.entity.Nav;
import com.lovenav.service.NavService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class NavServiceImpl implements NavService {
@Autowired
NavDao navDao;
@Override
public String deleteNav(Nav nav) {
if (navDao.selectAlreadyExist(nav)==null) {
return "没有该记录";
}
int nav1=navDao.deleteByNavName(nav.getNavName());
if (nav1==1){
return "删除成功";
}else {
return "删除失败";
}
}
@Override
public String updateNav(Nav nav) {
if (navDao.selectAlreadyExist(nav)==null) {
return "没有该记录";
}
int result=navDao.updateByName(nav);
if (result==1){
return "更新成功";
}else {
return "更新失败";
}
}
@Override
public String selectNav(Nav nav) {
return null;
}
@Override
public String addNav(Nav nav) {
int result;
if(navDao.selectAlreadyExist(nav)!=null){
return "已经有相同名称的导航!";
}
result=navDao.insertSelective(nav);
if (result==1){
return "添加成功";
}else {
return "添加失败";
}
}
@Override
public String selectAllNav() {
return (String) JSON.toJSON(navDao.selectAllNav());
}
}

View File

@ -60,4 +60,14 @@ public class UrlLiserServiceImpl implements UrlListService {
urlListDao.updateByPrimaryKeySelective(urlList);
return urlList;
}
@Override
public int updateUrlStatusListById(UrlList urlList) {
if (urlListDao.updateByPrimaryKey(urlList)==1){
return 1;
}else {
return 0;
}
}
}

View File

@ -14,7 +14,7 @@ import javax.annotation.Resource;
import java.util.Date;
import java.util.regex.Pattern;
@Transactional
@Service("userService")
public class UserServiceImpl implements UserService {
@ -72,7 +72,6 @@ public class UserServiceImpl implements UserService {
user.setUserRegistered(date);
return userDao.insert(user);
}

View File

@ -141,4 +141,6 @@
createtime = #{createtime,jdbcType=INTEGER}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>

View File

@ -6,7 +6,7 @@
<result column="type" jdbcType="OTHER" property="type" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="value" jdbcType="VARCHAR" property="value" />
<result column="updatetime" jdbcType="TIMESTAMP" property="updatetime" />
<result column="updatetime" jdbcType="INTEGER" property="updatetime" />
</resultMap>
<sql id="Base_Column_List">
id, `type`, `name`, `value`, updatetime
@ -17,6 +17,13 @@
from ln_config
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectByName" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from ln_config
where name = #{name,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from ln_config
where id = #{id,jdbcType=INTEGER}
@ -25,7 +32,7 @@
insert into ln_config (`type`, `name`, `value`,
updatetime)
values (#{type,jdbcType=OTHER}, #{name,jdbcType=VARCHAR}, #{value,jdbcType=VARCHAR},
#{updatetime,jdbcType=TIMESTAMP})
#{updatetime,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.lovenav.entity.Config" useGeneratedKeys="true">
insert into ln_config
@ -54,7 +61,7 @@
#{value,jdbcType=VARCHAR},
</if>
<if test="updatetime != null">
#{updatetime,jdbcType=TIMESTAMP},
#{updatetime,jdbcType=INTEGER},
</if>
</trim>
</insert>
@ -71,7 +78,7 @@
`value` = #{value,jdbcType=VARCHAR},
</if>
<if test="updatetime != null">
updatetime = #{updatetime,jdbcType=TIMESTAMP},
updatetime = #{updatetime,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
@ -81,7 +88,22 @@
set `type` = #{type,jdbcType=OTHER},
`name` = #{name,jdbcType=VARCHAR},
`value` = #{value,jdbcType=VARCHAR},
updatetime = #{updatetime,jdbcType=TIMESTAMP}
updatetime = #{updatetime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByName" parameterType="com.lovenav.entity.Config">
update ln_config
<set>
<if test="type != null">
`type` = #{type,jdbcType=OTHER},
</if>
<if test="value != null">
`value` = #{value,jdbcType=VARCHAR},
</if>
<if test="updatetime != null">
updatetime = #{updatetime,jdbcType=INTEGER},
</if>
</set>
where name = #{name,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -230,22 +230,56 @@
</update>
<update id="updateByPrimaryKey" parameterType="com.lovenav.entity.UrlList">
update ln_url_list
set `name` = #{name,jdbcType=VARCHAR},
icon = #{icon,jdbcType=VARCHAR},
cate_id = #{cateId,jdbcType=INTEGER},
url = #{url,jdbcType=VARCHAR},
createtime = #{createtime,jdbcType=BIGINT},
views = #{views,jdbcType=BIGINT},
tags = #{tags,jdbcType=VARCHAR},
weigh = #{weigh,jdbcType=BIGINT},
`status` = #{status,jdbcType=TINYINT},
`desc` = #{desc,jdbcType=VARCHAR},
need_login = #{needLogin,jdbcType=TINYINT},
agent_hint = #{agentHint,jdbcType=VARCHAR},
is_need_agent = #{isNeedAgent,jdbcType=TINYINT},
is_ad = #{isAd,jdbcType=TINYINT},
is_top = #{isTop,jdbcType=TINYINT},
is_encrypt = #{isEncrypt,jdbcType=TINYINT}
<set>
<if test="name != null">
`name` = #{name,jdbcType=VARCHAR},
</if>
<if test="icon != null">
icon = #{icon,jdbcType=VARCHAR},
</if>
<if test="cateId != null">
cate_id = #{cateId,jdbcType=INTEGER},
</if>
<if test="url != null">
url = #{url,jdbcType=VARCHAR},
</if>
<if test="createtime != null">
createtime = #{createtime,jdbcType=BIGINT},
</if>
<if test="views != null">
views = #{views,jdbcType=BIGINT},
</if>
<if test="tags != null">
tags = #{tags,jdbcType=VARCHAR},
</if>
<if test="weigh != null">
weigh = #{weigh,jdbcType=BIGINT},
</if>
<if test="status != null">
`status` = #{status,jdbcType=TINYINT},
</if>
<if test="desc != null">
`desc` = #{desc,jdbcType=VARCHAR},
</if>
<if test="needLogin != null">
need_login = #{needLogin,jdbcType=TINYINT},
</if>
<if test="agentHint != null">
agent_hint = #{agentHint,jdbcType=VARCHAR},
</if>
<if test="isNeedAgent != null">
is_need_agent = #{isNeedAgent,jdbcType=TINYINT},
</if>
<if test="isAd != null">
is_ad = #{isAd,jdbcType=TINYINT},
</if>
<if test="isTop != null">
is_top = #{isTop,jdbcType=TINYINT},
</if>
<if test="isEncrypt != null">
is_encrypt = #{isEncrypt,jdbcType=TINYINT},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>