XMTT 7 years ago
parent
commit
a0eb5c178f

+ 5 - 0
pom.xml

@ -107,6 +107,11 @@
107 107
			<artifactId>slf4j-log4j12</artifactId>
108 108
			<version>1.7.21</version>
109 109
		</dependency>
110
		<dependency>
111
			<groupId>org.freemarker</groupId>
112
			<artifactId>freemarker</artifactId>
113
			<version>2.3.26-incubating</version>
114
		</dependency>
110 115
	</dependencies>
111 116
	<build>
112 117
		<resources>

+ 41 - 0
src/main/java/com/ekexiu/console/system/dao/DiscoverBannerDao.java

@ -0,0 +1,41 @@
1
package com.ekexiu.console.system.dao;
2
3
import com.ekexiu.console.system.po.DiscoverBanner;
4
import org.jfw.apt.annotation.Nullable;
5
import org.jfw.apt.orm.annotation.dao.DAO;
6
import org.jfw.apt.orm.annotation.dao.method.From;
7
import org.jfw.apt.orm.annotation.dao.method.OrderBy;
8
import org.jfw.apt.orm.annotation.dao.method.SetSentence;
9
import org.jfw.apt.orm.annotation.dao.method.Where;
10
import org.jfw.apt.orm.annotation.dao.method.operator.*;
11
import org.jfw.util.PageQueryResult;
12
13
import java.sql.Connection;
14
import java.sql.SQLException;
15
16
/**
17
 * Created by TT on 2017/8/25.
18
 */
19
@DAO
20
public interface DiscoverBannerDao {
21
22
    @Nullable
23
    @SelectOne
24
    DiscoverBanner query(Connection con, long id) throws SQLException;
25
26
    @Update
27
    int update(Connection con, DiscoverBanner discoverBanner) throws SQLException;
28
29
    @InsertAndGenKey(value = "id")
30
    long insert(Connection con, DiscoverBanner discoverBanner) throws SQLException;
31
32
    @PageQuery
33
    @OrderBy(" ORDER BY create_time DESC")
34
    PageQueryResult<DiscoverBanner> query(Connection con, @Nullable String title, int pageSize, int pageNo) throws SQLException;
35
36
    @UpdateWith
37
    @From(DiscoverBanner.class)
38
    @SetSentence("end_time = TO_CHAR(NOW(),'YYYYMMDDHH24MISS') ")
39
    @Where("begin_time is not null and end_time is null")
40
    int end(Connection con)throws SQLException;
41
}

+ 139 - 0
src/main/java/com/ekexiu/console/system/po/DiscoverBanner.java

@ -0,0 +1,139 @@
1
package com.ekexiu.console.system.po;
2
3
import com.ekexiu.console.basepo.CreateTimeSupported;
4
import com.ekexiu.console.basepo.ModifyTimeSupported;
5
import org.jfw.apt.orm.annotation.entry.Column;
6
import org.jfw.apt.orm.annotation.entry.PrimaryKey;
7
import org.jfw.apt.orm.annotation.entry.Table;
8
import org.jfw.apt.orm.core.defaultImpl.LongHandler;
9
import org.jfw.apt.orm.core.enums.DE;
10
11
/**
12
 * Created by TT on 2017/8/25.
13
 */
