MainController.java 2.5 KB
package com.viontech.match.controller;

import com.viontech.match.entity.vo.RequestVo;
import com.viontech.match.entity.vo.ResponseVo;
import com.viontech.match.service.PersonService;
import com.viontech.match.service.PoolService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * .
 *
 * @author 谢明辉
 * @version 0.0.1
 */
@RestController
@RequestMapping("/alg")
@Slf4j
public class MainController {

    @Resource
    private PersonService personService;
    @Resource
    private PoolService poolService;

    @PostMapping
    public ResponseVo all(@RequestBody RequestVo requestVo) throws Exception {
        String rid = requestVo.getRid();
        try {
            switch (requestVo.getCommand()) {
                case AddPersonPool:
                    return poolService.createPool(requestVo);
                case DelPersonPool:
                    return poolService.deletePool(requestVo);
                case ModifyPersonPool:
                    return poolService.modifyPool(requestVo);
                case QueryPersonPool:
                    return poolService.queryPool(requestVo);
                case MatchPerson:
                    return personService.matchPerson(requestVo);
                case UpdatePerson:
                    return personService.updatePerson(requestVo);
                case CountMatchPerson:
                    return personService.countMatchPerson(requestVo);
                default:
                    return ResponseVo.commandNotFound(rid);
            }
        } catch (Exception e) {
            log.error("match exception", e);
            return ResponseVo.error(rid, e.getMessage());
        }
    }

    @GetMapping("/pools")
    public Object getPools() {
        try {
            return poolService.queryPoolInfo(null);
        } catch (IOException e) {
            return ResponseVo.error("error", e.getMessage());
        }
    }

    @GetMapping("/compare")
    public Object compare(@RequestParam(name = "poolId")List<String> poolId, @RequestParam(name = "unid")String unid, @RequestParam(name = "mallId")Long mallId, @RequestParam(name = "zoneId", required = false)List<Long> zoneId, @RequestParam(name = "gateId")List<Long> gateId, @RequestParam(name = "direction")List<Integer> direction, @RequestParam(name = "size")Integer size) throws IOException {
        return personService.compare(poolId, unid, mallId, zoneId, gateId, direction,size);
    }
}