提交 35d9fa5c 编写于 作者: sq3536's avatar sq3536

移除无效

上级 03f52b57
package cn.ibizlab.web.filter;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;
/**
* 将应用实体映射到对应的系统服务接口
*/
@Component
public class AppDataEntitySysApiMappingFilter extends ZuulFilter {
private static Map<String, String> AppDataEntitySysApiMapping = new HashMap<>();
@PostConstruct
private void initDataEntitySysApiMapping() {
AppDataEntitySysApiMapping.put("ibzdictitem", "dictapi");
AppDataEntitySysApiMapping.put("ibzdict", "dictapi");
}
@Override
public Object run() {
RequestContext context = RequestContext.getCurrentContext();
Object entity = context.get(FilterConstants.PROXY_KEY);
Object requestPath = context.get(FilterConstants.REQUEST_URI_KEY);
if (ObjectUtils.isEmpty(requestPath) || ObjectUtils.isEmpty(entity)) {
return null;
}
String sysApiPrefix = AppDataEntitySysApiMapping.get(entity);
if (StringUtils.isEmpty(sysApiPrefix)) {
return null;
}
context.put(FilterConstants.REQUEST_URI_KEY, String.format("/%s%s", sysApiPrefix,requestPath));
return null;
}
@Override
public String filterType() {
return FilterConstants.PRE_TYPE;
}
@Override
public int filterOrder() {
return FilterConstants.PRE_DECORATION_FILTER_ORDER + 1;
}
@Override
public boolean shouldFilter() {
return true;
}
}
package cn.ibizlab.service.dictapi.resource;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.math.BigInteger;
import java.util.HashMap;
import lombok.extern.slf4j.Slf4j;
import com.alibaba.fastjson.JSONObject;
import javax.servlet.ServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.HttpStatus;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import cn.ibizlab.core.dict.service.dto.IBZDictItemDTO;
import cn.ibizlab.core.dict.domain.IBZDictItem;
import cn.ibizlab.core.dict.service.IIBZDictItemService;
import cn.ibizlab.core.dict.filter.IBZDictItemSearchContext;
import cn.ibizlab.core.dict.service.mapping.IBZDictItemMapping;
import cn.ibizlab.util.log.IBIZLog;
@Slf4j
@IBIZLog
@Api(tags = {"IBZDictItem" })
@RestController
@RequestMapping("")
public class IBZDictItemResource {
@Autowired
private IIBZDictItemService ibzdictitemService;
@ApiOperation(value = "Get", tags = {"IBZDictItem" }, notes = "Get")
@RequestMapping(method = RequestMethod.GET, value = "/dictapi/ibzdictitems/{ibzdictitem_id}")
public ResponseEntity<IBZDictItemDTO> get(@PathVariable("ibzdictitem_id") String ibzdictitem_id) {
IBZDictItem domain = ibzdictitemService.get(ibzdictitem_id);
IBZDictItemDTO dto = IBZDictItemMapping.MAPPER.toDto(domain);
return ResponseEntity.status(HttpStatus.OK).body(dto);
}
@ApiOperation(value = "GetDraft", tags = {"IBZDictItem" }, notes = "GetDraft")
@RequestMapping(method = RequestMethod.GET, value = "/dictapi/ibzdictitems/getdraft")
@Transactional
public ResponseEntity<IBZDictItemDTO> getDraft() {
return ResponseEntity.status(HttpStatus.OK).body(new IBZDictItemDTO());
}
//SAVE
@ApiOperation(value = "Save", tags = {"IBZDictItem" }, notes = "Save")
@RequestMapping(method = RequestMethod.POST, value = "/dictapi/ibzdictitems/{ibzdictitem_id}/save")
public ResponseEntity<Boolean> save(@RequestBody IBZDictItemDTO ibzdictitemdto) {
IBZDictItem ibzdictitem = IBZDictItemMapping.MAPPER.toDomain(ibzdictitemdto);
Boolean b = ibzdictitemService.save(ibzdictitem) ;
return ResponseEntity.status(HttpStatus.OK).body(b);
}
@ApiOperation(value = "CheckKey", tags = {"IBZDictItem" }, notes = "CheckKey")
@RequestMapping(method = RequestMethod.POST, value = "/dictapi/ibzdictitems/checkkey")
public ResponseEntity<Boolean> checkKey(@RequestBody IBZDictItemDTO ibzdictitemdto) {
return ResponseEntity.status(HttpStatus.OK).body(true);
}
@ApiOperation(value = "Remove", tags = {"IBZDictItem" }, notes = "Remove")
@RequestMapping(method = RequestMethod.DELETE, value = "/dictapi/ibzdictitems/{ibzdictitem_id}")
@Transactional
public ResponseEntity<Boolean> remove(@PathVariable("ibzdictitem_id") String ibzdictitem_id) {
IBZDictItemDTO ibzdictitemdto = new IBZDictItemDTO();
IBZDictItem domain = new IBZDictItem();
ibzdictitemdto.setItemId(ibzdictitem_id);
domain.setItemId(ibzdictitem_id);
Boolean rst = ibzdictitemService.remove(domain.getItemId());
if(rst){
return ResponseEntity.status(HttpStatus.OK).body(rst);
}else{
return ResponseEntity.status(HttpStatus.OK).body(rst);
}
}
@ApiOperation(value = "Create", tags = {"IBZDictItem" }, notes = "Create")
@RequestMapping(method = RequestMethod.POST, value = "/dictapi/ibzdictitems")
@Transactional
public ResponseEntity<IBZDictItemDTO> create(@RequestBody IBZDictItemDTO ibzdictitemdto) {
IBZDictItem domain = IBZDictItemMapping.MAPPER.toDomain(ibzdictitemdto);
ibzdictitemService.create(domain);
IBZDictItemDTO dto = IBZDictItemMapping.MAPPER.toDto(domain);
return ResponseEntity.status(HttpStatus.OK).body(dto);
}
@ApiOperation(value = "Update", tags = {"IBZDictItem" }, notes = "Update")
@RequestMapping(method = RequestMethod.PUT, value = "/dictapi/ibzdictitems/{ibzdictitem_id}")
@Transactional
public ResponseEntity<IBZDictItemDTO> update(@PathVariable("ibzdictitem_id") String ibzdictitem_id, @RequestBody IBZDictItemDTO ibzdictitemdto) {
IBZDictItem domain = IBZDictItemMapping.MAPPER.toDomain(ibzdictitemdto);
domain.setItemId(ibzdictitem_id);
ibzdictitemService.update(domain);
IBZDictItemDTO dto = IBZDictItemMapping.MAPPER.toDto(domain);
return ResponseEntity.status(HttpStatus.OK).body(dto);
}
//9
@ApiOperation(value = "获取DEFAULT", tags = {"IBZDictItem" } ,notes = "获取DEFAULT")
@RequestMapping(method= RequestMethod.GET , value="/dictapi/ibzdictitems/fetchdefault")
public ResponseEntity<List<IBZDictItemDTO>> fetchDefault(IBZDictItemSearchContext context) {
List<IBZDictItemDTO> list = new ArrayList<IBZDictItemDTO>();
Page<IBZDictItem> domains = ibzdictitemService.searchDefault(context) ;
for(IBZDictItem ibzdictitem : domains.getContent()){
IBZDictItemDTO dto =IBZDictItemMapping.MAPPER.toDto(ibzdictitem);
list.add(dto);
}
return ResponseEntity.status(HttpStatus.OK)
.header("x-page", String.valueOf(context.getPageable().getPageNumber()))
.header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
.header("x-total", String.valueOf(domains.getTotalElements()))
.body(list);
}
@ApiOperation(value = "Get", tags = {"IBZDictItem" }, notes = "Get")
@RequestMapping(method = RequestMethod.GET, value = "/dictapi/ibzdicts/{ibzdict_id}/ibzdictitems/{ibzdictitem_id}")
public ResponseEntity<IBZDictItemDTO> getByIBZDict(@PathVariable("ibzdict_id") String ibzdict_id, @PathVariable("ibzdictitem_id") String ibzdictitem_id) {
IBZDictItem domain = ibzdictitemService.get(ibzdictitem_id);
IBZDictItemDTO dto = IBZDictItemMapping.MAPPER.toDto(domain);
return ResponseEntity.status(HttpStatus.OK).body(dto);
}
@ApiOperation(value = "GetDraft", tags = {"IBZDictItem" }, notes = "GetDraft")
@RequestMapping(method = RequestMethod.GET, value = "/dictapi/ibzdicts/{ibzdict_id}/ibzdictitems/{ibzdictitemitemid}/getdraft")
@Transactional
public ResponseEntity<IBZDictItemDTO> getDraftByIBZDict(@PathVariable("ibzdict_id") String ibzdict_id, @PathVariable("ibzdictitem_id") String ibzdictitem_id, @RequestBody IBZDictItemDTO ibzdictitemdto) {
//8
IBZDictItem ibzdictitem = IBZDictItemMapping.MAPPER.toDomain(ibzdictitemdto);
ibzdictitem = ibzdictitemService.getDraft(ibzdictitem) ;
ibzdictitemdto = IBZDictItemMapping.MAPPER.toDto(ibzdictitem);
return ResponseEntity.status(HttpStatus.OK).body(ibzdictitemdto);
}
@ApiOperation(value = "Save", tags = {"IBZDictItem" }, notes = "Save")
@RequestMapping(method = RequestMethod.POST, value = "/dictapi/ibzdicts/{ibzdict_id}/ibzdictitems/save")
public ResponseEntity<Boolean> saveByIBZDict(@PathVariable("ibzdict_id") String ibzdict_id, @RequestBody IBZDictItemDTO ibzdictitemdto) {
//6
IBZDictItem domain = IBZDictItemMapping.MAPPER.toDomain(ibzdictitemdto);
domain.setDictId(ibzdict_id);
Boolean b = ibzdictitemService.save(domain) ;
return ResponseEntity.status(HttpStatus.OK).body(b);
}
@ApiOperation(value = "CheckKey", tags = {"IBZDictItem" }, notes = "CheckKey")
@RequestMapping(method = RequestMethod.POST, value = "/dictapi/ibzdicts/{ibzdict_id}/ibzdictitems/checkkey")
public ResponseEntity<Boolean> checkKeyByIBZDict(@PathVariable("ibzdict_id") String ibzdict_id, @RequestBody IBZDictItemDTO ibzdictitemdto) {
return ResponseEntity.status(HttpStatus.OK).body(true);
}
@ApiOperation(value = "Remove", tags = {"IBZDictItem" }, notes = "Remove")
@RequestMapping(method = RequestMethod.DELETE, value = "/dictapi/ibzdicts/{ibzdict_id}/ibzdictitems/{ibzdictitem_id}")
@Transactional
public ResponseEntity<Boolean> removeByIBZDict(@PathVariable("ibzdict_id") String ibzdict_id, @PathVariable("ibzdictitem_id") String ibzdictitem_id) {
IBZDictItem domain = new IBZDictItem();
domain.setItemId(ibzdictitem_id);
Boolean rst = ibzdictitemService.remove(domain.getItemId());
if(rst){
return ResponseEntity.status(HttpStatus.OK).body(rst);
}else{
return ResponseEntity.status(HttpStatus.OK).body(rst);
}
}
@ApiOperation(value = "Create", tags = {"IBZDictItem" }, notes = "Create")
@RequestMapping(method = RequestMethod.POST, value = "/dictapi/ibzdicts/{ibzdict_id}/ibzdictitems")
@Transactional
public ResponseEntity<IBZDictItemDTO> createByIBZDict(@PathVariable("ibzdict_id") String ibzdict_id, @RequestBody IBZDictItemDTO ibzdictitemdto) {
//4
IBZDictItem domain = IBZDictItemMapping.MAPPER.toDomain(ibzdictitemdto);
domain.setDictId(ibzdict_id);
ibzdictitemService.create(domain);
IBZDictItemDTO dto = IBZDictItemMapping.MAPPER.toDto(domain);
return ResponseEntity.status(HttpStatus.OK).body(dto);
}
@ApiOperation(value = "Update", tags = {"IBZDictItem" }, notes = "Update")
@RequestMapping(method = RequestMethod.PUT, value = "/dictapi/ibzdicts/{ibzdict_id}/ibzdictitems/{ibzdictitem_id}")
@Transactional
public ResponseEntity<IBZDictItemDTO> updateByIBZDict(@PathVariable("ibzdict_id") String ibzdict_id, @PathVariable("ibzdictitem_id") String ibzdictitem_id, @RequestBody IBZDictItemDTO ibzdictitemdto) {
//5
IBZDictItem domain = IBZDictItemMapping.MAPPER.toDomain(ibzdictitemdto);
domain.setDictId(ibzdict_id);
domain.setItemId(ibzdictitem_id);
ibzdictitemService.update(domain);
IBZDictItemDTO dto = IBZDictItemMapping.MAPPER.toDto(domain);
return ResponseEntity.status(HttpStatus.OK).body(dto);
}
//10
@ApiOperation(value = "获取DEFAULT", tags = {"IBZDictItem" } ,notes = "获取DEFAULT")
@RequestMapping(method= RequestMethod.GET , value="/dictapi/ibzdicts/{ibzdict_id}/ibzdictitems/fetchdefault")
public ResponseEntity<Page<IBZDictItemDTO>> fetchIBZDictItemDefault(@PathVariable("ibzdict_id") String ibzdict_id,IBZDictItemSearchContext context,Pageable pageable ,ServletRequest request) {
context.setPageable(pageable);
List<IBZDictItemDTO> list = new ArrayList<IBZDictItemDTO>();
context.setN_dictid_eq(ibzdict_id);
Page<IBZDictItem> domains = ibzdictitemService.searchDefault(context) ;
for(IBZDictItem ibzdictitem : domains.getContent()){
IBZDictItemDTO dto = IBZDictItemMapping.MAPPER.toDto(ibzdictitem);
list.add(dto);
}
return ResponseEntity.status(HttpStatus.OK).body(new PageImpl(list,context.getPageable(),domains.getTotalElements()));
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册