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_mro.domain.Mro_convert_order;
import cn.ibizlab.businesscentral.core.odoo_mro.service.IMro_convert_orderService;
import cn.ibizlab.businesscentral.core.odoo_mro.filter.Mro_convert_orderSearchContext;
import cn.ibizlab.businesscentral.util.annotation.VersionCheck;

@Slf4j
@Api(tags = {"Convert Order to Task" })
@RestController("Core-mro_convert_order")
@RequestMapping("")
public class Mro_convert_orderResource {

    @Autowired
    public IMro_convert_orderService mro_convert_orderService;

    @Autowired
    @Lazy
    public Mro_convert_orderMapping mro_convert_orderMapping;

    @PreAuthorize("hasPermission(this.mro_convert_orderMapping.toDomain(#mro_convert_orderdto),'iBizBusinessCentral-Mro_convert_order-Create')")
    @ApiOperation(value = "新建Convert Order to Task", tags = {"Convert Order to Task" },  notes = "新建Convert Order to Task")
	@RequestMapping(method = RequestMethod.POST, value = "/mro_convert_orders")
    public ResponseEntity<Mro_convert_orderDTO> create(@Validated @RequestBody Mro_convert_orderDTO mro_convert_orderdto) {
        Mro_convert_order domain = mro_convert_orderMapping.toDomain(mro_convert_orderdto);
		mro_convert_orderService.create(domain);
        Mro_convert_orderDTO dto = mro_convert_orderMapping.toDto(domain);
		return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.mro_convert_orderMapping.toDomain(#mro_convert_orderdtos),'iBizBusinessCentral-Mro_convert_order-Create')")
    @ApiOperation(value = "批量新建Convert Order to Task", tags = {"Convert Order to Task" },  notes = "批量新建Convert Order to Task")
	@RequestMapping(method = RequestMethod.POST, value = "/mro_convert_orders/batch")
    public ResponseEntity<Boolean> createBatch(@RequestBody List<Mro_convert_orderDTO> mro_convert_orderdtos) {
        mro_convert_orderService.createBatch(mro_convert_orderMapping.toDomain(mro_convert_orderdtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @VersionCheck(entity = "mro_convert_order" , versionfield = "writeDate")
    @PreAuthorize("hasPermission(this.mro_convert_orderService.get(#mro_convert_order_id),'iBizBusinessCentral-Mro_convert_order-Update')")
    @ApiOperation(value = "更新Convert Order to Task", tags = {"Convert Order to Task" },  notes = "更新Convert Order to Task")
	@RequestMapping(method = RequestMethod.PUT, value = "/mro_convert_orders/{mro_convert_order_id}")
    public ResponseEntity<Mro_convert_orderDTO> update(@PathVariable("mro_convert_order_id") Long mro_convert_order_id, @RequestBody Mro_convert_orderDTO mro_convert_orderdto) {
		Mro_convert_order domain  = mro_convert_orderMapping.toDomain(mro_convert_orderdto);
        domain .setId(mro_convert_order_id);
		mro_convert_orderService.update(domain );
		Mro_convert_orderDTO dto = mro_convert_orderMapping.toDto(domain );
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }

    @PreAuthorize("hasPermission(this.mro_convert_orderService.getMroConvertOrderByEntities(this.mro_convert_orderMapping.toDomain(#mro_convert_orderdtos)),'iBizBusinessCentral-Mro_convert_order-Update')")
    @ApiOperation(value = "批量更新Convert Order to Task", tags = {"Convert Order to Task" },  notes = "批量更新Convert Order to Task")
	@RequestMapping(method = RequestMethod.PUT, value = "/mro_convert_orders/batch")
    public ResponseEntity<Boolean> updateBatch(@RequestBody List<Mro_convert_orderDTO> mro_convert_orderdtos) {
        mro_convert_orderService.updateBatch(mro_convert_orderMapping.toDomain(mro_convert_orderdtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PreAuthorize("hasPermission(this.mro_convert_orderService.get(#mro_convert_order_id),'iBizBusinessCentral-Mro_convert_order-Remove')")
    @ApiOperation(value = "删除Convert Order to Task", tags = {"Convert Order to Task" },  notes = "删除Convert Order to Task")
	@RequestMapping(method = RequestMethod.DELETE, value = "/mro_convert_orders/{mro_convert_order_id}")
    public ResponseEntity<Boolean> remove(@PathVariable("mro_convert_order_id") Long mro_convert_order_id) {
         return ResponseEntity.status(HttpStatus.OK).body(mro_convert_orderService.remove(mro_convert_order_id));
    }

    @PreAuthorize("hasPermission(this.mro_convert_orderService.getMroConvertOrderByIds(#ids),'iBizBusinessCentral-Mro_convert_order-Remove')")
    @ApiOperation(value = "批量删除Convert Order to Task", tags = {"Convert Order to Task" },  notes = "批量删除Convert Order to Task")
	@RequestMapping(method = RequestMethod.DELETE, value = "/mro_convert_orders/batch")
    public ResponseEntity<Boolean> removeBatch(@RequestBody List<Long> ids) {
        mro_convert_orderService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    @PostAuthorize("hasPermission(this.mro_convert_orderMapping.toDomain(returnObject.body),'iBizBusinessCentral-Mro_convert_order-Get')")
    @ApiOperation(value = "获取Convert Order to Task", tags = {"Convert Order to Task" },  notes = "获取Convert Order to Task")
	@RequestMapping(method = RequestMethod.GET, value = "/mro_convert_orders/{mro_convert_order_id}")
    public ResponseEntity<Mro_convert_orderDTO> get(@PathVariable("mro_convert_order_id") Long mro_convert_order_id) {
        Mro_convert_order domain = mro_convert_orderService.get(mro_convert_order_id);
        Mro_convert_orderDTO dto = mro_convert_orderMapping.toDto(domain);
        return ResponseEntity.status(HttpStatus.OK).body(dto);
    }


}

