package com.chinaweal.aiccs.aiccs.fraudreg.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.chinaweal.aiccs.aiccs.abnormal.service.EBaseinfoService;
import com.chinaweal.aiccs.aiccs.fraudreg.entity.VFraudInfo;
import com.chinaweal.aiccs.aiccs.fraudreg.service.IVFraudInfoService;
import com.chinaweal.aiccs.aiccs.seriousillegal.entity.TSSerIllegalList;
import com.chinaweal.aiccs.common.util.StringUtils;
import com.chinaweal.aiccs.crgs.moveinDetails.entity.EAlterRecoder;
import com.chinaweal.youfool.framework.springboot.base.query.BaseQuery;
import com.chinaweal.youfool.framework.springboot.mybatis.plus.page.PageRequestDto;
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
import com.chinaweal.youfool.framework.springboot.util.AssertUtils;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.chinaweal.aiccs.aiccs.fraudreg.entity.TFraudEnt;
import com.chinaweal.aiccs.aiccs.fraudreg.service.ITFraudEntService;
import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 涉嫌冒用他人身份取得登记主体信息表 控制器
 * </p>
 *
 * @author chinaweal
 * @since 2021-11-11
 */
@Api(tags = "涉嫌冒用他人身份取得登记主体信息表")
@ApiSort(1)
@RestController
@RequestMapping("/fraudReg/tFraudEnt")
public class TFraudEntController {

    @Resource
    private ITFraudEntService iTFraudEntService;
    @Resource
    private IVFraudInfoService ivFraudInfoService;
        @Autowired
    private EBaseinfoService eBaseinfoService;

    @ApiOperation(value = "1.新增涉嫌冒用他人身份取得登记主体信息表", position = 1)
    @PostMapping("/save")
    public RestResult<TFraudEnt> saveTFraudEnt(@RequestBody @Valid TFraudEnt tFraudEnt, BindingResult bindingResult) {
        AssertUtils.isBndingValidit(bindingResult);
        tFraudEnt = iTFraudEntService.saveTFraudEnt(tFraudEnt);
        return RestResult.ok(tFraudEnt);
    }

    @ApiOperation(value = "2.删除涉嫌冒用他人身份取得登记主体信息表", position = 2)
    @PostMapping("/delete")
    public RestResult<String> removeTFraudEnt(@RequestParam @ApiParam("id") Serializable id) {
        iTFraudEntService.removeById(id);
        return RestResult.ok();
    }

    @ApiOperation(value = "3.修改涉嫌冒用他人身份取得登记主体信息表", position = 3)
    @PostMapping("/update")
    public RestResult<String> updateTFraudEnt(@RequestBody @Valid TFraudEnt tFraudEnt, BindingResult bindingResult) {
        AssertUtils.isBndingValidit(bindingResult);
        iTFraudEntService.updateTFraudEnt(tFraudEnt);
        return RestResult.ok();
    }

    @ApiOperation(value = "4.查询涉嫌冒用他人身份取得登记主体信息表", position = 4)
    @GetMapping("/get")
    public RestResult<TFraudEnt> getTFraudEnt(@RequestParam @ApiParam("id") Serializable id) {
        TFraudEnt tFraudEnt = iTFraudEntService.getById(id);
        return RestResult.ok(tFraudEnt);
    }

    @ApiOperation(value = "5.分页查询涉嫌冒用他人身份取得登记主体信息表", position = 5)
    @PostMapping("/list")
    public RestResult<IPage<VFraudInfo>> listTFraudEnt(@RequestBody PageRequestDto pageRequestDto) {
        IPage<VFraudInfo> data = ivFraudInfoService.defaultPaging(pageRequestDto, wrapper -> {

            Map<String, Object> customParamMap = pageRequestDto.getCustomParamMap();
            if(customParamMap == null) return;

            //投诉时间自定义处理
            String createTime = StringUtils.tranObject(customParamMap.get("createTime"));
            if(StringUtils.isNotBlank(createTime)){
                wrapper.lambda().ge(VFraudInfo::getCreateTime, createTime.split(",")[0]).le(VFraudInfo::getCreateTime, createTime.split(",")[1] + " 23:59:59");
            }

            //决定日期自定义处理
            String judDate = StringUtils.tranObject(customParamMap.get("judDate"));
            if(StringUtils.isNotBlank(judDate)){
                wrapper.lambda().ge(VFraudInfo::getJudDate, judDate.split(",")[0]).le(VFraudInfo::getJudDate, judDate.split(",")[1]);
            }

        }, null);
        return RestResult.ok(data);
    }

    @ApiOperation(value = "6.查询涉嫌冒用他人身份取得登记主体信息表", position = 6)
    @GetMapping("/getBybizSeq")
    public RestResult<TFraudEnt> getBybizSeq(@RequestParam @ApiParam("业务主键") String bizSeq) {
        TFraudEnt tFraudEnt = iTFraudEntService.getByBizSeq(bizSeq);

        return RestResult.ok(tFraudEnt);
    }
}
