标题图片管理

pull/25/head
xixiaowei 2021-12-15 12:25:54 +08:00
parent bec3356659
commit 3397662754
12 changed files with 741 additions and 0 deletions

View File

@ -24,6 +24,7 @@
<module>system-business-role</module>
<module>system-business-menu</module>
<module>system-business-notice</module>
<module>system-business-title</module>
<module>system-integration-beetl</module>
<module>system-integration-rest</module>
<module>system-spring-boot-starter</module>

View File

@ -0,0 +1,11 @@
package cn.stylefeng.roses.kernel.system.api;
/**
* api
*
* @author xixiaowei
* @date 2021/12/13 17:20
*/
public interface TitleServiceApi {
}

View File

@ -0,0 +1,45 @@
package cn.stylefeng.roses.kernel.system.api.exception.enums.title;
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
import cn.stylefeng.roses.kernel.system.api.constants.SystemConstants;
import lombok.Getter;
@Getter
public enum SysTitleExceptionEnum implements AbstractExceptionEnum {
/**
*
*/
TITLE_NOT_EXIST(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "101", "标题图片配置不存在id为{}"),
/**
*
*/
ENABLE_NOT_ALLOW_DELETE(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "102", "启用的配置不允许被删除id为{}"),
/**
*
*/
DISABLE_NOT_ALLOW_EDIT(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "103", "未启用的配置不允许被编辑id为{}"),
/**
*
*/
UNIQUE_ENABLE(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "104", "唯一启用的配置不允许禁用id为{}");
/**
*
*/
private final String errorCode;
/**
*
*/
private final String userTip;
SysTitleExceptionEnum(String errorCode, String userTip) {
this.errorCode = errorCode;
this.userTip = userTip;
}
}

View File

@ -0,0 +1,90 @@
package cn.stylefeng.roses.kernel.system.api.pojo.title;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import cn.stylefeng.roses.kernel.scanner.api.annotation.field.ChineseDescription;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.constraints.NotNull;
/**
*
*
* @author xixiaowei
* @date 2021/12/13 17:01
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class SysTitleRequest extends BaseRequest {
/**
* id
*/
@NotNull(message = "titleId不能为空", groups = {edit.class, delete.class, detail.class})
@ChineseDescription("标题id")
private Long titleId;
/**
*
*/
@NotNull(message = "标题名称不能为空", groups = {add.class, edit.class})
@ChineseDescription("标题名称")
private String titleName;
/**
*
*/
@NotNull(message = "公司名称不能为空", groups = {add.class, edit.class})
@ChineseDescription("公司名称")
private String companyName;
/**
*
*/
@NotNull(message = "平台名称不能为空", groups = {add.class, edit.class})
@ChineseDescription("平台名称")
private String platformName;
/**
*
*/
@NotNull(message = "平台英文名称不能为空", groups = {add.class, edit.class})
@ChineseDescription("平台英文名称")
private String platformEnglishName;
/**
*
*/
@NotNull(message = "背景图片不能为空", groups = {add.class, edit.class})
@ChineseDescription("背景图片")
private MultipartFile backgroundImage;
/**
* logo
*/
@NotNull(message = "公司logo不能为空", groups = {add.class, edit.class})
@ChineseDescription("公司logo")
private MultipartFile companyLogo;
/**
* icon
*/
@NotNull(message = "浏览器icon不能为空", groups = {add.class, edit.class})
@ChineseDescription("浏览器icon")
private MultipartFile browserIcon;
/**
*
*/
@NotNull(message = "首页名称不能为空", groups = {add.class, edit.class})
@ChineseDescription("首页名称")
private String pageName;
/**
*
*/
@NotNull(message = "首页图标不能为空", groups = {add.class, edit.class})
@ChineseDescription("首页图标")
private MultipartFile pageImage;
}

View File

@ -0,0 +1 @@
标题图片管理

