瀏覽代碼

更新自定义模块、点赞量、用户点赞、excel上传

wuweihao 3 年之前
父節點
當前提交
71f436024c
共有 36 個文件被更改,包括 1254 次插入89 次删除
  1. 1 1
      gis_application/src/main/resources/application.properties
  2. 二進制
      gis_application/src/main/resources/data/template.xlsx
  3. 5 16
      gis_cms/src/main/java/com/gis/cms/controller/GoodsController.java
  4. 63 0
      gis_cms/src/main/java/com/gis/cms/controller/GoodsModuleController.java
  5. 15 0
      gis_cms/src/main/java/com/gis/cms/controller/QuestionGroupController.java
  6. 6 7
      gis_cms/src/main/java/com/gis/cms/controller/WebController.java
  7. 32 5
      gis_cms/src/main/java/com/gis/cms/controller/WebManageController.java
  8. 4 0
      gis_cms/src/main/java/com/gis/cms/entity/dto/GoodsDto.java
  9. 43 0
      gis_cms/src/main/java/com/gis/cms/entity/dto/GoodsModuleDto.java
  10. 31 0
      gis_cms/src/main/java/com/gis/cms/entity/dto/GoodsPageDateDto.java
  11. 21 0
      gis_cms/src/main/java/com/gis/cms/entity/dto/GoodsVoteDto.java
  12. 27 0
      gis_cms/src/main/java/com/gis/cms/entity/dto/GoodsWebPageDto.java
  13. 24 0
      gis_cms/src/main/java/com/gis/cms/entity/dto/TopicDto.java
  14. 0 23
      gis_cms/src/main/java/com/gis/cms/entity/dto/TypePageDateDto.java
  15. 22 0
      gis_cms/src/main/java/com/gis/cms/entity/po/GoodsEntity.java
  16. 41 0
      gis_cms/src/main/java/com/gis/cms/entity/po/GoodsModuleEntity.java
  17. 33 0
      gis_cms/src/main/java/com/gis/cms/entity/po/GoodsVoteEntity.java
  18. 9 2
      gis_cms/src/main/java/com/gis/cms/mapper/GoodsMapper.java
  19. 18 0
      gis_cms/src/main/java/com/gis/cms/mapper/GoodsModuleMapper.java
  20. 25 0
      gis_cms/src/main/java/com/gis/cms/mapper/GoodsVoteMapper.java
  21. 17 0
      gis_cms/src/main/java/com/gis/cms/mapper/provider/BaseProvider.java
  22. 10 5
      gis_cms/src/main/java/com/gis/cms/mapper/provider/GoodsProvider.java
  23. 29 0
      gis_cms/src/main/java/com/gis/cms/service/GoodsModuleService.java
  24. 7 2
      gis_cms/src/main/java/com/gis/cms/service/GoodsService.java
  25. 28 0
      gis_cms/src/main/java/com/gis/cms/service/GoodsVoteService.java
  26. 3 0
      gis_cms/src/main/java/com/gis/cms/service/QuestionGroupService.java
  27. 117 0
      gis_cms/src/main/java/com/gis/cms/service/impl/GoodsModuleServiceImpl.java
  28. 111 26
      gis_cms/src/main/java/com/gis/cms/service/impl/GoodsServiceImpl.java
  29. 115 0
      gis_cms/src/main/java/com/gis/cms/service/impl/GoodsVoteServiceImpl.java
  30. 138 0
      gis_cms/src/main/java/com/gis/cms/service/impl/QuestionGroupServiceImpl.java
  31. 7 0
      gis_common/pom.xml
  32. 1 0
      gis_common/src/main/java/com/gis/common/base/exception/BaseRuntimeException.java
  33. 141 0
      gis_common/src/main/java/com/gis/common/util/ExcelUtils.java
  34. 80 1
      gis_common/src/main/java/com/gis/common/util/FileUtils.java
  35. 19 1
      gis_common/src/main/java/com/gis/common/util/RegexUtil.java
  36. 11 0
      pom.xml

+ 1 - 1
gis_application/src/main/resources/application.properties

@@ -9,7 +9,7 @@ project.sc=\u65B0\u7586\u6B66\u8B66\u519B\u53F2\u9986
 redis.prefix=${project.en}_token_
 
 # \u5141\u8BB8\u4E0A\u4F20\u6587\u4EF6\u540E\u7F00
-server.file.allow=.jpg,.gif,.png,.ico,.bmp,.jpeg,.zip,.zp,.rar,.mp3,.mp4,.avi,.mov,.4dage,.wav,.wma,.m4a,.obj,.pdf,audio
+server.file.allow=.jpg,.gif,.png,.ico,.bmp,.jpeg,.zip,.zp,.rar,.mp3,.mp4,.avi,.mov,.4dage,.wav,.wma,.m4a,.obj,.pdf,audio.xlsx
 
 
 

二進制
gis_application/src/main/resources/data/template.xlsx


+ 5 - 16
gis_cms/src/main/java/com/gis/cms/controller/GoodsController.java

@@ -1,7 +1,7 @@
 package com.gis.cms.controller;
 
 import com.gis.cms.entity.dto.AuditDto;
-import com.gis.cms.entity.dto.TypePageDateDto;
+import com.gis.cms.entity.dto.GoodsPageDateDto;
 import com.gis.cms.entity.po.GoodsEntity;
 import com.gis.common.base.aop.WebControllerLog;
 import com.gis.common.util.Result;
@@ -18,7 +18,7 @@ import javax.validation.Valid;
 /**
  * Created by owen on 2021/6/21 0008 9:54
  */
