package org.jeecg.modules.projectManagement.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.NotDuplicate;
import org.jeecg.common.aspect.annotation.PermissionData;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.projectManagement.entity.FdWorkingHours;
import org.jeecg.modules.projectManagement.entity.FdWorkingHoursItems;
import org.jeecg.modules.projectManagement.service.IFdWorkingHoursItemsService;
import org.jeecg.modules.projectManagement.service.IFdWorkingHoursService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysSerialPatternService;
import org.jeecg.modules.system.vo.CallResult;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;

/**
 * @Title: Controller
 * @Description: 工时记录
 * @author： jeecg-boot
 * @date： 2019-06-25
 * @version： V1.0
 */
@RestController
@RequestMapping("/projectManagement/fdWorkingHours")
@Slf4j
public class FdWorkingHoursController {
    @Autowired
    private IFdWorkingHoursService fdWorkingHoursService;

    @Autowired
    private IFdWorkingHoursItemsService fdWorkingHoursItemsService;
    @Autowired
    ISysSerialPatternService iSysSerialPatternService;

    /**
     * 分页列表查询
     *
     * @param fdWorkingHours
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @GetMapping(value = "/list")
    @PermissionData(pageComponent = "projectMilestones-working")
    @RequiresPermissions("url:working:view")
    public Result<IPage<FdWorkingHours>> queryPageList(FdWorkingHours fdWorkingHours,
                                                       @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                       @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize,
                                                       HttpServletRequest req) {
        Result<IPage<FdWorkingHours>> result = new Result<IPage<FdWorkingHours>>();

         // String hourFiller = fdWorkingHours.getHourFiller();
         // if (StringUtils.isNotBlank(fdWorkingHours.getHourFiller())) {
         //     fdWorkingHours.setHourFiller(null);
         // }
        // Date createTime = fdWorkingHours.getCreateTime();
        // if (fdWorkingHours.getCreateTime()!=null&& !fdWorkingHours.getCreateTime().equals("null")&& !fdWorkingHours.getCreateTime().equals("")) {
        //     fdWorkingHours.setCreateTime(null);
        // }
        String startDate=fdWorkingHours.getStartDate();//开始时间
        String endDate=fdWorkingHours.getEndDate();//结束时间
        if(StringUtils.isNotBlank(startDate)){
            fdWorkingHours.setStartDate(null);
        }
        if(StringUtils.isNotBlank(endDate)){
            fdWorkingHours.setEndDate(null);
        }
        QueryWrapper<FdWorkingHours> queryWrapper = QueryGenerator.initQueryWrapper(fdWorkingHours, req.getParameterMap());
        // queryWrapper.eq("wh.del_flag", "0");
        // queryWrapper.eq("whi.sort", "1");
        //  if (StringUtils.isNotBlank(hourFiller)) {
        //      queryWrapper.like("hour_filler", hourFiller);
        //  }
        // if (oConvertUtils.isNotEmpty(createTime)){
        //     queryWrapper.eq("wh.create_time",createTime);
        // }
        // queryWrapper.orderByDesc("wh.create_time");
        Page<FdWorkingHours> page = new Page<FdWorkingHours>(pageNo, pageSize);
        // IPage<FdWorkingHours> pageList = fdWorkingHoursService.findByPage(page, queryWrapper);
        queryWrapper.lambda().eq(FdWorkingHours::getDelFlag,"0");


        if(StringUtils.isNotBlank(startDate)&&StringUtils.isNotBlank(endDate)){
            //时间间隔查询
            queryWrapper.between("actual_hours",startDate,endDate);
        }else{
            //获取前45天的日期
            Calendar now = Calendar.getInstance();
            now.add(Calendar.DAY_OF_MONTH, -45);
            String date = new SimpleDateFormat("yyyy-MM-dd").format(now.getTime());
            queryWrapper.gt("actual_hours",date);
        }
        queryWrapper.lambda().orderByDesc(FdWorkingHours::getActualHours);
        IPage<FdWorkingHours> pageList = fdWorkingHoursService.page(page, queryWrapper);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /***
     * @Title:工时记录审核分页查询
            * @Description:TODO
            * @param fdWorkingHours, pageNo, pageSize, req]
            * @return org.jeecg.common.api.vo.Result<com.baomidou.mybatisplus.core.metadata.IPage<org.jeecg.modules.projectManagement.entity.FdWorkingHours>>
            * @exception 
            * @author 陈创
            * @date 2019/10/10 14:52
            * @updatehistory:
     *   2019/10/10 14:52 新增
            */
    @GetMapping(value = "/examinePage")
    @PermissionData(pageComponent = "projectMilestones-working-check")
    @RequiresPermissions("url:working:view")
    public Result<IPage<FdWorkingHours>> examinePage(FdWorkingHours fdWorkingHours,
                                                       @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                       @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize,
                                                       HttpServletRequest req) {
        Result<IPage<FdWorkingHours>> result = new Result<IPage<FdWorkingHours>>();

        //获取上级领导id
        // String hourFillerId=fdWorkingHours.getHourFillerId();
        // if(StringUtils.isNotBlank(hourFillerId)){
        //     fdWorkingHours.setHourFillerId(null);
        // }

        //获取工时时间
        Date actualHours=fdWorkingHours.getActualHours();
        String startDate=fdWorkingHours.getStartDate();//开始时间
        String endDate=fdWorkingHours.getEndDate();//结束时间
        if(actualHours!=null){
            fdWorkingHours.setActualHours(null);
        }
        if(StringUtils.isNotBlank(startDate)){
            fdWorkingHours.setStartDate(null);
        }
        if(StringUtils.isNotBlank(endDate)){
            fdWorkingHours.setEndDate(null);
        }
        //工时填报人
        String createBy=fdWorkingHours.getCreateBy();
        if(StringUtils.isNotBlank(createBy)){
            fdWorkingHours.setCreateBy(null);
        }
        QueryWrapper<FdWorkingHours> queryWrapper = QueryGenerator.initQueryWrapper(fdWorkingHours, req.getParameterMap());
        //上级领导条件
        // if(StringUtils.isNotBlank(hourFillerId)){
        //     queryWrapper.eq("p.pk_personnel",hourFillerId);
        // }
        queryWrapper.eq("wh.del_flag","0");
        if(actualHours!=null){
            queryWrapper.eq("wh.actual_hours",actualHours);
        }
        if(StringUtils.isNotBlank(createBy)&&!createBy.equals("null")){
            queryWrapper.eq("wh.create_by",createBy);
        }
        if(StringUtils.isNotBlank(startDate)&&StringUtils.isNotBlank(endDate)){
            //时间间隔查询
            queryWrapper.between("wh.actual_hours",startDate,endDate);
        }else{
            //获取前45天的日期
            Calendar now = Calendar.getInstance();
            now.add(Calendar.DAY_OF_MONTH, -45);
            String date = new SimpleDateFormat("yyyy-MM-dd").format(now.getTime());
            queryWrapper.gt("actual_hours",date);
        }
        queryWrapper.lambda().orderByDesc(FdWorkingHours::getActualHours);
        Page<FdWorkingHours> page = new Page<FdWorkingHours>(pageNo, pageSize);
        IPage<FdWorkingHours> pageList = fdWorkingHoursService.examinePage(page, queryWrapper);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /**
     * 添加
     *
     * @param fdWorkingHours
     * @return
     */
    @PostMapping(value = "/add")
    @NotDuplicate
    public Result<FdWorkingHours> add(@RequestBody @Valid FdWorkingHours fdWorkingHours, BindingResult bindingResult) {
        Result<FdWorkingHours> result = new Result<FdWorkingHours>();
        try {
            StringBuilder sb = new StringBuilder();
            if (bindingResult.hasErrors()) {
                //记录错误信息
                bindingResult.getAllErrors().stream().forEach(error -> sb.append(error.getDefaultMessage() + "<br/>"));
                result.error500(sb.toString());
                return result;
            }
            fdWorkingHoursService.save(fdWorkingHours);
            result.success("添加成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.info(e.getMessage());
            result.error500("操作失败");
        }
        return result;
    }

    /**
     * 编辑
     *
     * @param fdWorkingHours
     * @return
     */
    @PutMapping(value = "/edit")
    @NotDuplicate
    public Result<FdWorkingHours> edit(@RequestBody @Valid FdWorkingHours fdWorkingHours, BindingResult bindingResult) {
        Result<FdWorkingHours> result = new Result<FdWorkingHours>();
        FdWorkingHours fdWorkingHoursEntity = fdWorkingHoursService.getById(fdWorkingHours.getId());
        if (fdWorkingHoursEntity == null) {
            result.error500("未找到对应实体");
        } else {
            StringBuilder sb = new StringBuilder();
            if (bindingResult.hasErrors()) {
                //记录错误信息
                bindingResult.getAllErrors().stream().forEach(error -> sb.append(error.getDefaultMessage() + "<br/>"));
                result.error500(sb.toString());
                return result;
            }
            fdWorkingHours.setProjectHoursTotal(null);
            fdWorkingHours.setNonProjectHoursTotal(null);
            boolean ok = fdWorkingHoursService.updateById(fdWorkingHours);
            //TODO 返回false说明什么？
            if (ok) {
                result.success("修改成功!");
            }
        }

        return result;
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    // @DeleteMapping(value = "/delete")
    // public Result<FdWorkingHours> delete(@RequestParam(name = "id", required = true) String id) {
    //     Result<FdWorkingHours> result = new Result<FdWorkingHours>();
    //     FdWorkingHours fdWorkingHours = fdWorkingHoursService.getById(id);
    //     if (fdWorkingHours == null) {
    //         result.error500("未找到对应实体");
    //     } else {
    //         boolean ok = fdWorkingHoursService.removeById(id);
    //         if (ok) {
    //             result.success("删除成功!");
    //         }
    //     }
    //
    //     return result;
    // }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @DeleteMapping(value = "/delete")
    @NotDuplicate
    @RequiresPermissions("working:delete")
    public Result<FdWorkingHours> delete(@RequestParam(name = "id", required = true) String id) {
        Result<FdWorkingHours> result = new Result<FdWorkingHours>();
        FdWorkingHours fdWorkingHours = fdWorkingHoursService.getById(id);
        if (fdWorkingHours == null) {
            result.error500("未找到对应实体");
        } else {
            fdWorkingHours.setDelFlag(CommonConstant.DEL_FLAG_1.toString());
            boolean ok = fdWorkingHoursService.updateById(fdWorkingHours);
            if (ok) {
                result.success("删除成功!");
            }
        }

        return result;
    }

    @DeleteMapping(value = "/deleteAll")
    public Result<FdWorkingHours> deleteAll(@RequestParam(name = "id", required = true) String id) {
        Result<FdWorkingHours> result = new Result<FdWorkingHours>();
        FdWorkingHours fdWorkingHours = fdWorkingHoursService.getById(id);
        if (fdWorkingHours == null) {
            result.error500("未找到对应实体");
        } else {
            boolean ok = fdWorkingHoursService.deleteAll(id);
            if (ok) {
                result.success("删除成功!");
            }
        }

        return result;
    }


    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @DeleteMapping(value = "/deleteBatch")
    public Result<FdWorkingHours> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        Result<FdWorkingHours> result = new Result<FdWorkingHours>();
        if (ids == null || "".equals(ids.trim())) {
            result.error500("参数不识别！");
        } else {
            this.fdWorkingHoursService.removeByIds(Arrays.asList(ids.split(",")));
            result.success("删除成功!");
        }
        return result;
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/queryById")
    public Result<FdWorkingHours> queryById(@RequestParam(name = "id", required = true) String id) {
        Result<FdWorkingHours> result = new Result<FdWorkingHours>();
        FdWorkingHours fdWorkingHours = fdWorkingHoursService.getById(id);
        QueryWrapper<FdWorkingHoursItems> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("pk_woking_hour", fdWorkingHours.getId());
        fdWorkingHours.setFdWorkingHoursItemsList(fdWorkingHoursItemsService.list(queryWrapper));
        if (fdWorkingHours == null) {
            result.error500("未找到对应实体");
        } else {
            result.setResult(fdWorkingHours);
            result.setSuccess(true);
        }
        return result;
    }

    /**
     * 导出excel
     *
     * @param request
     * @param response
     */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
        // Step.1 组装查询条件
        QueryWrapper<FdWorkingHours> queryWrapper = null;
        try {
            String paramsStr = request.getParameter("paramsStr");
            if (oConvertUtils.isNotEmpty(paramsStr)) {
                String deString = URLDecoder.decode(paramsStr, "UTF-8");
                FdWorkingHours fdWorkingHours = JSON.parseObject(deString, FdWorkingHours.class);
                queryWrapper = QueryGenerator.initQueryWrapper(fdWorkingHours, request.getParameterMap());
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        //Step.2 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        List<FdWorkingHours> pageList = fdWorkingHoursService.list(queryWrapper);
        //导出文件名称
        mv.addObject(NormalExcelConstants.FILE_NAME, "工时记录列表");
        mv.addObject(NormalExcelConstants.CLASS, FdWorkingHours.class);
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("工时记录列表数据", "导出人:Jeecg", "导出信息"));
        mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
        return mv;
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            MultipartFile file = entity.getValue();// 获取上传文件对象
            ImportParams params = new ImportParams();
            params.setTitleRows(2);
            params.setHeadRows(1);
            params.setNeedSave(true);
            try {
                List<FdWorkingHours> listFdWorkingHourss = ExcelImportUtil.importExcel(file.getInputStream(), FdWorkingHours.class, params);
                for (FdWorkingHours fdWorkingHoursExcel : listFdWorkingHourss) {
                    fdWorkingHoursService.save(fdWorkingHoursExcel);
                }
                return Result.ok("文件导入成功！数据行数：" + listFdWorkingHourss.size());
            } catch (Exception e) {
                log.error(e.getMessage());
                return Result.error("文件导入失败！");
            } finally {
                try {
                    file.getInputStream().close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return Result.ok("文件导入失败！");
    }

    @PostMapping(value = "/addAll")
    @NotDuplicate
    @RequiresPermissions("working:add")
    public Result<FdWorkingHours> addAll(@RequestBody @Valid FdWorkingHours fdWorkingHours, BindingResult bindingResult) {
        Result<FdWorkingHours> result = new Result<FdWorkingHours>();
        try {
            CallResult<String> resultSerial = iSysSerialPatternService.getNextSerial(fdWorkingHours, "fd_working_hours", "code", true);
            if (!resultSerial.isSucceed()) {
                result.error500("获取编码失败");
                return result;
            }
            StringBuilder sb = new StringBuilder();
            if (bindingResult.hasErrors()) {
                //记录错误信息
                bindingResult.getAllErrors().stream().forEach(error -> sb.append(error.getDefaultMessage() + "<br/>"));
                result.error500(sb.toString());
                return result;
            }
            fdWorkingHours.setCode(resultSerial.getContent());
            fdWorkingHoursService.addAll(fdWorkingHours);
            result.success("添加成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.info(e.getMessage());
            result.error500("操作失败");
        }
        return result;
    }

    @GetMapping(value = "/copy")
    public Result copy(@RequestParam(name = "id",required = true) String id,@RequestParam(name = "actualHours",required = true) String actualHours){
        Result result=new Result();
        FdWorkingHours fdWorkingHours=fdWorkingHoursService.getById(id);
        if(fdWorkingHours==null){
            result.error500("未找到对应实体");
        }else{
            CallResult<String> resultSerial = iSysSerialPatternService.getNextSerial(fdWorkingHours, "fd_working_hours", "code", true);
            if (!resultSerial.isSucceed()) {
                result.error500("获取编码失败");
                return result;
            }
            SimpleDateFormat simdate1=new SimpleDateFormat("yyyy-MM-dd");
            try {
                fdWorkingHours.setActualHours(simdate1.parse(actualHours));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            SysUser user = (SysUser) SecurityUtils.getSubject().getPrincipal();
            fdWorkingHours.setCode(resultSerial.getContent());
            fdWorkingHours.setCreateTime(new Date());
            fdWorkingHours.setCreateBy(user.getUsername());
            LambdaQueryWrapper<FdWorkingHoursItems> fdWorkingHoursItemsLambdaQueryWrapper=new LambdaQueryWrapper<>();
            fdWorkingHoursItemsLambdaQueryWrapper.eq(FdWorkingHoursItems::getDelFlag,"0");
            fdWorkingHoursItemsLambdaQueryWrapper.eq(FdWorkingHoursItems::getPkWokingHour,fdWorkingHours.getId());
            fdWorkingHoursItemsLambdaQueryWrapper.orderByAsc(FdWorkingHoursItems::getSort);
            List<FdWorkingHoursItems> fdWorkingHoursItemsList=fdWorkingHoursItemsService.list(fdWorkingHoursItemsLambdaQueryWrapper);
            fdWorkingHours.setId(null);
            if(fdWorkingHoursItemsList!=null&&fdWorkingHoursItemsList.size()>0){
                for(FdWorkingHoursItems fdWorkingHoursItems:fdWorkingHoursItemsList){
                    fdWorkingHoursItems.setId(null);
                    fdWorkingHoursItems.setCreateBy(user.getUsername());
                    fdWorkingHoursItems.setCreateTime(new Date());
                }
                fdWorkingHours.setFdWorkingHoursItemsList(fdWorkingHoursItemsList);
            }
            fdWorkingHoursService.addAll(fdWorkingHours);
            result.success("操作成功");
        }
        return result;
    }

    /**
     * @return org.jeecg.common.api.vo.Result<org.jeecg.modules.projectManagement.entity.FdWorkingHours>
     * @Author gurui
     * @Description //TODO 审核数据
     * @Date 17:24 2019/7/9
     * @Param [ids]
     **/
    @GetMapping(value = "/reviewBatch")
    public Result<FdWorkingHours> reviewBatch(@RequestParam(name = "ids", required = true) List<String> ids) {
        Result<FdWorkingHours> result = new Result<>();
        String message = "";
        if (ids.isEmpty()) {
            message += "请选择数据</br>";
        }
        Map<String, Object> map = null;
        try {
            //执行service
            map = fdWorkingHoursService.reviewBatch(ids);
            result.setSuccess(true);
            result.setMessage(message + map.get("msg").toString());
        } catch (Exception e) {
            e.printStackTrace();
            result.setSuccess(false);
        }
        return result;
    }


    /**
     * @return org.jeecg.common.api.vo.Result<org.jeecg.modules.projectManagement.entity.FdWorkingHours>
     * @Author gurui
     * @Description //TODO 弃审核数据 是其状态变为0
     * @Date 17:24 2019/7/9
     * @Param [ids]
     **/
    @GetMapping(value = "/auditBatch")
    public Result<FdWorkingHours> auditBatch(@RequestParam(name = "ids", required = true) List<String> ids) {
        Result<FdWorkingHours> result = new Result<>();
        String message = "";
        if (ids.isEmpty()) {
            message += "请选择数据</br>";
        }
        Map<String, Object> map = null;
        try {
            //执行service
            map = fdWorkingHoursService.auditBatch(ids);
            result.setSuccess(true);
            result.setMessage(message + map.get("msg").toString());
        } catch (Exception e) {
            e.printStackTrace();
            result.setSuccess(false);
        }
        return result;
    }

    /***
     * @Title:查询今天是否做过工时记录
     * @Description:TODO 根据当天，登陆人
     * @param nowDate, createBy]
     * @return org.jeecg.common.api.vo.Result
     * @exception
     * @author 陈创
     * @date 2019/9/10 10:59
     * @updatehistory:
     *   2019/9/10 10:59 新增
     */
    @GetMapping(value = "/getNowDayCount")
    public Result<Boolean> getNowDayCount(String nowDate, String createBy) {
        Result<Boolean> result =new Result<>();
        try {
            int count = fdWorkingHoursService.getNowDayCount(nowDate, createBy);
            if (count > 0) {
                //当天存在工时
                result.setResult(false);
                result.setSuccess(true);
                result.setMessage("操作失败 ");
//                result.setMessage("您当天已经填报过工时记录");
            } else {
                //当天不存在工时
                result.setResult(true);
                result.setSuccess(true);
            }
        } catch (Exception e) {
            e.printStackTrace();
            result.error500("操作失败" + e.getMessage());
        }
        return result;
    }

    /***
     * @Title:工时记录上级领导改变审核状态
            * @Description:TODO
            * @param fdWorkingHours
            * @return org.jeecg.common.api.vo.Result
            * @exception
            * @author 陈创
            * @date 2019/10/11 10:18
            * @updatehistory:
     *   2019/10/11 10:18 新增
            */
    @GetMapping(value = "/updateStatus")
    public Result updateStatus(FdWorkingHours fdWorkingHours){
        Result result=new Result();
        try {
            fdWorkingHoursService.updateStatus(fdWorkingHours);
            result.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            result.error500("操作失败："+e.getMessage());
        }
        return result;
    }
}
