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

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

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

import org.jeecg.modules.jmreport.common.constant.CommonConstant;
import org.jeecg.modules.jmreport.common.util.oConvertUtils;
import org.jeecg.modules.jmreport.common.vo.Result;
import org.jeecg.modules.jmreport.config.JmReportBaseConfig;
import org.jeecg.modules.jmreport.config.client.JmReportTokenClient;
import org.jeecg.modules.jmreport.desreport.entity.JimuReportDict;
import org.jeecg.modules.jmreport.desreport.model.JmPage;
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.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController("jimuReportDictController")
@RequestMapping({"/jmreport/dict"})
public class b {
    @Autowired
    private IJimuReportDictService dictService;
    @Autowired
    private JmReportTokenClient jimuTokenClient;
    @Autowired
    private JmReportBaseConfig jmBaseConfig;

    public b() {
    }

    @GetMapping({"/list"})
    public Result<JmPage<JimuReportDict>> a(JimuReportDict var1, @RequestParam(name = "pageNo", defaultValue = "1") Integer var2, @RequestParam(name = "pageSize", defaultValue = "10") Integer var3, HttpServletRequest var4) {
        Result var5 = new Result();
        String var6 = this.jimuTokenClient.getUsername(var4);
        if (this.jmBaseConfig.getSaas()) {
            var1.setCreateBy(var6);
        }

        var1.setDelFlag(CommonConstant.DEL_FLAG_0);
        JmPage var7 = this.dictService.queryPageList(var1, var2, var3);
        var5.setSuccess(true);
        var5.setResult(var7);
        return var5;
    }

    @PostMapping({"/add"})
    public Result<JimuReportDict> a(@RequestBody JimuReportDict var1, HttpServletRequest var2) {
        Result var3 = new Result();
        String var4 = this.jimuTokenClient.getUsername(var2);
        Integer var5 = this.dictService.getDictCount(var1.getDictCode());
        if (var5 > 0) {
            var3.setSuccess(false);
            var3.setMessage("字典编码已存在！");
            return var3;
        } else {
            var1.setCreateTime(new Date());
            var1.setDelFlag(CommonConstant.DEL_FLAG_0);
            var1.setCreateBy(var4);
            this.dictService.save(var1);
            var3.setSuccess(true);
            var3.success("保存成功！");
            return var3;
        }
    }

    @PostMapping({"/edit"})
    @CacheEvict(
            value = {"jmreport:cache:dict", "jmreport:cache:dictTxt"},
            allEntries = true
    )
    public Result<JimuReportDict> a(@RequestBody JimuReportDict var1) {
        Result var2 = new Result();
        JimuReportDict var3 = this.dictService.getById(var1.getId());
        Integer var4 = this.dictService.getEditDictCount(var1.getDictCode(), var1.getId());
        if (var4 > 0) {
            var2.setSuccess(false);
            var2.setMessage("字典编码已存在！");
            return var2;
        } else {
            if (var3 == null) {
                var2.error500("未找到对应实体");
            } else {
                var1.setUpdateTime(new Date());
                int var5 = this.dictService.updateById(var1);
                if (var5 > 0) {
                    var2.success("编辑成功!");
                }
            }

            return var2;
        }
    }

    @DeleteMapping({"/delete"})
    public Result<JimuReportDict> a(@RequestParam(name = "id") String var1) {
        Result var2 = new Result();
        int var3 = this.dictService.updateDictDelFlag(CommonConstant.DEL_FLAG_1, var1);
        if (var3 > 0) {
            var2.success("删除成功!");
        } else {
            var2.error500("删除失败!");
        }

        return var2;
    }

    @DeleteMapping({"/thoroughDelete"})
    @CacheEvict(
            value = {"jmreport:cache:dict", "jmreport:cache:dictTxt"},
            allEntries = true
    )
    public Result<?> b(@RequestParam(name = "id") String var1) {
        try {
            this.dictService.deleteOneDictPhysically(var1);
            return Result.ok("删除成功!");
        } catch (Exception var3) {
            var3.printStackTrace();
            return Result.error("删除失败!");
        }
    }

    @DeleteMapping({"/deleteBatch"})
    @CacheEvict(
            value = {"jmreport:cache:dict", "jmreport:cache:dictTxt"},
            allEntries = true
    )
    public Result<JimuReportDict> c(@RequestParam(name = "ids") String var1) {
        Result var2 = new Result();
        if (oConvertUtils.isEmpty(var1)) {
            var2.error500("参数不识别！");
        } else {
            this.dictService.updateDelFlagByIds(var1);
            var2.success("删除成功!");
        }

        return var2;
    }

    @GetMapping({"/refleshCache"})
    @CacheEvict(
            value = {"jmreport:cache:dict", "jmreport:cache:dictTxt"},
            allEntries = true
    )
    public Result<String> a(HttpServletRequest var1) {
        new Result();
        this.jimuTokenClient.getUsername(var1);
        return Result.OK("刷新缓存成功!");
    }

    @GetMapping({"/deleteList"})
    public Result<List<JimuReportDict>> b(HttpServletRequest var1) {
        String var2 = this.jimuTokenClient.getUsername(var1);
        Result var3 = new Result();
        if (!this.jmBaseConfig.getSaas()) {
            var2 = "";
        }

        List var4 = this.dictService.queryDeleteList(var2);
        var3.setSuccess(true);
        var3.setResult(var4);
        return var3;
    }

    @PostMapping({"/back"})
    @CacheEvict(value = {"jmreport:cache:dict", "jmreport:cache:dictTxt"},allEntries = true)
    public Result<?> b(@RequestBody JimuReportDict var1) {
        try {
            this.dictService.updateDictDelFlag(CommonConstant.DEL_FLAG_0, var1.getId());
            return Result.ok("取回成功!");
        } catch (Exception var3) {
            var3.printStackTrace();
            return Result.error("操作失败!");
        }
    }

}
