Commit b2b1958f authored by zhoumaotao's avatar zhoumaotao

调整代码

parent 59ef8fcb
<?xml version="1.0"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.gavel.parent</groupId>
<artifactId>gavel-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../gavel-parent</relativePath>
</parent>
<groupId>com.gavel.platform</groupId>
<artifactId>gavel-common</artifactId>
<name>gavel-common</name>
<version>1.0.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.compile.version>1.8</project.compile.version>
</properties>
<dependencies>
<!-- spring 模块 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<!-- spring 结束 -->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.23</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</dependency>
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.gavel.platform</groupId>
<artifactId>gavel-persistence</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.github.javaparser</groupId>
<artifactId>javaparser-symbol-solver-core</artifactId>
<version>3.5.19</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
</dependency>
<!-- zxing - 二位码工具库 -->
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
</dependency>
<!-- start for swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
</dependency>
<!-- end for swagger -->
<dependency>
<groupId>com.monitorjbl</groupId>
<artifactId>xlsx-streamer</artifactId>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</dependency>
<dependency>
<groupId>org.t-io</groupId>
<artifactId>tio-utils</artifactId>
</dependency>
</dependencies>
</project>
package com.gavel.common;
public class BaseURL {
public static final String PAGEINIT = "/init";
public static final String QUERY = "/query";
public static final String QUERY_DETAIL = "/query/detail";
public static final String ADD = "/add";
public static final String ADD_VALID="/addValid";
public static final String UPDATE = "/update";
public static final String EDIT_VALID="/editValid";
public static final String DELETE = "/delete";
public static final String DElETE_VALID="/deleteValid";
public static final String BATCH_DELETE = "/batch/delete";
public static final String HELP = "/help";
public static final String REGISTER = "/register";
public static final String SETQT = "/record/qt";
public static final String GET = "/get";
public static final String DETAILS = "/details";
public static final String WFNEXTINFO = "/wfnextinfo";
public static final String WFNODEINFO = "/wfnodeinfo";
public static final String WFGO = "/wfgo";
public static final String WFGOBACK = "/wfgoback";
public static final String WFPULLBACK = "/wfpullback";
public static final String WFTRANSFER = "/wftransfer";
public static final String WFMANAGE = "/wfmanage";
public static final String EXPORT ="/export";
public static final String PRINTLOG = "/print/end";
}
package com.gavel.common;
public class CommonCacheConstant {
public static final String SYS_XTCS_CACHE = "XTCS";
}
package com.gavel.common;
public class Constants {
public static final String C_CRLF = System.getProperty("line.separator"); //获取回车换行符
public static final String GO = "GO"; //获取回车换行符
public static final String TREE_LEVEL_SPLIT = "-";
public static final String TREE_ROOT = "root";
public static class Page{
public static final String PAGENO = "pageno"; //页码
public static final String ROWCOUNT = "rowcount"; //每页行数
}
public static final String DEFAULT_APLICATION_NAME="格物软件";
public static final String MASTER = "master";
public static final String DETAILS = "details";
public static final String DETAIL = "detail";
public static final String DETAILLIST = "deleteList";
public static final String ID = "id";
public static final String URL_ORIGIN = "originUrl";
public static final String URL_VIEW = "viewUrl";
public static final String MASTER_ID = "mid";
public static final String EXTEND = "extend";
public static final String RECORDCOUT = "total"; //总记录数
public static final String RECORDSUM = "sum";
public static final String RECORDS = "records";
public static final String DATA = "data";
public static final String FILEDS = "fields";
public static final String DETAIL_RECORDS = "detailRecords";
/*public static final String DETAIL_FILEDS = "detailFields";*/
public static class CLOUD{
public static final String TITLE= "systitle";
public static final String URL = "sysurl";
public static final String SYSTEM_PASSWORD = "password";
public static final String SYSTEM_NEW_PASSWORD = "newPassword";
public static final String DEFAULT_TITLE= "cloudtitle";
public static final String DEFAULT_LOGIN_CONNECT_INDENT= "/";
public static final String DEFAULT_LOGIN_CONNECT_LOGIN_URL= "/main/login";
public static final String DEFAULT_LOGIN_CONNECT_APPLOGIN_URL= "/main/app/login";
}
public static class UserInfo{
public static final String ID= "userkey";
public static final String USERID = "userid";
public static final String USERNAME = "username";
public static final String ORGNAME = "orgname";
public static final String SUPERUSER = "superuser";
public static final String REMOTEIP = "remoteip";
public static final String REMOTEPORT = "remoteport";
public static final String USERTYPE = "usertype";
public static final String ROLES = "roles";
public static final String LOGINTIME = "logintime";
public static final String PUSHID = "pushid";
public static final String TOKEN = "token";
public static String getName() {
return "userinfo";
}
}
public static class WorkFlow{
public static final String NEXTINFO = "nextinfo";
public static final String OPERATE = "wfoperate";
public static final String WFID = "wfid";
public static final String WFINSTID = "wfinstid";
public static final String WFPID = "wfpid";
public static final String WFPNAME = "wfpname";
public static final String WFWUSERID = "wfwuserid";
public static final String WFWUSERNAME = "wfwusername";
public static final String WFHUSERID = "wfhuserid";
public static final String WFHUSERNAME = "wfhusername";
public static final String STATE_WAIT = "W";
public static final String STATE_HANDLE = "H";
public static final String STATE_ALL = "A";
}
public static class Attach{
public static final String COUNT = "attachcount";
public static final String GROUPID = "id";
}
public static class Print{
public static final String MASTER = "Master";
public static final String DETAIL = "Detail";
public static final String DETAIL0 = "Detail0";
}
public static final String RESOUCE_FILE_MODULE = "module.xml";
public static final String PROFILES = "profiles";
public static final String SUPERUSERID="SUPERUSER";
public static final String SUPERUSERNAME="超级用户";
public static class NumberRound{
public static final int PRICE = 6;
public static final int MONEY = 2;
}
public static class StringSplit{
public static final String IDSPLIT = ",";
}
public static class ExpressionVar{
public static final String DATE = "SERVERDATE";
public static final String DATETIME = "SERVERDATETIME";
public static final String USERID = "USERID";
public static final String USERNAME = "USERNAME";
public static final String YEAR = "YEAR";
public static final String MONTH = "MONTH";
public static final String WEEK = "WEEK";
public static final String WEEKOFMONTH = "WEEKOFMONTH";
}
/**
* 访问路径设置固定
*/
public static final String ACCESS_FILE_PATH = "api/file";
public static final String RES_FILE_PATH = "/api/file/**";
public static final String PATH_VIEW = "view";
}
package com.gavel.common;
public class ControlType {
public final static String TEXT = "text";
public final static String TYZT = "tyzt";
public final static String FLOWZT = "flowzt";
public final static String REG_STATUS = "reg";
public final static String MEMO = "memo";
public final static String COMBOBOX = "combobox";
public final static String CHECKBOX = "checkbox";
public final static String DATE = "date";
public final static String DATETIME = "datetime";
public final static String TIME = "time";
public final static String INT = "int";
public final static String FLOAT = "float";
public final static String QUANTITY = "quantity";
public final static String MONEY = "money";
public final static String PRICE = "price";
public final static String TEXTAREA = "TextArea";
public final static String RICHTEXT = "RichText";
}
package com.gavel.common;
public class SystemOperation {
public static class BottonResource {
public final static String ADD = "01";
public final static String EDIT = "02";
public final static String DELETE = "03";
public final static String EXPORT = "04"; //数据导出
public final static String PRINT = "05"; //打印
}
}
package com.gavel.common.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface GavelCacheInit {
String value() default "";
}
package com.gavel.common.annotation;
import static java.lang.annotation.ElementType.TYPE;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface GavelParams {
String value() default "";
}
package com.gavel.common.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.web.bind.annotation.Mapping;
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Mapping
public @interface NoRepeatSubmit {
String value() default "";
int lockTime() default 30000;
}
package com.gavel.common.annotation;
import org.springframework.web.bind.annotation.Mapping;
import java.lang.annotation.*;
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Mapping
public @interface ResourcePermissions {
String[] value() default {};
}
package com.gavel.common.attachment.dao;
import com.gavel.common.attachment.model.FileauthModel;
import com.gavel.common.attachment.persistent.Attachment;
import com.gavel.common.attachment.persistent.Folder;
import com.gavel.common.attachment.vo.AttachmentCondition;
import com.gavel.common.attachment.vo.AttachmentVO;
import com.gavel.common.base.dao.BaseDao;
import java.util.List;
public interface AttachmentDao extends BaseDao {
public List<Folder> queryAllSubFolder(String path);
public List<Folder> querySubFolder(String id);
public List<Attachment> queryAttachmentByGroupidAndFolder(String groupid, String folder);
public List<Attachment> queryAttachmentByGroupid(String groupid);
public List<Attachment> queryAttachmentByFolder(String folder);
public List<FileauthModel> queryFileAuth(String folder);
public List<AttachmentVO> queryAttachment(AttachmentCondition condition);
}
package com.gavel.common.attachment.dao.impl;
import com.gavel.common.attachment.dao.AttachmentDao;
import com.gavel.common.attachment.model.FileauthModel;
import com.gavel.common.attachment.persistent.Attachment;
import com.gavel.common.attachment.persistent.Folder;
import com.gavel.common.attachment.vo.AttachmentCondition;
import com.gavel.common.attachment.vo.AttachmentVO;
import com.gavel.common.base.dao.impl.BaseDaoImpl;
import com.gavel.common.utils.StringUtils;
import com.gavel.persistence.sql.SqlMap;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository("attachmentDao")
public class AttachmentDaoImpl extends BaseDaoImpl implements AttachmentDao {
/**
* 根据父文件路径获取所有的子文件夹(包含子文件的子文件夹)
* @param path
* @return
*/
public List<Folder> queryAllSubFolder(String path){
SqlMap sqlMap = new SqlMap();
sqlMap.append("select FOLDER_ID, FOLDER_PID, FOLDER_NAME, FOLDER_TYPE, FOLDER_AUTHTYPE, ");
sqlMap.append(" FOLDER_VERSION, FOLDER_LOG, FOLDER_PATH, FOLDER_VERSION, FOLDER_BZ, ");
sqlMap.append(" FOLDER_WHRID, FOLDER_WHSJ, FOLDER_WHR, FOLDER_CJRID, FOLDER_CJR,");
sqlMap.append(" FOLDER_CJSJ");
sqlMap.append("from FOLDER");
sqlMap.append("where FOLDER_PATH like :FOLDER_PATH");
sqlMap.setParamValue("FOLDER_PATH", path+"%");
return sqlMap.query(Folder.class);
}
public List<Folder> querySubFolder(String id){
SqlMap sqlMap = new SqlMap();
sqlMap.append("select FOLDER_ID, FOLDER_PID, FOLDER_NAME, FOLDER_TYPE, FOLDER_AUTHTYPE, ");
sqlMap.append(" FOLDER_VERSION, FOLDER_LOG, FOLDER_PATH, FOLDER_VERSION, FOLDER_BZ, ");
sqlMap.append(" FOLDER_WHRID, FOLDER_WHSJ, FOLDER_WHR, FOLDER_CJRID, FOLDER_CJR,");
sqlMap.append(" FOLDER_CJSJ");
sqlMap.append("from FOLDER");
sqlMap.append("where FOLDER_PID = :FOLDER_PID");
sqlMap.setParamValue("FOLDER_PID", id);
return sqlMap.query(Folder.class);
}
/**
* 查询 某个 单据下 某个文件夹中的文件
* @param groupid
* @param folder
* @return
*/
public List<Attachment> queryAttachmentByGroupidAndFolder(String groupid, String folder){
SqlMap sqlMap = new SqlMap();
sqlMap.append("select FILES_ID, FILES_FOLDER, FILES_GROUPID, FILES_PATH, FILES_NAME,");
sqlMap.append(" FILES_TYPE, FILES_SIZE, FILES_BZ, FILES_DELETE, FILES_VERSION,");
sqlMap.append(" FILES_SDRID, FILES_SDR, FILES_SDSJ, FILES_WHRID, FILES_WHR,");
sqlMap.append(" FILES_WHSJ, FILES_CJRID, FILES_CJR, FILES_CJSJ, FILES_ISSTATIC ");
sqlMap.append("from FILES");
sqlMap.append("where FILES_GROUPID = :FILES_GROUPID and FILES_FOLDER = :FILES_FOLDER");
sqlMap.setParamValue("FILES_GROUPID", groupid);
sqlMap.setParamValue("FILES_FOLDER", folder);
return sqlMap.query(Attachment.class);
}
/**
* 查询 某个单据下 所有的文件
* @param groupid
* @return
*/
public List<Attachment> queryAttachmentByGroupid(String groupid){
SqlMap sqlMap = new SqlMap();
sqlMap.append("select FILES_ID, FILES_FOLDER, FILES_GROUPID, FILES_PATH, FILES_NAME,");
sqlMap.append(" FILES_TYPE, FILES_SIZE, FILES_BZ, FILES_DELETE, FILES_VERSION,");
sqlMap.append(" FILES_SDRID, FILES_SDR, FILES_SDSJ, FILES_WHRID, FILES_WHR,");
sqlMap.append(" FILES_WHSJ, FILES_CJRID, FILES_CJR, FILES_CJSJ, FILES_ISSTATIC");
sqlMap.append("from FILES");
sqlMap.append("where FILES_GROUPID = :FILES_GROUPID");
sqlMap.setParamValue("FILES_GROUPID", groupid);
return sqlMap.query(Attachment.class);
}
/**
* 查询某个文件夹下所有的文件
* @param folder
* @return
*/
public List<Attachment> queryAttachmentByFolder(String folder){
SqlMap sqlMap = new SqlMap();
sqlMap.append("select FILES_ID, FILES_FOLDER, FILES_GROUPID, FILES_PATH, FILES_NAME,");
sqlMap.append(" FILES_TYPE, FILES_SIZE, FILES_BZ, FILES_DELETE, FILES_VERSION,");
sqlMap.append(" FILES_SDRID, FILES_SDR, FILES_SDSJ, FILES_WHRID, FILES_WHR,");
sqlMap.append(" FILES_WHSJ, FILES_CJRID, FILES_CJR, FILES_CJSJ, FILES_ISSTATIC");
sqlMap.append("from FILES");
sqlMap.append("where FILES_FOLDER = :FILES_FOLDER");
sqlMap.setParamValue("FILES_FOLDER", folder);
return sqlMap.query(Attachment.class);
}
/**
* 查询文件夹权限
* @param folder
*/
@Override
public List<FileauthModel> queryFileAuth(String folder){
SqlMap sqlMap = new SqlMap();
sqlMap.append("select FILEAUTH_ID, FILEAUTH_FOLDER, FILEAUTH_TYPE, FILEAUTH_CODE, FILEAUTH_READ, ");
sqlMap.append(" FILEAUTH_WRITE, FILEAUTH_DOWN, FOLDER_AUTHTYPE, FOLDER_LOG, FOLDER_VERSION ");
sqlMap.append("from FOLDER");
sqlMap.append(" left join FILEAUTH on FILEAUTH_FOLDER = FOLDER_ID");
sqlMap.append("where FILEAUTH_FOLDER = :FILEAUTH_FOLDER");
sqlMap.setParamValue("FILEAUTH_FOLDER", folder);
return sqlMap.query(FileauthModel.class);
}
@Override
public List<AttachmentVO> queryAttachment(AttachmentCondition condition){
SqlMap sqlMap = new SqlMap();
sqlMap.append("select FILES_ID, FILES_FOLDER, FILES_GROUPID, FILES_PATH, FILES_NAME,");
sqlMap.append(" FILES_TYPE, FILES_SIZE, FILES_BZ, FILES_DELETE, FILES_VERSION,");
sqlMap.append(" FILES_SDRID, FILES_SDR, FILES_SDSJ, FILES_WHRID, FILES_WHR,");
sqlMap.append(" FILES_WHSJ, FILES_CJRID, FILES_CJR, FILES_CJSJ, FILES_ISSTATIC ");
sqlMap.append("from FILES");
sqlMap.append("where 1 = 1 ");
if(StringUtils.isNotEmpty(condition.getFolder())){
sqlMap.append(" and FILES_FOLDER = :FILES_FOLDER ");
sqlMap.setParamValue("FILES_FOLDER", condition.getFolder());
}
if(StringUtils.isNotEmpty(condition.getGroupid())){
sqlMap.append(" and FILES_GROUPID = :FILES_GROUPID ");
sqlMap.setParamValue("FILES_GROUPID", condition.getGroupid());
}
if(StringUtils.isNotEmpty(condition.getUserid())){
sqlMap.append(" and FILES_CJRID = :FILES_CJRID ");
sqlMap.setParamValue("FILES_CJRID", condition.getUserid());
}
sqlMap.append("order by FILES_CJSJ ");
return sqlMap.query(AttachmentVO.class);
}
}
package com.gavel.common.attachment.model;
import com.gavel.common.attachment.persistent.Fileauth;
import com.gavel.persistence.annotation.FieldMeta;
public class FileauthModel extends Fileauth {
/**
*
*/
private static final long serialVersionUID = -7713259582958507686L;
@FieldMeta(fieldName="FOLDER_AUTHTYPE", caption = "权限类型")
private String authtype;
@FieldMeta(fieldName="FOLDER_LOG", caption = "记录日志")
private String log;
@FieldMeta(fieldName="FOLDER_VERSION", caption = "版本管理")
private String version;
public String getAuthtype() {
return authtype;
}
public void setAuthtype(String authtype) {
this.authtype = authtype;
}
public String getLog() {
return log;
}
public void setLog(String log) {
this.log = log;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
}
package com.gavel.common.attachment.model;
import com.gavel.common.base.entity.BaseEntity;
import com.gavel.persistence.annotation.FieldMeta;
import com.gavel.persistence.annotation.TableMeta;
@TableMeta(id = "USERROLES", name = "USERROLES")
public class UserRolesModel extends BaseEntity {
/**
*
*/
private static final long serialVersionUID = 1666565218883801443L;
@FieldMeta(fieldName = "USERROLES_USERID", caption = "用户编码")
private String userid;
@FieldMeta(fieldName = "USERROLES_ROLEID", caption = "角色编码")
private String roleid;
public String getUserid() {
return userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
public String getRoleid() {
return roleid;
}
public void setRoleid(String roleid) {
this.roleid = roleid;
}
}
package com.gavel.common.attachment.persistent;
import com.gavel.common.base.entity.BaseEntity;
import com.gavel.persistence.annotation.FieldMeta;
import com.gavel.persistence.annotation.TableMeta;
import java.util.Date;
/**
* 避免 和 系统类 冲突,将本类命名为Attachment
*
* @author zhouyi
*
*/
@TableMeta(id = "FILES", name = "FILES")
public class Attachment extends BaseEntity {
/**
*
*/
private static final long serialVersionUID = 1L;
/*---------AutoBegin-----------*/
@FieldMeta(fieldName = "FILES_ID", caption = "ID", primaryKey = true, length = 32, notEmpty = true)
private String id;
@FieldMeta(fieldName = "FILES_FOLDER", caption = "文件夹编码", length = 32, notEmpty = true)
private String folder;
@FieldMeta(fieldName = "FILES_GROUPID", caption = "附件组编码", length = 32)
private String groupid;
@FieldMeta(fieldName = "FILES_NAME", caption = "文档名称", length = 128, notEmpty = true)
private String name;
@FieldMeta(fieldName = "FILES_TYPE", caption = "文档类型", length = 8)
private String type;
@FieldMeta(fieldName = "FILES_SIZE", caption = "文档大小", index = 6)
private Long size;
@FieldMeta(fieldName = "FILES_CSIZE", caption = "压缩后大小")
private Long csize;
@FieldMeta(fieldName = "FILES_PATH", caption = "存储路径", length = 128)
private String path;
@FieldMeta(fieldName = "FILES_COMPRESS", caption = "压缩方式", length = 8)
private String compress;
@FieldMeta(fieldName = "FILES_ISCOMPRESS", caption = "是否被压缩")
private String iscompress;
@FieldMeta(fieldName = "FILES_VERSION", caption = "版本")
private Integer version;
@FieldMeta(fieldName = "FILES_SDRID", caption = "锁定人", length = 20)
private String sdrid;
@FieldMeta(fieldName = "FILES_SDR", caption = "锁定人ID", length = 30)
private String sdr;
@FieldMeta(fieldName = "FILES_SDSJ", caption = "锁定时间")
private Date sdsj;
@FieldMeta(fieldName = "FILES_WHRID", caption = "维护人", length = 10)
private String whrid;
@FieldMeta(fieldName = "FILES_WHR", caption = "维护人", length = 30)
private String whr;
@FieldMeta(fieldName = "FILES_WHSJ", caption = "维护时间")
private Date whsj;
@FieldMeta(fieldName = "FILES_CJRID", caption = "创建人编码", length = 10)
private String cjrid;
@FieldMeta(fieldName = "FILES_CJR", caption = "创建人", length = 30)
private String cjr;
@FieldMeta(fieldName = "FILES_CJSJ", caption = "创建时间")
private Date cjsj;
@FieldMeta(fieldName = "FILES_BZ", caption = "说明", length = 255)
private String bz;
@FieldMeta(fieldName = "FILES_DELETE", caption = "删除", length = 1)
private String delete;
@FieldMeta(fieldName = "FILES_MESSAGE", caption = "更新说明", length = 255)
private String message;
@FieldMeta(fieldName = "FILES_PREVIEW", caption = "预览图")
private String preview;
@FieldMeta(fieldName = "FILES_FILE", caption = "文件内容")
private String file;
@FieldMeta(fieldName = "FILES_ISSTATIC", caption = "是否静态文件")
private String isstatic;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFolder() {
return folder;
}
public void setFolder(String folder) {
this.folder = folder;
}
public String getGroupid() {
return groupid;
}
public void setGroupid(String groupid) {
this.groupid = groupid;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getCompress() {
return compress;
}
public void setCompress(String compress) {
this.compress = compress;
}
public Long getSize() {
return size;
}
public void setSize(Long size) {
this.size = size;
}
public String getSdrid() {
return sdrid;
}
public void setSdrid(String sdrid) {
this.sdrid = sdrid;
}
public String getSdr() {
return sdr;
}
public void setSdr(String sdr) {
this.sdr = sdr;
}
public Date getSdsj() {
return sdsj;
}
public void setSdsj(Date sdsj) {
this.sdsj = sdsj;
}
public String getWhrid() {
return whrid;
}
public void setWhrid(String whrid) {
this.whrid = whrid;
}
public String getWhr() {
return whr;
}
public void setWhr(String whr) {
this.whr = whr;
}
public Date getWhsj() {
return whsj;
}
public void setWhsj(Date whsj) {
this.whsj = whsj;
}
public String getCjrid() {
return cjrid;
}
public void setCjrid(String cjrid) {
this.cjrid = cjrid;
}
public String getCjr() {
return cjr;
}
public void setCjr(String cjr) {
this.cjr = cjr;
}
public Date getCjsj() {
return cjsj;
}
public void setCjsj(Date cjsj) {
this.cjsj = cjsj;
}
public String getBz() {
return bz;
}
public void setBz(String bz) {
this.bz = bz;
}
public String getDelete() {
return delete;
}
public void setDelete(String delete) {
this.delete = delete;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Long getCsize() {
return csize;
}
public void setCsize(Long csize) {
this.csize = csize;
}
public String getIscompress() {
return iscompress;
}
public void setIscompress(String iscompress) {
this.iscompress = iscompress;
}
public String getPreview() {
return preview;
}
public void setPreview(String preview) {
this.preview = preview;
}
public String getFile() {
return file;
}
public void setFile(String file) {
this.file = file;
}
public String getIsstatic() {
return isstatic;
}
public void setIsstatic(String isstatic) {
this.isstatic = isstatic;
}
/*---------AutoEnd-------------*/
}
package com.gavel.common.attachment.persistent;
import java.util.Date;
import com.gavel.common.base.entity.BaseEntity;
import com.gavel.common.utils.CodeStrategy;
import com.gavel.persistence.annotation.FieldMeta;
import com.gavel.persistence.annotation.TableMeta;
@TableMeta(id = "FILEAUTH", name = "FILEAUTH")
public class Fileauth extends BaseEntity {
/**
*
*/
private static final long serialVersionUID = 1L;
/*---------AutoBegin-----------*/
@FieldMeta(fieldName = "FILEAUTH_ID", caption = "ID", primaryKey = true, length = 32, codeStrategy = CodeStrategy.UUID)
private String id;
@FieldMeta(fieldName = "FILEAUTH_FOLDER", caption = "文件夹", length = 32)
private String folder;
@FieldMeta(fieldName = "FILEAUTH_TYPE", caption = "用户类型", length = 10)
private String type;
@FieldMeta(fieldName = "FILEAUTH_CODE", caption = "用户编码", length = 20)
private String code;
@FieldMeta(fieldName = "FILEAUTH_READ", caption = "读", length = 1)
private String read;
@FieldMeta(fieldName = "FILEAUTH_WRITE", caption = "写", length = 1)
private String write;
@FieldMeta(fieldName = "FILEAUTH_DOWN", caption = "下载", length = 1)
private String down;
@FieldMeta(fieldName = "FILEAUTH_CJRID", caption = "创建人编码", length = 20)
private String cjrid;
@FieldMeta(fieldName = "FILEAUTH_CJR", caption = "创建人", length = 30)
private String cjr;
@FieldMeta(fieldName = "FILEAUTH_CJSJ", caption = "创建时间")
private Date cjsj;
@FieldMeta(fieldName = "FILEAUTH_WHRID", caption = "维护人编码", length = 20)
private String whrid;
@FieldMeta(fieldName = "FILEAUTH_WHR", caption = "维护人", length = 30)
private String whr;
@FieldMeta(fieldName = "FILEAUTH_WHSJ", caption = "维护时间")
private Date whsj;
@FieldMeta(fieldName = "FILEAUTH_SYSVERSION", caption = "系统版本", defaultValue = "1")
private Integer sysversion;
public String getId(){
return id;
};
public String getFolder() {
return folder;
}
public void setFolder(String folder) {
this.folder = folder;
}
public void setId(String id){
this.id = id;
};
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getRead(){
return read;
};
public void setRead(String read){
this.read = read;
};
public String getWrite(){
return write;
};
public void setWrite(String write){
this.write = write;
};
public String getDown(){
return down;
};
public void setDown(String down){
this.down = down;
};
public String getCjrid(){
return cjrid;
};
public void setCjrid(String cjrid){
this.cjrid = cjrid;
};
public String getCjr(){
return cjr;
};
public void setCjr(String cjr){
this.cjr = cjr;
};
public Date getCjsj(){
return cjsj;
};
public void setCjsj(Date cjsj){
this.cjsj = cjsj;
};
public String getWhrid(){
return whrid;
};
public void setWhrid(String whrid){
this.whrid = whrid;
};
public String getWhr(){
return whr;
};
public void setWhr(String whr){
this.whr = whr;
};
public Date getWhsj(){
return whsj;
};
public void setWhsj(Date whsj){
this.whsj = whsj;
};
public Integer getSysversion(){
return sysversion;
};
public void setSysversion(Integer sysversion){
this.sysversion = sysversion;
};
/*---------AutoEnd-------------*/
}
package com.gavel.common.attachment.persistent;
import java.util.Date;
import com.gavel.common.base.entity.BaseEntity;
import com.gavel.common.utils.CodeStrategy;
import com.gavel.persistence.annotation.FieldMeta;
import com.gavel.persistence.annotation.TableMeta;
@TableMeta(id = "FILEHIST", name = "FILEHIST")
public class Filehist extends BaseEntity {
/**
*
*/
private static final long serialVersionUID = 1L;
/*---------AutoBegin-----------*/
@FieldMeta(fieldName = "FILEHIST_ID", caption = "ID", primaryKey = true, length = 32, notEmpty = true, codeStrategy = CodeStrategy.UUID)
private String id;
@FieldMeta(fieldName = "FILEHIST_FILEID", caption = "文件ID", length = 32, notEmpty = true)
private String fileid;
@FieldMeta(fieldName = "FILEHIST_VERSION", caption = "版本", notEmpty = true)
private Integer version;
@FieldMeta(fieldName = "FILEHIST_NAME", caption = "文件名", length = 128)
private String name;
@FieldMeta(fieldName = "FILEHIST_TYPE", caption = "文档类型", length = 8)
private String type;
@FieldMeta(fieldName = "FILEHIST_MESSAGE", caption = "更新说明", length = 255)
private String message;
@FieldMeta(fieldName = "FILEHIST_PATH", caption = "存储路径", length = 128)
private String path;
@FieldMeta(fieldName = "FILEHIST_SIZE", caption = "文档大小")
private Long size;
@FieldMeta(fieldName = "FILEHIST_COMPRESS", caption = "压缩方式", length = 8)
private String compress;
@FieldMeta(fieldName = "FILEHIST_OPTYPE", caption = "操作类型", length = 1)
private String optype;
@FieldMeta(fieldName = "FILEHIST_CJRID", caption = "创建人编码", length = 20, notEmpty = true)
private String cjrid;
@FieldMeta(fieldName = "FILEHIST_CJR", caption = "创建人", length = 30, notEmpty = true)
private String cjr;
@FieldMeta(fieldName = "FILEHIST_CJSJ", caption = "创建时间", notEmpty = true)
private Date cjsj;
public String getId(){
return id;
};
public void setId(String id){
this.id = id;
};
public String getFileid(){
return fileid;
};
public void setFileid(String fileid){
this.fileid = fileid;
};
public Integer getVersion(){
return version;
};
public void setVersion(Integer version){
this.version = version;
};
public String getName(){
return name;
};
public void setName(String name){
this.name = name;
};
public String getType(){
return type;
};
public void setType(String type){
this.type = type;
};
public String getMessage(){
return message;
};
public void setMessage(String message){
this.message = message;
};
public String getPath(){
return path;
};
public void setPath(String path){
this.path = path;
};
public Long getSize(){
return size;
};
public void setSize(Long size){
this.size = size;
};
public String getCompress(){
return compress;
};
public void setCompress(String compress){
this.compress = compress;
};
public String getOptype(){
return optype;
};
public void setOptype(String optype){
this.optype = optype;
};
public String getCjrid(){
return cjrid;
};
public void setCjrid(String cjrid){
this.cjrid = cjrid;
};
public String getCjr(){
return cjr;
};
public void setCjr(String cjr){
this.cjr = cjr;
};
public Date getCjsj(){
return cjsj;
};
public void setCjsj(Date cjsj){
this.cjsj = cjsj;
};
/*---------AutoEnd-------------*/
}
package com.gavel.common.attachment.persistent;
import java.util.Date;
import com.gavel.common.base.entity.BaseEntity;
import com.gavel.common.utils.CodeStrategy;
import com.gavel.persistence.annotation.FieldMeta;
import com.gavel.persistence.annotation.TableMeta;
@TableMeta(id = "FILELOG", name = "FILELOG")
public class Filelog extends BaseEntity {
/**
*
*/
private static final long serialVersionUID = 1L;
/*---------AutoBegin-----------*/
@FieldMeta(fieldName = "FILELOG_ID", caption = "ID", primaryKey = true, length = 32, notEmpty = true, codeStrategy = CodeStrategy.UUID)
private String id;
@FieldMeta(fieldName = "FILELOG_FILEID", caption = "文件ID", length = 32, notEmpty = true)
private String fileid;
@FieldMeta(fieldName = "FILELOG_OP", caption = "操作类型", length = 1, notEmpty = true)
private String op;
@FieldMeta(fieldName = "FILELOG_USERID", caption = "操作人工号", length = 20, notEmpty = true)
private String userid;
@FieldMeta(fieldName = "FILELOG_USERNAME", caption = "操作人", length = 30, notEmpty = true)
private String username;
@FieldMeta(fieldName = "FILELOG_OPTIME", caption = "操作时间", notEmpty = true)
private Date optime;
@FieldMeta(fieldName = "FILELOG_HISTID", caption = "历史文档ID", length = 32)
private String histid;
@FieldMeta(fieldName = "FILELOG_MESSAGE", caption = "历史文档ID", length = 32)
private String message;
public String getId(){
return id;
};
public void setId(String id){
this.id = id;
};
public String getFileid(){
return fileid;
};
public void setFileid(String fileid){
this.fileid = fileid;
};
public String getOp(){
return op;
};
public void setOp(String op){
this.op = op;
};
public String getUserid(){
return userid;
};
public void setUserid(String userid){
this.userid = userid;
};
public String getUsername(){
return username;
};
public void setUsername(String username){
this.username = username;
};
public Date getOptime(){
return optime;
};
public void setOptime(Date optime){
this.optime = optime;
};
public String getHistid(){
return histid;
};
public void setHistid(String histid){
this.histid = histid;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
};
/*---------AutoEnd-------------*/
}
package com.gavel.common.attachment.persistent;
import java.util.Date;
import com.gavel.common.base.entity.BaseEntity;
import com.gavel.common.utils.CodeStrategy;
import com.gavel.persistence.annotation.FieldMeta;
import com.gavel.persistence.annotation.TableMeta;
@TableMeta(id = "FOLDER", name = "FOLDER")
public class Folder extends BaseEntity {
/**
*
*/
private static final long serialVersionUID = 1L;
/*---------AutoBegin-----------*/
@FieldMeta(fieldName = "FOLDER_ID", caption = "ID", primaryKey = true, length = 32, notEmpty = true, codeStrategy = CodeStrategy.UUID)
private String id;
@FieldMeta(fieldName = "FOLDER_PID", caption = "父目录ID", length = 32)
private String pid;
//文件夹类型 分为 文档中心 和 单据附件
@FieldMeta(fieldName = "FOLDER_TYPE", caption = "文件类型", length = 1)
private String type;
@FieldMeta(fieldName = "FOLDER_PATH", caption = "路径", length = 2048, notEmpty = true)
private String path;
@FieldMeta(fieldName = "FOLDER_NAME", caption = "名称", length = 128, notEmpty = true)
private String name;
@FieldMeta(fieldName = "FOLDER_ZCYS",caption = "支持压缩")
private String zcys;
@FieldMeta(fieldName = "FOLDER_VERSION", caption = "版本管理", length = 1, notEmpty = true)
private String version;
@FieldMeta(fieldName = "FOLDER_AUTHTYPE", caption = "权限类型", length = 10, notEmpty = true)
private String authtype;
@FieldMeta(fieldName = "FOLDER_LOG", caption = "记录日志", length = 1, notEmpty = true)
private String log;
@FieldMeta(fieldName = "FOLDER_BZ", caption = "备注", length = 255)
private String bz;
@FieldMeta(fieldName = "FOLDER_WHRID", caption = "维护人", length = 20)
private String whrid;
@FieldMeta(fieldName = "FOLDER_WHSJ", caption = "维护时间")
private Date whsj;
@FieldMeta(fieldName = "FOLDER_WHR", caption = "维护人", length = 30)
private String whr;
@FieldMeta(fieldName = "FOLDER_CJRID", caption = "创建人编码", length = 20)
private String cjrid;
@FieldMeta(fieldName = "FOLDER_CJR", caption = "创建人", length = 30)
private String cjr;
@FieldMeta(fieldName = "FOLDER_CJSJ", caption = "创建时间", length = 19)
private Date cjsj;
public String getId(){
return id;
};
public void setId(String id){
this.id = id;
};
public String getPid() {
return pid;
}
public void setPid(String pid) {
this.pid = pid;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getPath(){
return path;
};
public void setPath(String path){
this.path = path;
};
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getVersion(){
return version;
};
public void setVersion(String version){
this.version = version;
};
public String getAuthtype() {
return authtype;
}
public void setAuthtype(String authtype) {
this.authtype = authtype;
}
public String getLog() {
return log;
}
public void setLog(String log) {
this.log = log;
}
public String getBz(){
return bz;
};
public void setBz(String bz){
this.bz = bz;
};
public String getWhrid(){
return whrid;
};
public void setWhrid(String whrid){
this.whrid = whrid;
};
public Date getWhsj(){
return whsj;
};
public void setWhsj(Date whsj){
this.whsj = whsj;
};
public String getWhr(){
return whr;
};
public void setWhr(String whr){
this.whr = whr;
};
public String getCjrid(){
return cjrid;
};
public void setCjrid(String cjrid){
this.cjrid = cjrid;
};
public String getCjr(){
return cjr;
};
public void setCjr(String cjr){
this.cjr = cjr;
};
public Date getCjsj(){
return cjsj;
};
public void setCjsj(Date cjsj){
this.cjsj = cjsj;
};
public String getZcys() {
return zcys;
}
public void setZcys(String zcys) {
this.zcys = zcys;
}
/*---------AutoEnd-------------*/
}
package com.gavel.common.attachment.service;
import com.gavel.common.attachment.persistent.Attachment;
import com.gavel.common.attachment.utils.FileOperator;
import com.gavel.common.attachment.vo.AttachmentCondition;
import com.gavel.common.attachment.vo.AttachmentVO;
import com.gavel.common.base.service.BaseService;
import org.springframework.web.multipart.MultipartFile;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.List;
public interface AttachmentService extends BaseService {
/**
* 上传新增文件
* @param multipartFile
* @param folderOrPath
* @param groupid
* @return
*/
public Attachment upload(MultipartFile multipartFile, String folderOrPath, String groupid);
/**
* 上传更新文件
* @param multipartFile
* @param id
* @return
*/
public void modify(MultipartFile multipartFile, String id, String message);
/**
* 下载文件
* @param id
* @return
*/
public FileInputStream download(String id);
/**
* 缩略图
* @param id
* @return
*/
public InputStream previewThumbnail(String id);
/**
* 删除文件
* @param id
*/
public void delete(String id);
/**
* 获取 某个分组 某个文件夹下的文件以及文件夹,不包含子文件夹下的文件
* @param groupid
* @param
* @return
*/
public List<Attachment> getAttachmentAndSubFolder(String groupid, String folderOrPath);
/**
* 获取 某个分组 某个文件夹下的所有文件以及文件夹,包含所有的子文件夹)
* @param groupid
* @param
* @return
*/
public List<Attachment> getAllAttachmentAndSubFolder(String groupid, String folderOrPath);
/**
* 权限校验
* @param op
* @param folderid
* @param userid
* @return
*/
public boolean validateAuth(FileOperator op, String folderid, String userid);
/**
* 上传服务器本地文件
* @param sourcePathName
* @param folderOrPath
* @param groupid
* @return
*/
public Attachment upload(String sourcePathName, String folderOrPath, String groupid);
/**
* 使用服务器本地文件更新
* @param sourcePathName
* @param id
* @param message
*/
public void modify(String sourcePathName, String id, String message);
/**
* 获取文件的预览图片
* @param id
* @return
*/
public String preview(String id);
/**
* 上传新增文件-资源存储
* @param multipartFile
* @param folderOrPath
* @param groupid
* @return
*/
public Attachment staticUpload(MultipartFile multipartFile, String folderOrPath, String groupid);
/**
* 上传服务器本地文件-资源存储
* @param sourcePathName
* @param folderOrPath
* @param groupid
* @return
*/
public Attachment staticUpload(String sourcePathName, String folderOrPath, String groupid);
/**
* 查询文件,返回文件ID及访问路径
* @param condition
* @return
*/
public List<AttachmentVO> queryAttachmentForPreivew(AttachmentCondition condition);
/**
* 固定名称上传
* @param multipartFile
* @param folderOrPath
* @param groupid
* @param constantName
* @return
*/
public Attachment upload(MultipartFile multipartFile, String folderOrPath, String groupid, String constantName);
/**
* 固定名称上传
* @param multipartFile
* @param folderOrPath
* @param groupid
* @param constantName
* @return
*/
public Attachment staticUpload(MultipartFile multipartFile, String folderOrPath, String groupid, String constantName);
}
package com.gavel.common.attachment.service;
import java.io.File;
import java.io.InputStream;
import org.springframework.web.multipart.MultipartFile;
import com.gavel.common.base.service.BaseService;
public interface FileService extends BaseService {
public void addFile(InputStream in, String path, String fileName);
public void addFile(MultipartFile multipartFile, String path, String fileName);
public void addFile(File file, String path, String fileName);
public void addFile(String sourcePathName, String path, String fileName);
public boolean addFilehist(String oldpath, String oldFileName, String newpath, String newFileName);
public boolean deleteFile(String path, String fileName);
}
package com.gavel.common.attachment.service.impl;
import java.io.File;
import java.io.InputStream;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import com.gavel.common.attachment.service.FileService;
import com.gavel.common.base.service.impl.BaseServiceImpl;
@Service("ftpFileService")
public class FtpFileServiceImpl extends BaseServiceImpl implements FileService {
@Override
public void addFile(InputStream in, String path, String fileName) {
}
@Override
public void addFile(MultipartFile multipartFile, String path, String fileName) {
}
@Override
public void addFile(File file, String path, String fileName) {
}
@Override
public boolean deleteFile(String path, String fileName) {
return false;
}
@Override
public boolean addFilehist(String oldpath, String oldFileName, String newpath, String newFileName) {
return false;
}
@Override
public void addFile(String sourcePathName, String path, String fileName) {
}
}
package com.gavel.common.attachment.service.impl;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import com.gavel.common.attachment.service.FileService;
import com.gavel.common.base.service.impl.BaseServiceImpl;
@Service("localFileService")
public class LocalFileServiceImpl extends BaseServiceImpl implements FileService {
private Logger logger = LoggerFactory.getLogger(LocalFileServiceImpl.class);
@Override
public void addFile(InputStream in, String path, String fileName) {
File dir = new File(path);
if ( !dir.exists() ){
dir.mkdirs();
}
try{
File target = new File(path + File.separator + fileName);
FileOutputStream fos = new FileOutputStream(target);
try {
IOUtils.copy(in, fos);
}finally {
fos.close();
//在调用处关闭
// in.close();
}
}catch(Exception e){
throw new RuntimeException(e.getMessage());
}
}
@Override
public void addFile(MultipartFile multipartFile, String path, String fileName) {
try{
InputStream inputStream = multipartFile.getInputStream();
try{
addFile(inputStream, path, fileName);
} finally {
inputStream.close();
}
}catch(Exception e){
throw new RuntimeException(e.getMessage());
}
}
@Override
public void addFile(File file, String path, String fileName) {
try{
FileInputStream fileInputStream = new FileInputStream(file);
try {
addFile(fileInputStream, path, fileName);
}finally {
fileInputStream.close();
}
}catch(Exception e){
throw new RuntimeException(e.getMessage());
}
}
@Override
public void addFile(String sourcePathName, String path, String fileName) {
try{
InputStream ins = new FileInputStream(new File(sourcePathName));
try {
addFile(ins, path, fileName);
}finally {
ins.close();
}
}catch(Exception e){
throw new RuntimeException(e.getMessage());
}
}
@Override
public boolean deleteFile(String path, String fileName) {
File file = new File(path + File.separator + fileName);
// 如果文件路径所对应的文件存在,并且是一个文件,则直接删除
if (file.exists() && file.isFile()) {
if (file.delete()) {
logger.debug("删除单个文件" + fileName + "成功!");
return true;
} else {
throw new RuntimeException("删除单个文件" + fileName + "失败!");
}
}
logger.info("删除单个文件失败:" + fileName + "失败!原因:文件不存在!");
return false;
}
@Override
public boolean addFilehist(String oldpath, String oldFileName, String newpath, String newFileName) {
File file = new File(oldpath + File.separator + oldFileName);
if (file.exists() && file.isFile()) {
File dir = new File(newpath);
if ( !dir.exists() ){
dir.mkdirs();
}
File newFile = new File(newpath + File.separator+ newFileName);
file.renameTo(newFile);
return true;
}else {
return false;
}
}
}
package com.gavel.common.attachment.utils;
public enum FileAuthType {
PUBLIC, USER;
}
package com.gavel.common.attachment.utils;
public class FileConstants {
public static final String AUTHTYPE_USER = "U";
public static final String AUTHTYPE_ROLE = "R";
public static final String ROOT_ID = "root";
public static final String FOLDER_DOCUMENT = "D";
public static final String FOLDER_ATTACHMENT = "A";
public static final String FILE_LOGO = "LOGO";
}
package com.gavel.common.attachment.utils;
public enum FileOperator {
READ, ADD, DELETE, UPDATE, DOWNLOAD, DESTROY;
}
package com.gavel.common.attachment.vo;
import com.gavel.common.base.entity.BaseEntity;
/**
* @Author youjian.ding
* @Date $
**/
public class AttachmentCondition extends BaseEntity {
/**
*
*/
private static final long serialVersionUID = 1521223735366843688L;
private String folder;
private String groupid;
private String userid;
private String type;
private String folderPath;
public String getFolder() {
return folder;
}
public void setFolder(String folder) {
this.folder = folder;
}
public String getGroupid() {
return groupid;
}
public void setGroupid(String groupid) {
this.groupid = groupid;
}
public String getUserid() {
return userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getFolderPath() {
return folderPath;
}
public void setFolderPath(String folderPath) {
this.folderPath = folderPath;
}
}
package com.gavel.common.attachment.vo;
import com.gavel.common.attachment.persistent.Attachment;
/**
* @Author youjian.ding
* @Date $
**/
public class AttachmentVO extends Attachment {
/**
*
*/
private static final long serialVersionUID = -6540117478594267655L;
private String originUrl;
private String viewUrl;
public String getOriginUrl() {
return originUrl;
}
public void setOriginUrl(String originUrl) {
this.originUrl = originUrl;
}
public String getViewUrl() {
return viewUrl;
}
public void setViewUrl(String viewUrl) {
this.viewUrl = viewUrl;
}
}
package com.gavel.common.base;
import java.util.ArrayList;
import java.util.List;
import com.gavel.common.base.entity.BaseEntity;
public class BaseEditDataSet {
private BaseEntity master;
private List<List<? extends BaseEntity>> detailList;
//批量删除
private List<BaseEntity> deleteList;
public BaseEditDataSet() {
}
public BaseEditDataSet(BaseEntity master) {
this.master = master;
}
public BaseEntity getMaster() {
return master;
}
public void setMaster(BaseEntity master) {
this.master = master;
}
public List<List<? extends BaseEntity>> getDetailList() {
return detailList;
}
public void setDetailList(List<List<? extends BaseEntity>> detailList) {
this.detailList = detailList;
}
public void addMaster(BaseEntity master){
this.master = master;
}
public void addDetail(List<? extends BaseEntity> detail){
if (detailList == null){
detailList = new ArrayList<List<? extends BaseEntity>>();
}
detailList.add(detail);
}
public void resetDetail(List<? extends BaseEntity> detail){
if (detail == null || detail.size() <= 0)
return;
if (detailList == null) {
detailList = new ArrayList<>();
detailList.add(detail);
}
Class<? extends BaseEntity> clazz = detail.get(0).getClass();
boolean bReset = false;
for (List<?> list : detailList) {
if (list != null && list.size() > 0) {
if (list.get(0) != null && clazz!=null && clazz.equals(list.get(0).getClass()) ) {
list = detail;
bReset = true;
}
}
}
if (!bReset)
detailList.add(detail);
}
public List<BaseEntity> getDeleteList() {
return deleteList;
}
public void setDeleteList(List<BaseEntity> deleteList) {
this.deleteList = deleteList;
}
@SuppressWarnings("unchecked")
public <T> List<T> getDetail(Class<? extends BaseEntity> clazz){
if (detailList == null)
return new ArrayList<>();
for (List<?> list : detailList) {
if (list != null && list.size() > 0) {
if (list.get(0) != null && clazz!=null && clazz.equals(list.get(0).getClass()) ) {
return (List<T>) list;
}
}
}
return new ArrayList<>();
}
@SuppressWarnings("unchecked")
public <T> T getMaster(Class<? extends BaseEntity> clazz) {
if (master != null) {
return (T)master;
}else {
throw new RuntimeException("数据异常!");
}
}
}
package com.gavel.common.base;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gavel.common.Constants;
import com.gavel.common.base.bean.TableInfoBuilder;
public class BaseEditDetail {
private String id;
private String extend;
private JSONArray records;
private TableInfoBuilder tableInfoBuilder;
public BaseEditDetail() {};
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getExtend() {
return extend;
}
public void setExtend(String extend) {
this.extend = extend;
}
public JSONArray getRecords() {
return records;
}
public void setRecords(JSONArray records) {
this.records = records;
}
public static BaseEditDetail parseJSON(JSONObject json){
BaseEditDetail result = new BaseEditDetail();
result.setId(json.getString(Constants.ID));
result.setExtend(json.getString(Constants.EXTEND));
result.setRecords(json.getJSONArray(Constants.RECORDS));
return result;
}
public String toString() {
return toJSONString();
}
public String toJSONString() {
return JSON.toJSONString(this);
}
public TableInfoBuilder getTableInfoBuilder() {
return tableInfoBuilder;
}
public void setTableInfoBuilder(TableInfoBuilder tableInfoBuilder) {
this.tableInfoBuilder = tableInfoBuilder;
}
}
package com.gavel.common.base;
import java.util.List;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gavel.common.Constants;
import com.gavel.common.base.bean.TableInfoBuilder;
public class BaseEditJSON {
private JSONObject master;
private BaseEditDetail[] details;
private JSONArray deleteList;
//动态实体支持,存储master的数据结构
private TableInfoBuilder tableInfoBuilder;
public BaseEditJSON() {};
public JSONObject getMaster() {
return master;
}
public void setMaster(JSONObject master) {
this.master = master;
}
public BaseEditDetail[] getDetails() {
return details;
}
public void setDetails(BaseEditDetail[] details) {
this.details = details;
}
public static BaseEditJSON parseJSON(String text) {
return BaseEditJSON.parseJSON(JSONObject.parseObject(text));
}
public static BaseEditJSON parseJSON(JSONObject json) {
BaseEditJSON result = new BaseEditJSON();
Object master = json.get(Constants.MASTER);
if (master != null && (master instanceof JSONObject || master instanceof String))
result.setMaster(json.getJSONObject(Constants.MASTER));
else {
Object deleteArray = json.get(Constants.DETAILLIST);
if (deleteArray != null)
result.setDeleteList(json.getJSONArray(Constants.DETAILLIST));
}
if (result.getMaster() == null && result.getDeleteList() == null)
result.setMaster(json);
Object detailObjects = json.get(Constants.DETAILS);
if (detailObjects != null && (detailObjects instanceof JSONArray || detailObjects instanceof String)) {
JSONArray detailJson = json.getJSONArray(Constants.DETAILS);
if (detailJson != null && detailJson.size() > 0) {
BaseEditDetail[] details = new BaseEditDetail[detailJson.size()];
for (int i = 0; i < detailJson.size(); i++) {
details[i] = BaseEditDetail.parseJSON(detailJson.getJSONObject(i));
}
result.setDetails(details);
}
}
return result;
}
public void addMaster(Object obj) {
this.master = (JSONObject) JSON.toJSON(obj);
}
//添加明细
public void addBaseEditDetail(String id, List<Object> records) {
BaseEditDetail dtl = new BaseEditDetail();
dtl.setId(id);
if (records != null) {
dtl.setRecords((JSONArray) JSON.toJSON(records));
}
if (details == null) {
details = new BaseEditDetail[] { dtl };
} else {
int len = details.length;
BaseEditDetail[] updArray = new BaseEditDetail[len + 1];
for (int i = 0; i < len; ++i) {
updArray[i] = details[i];
}
updArray[len] = dtl;
details = updArray;
}
}
public JSONArray getDeleteList() {
return deleteList;
}
public void setDeleteList(JSONArray deleteList) {
this.deleteList = deleteList;
}
public TableInfoBuilder getTableInfoBuilder() {
return tableInfoBuilder;
}
public void setTableInfoBuilder(TableInfoBuilder tableInfoBuilder) {
this.tableInfoBuilder = tableInfoBuilder;
}
}
package com.gavel.common.base.bean;
import com.gavel.common.base.entity.BaseEntity;
public interface Marshaller {
BaseEntity unmarshal();
}
package com.gavel.common.base.bean;
import com.gavel.common.base.entity.DynamicEntity;
import com.gavel.common.dataset.DataField;
import java.util.List;
public interface TableInfoBuilder {
List<DataField> dataFields(DynamicEntity entity);
String tableName();
}
package com.gavel.common.base.dao;
import com.gavel.common.base.entity.BaseEntity;
import java.util.List;
import java.util.Map;
import java.util.Set;
public interface BaseDao {
/**
* 插入数据时自动设置创建人、创建时间、维护人、维护时间
* @param entity
* @return
*/
public int insert(BaseEntity entity);
/**
* 维护数据时自动设置维护人、维护时间
* @param entity
* @return
*/
public int update(BaseEntity entity);
/**
* 根据关键字删除数据
* @param entity
* @return
*/
public int delete(BaseEntity entity);
/**
* 指定null值需要更新的字段
* @param entities
* @param nullNameSet
* @return
*/
public int update(BaseEntity entity, Set<String> nullNameSet);
/**
* 插入数据时不自动设置创建人、创建时间、维护人、维护时间
* @param entity
* @return
*/
public int insertByUser(BaseEntity entity);
/**
* 维护数据时不自动设置维护人、维护时间
* @param entity
* @return
*/
public int updateByUser(BaseEntity entity);
/**
* 根据条件删除数据
* @param entity
* @return
*/
public int deleteByEntity(BaseEntity entity);
/**
* 根据关键字查询
* @param entity
* @return
*/
public <T> T queryByKey(BaseEntity entity);
//根据条件查询单条记录
public <T> T queryByEntity(BaseEntity entity);
//根据条件查询记录列表
public <T> List<T> queryListByEntity(BaseEntity entity);
/**
* 根据关键字查询数据
* @param clz
* @param id
* @return
*/
public <T> T queryById(Class<T> clz, Object id);
/**
* 根据关键字列表查询数据
* @param clz
* @param ids
* @return
*/
public <T> List<T> queryByIds(Class<T> clz, List<String> ids);
/**
* 更新时自动设置创建人、维护人、创建时间、维护时间
* @param entities
* @return
*/
public int batchAdd(List<? extends BaseEntity> entities);
/**
* 更新时自动更新维护时间
* @param entities
* @return
*/
public int batchUpdate(List<? extends BaseEntity> entities);
/**
* 更新时自动更新维护时间
* @param entities
* @return
*/
public int batchUpdate(List<? extends BaseEntity> entities, Set<String> nullNameSet);
public int batchDelete(List<? extends BaseEntity> entities);
/**
* 插入时不自动设置维护时间
* @param entities
* @return
*/
public int batchAddByUser(List<? extends BaseEntity> entities);
/**
* 全量插入
* @param entities
* @return
*/
public int batchAddAllByUser(List<? extends BaseEntity> entities);
public int batchAddAll(List<? extends BaseEntity> entities);
/**
* 更新时不自动设置默认值
* @param entities
* @return
*/
public int batchUpdateByUser(List<? extends BaseEntity> entities);
/**
* 指定null值需要更新的字段
* @param entities
* @param nullNameSet
* @return
*/
public int batchUpdateByUser(List<? extends BaseEntity> entities, Set<String> nullNameSet);
/**
* 指定null值需要更新的字段
* @param entity
* @param nullNameSet
* @return
*/
public int updateByUser(BaseEntity entity, Set<String> nullNameSet);
/**
* 根据map更新记录,map里边的字段全量更新
* @param clazz
* @param map
* @return
*/
public int update(Class<? extends BaseEntity> clazz, Map<String, Object> map);
}
package com.gavel.common.base.dao.impl;
import com.gavel.common.base.dao.BaseDao;
import com.gavel.common.base.entity.BaseEntity;
import com.gavel.common.dataset.DataField;
import com.gavel.common.dataset.DataRecord;
import com.gavel.common.sql.GavelSql;
import com.gavel.common.utils.StringUtils;
import com.gavel.persistence.entity.EntityDataFactory;
import com.gavel.persistence.entity.EntityField;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
public abstract class BaseDaoImpl implements BaseDao{
@Override
public final int insert(BaseEntity entity){
entity.setFlag(BaseEntity.INSERT);
DataRecord record = entity.dataRecord();
record.setDefaultValue();
return GavelSql.insertDataReocrd(record);
}
@Override
public final int update(BaseEntity entity){
entity.setFlag(BaseEntity.UPDATE);
DataRecord record = entity.dataRecord();
record.setDefaultValue();
return GavelSql.updateDataReocrd(record);
}
@Override
public final int update(BaseEntity entity, Set<String> nullNameSet){
entity.setFlag(BaseEntity.UPDATE);
DataRecord record = entity.dataRecord();
record.setDefaultValue();
return GavelSql.updateDataReocrd(record, nullNameSet);
}
@Override
public final int insertByUser(BaseEntity entity){
entity.setFlag(BaseEntity.INSERT);
DataRecord record = entity.dataRecord();
return GavelSql.insertDataReocrd(record);
}
@Override
public final int updateByUser(BaseEntity entity){
entity.setFlag(BaseEntity.UPDATE);
DataRecord record = entity.dataRecord();
return GavelSql.updateDataReocrd(record);
}
@Override
public final int delete(BaseEntity entity){
return GavelSql.deleteEntity(entity);
}
@Override
public final int deleteByEntity(BaseEntity entity){
return GavelSql.deleteByEntity(entity);
}
@Override
public final <T> T queryByKey(BaseEntity entity){
return GavelSql.selectEntityByKey(entity);
}
@Override
public final <T> T queryByEntity(BaseEntity entity){
return GavelSql.selectEntity(entity);
}
@Override
public final <T> List<T> queryListByEntity(BaseEntity entity){
return GavelSql.selectList(entity);
}
@Override
public <T> T queryById(Class<T> clz, Object id) {
if ( clz==null || id==null || StringUtils.isBlank(id.toString())){
return null;
}
return GavelSql.selectEntityByKey(clz, id);
}
@Override
public <T> List<T> queryByIds(Class<T> clz, List<String> ids){
return GavelSql.selectListByKeys(clz, ids);
}
@Override
public int batchAdd(List<? extends BaseEntity> entities) {
return GavelSql.batchAdd(entities, true);
}
@Override
public int batchAddAll(List<? extends BaseEntity> entities) {
return GavelSql.batchAdd(entities, true,true);
}
@Override
public int batchUpdate(List<? extends BaseEntity> entities) {
return GavelSql.batchUpdate(entities, true, null);
}
@Override
public int batchUpdate(List<? extends BaseEntity> entities, Set<String> nullNameSet) {
return GavelSql.batchUpdate(entities, true, nullNameSet);
}
@Override
public int batchDelete(List<? extends BaseEntity> entities) {
return GavelSql.batchDelete(entities);
}
@Override
public int batchAddByUser(List<? extends BaseEntity> entities) {
return GavelSql.batchAdd(entities);
}
@Override
public int batchAddAllByUser(List<? extends BaseEntity> entities) {
return GavelSql.batchAdd(entities,false, true);
}
@Override
public int batchUpdateByUser(List<? extends BaseEntity> entities, Set<String> nullNameSet) {
return GavelSql.batchUpdate(entities, nullNameSet);
}
@Override
public int updateByUser(BaseEntity entity, Set<String> nullNameSet){
entity.setFlag(BaseEntity.UPDATE);
DataRecord record = entity.dataRecord();
return GavelSql.updateDataReocrd(record,nullNameSet);
}
@Override
public int update(Class<? extends BaseEntity> clazz, Map<String, Object> map) {
DataRecord record = new DataRecord(clazz);
Set<String> nullFieldSet = new HashSet<>();
List<EntityField> fields = EntityDataFactory.getDataFields(clazz);
for (EntityField field : fields) {
if (map.containsKey(field.getName())){
DataField dataField = record.getFieldByName(field.getName());
if (dataField != null) {
dataField.setValue(map.get(field.getName()));
nullFieldSet.add(field.getName());
}
}
}
return GavelSql.updateDataReocrd(record, nullFieldSet);
}
@Override
public int batchUpdateByUser(List<? extends BaseEntity> entities) {
return GavelSql.batchUpdate(entities);
}
}
package com.gavel.common.base.entity;
import com.alibaba.fastjson.annotation.JSONField;
import com.gavel.common.dataset.DataRecord;
import com.gavel.persistence.entity.EntityDataFactory;
import java.io.Serializable;
import java.util.Map;
public class BaseEntity implements Serializable {
@JSONField(serialize=false, deserialize=false)
private static final long serialVersionUID = 1L;
public final static String INSERT = "I";
public final static String UPDATE = "U";
public final static String DELETE = "D";
public final static String extraName = "extSysObj";
public Object getExtSysObj() {
return extSysObj;
}
public void setExtSysObj(Object extSysObj) {
this.extSysObj = extSysObj;
}
public enum DataState {
INSERT("I"), UPDATE("U"), DELETE("D"), INACTIVE("");
private String flag;
DataState(String flag) {
this.flag = flag;
}
public String getFlag() {
return flag;
}
public static DataState getDataStateByFlag(String flag) {
if (INSERT.flag.equalsIgnoreCase(flag)) {
return INSERT;
} else if (UPDATE.flag.equalsIgnoreCase(flag)) {
return UPDATE;
} else if (DELETE.flag.equalsIgnoreCase(flag)) {
return DELETE;
}
return INACTIVE;
}
}
@JSONField(serialize=false, deserialize=false)
private String tableName;
private String flag;
private boolean master;
private int pageNo;
private int pageSize;
private int recordCount;
private DataRecord dataRecord;
private Object extSysObj;
public synchronized DataRecord dataRecord(){
if ( dataRecord == null) {
dataRecord = new DataRecord(this);
}else {
dataRecord.updateValue(this);
}
return dataRecord;
}
public String getTableName() {
if (tableName == null) {
initTable();
}
return tableName;
}
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
public boolean isMaster() {
return master;
}
public void setMaster(boolean master) {
this.master = master;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getPageNo() {
return pageNo;
}
public void setPageNo(int pageNo) {
this.pageNo = pageNo;
}
public int getRecordCount() {
return recordCount;
}
public void setRecordCount(int recordCount) {
this.recordCount = recordCount;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
public DataState dataState() {
return DataState.getDataStateByFlag(flag);
}
public Map<String, Object> toMap(){
return new DataRecord(this).toMap();
}
private void initTable() {
this.tableName = EntityDataFactory.getTableName(getClass());
}
}
package com.gavel.common.base.entity;
import com.gavel.common.dataset.DataField;
import com.gavel.persistence.annotation.TableMeta;
import com.gavel.persistence.processor.DynamicBean;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@TableMeta(id = "", name = "")
public class DynamicEntity extends BaseEntity implements DynamicBean {
/**
*
*/
private static final long serialVersionUID = 1L;
private List<DataField> dataFields = new ArrayList<>();
private Map<String, Object> values = new HashMap<>();
//是否启用工作流
private boolean enableWorkflow;
public Map<String, Object> getValues() {
return values;
}
public void setValues(Map<String, Object> values) {
this.values = values;
}
@Override
public Object setValue(String name, Object value) {
if ( name==null ) {
return null;
}
Object exist = values.get(name);
values.put(name, value);
return exist;
}
@Override
public Object getValue(String name) {
if ( name==null ) {
return null;
}
return values.get(name.toLowerCase().trim());
}
public List<DataField> buildFields() {
for (DataField dataField : dataFields) {
dataField.setValue(getValue(dataField.getName()));
}
return dataFields;
}
public List<DataField> getDataFields() {
return dataFields;
}
public void setDataFields(List<DataField> dataFields) {
this.dataFields = dataFields;
}
public void convertValueByDataField(String table, List<DataField> dataFieldList) {
Map<String, Object> map = new HashMap<>();
map.putAll(values);
values.clear();
setTableName(table);
if (dataFields.size() == 0) {
dataFields.addAll(dataFieldList);
}
for (DataField dataField: dataFields) {
values.put(dataField.getName(), map.get(dataField.getFieldName()));
}
}
public boolean isEnableWorkflow() {
return enableWorkflow;
}
public void setEnableWorkflow(boolean enableWorkflow) {
this.enableWorkflow = enableWorkflow;
};
}
package com.gavel.common.base.service;
import com.gavel.common.base.BaseEditJSON;
import com.gavel.common.base.entity.BaseEntity;
import org.springframework.web.multipart.MultipartFile;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.List;
public interface BaseEditService extends BaseService {
//增删改
public void insert(BaseEditJSON json);
public BaseEntity insert(BaseEntity entity);
public void update(BaseEditJSON json);
public BaseEntity update(BaseEntity entity);
public void delete(BaseEditJSON json);
public void delete(BaseEntity entity);
//是否允许增删改的判断
public boolean promiseInsert(BaseEntity entity);
public boolean promiseUpdate(BaseEntity entity);
public boolean promiseDelete(BaseEntity entity);
//页面数据初始化
public void pageInit();
//启停记录
public void recordSetQT(BaseEntity entity);
public void insert(BaseEntity master, List<? extends BaseEntity> detailList);
public void update(BaseEntity master, List<? extends BaseEntity> detailList);
//附件相关方法
/**
* 附件上传
* @param multipartFile
* @param folderId
* @param groupid
*/
public String attachmentUpload(MultipartFile multipartFile, String folderId, String groupid);
//附件相关方法
/**
* 资源上传
* @param multipartFile
* @param folderId
* @param groupid
*/
public String staticAttachmentUpload(MultipartFile multipartFile, String folderId, String groupid);
/**
* 附件上传更新
* @param multipartFile
* @param id
* @param message
*/
public void attachmentUploadUpdate(MultipartFile multipartFile, String id, String message);
/**
* 附件删除
* @param id
*/
public void attachmentDelete(String id);
/**
* 附件下载
* @param id
* @return
*/
public FileInputStream attachmentDownload(String id);
/**
* 缩略图
* @param id
* @return
*/
public InputStream previewThumbnail(String id);
/**
* 为controller提供调用,页面判断是否允许编辑
* @param json
* @return
*/
public boolean allowUpdate(BaseEditJSON json);
/**
* 为controller提供调用,页面判断是否允许编辑
* @param entity
* @return
*/
public boolean allowUpdate(BaseEntity entity);
/**
* 为controller提供调用,页面判断是否允许删除
* @param json
* @return
*/
public boolean allowDelete(BaseEditJSON json);
/**
* 为controller提供调用,页面判断是否允许删除
* @param entity
* @return
*/
public boolean allowDelete(BaseEntity entity);
}
package com.gavel.common.base.service;
import org.springframework.web.multipart.MultipartFile;
public interface BaseService {
/**
* 附件上传,无groupid
* @param multipartFile
* @param folderId
* @return
*/
public String attachmentUpload(MultipartFile multipartFile, String folderId);
/**
* 资源上传,无groupid
* @param multipartFile
* @param folderId
* @return
*/
public String staticAttachmentUpload(MultipartFile multipartFile, String folderId);
/**
* 带名称上传
* @param multipartFile
* @param folderId
* @param fileName
* @return
*/
public String staticConstantAttachmentUpload(MultipartFile multipartFile, String folderId, String fileName);
}
package com.gavel.common.base.service.impl;
import java.io.File;
import java.util.List;
import java.util.Map;
import com.gavel.common.utils.SpringUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import com.gavel.common.Constants;
import com.gavel.common.attachment.persistent.Attachment;
import com.gavel.common.attachment.service.AttachmentService;
import com.gavel.common.base.service.BaseService;
import com.gavel.common.exception.ApplicationException;
import com.gavel.common.utils.BooleanEnum;
import com.gavel.common.utils.ReturnData;
import com.gavel.common.utils.ThreadContext;
/**
* 业务service操作数据库父类
*
* @author zhouyi
*
*/
public abstract class BaseServiceImpl implements BaseService{
protected void setReturnMessage(String value){
ReturnData rd = ThreadContext.getReturnData();
rd.setSuccess(false);
rd.setCode(value);
rd.setMessage(value);
}
protected void setReturnMessageSuccess(String value){
ReturnData rd = ThreadContext.getReturnData();
rd.setSuccess(true);
rd.setCode(value);
rd.setMessage(value);
}
protected void setReturnMessage(String code, String value){
ReturnData rd = ThreadContext.getReturnData();
rd.setSuccess(false);
if (code != null && code.contains("%s")){
rd.setMessage(String.format(code, value));
}else {
rd.setCode(code);
rd.setMessage(value);
}
}
protected void setReturnMessage(String value, Object... args){
ReturnData rd = ThreadContext.getReturnData();
rd.setSuccess(false);
rd.setMessage(String.format(value, args));
rd.setCode(rd.getMessage());
}
protected void addThreadData(String key, Object value){
Map<String, Object> map = ThreadContext.getThreadData();
map.put(key, value);
}
protected Object getThreadData(String key) {
Map<String, Object> map = ThreadContext.getThreadData();
return map.get(key);
}
@SuppressWarnings("unchecked")
protected <T> T getThreadData(String key, Class<T> clazz) {
Map<String, Object> map = ThreadContext.getThreadData();
return (T)map.get(key);
}
@SuppressWarnings("unchecked")
protected <T> List<T> getThreadDataList(String key, Class<T> clazz) {
Map<String, Object> map = ThreadContext.getThreadData();
return (List<T>)map.get(key);
}
protected void throwReturnMessage(String code, String value) {
if (code != null && code.contains("%s")){
throw new ApplicationException(String.format(code, value));
}
throw new ApplicationException(code, value);
}
protected void throwReturnMessage(String value) {
throw new ApplicationException(value);
}
protected void throwReturnMessage(String value, Object... args) {
throw new ApplicationException(String.format(value, args));
}
public void addReturnData(String key, Object value){
ThreadContext.addReturnData(key, value);
}
public void addReturnData(Object value){
ThreadContext.addReturnData(value);
}
public void addReturnMessage(String value) {
ReturnData rd = ThreadContext.getReturnData();
rd.addReturnMessage(value);
}
public void addReturnMessage(String code, String value) {
ReturnData rd = ThreadContext.getReturnData();
if (code != null && code.contains("%s")){
rd.addReturnMessage(String.format(code, value));
}else
rd.setCode(code);
}
protected void addReturnMessage(String value, Object... args){
ReturnData rd = ThreadContext.getReturnData();
rd.addReturnMessage(String.format(value, args));
}
/**
* 资源上传,与业务功能分离,无groupid
* @param multipartFile
* @param folderId
* @return
*/
@Override
@Transactional
public String staticAttachmentUpload(MultipartFile multipartFile, String folderId) {
Attachment attachment = SpringUtils.getBean(AttachmentService.class).staticUpload(multipartFile, folderId, "");
//返回id
addReturnData(Constants.ID, attachment.getId());
String fileTypeName = BooleanEnum.equalsYes(attachment.getIscompress())? ".zip":"." + attachment.getType();
String originUrl = Constants.ACCESS_FILE_PATH + File.separator + attachment.getPath() + File.separator + attachment.getId() + fileTypeName;
String viewUrl = Constants.ACCESS_FILE_PATH + File.separator + attachment.getPath() + File.separator + Constants.PATH_VIEW + File.separator + attachment.getId() + fileTypeName;
addReturnData(Constants.URL_ORIGIN,originUrl.replace("\\","/"));
addReturnData(Constants.URL_VIEW,viewUrl.replace("\\","/"));
return attachment.getId();
}
@Override
@Transactional
public String staticConstantAttachmentUpload(MultipartFile multipartFile, String folderId, String fileName) {
Attachment attachment = SpringUtils.getBean(AttachmentService.class).staticUpload(multipartFile, folderId, "", fileName);
//返回id
addReturnData(Constants.ID, attachment.getId());
// String fileTypeName = BooleanEnum.equalsYes(attachment.getIscompress())? ".zip":"." + attachment.getType();
String originUrl = Constants.ACCESS_FILE_PATH + File.separator + attachment.getPath() + File.separator + fileName;
String viewUrl = Constants.ACCESS_FILE_PATH + File.separator + attachment.getPath() + File.separator + Constants.PATH_VIEW + File.separator + fileName;
addReturnData(Constants.URL_ORIGIN,originUrl.replace("\\","/"));
addReturnData(Constants.URL_VIEW,viewUrl.replace("\\","/"));
return attachment.getId();
}
/**
* 附件上传,与业务功能分离,无groupid
* @param multipartFile
* @param folderId
* @return
*/
@Override
@Transactional
public String attachmentUpload(MultipartFile multipartFile, String folderId) {
Attachment attachment = SpringUtils.getBean(AttachmentService.class).upload(multipartFile, folderId, "");
//返回id
addReturnData(Constants.ID, attachment.getId());
return attachment.getId();
}
}
package com.gavel.common.base.validation.exception;
public class ValidationException extends Exception {
/**
*
*/
private static final long serialVersionUID = 1L;
public ValidationException() {
super();
}
public ValidationException(String message) {
super(message);
}
public ValidationException(String message, Throwable cause) {
super(message, cause);
}
public ValidationException(Throwable cause) {
super(cause);
}
}
package com.gavel.common.base.validation.field;
import com.gavel.common.base.validation.exception.ValidationException;
import com.gavel.common.dataset.DataField;
import com.gavel.common.utils.NumberUtils;
import com.gavel.persistence.entity.EntityField.FieldType;
/**
* @author Qi.Song(heikexiaosong@gmail.com)
* @since 17-3-31
*/
public class EmptyValidator implements FieldValidator<DataField> {
@Override
public boolean isValid(DataField dataField) throws ValidationException {
if ( dataField==null || dataField.isNotEmpty()==false ){
return true;
}
if ( dataField.getValue()==null ){
throw new ValidationException(dataField.getCaption() + " 不能为空!");
}
if ( dataField.getType()!=null && dataField.getType().equals(String.class)
&& "".equalsIgnoreCase(dataField.getValue().toString()) && dataField.isNotEmpty() ){
throw new ValidationException(dataField.getCaption() + " 不能为空!");
}
if ((dataField.getFieldType() == FieldType.ftFloat || dataField.getFieldType() == FieldType.ftInteger)
&& !dataField.isAllowZero() && NumberUtils.isZero(dataField.getFloat())){
throw new ValidationException(dataField.getCaption() + " 不能为0!");
}
return true;
}
}
package com.gavel.common.base.validation.field;
import com.gavel.common.base.validation.exception.ValidationException;
import com.gavel.common.dataset.DataField;
import com.gavel.common.utils.DateUtils;
import com.gavel.common.utils.StringUtils;
/**
* @author Qi.Song(heikexiaosong@gmail.com)
* @since 17-3-31
*/
public class FieldTypeValidator implements FieldValidator<DataField> {
@Override
public boolean isValid(DataField dataField) throws ValidationException {
if ( dataField==null || dataField.getFieldType()==null ){
return true;
}
if ( dataField.getFieldType() == DataField.FieldType.ftInteger
|| dataField.getFieldType() == DataField.FieldType.ftFloat ) {
if (!(dataField.getValue()==null || StringUtils.isNumeric(dataField.getValue())))
throw new ValidationException(dataField.getCaption() + " 不是有效的数值类型!");
}
if (dataField.getFieldType() == DataField.FieldType.ftDate){
if (!DateUtils.isDate(dataField.getValue()))
throw new ValidationException(dataField.getCaption() + " 不是有效的日期类型!");
}
return true;
}
}
package com.gavel.common.base.validation.field;
import java.util.ArrayList;
import java.util.List;
import com.gavel.common.base.validation.exception.ValidationException;
import com.gavel.common.dataset.DataField;
public class FieldValidationUtils {
@SuppressWarnings("rawtypes")
private static List<FieldValidator> fieldValidators = new ArrayList<FieldValidator>();
static {
fieldValidators.add(new FieldTypeValidator());
fieldValidators.add(new EmptyValidator());
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static ValidationResult validate(DataField dataField){
if ( dataField==null ){
return ValidationResult.SUCCESS_RESULT;
}
if ( fieldValidators==null || fieldValidators.size()==0 ){
return ValidationResult.SUCCESS_RESULT;
}
boolean valid = true;
for (FieldValidator fieldValidator : fieldValidators) {
try {
valid &= fieldValidator.isValid(dataField);
} catch (ValidationException e) {
ValidationResult validationResult = new ValidationResult(false);
validationResult.setErrorMsg(e.getMessage());
return validationResult;
}
}
if ( valid==false ){
return new ValidationResult(false);
}
return ValidationResult.SUCCESS_RESULT;
}
}
package com.gavel.common.base.validation.field;
import com.gavel.common.base.validation.exception.ValidationException;
public interface FieldValidator<T> {
boolean isValid(T obj) throws ValidationException;
}
\ No newline at end of file
package com.gavel.common.base.validation.field;
public class ValidationResult {
public static ValidationResult SUCCESS_RESULT = new ValidationResult(true);
//校验结果是否有错
private boolean pass;
//校验错误信息
private String errorMsg;
public ValidationResult() {
}
public ValidationResult(boolean pass) {
this.pass = pass;
}
public boolean isPass() {
return pass;
}
public void setPass(boolean pass) {
this.pass = pass;
}
public String getErrorMsg() {
return errorMsg;
}
public void setErrorMsg(String errorMsg) {
this.errorMsg = errorMsg;
}
}
package com.gavel.common.business.dao;
import org.springframework.cache.annotation.Cacheable;
import com.gavel.common.CommonCacheConstant;
import com.gavel.common.base.dao.BaseDao;
public interface CommonDao extends BaseDao {
public int getSequence(String table, String prefix);
/**
* 一次获取多个流水号(count)
* @param table
* @param prefix
* @param count
* @return
*/
public int getSequence(String table, String prefix, int incSize);
/**
* 一次获取多个流水号(count)
* @param table
* @param prefix
* @param count
* @return
*/
public int getSequence(String table, String prefix, int maxValue, int incSize);
/**
* 根据用户 获取 参数值
* @param userid
* @param csid
* @param yxy 缺省为空
* @return
*/
@Cacheable(value=CommonCacheConstant.SYS_XTCS_CACHE, key="T(String).valueOf(#userid).concat('-').concat(#csid)")
public Object getOptionValue(String userid, String csid, String yxy);
public int getSequenceNotIncrease(String table, String prefix);
public int rollbackSequence(String table, String prefix, int inc, int curValue);
public int setSequenceValue(String table, String prefix, int setValue);
}
package com.gavel.common.converter.json;
public interface DateFormat {
public String getDateFormat();
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment