1
0

feat(ware): 上架数据产品功能

- 新增数据产品上架相关的对话框组件和页面功能
- 实现数据产品的添加、编辑和详情查看功能
- 添加数据产品相关的实体类、控制器、服务类和仓库接口
This commit is contained in:
2024-12-13 18:18:49 +08:00
parent 8202a27f55
commit dbdf9c59bb
8 changed files with 345 additions and 2 deletions

View File

@@ -0,0 +1,98 @@
package com.eshore.gringotts.web.domain.controller;
import com.eshore.gringotts.web.domain.base.controller.SimpleControllerSupport;
import com.eshore.gringotts.web.domain.base.entity.FileInfo;
import com.eshore.gringotts.web.domain.base.entity.SimpleListItem;
import com.eshore.gringotts.web.domain.base.entity.SimpleSaveItem;
import com.eshore.gringotts.web.domain.entity.Ware;
import com.eshore.gringotts.web.domain.service.DataFileService;
import com.eshore.gringotts.web.domain.service.DataResourceService;
import com.eshore.gringotts.web.domain.service.WareService;
import java.time.LocalDateTime;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author lanyuanxiaoyao
* @date 2024-12-13
*/
@Slf4j
@RestController
@RequestMapping("ware")
public class WareController extends SimpleControllerSupport<Ware, WareController.SaveItem, WareController.ListItem, WareController.DetailItem> {
private final DataResourceService dataResourceService;
private final DataFileService dataFileService;
public WareController(WareService service, DataResourceService dataResourceService, DataFileService dataFileService) {
super(service);
this.dataResourceService = dataResourceService;
this.dataFileService = dataFileService;
}
@Override
protected Ware fromSaveItem(SaveItem saveItem) throws Exception {
Ware ware = new Ware();
ware.setResource(dataResourceService.detailOrThrow(saveItem.getResourceId()));
ware.setName(ware.getName());
ware.setDescription(saveItem.getDescription());
ware.setIcon(dataFileService.detailOrThrow(saveItem.getIcon().getValue()));
ware.setContent(saveItem.getContent());
return ware;
}
@Override
protected ListItem toListItem(Ware entity) throws Exception {
return new ListItem(entity);
}
@Override
protected DetailItem toDetailItem(Ware entity) throws Exception {
return new DetailItem(entity);
}
@Data
@EqualsAndHashCode(callSuper = true)
public static class SaveItem extends SimpleSaveItem<Ware> {
private Long resourceId;
private String name;
private String description;
private FileInfo icon;
private String content;
}
@Data
@EqualsAndHashCode(callSuper = true)
public static class ListItem extends SimpleListItem<Ware> {
private String name;
private String description;
public ListItem(Ware ware) {
this.setId(ware.getId());
this.setName(ware.getName());
this.setDescription(ware.getDescription());
this.setCreatedTime(ware.getCreatedTime());
this.setCreatedUsername(ware.getCreatedUser().getUsername());
}
}
@Data
@EqualsAndHashCode(callSuper = true)
public static class DetailItem extends SaveItem {
private LocalDateTime createdTime;
private String createdUsername;
private LocalDateTime modifiedTime;
private String modifiedUsername;
public DetailItem(Ware ware) {
this.setId(ware.getId());
this.setResourceId(ware.getResource().getId());
this.setName(ware.getName());
this.setDescription(ware.getDescription());
this.setIcon(new FileInfo(ware.getIcon()));
this.setContent(ware.getContent());
}
}
}

View File

@@ -0,0 +1,70 @@
package com.eshore.gringotts.web.domain.entity;
import com.eshore.gringotts.core.Constants;
import com.eshore.gringotts.web.domain.base.entity.LogicDeleteEntity;
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.ConstraintMode;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.NamedAttributeNode;
import javax.persistence.NamedEntityGraph;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
/**
* 商品
*
* @author lanyuanxiaoyao
* @date 2024-12-13
*/
@Getter
@Setter
@ToString(callSuper = true)
@Entity
@EntityListeners(AuditingEntityListener.class)
@DynamicUpdate
@Table(name = Constants.TABLE_PREFIX + "ware")
@NamedEntityGraph(name = "ware.list", attributeNodes = {
@NamedAttributeNode(value = "createdUser"),
})
@NamedEntityGraph(name = "ware.detail", attributeNodes = {
@NamedAttributeNode(value = "icon"),
@NamedAttributeNode(value = "content"),
@NamedAttributeNode(value = "createdUser"),
@NamedAttributeNode(value = "modifiedUser"),
})
@SQLDelete(sql = "update " + Constants.TABLE_PREFIX + "ware" + " set deleted = true where id = ?")
@Where(clause = LogicDeleteEntity.LOGIC_DELETE_CLAUSE)
public class Ware extends SimpleEntity {
@OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.EAGER)
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@ToString.Exclude
private DataResource resource;
@Column(nullable = false)
private String name;
@Column(nullable = false)
private String description;
@OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@ToString.Exclude
private DataFile icon;
@Lob
@Basic(fetch = FetchType.LAZY)
@ToString.Exclude
@Column(nullable = false)
private String content;
}

View File

@@ -0,0 +1,26 @@
package com.eshore.gringotts.web.domain.repository;
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
import com.eshore.gringotts.web.domain.entity.Ware;
import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.stereotype.Repository;
@SuppressWarnings("NullableProblems")
@Repository
public interface WareRepository extends SimpleRepository<Ware, Long> {
@Override
@EntityGraph(value = "ware.list", type = EntityGraph.EntityGraphType.FETCH)
List<Ware> findAll(Specification<Ware> specification);
@Override
@EntityGraph(value = "ware.list", type = EntityGraph.EntityGraphType.FETCH)
List<Ware> findAll(Specification<Ware> specification, Sort sort);
@Override
@EntityGraph(value = "ware.detail", type = EntityGraph.EntityGraphType.FETCH)
Optional<Ware> findOne(Specification<Ware> specification);
}

View File

@@ -0,0 +1,19 @@
package com.eshore.gringotts.web.domain.service;
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
import com.eshore.gringotts.web.domain.entity.Ware;
import com.eshore.gringotts.web.domain.repository.WareRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @author lanyuanxiaoyao
* @date 2024-12-13
*/
@Slf4j
@Service
public class WareService extends SimpleServiceSupport<Ware> {
public WareService(WareRepository repository, UserService userService) {
super(repository, userService);
}
}