|
@@ -33,10 +33,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -63,8 +60,6 @@ public class GoodsServiceImpl extends IBaseServiceImpl<GoodsEntity, Long> implem
|
|
|
private final static String PREFIX_PATH = "/goods";
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
@Override
|
|
|
public IBaseMapper<GoodsEntity, Long> getBaseMapper() {
|
|
|
return this.entityMapper;
|
|
@@ -77,11 +72,6 @@ public class GoodsServiceImpl extends IBaseServiceImpl<GoodsEntity, Long> implem
|
|
|
return Result.success(new PageInfo<>(entityMapper.search(param, display)));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
@Override
|
|
|
public Result removes(String ids) {
|
|
|
String[] split = StrUtil.split(ids, ",");
|
|
@@ -103,19 +93,6 @@ public class GoodsServiceImpl extends IBaseServiceImpl<GoodsEntity, Long> implem
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public Result removeFile(Long fileId) {
|
|
|
- FileEntity entity = fileService.findById(fileId);
|
|
|
- if (entity == null){
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
-
|
|
|
- entity.setIsDelete(1);
|
|
|
- entity.setIsIndex(0);
|
|
|
- entity.setUpdateTime(LocalDateTime.now());
|
|
|
- fileService.update(entity);
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 设置封面图
|
|
@@ -133,165 +110,37 @@ public class GoodsServiceImpl extends IBaseServiceImpl<GoodsEntity, Long> implem
|
|
|
fileService.indexDisable(goodId, entity.getModule());
|
|
|
fileService.indexEnabled(fileId);
|
|
|
|
|
|
- // 设置缩略图
|
|
|
-// setThumbByIndex(goodId, entity.getFilePath());
|
|
|
Object thumb = entity.getFilePath();
|
|
|
return Result.success(thumb);
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 将封面图更新为缩略图
|
|
|
- */
|
|
|
- private void setThumbByIndex(Long goodId, String thumb){
|
|
|
- GoodsEntity entity = this.findById(goodId);
|
|
|
-// entity.setThumb(thumb);
|
|
|
- entity.setUpdateTime(LocalDateTime.now());
|
|
|
- this.update(entity);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Result uploadImg(MultipartFile file, String code) {
|
|
|
- if (!fileUtils.checkFile(file)) {
|
|
|
- throw new BaseRuntimeException("非法文件, 请重新上传");
|
|
|
- }
|
|
|
-
|
|
|
- String originalFilename = file.getOriginalFilename();
|
|
|
- String suffix = StringUtils.substringAfterLast(originalFilename, ".");
|
|
|
-
|
|
|
- String savePath = null;
|
|
|
- String time = DateUtil.format(LocalDateTime.now(), "yyyyMMdd_HHmmssSSS");
|
|
|
- if ("null".equals(code) || StringUtils.isBlank(code)) {
|
|
|
- savePath = "/goods/thumb/thumb_" + time + "." + suffix;
|
|
|
- } else {
|
|
|
- savePath = "/goods/" + code + "/thumb/thumb_" + time + "." + suffix;
|
|
|
- }
|
|
|
-
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
- try {
|
|
|
- FileUtil.writeFromStream(file.getInputStream(), configConstant.serverBasePath + savePath);
|
|
|
- result.put("fileName", originalFilename);
|
|
|
- result.put("filePath", savePath);
|
|
|
- return Result.success(result);
|
|
|
-
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public Result detail(Long id) {
|
|
|
GoodsEntity entity = this.findById(id);
|
|
|
if (entity == null) {
|
|
|
return Result.failure(MsgCode.e3001,"对象不存在,id: " + id);
|
|
|
}
|
|
|
- return Result.success(entity);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public Result isStorage(Long id, Integer status) {
|
|
|
- GoodsEntity entity = this.findById(id);
|
|
|
- if (entity == null) {
|
|
|
- log.error("对象id不存在 : {}", id);
|
|
|
- return Result.failure("对象id不存在");
|
|
|
- }
|
|
|
-
|
|
|
-// entity.setIsStorage(status);
|
|
|
- this.update(entity);
|
|
|
- return Result.success(entity);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public Result isStorages(Map<String, Integer> param) {
|
|
|
- for (Map.Entry<String, Integer> m : param.entrySet()) {
|
|
|
- entityMapper.setIsStorage(m.getKey(), m.getValue());
|
|
|
- }
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
|
|
|
- @Override
|
|
|
- public void updateIsStorage(Map<String, Integer> param){
|
|
|
- for (Map.Entry<String, Integer> m : param.entrySet()) {
|
|
|
- entityMapper.setIsStorage(m.getKey(), m.getValue());
|
|
|
+ List<FileEntity> files = new ArrayList<>();
|
|
|
+ String fileIds = entity.getFileIds();
|
|
|
+ if (StringUtils.isNotBlank(fileIds)){
|
|
|
+ files = fileService.findByIds(fileIds);
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- @Override
|
|
|
- public void updateStatusByIds(int status, String goodsIds) {
|
|
|
- goodsIds = StringUtils.trim(goodsIds);
|
|
|
- entityMapper.updateStatusByIds(status, goodsIds);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<String> findIdsByIsStorageAndStatus(int isStorage, int status) {
|
|
|
-
|
|
|
- return entityMapper.findIdsByIsStorageAndStatus(isStorage, status);
|
|
|
+ HashMap<Object, Object> result = new HashMap<>();
|
|
|
+ result.put("entity", entity);
|
|
|
+ result.put("file", files);
|
|
|
+ return Result.success(result);
|
|
|
}
|
|
|
|
|
|
-// @Override
|
|
|
-// public Result<GoodsEntity> collectList(LedgerPageDto param) {
|
|
|
-// startPage(param);
|
|
|
-// GoodsBo conditionDto = new GoodsBo();
|
|
|
-// conditionDto.setSearchKey(param.getSearchKey());
|
|
|
-// conditionDto.setIsStorage(0);
|
|
|
-// List<GoodsEntity> list = entityMapper.searchByCondition(conditionDto);
|
|
|
-// return Result.success(new PageInfo<>(list));
|
|
|
-// }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Result save(GoodsDto param) {
|
|
|
-
|
|
|
- // 删除数据
|
|
|
- this.delByIds(param.getDelIds());
|
|
|
-
|
|
|
- // 更新保存数据
|
|
|
- Long projectId = param.getProjectId();
|
|
|
- String type = param.getType();
|
|
|
- List<MultipartFile> files = param.getFiles();
|
|
|
- this.saveAndUpload(projectId, type, files);
|
|
|
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public Result<SceneEntity> projectId(Long projectId) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
-// @Override
|
|
|
-// public Result<GoodsEntity> passList(LedgerPageDto param) {
|
|
|
-// startPage(param);
|
|
|
-// GoodsBo conditionDto = new GoodsBo();
|
|
|
-// conditionDto.setSearchKey(param.getSearchKey());
|
|
|
-// conditionDto.setIsStorage(1);
|
|
|
-// List<GoodsEntity> list = entityMapper.searchByCondition(conditionDto);
|
|
|
-// return Result.success(new PageInfo<>(list));
|
|
|
-// }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Result<GoodsEntity> findByRegisterId(Long registerId) {
|
|
|
- return Result.success(entityMapper.findByRegisterId(registerId));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public Result fileList(Long id, String type) {
|
|
|
- List<FileEntity> list = fileService.findByType(id, type, TypeCode.MODULE_GOODS);
|
|
|
- return Result.success(list);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
|
|
|
@Override
|
|
|
public Result upload(MultipartFile file, String type, String dirCode) {
|
|
@@ -344,6 +193,8 @@ public class GoodsServiceImpl extends IBaseServiceImpl<GoodsEntity, Long> implem
|
|
|
return Result.success(result);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 保存文件且保存文件信息
|
|
|
* @param projectId 项目id
|
|
@@ -366,26 +217,48 @@ public class GoodsServiceImpl extends IBaseServiceImpl<GoodsEntity, Long> implem
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 封面图默认是第一张(若果文件id没有index值时),只有前端设置了封面,才会更新文件封面
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
public Result saveModel(ModelDto param) {
|
|
|
Long id = param.getId();
|
|
|
GoodsEntity entity;
|
|
|
+ boolean flag = false; // 更新文件id 开关
|
|
|
if (id == null){
|
|
|
entity = new GoodsEntity();
|
|
|
BeanUtils.copyProperties(param, entity);
|
|
|
entity.setType(TypeCode.MODULE_MODEL);
|
|
|
this.save(entity);
|
|
|
+ flag = true;
|
|
|
} else {
|
|
|
entity = this.findById(id);
|
|
|
if (entity == null){
|
|
|
return Result.failure("对象不存在");
|
|
|
}
|
|
|
+ if (!StrUtil.equals(param.getFileIds(), entity.getFileIds())){
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
BeanUtils.copyProperties(param, entity);
|
|
|
this.update(entity);
|
|
|
}
|
|
|
+
|
|
|
+ if (flag){ // 绑定文件id
|
|
|
+ fileService.addModuleIdToFile(entity.getFileIds(), entity.getId(), TypeCode.MODULE_GOODS);
|
|
|
+ log.info("绑定文件id完成");
|
|
|
+ }
|
|
|
+
|
|
|
return Result.success(entity);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public Result modelUpload(MultipartFile file, String projectId) {
|
|
|
String savePath = PREFIX_PATH + "/" + projectId + "/" + TypeCode.GOODS_MODEL;
|
|
@@ -404,17 +277,6 @@ public class GoodsServiceImpl extends IBaseServiceImpl<GoodsEntity, Long> implem
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public Result<GoodsEntity> listByProjectId(Long projectId, String type) {
|
|
|
- List<GoodsEntity> list = entityMapper.findByTypeAndProjectId(type, projectId);
|
|
|
- return Result.success(list);
|
|
|
- }
|
|
|
-
|
|
|
- private void delByIds(String ids){
|
|
|
- if (StringUtils.isNotBlank(ids)){
|
|
|
- entityMapper.delByIds(ids);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
|
|
|
|