package com.chinaweal.aiccs.aiccs.punishment.controller;


import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chinaweal.aiccs.aiccs.abnormal.entity.EBaseinfo;
import com.chinaweal.aiccs.aiccs.abnormal.mapper.EBaseinfoMapper;
import com.chinaweal.aiccs.aiccs.business.entity.TSTaskList;
import com.chinaweal.aiccs.aiccs.business.mapper.TSTaskListMapper;
import com.chinaweal.aiccs.aiccs.punishment.entity.EntLock;
import com.chinaweal.aiccs.aiccs.punishment.entity.PunishmentMeasureFeedbackLog;
import com.chinaweal.aiccs.aiccs.punishment.entity.dto.FeedbackLogPageSearchDto;
import com.chinaweal.aiccs.aiccs.punishment.entity.dto.PersonEntDto;
import com.chinaweal.aiccs.aiccs.punishment.entity.excel.EntLockExcel;
import com.chinaweal.aiccs.aiccs.punishment.entity.vo.PunishmentSearchResultVO;
import com.chinaweal.aiccs.aiccs.punishment.mapper.EntlockMapper;
import com.chinaweal.aiccs.aiccs.punishment.mapper.PersonEntMapper;
import com.chinaweal.aiccs.aiccs.punishment.service.*;
import com.chinaweal.aiccs.aiccs.punishment.util.ParamUtils;
import com.chinaweal.aiccs.common.base.controller.BaseController;
import com.chinaweal.aiccs.common.constant.Constant;
import com.chinaweal.aiccs.common.util.StringUtils;
import com.chinaweal.aiccs.org.entity.OrgUnits;
import com.chinaweal.aiccs.org.mapper.AicorgMapper;
import com.chinaweal.aicorg.model.AICUser;
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.rest.ResultCode;
import com.chinaweal.youfool.framework.springboot.util.AssertUtils;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * <p>
 * 业户锁定 前端控制器
 * </p>
 *
 * @author Lee
 * @since 2021-06-06
 */
@RestController
@RequestMapping("/entlock")
public class EntlockController extends BaseController {

    @Autowired
    private EntlockService entLockService;

    @Autowired
    private PersonlockService personlockService;

    @Autowired
    private PersonEntService personEntService;

    @Autowired
    private AicorgMapper aicorgMapper;

    @Autowired
    private EBaseinfoMapper eBaseinfoMapper;

    @Autowired
    private EntlockMapper entlockMapper;

    @Autowired
    private PersonEntMapper personEntMapper;

    @Autowired
    private TSTaskListMapper tsTaskListMapper;
    @Autowired
    private JointPunishmentApiService jointPunishmentApiService;
    @Autowired
    private IPunishmentMeasureFeedbackLogService punishmentMeasureFeedbackLogService;