14
@PrimaryKey("id")
15
@Table
16
public class DiscoverBanner implements CreateTimeSupported, ModifyTimeSupported {
17
    private long id;
18
    private String title;
19
    private int banner;
20
    private String beginTime;
21
    private String endTime;
22
    private long pageViews;
23
    private String descp;
24
    private String articleId;
25
    private String modifyTime;
26
    private String modifier;
27
    private String createTime;
28
    private String creator;
29
30
    @Column(DE.bigSerial)
31
    public long getId() {
32
        return id;
33
    }
34
35
    public void setId(long id) {
36
        this.id = id;
37
    }
38
39
    @Column(DE.Text_de)
40
    public String getTitle() {
41
        return title;
42
    }
43
44
    public void setTitle(String title) {
45
        this.title = title;
46
    }
47
48
    @Column(DE.int_de)
49
    public int getBanner() {
50
        return banner;
51
    }
52
53
    public void setBanner(int banner) {
54
        this.banner = banner;
55
    }
56
57
    @Column(DE.Text_de)
58
    public String getBeginTime() {
59
        return beginTime;
60
    }
61
62
    public void setBeginTime(String beginTime) {
63
        this.beginTime = beginTime;
64
    }
65
66
    @Column(DE.Text_de)
67
    public String getEndTime() {
68
        return endTime;
69
    }
70
71
    public void setEndTime(String endTime) {
72
        this.endTime = endTime;
73
    }
74
75
    @Column(handlerClass = LongHandler.class, dbType = "BIGINT", fixSqlValueWithInsert = "0", insertable = true, renewable = false, nullable = false, queryable = true)
76
    public long getPageViews() {
77
        return pageViews;
78
    }
79
80
    public void setPageViews(long pageViews) {
81
        this.pageViews = pageViews;
82
    }
83
84
    @Column(DE.Text_de)
85
    public String getDescp() {
86
        return descp;
87
    }
88
89
    public void setDescp(String descp) {
90
        this.descp = descp;
91
    }
92
93
    @Column(DE.Text_de)
94
    public String getArticleId() {
95
        return articleId;
96
    }
97
98
    public void setArticleId(String articleId) {
99
        this.articleId = articleId;
100
    }
101
102
    @Column(DE.Text_de)
103
    public String getModifier() {
104
        return modifier;
105
    }
106
107
    public void setModifier(String modifier) {
108
        this.modifier = modifier;
109
    }
110
111
    @Column(DE.Text_de)
112
    public String getCreator() {
113
        return creator;
114
    }
115
116
    public void setCreator(String creator) {
117
        this.creator = creator;
118
    }
119
120
    @Override
121
    public String getModifyTime() {
122
        return this.modifyTime;
123
    }
124
125
    @Override
126
    public void setModifyTime(String modifyTime) {
127
        this.modifyTime = modifyTime;
128
    }
129
130
    @Override
131
    public String getCreateTime() {
132
        return this.createTime;
133
    }
134
135
    @Override
136
    public void setCreateTime(String createTime) {
137
        this.createTime = createTime;
138
    }
139
}

+ 130 - 0
src/main/java/com/ekexiu/console/system/service/BannerService.java

@ -0,0 +1,130 @@
1
package com.ekexiu.console.system.service;
2
3
import freemarker.template.Configuration;
4
5
import java.io.File;
6
7
/**
8
 * Created by TT on 2017/8/24.
9
 */
10
public class BannerService {
11
12
    private File source;
13
    private Configuration cfg = new Configuration(Configuration.VERSION_2_3_26);
14
    //public void setSource(File source) {
15
    //    this.source = source;
16
    //    try {
17
    //        this.cfg.setDirectoryForTemplateLoading(source);
18
    //    } catch (IOException e) {
19
    //        this.source = null;
20
    //        this.cfg.setTemplateLoader(new TemplateLoader() {
21
    //            @Override
22
    //            public Reader getReader(Object templateSource, String encoding) throws IOException {
23
    //                StringReader reader = new StringReader("TemplateService'source is invalid dir,so "+templateSource.toString()+" can't read");
24
    //                return reader;
25
    //            }
26
    //
27
    //            @Override
28
    //            public long getLastModified(Object templateSource) {
29
    //                return 0;
30
    //            }
31
    //
32
    //            @Override
33
    //            public Object findTemplateSource(String name) throws IOException {
34
    //                return name;
35
    //            }
36
    //
37
    //            @Override
38
    //            public void closeTemplateSource(Object templateSource) throws IOException {
39
    //            }
40
    //        });
41
    //    }
42
    //    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
43
    //}
44
    //
45
    //public void genCnt(String templateName,File dest,Map<String,Object> root) throws IOException, TemplateException{
46
    //    if(dest.exists()){
47
    //        if(!dest.delete()){
48
    //            throw new IOException("delete file["+dest.getAbsolutePath()+"] error");
49
    //        }
50
    //    }
51
    //    Template template = this.cfg.getTemplate(templateName,"UTF-8");
52
    //    OutputStream out = new FileOutputStream(dest);
53
    //    try {
54
    //        template.process(root, new OutputStreamWriter(out, ConstData.UTF8));
55
    //        out.flush();
56
    //    } finally {
57
    //        out.close();
58
    //    }
59
    //}
60
    //
61
    //
62
    //public static void main(String[] args) {
63
    //    BannerService templateService = new BannerService();
64
    //    templateService.setSource(new File("D:/tmp/banner"));
65
    //    ArrayList<Banner> banners = new ArrayList<>();
66
    //    ArrayList<Integer> ids = new ArrayList<>();
67
    //    ids.add(3);
68
    //    ids.add(2);
69
    //    ids.add(1);
70
    //    ids.add(5);
71
    //    ids.add(6);
72
    //    for (int i=0;i<5;i++) {
73
    //        Banner b = new Banner();
74
    //        b.setId(String.valueOf(ids.get(i)));
75
    //        b.setImage("image"+i);
76
    //        b.setBanner("banner"+i);
77
    //        b.setTitle("title"+i);
78
    //        banners.add(b);
79
    //    }
80
    //    Map<String, Object> root = new HashMap<String, Object>();
81
    //    root.put("banner", banners);
82
    //    try {
83
    //        templateService.genCnt("slideTab.html",new File("D:/tmp/banner/generate.html"),root);
84
    //        templateService.genCnt("appfound.html",new File("D:/tmp/banner/generateApp.html"),root);
85
    //    } catch (IOException | TemplateException e) {
86
    //        e.printStackTrace();
87
    //    }
88
    //}
89
    //
90
    //public static class Banner{
91
    //    private String id;
92
    //    private String image;
93
    //    private String title;
94
    //    private String banner;
95
    //
96
    //    public String getId() {
97
    //        return id;
98
    //    }
99
    //
100
    //    public void setId(String id) {
101
    //        this.id = id;
102
    //    }
103
    //
104
    //    public String getImage() {
105
    //        return image;
106
    //    }
107
    //
108
    //    public void setImage(String image) {
109
    //        this.image = image;
110
    //    }
111
    //
112
    //    public String getTitle() {
113
    //        return title;
114
    //    }
115
    //
116
    //    public void setTitle(String title) {
117
    //        this.title = title;
118
    //    }
119
    //
120
    //    public String getBanner() {
121
    //        return banner;
122
    //    }
123
    //
124
    //    public void setBanner(String banner) {
125
    //        this.banner = banner;
126
    //    }
127
    //}
128
129
130
}

