package cn.ibizlab.businesscentral.core.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.businesscentral.core.dto.*;
import cn.ibizlab.businesscentral.core.mapping.*;
import cn.ibizlab.businesscentral.core.odoo_base_import.domain.Base_import_tests_models_char_stillreadonly;
import cn.ibizlab.businesscentral.core.odoo_base_import.service.IBase_import_tests_models_char_stillreadonlyService;
import cn.ibizlab.businesscentral.core.odoo_base_import.filter.Base_import_tests_models_char_stillreadonlySearchContext;
import cn.ibizlab.businesscentral.util.annotation.VersionCheck;

@Slf4j
@Api(tags = {"测试:基本导入模型，字符仍然只读" })
@RestController("Core-base_import_tests_models_char_stillreadonly")
@RequestMapping("")
public class Base_import_tests_models_char_stillreadonlyResource {

    @Autowired
    public IBase_import_tests_models_char_stillreadonlyService base_import_tests_models_char_stillreadonlyService;

    @Autowired
    @Lazy
    public Base_import_tests_models_char_stillreadonlyMapping base_import_tests_models_char_stillreadonlyMapping;

    @PreAuthorize("hasPermission(this.base_import_tests_models_char_stillreadonlyMapping.toDomain(#base_import_tests_models_char_stillreadonlydto),'iBizBusinessCentral-Base_import_tests_models_char_stillreadonly-Create')")
    @ApiOperation(value = "新建测试:基本导入模型，字符仍然只读", tags = {"测试:基本导入模型，字符仍然只读" },  notes = "新建测试:基本导入模型，字符仍然只读")
	@RequestMapping(method = RequestMethod.POST, value = "/base_import_tests_models_char_stillreadonlies")
    public ResponseEntity<Base_import_tests_models_char_stillreadonlyDTO> create(@Validated @RequestBody Base_import_tests_models_char_stillreadonlyDTO base_import_tests_models_char_stillreadonlydto) {
        Base_import_tests_models_char_stillreadonly domain = base_import_tests_models_char_stillreadonlyMapping.toDomain(base_import_tests_models_char_stillreadonlydto);
		base_import_tests_models_char_stillreadonlyService.create(domain);
        Base_import_tests_models_char_stillreadonlyDTO dto = base_import_tests_models_char_stillreadonlyMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.base_import_tests_models_char_stillreadonlyMapping.toDomain(#base_import_tests_models_char_stillreadonlydtos),'iBizBusinessCentral-Base_import_tests_models_char_stillreadonly-Create')")
    @ApiOperation(value = "批量新建测试:基本导入模型，字符仍然只读", tags = {"测试:基本导入模型，字符仍然只读" },  notes = "批量新建测试:基本导入模型，字符仍然只读")
	@RequestMapping(method = RequestMethod.POST, value = "/base_import_tests_models_char_stillreadonlies/batch")
    public ResponseEntity<Boolean> createBatch(@RequestBody List<Base_import_tests_models_char_stillreadonlyDTO> base_import_tests_models_char_stillreadonlydtos) {
        base_import_tests_models_char_stillreadonlyService.createBatch(base_import_tests_models_char_stillreadonlyMapping.toDomain(base_import_tests_models_char_stillreadonlydtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "base_import_tests_models_char_stillreadonly" , versionfield = "writeDate")
    @PreAuthorize("hasPermission(this.base_import_tests_models_char_stillreadonlyService.get(#base_import_tests_models_char_stillreadonly_id),'iBizBusinessCentral-Base_import_tests_models_char_stillreadonly-Update')")
    @ApiOperation(value = "更新测试:基本导入模型，字符仍然只读", tags = {"测试:基本导入模型，字符仍然只读" },  notes = "更新测试:基本导入模型，字符仍然只读")
	@RequestMapping(method = RequestMethod.PUT, value = "/base_import_tests_models_char_stillreadonlies/{base_import_tests_models_char_stillreadonly_id}")
    public ResponseEntity<Base_import_tests_models_char_stillreadonlyDTO> update(@PathVariable("base_import_tests_models_char_stillreadonly_id") Long base_import_tests_models_char_stillreadonly_id, @RequestBody Base_import_tests_models_char_stillreadonlyDTO base_import_tests_models_char_stillreadonlydto) {
		Base_import_tests_models_char_stillreadonly domain  = base_import_tests_models_char_stillreadonlyMapping.toDomain(base_import_tests_models_char_stillreadonlydto);
        domain .setId(base_import_tests_models_char_stillreadonly_id);
		base_import_tests_models_char_stillreadonlyService.update(domain );
		Base_import_tests_models_char_stillreadonlyDTO dto = base_import_tests_models_char_stillreadonlyMapping.toDto(domain );
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.base_import_tests_models_char_stillreadonlyService.getBaseImportTestsModelsCharStillreadonlyByEntities(this.base_import_tests_models_char_stillreadonlyMapping.toDomain(#base_import_tests_models_char_stillreadonlydtos)),'iBizBusinessCentral-Base_import_tests_models_char_stillreadonly-Update')")
    @ApiOperation(value = "批量更新测试:基本导入模型，字符仍然只读", tags = {"测试:基本导入模型，字符仍然只读" },  notes = "批量更新测试:基本导入模型，字符仍然只读")
	@RequestMapping(method = RequestMethod.PUT, value = "/base_import_tests_models_char_stillreadonlies/batch")
    public ResponseEntity<Boolean> updateBatch(@RequestBody List<Base_import_tests_models_char_stillreadonlyDTO> base_import_tests_models_char_stillreadonlydtos) {
        base_import_tests_models_char_stillreadonlyService.updateBatch(base_import_tests_models_char_stillreadonlyMapping.toDomain(base_import_tests_models_char_stillreadonlydtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.base_import_tests_models_char_stillreadonlyService.get(#base_import_tests_models_char_stillreadonly_id),'iBizBusinessCentral-Base_import_tests_models_char_stillreadonly-Remove')")
    @ApiOperation(value = "删除测试:基本导入模型，字符仍然只读", tags = {"测试:基本导入模型，字符仍然只读" },  notes = "删除测试:基本导入模型，字符仍然只读")
	@RequestMapping(method = RequestMethod.DELETE, value = "/base_import_tests_models_char_stillreadonlies/{base_import_tests_models_char_stillreadonly_id}")
    public ResponseEntity<Boolean> remove(@PathVariable("base_import_tests_models_char_stillreadonly_id") Long base_import_tests_models_char_stillreadonly_id) {
         return ResponseEntity.status(HttpStatus.OK).body(base_import_tests_models_char_stillreadonlyService.remove(base_import_tests_models_char_stillreadonly_id));
    }

    @PreAuthorize("hasPermission(this.base_import_tests_models_char_stillreadonlyService.getBaseImportTestsModelsCharStillreadonlyByIds(#ids),'iBizBusinessCentral-Base_import_tests_models_char_stillreadonly-Remove')")
    @ApiOperation(value = "批量删除测试:基本导入模型，字符仍然只读", tags = {"测试:基本导入模型，字符仍然只读" },  notes = "批量删除测试:基本导入模型，字符仍然只读")
	@RequestMapping(method = RequestMethod.DELETE, value = "/base_import_tests_models_char_stillreadonlies/batch")
    public ResponseEntity<Boolean> removeBatch(@RequestBody List<Long> ids) {
        base_import_tests_models_char_stillreadonlyService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PostAuthorize("hasPermission(this.base_import_tests_models_char_stillreadonlyMapping.toDomain(returnObject.body),'iBizBusinessCentral-Base_import_tests_models_char_stillreadonly-Get')")
    @ApiOperation(value = "获取测试:基本导入模型，字符仍然只读", tags = {"测试:基本导入模型，字符仍然只读" },  notes = "获取测试:基本导入模型，字符仍然只读")
	@RequestMapping(method = RequestMethod.GET, value = "/base_import_tests_models_char_stillreadonlies/{base_import_tests_models_char_stillreadonly_id}")
    public ResponseEntity<Base_import_tests_models_char_stillreadonlyDTO> get(@PathVariable("base_import_tests_models_char_stillreadonly_id") Long base_import_tests_models_char_stillreadonly_id) {
        Base_import_tests_models_char_stillreadonly domain = base_import_tests_models_char_stillreadonlyService.get(base_import_tests_models_char_stillreadonly_id);
        Base_import_tests_models_char_stillreadonlyDTO dto = base_import_tests_models_char_stillreadonlyMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @ApiOperation(value = "获取测试:基本导入模型，字符仍然只读草稿", tags = {"测试:基本导入模型，字符仍然只读" },  notes = "获取测试:基本导入模型，字符仍然只读草稿")
	@RequestMapping(method = RequestMethod.GET, value = "/base_import_tests_models_char_stillreadonlies/getdraft")
    public ResponseEntity<Base_import_tests_models_char_stillreadonlyDTO> getDraft() {
        return ResponseEntity.status(HttpStatus.OK).body(base_import_tests_models_char_stillreadonlyMapping.toDto(base_import_tests_models_char_stillreadonlyService.getDraft(new Base_import_tests_models_char_stillreadonly())));
    }

    @ApiOperation(value = "检查测试:基本导入模型，字符仍然只读", tags = {"测试:基本导入模型，字符仍然只读" },  notes = "检查测试:基本导入模型，字符仍然只读")
	@RequestMapping(method = RequestMethod.POST, value = "/base_import_tests_models_char_stillreadonlies/checkkey")
    public ResponseEntity<Boolean> checkKey(@RequestBody Base_import_tests_models_char_stillreadonlyDTO base_import_tests_models_char_stillreadonlydto) {
        return  ResponseEntity.status(HttpStatus.OK).body(base_import_tests_models_char_stillreadonlyService.checkKey(base_import_tests_models_char_stillreadonlyMapping.toDomain(base_import_tests_models_char_stillreadonlydto)));
    }

    @PreAuthorize("hasPermission(this.base_import_tests_models_char_stillreadonlyMapping.toDomain(#base_import_tests_models_char_stillreadonlydto),'iBizBusinessCentral-Base_import_tests_models_char_stillreadonly-Save')")
    @ApiOperation(value = "保存测试:基本导入模型，字符仍然只读", tags = {"测试:基本导入模型，字符仍然只读" },  notes = "保存测试:基本导入模型，字符仍然只读")
	@RequestMapping(method = RequestMethod.POST, value = "/base_import_tests_models_char_stillreadonlies/save")
    public ResponseEntity<Boolean> save(@RequestBody Base_import_tests_models_char_stillreadonlyDTO base_import_tests_models_char_stillreadonlydto) {
        return ResponseEntity.status(HttpStatus.OK).body(base_import_tests_models_char_stillreadonlyService.save(base_import_tests_models_char_stillreadonlyMapping.toDomain(base_import_tests_models_char_stillreadonlydto)));
    }

    @PreAuthorize("hasPermission(this.base_import_tests_models_char_stillreadonlyMapping.toDomain(#base_import_tests_models_char_stillreadonlydtos),'iBizBusinessCentral-Base_import_tests_models_char_stillreadonly-Save')")
    @ApiOperation(value = "批量保存测试:基本导入模型，字符仍然只读", tags = {"测试:基本导入模型，字符仍然只读" },  notes = "批量保存测试:基本导入模型，字符仍然只读")
	@RequestMapping(method = RequestMethod.POST, value = "/base_import_tests_models_char_stillreadonlies/savebatch")
    public ResponseEntity<Boolean> saveBatch(@RequestBody List<Base_import_tests_models_char_stillreadonlyDTO> base_import_tests_models_char_stillreadonlydtos) {
        base_import_tests_models_char_stillreadonlyService.saveBatch(base_import_tests_models_char_stillreadonlyMapping.toDomain(base_import_tests_models_char_stillreadonlydtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','iBizBusinessCentral-Base_import_tests_models_char_stillreadonly-searchDefault-all') and hasPermission(#context,'iBizBusinessCentral-Base_import_tests_models_char_stillreadonly-Get')")
	@ApiOperation(value = "获取数据集", tags = {"测试:基本导入模型，字符仍然只读" } ,notes = "获取数据集")
    @RequestMapping(method= RequestMethod.GET , value="/base_import_tests_models_char_stillreadonlies/fetchdefault")
	public ResponseEntity<List<Base_import_tests_models_char_stillreadonlyDTO>> fetchDefault(Base_import_tests_models_char_stillreadonlySearchContext context) {
        Page<Base_import_tests_models_char_stillreadonly> domains = base_import_tests_models_char_stillreadonlyService.searchDefault(context) ;
        List<Base_import_tests_models_char_stillreadonlyDTO> list = base_import_tests_models_char_stillreadonlyMapping.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','iBizBusinessCentral-Base_import_tests_models_char_stillreadonly-searchDefault-all') and hasPermission(#context,'iBizBusinessCentral-Base_import_tests_models_char_stillreadonly-Get')")
	@ApiOperation(value = "查询数据集", tags = {"测试:基本导入模型，字符仍然只读" } ,notes = "查询数据集")
    @RequestMapping(method= RequestMethod.POST , value="/base_import_tests_models_char_stillreadonlies/searchdefault")
	public ResponseEntity<Page<Base_import_tests_models_char_stillreadonlyDTO>> searchDefault(@RequestBody Base_import_tests_models_char_stillreadonlySearchContext context) {
        Page<Base_import_tests_models_char_stillreadonly> domains = base_import_tests_models_char_stillreadonlyService.searchDefault(context) ;
	    return ResponseEntity.status(HttpStatus.OK)
                .body(new PageImpl(base_import_tests_models_char_stillreadonlyMapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
	}


}