    @PostMapping("toUnLockEntListPage")
    public RestResult<?> toUnLockEntListPage(@RequestBody PageRequestDto pageRequestDto, HttpServletRequest request) {

        IPage<PersonEntDto> query = null;
        Map<String, Object> customParamMap = pageRequestDto.getCustomParamMap();
        AICUser curUser = getLoginUser(request);
        customParamMap = ParamUtils.getRegorg(customParamMap, curUser);
        String regorg1 = "";
        String regorg2 = "";
        String searchCode = "";
        String searchEntName = "";
        String searchLockType = "";
        String unisicd = "";
        String regno = "";

        if (customParamMap != null) {
            regorg1 = (String) customParamMap.get("regorg1");
            regorg2 = (String) customParamMap.get("regorg2");
            searchCode = (String) customParamMap.get("searchCode");
            searchEntName = (String) customParamMap.get("searchEntName");
            searchLockType = (String) customParamMap.get("searchLockType");

//            regorg1 = StringUtils.tranObject(customParamMap.get("regorg1"));
//            regorg2 = StringUtils.tranObject(customParamMap.get("regorg2"));
//            searchCode = StringUtils.tranObject(customParamMap.get("searchCode"));
//            searchEntName = StringUtils.tranObject(customParamMap.get("searchEntName"));
//            searchLockType = StringUtils.tranObject(customParamMap.get("searchLockType"));
        }
        if (StringUtils.isNotBlank(searchCode)) {
            if (StringUtils.isUscc(searchCode)) {
                unisicd = searchCode;
            } else {
                regno = searchCode;
            }
        }
//        LambdaQueryWrapper<PersonEntDto> queryWrapper= new LambdaQueryWrapper<>();
//        queryWrapper.eq(PersonEntDto::getEntname,searchEntName);
//        queryWrapper.eq(PersonEntDto::getLocktype,searchLockType);
//        String finalSearchCode = searchCode;
//        queryWrapper.and(LambdaQueryWrapper ->LambdaQueryWrapper.eq(PersonEntDto::getUniscid, finalSearchCode).or().eq(PersonEntDto::getRegno,finalSearchCode));
        if ("440101".equals(regorg1)) {
            query = personEntService.query(new Page<>(pageRequestDto.getCurPage(), pageRequestDto.getPageSize()), "%%", searchEntName, searchLockType, searchCode);

//            queryWrapper.and(LambdaQueryWrapper ->LambdaQueryWrapper.eq(PersonEntDto::getRegorg, null).or().like(PersonEntDto::getRegorg,"%%"));
//            query = personEntService.page(new Page<>(pageRequestDto.getCurPage(), pageRequestDto.getPageSize()),queryWrapper);

//            personEntDtos = personEntMapper.queryEnt("440101", searchEntName, searchLockType, searchCode);
//            personEntDtos1 = personEntMapper.queryPerson("440101", searchEntName, searchCode);
        } else {
            query = personEntService.query(new Page<>(pageRequestDto.getCurPage(), pageRequestDto.getPageSize()), regorg1, searchEntName, searchLockType, searchCode);
//            personEntDtos = personEntMapper.queryEnt("%%", searchEntName, searchLockType, searchCode);
//            personEntDtos1 = personEntMapper.queryPerson("%%", searchEntName, searchCode);
//            String finalRegorg = regorg1;
//            queryWrapper.and(LambdaQueryWrapper ->LambdaQueryWrapper.eq(PersonEntDto::getRegorg, null).or().like(PersonEntDto::getRegorg, finalRegorg));
//            query = personEntService.page(new Page<>(pageRequestDto.getCurPage(), pageRequestDto.getPageSize()),queryWrapper);
        }
        return RestResult.ok(query);


//        LambdaQueryWrapper<EntLock> wrapper = new LambdaQueryWrapper<>();
//        LambdaQueryWrapper<Personlock> personwrapper = new LambdaQueryWrapper<>();
//
//            if ("440101".equals(regorg1)) {
//
//                wrapper.eq(StringUtils.isNotBlank(regno), EntLock::getRegno, regno)
//                        .eq(StringUtils.isNotBlank(unisicd), EntLock::getUniscid, unisicd)
//                        .like(StringUtils.isNotBlank(searchEntName), EntLock::getEntname, searchEntName)
//                .eq(StringUtils.isNotBlank(searchEntName),EntLock::getEntname,searchEntName)
//                .eq(StringUtils.isNotBlank(searchLockType),EntLock::getLocktype,searchLockType)
//                 .likeRight(StringUtils.isNotBlank(regorg1),EntLock::getRegorg,regorg1)
//                    .eq(StringUtils.isNotBlank(regorg2),EntLock::getRegorg,regorg2)
//                        .eq(EntLock::getState, "0")
//                        .orderByDesc(EntLock::getLockTime).orderByDesc(EntLock::getUniscid);
//            } else {
//                wrapper.eq(StringUtils.isNotBlank(regno), EntLock::getRegno, regno)
//                        .eq(StringUtils.isNotBlank(unisicd), EntLock::getUniscid, unisicd)
//                        .like(StringUtils.isNotBlank(searchEntName), EntLock::getEntname, searchEntName)
//                .eq(StringUtils.isNotBlank(searchEntName),EntLock::getEntname,searchEntName)
//                .eq(StringUtils.isNotBlank(searchLockType),EntLock::getLocktype,searchLockType)
//                        .eq(StringUtils.isNotBlank(regorg1), EntLock::getRegorg, regorg1)
//                        //.likeRight(StringUtils.isNotBlank(regorg1),EntLock::getRegorg,regorg1)
//                        .eq(StringUtils.isNotBlank(regorg2), EntLock::getRegorg, regorg2)
//                        .eq(EntLock::getState, "0")
//                        .orderByDesc(EntLock::getLockTime).orderByDesc(EntLock::getUniscid);
//            }
//        if ("440101".equals(regorg1)) {
//            personwrapper.eq(StringUtils.isNotBlank(regno), Personlock::getRegno, regno)
//                    .like(StringUtils.isNotBlank(searchEntName), Personlock::getEntname, searchEntName)
//                    .eq(Personlock::getLockstate, "1")
//                    .orderByDesc(Personlock::getLockstartdate).orderByDesc(Personlock::getRegno);
//        }else{
//            personwrapper.eq(StringUtils.isNotBlank(regno), Personlock::getRegno, regno)
//                    .like(StringUtils.isNotBlank(searchEntName), Personlock::getEntname, searchEntName)
//                    //.eq(StringUtils.isNotBlank(regorg1), EntLock::getRegorg, regorg1)
//                    //.eq(StringUtils.isNotBlank(regorg2), EntLock::getRegorg, regorg2)
//                    .eq(Personlock::getLockstate, "1")
//                    .orderByDesc(Personlock::getLockstartdate).orderByDesc(Personlock::getRegno);
//        }


//        Page<EntLock> entpage = entLockService.page(new Page<>(pageRequestDto.getCurPage(), pageRequestDto.getPageSize()), wrapper);
//        Page<Personlock> personpage = personlockService.page(new Page<>(pageRequestDto.getCurPage(), pageRequestDto.getPageSize()), personwrapper);
//        hashMap.put("entpage",entpage);
//        hashMap.put("personpage",personpage);
//        return RestResult.ok(hashMap);
        // return RestResult.ok(entpage);

    }

