DstAppResource.java 14.8 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
package cn.ibizlab.api.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.api.dto.*;
import cn.ibizlab.api.mapping.*;
import cn.ibizlab.core.lite.domain.DstApp;
import cn.ibizlab.core.lite.service.IDstAppService;
import cn.ibizlab.core.lite.filter.DstAppSearchContext;
import cn.ibizlab.util.annotation.VersionCheck;

@Slf4j
@Api(tags = {"应用" })
@RestController("api-dstapp")
@RequestMapping("")
public class DstAppResource {

    @Autowired
    public IDstAppService dstappService;

    @Autowired
    @Lazy
    public DstAppMapping dstappMapping;

    @ApiOperation(value = "新建应用", tags = {"应用" },  notes = "新建应用")
	@RequestMapping(method = RequestMethod.POST, value = "/dstapps")
    public ResponseEntity<DstAppDTO> create(@Validated @RequestBody DstAppDTO dstappdto) {
        DstApp domain = dstappMapping.toDomain(dstappdto);
		dstappService.create(domain);
        DstAppDTO dto = dstappMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "批量新建应用", tags = {"应用" },  notes = "批量新建应用")
	@RequestMapping(method = RequestMethod.POST, value = "/dstapps/batch")
    public ResponseEntity<Boolean> createBatch(@RequestBody List<DstAppDTO> dstappdtos) {
        dstappService.createBatch(dstappMapping.toDomain(dstappdtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @ApiOperation(value = "更新应用", tags = {"应用" },  notes = "更新应用")
	@RequestMapping(method = RequestMethod.PUT, value = "/dstapps/{dstapp_id}")
    public ResponseEntity<DstAppDTO> update(@PathVariable("dstapp_id") String dstapp_id, @RequestBody DstAppDTO dstappdto) {
		DstApp domain  = dstappMapping.toDomain(dstappdto);
        domain .setId(dstapp_id);
		dstappService.update(domain );
		DstAppDTO dto = dstappMapping.toDto(domain );
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "批量更新应用", tags = {"应用" },  notes = "批量更新应用")
	@RequestMapping(method = RequestMethod.PUT, value = "/dstapps/batch")
    public ResponseEntity<Boolean> updateBatch(@RequestBody List<DstAppDTO> dstappdtos) {
        dstappService.updateBatch(dstappMapping.toDomain(dstappdtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @ApiOperation(value = "删除应用", tags = {"应用" },  notes = "删除应用")
	@RequestMapping(method = RequestMethod.DELETE, value = "/dstapps/{dstapp_id}")
    public ResponseEntity<Boolean> remove(@PathVariable("dstapp_id") String dstapp_id) {
         return ResponseEntity.status(HttpStatus.OK).body(dstappService.remove(dstapp_id));
    }

    @ApiOperation(value = "批量删除应用", tags = {"应用" },  notes = "批量删除应用")
	@RequestMapping(method = RequestMethod.DELETE, value = "/dstapps/batch")
    public ResponseEntity<Boolean> removeBatch(@RequestBody List<String> ids) {
        dstappService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @ApiOperation(value = "获取应用", tags = {"应用" },  notes = "获取应用")
	@RequestMapping(method = RequestMethod.GET, value = "/dstapps/{dstapp_id}")
    public ResponseEntity<DstAppDTO> get(@PathVariable("dstapp_id") String dstapp_id) {
        DstApp domain = dstappService.get(dstapp_id);
        DstAppDTO dto = dstappMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "获取应用草稿", tags = {"应用" },  notes = "获取应用草稿")
	@RequestMapping(method = RequestMethod.GET, value = "/dstapps/getdraft")
    public ResponseEntity<DstAppDTO> getDraft() {
        return ResponseEntity.status(HttpStatus.OK).body(dstappMapping.toDto(dstappService.getDraft(new DstApp())));
    }

    @ApiOperation(value = "检查应用", tags = {"应用" },  notes = "检查应用")
	@RequestMapping(method = RequestMethod.POST, value = "/dstapps/checkkey")
    public ResponseEntity<Boolean> checkKey(@RequestBody DstAppDTO dstappdto) {
        return  ResponseEntity.status(HttpStatus.OK).body(dstappService.checkKey(dstappMapping.toDomain(dstappdto)));
    }

    @ApiOperation(value = "保存应用", tags = {"应用" },  notes = "保存应用")
	@RequestMapping(method = RequestMethod.POST, value = "/dstapps/save")
    public ResponseEntity<Boolean> save(@RequestBody DstAppDTO dstappdto) {
        return ResponseEntity.status(HttpStatus.OK).body(dstappService.save(dstappMapping.toDomain(dstappdto)));
    }

    @ApiOperation(value = "批量保存应用", tags = {"应用" },  notes = "批量保存应用")
	@RequestMapping(method = RequestMethod.POST, value = "/dstapps/savebatch")
    public ResponseEntity<Boolean> saveBatch(@RequestBody List<DstAppDTO> dstappdtos) {
        dstappService.saveBatch(dstappMapping.toDomain(dstappdtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

	@ApiOperation(value = "获取数据集", tags = {"应用" } ,notes = "获取数据集")
    @RequestMapping(method= RequestMethod.GET , value="/dstapps/fetchdefault")
	public ResponseEntity<List<DstAppDTO>> fetchDefault(DstAppSearchContext context) {
        Page<DstApp> domains = dstappService.searchDefault(context) ;
        List<DstAppDTO> list = dstappMapping.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);
	}

	@ApiOperation(value = "查询数据集", tags = {"应用" } ,notes = "查询数据集")
    @RequestMapping(method= RequestMethod.POST , value="/dstapps/searchdefault")
	public ResponseEntity<Page<DstAppDTO>> searchDefault(@RequestBody DstAppSearchContext context) {
        Page<DstApp> domains = dstappService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(dstappMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}


    @ApiOperation(value = "根据系统建立应用", tags = {"应用" },  notes = "根据系统建立应用")
	@RequestMapping(method = RequestMethod.POST, value = "/dstsystems/{dstsystem_id}/dstapps")
    public ResponseEntity<DstAppDTO> createByDstSystem(@PathVariable("dstsystem_id") String dstsystem_id, @RequestBody DstAppDTO dstappdto) {
        DstApp domain = dstappMapping.toDomain(dstappdto);
        domain.setSystemid(dstsystem_id);
		dstappService.create(domain);
        DstAppDTO dto = dstappMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "根据系统批量建立应用", tags = {"应用" },  notes = "根据系统批量建立应用")
	@RequestMapping(method = RequestMethod.POST, value = "/dstsystems/{dstsystem_id}/dstapps/batch")
    public ResponseEntity<Boolean> createBatchByDstSystem(@PathVariable("dstsystem_id") String dstsystem_id, @RequestBody List<DstAppDTO> dstappdtos) {
        List<DstApp> domainlist=dstappMapping.toDomain(dstappdtos);
        for(DstApp domain:domainlist){
            domain.setSystemid(dstsystem_id);
        }
        dstappService.createBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @ApiOperation(value = "根据系统更新应用", tags = {"应用" },  notes = "根据系统更新应用")
	@RequestMapping(method = RequestMethod.PUT, value = "/dstsystems/{dstsystem_id}/dstapps/{dstapp_id}")
    public ResponseEntity<DstAppDTO> updateByDstSystem(@PathVariable("dstsystem_id") String dstsystem_id, @PathVariable("dstapp_id") String dstapp_id, @RequestBody DstAppDTO dstappdto) {
        DstApp domain = dstappMapping.toDomain(dstappdto);
        domain.setSystemid(dstsystem_id);
        domain.setId(dstapp_id);
		dstappService.update(domain);
        DstAppDTO dto = dstappMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "根据系统批量更新应用", tags = {"应用" },  notes = "根据系统批量更新应用")
	@RequestMapping(method = RequestMethod.PUT, value = "/dstsystems/{dstsystem_id}/dstapps/batch")
    public ResponseEntity<Boolean> updateBatchByDstSystem(@PathVariable("dstsystem_id") String dstsystem_id, @RequestBody List<DstAppDTO> dstappdtos) {
        List<DstApp> domainlist=dstappMapping.toDomain(dstappdtos);
        for(DstApp domain:domainlist){
            domain.setSystemid(dstsystem_id);
        }
        dstappService.updateBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @ApiOperation(value = "根据系统删除应用", tags = {"应用" },  notes = "根据系统删除应用")
	@RequestMapping(method = RequestMethod.DELETE, value = "/dstsystems/{dstsystem_id}/dstapps/{dstapp_id}")
    public ResponseEntity<Boolean> removeByDstSystem(@PathVariable("dstsystem_id") String dstsystem_id, @PathVariable("dstapp_id") String dstapp_id) {
		return ResponseEntity.status(HttpStatus.OK).body(dstappService.remove(dstapp_id));
    }

    @ApiOperation(value = "根据系统批量删除应用", tags = {"应用" },  notes = "根据系统批量删除应用")
	@RequestMapping(method = RequestMethod.DELETE, value = "/dstsystems/{dstsystem_id}/dstapps/batch")
    public ResponseEntity<Boolean> removeBatchByDstSystem(@RequestBody List<String> ids) {
        dstappService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @ApiOperation(value = "根据系统获取应用", tags = {"应用" },  notes = "根据系统获取应用")
	@RequestMapping(method = RequestMethod.GET, value = "/dstsystems/{dstsystem_id}/dstapps/{dstapp_id}")
    public ResponseEntity<DstAppDTO> getByDstSystem(@PathVariable("dstsystem_id") String dstsystem_id, @PathVariable("dstapp_id") String dstapp_id) {
        DstApp domain = dstappService.get(dstapp_id);
        DstAppDTO dto = dstappMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "根据系统获取应用草稿", tags = {"应用" },  notes = "根据系统获取应用草稿")
    @RequestMapping(method = RequestMethod.GET, value = "/dstsystems/{dstsystem_id}/dstapps/getdraft")
    public ResponseEntity<DstAppDTO> getDraftByDstSystem(@PathVariable("dstsystem_id") String dstsystem_id) {
        DstApp domain = new DstApp();
        domain.setSystemid(dstsystem_id);
        return ResponseEntity.status(HttpStatus.OK).body(dstappMapping.toDto(dstappService.getDraft(domain)));
    }

    @ApiOperation(value = "根据系统检查应用", tags = {"应用" },  notes = "根据系统检查应用")
	@RequestMapping(method = RequestMethod.POST, value = "/dstsystems/{dstsystem_id}/dstapps/checkkey")
    public ResponseEntity<Boolean> checkKeyByDstSystem(@PathVariable("dstsystem_id") String dstsystem_id, @RequestBody DstAppDTO dstappdto) {
        return  ResponseEntity.status(HttpStatus.OK).body(dstappService.checkKey(dstappMapping.toDomain(dstappdto)));
    }

    @ApiOperation(value = "根据系统保存应用", tags = {"应用" },  notes = "根据系统保存应用")
	@RequestMapping(method = RequestMethod.POST, value = "/dstsystems/{dstsystem_id}/dstapps/save")
    public ResponseEntity<Boolean> saveByDstSystem(@PathVariable("dstsystem_id") String dstsystem_id, @RequestBody DstAppDTO dstappdto) {
        DstApp domain = dstappMapping.toDomain(dstappdto);
        domain.setSystemid(dstsystem_id);
        return ResponseEntity.status(HttpStatus.OK).body(dstappService.save(domain));
    }

    @ApiOperation(value = "根据系统批量保存应用", tags = {"应用" },  notes = "根据系统批量保存应用")
	@RequestMapping(method = RequestMethod.POST, value = "/dstsystems/{dstsystem_id}/dstapps/savebatch")
    public ResponseEntity<Boolean> saveBatchByDstSystem(@PathVariable("dstsystem_id") String dstsystem_id, @RequestBody List<DstAppDTO> dstappdtos) {
        List<DstApp> domainlist=dstappMapping.toDomain(dstappdtos);
        for(DstApp domain:domainlist){
             domain.setSystemid(dstsystem_id);
        }
        dstappService.saveBatch(domainlist);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

	@ApiOperation(value = "根据系统获取数据集", tags = {"应用" } ,notes = "根据系统获取数据集")
    @RequestMapping(method= RequestMethod.GET , value="/dstsystems/{dstsystem_id}/dstapps/fetchdefault")
	public ResponseEntity<List<DstAppDTO>> fetchDstAppDefaultByDstSystem(@PathVariable("dstsystem_id") String dstsystem_id,DstAppSearchContext context) {
        context.setN_pssystemid_eq(dstsystem_id);
        Page<DstApp> domains = dstappService.searchDefault(context) ;
        List<DstAppDTO> list = dstappMapping.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);
	}

	@ApiOperation(value = "根据系统查询数据集", tags = {"应用" } ,notes = "根据系统查询数据集")
    @RequestMapping(method= RequestMethod.POST , value="/dstsystems/{dstsystem_id}/dstapps/searchdefault")
	public ResponseEntity<Page<DstAppDTO>> searchDstAppDefaultByDstSystem(@PathVariable("dstsystem_id") String dstsystem_id, @RequestBody DstAppSearchContext context) {
        context.setN_pssystemid_eq(dstsystem_id);
        Page<DstApp> domains = dstappService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(dstappMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}
}