package com.chinaweal.aiccs.aicbiz.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chinaweal.aiccs.aicbiz.entity.TbBatchGsDetail;
import com.chinaweal.aiccs.aicbiz.service.TbBatchGsDetailService;
import com.chinaweal.aiccs.aiccs.abnormal.entity.TSWrit;
import com.chinaweal.aiccs.common.base.controller.BaseController;
import com.chinaweal.aiccs.common.util.ConstantsUtil;
import com.chinaweal.aiccs.common.util.DateUtils;
import com.chinaweal.aiccs.common.util.WorkNoUtil;
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
import com.chinaweal.youfool.framework.springboot.util.AssertUtils;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * <p>
 * 47.8批量吊销公示基本信息表 前端控制器
 * </p>
 *
 * @author Lee
 * @since 2022-03-28
 */
@RestController
@RequestMapping("/tbBatchGsDetail")
public class TbBatchGsDetailController extends BaseController {

    @Autowired
    private TbBatchGsDetailService tbBatchGsDetailService;

    /**
     * 批量吊销文书公示信息详情
     * @return 详情结果
     * @author Lee
     * @since 2022年3月28日 14点17分
     */
    @ApiOperation("批量吊销文书公示信息详情")
    @GetMapping("queryRevocationGsDetails")
    public RestResult<?> queryRevocationGsDetails(@RequestParam String writsno) {
        LambdaQueryWrapper<TbBatchGsDetail> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TbBatchGsDetail::getSbookcode, writsno);
        queryWrapper.eq(TbBatchGsDetail::getDelflag, "0");

        List<TbBatchGsDetail> detailList = tbBatchGsDetailService.list(queryWrapper);
        TbBatchGsDetail detail;
        if (detailList.size() == 1) {
            detail = tbBatchGsDetailService.getOne(queryWrapper);
        } else {
            detail = detailList.get(0);
            if (detail.getSmemo().substring(0, 3).equals("当事人")) {
                detail.setSmemo(detail.getSmemo() + detailList.get(1).getSmemo());
            } else {
                detail.setSmemo(detailList.get(1).getSmemo() + detail.getSmemo());
            }
        }

        SimpleDateFormat sbf = new SimpleDateFormat("yyyy年MM月dd日");
        String dateStr = sbf.format(detail.getSdate());
        detail.setWritsTimeStr(dateStr);
        return RestResult.ok(detail);
    }
}

