package com.crm.manager.controller;

import com.crm.manager.service.CustomLoginGroupHistoryService;
import com.crm.rely.backend.core.dto.base.BaseResultWithPagerDto;
import com.crm.rely.backend.core.dto.custom.login.group.CustomLoginGroupHistoryDto;
import com.crm.rely.backend.core.entity.custom.login.group.CustomLoginGroupHistorySearchEntity;
import com.crm.rely.backend.util.DateUtil;
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 java.util.Date;
import java.util.List;

/**
 * Created by max on 2020/7/8.
 */
@RestController
@RequestMapping("/custom/login/group/history")
public class CustomLoginGroupHistoryController {

    @Autowired
    private CustomLoginGroupHistoryService customLoginGroupHistoryService;


    @PostMapping("/search/list")
    public BaseResultWithPagerDto<List<CustomLoginGroupHistoryDto>> searchList(@RequestBody CustomLoginGroupHistorySearchEntity entity) throws Exception {

//
//        if (!Strings.isNullOrEmpty(entity.getNewGroup())) {
//            entity.setNewGroup(entity.getNewGroup().replace("\\", "\\\\"));
//        }
//        if (!Strings.isNullOrEmpty(entity.getOldGroup())) {
//            entity.setOldGroup(entity.getOldGroup().replace("\\", "\\\\"));
//        }

        if (entity.getStartDate() != null) {
            entity.setStartDate(DateUtil.parseDate(entity.getStartDate()));
        }
        if (entity.getEndDate() != null) {
            Date endDate = DateUtil.operationDay(entity.getEndDate(), 1);
            entity.setEndDate(DateUtil.parseDate(endDate));
        }
        return customLoginGroupHistoryService.searchPageList(entity);
    }

}