View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>kernel-s-system</artifactId>
<groupId>cn.stylefeng.roses</groupId>
<version>7.1.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>system-business-title</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<!--系统管理的api-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>system-api</artifactId>
<version>${roses.version}</version>
</dependency>
<!--资源api模块-->
<!--用在资源控制器,资源扫描上-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>scanner-api</artifactId>
<version>${roses.version}</version>
</dependency>
<!--参数校验模块-->
<!--用在控制器,参数校验-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>validator-api</artifactId>
<version>${roses.version}</version>
</dependency>
<!--数据库sdk-->
<!--数据库dao框架-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>db-sdk-mp</artifactId>
<version>${roses.version}</version>
</dependency>
<!--web模块-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>file-business</artifactId>
<version>7.1.6</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,100 @@
package cn.stylefeng.roses.kernel.system.modular.title.controller;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.system.api.pojo.title.SysTitleRequest;
import cn.stylefeng.roses.kernel.system.modular.title.entity.SysTitle;
import cn.stylefeng.roses.kernel.system.modular.title.service.SysTitleService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
*
*
* @author xixiaowei
* @date 2021/12/13 17:29
*/
@RestController
@ApiResource(name = "标题图片配置管理")
public class SysTitleController {
@Resource
private SysTitleService sysTitleService;
/**
*
*
* @author xixiaowei
* @date 2021/12/14 9:26
*/
@PostResource(name = "添加标题图片配置", path = "/sysTitle/add")
public ResponseData add(@RequestBody @Validated(SysTitleRequest.add.class) SysTitleRequest sysTitleParam) {
sysTitleService.add(sysTitleParam);
return new SuccessResponseData();
}
/**
*
*
* @author xixiaowei
* @date 2021/12/14 9:28
*/
@PostResource(name = "删除标题图片配置", path = "/sysTitle/del")
public ResponseData del(@RequestBody @Validated(SysTitleRequest.delete.class) SysTitleRequest sysTitleParam) {
sysTitleService.del(sysTitleParam);
return new SuccessResponseData();
}
/**
*
*
* @author xixiaowei
* @date 2021/12/14 9:53
*/
@PostResource(name = "修改标题图片配置", path = "/sysTitle/edit")
public ResponseData edit(@RequestBody @Validated(SysTitleRequest.edit.class) SysTitleRequest sysTitleParam) {
sysTitleService.edit(sysTitleParam);
return new SuccessResponseData();
}
/**
*
*
* @author xixiaowei
* @date 2021/12/14 10:26
*/
@GetResource(name = "查询标题图片配置", path = "/sysTitle/find", responseClass = SysTitle.class)
public ResponseData findPage(SysTitleRequest sysTitleParam) {
return new SuccessResponseData(sysTitleService.findPage(sysTitleParam));
}
/**
*
*
* @author xixiaowei
* @date 2021/12/14 11:29
*/
@PostResource(name = "复制标题", path = "/sysTitle/copy")
public ResponseData copyTitle(@RequestBody @Validated(SysTitleRequest.add.class) SysTitleRequest sysTitleRequest) {
sysTitleService.copyTitle(sysTitleRequest);
return new SuccessResponseData();
}
/**
*
*
* @author xixiaowei
* @date 2021/12/14 11:43
*/
@PostResource(name = "修改启用状态", path = "/sysTitle/updateStatus")
public ResponseData updateStatus(@RequestBody @Validated(SysTitleRequest.edit.class) SysTitleRequest sysTitleRequest) {
sysTitleService.updateStatus(sysTitleRequest);
return new SuccessResponseData();
}
}

View File

