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_account.domain.Account_chart_template;
import cn.ibizlab.businesscentral.core.odoo_account.service.IAccount_chart_templateService;
import cn.ibizlab.businesscentral.core.odoo_account.filter.Account_chart_templateSearchContext;
import cn.ibizlab.businesscentral.util.annotation.VersionCheck;

@Slf4j
@Api(tags = {"科目表模版" })
@RestController("Core-account_chart_template")
@RequestMapping("")
public class Account_chart_templateResource {

    @Autowired
    public IAccount_chart_templateService account_chart_templateService;

    @Autowired
    @Lazy
    public Account_chart_templateMapping account_chart_templateMapping;

    @PreAuthorize("hasPermission(this.account_chart_templateMapping.toDomain(#account_chart_templatedto),'iBizBusinessCentral-Account_chart_template-Create')")
    @ApiOperation(value = "新建科目表模版", tags = {"科目表模版" },  notes = "新建科目表模版")
	@RequestMapping(method = RequestMethod.POST, value = "/account_chart_templates")
    public ResponseEntity<Account_chart_templateDTO> create(@Validated @RequestBody Account_chart_templateDTO account_chart_templatedto) {
        Account_chart_template domain = account_chart_templateMapping.toDomain(account_chart_templatedto);
		account_chart_templateService.create(domain);
        Account_chart_templateDTO dto = account_chart_templateMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.account_chart_templateMapping.toDomain(#account_chart_templatedtos),'iBizBusinessCentral-Account_chart_template-Create')")
    @ApiOperation(value = "批量新建科目表模版", tags = {"科目表模版" },  notes = "批量新建科目表模版")
	@RequestMapping(method = RequestMethod.POST, value = "/account_chart_templates/batch")
    public ResponseEntity<Boolean> createBatch(@RequestBody List<Account_chart_templateDTO> account_chart_templatedtos) {
        account_chart_templateService.createBatch(account_chart_templateMapping.toDomain(account_chart_templatedtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "account_chart_template" , versionfield = "writeDate")
    @PreAuthorize("hasPermission(this.account_chart_templateService.get(#account_chart_template_id),'iBizBusinessCentral-Account_chart_template-Update')")
    @ApiOperation(value = "更新科目表模版", tags = {"科目表模版" },  notes = "更新科目表模版")
	@RequestMapping(method = RequestMethod.PUT, value = "/account_chart_templates/{account_chart_template_id}")
    public ResponseEntity<Account_chart_templateDTO> update(@PathVariable("account_chart_template_id") Long account_chart_template_id, @RequestBody Account_chart_templateDTO account_chart_templatedto) {
		Account_chart_template domain  = account_chart_templateMapping.toDomain(account_chart_templatedto);
        domain .setId(account_chart_template_id);
		account_chart_templateService.update(domain );
		Account_chart_templateDTO dto = account_chart_templateMapping.toDto(domain );
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.account_chart_templateService.getAccountChartTemplateByEntities(this.account_chart_templateMapping.toDomain(#account_chart_templatedtos)),'iBizBusinessCentral-Account_chart_template-Update')")
    @ApiOperation(value = "批量更新科目表模版", tags = {"科目表模版" },  notes = "批量更新科目表模版")
	@RequestMapping(method = RequestMethod.PUT, value = "/account_chart_templates/batch")
    public ResponseEntity<Boolean> updateBatch(@RequestBody List<Account_chart_templateDTO> account_chart_templatedtos) {
        account_chart_templateService.updateBatch(account_chart_templateMapping.toDomain(account_chart_templatedtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.account_chart_templateService.get(#account_chart_template_id),'iBizBusinessCentral-Account_chart_template-Remove')")
    @ApiOperation(value = "删除科目表模版", tags = {"科目表模版" },  notes = "删除科目表模版")
	@RequestMapping(method = RequestMethod.DELETE, value = "/account_chart_templates/{account_chart_template_id}")
    public ResponseEntity<Boolean> remove(@PathVariable("account_chart_template_id") Long account_chart_template_id) {
         return ResponseEntity.status(HttpStatus.OK).body(account_chart_templateService.remove(account_chart_template_id));
    }

    @PreAuthorize("hasPermission(this.account_chart_templateService.getAccountChartTemplateByIds(#ids),'iBizBusinessCentral-Account_chart_template-Remove')")
    @ApiOperation(value = "批量删除科目表模版", tags = {"科目表模版" },  notes = "批量删除科目表模版")
	@RequestMapping(method = RequestMethod.DELETE, value = "/account_chart_templates/batch")
    public ResponseEntity<Boolean> removeBatch(@RequestBody List<Long> ids) {
        account_chart_templateService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PostAuthorize("hasPermission(this.account_chart_templateMapping.toDomain(returnObject.body),'iBizBusinessCentral-Account_chart_template-Get')")
    @ApiOperation(value = "获取科目表模版", tags = {"科目表模版" },  notes = "获取科目表模版")
	@RequestMapping(method = RequestMethod.GET, value = "/account_chart_templates/{account_chart_template_id}")
    public ResponseEntity<Account_chart_templateDTO> get(@PathVariable("account_chart_template_id") Long account_chart_template_id) {
        Account_chart_template domain = account_chart_templateService.get(account_chart_template_id);
        Account_chart_templateDTO dto = account_chart_templateMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }


}

