|
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.gis.cms.entity.dto.GoodsDto;
|
|
|
import com.gis.cms.entity.dto.GoodsPageDateDto;
|
|
|
+import com.gis.cms.entity.dto.GoodsSortDto;
|
|
|
import com.gis.cms.entity.po.FileEntity;
|
|
|
import com.gis.cms.entity.po.GoodsEntity;
|
|
|
import com.gis.cms.entity.vo.SearchVo;
|
|
@@ -29,6 +30,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.validation.constraints.NotBlank;
|
|
|
+import javax.validation.constraints.NotNull;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
@@ -257,6 +260,38 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, GoodsEntity> impl
|
|
|
return Result.success(entity);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Result sort(GoodsSortDto param) {
|
|
|
+ Long id = param.getId();
|
|
|
+ GoodsEntity entity = this.getById(id);
|
|
|
+ String orderBy = param.getOrderBy();
|
|
|
+ // id降序, 区间升
|
|
|
+ if ("desc".equals(orderBy)){
|
|
|
+ ascSort(id, param.getSort(), entity.getSort(), entity.getType());
|
|
|
+ } else { // id升序, 区间降
|
|
|
+ descSort(id, param.getSort(), entity.getSort(), entity.getType());
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param id 对象id
|
|
|
+ * @param sort 新排序序号
|
|
|
+ * @param oldSort 旧序号
|
|
|
+ */
|
|
|
+ private void descSort(Long id, Integer sort, Integer oldSort, String type){
|
|
|
+ entityMapper.descSort(sort, oldSort, type);
|
|
|
+ entityMapper.updateSortById(id, sort);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ascSort(Long id, Integer sort, Integer oldSort, String type){
|
|
|
+ entityMapper.ascSort(sort, oldSort, type);
|
|
|
+ entityMapper.updateSortById(id, sort);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
// 更新封面图
|
|
|
private void updateIndexImg(FileEntity entity){
|
|
|
if (entity.getIsIndex() == 1) {
|