@ -0,0 +1,99 @@
package cn.stylefeng.roses.kernel.system.modular.title.entity;
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
import cn.stylefeng.roses.kernel.scanner.api.annotation.field.ChineseDescription;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
*
*
* @author xixiaowei
* @date 2021/12/13 15:49
*/
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("sys_title")
public class SysTitle extends BaseEntity {
/**
* id
*/
@TableId(value = "title_id", type = IdType.ASSIGN_ID)
@ChineseDescription("标题id")
private Long titleId;
/**
*
*/
@TableField("title_name")
@ChineseDescription("标题名称")
private String titleName;
/**
*
*/
@TableField("company_name")
@ChineseDescription("公司名称")
private String companyName;
/**
*
*/
@TableField("platform_name")
@ChineseDescription("平台名称")
private String platformName;
/**
*
*/
@TableField("platform_english_name")
@ChineseDescription("平台英文名称")
private String platformEnglishName;
/**
*
*/
@TableField("background_image")
@ChineseDescription("背景图片")
private String backgroundImage;
/**
* logo
*/
@TableField("company_logo")
@ChineseDescription("公司logo")
private String companyLogo;
/**
* icon
*/
@TableField("browser_icon")
@ChineseDescription("浏览器icon")
private String browserIcon;
/**
*
*/
@TableField("page_name")
@ChineseDescription("首页名称")
private String pageName;
/**
*
*/
@TableField("page_image")
@ChineseDescription("首页图标")
private String pageImage;
/**
* Y N
*/
@TableField("status")
@ChineseDescription("启用状态")
private Character status;
}

View File