+ 200 - 0
src/main/java/com/ekexiu/console/system/service/DiscoverBannerService.java

@ -0,0 +1,200 @@
1
package com.ekexiu.console.system.service;
2
3
import com.ekexiu.console.system.dao.DiscoverBannerDao;
4
import com.ekexiu.console.system.po.DiscoverBanner;
5
import com.ekexiu.console.system.vo.ConsoleAuthUser;
6
import freemarker.cache.TemplateLoader;
7
import freemarker.template.Configuration;
8
import freemarker.template.Template;
9
import freemarker.template.TemplateException;
10
import freemarker.template.TemplateExceptionHandler;
11
import org.jfw.apt.annotation.Autowrie;
12
import org.jfw.apt.annotation.DefaultValue;
13
import org.jfw.apt.annotation.Nullable;
14
import org.jfw.apt.web.annotation.LoginUser;
15
import org.jfw.apt.web.annotation.Path;
16
import org.jfw.apt.web.annotation.operate.Get;
17
import org.jfw.apt.web.annotation.operate.Post;
18
import org.jfw.apt.web.annotation.param.JdbcConn;
19
import org.jfw.apt.web.annotation.param.PathVar;
20
import org.jfw.apt.web.annotation.param.RequestParam;
21
import org.jfw.util.ConstData;
22
import org.jfw.util.DateUtil;
23
import org.jfw.util.PageQueryResult;
24
25
import java.io.*;
26
import java.sql.Connection;
27
import java.sql.SQLException;
28
import java.util.ArrayList;
29
import java.util.HashMap;
30
import java.util.Map;
31
32
/**
33
 * Created by TT on 2017/8/25.
34
 */
