package com.hzs.member.personal.controller.manage;/**
 * @Description:
 * @Author: yuhui
 * @Time: 2024/1/24 13:58
 * @Classname: PersonalServiceController
 * @PackageName: com.hzs.member.personal.controller.manage
 */

import com.baomidou.mybatisplus.annotation.TableField;
import com.hzs.common.core.constant.EnumsPrefixConstants;
import com.hzs.common.core.enums.EPersonalServiceStatus;
import com.hzs.common.core.enums.EPersonalServiceType;
import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.core.utils.poi.ExcelUtil;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.domain.member.personal.CuPersonalService;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.common.service.ITransactionCommonService;
import com.hzs.member.personal.param.PersonalServiceParam;
import com.hzs.member.personal.service.ICuPersonalServiceService;
import com.hzs.member.personal.vo.PersonalServiceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 *@BelongsProject: hzs_java_cloud_africa
 *@BelongsPackage: com.hzs.member.personal.controller.manage
 *@Author: yh
 *@CreateTime: 2024-01-24  13:58
 *@Description: TODO
 *@Version: 1.0
 */
@RestController
@RequestMapping("/manage/personal")
public class PersonalServiceController extends BaseController {

    @Autowired
    private ICuPersonalServiceService personalServiceService;
    @Autowired
    private ITransactionCommonService iTransactionCommonService;
    /**
     * 申请列表
     * @return
     */
    @GetMapping("list")
    public TableDataInfo list(PersonalServiceParam personalServiceParam){
        if (personalServiceParam.getStartCreateDate() != null){
            personalServiceParam.setStartCreateDate(DateUtils.getStartTime(personalServiceParam.getStartCreateDate()));
        }
        if (personalServiceParam.getEndCreateDate() != null){
            personalServiceParam.setEndCreateDate(DateUtils.getEndTime(personalServiceParam.getEndCreateDate()));
        }

        startPage();
        personalServiceParam.setPkCountry(SecurityUtils.getPkCountry());
        List<PersonalServiceVo> personalServiceVoList = personalServiceService.selectByList(personalServiceParam);
 //       Map<String, String> transactionMap = iTransactionCommonService.exportEnumTransaction(EPersonalServiceStatus.values(), EPersonalServiceType.values());
        List<PersonalServiceVo> resultList = personalServiceVoList.stream().map(a -> {
//            a.setTypeStr(transactionMap.get(EnumsPrefixConstants.PERSONAL_TYPE + a.getType()));
//            a.setStatusStr(transactionMap.get(EnumsPrefixConstants.PERSONAL_STATUS + a.getType()));
           // a.setTypeStr(EPersonalServiceType.getEnumByValue(a.getType()).getLabel());
        //    a.setStatusStr(EPersonalServiceStatus.getEnumByValue(a.getStatus()).getLabel());
            return a;
        }).collect(Collectors.toList());
        return getDataTable(resultList);
    }


    /**
     * 申请列表
     * @return
     */
    @PostMapping("export")
    public void export(PersonalServiceParam personalServiceParam,HttpServletResponse response){
        if (personalServiceParam.getStartCreateDate() != null){
            personalServiceParam.setStartCreateDate(DateUtils.getStartTime(personalServiceParam.getStartCreateDate()));
        }
        if (personalServiceParam.getEndCreateDate() != null){
            personalServiceParam.setEndCreateDate(DateUtils.getEndTime(personalServiceParam.getEndCreateDate()));
        }
        personalServiceParam.setPkCountry(SecurityUtils.getPkCountry());
        List<PersonalServiceVo> personalServiceVoList = personalServiceService.selectByList(personalServiceParam);
        List<PersonalServiceVo> resultList = personalServiceVoList.stream().map(a -> {
//            a.setTypeStr(transactionMap.get(EnumsPrefixConstants.PERSONAL_TYPE + a.getType()));
//            a.setStatusStr(transactionMap.get(EnumsPrefixConstants.PERSONAL_STATUS + a.getType()));
  //          a.setTypeStr(EPersonalServiceType.getEnumByValue(a.getType()).getLabel());
 //           a.setStatusStr(EPersonalServiceStatus.getEnumByValue(a.getStatus()).getLabel());
            return a;
        }).collect(Collectors.toList());
        ExcelUtil<PersonalServiceVo> util = new ExcelUtil<>(PersonalServiceVo.class);
        util.exportExcel(response, resultList, "个人服务申请列表导出");
    }

    /**
     * 信息确认
     */
    @GetMapping("confirm")
    public AjaxResult confirm(Long pkId){
        CuPersonalService personalService = new CuPersonalService();
        personalService.setModifiedTime(DateUtils.currentDateTime());
        personalService.setPkModified(SecurityUtils.getUserId());
        personalService.setPkId(pkId);
        personalService.setStatus(EPersonalServiceStatus.PASSED.getValue());
        personalServiceService.updateById(personalService);
        return AjaxResult.success();
    }

    /**
     * 信息驳回
     */
    @GetMapping("reject")
    public AjaxResult reject(Long pkId,String rejectInfo){
        CuPersonalService personalService = new CuPersonalService();
        personalService.setModifiedTime(DateUtils.currentDateTime());
        personalService.setPkModified(SecurityUtils.getUserId());
        personalService.setPkId(pkId);
        personalService.setStatus(EPersonalServiceStatus.REJECTED.getValue());
        personalService.setRejectInfo(rejectInfo);
        personalServiceService.updateById(personalService);
        return AjaxResult.success();
    }

}