    @PostMapping("entlockListPage")
    public RestResult<?> entlockListPage(@RequestBody PageRequestDto pageRequestDto, HttpServletRequest request) {

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

        AICUser curUser = getLoginUser(request);
        customParamMap = ParamUtils.getRegorg(customParamMap, curUser);

        String regorg1 = "";
        String regorg2 = "";
        String representative = "";
        String uLSRCode = "";
        String measure = "";
        String searchCode = "";
        String searchEntName = "";
        String searchLockType = "";
        String unisicd = "";
        String regno = "";
        String searchLockDate = "";
        String beginLockDate = "";
        String endLockDate = "";
        String beginUnlockDate = "";
        String endUnlockDate = "";
        String searchPunishFrom = "";
        String searchDepart = "";
        String[] departs = new String[]{};
        String method = "";
        String lockusername = "";
        String state = "";
        String punishstatus = "";
        String lockreason = "";
        String lockdepartment = "";

        if (customParamMap != null) {
            regorg1 = StringUtils.tranObject(customParamMap.get("regorg1"));
            regorg2 = StringUtils.tranObject(customParamMap.get("regorg2"));
            representative = StringUtils.tranObject(customParamMap.get("representative"));
            uLSRCode = StringUtils.tranObject(customParamMap.get("uLSRCode"));
            measure = StringUtils.tranObject(customParamMap.get("measure"));
            searchCode = StringUtils.tranObject(customParamMap.get("searchCode"));
            searchEntName = StringUtils.tranObject(customParamMap.get("searchEntName"));
            searchLockType = StringUtils.tranObject(customParamMap.get("searchLockType"));
            searchLockDate = StringUtils.tranObject(customParamMap.get("searchLockDate"));
            searchPunishFrom = StringUtils.tranObject(customParamMap.get("searchPunishFrom"));
            beginLockDate = StringUtils.tranObject(customParamMap.get("beginLockDate"));
            endLockDate = StringUtils.tranObject(customParamMap.get("endLockDate"));
            beginUnlockDate = StringUtils.tranObject(customParamMap.get("beginUnlockDate"));
            endUnlockDate = StringUtils.tranObject(customParamMap.get("endUnlockDate"));
            searchDepart = StringUtils.tranObject(customParamMap.get("searchDepart"));
            lockusername = StringUtils.tranObject(customParamMap.get("lockperson"));
            lockreason = StringUtils.tranObject(customParamMap.get("lockreason"));
            lockdepartment = StringUtils.tranObject(customParamMap.get("lockdepartment"));
            punishstatus = StringUtils.tranObject(customParamMap.get("punishstatus"));
            method = StringUtils.tranObject(customParamMap.get("method"));
        }
        if ("1".equals(punishstatus)) {
            state = "0";
        } else if ("0".equals(punishstatus)) {
            state = "3";
        }
        if ("1".equals(method) && "".equals(lockusername)) {
//            if("1".equals(punishstatus)){
//                lockusername="自动锁定";
//            }else if("0".equals(punishstatus)){
//                lockusername="自动解锁";
//            }
            lockusername = "信用风险监管处";
        }
        if (StringUtils.isNotBlank(searchCode)) {
            if (StringUtils.isUscc(searchCode)) {
                unisicd = searchCode;
            } else {
                regno = searchCode;
            }
        }
        if (StringUtils.isNotBlank(searchDepart)) {
            departs = StringUtils.split(searchDepart, Constant.COMMA);
        }

        LambdaQueryWrapper<EntLock> wrapper = new LambdaQueryWrapper<>();

        wrapper.eq(StringUtils.isNotBlank(regno), EntLock::getRegno, regno)
                .eq(StringUtils.isNotBlank(unisicd), EntLock::getUniscid, unisicd)
                .like(StringUtils.isNotBlank(searchEntName), EntLock::getEntname, searchEntName)
                .eq(StringUtils.isNotBlank(searchLockType), EntLock::getLocktype, searchLockType)
                //.eq(StringUtils.isNotBlank(searchPunishFrom),EntLock::getPunishFrom,searchPunishFrom)
                .between(StringUtils.isNotBlank(beginLockDate) && StringUtils.isNotBlank(endLockDate), EntLock::getLockTime, beginLockDate, endLockDate)
                .between(StringUtils.isNotBlank(beginUnlockDate) && StringUtils.isNotBlank(endUnlockDate), EntLock::getUnlockTime, beginUnlockDate, endUnlockDate)
                .in(departs.length > 0, EntLock::getPunishFrom, Arrays.asList(departs))
                //.likeRight(StringUtils.isNotBlank(regorg1),EntLock::getRegorg,regorg1)
                //.eq(StringUtils.isNotBlank(regorg2),EntLock::getRegorg,regorg2)
                .eq(StringUtils.isNotBlank(measure), EntLock::getMeasure, measure)
                .eq(StringUtils.isNotBlank(representative), EntLock::getRepresentative, representative)
                .eq(StringUtils.isNotBlank(uLSRCode), EntLock::getULSRCode, uLSRCode)
                .eq(StringUtils.isNotBlank(lockreason), EntLock::getLockreason, lockreason)
                .eq(StringUtils.isNotBlank(state), EntLock::getState, state)
                .eq(StringUtils.isNotBlank(lockdepartment), EntLock::getDepartment, lockdepartment)
                .orderByDesc(EntLock::getLockTime);

        if ("1".equals(punishstatus)) {
            wrapper.like(StringUtils.isNotBlank(lockusername), EntLock::getLockusername, lockusername);
            if ("0".equals(method)) {
                wrapper.and(LambdaQueryWrapper -> LambdaQueryWrapper.ne(EntLock::getLockusername, "信用风险监管处"));
            }


        } else if ("0".equals(punishstatus)) {
            wrapper.like(StringUtils.isNotBlank(lockusername), EntLock::getUnlusername, lockusername);
            if ("0".equals(method)) {
                wrapper.and(LambdaQueryWrapper -> LambdaQueryWrapper.ne(EntLock::getUnlusername, "信用风险监管处"));
            }
            //}
        } else {
            if ("1".equals(method)) {
                String finalLockusername = lockusername;
                wrapper.and(LambdaQueryWrapper -> LambdaQueryWrapper.like(EntLock::getLockusername, finalLockusername).or().like(EntLock::getUnlusername, finalLockusername));
                wrapper.and(LambdaQueryWrapper -> LambdaQueryWrapper.like(EntLock::getLockusername, "信用风险监管处").or().like(EntLock::getUnlusername, "信用风险监管处"));
            } else if ("0".equals(method)) {
                String finalLockusername = lockusername;
                wrapper.and(LambdaQueryWrapper -> LambdaQueryWrapper.like(EntLock::getLockusername, finalLockusername).or().like(EntLock::getUnlusername, finalLockusername));
                wrapper.ne(EntLock::getLockusername, "信用风险监管处");
                wrapper.ne(EntLock::getUnlusername, "信用风险监管处");
            }

        }
        if (!"440101".equals(regorg1)) {
            wrapper.eq(StringUtils.isNotBlank(regorg1), EntLock::getRegorg, regorg1);
        }
        Page<EntLock> page = entLockService.page(new Page<>(pageRequestDto.getCurPage(), pageRequestDto.getPageSize()), wrapper);
        return RestResult.ok(page);

    }