35
@Path("/disBanner")
36
public class DiscoverBannerService {
37
38
    private File source;
39
    private Configuration cfg = new Configuration(Configuration.VERSION_2_3_26);
40
41
    @Autowrie
42
    private DiscoverBannerDao discoverBannerDao;
43
    @Autowrie
44
    private ImageService imageService;
45
46
    public DiscoverBannerDao getDiscoverBannerDao() {
47
        return discoverBannerDao;
48
    }
49
50
    public void setDiscoverBannerDao(DiscoverBannerDao discoverBannerDao) {
51
        this.discoverBannerDao = discoverBannerDao;
52
    }
53
54
    public File getSource() {
55
        return source;
56
    }
57
58
    public void setSource(File source) {
59
        this.source = source;
60
        try {
61
            this.cfg.setDirectoryForTemplateLoading(source);
62
        } catch (IOException e) {
63
            this.source = null;
64
            this.cfg.setTemplateLoader(new TemplateLoader() {
65
                @Override
66
                public Reader getReader(Object templateSource, String encoding) throws IOException {
67
                    StringReader reader = new StringReader("TemplateService'source is invalid dir,so "+templateSource.toString()+" can't read");
68
                    return reader;
69
                }
70
71
                @Override
72
                public long getLastModified(Object templateSource) {
73
                    return 0;
74
                }
75
76
                @Override
77
                public Object findTemplateSource(String name) throws IOException {
78
                    return name;
79
                }
80
81
                @Override
82
                public void closeTemplateSource(Object templateSource) throws IOException {
83
                }
84
            });
85
        }
86
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
87
    }
88
89
    public void genCnt(String templateName,File dest,Map<String,Object> root) throws IOException, TemplateException {
90
        if(dest.exists()){
91
            if(!dest.delete()){
92
                throw new IOException("delete file["+dest.getAbsolutePath()+"] error");
93
            }
94
        }
95
        Template template = this.cfg.getTemplate(templateName,"UTF-8");
96
        OutputStream out = new FileOutputStream(dest);
97
        try {
98
            template.process(root, new OutputStreamWriter(out, ConstData.UTF8));
99
            out.flush();
100
        } finally {
101
            out.close();
102
        }
103
    }
104
105
    @Path
106
    @Post
107
    public void insert(@JdbcConn(true) Connection con,@RequestParam(excludeFields = {"createTime", "modifyTime", "id"}) DiscoverBanner discoverBanner,@Nullable String fn) throws SQLException, IOException {
108
        long id = this.discoverBannerDao.insert(con, discoverBanner);
109
        this.imageService.saveBannerImage(id, fn);
110
111
    }
112
113
    @Path("/id/{id}")
114
    @Get
115
    public DiscoverBanner query(@JdbcConn Connection con,@PathVar long id)throws SQLException {
116
        return this.discoverBannerDao.query(con, id);
117
    }
118
119
    @Path("update")
120
    @Post
121
    public void update(@JdbcConn(true) Connection con, DiscoverBanner banner,@Nullable String fn) throws SQLException, IOException {
122
        this.discoverBannerDao.update(con, banner);
123
        this.imageService.saveBannerImage(banner.getId(), fn);
124
    }
125
126
    @Path("/pq")
127
    @Get
128
    public PageQueryResult<DiscoverBanner> pageQuery(@JdbcConn Connection con, @Nullable String title, @DefaultValue("1") int pageNo, @DefaultValue("10") int pageSize) throws SQLException {
129
        return this.discoverBannerDao.query(con,title,pageNo,pageSize);
130
    }
131
132
    @Path("/putOn")
133
    @Post
134
    public void putOn(@JdbcConn(true) Connection con, Long[] ids, @LoginUser ConsoleAuthUser user) throws SQLException {
135
136
        this.setSource(new File("D:/tmp/banner"));
137
        ArrayList<Banner> banners = new ArrayList<>();
138
        for (int i=0;i<5;i++) {
139
            DiscoverBanner discoverBanner = this.discoverBannerDao.query(con, ids[i]);
140
            discoverBanner.setBeginTime(DateUtil.formatDateTime(System.currentTimeMillis()));
141
            discoverBanner.setModifier(user.getId());
142
            this.discoverBannerDao.update(con, discoverBanner);
143
            Banner b = new Banner();
144
            b.setId(discoverBanner.getArticleId());
145
            b.setImage("image"+i);
146
            b.setBanner(discoverBanner.getBanner());
147
            b.setTitle(discoverBanner.getTitle());
148
            banners.add(b);
149
        }
150
        Map<String, Object> root = new HashMap<String, Object>();
151
        root.put("banner", banners);
152
        try {
153
            this.genCnt("slideTab.html",new File("D:/tmp/banner/generate.html"),root);
154
            this.genCnt("appfound.html",new File("D:/tmp/banner/generateApp.html"),root);
155
        } catch (IOException | TemplateException e) {
156
            e.printStackTrace();
157
        }
158
    }
159
160
161
    public static class Banner{
162
        private String id;
163
        private String image;
164
        private String title;
165
        private int banner;
166
167
        public String getId() {
168
            return id;
169
        }
170
171
        public void setId(String id) {
172
            this.id = id;
173
        }
174
175
        public String getImage() {
176
            return image;
177
        }
178
179
        public void setImage(String image) {
180
            this.image = image;
181
        }
182
183
        public String getTitle() {
184
            return title;
185
        }
186
187
        public void setTitle(String title) {
188
            this.title = title;
189
        }
190
191
        public int getBanner() {
192
            return banner;
193
        }
194
195
        public void setBanner(int banner) {
196
            this.banner = banner;
197
        }
198
    }
199
200
}