-@Api(tags = "精品典藏管理")
+@Api(tags = "v0.2-精品典藏管理")
 @RestController
 @RequestMapping("cms/goods")
 public class GoodsController  {
@@ -28,14 +28,14 @@ public class GoodsController  {
 
 
 
-    @ApiOperation("列表")
+    @ApiOperation("v0.2-列表")
     @PostMapping("list")
-    public Result<GoodsEntity> list(@RequestBody TypePageDateDto param) {
+    public Result<GoodsEntity> list(@RequestBody GoodsPageDateDto param) {
         return entityService.search(param, null);
     }
 
     @WebControllerLog(description = "精品典藏-新增/修改", addDb = true)
-    @ApiOperation(value = "新增/修改", notes = "type=img, 才使用fileIds")
+    @ApiOperation(value = "v0.2-新增/修改", notes = "type=img, 才使用fileIds")
     @PostMapping("save")
     public Result save(@Valid @RequestBody GoodsDto param) {
         return entityService.saveEntity(param);
@@ -77,17 +77,6 @@ public class GoodsController  {
 
     }
 
-    /**
-     * 废弃
-     * @param fileId
-     * @return
-     */
-//    @WebControllerLog(description = "精品典藏-图片置顶", addDb = true)
-//    @ApiOperation(value = "图片置顶")
-//    @GetMapping("setIndex/{fileId}")
-//    public Result setIndex(@PathVariable Long fileId) {
-//        return entityService.setIndex(fileId);
-//    }
 
     @WebControllerLog(description = "烈士管理-提审", addDb = true)
     @ApiOperation("提审")

+ 63 - 0
gis_cms/src/main/java/com/gis/cms/controller/GoodsModuleController.java

@@ -0,0 +1,63 @@
+package com.gis.cms.controller;
+
+import com.gis.cms.entity.dto.GoodsModuleDto;
+import com.gis.cms.entity.po.GoodsModuleEntity;
+import com.gis.cms.service.GoodsModuleService;
+import com.gis.common.base.aop.WebControllerLog;
+import com.gis.common.util.Result;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import tk.mybatis.mapper.entity.Condition;
+
+import javax.validation.Valid;
+
+/**
+ * Created by owen on 2021/6/24 0008 9:54
+ */
+@Slf4j
+@Api(tags = "v0.2-精密典藏模块管理")
+@RestController
+@RequestMapping("cms/goodsModule")
+public class GoodsModuleController {
+
+    @Autowired
+    private GoodsModuleService entityService;
+
+
+
+    @ApiOperation("列表")
+    @PostMapping("list")
+    public Result<GoodsModuleEntity> search() {
+        Condition condition = new Condition(GoodsModuleEntity.class);
+        // 排序:默认模块>自定义模块还创建时间正序;
+        condition.orderBy("isDefault").desc().orderBy("createTime").asc();
+        return Result.success(entityService.findAll(condition));
+    }
+
+
+    @WebControllerLog(description = "模块管理-删除", addDb = true)
+    @ApiOperation("删除")
+    @GetMapping("remove/{id}")
+    public Result remove(@PathVariable Long id) {
+        return entityService.remove(id);
+    }
+
+    @ApiOperation("场景详情")
+    @GetMapping("detail/{id}")
+    public Result<GoodsModuleEntity> detail(@PathVariable Long id) {
+        return entityService.detail(id);
+    }
+
+    @WebControllerLog(description = "模块管理-新增/编辑", addDb = true)
+    @ApiOperation(value = "新增/修改", notes = "display, 0:不显示, 1:显示")
+    @PostMapping("save")
+    public Result saveEntity(@Valid @RequestBody GoodsModuleDto param) {
+        return entityService.saveEntity(param);
+    }
+
+
+
+}

+ 15 - 0
gis_cms/src/main/java/com/gis/cms/controller/QuestionGroupController.java

@@ -11,6 +11,7 @@ import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.validation.Valid;
 import java.util.List;
@@ -110,4 +111,18 @@ public class QuestionGroupController  {
     public Result updateDisplay(@PathVariable Long id, @PathVariable Integer display) {
         return entityService.updateDisplay(id, display);
     }
+
+    @WebControllerLog(description = "题组管理-批量导入Excel", addDb = true)
+    @ApiOperation(value = "v0.2批量导入Excel", notes = "excel格式后缀必须为xlsx")
+    @PostMapping("uploadExcel")
+    public Result uploadExcel(MultipartFile file) {
+        return entityService.uploadExcel(file);
+    }
+
+    @WebControllerLog(description = "题组管理-下载模板", addDb = true)
+    @ApiOperation(value = "v0.2下载模板", notes = "excel格式后缀必须为xlsx")
+    @GetMapping("downloadExcel")
+    public Result downloadExcel() {
+        return Result.success("/excel/template.xlsx");
+    }
 }

+ 6 - 7
gis_cms/src/main/java/com/gis/cms/controller/WebController.java

@@ -2,6 +2,7 @@ package com.gis.cms.controller;
 
 import com.gis.admin.entity.dto.PasswordDto;
 import com.gis.admin.entity.dto.ResetPasswordDto;
+import com.gis.cms.entity.dto.GoodsWebPageDto;
 import com.gis.cms.entity.dto.NewsPageDataDto;
 import com.gis.admin.entity.dto.RegisterDto;
 import com.gis.cms.entity.dto.StatusPageDataDto;
@@ -14,7 +15,7 @@ import com.gis.common.base.entity.dto.PageDto;
 import com.gis.common.base.service.LogService;
 import com.gis.common.util.Base64Converter;
 import com.gis.common.util.Result;
-import com.gis.cms.entity.dto.TypePageDateDto;
+import com.gis.cms.entity.dto.GoodsPageDateDto;
 import com.gis.admin.service.*;
 import com.gis.cms.entity.po.GoodsEntity;
 import com.gis.cms.entity.po.MartyrEntity;
@@ -104,17 +105,15 @@ public class WebController {
 
 
     @WebControllerLog(description = "门户网站-精品典藏列表(详情)")
-    @ApiOperation("精品典藏-列表")
+    @ApiOperation(value = "v0.2-精品典藏-列表",notes = "区分登陆")
     @PostMapping("goods/list")
-    public Result<GoodsEntity> goodsList(@RequestBody TypePageDateDto param){
-        // 3:审核通过
-        param.setStatus(3);
-        return goodsService.search(param, 1);
+    public Result<GoodsEntity> goodsList(@Valid @RequestBody GoodsWebPageDto param){
+        return goodsService.webList(param);
     }
 
 
     @WebControllerLog(description = "门户网站-精品典藏详情")
-    @ApiOperation("精品典藏-列表")
+    @ApiOperation("精品典藏-详情")
     @GetMapping("goods/detail/{id}")
     public Result<GoodsEntity> goodsDetail(@PathVariable Long id){
         goodsService.addVisit(id);

+ 32 - 5
gis_cms/src/main/java/com/gis/cms/controller/WebManageController.java

@@ -4,7 +4,7 @@ import com.gis.admin.entity.dto.UserDto;
 import com.gis.admin.entity.dto.UserWebDto;
 import com.gis.admin.entity.po.SysUserEntity;
 import com.gis.admin.service.SysUserService;
-import com.gis.cms.entity.dto.CountAnswerDto;
+import com.gis.cms.entity.dto.*;
 import com.gis.cms.entity.po.QuestionGroupEntity;
 import com.gis.cms.service.*;
 import com.gis.common.base.aop.WebControllerLog;
@@ -12,9 +12,6 @@ import com.gis.common.base.entity.dto.PageDateDto;
 import com.gis.common.constant.ConfigConstant;
 import com.gis.common.util.RedisUtil;
 import com.gis.common.util.Result;
-import com.gis.cms.entity.dto.CommentDto;
-import com.gis.cms.entity.dto.MournDto;
-import com.gis.cms.entity.dto.StatusPageDataDto;
 import com.gis.cms.entity.vo.CommentVo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
@@ -67,6 +64,9 @@ public class WebManageController {
     @Autowired
     ConfigConstant configConstant;
 
+    @Autowired
+    GoodsVoteService goodsVoteService;
+
 
 
 
@@ -137,7 +137,7 @@ public class WebManageController {
         return sysUserService.detail(id);
     }
 
-    @WebControllerLog(description = "用户管理-修改用户", addDb = true)
+    @WebControllerLog(description = "门户网站-修改用户", addDb = true)
     @ApiOperation("新增/修改用户信息")
     @PostMapping("save")
     public Result save(@Valid @RequestBody UserWebDto param) {
@@ -146,8 +146,35 @@ public class WebManageController {
         return sysUserService.saveEntity(userDto);
     }
 
+    @WebControllerLog(description = "门户网站-臧品投票", addDb = true)
+    @ApiOperation("v0.2-臧品投票")
+    @PostMapping("goods/vote")
+    public Result goodsVote(@Valid @RequestBody GoodsVoteDto param) {
+        return goodsVoteService.goodsVote(param);
+    }
 
 
+    @WebControllerLog(description = "门户网站-取消臧品投票", addDb = true)
+    @ApiOperation("v0.2-取消臧品投票")
+    @GetMapping("goods/vote/del/{goodsId}")
+    public Result goodsVoteDel(@PathVariable Long goodsId) {
+        return goodsVoteService.goodsVoteDel(goodsId);
+    }
+
+    @WebControllerLog(description = "门户网站-臧品点赞", addDb = true)
+    @ApiOperation("v0.2-臧品点赞")
+    @PostMapping("goods/like")
+    public Result goodsLike(@Valid @RequestBody GoodsVoteDto param) {
+        return goodsVoteService.goodsLike(param);
+    }
+
+    @WebControllerLog(description = "门户网站-取消臧品点赞", addDb = true)
+    @ApiOperation("v0.2-取消臧品点赞")
+    @GetMapping("goods/like/del/{goodsId}")
+    public Result goodsLikeDel(@PathVariable Long goodsId) {
+        return goodsVoteService.goodsVoteDelByType(goodsId, "like");
+    }
+
 
 
 }

+ 4 - 0
gis_cms/src/main/java/com/gis/cms/entity/dto/GoodsDto.java

@@ -50,6 +50,10 @@ public class GoodsDto {
     @ApiModelProperty(value = "封面图id")
     private Long indexId;
 
+    @NotNull(message = "模块id不能为空")
+    @ApiModelProperty(value = "模块id", required = true)
+    private Long goodsModuleId;
+
 
 
 

+ 43 - 0
gis_cms/src/main/java/com/gis/cms/entity/dto/GoodsModuleDto.java

@@ -0,0 +1,43 @@
+package com.gis.cms.entity.dto;
+
+import com.gis.common.base.entity.po.BaseEntity;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.persistence.Table;
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
+/**
+ * Created by owen on 2022/2/8 0010 17:39
+ * 精品典藏模块管理
+ */
+@Data
+@Table(name = "tb_goods_module")
+public class GoodsModuleDto  {
+
+    private Long id;
+
+    @NotBlank(message = "名称不能为空")
+    @ApiModelProperty(value = "名称", required = true)
+    private String name;
+
+    @NotBlank(message = "类型不能为空")
+    @ApiModelProperty(value = "类型, model:模型, img:图片, video:视频", required = true)
+    private String type;
+
+
+    @ApiModelProperty(value = "投票功能,0:关, 1:开")
+    private Integer isVote;
+
+    @ApiModelProperty(value = "投票数量,默认为1")
+    private Integer voteCount;
+
+    @ApiModelProperty(value = "点赞功能,0:关, 1:开")
+    private Integer isLike;
+
+
+
+
+
+}

+ 31 - 0
gis_cms/src/main/java/com/gis/cms/entity/dto/GoodsPageDateDto.java

@@ -0,0 +1,31 @@
+package com.gis.cms.entity.dto;
+
+import com.gis.common.base.entity.dto.PageDateDto;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
+/**
+ * Created by owen on 2020/5/9 0009 12:20
+ */
+@Data
+public class GoodsPageDateDto extends PageDateDto {
+
+    @ApiModelProperty(value = "状态")
+    private Integer status;
+
+    @NotNull(message = "模块id不能为空")
+    @ApiModelProperty(value = "模块id", required = true)
+    private Long goodsModuleId;
+
+    @NotBlank(message = "排序类型不能为空")
+    @ApiModelProperty(value = "排序类型, time:时间, vote:投票, like:点赞", required = true)
+    private String sortType;
+
+
+
+
+
+}

+ 21 - 0
gis_cms/src/main/java/com/gis/cms/entity/dto/GoodsVoteDto.java

@@ -0,0 +1,21 @@
+package com.gis.cms.entity.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * Created by owen on 2022/2/8 0008 16:10
+ */
+@Data
+public class GoodsVoteDto {
+
+    @NotNull(message = "模块id不能为空")
+    @ApiModelProperty(value = "模块id", required = true)
+    private Long goodsModuleId;
+
+    @NotNull(message = "模块id不能为空")
+    @ApiModelProperty(value = "臧品id", required = true)
+    private Long goodsId;
+}

+ 27 - 0
gis_cms/src/main/java/com/gis/cms/entity/dto/GoodsWebPageDto.java

@@ -0,0 +1,27 @@
+package com.gis.cms.entity.dto;
+
+import com.gis.common.base.entity.dto.PageDateDto;
+import com.gis.common.base.entity.dto.PageDto;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
+/**
+ * Created by owen on 2020/5/9 0009 12:20
+ */
+@Data
+public class GoodsWebPageDto extends PageDto {
+
+
+    @NotNull(message = "模块id不能为空")
+    @ApiModelProperty(value = "模块id", required = true)
+    private Long goodsModuleId;
+
+
+
+
+
+
+}

+ 24 - 0
gis_cms/src/main/java/com/gis/cms/entity/dto/TopicDto.java

@@ -0,0 +1,24 @@
+package com.gis.cms.entity.dto;
+
+import lombok.Data;
+
+import java.util.Map;
+
+/**
+ * Created by owen on 2022/2/8 0008 9:13
+ * 解析问题上传实体换行类
+ */
+@Data
+public class TopicDto {
+
+    // 题目
+    private String topic;
+
+    // 选项, 序号:选项
+    private Map<String, String> options;
+
+    // 正确答案序号
+    private String correct;
+
+
+}

+ 0 - 23
gis_cms/src/main/java/com/gis/cms/entity/dto/TypePageDateDto.java

@@ -1,23 +0,0 @@
-package com.gis.cms.entity.dto;
-
-import com.gis.common.base.entity.dto.PageDateDto;
-import io.swagger.annotations.ApiModelProperty;
-import lombok.Data;
-
-/**
- * Created by owen on 2020/5/9 0009 12:20
- */
-@Data
-public class TypePageDateDto extends PageDateDto {
-
-    @ApiModelProperty(value = "类型")
-    private String type;
-
-    @ApiModelProperty(value = "状态")
-    private Integer status;
-
-
-
-
-
-}

+ 22 - 0
gis_cms/src/main/java/com/gis/cms/entity/po/GoodsEntity.java

@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import javax.persistence.Table;
+import javax.persistence.Transient;
 
 /**
  * Created by owen on 2021/4/20 0010 17:39
@@ -53,4 +54,25 @@ public class GoodsEntity extends BaseEntity {
     @ApiModelProperty(value = "封面图id")
     private Long indexId;
 
+    @ApiModelProperty(value = "模块id")
+    private Long goodsModuleId;
+
+    @Transient
+    @ApiModelProperty(value = "投票,0:否,1:是")
+    private Integer isVote;
+
+    @Transient
+    @ApiModelProperty(value = "点赞,0:否,1:是")
+    private Integer isLike;
+
+    @Transient
+    @ApiModelProperty(value = "投票数")
+    private Integer countVote;
+
+    @Transient
+    @ApiModelProperty(value = "点赞数")
+    private Integer countLike;
+
+
+
 }

+ 41 - 0
gis_cms/src/main/java/com/gis/cms/entity/po/GoodsModuleEntity.java

@@ -0,0 +1,41 @@
+package com.gis.cms.entity.po;
+
+import com.gis.common.base.entity.po.BaseEntity;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.persistence.Table;
+import java.io.Serializable;
+
+/**
+ * Created by owen on 2022/2/8 0010 17:39
+ * 精品典藏模块管理
+ */
+@Data
+@Table(name = "tb_goods_module")
+public class GoodsModuleEntity extends BaseEntity implements Serializable {
+
+    private static final long serialVersionUID = 7751041761372618223L;
+    @ApiModelProperty(value = "名称" )
+    private String name;
+
+    @ApiModelProperty(value = "类型, model:模型, img:图片, video:视频")
+    private String type;
+
+    @ApiModelProperty(value = "投票功能,0:关, 1:开")
+    private Integer isVote;
+
+    @ApiModelProperty(value = "投票数量,默认为1")
+    private Integer voteCount;
+
+    @ApiModelProperty(value = "点赞功能,0:关, 1:开")
+    private Integer isLike;
+
+    @ApiModelProperty(value = "预设, 0:否, 1:是" )
+    private Integer isDefault;
+
+
+
+
+
+}

+ 33 - 0
gis_cms/src/main/java/com/gis/cms/entity/po/GoodsVoteEntity.java

@@ -0,0 +1,33 @@
+package com.gis.cms.entity.po;
+
+import com.gis.common.base.entity.po.BaseEntity;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.persistence.Table;
+import java.io.Serializable;
+
+/**
+ * Created by owen on 2021/4/20 0010 17:39
+ * 典藏-投票
+ */
+@Data
+@Table(name = "tb_goods_vote")
+public class GoodsVoteEntity extends BaseEntity implements Serializable {
+
+    private static final long serialVersionUID = -9153315542209052775L;
+    @ApiModelProperty(value = "用户id" )
+    private Long userId;
+
+    @ApiModelProperty(value = "模块id" )
+    private Long goodsModuleId;
+
+    @ApiModelProperty(value = "臧品id" )
+    private Long goodsId;
+
+    @ApiModelProperty(value = "类型: vote:投票, like:点赞" )
+    private String type;
+
+
+
+}

+ 9 - 2
gis_cms/src/main/java/com/gis/cms/mapper/GoodsMapper.java

@@ -2,9 +2,10 @@ package com.gis.cms.mapper;
 
 
 import com.gis.cms.entity.po.GoodsEntity;
+import com.gis.cms.mapper.provider.BaseProvider;
 import com.gis.cms.mapper.provider.GoodsProvider;
 import com.gis.common.base.mapper.IBaseMapper;
-import com.gis.cms.entity.dto.TypePageDateDto;
+import com.gis.cms.entity.dto.GoodsPageDateDto;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.SelectProvider;
 import org.apache.ibatis.annotations.Update;
@@ -19,8 +20,14 @@ public interface GoodsMapper extends IBaseMapper<GoodsEntity, Long> {
 
 
     @SelectProvider(type = GoodsProvider.class, method = "search")
-    List<GoodsEntity> search(TypePageDateDto param, Integer display);
+    List<GoodsEntity> search(GoodsPageDateDto param, Integer display);
 
     @Update("update tb_goods set visit = visit + 1 , update_time = NOW() where is_delete = 0  and id = #{id}")
     void addVisit(Long id);
+
+    @Update("update tb_goods set is_delete = 1 , update_time = NOW() where is_delete = 0  and goods_module_id = #{id}")
+    void delByGoodsModelId(Long goodsModelId);
+
+    @SelectProvider(type = BaseProvider.class, method = "selectSql")
+    List<GoodsEntity> selectSql(String sql);
 }

+ 18 - 0
gis_cms/src/main/java/com/gis/cms/mapper/GoodsModuleMapper.java

@@ -0,0 +1,18 @@
+package com.gis.cms.mapper;
+
+
+import com.gis.cms.entity.po.GoodsModuleEntity;
+import com.gis.common.base.mapper.IBaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import org.springframework.stereotype.Component;
+
+
+@Component
+@Mapper
+public interface GoodsModuleMapper extends IBaseMapper<GoodsModuleEntity, Long> {
+
+
+
+
+
+}

+ 25 - 0
gis_cms/src/main/java/com/gis/cms/mapper/GoodsVoteMapper.java

@@ -0,0 +1,25 @@
+package com.gis.cms.mapper;
+
+
+import com.gis.cms.entity.po.GoodsVoteEntity;
+import com.gis.cms.entity.po.NewsEntity;
+import com.gis.common.base.mapper.IBaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+@Component
+@Mapper
+public interface GoodsVoteMapper extends IBaseMapper<GoodsVoteEntity, Long> {
+
+
+    @Select("select id from tb_goods_vote where is_delete=0 and goods_module_id=${goodsModuleId} " +
+            "and user_id=${userId} and type=${type}")
+    List<String> findByGoodsModuleIdAndUserIdAndType(Long goodsModuleId, Long userId, String type);
+
+    @Update("update tb_goods_vote set is_delete=1 , update_time=NOW() where is_delete=0 and goods_id=#{goodsId} and type=${type}")
+    void delByGoodsIdAndType(Long goodsId, String type);
+}

+ 17 - 0
gis_cms/src/main/java/com/gis/cms/mapper/provider/BaseProvider.java

@@ -0,0 +1,17 @@
+package com.gis.cms.mapper.provider;
+
+
+
+/**
+ * Created by owen on 2022/2/9.
+ */
+public class BaseProvider {
+
+    public String selectSql(String sql){
+
+        return sql;
+    }
+
+
+
+}

+ 10 - 5
gis_cms/src/main/java/com/gis/cms/mapper/provider/GoodsProvider.java

@@ -1,6 +1,6 @@
 package com.gis.cms.mapper.provider;
 
-import com.gis.cms.entity.dto.TypePageDateDto;
+import com.gis.cms.entity.dto.GoodsPageDateDto;
 import lombok.extern.log4j.Log4j2;
 import org.apache.commons.lang3.StringUtils;
 
@@ -12,7 +12,7 @@ import org.apache.commons.lang3.StringUtils;
 public class GoodsProvider {
 
 
-    public String search(TypePageDateDto param, Integer display) {
+    public String search(GoodsPageDateDto param, Integer display) {
         StringBuffer sql = new StringBuffer(
                 "select * from tb_goods where is_delete = '0' ");
 
@@ -32,9 +32,14 @@ public class GoodsProvider {
             sql.append(" and  display = ").append(display);
         }
 
-        String type = param.getType();
-        if (StringUtils.isNotBlank(type)) {
-            sql.append(" and  type = '").append(type).append("'");
+//        String type = param.getType();
+//        if (StringUtils.isNotBlank(type)) {
+//            sql.append(" and  type = '").append(type).append("'");
+//        }
+
+        Long goodsModuleId = param.getGoodsModuleId();
+        if (goodsModuleId != null){
+            sql.append(" and goods_module_id = ").append(goodsModuleId);
         }
 
         Integer status = param.getStatus();

+ 29 - 0
gis_cms/src/main/java/com/gis/cms/service/GoodsModuleService.java

@@ -0,0 +1,29 @@
+package com.gis.cms.service;
+
+
+import com.gis.cms.entity.dto.GoodsModuleDto;
+import com.gis.cms.entity.po.GoodsModuleEntity;
+import com.gis.common.base.service.IBaseService;
+import com.gis.common.util.Result;
+
+
+/**
+ * Created by owen on 2020/3/11 0011 16:14
+ */
+public interface GoodsModuleService extends IBaseService<GoodsModuleEntity, Long> {
+
+
+
+    Result saveEntity(GoodsModuleDto param);
+
+    Result detail(Long id);
+
+    Result remove(Long id);
+
+
+
+
+
+
+
+}

+ 7 - 2
gis_cms/src/main/java/com/gis/cms/service/GoodsService.java

@@ -3,7 +3,8 @@ package com.gis.cms.service;
 
 import com.gis.cms.entity.dto.AuditDto;
 import com.gis.cms.entity.dto.GoodsDto;
-import com.gis.cms.entity.dto.TypePageDateDto;
+import com.gis.cms.entity.dto.GoodsPageDateDto;
+import com.gis.cms.entity.dto.GoodsWebPageDto;
 import com.gis.cms.entity.po.GoodsEntity;
 import com.gis.common.base.service.IBaseService;
 import com.gis.common.util.Result;
@@ -16,7 +17,7 @@ import org.springframework.web.multipart.MultipartFile;
 public interface GoodsService extends IBaseService<GoodsEntity, Long> {
 
 
-    Result<GoodsEntity> search(TypePageDateDto param, Integer display);
+    Result<GoodsEntity> search(GoodsPageDateDto param, Integer display);
 
     Result saveEntity(GoodsDto param);
 
@@ -41,4 +42,8 @@ public interface GoodsService extends IBaseService<GoodsEntity, Long> {
     Result display(Long id, Integer display);
 
     void addVisit(Long id);
+
+    void delByGoodsModelId(Long id);
+
+    Result<GoodsEntity> webList(GoodsWebPageDto param);
 }

+ 28 - 0
gis_cms/src/main/java/com/gis/cms/service/GoodsVoteService.java

@@ -0,0 +1,28 @@
+package com.gis.cms.service;
+
+
+import com.gis.cms.entity.dto.GoodsVoteDto;
+import com.gis.cms.entity.po.GoodsVoteEntity;
+import com.gis.common.base.service.IBaseService;
+import com.gis.common.util.Result;
+
+
+/**
+ * Created by owen on 2020/3/11 0011 16:14
+ */
+public interface GoodsVoteService extends IBaseService<GoodsVoteEntity, Long> {
+
+
+    Result saveEntity(GoodsVoteDto param);
+
+    Result remove(Long id);
+
+
+    Result goodsVote(GoodsVoteDto param);
+
+    Result goodsVoteDel(Long goodsId);
+
+    Result goodsLike(GoodsVoteDto param);
+
+    Result goodsVoteDelByType(Long goodsId, String type);
+}

+ 3 - 0
gis_cms/src/main/java/com/gis/cms/service/QuestionGroupService.java

@@ -7,6 +7,7 @@ import com.gis.cms.entity.dto.StatusPageDataDto;
 import com.gis.cms.entity.po.QuestionGroupEntity;
 import com.gis.common.base.service.IBaseService;
 import com.gis.common.util.Result;
+import org.springframework.web.multipart.MultipartFile;
 
 
 /**
@@ -30,4 +31,6 @@ public interface QuestionGroupService extends IBaseService<QuestionGroupEntity,
     Result auditDetail(Long id);
 
     Result updateDisplay(Long id, Integer display);
+
+    Result uploadExcel(MultipartFile file);
 }

+ 117 - 0
gis_cms/src/main/java/com/gis/cms/service/impl/GoodsModuleServiceImpl.java

@@ -0,0 +1,117 @@
+package com.gis.cms.service.impl;
+
+import com.gis.cms.entity.dto.GoodsModuleDto;
+import com.gis.cms.entity.po.GoodsModuleEntity;
+import com.gis.cms.mapper.GoodsModuleMapper;
+import com.gis.cms.service.AuditLogService;
+import com.gis.cms.service.FileService;
+import com.gis.cms.service.GoodsModuleService;
+import com.gis.cms.service.GoodsService;
+import com.gis.common.base.mapper.IBaseMapper;
+import com.gis.common.base.service.impl.IBaseServiceImpl;
+import com.gis.common.constant.MsgCode;
+import com.gis.common.util.Result;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDateTime;
+
+
+/**
+ * Created by owen on 2020/3/11 0011 16:16
+ */
+@Slf4j
+@Service
+public class GoodsModuleServiceImpl extends IBaseServiceImpl<GoodsModuleEntity, Long> implements GoodsModuleService {
+
+    @Autowired
+    private GoodsModuleMapper entityMapper;
+
+    @Autowired
+    GoodsService goodsService;
+
+
+
+
+
+
+
+    @Override
+    public IBaseMapper<GoodsModuleEntity, Long> getBaseMapper() {
+        return this.entityMapper;
+    }
+
+
+
+
+    @Override
+    public Result saveEntity(GoodsModuleDto param) {
+        Long id = param.getId();
+        GoodsModuleEntity entity = null;
+        if (id == null) {
+            entity = new GoodsModuleEntity();
+            BeanUtils.copyProperties(param, entity);
+            this.save(entity);
+        } else {
+            entity = this.findById(id);
+            if (entity == null) {
+                return Result.failure("对象不存在: " + id);
+            }
+            BeanUtils.copyProperties(param, entity);
+            entity.setUpdateTime(LocalDateTime.now());
+            this.update(entity);
+        }
+
+
+        return Result.success(entity);
+    }
+
+
+    @Override
+    public Result remove(Long id) {
+        GoodsModuleEntity entity = this.findById(id);
+        if (entity == null) {
+            return Result.success();
+        }
+
+        if (entity.getIsDefault() == 1){
+            return Result.failure("预设模块不允许删除");
+        }
+
+        entity.setIsDelete(1);
+        entity.setUpdateTime(LocalDateTime.now());
+        this.update(entity);
+
+        // 删除该模块下数据
+        goodsService.delByGoodsModelId(id);
+        log.info("该模块关联数据已删除 : {}", id);
+
+        return Result.success();
+    }
+
+
+
+
+
+
+
+
+    @Override
+    public Result detail(Long id) {
+        GoodsModuleEntity entity = this.findById(id);
+        if (entity == null) {
+            return Result.failure(MsgCode.e3001,"对象不存在,id: " + id);
+        }
+        return Result.success(entity);
+    }
+
+
+
+
+
+
+
+
+}

+ 111 - 26
gis_cms/src/main/java/com/gis/cms/service/impl/GoodsServiceImpl.java

@@ -4,9 +4,9 @@ import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.io.FileUtil;
 import com.gis.cms.entity.dto.AuditDto;
 import com.gis.cms.entity.dto.GoodsDto;
-import com.gis.cms.entity.dto.TypePageDateDto;
+import com.gis.cms.entity.dto.GoodsPageDateDto;
+import com.gis.cms.entity.dto.GoodsWebPageDto;
 import com.gis.cms.entity.po.AuditLogEntity;
-import com.gis.cms.entity.po.CommentEntity;
 import com.gis.cms.entity.po.FileEntity;
 import com.gis.cms.entity.po.GoodsEntity;
 import com.gis.cms.mapper.GoodsMapper;
@@ -28,8 +28,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
 import java.time.LocalDateTime;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -47,9 +45,6 @@ public class GoodsServiceImpl extends IBaseServiceImpl<GoodsEntity, Long> implem
     @Autowired
     private GoodsMapper entityMapper;
 
-    @Resource
-    HttpServletRequest request;
-
     @Autowired
     FileService fileService;
 
@@ -65,9 +60,108 @@ public class GoodsServiceImpl extends IBaseServiceImpl<GoodsEntity, Long> implem
 
 
     @Override
-    public Result<GoodsEntity> search(TypePageDateDto param, Integer display) {
+    public Result<GoodsEntity> search(GoodsPageDateDto param, Integer display) {
+        startPage(param);
+
+        StringBuffer sql = new StringBuffer();
+        // 使用了子查询
+        sql.append("select a.*, b.countLike as countLike, b.countVote as countVote from tb_goods a left join " +
+                "(select g.id,sum(case v.type when 'like' then 1 else 0 end )countLike, " +
+                    "sum(case v.type when 'vote' then 1 else 0 end )countVote " +
+                    "from tb_goods g left join tb_goods_vote v on g.id=v.goods_id where g.is_delete=0 and v.is_delete=0 ) b " +
+                "on a.id=b.id where a.is_delete=0");
+
+        if (display != null){
+            sql.append(" and a.display=").append(display);
+        }
+
+        Long goodsModuleId = param.getGoodsModuleId();
+        if (goodsModuleId != null){
+            sql.append(" and a.goods_module_id=").append(goodsModuleId);
+        }
+
+        Integer status = param.getStatus();
+        if (status != null){
+            sql.append(" and a.status=").append(status);
+        }
+
+        if (StringUtils.isNotBlank(param.getStartTime()) && StringUtils.isNotBlank(param.getEndTime())) {
+
+            sql.append(" and a.create_time >= ").append("'").append(param.getStartTime()).append("'");
+            sql.append(" and a.create_time <= ").append("'").append(param.getEndTime()).append("'");
+        }
+
+
+        String searchKey = param.getSearchKey();
+        if (StringUtils.isNotBlank(searchKey)){
+            searchKey = RegexUtil.sqlReplaceSpecialStr(searchKey);
+            sql.append(" and a.name like '%").append(searchKey).append("%'");
+        }
+
+        String sortType = param.getSortType();
+        if (StringUtils.isNotBlank(sortType)){
+
+            if ("vote".equals(sortType)){
+                sql.append(" order by b.countVote desc");
+            } else if ("like".equals(sortType)){
+                sql.append(" order by b.countLike desc");
+            } else {
+                sql.append(" order by a.create_time desc");
+            }
+        } else {
+            sql.append(" order by a.create_time desc");
+
+        }
+
+
+        log.info("sql: {}", sql.toString());
+
+        PageInfo<GoodsEntity> pageInfo = new PageInfo<>(entityMapper.selectSql(sql.toString()));
+
+        return Result.success(pageInfo);
+    }
+
+    /**
+     * 展示端,区分登录
+     * @param param
+     * @return
+     */
+    @Override
+    public Result<GoodsEntity> webList(GoodsWebPageDto param) {
+
         startPage(param);
-        return Result.success(new PageInfo<>(entityMapper.search(param, display)));
+
+        StringBuffer sql = new StringBuffer();
+        // 判断是否登录
+        if (getTokenUserId() != null){  // 登录, 返回是否点赞、投票
+            // 使用了子查询
+            sql.append("select a.*, if(b.countLike > 0, 1, 0) isLike, if(b.countVote > 0, 1, 0) isVote from tb_goods a left join " +
+                    "(select g.id,sum(case when v.type='like' and v.is_delete=0 and v.user_id=" + getTokenUserId() +" then 1 else 0 end )countLike, " +
+                    "sum(case when v.type='vote' and v.is_delete=0  and v.user_id=" + getTokenUserId() +" then 1 else 0 end )countVote " +
+                    "from tb_goods g left join tb_goods_vote v on g.id=v.goods_id where g.is_delete=0 and v.is_delete=0 ) b " +
+                    "on a.id=b.id where a.is_delete=0");
+        } else { // 非登录
+            sql.append("select a.* from tb_goods a where a.is_delete=0");
+        }
+
+        sql.append(" and a.display=1 and a.status=3");
+
+        String searchKey = param.getSearchKey();
+        if (StringUtils.isNotBlank(searchKey)){
+            searchKey = RegexUtil.sqlReplaceSpecialStr(searchKey);
+            sql.append(" and a.name like '%").append(searchKey).append("%'");
+        }
+
+
+        sql.append(" order by a.create_time desc");
+
+
+
+        log.info("sql: {}", sql.toString());
+
+        PageInfo<GoodsEntity> pageInfo = new PageInfo<>(entityMapper.selectSql(sql.toString()));
+
+        return Result.success(pageInfo);
     }
 
     @Override
@@ -105,23 +199,7 @@ public class GoodsServiceImpl extends IBaseServiceImpl<GoodsEntity, Long> implem
         return Result.success(entity);
     }
 
-//    /**
-//     * 设置首张图片
-//     * @param fileIds 文件id
-//     * @param moduleId 模块id
-//     */
-//    private void setIndex(String fileIds, Long moduleId){
-//        List<FileEntity> entities = fileService.findIndexByModule(moduleId, TypeCode.MODULE_GOODS);
-//        if (entities.size() == 0) {
-//            // 初始页面不存在,设置第一张为初始页面
-//            String[] split = fileIds.split(",");
-//            Long indexId = Long.valueOf(split[0]);
-//            fileService.indexEnabled(indexId);
-//            // 设置缩略图
-//            FileEntity fileEntity = fileService.findById(indexId);
-//            setThumbByIndex(moduleId, fileEntity.getFilePath());
-//        }
-//    }
+
 
     @Override
     public Result remove(Long id) {
@@ -275,6 +353,13 @@ public class GoodsServiceImpl extends IBaseServiceImpl<GoodsEntity, Long> implem
 
     }
 
+    @Override
+    public void delByGoodsModelId(Long goodsModelId) {
+        entityMapper.delByGoodsModelId(goodsModelId);
+    }
+
+
+
     private void updateStatus(Long id, Integer status){
         GoodsEntity entity = this.findById(id);
         if (entity == null) {

+ 115 - 0
gis_cms/src/main/java/com/gis/cms/service/impl/GoodsVoteServiceImpl.java

@@ -0,0 +1,115 @@
+package com.gis.cms.service.impl;
+
+import com.gis.cms.entity.dto.GoodsVoteDto;
+import com.gis.cms.entity.po.GoodsModuleEntity;
+import com.gis.cms.entity.po.GoodsVoteEntity;
+import com.gis.cms.mapper.GoodsVoteMapper;
+import com.gis.cms.service.AuditLogService;
+import com.gis.cms.service.FileService;
+import com.gis.cms.service.GoodsModuleService;
+import com.gis.cms.service.GoodsVoteService;
+import com.gis.common.base.mapper.IBaseMapper;
+import com.gis.common.base.service.impl.IBaseServiceImpl;
+import com.gis.common.util.Result;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDateTime;
+import java.util.List;
+
+
+/**
+ * Created by owen on 2022/2/8 0011 16:16
+ */
+@Slf4j
+@Service
+public class GoodsVoteServiceImpl extends IBaseServiceImpl<GoodsVoteEntity, Long> implements GoodsVoteService {
+
+    @Autowired
+    GoodsVoteMapper entityMapper;
+
+    @Autowired
+    GoodsModuleService goodsModuleService;
+
+    static String TYPE_VOTE = "vote";
+
+    static String TYPE_LIKE = "like";
+
+    @Override
+    public IBaseMapper<GoodsVoteEntity, Long> getBaseMapper() {
+        return this.entityMapper;
+    }
+
+    @Override
+    public Result saveEntity(GoodsVoteDto param) {
+        GoodsVoteEntity entity =  new GoodsVoteEntity();
+            BeanUtils.copyProperties(param, entity);
+            entity.setUserId(getTokenUserId());
+            this.save(entity);
+
+        return Result.success();
+    }
+
+    @Override
+    public Result remove(Long id) {
+        GoodsVoteEntity entity = this.findById(id);
+        if (entity == null) {
+            return Result.success();
+        }
+        // db数据软删除, 物理数据真删除
+        entity.setIsDelete(1);
+        entity.setUpdateTime(LocalDateTime.now());
+        this.update(entity);
+        return  Result.success();
+    }
+
+    @Override
+    public Result goodsVote(GoodsVoteDto param) {
+
+        // 每个用户每个板块能投的票数,按后台设置
+        Long goodsModuleId = param.getGoodsModuleId();
+
+        List<String> voteByUser = entityMapper.findByGoodsModuleIdAndUserIdAndType(goodsModuleId, getTokenUserId(), TYPE_VOTE);
+        GoodsModuleEntity moduleEntity = goodsModuleService.findById(goodsModuleId);
+        if (voteByUser.size() >= moduleEntity.getVoteCount()){
+            return Result.failure("已达到投票上限");
+        }
+
+        // 保存投票
+        GoodsVoteEntity entity =  new GoodsVoteEntity();
+        BeanUtils.copyProperties(param, entity);
+        entity.setUserId(getTokenUserId());
+        entity.setType(TYPE_VOTE);
+        this.save(entity);
+
+        return Result.success();
+    }
+
+    @Override
+    public Result goodsVoteDel(Long goodsId) {
+        entityMapper.delByGoodsIdAndType(goodsId, TYPE_VOTE);
+        return Result.success();
+    }
+
+    @Override
+    public Result goodsLike(GoodsVoteDto param) {
+
+        // 保存点赞
+        GoodsVoteEntity entity =  new GoodsVoteEntity();
+        BeanUtils.copyProperties(param, entity);
+        entity.setUserId(getTokenUserId());
+        entity.setType(TYPE_LIKE);
+        this.save(entity);
+        return Result.success();
+    }
+
+    @Override
+    public Result goodsVoteDelByType(Long goodsId, String type) {
+        entityMapper.delByGoodsIdAndType(goodsId, type);
+        return Result.success();
+    }
+
+
+}

+ 138 - 0
gis_cms/src/main/java/com/gis/cms/service/impl/QuestionGroupServiceImpl.java

@@ -1,8 +1,14 @@
 package com.gis.cms.service.impl;
 
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.gis.cms.entity.dto.AuditDto;
 import com.gis.cms.entity.dto.QuestionGroupDto;
 import com.gis.cms.entity.dto.StatusPageDataDto;
+import com.gis.cms.entity.dto.TopicDto;
 import com.gis.cms.entity.po.AuditLogEntity;
 import com.gis.cms.entity.po.GoodsEntity;
 import com.gis.cms.entity.po.QuestionAnswerEntity;
@@ -16,6 +22,7 @@ import com.gis.common.base.mapper.IBaseMapper;
 import com.gis.common.base.service.impl.IBaseServiceImpl;
 import com.gis.common.constant.MsgCode;
 import com.gis.common.constant.TypeCode;
+import com.gis.common.util.ExcelUtils;
 import com.gis.common.util.Result;
 import com.gis.cms.service.FileService;
 import com.github.pagehelper.PageInfo;
@@ -23,6 +30,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
 import tk.mybatis.mapper.entity.Condition;
 
 import javax.annotation.Resource;
@@ -31,6 +39,7 @@ import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 
@@ -159,6 +168,135 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
         return Result.success(entity);
     }
 
+    @Override
+    public Result uploadExcel(MultipartFile file) {
+        // 保存文件
+        Map<String, Object> uploadMap = fileUtils.uploadMap(file, "/excel", false);
+        parseExcel(uploadMap.get("filePath").toString());
+
+        return Result.success();
+    }
+
+    /**
+     * 解决excel数据并保存数据库
+     * @param filePath 相对路径
+     * @return
+     */
+    private void parseExcel(String filePath){
+        // 读取excel数据
+        String excelPath = configConstant.serverBasePath + filePath;
+        List<List<Object>> read = ExcelUtils.readExcel(excelPath);
+
+        // 解析excel数据
+
+        // 题组标题
+        List<Object> group = read.get(1);
+        String groupTitle = group.get(1).toString();
+        if (StrUtil.isBlank(groupTitle)){
+            throw new BaseRuntimeException("题组名称不能为空");
+        }
+        log.info("题组名称:{}", groupTitle );
+
+        // 重第三行读取,直接读取题目跟选项
+        HashMap<String, TopicDto> topicMap = new HashMap<>();
+        String topic = null;
+        for (int i = 2; i < read.size(); i++) {
+            List<Object> list = read.get(i);
+            String tips = (String)list.get(0);
+            if (StrUtil.isBlank(tips)){
+                log.warn("提示行为空,默认为结束行");
+                break;
+            }
+            // 题目
+            if (tips.contains("题目")){
+                topic = (String)list.get(1);
+                // 题目为空,结束循环
+                if (StrUtil.isBlank(topic)){
+                    log.warn(tips + ": 为空,结束循环");
+                    break;
+                }
+
+                // 保存题目
+                TopicDto topicDto = new TopicDto();
+                topicDto.setTopic(topic);
+                topicMap.put(topic, topicDto);
+            }
+
+            // 选项
+            if (tips.contains("选项")){
+                String option = (String)list.get(1);
+                if (StrUtil.isBlank(option)){
+                    // 选项为空, 执行下一次循环
+                    continue;
+                }
+                TopicDto topicDto = topicMap.get(topic);
+                String random = RandomUtil.randomString(8);
+
+                // 正确答案
+                String correct = (String)list.get(2);
+                if (StrUtil.isNotBlank(correct)){
+                    topicDto.setCorrect(random);
+                }
+
+                Map<String, String> options = topicDto.getOptions();
+                if (CollectionUtil.isEmpty(options)){
+                    options = new HashMap<>();
+                }
+                options.put(random, option);
+
+                topicDto.setOptions(options);
+                // 设置题目到题组
+                topicMap.put(topic, topicDto);
+
+            }
+        }
+
+        log.info("excel数据封装完成");
+        // 题组保存数据库
+        QuestionGroupEntity groupEntity = new QuestionGroupEntity();
+        groupEntity.setName(groupTitle);
+        groupEntity.setUserName(getTokenUserName());
+        this.save(groupEntity);
+        Long groupEntityId = groupEntity.getId();
+        log.info("保存题组完成, 题组id: {}", groupEntityId);
+
+        // 题目保存数据库
+        for(Map.Entry<String, TopicDto> entry : topicMap.entrySet()){
+            TopicDto value = entry.getValue();
+            QuestionAnswerEntity answerEntity = new QuestionAnswerEntity();
+            answerEntity.setQuestionGroupId(groupEntityId);
+            answerEntity.setQuestion(value.getTopic());
+            answerEntity.setCorrect(value.getCorrect());
+            answerEntity.setAnswer(parseAnswer(value.getOptions()));
+
+            questionAnswerService.save(answerEntity);
+        }
+        log.info("保存题目完成");
+
+
+
+
+    }
+
+    /**
+     * 解析选项
+     * @param options
+     * @return
+     */
+    private String parseAnswer(Map<String, String> options){
+        JSONArray array = new JSONArray();
+        for(Map.Entry<String, String> entry : options.entrySet()){
+            String key = entry.getKey();
+            String value = entry.getValue();
+            JSONObject obj = new JSONObject();
+            obj.put("val", key);
+            obj.put("name", value);
+            array.add(obj);
+        }
+        return JSONObject.toJSONString(array);
+
+    }
+
 
     private void updateStatus(Long id, Integer status){
         QuestionGroupEntity entity = this.findById(id);

+ 7 - 0
gis_common/pom.xml

@@ -84,6 +84,13 @@
             <artifactId>hutool-all</artifactId>
         </dependency>
 
+        <!--excel 依赖工具包, hutool需要用的-->
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-ooxml</artifactId>
+        </dependency>
+
+
         <dependency>
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-lang3</artifactId>

+ 1 - 0
gis_common/src/main/java/com/gis/common/base/exception/BaseRuntimeException.java

@@ -8,6 +8,7 @@ public class BaseRuntimeException extends RuntimeException{
 
     public BaseRuntimeException(String msg){
         super(msg);
+        this.code = -1;
         this.msg = msg;
     }
 

+ 141 - 0
gis_common/src/main/java/com/gis/common/util/ExcelUtils.java

@@ -0,0 +1,141 @@
+package com.gis.common.util;
+
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.poi.excel.ExcelReader;
+import cn.hutool.poi.excel.ExcelUtil;
+import cn.hutool.poi.excel.ExcelWriter;
+import com.gis.common.base.exception.BaseRuntimeException;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by owen on 2022/2/8 0008 15:50
+ */
+@Slf4j
+public class ExcelUtils {
+
+    /**
+     * 写
+     * @param rows 每行数据
+     * @param savePath 保存地址 xxx.xlsx
+     * @param rowTitle 标题
+     */
+    public static void createExcel(List rows, String savePath, Map<String, String> rowTitle) {
+        log.info("rows size: {}", rows.size());
+//        log.info("savePath: {}", savePath);
+        ExcelWriter writer = ExcelUtil.getWriter(savePath);
+
+        //自定义标题别名
+        if (rowTitle != null) {
+            for (Map.Entry<String, String> a : rowTitle.entrySet()) {
+                writer.addHeaderAlias(a.getKey(), a.getValue());
+            }
+        }
+
+        // 一次性写出内容,使用默认样式,强制输出标题
+        writer.write(rows, true);
+        // 关闭writer,释放内存
+        writer.close();
+        log.info("excel完成:" +  savePath);
+
+    }
+
+
+    /**
+     * 读
+     */
+    public static List<List<Object>> readExcel(String filePath) {
+        log.info("文件地址: {}", filePath);
+        if (!filePath.endsWith(".xlsx")){
+            throw new BaseRuntimeException("非法文件");
+        }
+        // 默认读第一个sheet
+        ExcelReader reader = ExcelUtil.getReader(filePath);
+        // 读取Excel中所有行和列,都用列表表示
+        List<List<Object>> read = reader.read();
+
+        log.info("读取excel完成" );
+        return read;
+
+    }
+
+//    @Test
+//    public void readExcelTest(){
+//        String filePath = "E:\\data\\museum_dali_data\\test.xlsx";
+//        List<List<Object>> read = readExcel(filePath);
+//
+//        // 题组标题
+//        List<Object> group = read.get(1);
+//        String groupTitle = group.get(1).toString();
+//        if (StrUtil.isBlank(groupTitle)){
+//            throw new BaseRuntimeException("题组名称不能为空");
+//        }
+//        log.info("题组名称:{}", groupTitle );
+//        // 重第三行读取,直接读取题目跟选项
+//
+//        HashMap<String, TopicDto> topicMap = new HashMap<>();
+//        String topic = null;
+//        for (int i = 2; i < read.size(); i++) {
+//            List<Object> list = read.get(i);
+//            String tips = (String)list.get(0);
+//            if (StrUtil.isBlank(tips)){
+//                log.warn("提示行为空,默认为结束行");
+//                break;
+//            }
+//            // 题目
+//            if (tips.contains("题目")){
+//                topic = (String)list.get(1);
+//                // 题目为空,结束循环
+//                if (StrUtil.isBlank(topic)){
+//                    log.warn(tips + ": 为空");
+//                    break;
+//                }
+//
+//                // 保存题目
+//                TopicDto topicDto = new TopicDto();
+//                topicDto.setTopic(topic);
+//                topicMap.put(topic, topicDto);
+//            }
+//
+//            // 选项
+//            if (tips.contains("选项")){
+//                String option = (String)list.get(1);
+//                if (StrUtil.isBlank(option)){
+//                    // 选项为空, 执行下一次循环
+//                    continue;
+//                }
+//                TopicDto topicDto = topicMap.get(topic);
+//                String random = RandomUtil.randomString(8);
+//
+//                // 正确答案
+//                String correct = (String)list.get(2);
+//                if (StrUtil.isNotBlank(correct)){
+//                    topicDto.setCorrect(random);
+//                }
+//
+//                Map<String, String> options = topicDto.getOptions();
+//                if (CollectionUtil.isEmpty(options)){
+//                    options = new HashMap<>();
+//                }
+//                options.put(random, option);
+//
+//                topicDto.setOptions(options);
+//                // 设置题目到题组
+//                topicMap.put(topic, topicDto);
+//
+//            }
+//
+//
+//
+//        }
+//
+//        log.info("excel数据封装完成");
+//
+//    }
+}

+ 80 - 1
gis_common/src/main/java/com/gis/common/util/FileUtils.java

@@ -1,11 +1,19 @@
 package com.gis.common.util;
 
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.io.FileUtil;
+import com.gis.common.base.exception.BaseRuntimeException;
 import com.gis.common.constant.ConfigConstant;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.time.LocalDateTime;
+import java.util.HashMap;
+import java.util.Map;
+
 
 /**
  * Created by owen on 2020/5/12 0012 17:21
@@ -33,8 +41,79 @@ public class FileUtils {
             log.info("无非法参数可以放行!!!");
             return true;
         }
-        log.info("存在非法参数不能放行!请核对上传文件格式,重新刷新页面再次上传!");
+        log.warn("存在非法参数不能放行!请核对上传文件格式,重新刷新页面再次上传!, {}", suffix);
         return false;
     }
 
+    /**
+     * 真删除文件
+     * @param path 参数是相对地址
+     */
+    public void del(String path){
+        if (StringUtils.isNotBlank(path)){
+            String delPath = configConstant.serverBasePath + path;
+            FileUtil.del(delPath);
+            log.info("真删除文件: {}", delPath);
+        }
+
+    }
+
+    /**
+     *
+     * @param file
+     * @param isPinYinRename false:时间戳重命名, true:用拼音重名文件
+     * @param savePath 保存地址(前面有斜杠, 后面没有),没有文件名
+     * @return map
+     */
+    public Map<String, Object> uploadMap(MultipartFile file, String savePath, boolean isPinYinRename) {
+        String newName = this.upload(file, savePath, isPinYinRename);
+        HashMap<String, Object> result = new HashMap<>();
+        result.put("fileName", file.getOriginalFilename());
+        result.put("filePath", savePath + "/" + newName);
+//        result.put("newName", newName);
+        return result;
+
+    }
+
+    /**
+     *
+     * @param file
+     * @param isPinYinRename false:时间戳重命名, true:用拼音重名文件
+     * @param savePath 保存地址(前面有斜杠, 后面没有),没有文件名
+     * @return 文件名
+     */
+    public String upload(MultipartFile file, String savePath, boolean isPinYinRename) {
+
+        // 检查非法文件上传
+        boolean checkFile = this.checkFile(file);
+        if (!checkFile) {
+//            throw new BaseRuntimeException(3009, "上传文件格式有误, 请重新上传");
+            throw new BaseRuntimeException("上传文件格式有误, 请重新上传");
+        }
+
+
+        // 文件目录
+        String fileName = file.getOriginalFilename();
+        String newName;
+        if (isPinYinRename){
+            newName = RegexUtil.getPinyinName(fileName);
+        } else {
+            String suffix = StringUtils.substringAfterLast(fileName, ".");
+            newName = DateUtil.format(LocalDateTime.now(), "yyyyMMdd_HHmmssSSS") + "." + suffix;
+        }
+
+        savePath = configConstant.serverBasePath + savePath + "/" + newName;
+        log.info("保存文件地址:{}", savePath);
+
+        try {
+            FileUtil.writeFromStream(file.getInputStream(), savePath);
+
+            return newName;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+
 }

+ 19 - 1
gis_common/src/main/java/com/gis/common/util/RegexUtil.java

@@ -4,7 +4,9 @@ import cn.hutool.extra.pinyin.PinyinUtil;
 import org.apache.commons.lang3.StringUtils;
 
 public class RegexUtil {
-    //specific symbol
+
+    // 需要过滤的特殊字符
+    static String [] specialSql = {"%","or","=","and"};
 
     /** 处理特殊符号,变空值*/
     public static String specificSymbol(String str){
@@ -26,6 +28,22 @@ public class RegexUtil {
     }
 
 
+    /**
+     * sql 过滤特殊字符
+     * @param str
+     * @return
+     */
+    public static String sqlReplaceSpecialStr(String str){
+        str = StringUtils.trim(str);
+        str = str.toLowerCase();
+        for (String s : specialSql) {
+            if (str.contains(s)) {
+                str = str.replaceAll(s, "");
+            }
+        }
+        return str;
+    }
+
 
 
 

+ 11 - 0
pom.xml

@@ -34,6 +34,7 @@
     <gis.version>1.0.0</gis.version>
     <druid.version>1.1.14</druid.version>
     <hutool.version>5.3.3</hutool.version>
+    <poi.version>3.17</poi.version>
     <lombok.version>1.18.2</lombok.version>
     <fastjson.version>1.2.75</fastjson.version>
     <lang3.version>3.7</lang3.version>
@@ -167,6 +168,16 @@
         <version>${hutool.version}</version>
       </dependency>
 
+      <!--excel 依赖工具包, hutool需要用的-->
+      <dependency>
+        <groupId>org.apache.poi</groupId>
+        <artifactId>poi-ooxml</artifactId>
+        <version>${poi.version}</version>
+      </dependency>
+
+
+
+
       <!-- StringUtils -->
       <dependency>
         <groupId>org.apache.commons</groupId>