package com.chinaweal.aiccs.aicbiz.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chinaweal.aiccs.aicbiz.entity.TbBatchGsList;
import com.chinaweal.aiccs.aicbiz.service.TbBatchGsListService;
import com.chinaweal.aiccs.aiccs.revoke.entity.Tsbizrevlist;
import com.chinaweal.aiccs.aiceps.annual.entity.dto.QueryAbnormalDto;
import com.chinaweal.aiccs.common.util.DateUtils;
import com.chinaweal.aiccs.common.util.StringUtils;
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.chinaweal.aiccs.common.base.controller.BaseController;

import javax.swing.text.DateFormatter;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 47.8批量吊销公示文书列表 前端控制器
 * </p>
 *
 * @author Lee
 * @since 2022-03-28
 */
@RestController
@RequestMapping("/tbBatchGsList")
public class TbBatchGsListController extends BaseController {

    @Autowired
    private TbBatchGsListService tbBatchGsListService;

    /**
     * 批吊文书公示按条件查询清单分页
     * @param rows     行数
     * @param page     当前页
     * @param entName  主体名称
     * @param type     文书类型 1查询行政处罚听证告知书；2查询行政处罚决定告知书
     * @return
     */
    @ApiOperation("批吊文书公示按条件查询清单分页")
    @PostMapping("queryRevocationByNamePage")
    public RestResult<?> queryRevocationByNamePage(@RequestBody QueryAbnormalDto queryAbnormalDto) {
        String type = queryAbnormalDto.getType();
        String entName = queryAbnormalDto.getEntName();
        int rows = queryAbnormalDto.getRows();
        int page = queryAbnormalDto.getPage();
        Map<String,Object> pram = new HashMap<>();
        if (StringUtils.isNotBlank(entName)){
            pram.put("entName",entName);
        }

        List<TbBatchGsList> tbBatchGsLists = null;
        if ("1".equals(type) || "2".equals(type)){//1查询行政处罚听证告知书；2查询行政处罚决定告知书
            pram.put("sgstype",type);
            IPage<TbBatchGsList> resultPage = tbBatchGsListService.queryRevokeWritsByName(new Page<>(page, rows),pram);
            tbBatchGsLists = resultPage.getRecords();
            if(CollectionUtils.isNotEmpty(tbBatchGsLists)) {
                for (TbBatchGsList tbBatchGsList : tbBatchGsLists) {
//                    String tswritTime = DateUtils.localDateFormat(tbBatchGsList.getSpublictime().toLocalDate(), "yyyy年MM月dd日");
//                    tbBatchGsList.setWritsTimeStr(tswritTime);
                    SimpleDateFormat sbf = new SimpleDateFormat("yyyy年MM月dd日");
                    String dateStr = sbf.format(tbBatchGsList.getSpublictime());
                    tbBatchGsList.setWritsTimeStr(dateStr);
                }


            }
            return RestResult.ok(resultPage);
        }
        return RestResult.ok(new Page<TbBatchGsList>());
    }
}

