package com.philisense.www.controller.web;

import com.philisense.www.annotation.log.OperateLog;
import com.philisense.www.common.config.CommonConst;
import com.philisense.www.controller.BaseUtilController;
import com.philisense.www.service.EbookArticleTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

@RestController
@RequestMapping(CommonConst.WEB_REST_SERVICE_PREFICX + "ebookarticletype")
@Api(tags = "EbookArticleTypeControllerForWeb|一个用来操作-{文章分类表}-业务模块的控制器")
public class EbookArticleTypeControllerForWeb extends BaseUtilController {

    @Autowired
    private EbookArticleTypeService ebookArticleTypeService;


    @GetMapping("/delete")
    @ApiOperation(value = "根据-{文章分类表}-主键删除记录", notes = "成功返回:{\"success\":true,\"message\",\"数据删除成功\"},失败返回:{\"success\":false,\"message\",\"数据删除失败\"}")
    @ApiImplicitParam(paramType = "query", name = "recordid", value = "记录主键", required = true,  dataTypeClass = String.class)
    @OperateLog(name = "根据-{文章分类表}-主键删除记录", value = "delete", type = "PC")
    public Map<String, Object> deleteByPrimaryKeyForEbookArticleTypeForWeb(HttpServletRequest request, HttpServletResponse response, @RequestParam String recordid) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            Map<String, Object> one = ebookArticleTypeService.getOne(new HashMap<String, Object>() {{
                put("id", recordid);
            }});
//            int flag = ebookArticleTypeService.deleteByPrimaryKey(recordid);
            int flag = 0;
            if(one != null) {
                flag = ebookArticleTypeService.deleteByMap(new HashMap<String, Object>() {{
                    put("levelcode", one.get("levelcode"));
                }});
            }
            if (1 <= flag) {
                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, DELETE_SUCCESS_MSG);
            } else {
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, DELETE_FAIL_MSG);
            }

        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, DELETE_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @GetMapping("/get")
    @ApiOperation(value = "根据-{文章分类表}-主键查询记录", notes = "成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"datarecord\":\"{}\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
    @ApiImplicitParam(paramType = "body", name = "recordid", value = "记录主键", required = true,  dataTypeClass = String.class)
    @OperateLog(name = "根据-{文章分类表}-主键查询记录", value = "query", type = "PC")
    public Map<String, Object> selectByPrimaryKeyForEbookArticleTypeForWeb(HttpServletRequest request, HttpServletResponse response, @RequestParam String recordid) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {

            result.put(DATASUCCESS, SUCCESSFLAG);
            result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
            result.put(DATARECORD, ebookArticleTypeService.selectByPrimaryKey(recordid));
        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, QUERY_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @PostMapping("/insert")
    @ApiOperation(value = "根据-{文章分类表}-对象插入记录", notes = "成功返回:{\"success\":true,\"message\",\"数据插入成功\"},失败返回:{\"success\":false,\"message\",\"数据插入失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "id", value = "ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "title", value = "名称", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "description", value = "描述", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "parentid", value = "父ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "levelcode", value = "层级", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "icon", value = "图标", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "cls", value = "层样式", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "leaf", value = "树叶", required = true, dataType = "int", dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = "create_user_id", value = "创建用户", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "create_time", value = "创建时间", required = true, dataType = "Date", dataTypeClass = Date.class)
    })
    @OperateLog(name = "根据-{文章分类表}-对象插入记录", value = "insert", type = "PC")
    public Map<String, Object> insertForEbookArticleTypeForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {

            String ID = UUID.randomUUID().toString().replaceAll("-", "");
            map.put("id", ID);
            map.put("levelcode", map.get("parentlevelcode") + "/" + ID);
            ebookArticleTypeService.insert(map);
            result.put(DATASUCCESS, SUCCESSFLAG);
            result.put(DATAMESSAGE, INSERT_SUCCESS_MSG);
            result.put(DATARECORD, map);
        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, INSERT_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @PostMapping("/update")
    @ApiOperation(value = "根据-{文章分类表}-对象更新记录", notes = "成功返回:{\"success\":true,\"message\",\"数据更新成功\"},失败返回:{\"success\":false,\"message\",\"数据更新失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "id", value = "ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "title", value = "名称", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "description", value = "描述", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "parentid", value = "父ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "levelcode", value = "层级", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "icon", value = "图标", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "cls", value = "层样式", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "leaf", value = "树叶", required = true, dataType = "int", dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = "create_user_id", value = "创建用户", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "create_time", value = "创建时间", required = true, dataType = "Date", dataTypeClass = Date.class)
    })
    @OperateLog(name = "根据-{文章分类表}-对象更新记录", value = "update", type = "PC")
    public Map<String, Object> updateForEbookArticleTypeForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {

            int flag = ebookArticleTypeService.update(map);
            if (1 <= flag) {
                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, UPDATE_SUCCESS_MSG);
            } else {
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, UPDATE_FAIL_MSG);
            }

        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, UPDATE_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @PostMapping("/deleteByMap")
    @ApiOperation(value = "根据-{文章分类表}-对象Map删除记录", notes = "成功返回:{\"success\":true,\"message\",\"数据删除成功\"},失败返回:{\"success\":false,\"message\",\"数据删除失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "id", value = "ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "title", value = "名称", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "description", value = "描述", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "parentid", value = "父ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "levelcode", value = "层级", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "icon", value = "图标", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "cls", value = "层样式", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "leaf", value = "树叶", required = true, dataType = "int", dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = "create_user_id", value = "创建用户", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "create_time", value = "创建时间", required = true, dataType = "Date", dataTypeClass = Date.class)
    })
    @OperateLog(name = "根据-{文章分类表}-对象Map删除记录", value = "delete", type = "PC")
    public Map<String, Object> deleteByMapForEbookArticleTypeForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            int flag = ebookArticleTypeService.deleteByMap(map);
            if (1 <= flag) {
                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, DELETE_SUCCESS_MSG);
            } else {
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, DELETE_FAIL_MSG);
            }

        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, DELETE_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @PostMapping("/updateByMap")
    @ApiOperation(value = "根据-{文章分类表}-对象Map更新记录", notes = "成功返回:{\"success\":true,\"message\",\"数据更新成功\"},失败返回:{\"success\":false,\"message\",\"数据更新失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "id", value = "ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "title", value = "名称", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "description", value = "描述", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "parentid", value = "父ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "levelcode", value = "层级", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "icon", value = "图标", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "cls", value = "层样式", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "leaf", value = "树叶", required = true, dataType = "int", dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = "create_user_id", value = "创建用户", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "create_time", value = "创建时间", required = true, dataType = "Date", dataTypeClass = Date.class)
    })
    @OperateLog(name = "根据-{文章分类表}-对象Map更新记录", value = "update", type = "PC")
    public Map<String, Object> updateByMapForEbookArticleTypeForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {


            int flag = ebookArticleTypeService.updateByMap(map);
            if (1 <= flag) {
                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, UPDATE_SUCCESS_MSG);
            } else {
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, UPDATE_FAIL_MSG);
            }

        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, UPDATE_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @PostMapping("/getOne")
    @ApiOperation(value = "根据-{文章分类表}-对象Map查询记录", notes = "成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"datarecord\":\"{}\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "id", value = "ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "title", value = "名称", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "description", value = "描述", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "parentid", value = "父ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "levelcode", value = "层级", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "icon", value = "图标", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "cls", value = "层样式", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "leaf", value = "树叶", required = true, dataType = "int", dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = "create_user_id", value = "创建用户", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "create_time", value = "创建时间", required = true, dataType = "Date", dataTypeClass = Date.class)
    })
    @OperateLog(name = "根据-{文章分类表}-对象Map查询记录", value = "query", type = "PC")
    public Map<String, Object> getOneForEbookArticleTypeForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {

            result.put(DATASUCCESS, SUCCESSFLAG);
            result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
            result.put(DATARECORD, ebookArticleTypeService.getOne(map));
        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, QUERY_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @PostMapping("/getAll")
    @ApiOperation(value = "根据-{文章分类表}-对象Map查询所有记录", notes = "成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"data\":\"[]\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "id", value = "ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "title", value = "名称", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "description", value = "描述", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "parentid", value = "父ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "levelcode", value = "层级", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "icon", value = "图标", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "cls", value = "层样式", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "leaf", value = "树叶", required = true, dataType = "int", dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = "create_user_id", value = "创建用户", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "create_time", value = "创建时间", required = true, dataType = "Date", dataTypeClass = Date.class)
    })
    @OperateLog(name = "根据-{文章分类表}-对象Map查询所有记录", value = "query", type = "PC")
    public Map<String, Object> getAllForEbookArticleTypeForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {

            result.put(DATASUCCESS, SUCCESSFLAG);
            result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
            result.put(DATALIST, ebookArticleTypeService.getAll(map));
        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, QUERY_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @PostMapping("/queryPage")
    @ApiOperation(value = "根据-{文章分类表}-对象Map分页记录", notes = "成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"data\":\"[]\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "id", value = "ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "title", value = "名称", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "description", value = "描述", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "parentid", value = "父ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "levelcode", value = "层级", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "icon", value = "图标", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "cls", value = "层样式", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "leaf", value = "树叶", required = true, dataType = "int", dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = "create_user_id", value = "创建用户", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "create_time", value = "创建时间", required = true, dataType = "Date", dataTypeClass = Date.class)
    })
    @OperateLog(name = "根据-{文章分类表}-对象Map分页记录", value = "query", type = "PC")
    public Map<String, Object> queryPageForEbookArticleTypeForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            int currentPage = map.get(DATACURRENT) != null ? Integer.parseInt(map.get(DATACURRENT) + "") - 1 : 0;
            int pageSize = map.get(PAGESIZE) != null ? Integer.parseInt(map.get(PAGESIZE) + "") : 10;
            int pageStart = currentPage * pageSize;

            map.put(PAGESIZE, pageSize);
            map.put(PAGESTART, pageStart);
            int total = ebookArticleTypeService.count(map);
            List<Map<String, Object>> datalist = new ArrayList<Map<String, Object>>();
            if (total > 0) {
                datalist = ebookArticleTypeService.queryPage(map);
            }
            result.put(DATASUCCESS, SUCCESSFLAG);
            result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
            result.put(DATALIST, datalist);
            Map<String, Object> pagemode = new HashMap<String, Object>();
            pagemode.put(DATATOTAL, total);
            pagemode.put(PAGESIZE, map.get(PAGESIZE) != null ? map.get(PAGESIZE) : 10);
            pagemode.put(DATACURRENT, map.get(DATACURRENT) != null ? map.get(DATACURRENT) : 0);
            result.put(PAGINATION, pagemode);
        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, QUERY_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @PostMapping("/count")
    @ApiOperation(value = "根据-{文章分类表}-对象Map统计查询总数记录", notes = "成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"data\":\"[]\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "id", value = "ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "title", value = "名称", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "description", value = "描述", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "parentid", value = "父ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "levelcode", value = "层级", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "icon", value = "图标", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "cls", value = "层样式", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "leaf", value = "树叶", required = true, dataType = "int", dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = "create_user_id", value = "创建用户", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "create_time", value = "创建时间", required = true, dataType = "Date", dataTypeClass = Date.class)
    })
    @OperateLog(name = "根据-{文章分类表}-对象Map统计查询总数记录", value = "query", type = "PC")
    public Map<String, Object> countForEbookArticleTypeForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {

            result.put(DATASUCCESS, SUCCESSFLAG);
            result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
            result.put(DATATOTAL, ebookArticleTypeService.count(map));
        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, QUERY_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @PostMapping("/insertBatch")
    @ApiOperation(value = "根据-{文章分类表}-对象Map批量插入记录", notes = "成功返回:{\"success\":true,\"message\",\"数据插入成功\"},失败返回:{\"success\":false,\"message\",\"数据插入失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "id", value = "ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "title", value = "名称", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "description", value = "描述", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "parentid", value = "父ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "levelcode", value = "层级", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "icon", value = "图标", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "cls", value = "层样式", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "leaf", value = "树叶", required = true, dataType = "int", dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = "create_user_id", value = "创建用户", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "create_time", value = "创建时间", required = true, dataType = "Date", dataTypeClass = Date.class)
    })
    @OperateLog(name = "根据-{文章分类表}-对象Map批量插入记录", value = "insert", type = "PC")
    public Map<String, Object> insertBatchForEbookArticleTypeForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody List<Map<String, Object>> list) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {

            for (Map<String, Object> map : list) {
                map.put("id", UUID.randomUUID().toString().replaceAll("-", ""));
            }

            ebookArticleTypeService.insertBatch(list);
            result.put(DATASUCCESS, SUCCESSFLAG);
            result.put(DATAMESSAGE, INSERT_SUCCESS_MSG);
        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, INSERT_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @PostMapping("/deleteBatch")
    @ApiOperation(value = "根据-{文章分类表}-对象Map批量删除记录", notes = "成功返回:{\"success\":true,\"message\",\"数据删除成功\"},失败返回:{\"success\":false,\"message\",\"数据删除失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "id", value = "ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "title", value = "名称", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "description", value = "描述", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "parentid", value = "父ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "levelcode", value = "层级", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "icon", value = "图标", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "cls", value = "层样式", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "leaf", value = "树叶", required = true, dataType = "int", dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = "create_user_id", value = "创建用户", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "create_time", value = "创建时间", required = true, dataType = "Date", dataTypeClass = Date.class)
    })
    @OperateLog(name = "根据-{文章分类表}-对象Map批量删除记录", value = "delete", type = "PC")
    public Map<String, Object> deleteBatchForEbookArticleTypeForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody List<Map<String, Object>> list) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            ebookArticleTypeService.deleteBatch(list);
            result.put(DATASUCCESS, SUCCESSFLAG);
            result.put(DATAMESSAGE, DELETE_SUCCESS_MSG);

        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, DELETE_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @PostMapping("/updateBatch")
    @ApiOperation(value = "根据-{文章分类表}-对象Map批量更新记录", notes = "成功返回:{\"success\":true,\"message\",\"数据更新成功\"},失败返回:{\"success\":false,\"message\",\"数据更新失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "id", value = "ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "title", value = "名称", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "description", value = "描述", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "parentid", value = "父ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "levelcode", value = "层级", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "icon", value = "图标", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "cls", value = "层样式", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "leaf", value = "树叶", required = true, dataType = "int", dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = "create_user_id", value = "创建用户", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "create_time", value = "创建时间", required = true, dataType = "Date", dataTypeClass = Date.class)
    })
    @OperateLog(name = "根据-{文章分类表}-对象Map批量更新记录", value = "update", type = "PC")
    public Map<String, Object> updateBatchForEbookArticleTypeForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody List<Map<String, Object>> list) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {


            ebookArticleTypeService.updateBatch(list);
            result.put(DATASUCCESS, SUCCESSFLAG);
            result.put(DATAMESSAGE, UPDATE_SUCCESS_MSG);

        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, UPDATE_FAIL_MSG + e.getMessage());
        }
        return result;
    }


    @PostMapping("/getEbookArticleTypeByParentid")
    @ApiOperation(value = "查询所有文章分类数据根据父节点id", notes = "成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"data\":\"[]\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "parentid", value = "父房间ID", required = true,  dataTypeClass = String.class)
    })
    @OperateLog(name = "查询所有文章分类数据根据父节点id", value = "query", type = "PC")
    public Map<String, Object> getEbookArticleTypeByParentidForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {

            List<Map<String, Object>> treedata = ebookArticleTypeService.getEbookArticleTypeByParentid(map);

            result.put(DATASUCCESS, SUCCESSFLAG);
            result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
            result.put(DATALIST, treedata);

        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, QUERY_FAIL_MSG + e.getMessage());
        }
        return result;
    }


    @PostMapping("/getEbookArticleTypeByLevelCode")
    @ApiOperation(value = "查询所有文章分类数据根据层次码", notes = "成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"data\":\"[]\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "parentid", value = "父房间ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "levelcode", value = "层级", required = true,  dataTypeClass = String.class)
    })
    @OperateLog(name = "查询所有文章分类数据根据层次码", value = "query", type = "PC")
    public Map<String, Object> getEbookArticleTypeByLevelCodeForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            String parentid = map.get("parentid") + "";

            List<Map<String, Object>> treedata = ebookArticleTypeService.getEbookArticleTypeByLevelCode(map);

            List<Map<String, Object>> parenttreedata = new ArrayList<Map<String, Object>>();

            if (null != treedata && treedata.size() > 0) {

                //一级树节点
                for (Map<String, Object> tree : treedata) {
                    tree.put("key", tree.get("id"));
                    if (tree.get("parentid").equals(parentid)) {
                        parenttreedata.add(tree);
                    }
                }


                //二级树节点
                List<Map<String, Object>> second_treedata = new ArrayList<Map<String, Object>>();//二级树节点
                for (Map<String, Object> ptree : parenttreedata) {

                    List<Map<String, Object>> sontreedata = new ArrayList<Map<String, Object>>();
                    for (Map<String, Object> tree : treedata) {
                        tree.put("key", tree.get("id"));
                        if (tree.get("parentid").equals(ptree.get("id"))) {
                            second_treedata.add(tree);
                            sontreedata.add(tree);
                        }
                    }
                    ptree.put("children", sontreedata);
                }


                List<Map<String, Object>> third_treedata = new ArrayList<Map<String, Object>>();//三级树节点
                List<Map<String, Object>> fourth_treedata = new ArrayList<Map<String, Object>>();//四级树节点
                List<Map<String, Object>> fifth_treedata = new ArrayList<Map<String, Object>>();//五级树节点
                List<Map<String, Object>> sixth_treedata = new ArrayList<Map<String, Object>>();//六级树节点

                //三级树节点
                for (Map<String, Object> ptree : second_treedata) {
                    List<Map<String, Object>> sontreedata = new ArrayList<Map<String, Object>>();

                    for (Map<String, Object> tree : treedata) {
                        tree.put("key", tree.get("id"));

                        if (tree.get("parentid").equals(ptree.get("id"))) {
                            third_treedata.add(tree);
                            sontreedata.add(tree);
                        }
                    }
                    ptree.put("children", sontreedata);
                }


                //四级树节点
                for (Map<String, Object> ptree : third_treedata) {

                    List<Map<String, Object>> sontreedata = new ArrayList<Map<String, Object>>();
                    for (Map<String, Object> tree : treedata) {
                        tree.put("key", tree.get("id"));

                        if (tree.get("parentid").equals(ptree.get("id"))) {
                            fourth_treedata.add(tree);
                            sontreedata.add(tree);
                        }
                    }
                    ptree.put("children", sontreedata);
                }


                //五级树节点
                for (Map<String, Object> ptree : fourth_treedata) {

                    List<Map<String, Object>> sontreedata = new ArrayList<Map<String, Object>>();
                    for (Map<String, Object> tree : treedata) {
                        tree.put("key", tree.get("id"));

                        if (tree.get("parentid").equals(ptree.get("id"))) {
                            fifth_treedata.add(tree);
                            sontreedata.add(tree);
                        }
                    }
                    ptree.put("children", sontreedata);
                }


                //六级树节点
                for (Map<String, Object> ptree : fifth_treedata) {

                    List<Map<String, Object>> sontreedata = new ArrayList<Map<String, Object>>();
                    for (Map<String, Object> tree : treedata) {
                        tree.put("key", tree.get("id"));

                        if (tree.get("parentid").equals(ptree.get("id"))) {
                            sixth_treedata.add(tree);
                            sontreedata.add(tree);
                        }
                    }
                    ptree.put("children", sontreedata);
                }

            }

            result.put(DATASUCCESS, SUCCESSFLAG);
            result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
            result.put(DATALIST, parenttreedata);

        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, QUERY_FAIL_MSG + e.getMessage());
        }
        return result;
    }


    @PostMapping("/updateDropNode")
    @ApiOperation(value = "根据-{来源节点与目标节点}-对象更新记录", notes = "成功返回:{\"success\":true,\"message\",\"数据更新成功\"},失败返回:{\"success\":false,\"message\",\"数据更新失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "source_id", value = "来源文章分类ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "source_parentid", value = "来源文章分类父ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "target_id", value = "目标文章分类ID", required = true,  dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "levelcode", value = "修改后的层次码", required = true,  dataTypeClass = String.class),
    })
    @OperateLog(name = "根据-{来源节点与目标节点}-对象更新记录", value = "update", type = "PC")
    public Map<String, Object> updateDropNodeForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            Map<String, Object> temp = new HashMap<String, Object>();

            temp.put("id", map.get("source_id"));
            temp.put("source_parentid", map.get("source_parentid"));
            temp.put("parentid", map.get("target_id"));
            temp.put("levelcode", map.get("levelcode"));

            Map<String, Object> paramsmap = ebookArticleTypeService.selectByPrimaryKey(map.get("source_id") + "");


            int flag = 0;

            if (null != paramsmap && paramsmap.size() > 0) {
                paramsmap.putAll(temp);
                flag = ebookArticleTypeService.updateDropNode(paramsmap);
            }
            if (1 <= flag) {
                 // 修改子节点 levelcode
                    ebookArticleTypeService.updateBatchLevelCode(new HashMap<String, Object>() {{
                    put("source_levelcode", map.get("source_levelcode"));
                    put("levelcode", map.get("levelcode"));
                }});
                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, UPDATE_SUCCESS_MSG);
                result.put(DATARECORD, paramsmap);
            } else {
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, UPDATE_FAIL_MSG);
            }

        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, UPDATE_FAIL_MSG + e.getMessage());
        }
        return result;
    }

}
