package com.hzs.member.personal.controller.api;/**
 * @Description:
 * @Author: yuhui
 * @Time: 2024/1/24 15:11
 * @Classname: ApiPersonalServiceController
 * @PackageName: com.hzs.member.personal.controller.api
 */

import com.hzs.common.core.constant.EnumsPrefixConstants;
import com.hzs.common.core.enums.EOrderType;
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.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.*;

import javax.xml.crypto.Data;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 *@BelongsProject: hzs_java_cloud_africa
 *@BelongsPackage: com.hzs.member.personal.controller.api
 *@Author: yh
 *@CreateTime: 2024-01-24  15:11
 *@Description: TODO
 *@Version: 1.0
 */
@RestController
@RequestMapping("/api/personal")
public class ApiPersonalServiceController  extends BaseController {
    @Autowired
    private ICuPersonalServiceService personalServiceService;

    @Autowired
    private ITransactionCommonService iTransactionCommonService;

    /**
     * 列表
     * @param personalServiceParam
     * @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.setMemberCode(SecurityUtils.getMemberCode());
        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("apply-for")
    public AjaxResult applyFor(@RequestBody CuPersonalService personalService){
        personalService.setStatus(EPersonalServiceStatus.APPLIED_FOR.getValue());
        personalService.setCreationTime(DateUtils.currentDateTime());
        personalService.setPkCreator(SecurityUtils.getUserId());
        personalService.setPkCountry(SecurityUtils.getPkCountry());
        personalService.setMemberCode(SecurityUtils.getMemberCode());
        personalServiceService.save(personalService);
        return AjaxResult.success();
    }
}
