add application remove
This commit is contained in:
parent
107963da98
commit
55ae266381
@ -294,7 +294,6 @@ public abstract class AbstractBaseController {
|
||||
}
|
||||
}
|
||||
}
|
||||
return search;
|
||||
}
|
||||
return search;
|
||||
}
|
||||
|
@ -9,16 +9,15 @@ import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import me.chyxion.tigon.model.ViewModel;
|
||||
import me.chyxion.tigon.model.ListResult;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.pudonghot.ambition.crm.model.User;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import com.pudonghot.ambition.crm.model.Application;
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
import com.pudonghot.ambition.crm.service.UserService;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import com.pudonghot.ambition.crm.model.CustomerProperty;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import com.pudonghot.ambition.crm.model.ApplicationImage;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import com.pudonghot.ambition.crm.service.ApplicationService;
|
||||
@ -40,8 +39,6 @@ import com.pudonghot.ambition.crm.form.update.ApplicationImageFormForUpdate;
|
||||
public class ApplicationController
|
||||
extends BaseQueryController<Application> {
|
||||
|
||||
@Value("${file.base-path}")
|
||||
private String fileBasePath;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
private final List<String> SEARCH_COLS =
|
||||
@ -70,7 +67,6 @@ public class ApplicationController
|
||||
}
|
||||
final ListResult<ViewModel<Application>> result =
|
||||
listViewModels(search, start, limit, strSearch, null, filters, null);
|
||||
result.setAttr("fileBasePath", fileBasePath);
|
||||
result.setAttr("users", userService.listViewModels(
|
||||
new Search().asc(User.EMPLOYEE_ID)));
|
||||
return result;
|
||||
@ -138,6 +134,12 @@ public class ApplicationController
|
||||
((ApplicationService) queryService).updateImage(form);
|
||||
}
|
||||
|
||||
@RequiresRoles(User.ROLE_ADMIN)
|
||||
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
||||
public void delete(@NotBlank @RequestParam("id") String id) {
|
||||
((ApplicationService) queryService).delete(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -2,9 +2,8 @@ package com.pudonghot.ambition.crm.controller;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import me.chyxion.tigon.mybatis.Search;
|
||||
import me.chyxion.tigon.model.ViewModel;
|
||||
import javax.validation.constraints.Max;
|
||||
@ -19,7 +18,6 @@ import com.pudonghot.ambition.crm.model.Customer;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.pudonghot.ambition.crm.model.CustomerProperty;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import com.pudonghot.ambition.crm.service.CustomerService;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
@ -39,8 +37,6 @@ import com.pudonghot.ambition.crm.form.update.CustomerFormForUpdate;
|
||||
public class CustomerController
|
||||
extends BaseQueryController<Customer> {
|
||||
|
||||
@Value("${file.base-path}")
|
||||
private String fileBasePath;
|
||||
private static final List<String> SEARCH_COLS = Arrays.asList(
|
||||
"customer.id",
|
||||
"customer.name",
|
||||
@ -148,10 +144,7 @@ public class CustomerController
|
||||
if (StringUtils.isNotBlank(strSearch)) {
|
||||
search.setAttr("YTD_SALE", true);
|
||||
}
|
||||
final ListResult<ViewModel<Customer>> result =
|
||||
listViewModels(search, start, limit, strSearch, criteria, filters, orders);
|
||||
result.setAttr("fileBasePath", fileBasePath);
|
||||
return result;
|
||||
return listViewModels(search, start, limit, strSearch, criteria, filters, orders);
|
||||
}
|
||||
|
||||
@RequiresRoles(User.ROLE_ADMIN)
|
||||
|
@ -1,9 +1,5 @@
|
||||
package com.pudonghot.ambition.crm.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.http.MediaType;
|
||||
import me.chyxion.tigon.webmvc.ResourceModel;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@ -16,9 +12,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
public class SiteController {
|
||||
|
||||
@RequestMapping("/")
|
||||
public ResourceModel index() throws IOException {
|
||||
return new ResourceModel(
|
||||
IOUtils.toByteArray(SiteController.class.getResourceAsStream("/static/index.html")),
|
||||
MediaType.TEXT_HTML_VALUE, null);
|
||||
public void index() {
|
||||
}
|
||||
}
|
||||
|
@ -10,17 +10,19 @@ import me.chyxion.tigon.mybatis.Search;
|
||||
import org.springframework.util.Assert;
|
||||
import me.chyxion.tigon.model.ViewModel;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.pudonghot.ambition.file.AmbitionFileApi;
|
||||
import com.pudonghot.ambition.file.DiskFileApi;
|
||||
import com.pudonghot.ambition.crm.model.FileInfo;
|
||||
import com.pudonghot.ambition.crm.model.Application;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.pudonghot.ambition.crm.model.ApplicationImage;
|
||||
import com.pudonghot.ambition.crm.mapper.ApplicationMapper;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import com.pudonghot.ambition.crm.model.CustomerApplication;
|
||||
import com.pudonghot.ambition.crm.service.ApplicationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import me.chyxion.tigon.service.support.BaseCrudServiceSupport;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.pudonghot.ambition.crm.mapper.ApplicationImageMapper;
|
||||
import com.pudonghot.ambition.crm.mapper.CustomerApplicationMapper;
|
||||
import com.pudonghot.ambition.crm.form.update.ApplicationFormForUpdate;
|
||||
import com.pudonghot.ambition.crm.form.create.ApplicationFormForCreate;
|
||||
import com.pudonghot.ambition.crm.form.create.ApplicationImageFormForCreate;
|
||||
@ -40,9 +42,9 @@ public class ApplicationServiceSupport
|
||||
@Autowired
|
||||
private ApplicationImageMapper imageMapper;
|
||||
@Autowired
|
||||
private AmbitionFileApi fileApi;
|
||||
@Value("${file.base-path}")
|
||||
private String fileBasePath;
|
||||
private DiskFileApi fileApi;
|
||||
@Autowired
|
||||
private CustomerApplicationMapper customerApplicationMapper;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -82,7 +84,6 @@ public class ApplicationServiceSupport
|
||||
final List<ApplicationImage> images = imageMapper.list(
|
||||
new Search(ApplicationImage.APPLICATION_ID, id)
|
||||
.asc(ApplicationImage.SORT));
|
||||
images.forEach(image -> image.setUrl(fileBasePath + imageFolder(id) + "/" + image.getId()));
|
||||
return super.findViewModel(id)
|
||||
.setAttr("images", images);
|
||||
}
|
||||
@ -149,7 +150,33 @@ public class ApplicationServiceSupport
|
||||
}
|
||||
}
|
||||
|
||||
private List<ApplicationImage> uploadImages(final String applicationId, int sort, final MultipartFile[] images, final String[] titles, final String createdBy) {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Throwable.class)
|
||||
public int delete(final String id) {
|
||||
log.info("Delete application [{}].", id);
|
||||
final Application app = find(id);
|
||||
Assert.state(app != null, "No application [" + id + "] found");
|
||||
Assert.state(!app.isEnabled(), "Application [" + id + "] is enabled");
|
||||
Assert.state(customerApplicationMapper.count(
|
||||
new Search(CustomerApplication.APPLICATION_ID, id)) == 0,
|
||||
"Application [" + id + "] is in using");
|
||||
final Search appImageSearch = new Search(ApplicationImage.APPLICATION_ID, id);
|
||||
imageMapper.list(appImageSearch).forEach(
|
||||
image -> fileApi.deleteById(image.getFileId()));
|
||||
imageMapper.delete(appImageSearch);
|
||||
return mapper.delete(id);
|
||||
}
|
||||
|
||||
private List<ApplicationImage> uploadImages(
|
||||
final String applicationId,
|
||||
int sort,
|
||||
final MultipartFile[] images,
|
||||
final String[] titles,
|
||||
final String createdBy) {
|
||||
|
||||
final List<ApplicationImage> imagesRtn = new ArrayList<>();
|
||||
final Date now = new Date();
|
||||
final String imageFolder = imageFolder(applicationId);
|
||||
@ -159,9 +186,11 @@ public class ApplicationServiceSupport
|
||||
try (final InputStream ins = image.getInputStream()) {
|
||||
final String imageId = idSeq.get();
|
||||
final ApplicationImage appImage = new ApplicationImage();
|
||||
appImage.setUrl(fileApi.uploadImage(ins, imageFolder, imageId));
|
||||
final FileInfo fileInfo = fileApi.uploadImage(ins, imageFolder, imageId);
|
||||
appImage.setId(imageId);
|
||||
appImage.setApplicationId(applicationId);
|
||||
appImage.setFileId(fileInfo.getId());
|
||||
appImage.setUrl(fileInfo.getUrl());
|
||||
appImage.setSort(sort++);
|
||||
appImage.setEnabled(true);
|
||||
appImage.setNote(titles[i]);
|
||||
|
@ -152,7 +152,7 @@ public class CustomerServiceSupport
|
||||
final CustomerApplication customerApplication = new CustomerApplication();
|
||||
customerApplication.setId(idSeq.get());
|
||||
customerApplication.setCustomerId(customerId);
|
||||
customerApplication.setPropertyId(applicationId);
|
||||
customerApplication.setApplicationId(applicationId);
|
||||
customerApplication.setCreatedBy(operator);
|
||||
customerApplication.setDateCreated(now);
|
||||
customerApplicationMapper.insert(customerApplication);
|
||||
|
@ -18,5 +18,5 @@ spring.http.multipart.max-file-size=1024MB
|
||||
spring.http.multipart.max-request-size=1024MB
|
||||
|
||||
# File
|
||||
file.base-path=http://127.0.0.1:${server.port}/f/
|
||||
file.base-path=http://127.0.0.1:1217/lm-f/
|
||||
file.base-dir=/Users/chyxion/Workspaces/ambition-crm/files/
|
||||
|
@ -5,6 +5,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.pudonghot.ambition.crm.AmbitionCRM;
|
||||
import com.pudonghot.ambition.crm.model.FileInfo;
|
||||
import com.pudonghot.ambition.file.AmbitionFileApi;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@ -23,11 +24,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
public class DiskFileStoreTest {
|
||||
|
||||
@Autowired
|
||||
private AmbitionFileApi fileApi;
|
||||
private AmbitionFileApi<FileInfo> fileApi;
|
||||
|
||||
@Test
|
||||
public void testUpload() throws Exception {
|
||||
final String foobar = fileApi.upload(new File("/Users/chyxion/Workspaces//Eclipse/Default/bzush-schoolmate-api/src/main/java/cn/edu/bzu/schoolmate/controllers/FileController.java"), "foobar");
|
||||
final FileInfo foobar = fileApi.upload(new File("/Users/chyxion/Workspaces//Eclipse/Default/bzush-schoolmate-api/src/main/java/cn/edu/bzu/schoolmate/controllers/FileController.java"), "foobar");
|
||||
log.info("Upload result [{}].", foobar);
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
* Mar 24, 2015 1:22:40 PM
|
||||
*/
|
||||
@Validated
|
||||
public interface AmbitionFileApi {
|
||||
String META_FORMAT = "format";
|
||||
String META_DOWNLOAD_NAME = "downloadName";
|
||||
public interface AmbitionFileApi<UploadReturn> {
|
||||
|
||||
/**
|
||||
* get object url
|
||||
@ -50,39 +48,36 @@ public interface AmbitionFileApi {
|
||||
* A UUID Will Be The Name, If Name Not Specified,
|
||||
* @return File Link [http://umsapp.oss-cn-hangzhou.aliyuncs.com/echat-dev/foobar.png]
|
||||
*/
|
||||
@NotBlank String upload(@NotNull File file, String name);
|
||||
UploadReturn upload(@NotNull File file, String name);
|
||||
|
||||
/**
|
||||
* Upload File To OSS
|
||||
* Upload File
|
||||
* @param file File
|
||||
* @param folder Custom Folder
|
||||
* @param name File Name [optional], Such As "foobar.doc",
|
||||
* A UUID Will Be The Name, If Name Not Specified,
|
||||
* @param name File Name
|
||||
* @param contentType Content Type [Optional]
|
||||
* @param format File Format [Optional]
|
||||
* @return
|
||||
*/
|
||||
@NotBlank String upload(@NotNull File file, String folder, String name, String contentType, String format);
|
||||
UploadReturn upload(@NotNull File file, String folder, String name, String contentType, String format);
|
||||
|
||||
/**
|
||||
* Upload Stream To OSS
|
||||
* Upload Stream
|
||||
* @param ins Input Stream
|
||||
* @param name File Name [optional], Such As "foobar.png",
|
||||
* A UUID Will Be The Name, If Name Not Specified,
|
||||
* @param name File Name
|
||||
* @return File Link [http://umsapp.oss-cn-hangzhou.aliyuncs.com/echat-dev/foobar.png]
|
||||
*/
|
||||
@NotBlank String upload(@NotNull InputStream ins, @Min(1) long contentLength, String name);
|
||||
UploadReturn upload(@NotNull InputStream ins, @Min(1) long contentLength, String name);
|
||||
|
||||
/**
|
||||
* Upload Stream To OSS
|
||||
* Upload Stream
|
||||
* @param ins Input Stream
|
||||
* @param folder Custom Folder
|
||||
* @param name File Name [optional], Such As "foobar.doc",
|
||||
* A UUID Will Be The Name, If Name Not Specified,
|
||||
* @param name name
|
||||
* @param contentType Content Type [Optional]
|
||||
* @param format File Format [Optional]
|
||||
*/
|
||||
@NotBlank String upload(@NotNull InputStream ins,
|
||||
UploadReturn upload(@NotNull InputStream ins,
|
||||
@Min(1) long contentLength,
|
||||
String folder,
|
||||
String name,
|
||||
@ -101,7 +96,7 @@ public interface AmbitionFileApi {
|
||||
* @param downloadName File Download Name [Optional]
|
||||
* @return
|
||||
*/
|
||||
@NotBlank String upload(@NotNull InputStream ins,
|
||||
UploadReturn upload(@NotNull InputStream ins,
|
||||
@Min(1) long contentLength,
|
||||
String folder,
|
||||
String name,
|
||||
@ -159,7 +154,7 @@ public interface AmbitionFileApi {
|
||||
* @param gender F/M/S
|
||||
* @return
|
||||
*/
|
||||
@NotBlank String uploadAvatar(@NotBlank String memberId, @NotBlank String name, String gender);
|
||||
UploadReturn uploadAvatar(@NotBlank String memberId, @NotBlank String name, String gender);
|
||||
|
||||
/**
|
||||
* Upload Member Avatar
|
||||
@ -169,7 +164,7 @@ public interface AmbitionFileApi {
|
||||
* @param gender
|
||||
* @return
|
||||
*/
|
||||
@NotBlank String uploadAvatar(@NotBlank String folder, @NotNull String memberId, @NotBlank String name, String gender);
|
||||
UploadReturn uploadAvatar(@NotBlank String folder, @NotNull String memberId, @NotBlank String name, String gender);
|
||||
|
||||
/**
|
||||
* get member avatar url
|
||||
@ -184,14 +179,14 @@ public interface AmbitionFileApi {
|
||||
* @param insAvatar
|
||||
* @return
|
||||
*/
|
||||
@NotBlank String uploadAvatar(@NotBlank String memberId, @NotNull InputStream insAvatar);
|
||||
UploadReturn uploadAvatar(@NotBlank String memberId, @NotNull InputStream insAvatar);
|
||||
|
||||
/**
|
||||
* @param memberId
|
||||
* @param bytesAvatar
|
||||
* @return
|
||||
*/
|
||||
@NotBlank String uploadAvatar(@NotBlank String memberId, @NotNull byte[] bytesAvatar);
|
||||
UploadReturn uploadAvatar(@NotBlank String memberId, @NotNull byte[] bytesAvatar);
|
||||
|
||||
/**
|
||||
* Upload Image
|
||||
@ -200,7 +195,7 @@ public interface AmbitionFileApi {
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
@NotBlank String uploadImage(@NotNull InputStream ins, String folder, String name);
|
||||
UploadReturn uploadImage(@NotNull InputStream ins, String folder, String name);
|
||||
|
||||
/**
|
||||
* @param image
|
||||
@ -208,7 +203,7 @@ public interface AmbitionFileApi {
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
@NotBlank String uploadImage(@NotNull byte[] image, String folder, String name);
|
||||
UploadReturn uploadImage(@NotNull byte[] image, String folder, String name);
|
||||
|
||||
/**
|
||||
* Upload Image
|
||||
@ -216,5 +211,5 @@ public interface AmbitionFileApi {
|
||||
* @param ins
|
||||
* @return
|
||||
*/
|
||||
@NotBlank String uploadImage(@NotNull InputStream ins, String folder);
|
||||
UploadReturn uploadImage(@NotNull InputStream ins, String folder);
|
||||
}
|
||||
|
@ -2,13 +2,11 @@ package com.pudonghot.ambition.file.support;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.LinkedList;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.io.FileInputStream;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
@ -32,7 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
* Sep 14, 2016 3:31:52 PM
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class AbstractAmbitionFileApi implements AmbitionFileApi {
|
||||
public abstract class AbstractAmbitionFileApi<UploadReturn> implements AmbitionFileApi<UploadReturn> {
|
||||
@Autowired
|
||||
protected ImageTool imageTool;
|
||||
@Autowired
|
||||
@ -42,8 +40,8 @@ public abstract class AbstractAmbitionFileApi implements AmbitionFileApi {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String upload(File file, String folder, String name, String contentType, String format) {
|
||||
log.debug("Upload Input Stream To OSS With File [{}].", name);
|
||||
public UploadReturn upload(final File file, final String folder, String name, final String contentType, String format) {
|
||||
log.info("Upload input stream file [{}].", name);
|
||||
if (StringUtils.isBlank(name)) {
|
||||
name = idSeq.get();
|
||||
String fileExt = FilenameUtils.getExtension(file.getName());
|
||||
@ -70,7 +68,7 @@ public abstract class AbstractAmbitionFileApi implements AmbitionFileApi {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String upload(File file, String name) {
|
||||
public UploadReturn upload(File file, String name) {
|
||||
return upload(file, null, name, null, null);
|
||||
}
|
||||
|
||||
@ -78,7 +76,7 @@ public abstract class AbstractAmbitionFileApi implements AmbitionFileApi {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String upload(InputStream in, long contentLength, String name) {
|
||||
public UploadReturn upload(InputStream in, long contentLength, String name) {
|
||||
return upload(in, contentLength, null, name, null, null);
|
||||
}
|
||||
|
||||
@ -86,7 +84,7 @@ public abstract class AbstractAmbitionFileApi implements AmbitionFileApi {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String upload(InputStream in,
|
||||
public UploadReturn upload(InputStream in,
|
||||
long contentLength,
|
||||
String folder, String name,
|
||||
String contentType, String fileFormat) {
|
||||
@ -144,7 +142,7 @@ public abstract class AbstractAmbitionFileApi implements AmbitionFileApi {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String uploadAvatar(String memberId, String name, String gender) {
|
||||
public UploadReturn uploadAvatar(String memberId, String name, String gender) {
|
||||
return uploadAvatar(avatarFolder(), memberId, name, gender);
|
||||
}
|
||||
|
||||
@ -152,7 +150,7 @@ public abstract class AbstractAmbitionFileApi implements AmbitionFileApi {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String uploadAvatar(String folder, String memberId, String name, String gender) {
|
||||
public UploadReturn uploadAvatar(String folder, String memberId, String name, String gender) {
|
||||
byte[] bytesAvatar = imageTool.genAvatar(name, gender);
|
||||
return upload(new ByteArrayInputStream(bytesAvatar),
|
||||
bytesAvatar.length,
|
||||
@ -165,7 +163,7 @@ public abstract class AbstractAmbitionFileApi implements AmbitionFileApi {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String uploadAvatar(String memberId, InputStream ins) {
|
||||
public UploadReturn uploadAvatar(String memberId, InputStream ins) {
|
||||
return uploadImage(ins, avatarFolder(), memberId);
|
||||
}
|
||||
|
||||
@ -181,7 +179,7 @@ public abstract class AbstractAmbitionFileApi implements AmbitionFileApi {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String uploadImage(InputStream ins, String folder, String name) {
|
||||
public UploadReturn uploadImage(InputStream ins, String folder, String name) {
|
||||
byte[] bytesFile = null;
|
||||
try {
|
||||
bytesFile = IOUtils.toByteArray(ins);
|
||||
@ -200,7 +198,7 @@ public abstract class AbstractAmbitionFileApi implements AmbitionFileApi {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String uploadImage(byte[] bytesFile, String folder, String name) {
|
||||
public UploadReturn uploadImage(byte[] bytesFile, String folder, String name) {
|
||||
String format = imageTool.imageType(new ByteArrayInputStream(bytesFile));
|
||||
if (StringUtils.isNotBlank(format)) {
|
||||
if (!ArrayUtils.contains(new String[] {"png", "jpg", "jpeg"}, format)) {
|
||||
@ -226,7 +224,7 @@ public abstract class AbstractAmbitionFileApi implements AmbitionFileApi {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String uploadImage(InputStream ins, String folder) {
|
||||
public UploadReturn uploadImage(InputStream ins, String folder) {
|
||||
return uploadImage(ins, folder, null);
|
||||
}
|
||||
|
||||
@ -234,7 +232,7 @@ public abstract class AbstractAmbitionFileApi implements AmbitionFileApi {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String uploadAvatar(String memberId, byte[] bytesAvatar) {
|
||||
public UploadReturn uploadAvatar(String memberId, byte[] bytesAvatar) {
|
||||
return uploadImage(bytesAvatar, avatarFolder(), memberId);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.pudonghot.ambition.file;
|
||||
|
||||
import com.pudonghot.ambition.crm.model.FileInfo;
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@ -9,7 +10,7 @@ import java.io.File;
|
||||
* chyxion@163.com <br>
|
||||
* Mar 11, 2018 18:13:51
|
||||
*/
|
||||
public interface DiskFileApi extends AmbitionFileApi {
|
||||
public interface DiskFileApi extends AmbitionFileApi<FileInfo> {
|
||||
|
||||
/**
|
||||
* find file info
|
||||
@ -24,4 +25,10 @@ public interface DiskFileApi extends AmbitionFileApi {
|
||||
* @return file
|
||||
*/
|
||||
File getFile(FileInfo fileInfo);
|
||||
|
||||
/**
|
||||
* delete file by id
|
||||
* @param id id
|
||||
*/
|
||||
void deleteById(@NotBlank String id);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ import com.pudonghot.ambition.file.support.AbstractAmbitionFileApi;
|
||||
*/
|
||||
@Slf4j
|
||||
public class DiskFileSupport
|
||||
extends AbstractAmbitionFileApi
|
||||
extends AbstractAmbitionFileApi<FileInfo>
|
||||
implements DiskFileApi {
|
||||
|
||||
@Autowired
|
||||
@ -85,7 +85,7 @@ public class DiskFileSupport
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public String upload(final InputStream in,
|
||||
public FileInfo upload(final InputStream in,
|
||||
final long contentLength,
|
||||
String folder,
|
||||
final String name,
|
||||
@ -97,13 +97,17 @@ public class DiskFileSupport
|
||||
boolean update = false;
|
||||
Date now = new Date();
|
||||
FileInfo fileInfo = findFileInfo(fullName);
|
||||
File prevFile = null;
|
||||
if (fileInfo != null) {
|
||||
fileInfo.setDateUpdated(now);
|
||||
update = true;
|
||||
// delete previous file
|
||||
prevFile = new File(getFileDir(), fileInfo.getFilePath());
|
||||
final File prevFile = getFile(fileInfo);
|
||||
log.info("Will delete previous file [{}].", prevFile);
|
||||
// delete previous files
|
||||
if (prevFile != null) {
|
||||
log.info("Delete previous file [{}] before upload.", prevFile);
|
||||
FileUtils.deleteQuietly(prevFile);
|
||||
}
|
||||
}
|
||||
else {
|
||||
fileInfo = new FileInfo();
|
||||
@ -132,18 +136,6 @@ public class DiskFileSupport
|
||||
log.info("Upload input stream with name [{}].", fullName);
|
||||
OutputStream fout = null;
|
||||
try {
|
||||
// delete previous files
|
||||
if (prevFile != null) {
|
||||
FileUtils.deleteQuietly(prevFile);
|
||||
log.info("Delete file [{}] before upload.", prevFile);
|
||||
FileUtils.deleteQuietly(prevFile);
|
||||
}
|
||||
|
||||
// for (File file : getFileDir().listFiles(
|
||||
// (FilenameFilter) new WildcardFileFilter(filePath + ".*"))) {
|
||||
// log.info("Delete File [{}] Before Upload.", file.getAbsolutePath());
|
||||
// FileUtils.deleteQuietly(file);
|
||||
// }
|
||||
|
||||
final File storeFile = new File(getFileDir(), filePath);
|
||||
final File fileParent = storeFile.getParentFile();
|
||||
@ -153,8 +145,9 @@ public class DiskFileSupport
|
||||
|
||||
fout = new FileOutputStream(storeFile);
|
||||
IOUtils.copy(in, fout);
|
||||
// return getUrl(filePath);
|
||||
return basePath + fullName;
|
||||
// return basePath + fullName;
|
||||
fileInfo.setUrl(basePath + filePath);
|
||||
return fileInfo;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException(
|
||||
@ -230,6 +223,19 @@ public class DiskFileSupport
|
||||
return new File(getFileDir(), fileInfo.getFilePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void deleteById(String id) {
|
||||
final FileInfo fileInfo = fileInfoMapper.find(id);
|
||||
if (fileInfo != null) {
|
||||
log.info("Delete file [{}].", fileInfo);
|
||||
fileInfoMapper.delete(id);
|
||||
FileUtils.deleteQuietly(getFile(fileInfo));
|
||||
}
|
||||
}
|
||||
|
||||
// --
|
||||
// private methods
|
||||
|
||||
@ -275,7 +281,7 @@ public class DiskFileSupport
|
||||
String getFilePath(final String fileId, final String folder, final String name, String fileFormat) {
|
||||
String distFolder = DateFormatUtils.format(new Date(), "yyyyMMdd") + "/";
|
||||
if (StringUtils.isNotBlank(folder)) {
|
||||
if (distFolder.endsWith("/")) {
|
||||
if (folder.endsWith("/")) {
|
||||
distFolder = folder + distFolder;
|
||||
}
|
||||
else {
|
||||
@ -301,5 +307,4 @@ public class DiskFileSupport
|
||||
return StringUtils.isNotBlank(fileFormat) ?
|
||||
filePath + "." + fileFormat : filePath;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,7 +30,8 @@
|
||||
</update>
|
||||
|
||||
<select id="listSort" resultType="com.pudonghot.ambition.crm.model.ApplicationImage">
|
||||
select id, application_id,
|
||||
select id, file_id,
|
||||
url, application_id,
|
||||
created_by, date_created,
|
||||
updated_by, date_updated,
|
||||
enabled, note,
|
||||
|
@ -14,7 +14,7 @@
|
||||
<select id="list" resultType="com.pudonghot.ambition.crm.model.Application">
|
||||
select
|
||||
<include refid="cols" />,
|
||||
(select group_concat(id order by sort separator 0x1d) from
|
||||
(select group_concat(url order by sort separator 0x1d) from
|
||||
crm_application_image
|
||||
where application_id = a.id
|
||||
group by application_id) images,
|
||||
|
@ -183,7 +183,7 @@
|
||||
(select group_concat(p.id order by p.name separator ',')
|
||||
from crm_customer_application a
|
||||
join crm_customer_property p
|
||||
on a.property_id = p.id
|
||||
on a.application_id = p.id
|
||||
where a.customer_id = customer.id
|
||||
group by a.customer_id) applications,
|
||||
|
||||
@ -191,7 +191,7 @@
|
||||
(select group_concat(p.name order by p.name separator ',')
|
||||
from crm_customer_application a
|
||||
join crm_customer_property p
|
||||
on a.property_id = p.id
|
||||
on a.application_id = p.id
|
||||
where a.customer_id = customer.id
|
||||
group by a.customer_id) application_names
|
||||
|
||||
@ -202,7 +202,7 @@
|
||||
<if test="s.getAttr('APPLICATIONS') != null">
|
||||
join (select distinct customer_id
|
||||
from crm_customer_application
|
||||
where property_id in
|
||||
where application_id in
|
||||
<foreach item="appId" collection="s.getAttr('APPLICATIONS')" open="(" close=")" separator=",">
|
||||
#{appId}
|
||||
</foreach>
|
||||
|
@ -1,15 +1,14 @@
|
||||
package com.pudonghot.ambition.crm.mapper;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import java.util.Date;
|
||||
import org.junit.Assert;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import com.pudonghot.ambition.crm.mapper.CustomerApplicationMapper;
|
||||
import com.pudonghot.ambition.crm.model.CustomerApplication;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
@ -32,7 +31,7 @@ public class CustomerApplicationMapperTest extends AbstractTransactionalJUnit4Sp
|
||||
m.setId(id);
|
||||
m.setDateCreated(new Date());
|
||||
m.setCustomerId("s");
|
||||
m.setPropertyId("s");
|
||||
m.setApplicationId("s");
|
||||
mapper.insert(m);
|
||||
Assert.assertTrue(mapper.list(null).size() > 0);
|
||||
/*
|
||||
|
@ -4,7 +4,6 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.chyxion.tigon.model.M3;
|
||||
import me.chyxion.tigon.mybatis.Table;
|
||||
import me.chyxion.tigon.mybatis.Transient;
|
||||
|
||||
/**
|
||||
* @author Shaun Chyxion <br>
|
||||
@ -18,12 +17,14 @@ public class ApplicationImage extends M3<String, String> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// Column Names
|
||||
public static final String FILE_ID = "file_id";
|
||||
public static final String URL = "url";
|
||||
public static final String APPLICATION_ID = "application_id";
|
||||
public static final String SORT = "sort";
|
||||
|
||||
// Properties
|
||||
private String fileId;
|
||||
private String url;
|
||||
private String applicationId;
|
||||
private float sort;
|
||||
@Transient
|
||||
private String url;
|
||||
}
|
||||
|
@ -19,10 +19,10 @@ public class CustomerApplication extends M3<String, String> {
|
||||
|
||||
// Column Names
|
||||
public static final String CUSTOMER_ID = "customer_id";
|
||||
public static final String PROPERTY_ID = "property_id";
|
||||
public static final String APPLICATION_ID = "application_id";
|
||||
|
||||
// Properties
|
||||
private String customerId;
|
||||
private String propertyId;
|
||||
private String applicationId;
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.chyxion.tigon.model.M3;
|
||||
import me.chyxion.tigon.mybatis.Table;
|
||||
import me.chyxion.tigon.mybatis.Transient;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
@ -33,4 +34,6 @@ public class FileInfo extends M3<String, String> {
|
||||
private String downloadName;
|
||||
private long contentLength;
|
||||
private String contentType;
|
||||
@Transient
|
||||
private String url;
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ export default BaseFormInput.extend({
|
||||
if (me.get('multiple')) {
|
||||
const vals = me.getVal();
|
||||
if (isArray(vals)) {
|
||||
vals.each(v => me.select(me.findOption(v)));
|
||||
vals.forEach(v => me.select(me.findOption(v)));
|
||||
}
|
||||
else {
|
||||
me.setVal(me.getSelected());
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { helper } from '@ember/component/helper';
|
||||
|
||||
export function customerApplicationImages([fileBasePath, appId, images, titles]) {
|
||||
export function customerApplicationImages([images, titles]) {
|
||||
if (images) {
|
||||
titles = titles ? titles.split(String.fromCharCode(0x1d)) : [];
|
||||
return images.split(String.fromCharCode(0x1d)).map((image, i) => {
|
||||
return {
|
||||
image: fileBasePath + 'app/' + appId + '/' + image,
|
||||
image: image,
|
||||
title: titles[i]
|
||||
}
|
||||
});
|
||||
|
@ -14,7 +14,9 @@
|
||||
<div class="space-12"></div>
|
||||
<p>{{content}}</p>
|
||||
<hr />
|
||||
{{#with (customer-application-images file-base-path model.id model.images model.imageTitles) as |images|}}
|
||||
<p>{{model.note}}</p>
|
||||
<hr />
|
||||
{{#with (customer-application-images model.images model.imageTitles) as |images|}}
|
||||
{{#each images as |image index|}}
|
||||
{{image-previews cover-title=true image-height=192 image-style='border-radius: 2%; border: 1px solid #DCDCDC; max-width: 480px;' previews=images index=index}}
|
||||
{{/each}}
|
||||
|
@ -23,7 +23,8 @@
|
||||
Name
|
||||
</th>
|
||||
<th>
|
||||
Content
|
||||
<i class="ace-icon fa fa-file-image-o bigger-110 hidden-480"></i>
|
||||
Images
|
||||
</th>
|
||||
<th>
|
||||
<i class="ace-icon fa fa-sticky-note-o bigger-110 hidden-480"></i>
|
||||
@ -56,11 +57,10 @@
|
||||
{{#each model.data as |it|}}
|
||||
<tr>
|
||||
<td>
|
||||
{{!it.name}}
|
||||
{{customer-application/preview-btn model=it file-base-path=model.fileBasePath}}
|
||||
{{customer-application/preview-btn model=it}}
|
||||
</td>
|
||||
<td>
|
||||
{{image-previews previews=(customer-application-images model.fileBasePath it.id it.images it.imageTitles)}}
|
||||
{{image-previews previews=(customer-application-images it.images it.imageTitles)}}
|
||||
</td>
|
||||
<td>
|
||||
{{editable-cell model=it field='note'}}
|
||||
@ -79,6 +79,11 @@
|
||||
{{#link-to 'customer-application.edit' it.id class='btn btn-xs btn-info' data-rel='tooltip' title='Edit'}}
|
||||
<i class="ace-icon fa fa-pencil bigger-120"></i>
|
||||
{{/link-to}}
|
||||
{{#if ajax.user.admin}}
|
||||
{{#unless it.enabled}}
|
||||
{{delete-btn model=it}}
|
||||
{{/unless}}
|
||||
{{/if}}
|
||||
</div>
|
||||
<div class="hidden-md hidden-lg">
|
||||
<div class="inline pos-rel">
|
||||
@ -91,27 +96,20 @@
|
||||
<li>
|
||||
{{status-toggle-button model=it iconOnly=true}}
|
||||
</li>
|
||||
{{!--
|
||||
<li>
|
||||
{{#link-to 'customer-status.edit' it.id class='tooltip-info' data-rel='tooltip' title='Edit'}}
|
||||
{{#link-to 'customer-application.edit' it.id class='tooltip-info' data-rel='tooltip' title='Edit'}}
|
||||
<span class="blue">
|
||||
<i class="ace-icon fa fa-pencil-square-o bigger-120"></i>
|
||||
</span>
|
||||
{{/link-to}}
|
||||
</li>
|
||||
{{#if ajax.user.admin}}
|
||||
{{#unless it.enabled}}
|
||||
<li>
|
||||
{{#if (not-eq model.data.firstObject.id it.id)}}
|
||||
<a class="tooltip-info" title="Move Up" {{action (route-action 'moveUp' it)}}>
|
||||
<i class="ace-icon fa fa-arrow-up bigger-120"></i>
|
||||
</a>
|
||||
{{/if}}
|
||||
{{#if (not-eq model.data.lastObject.id it.id)}}
|
||||
<a class="tooltip-info" title="Move Down" {{action (route-action 'moveDown' it)}}>
|
||||
<i class="ace-icon fa fa-arrow-down bigger-120"></i>
|
||||
</a>
|
||||
{{/if}}
|
||||
{{delete-btn model=it icon-only=true}}
|
||||
</li>
|
||||
--}}
|
||||
{{/unless}}
|
||||
{{/if}}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -226,7 +226,7 @@
|
||||
{{#each (str-split it.applications) as |aId|}}
|
||||
{{#each model.applicationList as |app|}}
|
||||
{{#if (eq aId app.id)}}
|
||||
{{customer-application/preview-btn model=app file-base-path=model.fileBasePath}}
|
||||
{{customer-application/preview-btn model=app}}
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
{{!option-text model.applicationList a 'id' 'name'}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user