+ 151 - 0
src/main/java/com/ekexiu/console/system/service/ImageService.java

@ -0,0 +1,151 @@
1
package com.ekexiu.console.system.service;
2
3
import com.ekexiu.console.service.Upload;
4
import org.jfw.apt.web.annotation.Path;
5
import org.jfw.util.JpgUtil;
6
import org.jfw.util.io.IoUtil;
7
8
import java.io.*;
9
10
/**
11
 * Created by TT on 2017/8/24.
12
 */
13
@Path("/image")
14
public class ImageService extends Upload {
15
    private File imagePath;
16
    private File tmpPath;
17
    private File orgPath;
18
    private File bannerPath;
19
    private int largeHeadPhotoWidth = 200;
20
    private int largeHeadPhotoHeight = 200;
21
    private int middleHeadPhotoWidth = 200;
22
    private int middleHeadPhotoHeight = 200;
23
    private int smallHeadPhotoWidth = 200;
24
    private int smallHeadPhotoHeight = 200;
25
26
    private File defaultHeadPhoto;
27
    private File defaultOrgLogo;
28
    private File defaultResourcePhoto;
29
30
    private byte[] dli;
31
    private byte[] dmi;
32
    private byte[] dsi;
33
    private byte[] dol;
34
    private byte[] dsl;
35
36
    public File getDefaultHeadPhoto() {
37
        return defaultHeadPhoto;
38
    }
39
40
    public void setDefaultHeadPhoto(File defaultHeadPhoto) {
41
        this.defaultHeadPhoto = defaultHeadPhoto;
42
    }
43
44
    public File getDefaultOrgLogo() {
45
        return defaultOrgLogo;
46
    }
47
48
    public void setDefaultOrgLogo(File defaultOrgLogo) {
49
        this.defaultOrgLogo = defaultOrgLogo;
50
    }
51
52
    public File getDefaultResourcePhoto() {
53
        return defaultResourcePhoto;
54
    }
55
56
    public void setDefaultResourcePhoto(File defaultResourcePhoto) {
57
        this.defaultResourcePhoto = defaultResourcePhoto;
58
    }
59
60
    public File getImagePath() {
61
        return imagePath;
62
    }
63
64
    public void setImagePath(File imagePath) {
65
        this.imagePath = imagePath;
66
        this.orgPath = new File(this.imagePath, "org");
67
        this.bannerPath = new File(this.imagePath, "banner");
68
    }
69
70
    public File getTmpPath() {
71
        return tmpPath;
72
    }
73
74
    public void setTmpPath(File tmpPath) {
75
        this.tmpPath = tmpPath;
76
    }
77
78
    public File getOrgPath() {
79
        return orgPath;
80
    }
81
82
    public void setOrgPath(File orgPath) {
83
        this.orgPath = orgPath;
84
    }
85
86
    public void saveOrgLogo(String id, String fn) throws IOException {
87
        InputStream in = new FileInputStream(new File(this.tmpPath, fn));
88
        try {
89
            IoUtil.copy(in, new FileOutputStream(new File(this.orgPath, id + ".jpg")), false, true);
90
        } finally {
91
            in.close();
92
        }
93
    }
94
95
    public void saveBannerImage(long id, String fn) throws IOException{
96
        InputStream in = new FileInputStream(new File(this.tmpPath, fn));
97
        try {
98
            IoUtil.copy(in,new FileOutputStream(new File(this.bannerPath, id +".jpg")),false,true);
99
        }finally {
100
            in.close();
101
        }
102
    }
103
104
    public void saveDefaultOrgLogo(String id) throws IOException {
105
        this.initDefaultImage();
106
        IoUtil.saveStream(new FileOutputStream(new File(this.orgPath, id + ".jpg")), this.dol, true);
107
    }
108
109
    private byte[] zoomImage(byte[] src, int w, int h) throws IOException {
110
        ByteArrayInputStream in = new ByteArrayInputStream(src);
111
        ByteArrayOutputStream out = new ByteArrayOutputStream();
112
        JpgUtil.zoom(in, out, w, h);
113
        out.flush();
114
        return out.toByteArray();
115
    }
116
117
    private void initDefaultImage() {
118
        if (this.dli != null)
119
            return;
120
        synchronized (this) {
121
            if (this.dli != null)
122
                return;
123
            try {
124
                byte[] dd = IoUtil.readStream(new FileInputStream(this.defaultHeadPhoto), true);
125
                this.dli = this.zoomImage(dd, this.largeHeadPhotoWidth, this.largeHeadPhotoHeight);
126
                this.dmi = this.zoomImage(dd, this.middleHeadPhotoWidth, this.middleHeadPhotoHeight);
127
                this.dsi = this.zoomImage(dd, this.smallHeadPhotoWidth, this.smallHeadPhotoHeight);
128
                this.dol = IoUtil.readStream(new FileInputStream(this.defaultOrgLogo), true);
129
                this.dsl = IoUtil.readStream(new FileInputStream(this.defaultResourcePhoto), true);
130
            } catch (IOException e) {
131
                this.dli = null;
132
                this.dmi = null;
133
                this.dsi = null;
134
                this.dol = null;
135
                this.dsl = null;
136
                throw new RuntimeException("init image error", e);
137
            }
138
        }
139
    }
140
141
    public boolean hasOrgLogo(String id) {
142
        String orgPath = this.orgPath+"/"+id+".jpg";
143
        File file = new File(orgPath);
144
        if(file.exists()){
145
            return true;
146
        }else{
147
            return false;
148
        }
149
    }
150
151
}