    @RequestMapping("/queryEntlockOne")
    public RestResult<?> queryOne(String pripid) {
        List<EntLock> entLock = entLockService.queryByPripid(pripid);
        return RestResult.ok(entLock);
    }

    @RequestMapping(value = "exportExcel", method = {RequestMethod.POST}, produces = {"application/vnd.ms-excel;" +
            "charset=UTF-8"})
    public void exportExcel(@RequestBody PageRequestDto pageRequestDto, HttpServletRequest request, HttpServletResponse response) throws IOException {
        ServletOutputStream outputStream = null;
        Map<String, Object> customParamMap = pageRequestDto.getCustomParamMap();
        AICUser curUser = getLoginUser(request);
        customParamMap = ParamUtils.getRegorg(customParamMap, curUser);
        List<EntLockExcel> entLockExcels = entLockService.queryForExcel(new Page<>(pageRequestDto.getCurPage(), pageRequestDto.getPageSize()), customParamMap);
        try {
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setHeader("Content-Disposition",
                    "attachment;filename=" + new String("导入失败数据.xls".getBytes(), "UTF-8"));
            response.setContentType("application/msexcel;charset=UTF-8");
            outputStream = response.getOutputStream();
            ExcelWriter excelWriter = EasyExcel.write(outputStream).build();
            WriteSheet writeSheet1 = EasyExcel.writerSheet(0, "sheet1").head(EntLockExcel.class).build();
            excelWriter.write(entLockExcels, writeSheet1);
            excelWriter.finish();
        } catch (IOException e) {
            outputStream.close();
            e.printStackTrace();
        } finally {
            outputStream.close();
        }
    }