@ -0,0 +1,14 @@
package cn.stylefeng.roses.kernel.system.modular.title.mapper;
import cn.stylefeng.roses.kernel.system.modular.title.entity.SysTitle;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* mapper
*
* @author xixiaowei
* @date 2021/12/13 16:37
*/
public interface SysTitleMapper extends BaseMapper<SysTitle> {
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.stylefeng.roses.kernel.system.modular.title.mapper.SysTitleMapper">
</mapper>

View File

@ -0,0 +1,80 @@
package cn.stylefeng.roses.kernel.system.modular.title.service;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.system.api.TitleServiceApi;
import cn.stylefeng.roses.kernel.system.api.pojo.title.SysTitleRequest;
import cn.stylefeng.roses.kernel.system.modular.title.entity.SysTitle;
import com.baomidou.mybatisplus.extension.service.IService;
/**
*
*
* @author xixiaowei
* @date 2021/12/13 17:22
*/
public interface SysTitleService extends IService<SysTitle>, TitleServiceApi {
/**
*
*
* @param sysTitleRequest
* @author xixiaowei
* @date 2021/12/13 17:45
*/
void add(SysTitleRequest sysTitleRequest);
/**
*
*
* @param sysTitleRequest
* @author xixiaowei
* @date 2021/12/13 18:39
*/
void del(SysTitleRequest sysTitleRequest);
/**
*
*
* @param sysTitleRequest
* @author xixiaowei
* @date 2021/12/14 9:32
*/
void edit(SysTitleRequest sysTitleRequest);
/**
*
*
* @param sysTitleRequest
* @author xixiaowei
* @date 2021/12/14 11:38
*/
SysTitle detail(SysTitleRequest sysTitleRequest);
/**
*
*
* @param sysTitleRequest
* @return
* @author xixiaowei
* @date 2021/12/14 10:00
*/
PageResult<SysTitle> findPage(SysTitleRequest sysTitleRequest);
/**
*
*
* @param sysTitleRequest
* @author xixiaowei
* @date 2021/12/14 10:47
*/
void copyTitle(SysTitleRequest sysTitleRequest);
/**
*
*
* @param sysTitleRequest
* @author xixiaowei
* @date 2021/12/14 11:32
*/
void updateStatus(SysTitleRequest sysTitleRequest);
}

View File

@ -0,0 +1,232 @@
package cn.stylefeng.roses.kernel.system.modular.title.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.file.api.pojo.request.SysFileInfoRequest;
import cn.stylefeng.roses.kernel.file.api.pojo.response.SysFileInfoResponse;
import cn.stylefeng.roses.kernel.file.modular.service.SysFileInfoService;
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import cn.stylefeng.roses.kernel.system.api.exception.SystemModularException;
import cn.stylefeng.roses.kernel.system.api.exception.enums.title.SysTitleExceptionEnum;
import cn.stylefeng.roses.kernel.system.api.pojo.title.SysTitleRequest;
import cn.stylefeng.roses.kernel.system.modular.title.entity.SysTitle;
import cn.stylefeng.roses.kernel.system.modular.title.mapper.SysTitleMapper;
import cn.stylefeng.roses.kernel.system.modular.title.service.SysTitleService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
/**
*
*
* @author xixiaowei
* @date 2021/12/13 17:28
*/
@Service
public class SysTitleServiceImpl extends ServiceImpl<SysTitleMapper, SysTitle> implements SysTitleService {
private static final Long DEFAULT_FILE_UPLOAD = null;
@Resource
private SysFileInfoService sysFileInfoService;
@Override
public void add(SysTitleRequest sysTitleRequest) {
SysTitle sysTitle = new SysTitle();
// 拷贝属性
BeanUtil.copyProperties(sysTitleRequest, sysTitle);
// 启用状态默认为未启用 N
sysTitle.setStatus(YesOrNotEnum.N.getCode().charAt(0));
// 保存图片信息
SysFileInfoResponse backgroundImageResponse = this.uploadFile(sysTitleRequest.getBackgroundImage(), DEFAULT_FILE_UPLOAD);
sysTitle.setBackgroundImage(backgroundImageResponse.getFileId().toString());
SysFileInfoResponse browserIconResponse = this.uploadFile(sysTitleRequest.getBrowserIcon(), DEFAULT_FILE_UPLOAD);
sysTitle.setBrowserIcon(browserIconResponse.getFileId().toString());
SysFileInfoResponse companyLogoResponse = this.uploadFile(sysTitleRequest.getCompanyLogo(), DEFAULT_FILE_UPLOAD);
sysTitle.setCompanyLogo(companyLogoResponse.getFileId().toString());
SysFileInfoResponse pageImageResponse = this.uploadFile(sysTitleRequest.getPageImage(), DEFAULT_FILE_UPLOAD);
sysTitle.setPageImage(pageImageResponse.getFileId().toString());
// 保存配置信息
this.save(sysTitle);
}
/**
*
*
* @param multipartFile
* @author xixiaowei
* @date 2021/12/14 14:40
*/
private SysFileInfoResponse uploadFile(MultipartFile multipartFile, Long fileCode) {
SysFileInfoRequest sysFileInfoRequest = new SysFileInfoRequest();
sysFileInfoRequest.setFileId(IdWorker.getId());
if (fileCode != null) {
sysFileInfoRequest.setFileCode(fileCode);
}
sysFileInfoRequest.setSecretFlag(YesOrNotEnum.N.getCode());
sysFileInfoRequest.setFileLocation(4);
sysFileInfoRequest.setFilePath("D:\\test");
sysFileInfoRequest.setFileOriginName(multipartFile.getOriginalFilename());
return sysFileInfoService.uploadFile(multipartFile, sysFileInfoRequest);
}
@Override
public void del(SysTitleRequest sysTitleRequest) {
SysTitle sysTitle = this.querySysTitleById(sysTitleRequest);
// 启用状态不允许删除
if (Character.valueOf(YesOrNotEnum.Y.getCode().charAt(0)).equals(sysTitle.getStatus())) {
throw new SystemModularException(SysTitleExceptionEnum.ENABLE_NOT_ALLOW_DELETE, sysTitleRequest.getTitleId());
}
// 删除配置
this.removeById(sysTitle);
}
/**
*
*
* @author xixiaowei
* @date 2021/12/14 9:18
*/
private SysTitle querySysTitleById(SysTitleRequest sysTitleRequest) {
SysTitle sysTitle = this.getById(sysTitleRequest.getTitleId());
if (ObjectUtil.isEmpty(sysTitle)) {
throw new SystemModularException(SysTitleExceptionEnum.TITLE_NOT_EXIST, sysTitleRequest.getTitleId());
}
return sysTitle;
}
@Override
public void edit(SysTitleRequest sysTitleRequest) {
SysTitle sysTitle = this.querySysTitleById(sysTitleRequest);
// 未启用状态不允许编辑
if (Character.valueOf(YesOrNotEnum.N.getCode().charAt(0)).equals(sysTitle.getStatus())) {
throw new SystemModularException(SysTitleExceptionEnum.DISABLE_NOT_ALLOW_EDIT, sysTitleRequest.getTitleId());
}
// 图片修改
sysTitle.setBackgroundImage(this.updateFile(sysTitleRequest.getBackgroundImage(), sysTitle.getBackgroundImage()));
sysTitle.setBrowserIcon(this.updateFile(sysTitleRequest.getBrowserIcon(), sysTitle.getBrowserIcon()));
sysTitle.setCompanyLogo(this.updateFile(sysTitleRequest.getCompanyLogo(), sysTitle.getCompanyLogo()));
sysTitle.setPageImage(this.updateFile(sysTitleRequest.getPageImage(), sysTitle.getPageImage()));
// 更新属性
BeanUtil.copyProperties(sysTitleRequest, sysTitle);
// 修改配置
this.updateById(sysTitle);
}
/**
*
*
* @param multipartFile
* @param fileId Id
* @return Id
* @author xixiaowei
* @date 2021/12/14 15:21
*/
private String updateFile(MultipartFile multipartFile, String fileId) {
SysFileInfoResponse fileInfoResult = sysFileInfoService.getFileInfoResult(Long.parseLong(fileId));
// 上传图片
SysFileInfoResponse sysFileInfoResponse = this.uploadFile(multipartFile, fileInfoResult.getFileCode());
return sysFileInfoResponse.getFileId().toString();
}
@Override
public SysTitle detail(SysTitleRequest sysTitleRequest) {
return this.querySysTitleById(sysTitleRequest);
}
@Override
public PageResult<SysTitle> findPage(SysTitleRequest sysTitleRequest) {
LambdaQueryWrapper<SysTitle> wrapper = this.createWrapper(sysTitleRequest);
Page<SysTitle> page = this.page(PageFactory.defaultPage(), wrapper);
return PageResultFactory.createPageResult(page);
}
/**
* Wrapper
*
* @author xixiaowei
* @date 2021/12/14 10:04
*/
private LambdaQueryWrapper<SysTitle> createWrapper(SysTitleRequest sysTitleRequest) {
LambdaQueryWrapper<SysTitle> wrapper = new LambdaQueryWrapper<>();
// 按照创建时间倒序
wrapper.orderByDesc(BaseEntity::getCreateTime);
// 如果标题不为空,根据标题名称模糊查询;如果标题为空,查询全部
wrapper.like(StrUtil.isNotBlank(sysTitleRequest.getTitleName()), SysTitle::getTitleName, sysTitleRequest.getTitleName());
return wrapper;
}
@Override
public void copyTitle(SysTitleRequest sysTitleRequest) {
SysTitle sysTitle = this.querySysTitleById(sysTitleRequest);
SysTitle title = new SysTitle();
// 拷贝属性
BeanUtil.copyProperties(sysTitle, title);
// 修改标题名称
title.setTitleName(sysTitle.getTitleName() + "复制");
// 标题状态设为默认状态 未启用 N
title.setStatus(YesOrNotEnum.N.getCode().charAt(0));
// 保存配置信息
this.save(title);
}
@Override
public void updateStatus(SysTitleRequest sysTitleRequest) {
SysTitle sysTitle = this.querySysTitleById(sysTitleRequest);
// 如果状态为唯一启用状态不允许被禁用, 如果为未启用状态则可以启用该配置同时禁用已启用的标题配置
if (Character.valueOf(YesOrNotEnum.Y.getCode().charAt(0)).equals(sysTitle.getStatus())) {
throw new SystemModularException(SysTitleExceptionEnum.UNIQUE_ENABLE, sysTitleRequest.getTitleId());
} else {
// 设置为启用状态
sysTitle.setStatus(YesOrNotEnum.Y.getCode().charAt(0));
// 修改已启用的标题配置
if (this.updateEnableToDisableStatus()) {
updateById(sysTitle);
}
}
}
/**
*
*
* @author xixiaowei
* @date 2021/12/14 14:00
*/
private Boolean updateEnableToDisableStatus() {
// 查询已启用的标题配置
LambdaQueryWrapper<SysTitle> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(SysTitle::getStatus, YesOrNotEnum.Y.getCode().charAt(0));
SysTitle sysTitle = getOne(wrapper);
// 修改状态
sysTitle.setStatus(YesOrNotEnum.N.getCode().charAt(0));
return updateById(sysTitle);
}
}