+ 15 - 180
src/main/java/com/ekexiu/console/system/service/OrgService.java

@ -20,19 +20,17 @@ import org.jfw.apt.web.annotation.param.JdbcConn;
20 20
import org.jfw.apt.web.annotation.param.PathVar;
21 21
import org.jfw.apt.web.annotation.param.RequestParam;
22 22
import org.jfw.util.DateUtil;
23
import org.jfw.util.JpgUtil;
24 23
import org.jfw.util.PageQueryResult;
25 24
import org.jfw.util.StringUtil;
26 25
import org.jfw.util.exception.JfwBaseException;
27
import org.jfw.util.io.IoUtil;
28 26

29
import java.io.*;
27
import java.io.IOException;
30 28
import java.sql.Connection;
31 29
import java.sql.SQLException;
32 30
import java.util.Objects;
33 31

34 32
@Path("/sys/org")
35
public class OrgService extends com.ekexiu.console.service.Upload {
33
public class OrgService {
36 34
    private String defaultOrgType;
37 35

38 36
    /**
@ -40,25 +38,6 @@ public class OrgService extends com.ekexiu.console.service.Upload {
40 38
     */
41 39
    private String defaultAuthStatus = "0";
42 40

43
    private File imagePath;
44
    private File tmpPath;
45
    private File orgPath;
46
    private int largeHeadPhotoWidth = 200;
47
    private int largeHeadPhotoHeight = 200;
48
    private int middleHeadPhotoWidth = 200;
49
    private int middleHeadPhotoHeight = 200;
50
    private int smallHeadPhotoWidth = 200;
51
    private int smallHeadPhotoHeight = 200;
52

53
    private File defaultHeadPhoto;
54
    private File defaultOrgLogo;
55
    private File defaultResourcePhoto;
56

57
    private byte[] dli;
58
    private byte[] dmi;
59
    private byte[] dsi;
60
    private byte[] dol;
61
    private byte[] dsl;
62 41
    public static final String DEFAULT_PW_STR = StringUtil.md5("123456");
63 42

64 43
    @Autowrie
@ -68,6 +47,8 @@ public class OrgService extends com.ekexiu.console.service.Upload {
68 47
    @Autowrie
69 48
    private OrgRecordDao orgRecordDao;
70 49
    @Autowrie
50
    private ImageService imageService;
51
    @Autowrie
71 52
    private KeyWordService keyWordService;
72 53

73 54
    public OrgRecordDao getOrgRecordDao() {
@ -78,30 +59,6 @@ public class OrgService extends com.ekexiu.console.service.Upload {
78 59
        this.orgRecordDao = orgRecordDao;
79 60
    }
80 61

81
    public File getDefaultHeadPhoto() {
82
        return defaultHeadPhoto;
83
    }
84

85
    public void setDefaultHeadPhoto(File defaultHeadPhoto) {
86
        this.defaultHeadPhoto = defaultHeadPhoto;
87
    }
88

89
    public File getDefaultOrgLogo() {
90
        return defaultOrgLogo;
91
    }
92

93
    public void setDefaultOrgLogo(File defaultOrgLogo) {
94
        this.defaultOrgLogo = defaultOrgLogo;
95
    }
96

97
    public File getDefaultResourcePhoto() {
98
        return defaultResourcePhoto;
99
    }
100

101
    public void setDefaultResourcePhoto(File defaultResourcePhoto) {
102
        this.defaultResourcePhoto = defaultResourcePhoto;
103
    }
104

105 62
    public String getDefaultOrgType() {
106 63
        return defaultOrgType;
107 64
    }
@ -118,31 +75,6 @@ public class OrgService extends com.ekexiu.console.service.Upload {
118 75
        this.defaultAuthStatus = defaultAuthStatus;
119 76
    }
120 77

121
    public File getImagePath() {
122
        return imagePath;
123
    }
124

125
    public void setImagePath(File imagePath) {
126
        this.imagePath = imagePath;
127
        this.orgPath = new File(this.imagePath, "org");
128
    }
129

130
    public File getTmpPath() {
131
        return tmpPath;
132
    }
133

134
    public void setTmpPath(File tmpPath) {
135
        this.tmpPath = tmpPath;
136
    }
137

138
    public File getOrgPath() {
139
        return orgPath;
140
    }
141

142
    public void setOrgPath(File orgPath) {
143
        this.orgPath = orgPath;
144
    }
145

146 78
    public OrgUserDao getOrgUserDao() {
147 79
        return orgUserDao;
148 80
    }
@ -159,60 +91,20 @@ public class OrgService extends com.ekexiu.console.service.Upload {
159 91
        this.orgDao = orgDao;
160 92
    }
161 93

162
    public KeyWordService getKeyWordService() {
163
        return keyWordService;
164
    }
165

166
    public void setKeyWordService(KeyWordService keyWordService) {
167
        this.keyWordService = keyWordService;
168
    }
169

170
    public int getLargeHeadPhotoWidth() {
171
        return largeHeadPhotoWidth;
172
    }
173

174
    public void setLargeHeadPhotoWidth(int largeHeadPhotoWidth) {
175
        this.largeHeadPhotoWidth = largeHeadPhotoWidth;
94
    public ImageService getImageService() {
95
        return imageService;
176 96
    }
177 97

178
    public int getLargeHeadPhotoHeight() {
179
        return largeHeadPhotoHeight;
98
    public void setImageService(ImageService imageService) {
99
        this.imageService = imageService;
180 100
    }
181 101

182
    public void setLargeHeadPhotoHeight(int largeHeadPhotoHeight) {
183
        this.largeHeadPhotoHeight = largeHeadPhotoHeight;
184
    }
185

186
    public int getMiddleHeadPhotoWidth() {
187
        return middleHeadPhotoWidth;
188
    }
189

190
    public void setMiddleHeadPhotoWidth(int middleHeadPhotoWidth) {
191
        this.middleHeadPhotoWidth = middleHeadPhotoWidth;
192
    }
193

194
    public int getMiddleHeadPhotoHeight() {
195
        return middleHeadPhotoHeight;
196
    }
197

198
    public void setMiddleHeadPhotoHeight(int middleHeadPhotoHeight) {
199
        this.middleHeadPhotoHeight = middleHeadPhotoHeight;
200
    }
201

202
    public int getSmallHeadPhotoWidth() {
203
        return smallHeadPhotoWidth;
204
    }
205

206
    public void setSmallHeadPhotoWidth(int smallHeadPhotoWidth) {
207
        this.smallHeadPhotoWidth = smallHeadPhotoWidth;
208
    }
209

210
    public int getSmallHeadPhotoHeight() {
211
        return smallHeadPhotoHeight;
102
    public KeyWordService getKeyWordService() {
103
        return keyWordService;
212 104
    }
213 105

214
    public void setSmallHeadPhotoHeight(int smallHeadPhotoHeight) {
215
        this.smallHeadPhotoHeight = smallHeadPhotoHeight;
106
    public void setKeyWordService(KeyWordService keyWordService) {
107
        this.keyWordService = keyWordService;
216 108
    }
217 109

218 110
    @Post
@ -225,63 +117,6 @@ public class OrgService extends com.ekexiu.console.service.Upload {
225 117
        return id;
226 118
    }
227 119

228
    public void saveOrgLogo(String id, String fn) throws IOException {
229
        InputStream in = new FileInputStream(new File(this.tmpPath, fn));
230
        try {
231
            IoUtil.copy(in, new FileOutputStream(new File(this.orgPath, id + ".jpg")), false, true);
232
        } finally {
233
            in.close();
234
        }
235
    }
236

237
    public void saveDefaultOrgLogo(String id) throws IOException {
238
        this.initDefaultImage();
239
        IoUtil.saveStream(new FileOutputStream(new File(this.orgPath, id + ".jpg")), this.dol, true);
240
    }
241

242
    private byte[] zoomImage(byte[] src, int w, int h) throws IOException {
243
        ByteArrayInputStream in = new ByteArrayInputStream(src);
244
        ByteArrayOutputStream out = new ByteArrayOutputStream();
245
        JpgUtil.zoom(in, out, w, h);
246
        out.flush();
247
        return out.toByteArray();
248
    }
249

250
    private void initDefaultImage() {
251
        if (this.dli != null)
252
            return;
253
        synchronized (this) {
254
            if (this.dli != null)
255
                return;
256
            try {
257
                byte[] dd = IoUtil.readStream(new FileInputStream(this.defaultHeadPhoto), true);
258
                this.dli = this.zoomImage(dd, this.largeHeadPhotoWidth, this.largeHeadPhotoHeight);
259
                this.dmi = this.zoomImage(dd, this.middleHeadPhotoWidth, this.middleHeadPhotoHeight);
260
                this.dsi = this.zoomImage(dd, this.smallHeadPhotoWidth, this.smallHeadPhotoHeight);
261
                this.dol = IoUtil.readStream(new FileInputStream(this.defaultOrgLogo), true);
262
                this.dsl = IoUtil.readStream(new FileInputStream(this.defaultResourcePhoto), true);
263
            } catch (IOException e) {
264
                this.dli = null;
265
                this.dmi = null;
266
                this.dsi = null;
267
                this.dol = null;
268
                this.dsl = null;
269
                throw new RuntimeException("init image error", e);
270
            }
271
        }
272
    }
273

274
    public boolean hasOrgLogo(String id) {
275
        String orgPath = this.orgPath+"/"+id+".jpg";
276
        File file = new File(orgPath);
277
        if(file.exists()){
278
            return true;
279
        }else{
280
            return false;
281
        }
282
    }
283

284

285 120
    @Path("/entryCheck")
286 121
    @Get
287 122
    public int entryCheck(@JdbcConn Connection con, String name, String email) throws SQLException {
@ -405,7 +240,7 @@ public class OrgService extends com.ekexiu.console.service.Upload {
405 240
    @Path("/update")
406 241
    public void update(@JdbcConn(true) Connection con, Organization orgn, @Nullable String fn,@LoginUser ConsoleAuthUser user) throws SQLException, IOException {
407 242
        if (fn != null) {
408
            this.saveOrgLogo(orgn.getId(), fn);
243
            this.imageService.saveOrgLogo(orgn.getId(), fn);
409 244
        }
410 245
        this.orgDao.update(con, orgn);
411 246
        OrgRecord orgRecord = this.orgRecordDao.queryById(con, orgn.getId());
@ -454,7 +289,7 @@ public class OrgService extends com.ekexiu.console.service.Upload {
454 289
    public OrganizationInfo query(@JdbcConn Connection con, @PathVar String id) throws SQLException {
455 290
        OrganizationInfo organizationInfo = this.orgDao.query(con, id);
456 291
        if (organizationInfo != null) {
457
            organizationInfo.setHasOrgLogo(this.hasOrgLogo(organizationInfo.getId()));
292
            organizationInfo.setHasOrgLogo(this.imageService.hasOrgLogo(organizationInfo.getId()));
458 293
        }
459 294
        return organizationInfo;
460 295
    }
@ -482,7 +317,7 @@ public class OrgService extends com.ekexiu.console.service.Upload {
482 317
        org.setAuthStatus(this.defaultAuthStatus);
483 318
        try {
484 319
            orgDao.insert(con, org);
485
            this.saveDefaultOrgLogo(id);
320
            this.imageService.saveDefaultOrgLogo(id);
486 321
        } catch (SQLException e) {
487 322
            if ("23505".equals(e.getSQLState())) {
488 323
                con.rollback();