    @PostMapping("/list")
    public RestResult<?> list(@RequestBody Map<String, Object> data) {
        Map<String, Object> map = new HashMap<>();
        int size = (int) data.getOrDefault("size", 10);
        int current = (int) data.getOrDefault("current", 1);
        String type = (String) data.getOrDefault("type", null);
        String department = (String) data.getOrDefault("department", null);
        List<String> states = (List) data.getOrDefault("states", null);
        String beginDate = (String) data.getOrDefault("beginDate", null);
        //String endLockDate = (String) data.getOrDefault("endLockDate",null);
        //String beginUnlockDate = (String) data.getOrDefault("beginUnlockDate",null);
        String endDate = (String) data.getOrDefault("endDate", null);
        String finalBeginDate = beginDate;
        String finalEndDate = endDate;
        LambdaQueryWrapper<EntLock> lqw = Wrappers.lambdaQuery();
        if ("autolocked".equals(type)) {
            lqw.eq(StringUtils.isNotBlank(type), EntLock::getLockusername, "信用风险监管处");
        } else if ("manuallocked".equals(type)) {
            lqw.ne(StringUtils.isNotBlank(type), EntLock::getLockusername, "信用风险监管处");
        } else if ("autounlocked".equals(type)) {
            lqw.eq(StringUtils.isNotBlank(type), EntLock::getUnlusername, "信用风险监管处");
        } else if ("manualunlocked".equals(type)) {
            lqw.ne(StringUtils.isNotBlank(type), EntLock::getUnlusername, "信用风险监管处");
        }
        lqw.eq(StringUtils.isNotBlank(department), EntLock::getDepartment, department);
        lqw.in((states != null) && states.size() > 0, EntLock::getState, states);
        if (StringUtils.isNotBlank(finalBeginDate) && StringUtils.isNotBlank(finalEndDate)) {
            lqw.and(LambdaQueryWrapper -> LambdaQueryWrapper.between(EntLock::getLockTime, finalBeginDate, finalEndDate).
                    or().between(EntLock::getUnlockTime, finalBeginDate, finalEndDate));
        }

//        lqw.between(StringUtils.isNotBlank(beginDate)&&StringUtils.isNotBlank(endDate),EntLock::getLockTime,beginDate,endDate);
//        lqw.between(StringUtils.isNotBlank(beginDate)&&StringUtils.isNotBlank(endDate),EntLock::getUnlockTime,beginDate,endDate);
        List<Map> selectlocktime = entlockMapper.selectlocktime(department);

        //lqw.groupBy(EntLock::getEntname);
        //QueryWrapper<EntLock> l=new QueryWrapper();
        //l.eq("state","0").groupBy("entname");
        //l.eq(StringUtils.isNotBlank(department), EntLock::getDepartment, department);
        //l.in((states != null)&&states.size()>0, EntLock::getState, states);
        Page<EntLock> page = entLockService.page(new Page<>(current, size), lqw);
        for (EntLock record : page.getRecords()) {
            String entname = record.getEntname();
            for (Map entlock : selectlocktime) {
                if (entlock.get("entname").equals(entname)) {
                    record.setLockcount((Long) entlock.get("count"));
                }
            }
        }
        //Page<EntLock> page = entLockService.page(new Page<>(current, size), l);
        //Integer count = entlockMapper.selectCount(l);
        //map.put("page",page);
        //map.put("count",selectlocktime);
        return RestResult.ok(page);
        //return RestResult.ok(map);
    }

