package com.ssm.controller;

import com.ssm.core.bean.GenericResponse;
import com.ssm.core.utils.SnowflakeUtil;
import com.ssm.manage.entity.AllinpayCashList;
import com.ssm.manage.response.ResponseCode;
import com.ssm.manage.service.SsmAllinpayCashListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@Api(value = "通联订单关联收银单controller", tags = {"通联订单关联收银单相关接口"})
@RestController
@RequestMapping("/demay/ssm/allipayCash")
@Slf4j
public class SsmAllinpayCashListController {
    @Autowired
    private SsmAllinpayCashListService ssmAllinpayCashListService;

    @ApiOperation(value = "通联订单关联收银单查询接口", notes = "美发版-通联订单关联收银单查询接口", response = GenericResponse.class)
    @RequestMapping(path="/one", method= RequestMethod.POST)
    public GenericResponse one(@RequestBody AllinpayCashList allinpayCashList){
        GenericResponse genericResponse = new GenericResponse();
        AllinpayCashList cashList = new AllinpayCashList();
        try {
            cashList = ssmAllinpayCashListService.selectOne(allinpayCashList);
        }catch (Exception e){
            log.error("SsmAllinpayCashListController.one:", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        genericResponse.setData(cashList);
        return genericResponse;
    }


    @ApiOperation(value = "通联订单关联收银单添加接口", notes = "美发版-通联订单关联收银单添加接口", response = GenericResponse.class)
    @RequestMapping(path="/add", method= RequestMethod.POST)
    public GenericResponse add(@RequestBody AllinpayCashList allinpayCashList){
        GenericResponse genericResponse = new GenericResponse();
        int i = 0;
        allinpayCashList.setId(new SnowflakeUtil(new Random().nextInt(1023)).nextId());
        try {
            i = ssmAllinpayCashListService.saveNotNull(allinpayCashList);
        }catch (Exception e){
            log.error("SsmAllinpayCashListController.add:", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }
        return genericResponse;
    }


}
