package com.unis.base.server.controller;

import com.github.pagehelper.PageInfo;
import com.unis.base.common.vo.*;
import com.unis.base.server.entity.TzSlqyDO;
import com.unis.base.server.service.CompanyService;
import com.unis.base.server.service.MoneyMonitorService;
import com.unis.common.utils.ResponseWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Set;


/**
 * 价格监测
 * @author zoujieli
 */
@RestController
@Api(value = "价格监测", tags = "价格监测")
@Slf4j
public class MoneyMonitorController {
	
    @Autowired
    private MoneyMonitorService moneyMonitorService;

    @ApiOperation(value = "价格监测-分页查询", notes = "参数：pageNum,pageSize")
    @PostMapping(value = "/moneyMonitorList/{pageNum}/{pageSize}")
    public ResponseWrapper getMoneyMonitorList(@PathVariable(value = "pageNum") Integer pageNum,
                                               @PathVariable(value = "pageSize") Integer pageSize){
        try {
            Map<String,Object> resultMap = moneyMonitorService.getMoneyMonitorList(pageNum,pageSize);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), resultMap);
        } catch (Exception e) {
            log.error(e.getMessage());
            return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
        }
    }

    @ApiOperation(value = "价格监测-查询详情", notes = "参数：监测点ID")
    @GetMapping(value = "/moneyMonitorDetail/{jcdid}")
    public ResponseWrapper getMoneyMonitorDetail(@PathVariable(value = "jcdid") String jcdid){
        try {
            MoneyMonitorVO moneyMonitorVO = moneyMonitorService.getMoneyMonitorDetail(jcdid);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), moneyMonitorVO);
        } catch (Exception e) {
            log.error(e.getMessage());
            return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
        }
    }

    @ApiOperation(value = "价格监测-编辑修改", notes = "参数：监测点ID")
    @PutMapping(value = "/moneyMonitor")
    public ResponseWrapper updateMoneyMonitor(@RequestBody MoneyMonitorVO moneyMonitorVO){
        try {
            if (moneyMonitorVO.getJcdid().isEmpty()){
                return ResponseWrapper.success(HttpStatus.BAD_REQUEST.value(), "修改失败，jcdid未传", null);
            }
            moneyMonitorService.updateMoneyMonitor(moneyMonitorVO);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), null);
        } catch (Exception e) {
            log.error(e.getMessage());
            return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
        }
    }

    @ApiOperation(value = "价格监测-删除", notes = "参数：监测点ID")
    @DeleteMapping(value = "/moneyMonitor/{jcdid}")
    public ResponseWrapper deleteMoneyMonitor(@PathVariable String jcdid){
        try {
            if (jcdid.isEmpty()){
                return ResponseWrapper.success(HttpStatus.BAD_REQUEST.value(), "删除失败，jcdid未传", null);
            }
            moneyMonitorService.deleteMoneyMonitor(jcdid);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), null);
        } catch (Exception e) {
            log.error(e.getMessage());
            return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
        }
    }

    @ApiOperation(value = "价格监测-新增", notes = "参数：价格监测VO")
    @PostMapping(value = "/moneyMonitor")
    public ResponseWrapper insertMoneyMonitor(@RequestBody MoneyMonitorVO moneyMonitorVO){
        try {
            moneyMonitorService.insertMoneyMonitor(moneyMonitorVO);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), null);
        } catch (Exception e) {
            log.error(e.getMessage());
            return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
        }
    }
}