    @GetMapping("/selectByEntname")
    public RestResult<?> selectByEntname(String entname) {
        EBaseinfo eBaseinfo = eBaseinfoMapper.selectByEntname(entname);
        return RestResult.ok(eBaseinfo);
    }


    @GetMapping("/queryOrgDept")
    public RestResult<?> queryOrgDept(String id) {
        if (id != null) {
            OrgUnits orgUnits = aicorgMapper.queryOrgUnitID(id);
            return RestResult.ok(orgUnits);
        }

        return RestResult.error(ResultCode.PARAM_IS_BLANK);

    }

    @PostMapping("/toDetail")
    public RestResult<?> toDetail(@RequestBody EntLock entLock) {
        TSTaskList tsTaskList = null;
        //Map<String, Object> paramMap = pageRequestDto.getParamMap();
        String entname = entLock.getEntname();

        if ("0".equals(entLock.getState())) {
            LocalDateTime locktime = entLock.getLockTime();
            String time = locktime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            tsTaskList = tsTaskListMapper.tolockDetail(entname, time);
        } else if ("3".equals(entLock.getState())) {
            LocalDateTime unlocktime = entLock.getUnlockTime();
            String time = unlocktime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            tsTaskList = tsTaskListMapper.tounlockDetail(entname, time);
        }

        return RestResult.ok(tsTaskList);
    }


