IBIZAPPCTRLResource.java 9.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
package cn.ibizlab.demoapi.rest;

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.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 org.springframework.context.annotation.Lazy;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import cn.ibizlab.demoapi.dto.*;
import cn.ibizlab.demoapi.mapping.*;
import cn.ibizlab.core.sample.domain.IBIZAPPCTRL;
import cn.ibizlab.core.sample.service.IIBIZAPPCTRLService;
import cn.ibizlab.core.sample.filter.IBIZAPPCTRLSearchContext;
import cn.ibizlab.util.annotation.VersionCheck;

@Slf4j
@Api(tags = {"应用部件" })
@RestController("DemoAPI-ibizappctrl")
@RequestMapping("")
public class IBIZAPPCTRLResource {

    @Autowired
    public IIBIZAPPCTRLService ibizappctrlService;

    @Autowired
    @Lazy
    public IBIZAPPCTRLMapping ibizappctrlMapping;

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
    @PreAuthorize("hasPermission(this.ibizappctrlMapping.toDomain(#ibizappctrldto),'DemoSys-IBIZAPPCTRL-Create')")
    @ApiOperation(value = "新建应用部件", tags = {"应用部件" },  notes = "新建应用部件")
	@RequestMapping(method = RequestMethod.POST, value = "/ibizappctrls")
    public ResponseEntity<IBIZAPPCTRLDTO> create(@Validated @RequestBody IBIZAPPCTRLDTO ibizappctrldto) {
        IBIZAPPCTRL domain = ibizappctrlMapping.toDomain(ibizappctrldto);
		ibizappctrlService.create(domain);
        IBIZAPPCTRLDTO dto = ibizappctrlMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.ibizappctrlMapping.toDomain(#ibizappctrldtos),'DemoSys-IBIZAPPCTRL-Create')")
    @ApiOperation(value = "批量新建应用部件", tags = {"应用部件" },  notes = "批量新建应用部件")
	@RequestMapping(method = RequestMethod.POST, value = "/ibizappctrls/batch")
    public ResponseEntity<Boolean> createBatch(@RequestBody List<IBIZAPPCTRLDTO> ibizappctrldtos) {
        ibizappctrlService.createBatch(ibizappctrlMapping.toDomain(ibizappctrldtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

68 69 70 71 72 73
    @PostAuthorize("hasPermission(this.ibizappctrlMapping.toDomain(returnObject.body),'DemoSys-IBIZAPPCTRL-Get')")
    @ApiOperation(value = "获取应用部件", tags = {"应用部件" },  notes = "获取应用部件")
	@RequestMapping(method = RequestMethod.GET, value = "/ibizappctrls/{ibizappctrl_id}")
    public ResponseEntity<IBIZAPPCTRLDTO> get(@PathVariable("ibizappctrl_id") String ibizappctrl_id) {
        IBIZAPPCTRL domain = ibizappctrlService.get(ibizappctrl_id);
        IBIZAPPCTRLDTO dto = ibizappctrlMapping.toDto(domain);
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.ibizappctrlService.get(#ibizappctrl_id),'DemoSys-IBIZAPPCTRL-Remove')")
    @ApiOperation(value = "删除应用部件", tags = {"应用部件" },  notes = "删除应用部件")
	@RequestMapping(method = RequestMethod.DELETE, value = "/ibizappctrls/{ibizappctrl_id}")
    public ResponseEntity<Boolean> remove(@PathVariable("ibizappctrl_id") String ibizappctrl_id) {
         return ResponseEntity.status(HttpStatus.OK).body(ibizappctrlService.remove(ibizappctrl_id));
    }

    @PreAuthorize("hasPermission(this.ibizappctrlService.getIbizappctrlByIds(#ids),'DemoSys-IBIZAPPCTRL-Remove')")
    @ApiOperation(value = "批量删除应用部件", tags = {"应用部件" },  notes = "批量删除应用部件")
	@RequestMapping(method = RequestMethod.DELETE, value = "/ibizappctrls/batch")
    public ResponseEntity<Boolean> removeBatch(@RequestBody List<String> ids) {
        ibizappctrlService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

92 93 94 95 96 97 98 99 100
    @VersionCheck(entity = "ibizappctrl" , versionfield = "updatedate")
    @PreAuthorize("hasPermission(this.ibizappctrlService.get(#ibizappctrl_id),'DemoSys-IBIZAPPCTRL-Update')")
    @ApiOperation(value = "更新应用部件", tags = {"应用部件" },  notes = "更新应用部件")
	@RequestMapping(method = RequestMethod.PUT, value = "/ibizappctrls/{ibizappctrl_id}")
    public ResponseEntity<IBIZAPPCTRLDTO> update(@PathVariable("ibizappctrl_id") String ibizappctrl_id, @RequestBody IBIZAPPCTRLDTO ibizappctrldto) {
		IBIZAPPCTRL domain  = ibizappctrlMapping.toDomain(ibizappctrldto);
        domain .setIbizappctrlid(ibizappctrl_id);
		ibizappctrlService.update(domain );
		IBIZAPPCTRLDTO dto = ibizappctrlMapping.toDto(domain);
101 102 103
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

104 105 106 107 108 109
    @PreAuthorize("hasPermission(this.ibizappctrlService.getIbizappctrlByEntities(this.ibizappctrlMapping.toDomain(#ibizappctrldtos)),'DemoSys-IBIZAPPCTRL-Update')")
    @ApiOperation(value = "批量更新应用部件", tags = {"应用部件" },  notes = "批量更新应用部件")
	@RequestMapping(method = RequestMethod.PUT, value = "/ibizappctrls/batch")
    public ResponseEntity<Boolean> updateBatch(@RequestBody List<IBIZAPPCTRLDTO> ibizappctrldtos) {
        ibizappctrlService.updateBatch(ibizappctrlMapping.toDomain(ibizappctrldtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
110 111 112 113 114 115 116 117
    }

    @ApiOperation(value = "检查应用部件", tags = {"应用部件" },  notes = "检查应用部件")
	@RequestMapping(method = RequestMethod.POST, value = "/ibizappctrls/checkkey")
    public ResponseEntity<Boolean> checkKey(@RequestBody IBIZAPPCTRLDTO ibizappctrldto) {
        return  ResponseEntity.status(HttpStatus.OK).body(ibizappctrlService.checkKey(ibizappctrlMapping.toDomain(ibizappctrldto)));
    }

118 119 120 121 122 123 124
    @ApiOperation(value = "获取应用部件草稿", tags = {"应用部件" },  notes = "获取应用部件草稿")
	@RequestMapping(method = RequestMethod.GET, value = "/ibizappctrls/getdraft")
    public ResponseEntity<IBIZAPPCTRLDTO> getDraft(IBIZAPPCTRLDTO dto) {
        IBIZAPPCTRL domain = ibizappctrlMapping.toDomain(dto);
        return ResponseEntity.status(HttpStatus.OK).body(ibizappctrlMapping.toDto(ibizappctrlService.getDraft(domain)));
    }

125 126 127
    @PreAuthorize("hasPermission(this.ibizappctrlMapping.toDomain(#ibizappctrldto),'DemoSys-IBIZAPPCTRL-Save')")
    @ApiOperation(value = "保存应用部件", tags = {"应用部件" },  notes = "保存应用部件")
	@RequestMapping(method = RequestMethod.POST, value = "/ibizappctrls/save")
128 129 130 131
    public ResponseEntity<IBIZAPPCTRLDTO> save(@RequestBody IBIZAPPCTRLDTO ibizappctrldto) {
        IBIZAPPCTRL domain = ibizappctrlMapping.toDomain(ibizappctrldto);
        ibizappctrlService.save(domain);
        return ResponseEntity.status(HttpStatus.OK).body(ibizappctrlMapping.toDto(domain));
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
    }

    @PreAuthorize("hasPermission(this.ibizappctrlMapping.toDomain(#ibizappctrldtos),'DemoSys-IBIZAPPCTRL-Save')")
    @ApiOperation(value = "批量保存应用部件", tags = {"应用部件" },  notes = "批量保存应用部件")
	@RequestMapping(method = RequestMethod.POST, value = "/ibizappctrls/savebatch")
    public ResponseEntity<Boolean> saveBatch(@RequestBody List<IBIZAPPCTRLDTO> ibizappctrldtos) {
        ibizappctrlService.saveBatch(ibizappctrlMapping.toDomain(ibizappctrldtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','DemoSys-IBIZAPPCTRL-searchDefault-all') and hasPermission(#context,'DemoSys-IBIZAPPCTRL-Get')")
	@ApiOperation(value = "获取数据集", tags = {"应用部件" } ,notes = "获取数据集")
    @RequestMapping(method= RequestMethod.GET , value="/ibizappctrls/fetchdefault")
	public ResponseEntity<List<IBIZAPPCTRLDTO>> fetchDefault(IBIZAPPCTRLSearchContext context) {
        Page<IBIZAPPCTRL> domains = ibizappctrlService.searchDefault(context) ;
        List<IBIZAPPCTRLDTO> list = ibizappctrlMapping.toDto(domains.getContent());
        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);
	}

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','DemoSys-IBIZAPPCTRL-searchDefault-all') and hasPermission(#context,'DemoSys-IBIZAPPCTRL-Get')")
	@ApiOperation(value = "查询数据集", tags = {"应用部件" } ,notes = "查询数据集")
    @RequestMapping(method= RequestMethod.POST , value="/ibizappctrls/searchdefault")
	public ResponseEntity<Page<IBIZAPPCTRLDTO>> searchDefault(@RequestBody IBIZAPPCTRLSearchContext context) {
        Page<IBIZAPPCTRL> domains = ibizappctrlService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(ibizappctrlMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}

164

165

166 167
}