提交 4c542921 authored 作者: 黄承天's avatar 黄承天

[设置模块]初始提交

上级 d7410e88
package com.tykj.setting.controller;
import com.tykj.base.result.ResultUtil;
import com.tykj.setting.entity.vo.DisplaySettingVo;
import com.tykj.setting.service.DisplaySettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@Api(tags = "展示设置相关接口")
@RequestMapping("/setting/display")
@RestController
public class DisplaySettingController {
@Autowired
private DisplaySettingService displaySettingService;
@PostMapping
@ApiOperation("保存展示设置")
public ResponseEntity save(@RequestBody DisplaySettingVo displaySettingVo){
displaySettingService.save(displaySettingVo);
return ResultUtil.success("", "保存成功");
}
@GetMapping
@ApiOperation("查找展示设置")
public ResponseEntity find(){
return ResultUtil.success(displaySettingService.find(),"查找成功");
}
@DeleteMapping
@ApiOperation("删除展示设置")
public ResponseEntity delete(){
displaySettingService.delete();
return ResultUtil.success("", "删除成功");
}
}
package com.tykj.setting.controller;
import com.tykj.base.result.ResultUtil;
import com.tykj.setting.entity.GroupSetting;
import com.tykj.setting.service.GroupSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@Api(tags = "分类设置相关接口")
@RequestMapping("/setting/group")
@RestController
public class GroupSettingController {
@Autowired
private GroupSettingService groupSettingService;
@PostMapping
@ApiOperation("新增分类设置")
public ResponseEntity save(@RequestBody GroupSetting groupSetting){
groupSettingService.save(groupSetting);
return ResultUtil.success("", "保存成功");
}
@PutMapping
@ApiOperation("更新分类设置")
public ResponseEntity update(@RequestBody GroupSetting groupSetting){
groupSettingService.update(groupSetting);
return ResultUtil.success("", "更新成功");
}
@GetMapping
@ApiOperation("查找所有分类设置")
public ResponseEntity findAll(){
return ResultUtil.success(groupSettingService.findAll(),"查找成功");
}
@GetMapping("/{id}")
@ApiOperation("按id查找单个分类设置")
public ResponseEntity findById(@PathVariable Integer id){
return ResultUtil.success(groupSettingService.findById(id),"查找成功");
}
@DeleteMapping("/{id}")
@ApiOperation("按id删除单个分类设置")
public ResponseEntity deleteById(@PathVariable Integer id){
groupSettingService.deleteById(id);
return ResultUtil.success("", "删除成功");
}
}
package com.tykj.setting.controller;
import com.tykj.base.result.ResultUtil;
import com.tykj.setting.entity.vo.ScreenSettingVo;
import com.tykj.setting.service.ScreenSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@Api(tags = "筛选设置相关接口")
@RequestMapping("/setting/group")
@RestController
public class ScreenSettingController {
@Autowired
private ScreenSettingService screenSettingService;
@PostMapping
@ApiOperation("新增筛选设置")
public ResponseEntity save(@RequestBody ScreenSettingVo screenSettingVo){
screenSettingService.save(screenSettingVo);
return ResultUtil.success("", "保存成功");
}
@PutMapping
@ApiOperation("更新筛选设置")
public ResponseEntity update(@RequestBody ScreenSettingVo screenSettingVo){
screenSettingService.update(screenSettingVo);
return ResultUtil.success("", "更新成功");
}
@GetMapping
@ApiOperation("查找所有筛选设置")
public ResponseEntity findAll(){
return ResultUtil.success(screenSettingService.findAll(),"查找成功");
}
@GetMapping("/{id}")
@ApiOperation("按id查找单个筛选设置")
public ResponseEntity findById(@PathVariable Integer id){
return ResultUtil.success(screenSettingService.findById(id),"查找成功");
}
@DeleteMapping("/{id}")
@ApiOperation("按id删除单个筛选设置")
public ResponseEntity deleteById(@PathVariable Integer id){
screenSettingService.deleteById(id);
return ResultUtil.success("", "删除成功");
}
}
package com.tykj.setting.entity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity
public class ConditionSetting {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty("主键")
private Integer id;
@ApiModelProperty("字段名")
private String columnName;
@ApiModelProperty("操作符类型")
private String type;
@ApiModelProperty("对象值")
private String value;
@JsonIgnore
private Integer screenSettingId;
}
package com.tykj.setting.entity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
import javax.persistence.Id;
@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity
public class DisplaySetting {
@Id
@JsonIgnore
@ApiModelProperty("主键")
private Integer id;
@ApiModelProperty("字段信息id集 字符串形式")
private String columnIds;
}
package com.tykj.setting.entity;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity
public class GroupSetting {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty("主键")
private Integer id;
@ApiModelProperty("类型")
private String type;
@ApiModelProperty("分类字段名")
private String columnName;
@ApiModelProperty("名称")
private String name;
}
package com.tykj.setting.entity;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity
public class ScreenSetting {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty("主键")
private Integer id;
@ApiModelProperty("表信息id")
private Integer tableInfoId;
}
package com.tykj.setting.entity.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@AllArgsConstructor
@NoArgsConstructor
@Data
public class DisplaySettingVo {
@ApiModelProperty("主键")
private Integer id;
@ApiModelProperty("字段信息id集")
private List<Integer> columnIds;
}
package com.tykj.setting.entity.vo;
import com.tykj.setting.entity.ConditionSetting;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@AllArgsConstructor
@NoArgsConstructor
@Data
public class ScreenSettingVo {
@ApiModelProperty("主键")
private Integer id;
@ApiModelProperty("表信息id")
private Integer tableInfoId;
@ApiModelProperty("筛选条件")
private List<ConditionSetting> conditions;
}
package com.tykj.setting.repository;
import com.tykj.setting.entity.ConditionSetting;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface ConditionSettingRepository extends JpaRepository<ConditionSetting,Integer> {
void deleteAllByScreenSettingId(Integer screenSettingId);
List<ConditionSetting> findAllByScreenSettingId(Integer screenSettingId);
}
package com.tykj.setting.repository;
import com.tykj.setting.entity.DisplaySetting;
import org.springframework.data.jpa.repository.JpaRepository;
public interface DisplaySettingRepository extends JpaRepository<DisplaySetting,Integer> {
}
package com.tykj.setting.repository;
import com.tykj.setting.entity.GroupSetting;
import org.springframework.data.jpa.repository.JpaRepository;
public interface GroupSettingRepository extends JpaRepository<GroupSetting,Integer> {
}
package com.tykj.setting.repository;
import com.tykj.setting.entity.ScreenSetting;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ScreenSettingRepository extends JpaRepository<ScreenSetting,Integer> {
}
package com.tykj.setting.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.tykj.setting.entity.DisplaySetting;
import com.tykj.setting.entity.vo.DisplaySettingVo;
import com.tykj.setting.repository.DisplaySettingRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Service
public class DisplaySettingService {
@Autowired
private DisplaySettingRepository displaySettingRepository;
private final Integer id = 1;
public void save(DisplaySettingVo groupSettingVo){
String columnIds = "[]";
try {
columnIds = new ObjectMapper().writeValueAsString(groupSettingVo);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
DisplaySetting displaySetting = new DisplaySetting(id, columnIds);
displaySettingRepository.save(displaySetting);
}
public DisplaySettingVo find(){
Optional<DisplaySetting> byId = displaySettingRepository.findById(id);
if (byId.isPresent()){
DisplaySetting displaySetting = byId.get();
List<Integer> columnIds = new ArrayList<>();
try {
columnIds = new ObjectMapper().readValue(displaySetting.getColumnIds(), new TypeReference<List<Integer>>() {
});
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return new DisplaySettingVo(displaySetting.getId(),columnIds);
} else {
throw new RuntimeException("未找到该数据");
}
}
public void delete(){
displaySettingRepository.deleteById(id);
}
}
package com.tykj.setting.service;
import com.tykj.setting.entity.GroupSetting;
import com.tykj.setting.repository.GroupSettingRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@Service
public class GroupSettingService {
@Autowired
private GroupSettingRepository groupSettingRepository;
public void save(GroupSetting groupSetting) {
boolean newData = Objects.isNull(groupSetting.getId());
if (newData) {
groupSettingRepository.save(groupSetting);
} else {
throw new RuntimeException("新增数据不可附带id");
}
}
public void update(GroupSetting groupSetting) {
boolean exist = Objects.nonNull(groupSetting.getId()) && groupSettingRepository.existsById(groupSetting.getId());
if (exist) {
groupSettingRepository.save(groupSetting);
} else {
throw new RuntimeException("未找到该id的数据");
}
}
public List<GroupSetting> findAll() {
return groupSettingRepository.findAll();
}
public GroupSetting findById(Integer id) {
Optional<GroupSetting> byId = groupSettingRepository.findById(id);
if (byId.isPresent()) {
return byId.get();
} else {
throw new RuntimeException("未找到该id的数据");
}
}
public void deleteById(Integer id) {
groupSettingRepository.deleteById(id);
}
}
package com.tykj.setting.service;
import com.tykj.setting.entity.ConditionSetting;
import com.tykj.setting.entity.ScreenSetting;
import com.tykj.setting.entity.vo.ScreenSettingVo;
import com.tykj.setting.repository.ConditionSettingRepository;
import com.tykj.setting.repository.ScreenSettingRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
@Service
public class ScreenSettingService {
/**
* 筛选设置
*/
@Autowired
private ScreenSettingRepository screenSettingRepository;
/**
* 筛选设置中的条件
*/
@Autowired
private ConditionSettingRepository conditionSettingRepository;
public void save(ScreenSettingVo screenSettingVo){
boolean newData = Objects.isNull(screenSettingVo.getId());
if (newData){
ScreenSetting saved = screenSettingRepository.save(new ScreenSetting(screenSettingVo.getId(),screenSettingVo.getTableInfoId()));
Integer savedId = saved.getId();
List<ConditionSetting> conditionsForSave = screenSettingVo.getConditions().stream()
.map(conditionSetting -> conditionSetting.setScreenSettingId(savedId))
.collect(Collectors.toList());
conditionSettingRepository.saveAll(conditionsForSave);
} else {
throw new RuntimeException("新增数据不可附带id");
}
}
public void update(ScreenSettingVo screenSettingVo){
boolean exist = Objects.nonNull(screenSettingVo.getId()) && screenSettingRepository.existsById(screenSettingVo.getId());
if (exist){
conditionSettingRepository.deleteAllByScreenSettingId(screenSettingVo.getId());
screenSettingRepository.save(new ScreenSetting(screenSettingVo.getId(),screenSettingVo.getTableInfoId()));
Integer savedId = screenSettingVo.getId();
List<ConditionSetting> conditionsForSave = screenSettingVo.getConditions().stream()
.map(conditionSetting -> conditionSetting.setScreenSettingId(savedId))
.collect(Collectors.toList());
conditionSettingRepository.saveAll(conditionsForSave);
} else {
throw new RuntimeException("未找到该id的数据");
}
}
public List<ScreenSettingVo> findAll(){
return screenSettingRepository.findAll().stream()
.map(this::screenSettingVo)
.collect(Collectors.toList());
}
public ScreenSettingVo findById(Integer id){
Optional<ScreenSetting> byId = screenSettingRepository.findById(id);
if (byId.isPresent()){
ScreenSetting screenSetting = byId.get();
List<ConditionSetting> conditions = conditionSettingRepository.findAllByScreenSettingId(id);
return new ScreenSettingVo(screenSetting.getId(),screenSetting.getTableInfoId(),conditions
);
} else {
throw new RuntimeException("未找到该id的数据");
}
}
public void deleteById(Integer id){
screenSettingRepository.deleteById(id);
}
private ScreenSettingVo screenSettingVo(ScreenSetting screenSetting){
List<ConditionSetting> conditions = conditionSettingRepository.findAllByScreenSettingId(screenSetting.getId());
return new ScreenSettingVo(screenSetting.getId(),screenSetting.getTableInfoId(),conditions);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论