    /**
     * 联合惩戒-查询奖惩名单
     *
     * @param xxztlb 信息主体类别（0：法人；1：自然人）
     * @param xxztmc 信息主体名称
     * @param xxzthm 信息主体号码
     * @return 查询名单
     * @author lroyia
     * @since 2025年5月7日17:37:39
     */
    @ApiOperation("联合惩戒-查询奖惩名单")
    @GetMapping("namelist/search")
    public RestResult<PunishmentSearchResultVO> searchNameList(@ApiParam(value = "信息主体类别（0：法人；1：自然人）", required = true) @RequestParam int xxztlb,
                                                               @ApiParam(value = "信息主体名称", required = true) @RequestParam String xxztmc,
                                                               @ApiParam("信息主体号码") @RequestParam(required = false) String xxzthm) {
        if (xxztlb == 1) {
            AssertUtils.isNotBlank(xxzthm);
        }
        return RestResult.ok(jointPunishmentApiService.searchPunishmentNameList(xxztlb, xxztmc, xxzthm));
    }

    /**
     * 查询联合惩戒-措施反馈
     *
     * @param feedbackLog 反馈信息
     * @return 查询名单
     * @author lroyia
     * @since 2025年5月7日17:37:39
     */
    @ApiOperation("联合惩戒-措施反馈")
    @GetMapping("measure/feedback")
    public RestResult<PunishmentMeasureFeedbackLog> feedback(@ApiParam(value = "反馈信息", required = true)
                                                             @RequestBody PunishmentMeasureFeedbackLog feedbackLog) {
        return RestResult.ok(jointPunishmentApiService.feedback(feedbackLog));
    }

    /**
     * 联合惩戒-措施反馈记录分页
     *
     * @param pageQuery 分页参数
     * @return 分页结果
     * @author lroyia
     * @since 2025年5月8日09:58:15
     */
    @ApiOperation("联合惩戒-措施反馈记录分页")
    @PostMapping("measure/feedback/log/page")
    public RestResult<IPage<PunishmentMeasureFeedbackLog>> feedbackLogPage(@ApiParam(value = "分页参数", required = true)
                                                                           @RequestBody BaseQuery<FeedbackLogPageSearchDto> pageQuery) {
        FeedbackLogPageSearchDto params = pageQuery.getEntity(FeedbackLogPageSearchDto.class);
        String xxztmc = params.getXxztmc();

        return RestResult.ok(punishmentMeasureFeedbackLogService.lambdaQuery().eq(StringUtils.isNotBlank(params.getXxztlb()),
                        PunishmentMeasureFeedbackLog::getZtlb, params.getXxztlb())
                .like(StringUtils.isNotBlank(xxztmc), PunishmentMeasureFeedbackLog::getZtmc, xxztmc)
                .and(StringUtils.isNotBlank(params.getXxzthm()), (wrapper) -> {
                    wrapper.and(StringUtils.isBlank(params.getXxztlb()), w -> w.like(PunishmentMeasureFeedbackLog::getZzjgdm, params.getXxzthm()).or().like(PunishmentMeasureFeedbackLog::getZzjgdm, params.getXxzthm()))
                            .like(StringUtils.equals(params.getXxztlb(), "0"), PunishmentMeasureFeedbackLog::getZzjgdm, params.getXxzthm())
                            .like(StringUtils.equals(params.getXxztlb(), "1"), PunishmentMeasureFeedbackLog::getZjhm, params.getXxzthm());
                }).page(new Page<>(pageQuery.getCurrent(), pageQuery.getSize()))
        );
    }

}

