|
@@ -7,7 +7,9 @@ import com.gis.domain.dto.GoodsDto;
|
|
|
import com.gis.domain.dto.GoodsPageDateDto;
|
|
|
import com.gis.domain.po.FileEntity;
|
|
|
import com.gis.domain.po.GoodsEntity;
|
|
|
+import com.gis.domain.po.SysUserEntity;
|
|
|
import com.gis.domain.vo.GoodsVo;
|
|
|
+import com.gis.domain.vo.SpiritVo;
|
|
|
import com.gis.service.FileService;
|
|
|
import com.gis.service.GoodsService;
|
|
|
import com.gis.web.aop.WebControllerLog;
|
|
@@ -15,6 +17,7 @@ import com.github.pagehelper.PageInfo;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.shiro.authz.annotation.Logical;
|
|
|
import org.apache.shiro.authz.annotation.RequiresRoles;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -52,9 +55,24 @@ public class GoodsController extends BaseController {
|
|
|
@PostMapping("list")
|
|
|
public Result<GoodsVo> list(@RequestBody GoodsPageDateDto param) {
|
|
|
|
|
|
+ SysUserEntity sysUser = getSysUser();
|
|
|
startPage(param);
|
|
|
+ List<GoodsVo> search;
|
|
|
|
|
|
- PageInfo<GoodsVo> page = new PageInfo<>(goodsService.search(param));
|
|
|
+
|
|
|
+ // 已审核
|
|
|
+ if (param.getStatus() == 4) {
|
|
|
+ search = goodsService.search(param, null);
|
|
|
+ // 待审核
|
|
|
+ } else {
|
|
|
+ if ("sys_normal".equals(sysUser.getRole())) {
|
|
|
+ search = goodsService.search(param, sysUser.getId());
|
|
|
+ } else {
|
|
|
+ search = goodsService.search(param, null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ PageInfo<GoodsVo> page = new PageInfo<>(search);
|
|
|
return Result.success(page);
|
|
|
}
|
|
|
|
|
@@ -63,27 +81,16 @@ public class GoodsController extends BaseController {
|
|
|
@PostMapping("save")
|
|
|
public Result save(@Valid @RequestBody GoodsDto param) {
|
|
|
|
|
|
+
|
|
|
+
|
|
|
GoodsEntity entity = null;
|
|
|
if (param.getId() == null) {
|
|
|
entity = new GoodsEntity();
|
|
|
BeanUtils.copyProperties(param, entity);
|
|
|
// 默认值279
|
|
|
- entity.setStatus(1);
|
|
|
+// entity.setStatus(1);
|
|
|
+ entity.setSubmitId(getTokenUserId());
|
|
|
goodsService.save(entity);
|
|
|
-
|
|
|
-
|
|
|
- String modelType = null;
|
|
|
- if (entity.getType() == 1) {
|
|
|
- modelType = TypeCode.MODEL_GOODS_IMG;
|
|
|
- } else if (entity.getType() == 2) {
|
|
|
- modelType = TypeCode.MODEL_GOODS_VIDEO;
|
|
|
- } else if (entity.getType() == 3) {
|
|
|
- modelType = TypeCode.MODEL_GOODS_MODEL;
|
|
|
- }
|
|
|
-
|
|
|
- // 图片信息跟goodsId绑定
|
|
|
- fileService.setFkIdByIds(param.getFileId(), entity.getId(), modelType);
|
|
|
-
|
|
|
} else {
|
|
|
entity = goodsService.findById(param.getId());
|
|
|
if (entity == null) {
|
|
@@ -96,9 +103,49 @@ public class GoodsController extends BaseController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ // 编辑封面
|
|
|
+ editCover(param, entity);
|
|
|
+
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
+ // 设置封面
|
|
|
+ private void editCover(GoodsDto param, GoodsEntity entity){
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ String modelType = null;
|
|
|
+ if (entity.getType() == 1) {
|
|
|
+ modelType = TypeCode.MODEL_GOODS_IMG;
|
|
|
+ } else if (entity.getType() == 2) {
|
|
|
+ modelType = TypeCode.MODEL_GOODS_VIDEO;
|
|
|
+ } else if (entity.getType() == 3) {
|
|
|
+ modelType = TypeCode.MODEL_GOODS_MODEL;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 图片信息跟goodsId绑定
|
|
|
+ String fileIds = param.getFileId();
|
|
|
+ String[] split = StringUtils.split(fileIds, ",");
|
|
|
+ for (String fileId: split) {
|
|
|
+ fileService.setFkIdByIds(fileId, entity.getId(), modelType);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 修改封面为默认值
|
|
|
+ fileService.setCoverByFkId(entity.getId(), modelType);
|
|
|
+
|
|
|
+ // 设置封面
|
|
|
+ FileEntity fileEntity = fileService.findById(param.getThumbFileId());
|
|
|
+ fileEntity.setCover(1);
|
|
|
+ fileEntity.setUpdateTime(new Date());
|
|
|
+ fileService.update(fileEntity);
|
|
|
+
|
|
|
+ // 更新缩略图
|
|
|
+ entity.setThumb(fileEntity.getThumb());
|
|
|
+ entity.setUpdateTime(new Date());
|
|
|
+ goodsService.update(entity);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 素材文件,真删除
|
|
@@ -116,9 +163,8 @@ public class GoodsController extends BaseController {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 设置封面后,把封面url设置到(可以在这里设置,也可以在保存方法设置)
|
|
|
- *
|
|
|
- */
|
|
|
+ * 有且只有一个封面
|
|
|
+ */
|
|
|
@ApiOperation("设置封面")
|
|
|
@GetMapping("setCover/{fileId}")
|
|
|
public Result setCover(@PathVariable Long fileId) {
|
|
@@ -127,6 +173,18 @@ public class GoodsController extends BaseController {
|
|
|
// 设置封面
|
|
|
fileService.setCover(fileId);
|
|
|
|
|
|
+ // 更新封面图
|
|
|
+
|
|
|
+ FileEntity fileEntity = fileService.findById(fileId);
|
|
|
+ if (fileEntity == null) {
|
|
|
+ log.error("文件不存在");
|
|
|
+ return Result.failure("文件不存在");
|
|
|
+ }
|
|
|
+ GoodsEntity entity = goodsService.findById(Long.valueOf(fileEntity.getFkId()));
|
|
|
+ entity.setThumb(fileEntity.getThumb());
|
|
|
+ entity.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ goodsService.update(entity);
|
|
|
|
|
|
return Result.success();
|
|
|
}
|