//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package org.jeecg.modules.jmreport.desreport.a;

import java.util.Arrays;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;

import org.jeecg.modules.jmreport.common.vo.Result;
import org.jeecg.modules.jmreport.config.client.JmReportTokenClient;
import org.jeecg.modules.jmreport.desreport.entity.JimuReportDictItem;
import org.jeecg.modules.jmreport.desreport.model.JmPage;
import org.jeecg.modules.jmreport.desreport.service.IJimuReportDictItemService;
import org.jeecg.modules.jmreport.desreport.service.IJimuReportDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController("jimuReportDictItemController")
@RequestMapping({"/jmreport/dictItem"})
public class c {
    @Autowired
    private IJimuReportDictItemService dictItemService;
    @Autowired
    private JmReportTokenClient jimuTokenClient;
    @Autowired
    private IJimuReportDictService dictService;

    public c() {
    }

    @RequestMapping(
            value = {"/list"},
            method = {RequestMethod.GET}
    )
    public Result<JmPage<JimuReportDictItem>> a(JimuReportDictItem var1, @RequestParam(name = "pageNo", defaultValue = "1") Integer var2, @RequestParam(name = "pageSize", defaultValue = "10") Integer var3, HttpServletRequest var4) {
        Result var5 = new Result();
        JmPage var6 = this.dictItemService.queryPageList(var1, var2, var3);
        var5.setSuccess(true);
        var5.setResult(var6);
        return var5;
    }

    @RequestMapping(
            value = {"/add"},
            method = {RequestMethod.POST}
    )
    @CacheEvict(
            value = {"jmreport:cache:dict", "jmreport:cache:dictTxt"},
            allEntries = true
    )
    public Result<JimuReportDictItem> a(@RequestBody JimuReportDictItem var1, HttpServletRequest var2) {
        Result var3 = new Result();
        Boolean var4 = this.a(var1);
        if (!var4) {
            var3.setSuccess(false);
            var3.setMessage("数据值已重复");
            return var3;
        } else {
            try {
                var1.setCreateTime(new Date());
                this.dictItemService.save(var1);
                var3.success("保存成功！");
            } catch (Exception var6) {
                var3.error500("操作失败");
            }

            return var3;
        }
    }

    @RequestMapping(
            value = {"/edit"},
            method = {RequestMethod.POST}
    )
    @CacheEvict(
            value = {"jmreport:cache:dict", "jmreport:cache:dictTxt"},
            allEntries = true
    )
    public Result<JimuReportDictItem> b(@RequestBody JimuReportDictItem var1, HttpServletRequest var2) {
        Result var3 = new Result();
        Boolean var4 = this.a(var1);
        if (!var4) {
            var3.setSuccess(false);
            var3.setMessage("数据值已重复");
            return var3;
        } else {
            JimuReportDictItem var5 = this.dictItemService.getById(var1.getId());
            if (var5 == null) {
                var3.error500("未找到对应实体");
            } else {
                var1.setUpdateTime(new Date());
                int var6 = this.dictItemService.updateById(var1);
                if (var6 > 0) {
                    var3.success("编辑成功!");
                }
            }

            return var3;
        }
    }

    @RequestMapping(
            value = {"/delete"},
            method = {RequestMethod.DELETE}
    )
    @CacheEvict(
            value = {"jmreport:cache:dict", "jmreport:cache:dictTxt"},
            allEntries = true
    )
    public Result<JimuReportDictItem> a(@RequestParam(name = "id") String var1, HttpServletRequest var2) {
        Result var3 = new Result();
        JimuReportDictItem var4 = this.dictItemService.getById(var1);
        String var5 = var4.getDictId();
        if (var4 == null) {
            var3.error500("未找到对应实体");
        } else {
            Integer var6 = this.dictItemService.removeById(var1);
            if (var6 > 0) {
                var3.success("删除成功!");
            }
        }

        return var3;
    }

    @RequestMapping(
            value = {"/deleteBatch"},
            method = {RequestMethod.DELETE}
    )
    @CacheEvict(
            value = {"jmreport:cache:dict", "jmreport:cache:dictTxt"},
            allEntries = true
    )
    public Result<JimuReportDictItem> a(@RequestParam(name = "ids") String var1) {
        Result var2 = new Result();
        if (var1 != null && !"".equals(var1.trim())) {
            this.dictItemService.removeByIds(Arrays.asList(var1.split(",")));
            var2.success("删除成功!");
        } else {
            var2.error500("参数不识别！");
        }

        return var2;
    }

    public Boolean a(JimuReportDictItem var1) {
        boolean var2 = false;
        int var3 = this.dictItemService.count(var1);
        return var3 == 0 ? true : false;
    }
}
