package com.bonus.material.contract.controller;

import cn.hutool.core.convert.Convert;
import com.bonus.common.biz.config.ListPagingUtil;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.contract.domain.BmContract;
import com.bonus.material.contract.service.BmContractService;
import com.bonus.material.device.domain.vo.DevInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLDecoder;
import java.util.List;

/**
 * @Author：liang.chao
 * @Date：2024/12/13 - 9:14
 */
@RestController
@RequestMapping("/contract")
@Api(value = "合同管理", tags = "合同管理")
public class BmContractController extends BaseController {

    @Resource
    private BmContractService bmContractService;

    @ApiOperation(value = "合同列表")
    @GetMapping("/list")
    public AjaxResult list(BmContract bmContract) {
        startPage();
        List<BmContract> list = bmContractService.list(bmContract);
        return AjaxResult.success(getDataTable(list));
    }
    @ApiOperation(value = "合同新增")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BmContract bmContract) throws UnsupportedEncodingException {
   /*     String decode = URLDecoder.decode(bmContract.getContent());
        decode = decode.replace("&#36", "$");
        bmContract.setContent(decode);*/
        Integer i = bmContractService.add(bmContract);
        if (i > 0){
            return AjaxResult.success("新增成功");
        }else {
            return AjaxResult.error("新增失败");
        }
    }
    @ApiOperation(value = "合同修改")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody BmContract bmContract) throws UnsupportedEncodingException {
/*        String decode = URLDecoder.decode(bmContract.getContent());
        decode = decode.replace("&#36", "$");
        bmContract.setContent(decode);*/
        Integer i = bmContractService.edit(bmContract);
        if (i > 0){
            return AjaxResult.success("修改成功");
        }else {
            return AjaxResult.error("修改失败");
        }
    }
    @ApiOperation(value = "合同删除")
    @PostMapping("/del")
    public AjaxResult del(@RequestBody BmContract bmContract) {
        Integer i = bmContractService.del(bmContract);
        if (i > 0){
            return AjaxResult.success("删除成功");
        }else {
            return AjaxResult.error("删除失败");
        }
    }

    @ApiOperation(value = "合同状态修改（开启/关闭）")
    @PostMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestBody BmContract bmContract) {
        Integer i = bmContractService.updateStatus(bmContract);
        if (i > 0){
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }

    @ApiOperation(value = "合同模板列表")
    @GetMapping("/lisTemplate")
    public AjaxResult lisTemplate(BmContract bmContract) {
        List<BmContract> list = bmContractService.lisTemplate(bmContract);
        return AjaxResult.success(list);
    }

}
