package com.ruoyi.web.controller.api;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.annotation.RateLimiter;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.ApiResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.JPushUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.mall.domain.*;
import com.ruoyi.mall.domain.dto.MallAppAddressDTO;
import com.ruoyi.mall.domain.dto.MallAppOrderOrderDTO;
import com.ruoyi.mall.domain.dto.MallOrderOrderDTO;
import com.ruoyi.mall.domain.vo.MallOrderGoodsVO;
import com.ruoyi.mall.mapper.MallGoodsGoodsMapper;
import com.ruoyi.mall.mapper.MallGoodsProductMapper;
import com.ruoyi.mall.service.*;
import com.ruoyi.system.mapper.SysUserMapper;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * APP
 *
 * @author chang
 * @date 2024-06-25
 */
@RestController
@RequestMapping("/api/app")
@ApiOperation("app")
public class ApiAppController {

    @Resource
    private IMallAppCompanyUserService mallAppCompanyUserService;
    @Resource
    private IMallAppAddressService mallAppAddressService;
    @Resource
    private IMallAppOrderOrderService mallAppOrderOrderService;
    @Resource
    private IMallAppGoodsUnitService mallAppGoodsUnitService;
    @Resource
    private IMallAppSalesmanAchievementService mallAppSalesmanAchievementService;
    @Resource
    private IMallAppOrderGoodsService mallAppOrderGoodsService;

    @Resource
    private SysUserMapper sysUserMapper;
    @Resource
    private JPushUtils jPushUtils;

    @Resource
    private IMallGoodsGoodsService mallGoodsGoodsService;
    @Resource
    private MallGoodsGoodsMapper mallGoodsGoodsMapper;
    @Resource
    private MallGoodsProductMapper mallGoodsProductMapper;
    @Resource
    private IMallOrderOrderService mallOrderOrderService;
    @Resource
    private IMallSalesmanService mallSalesmanService;
    @Resource
    private IMallConfigService mallConfigService;

    /**
     * 测试4（新增业务员、分公司管理系统用户信息）
     *
     * @param params 参数
     * @return ok
     */
    @GetMapping("/test4")
    public ApiResult test4(@RequestParam Map<String, Object> params) {
        try {
            List<MallSalesman> salesmanList = mallSalesmanService.selectMallSalesmanList(new MallSalesman());
            if (salesmanList.size() > 0) {
                for (MallSalesman salesman : salesmanList) {
                    if (salesman.getSysUserId() == null || salesman.getSysUserId() == 0) {
                        mallSalesmanService.insertSysUserMallSalesman(salesman);
                    }
                }
            }

            System.out.println("新增业务员、分公司管理系统用户信息" );
            return ApiResult.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResult.error("测试4异常");
        }
    }

    /**
     * 测试3（线上订单修改orderStatus等）
     *
     * @param params 参数
     * @return ok
     */
    @GetMapping("/test3")
    public ApiResult test3(@RequestParam Map<String, Object> params) {
        try {
            MallOrderOrder mallOrderOrder = new MallOrderOrder();
            mallOrderOrder.setDelFlag("0");
            List<MallOrderOrder> mallOrderOrders = mallOrderOrderService.selectMallOrderOrderList(mallOrderOrder);
            if (mallOrderOrders.size() > 0) {
                for (MallOrderOrder order : mallOrderOrders) {
                    MallOrderOrder orderOrder = new MallOrderOrder();
                    orderOrder.setId(order.getId());
                    if ("0".equals(order.getStatus()) || "8".equals(order.getStatus())) {
                        orderOrder.setIsPay("0");
                        orderOrder.setOrderStatus(order.getStatus());
                        orderOrder.setIsExamine("0");
                        orderOrder.setIsProof("0");
                        orderOrder.setIsFinance("0");
                        orderOrder.setIsCar("0");
                    }
                    if ("1".equals(order.getStatus())) {
                        orderOrder.setIsPay("1");
                        orderOrder.setOrderStatus("2");
                        orderOrder.setIsExamine("1");
                        orderOrder.setIsProof("1");
                        orderOrder.setIsFinance("1");
                        orderOrder.setIsCar("0");
                    }
                    if ("2".equals(order.getStatus()) || "3".equals(order.getStatus()) || "4".equals(order.getStatus())) {
                        orderOrder.setIsPay("1");
                        if ("2".equals(order.getStatus())) {
                            orderOrder.setOrderStatus("4");
                        }
                        if ("3".equals(order.getStatus()) || "4".equals(order.getStatus())) {
                            orderOrder.setOrderStatus("5");
                        }
                        orderOrder.setIsExamine("1");
                        orderOrder.setIsProof("1");
                        orderOrder.setIsFinance("1");
                        orderOrder.setIsCar("1");
                    }

                    if ("5".equals(order.getStatus()) || "6".equals(order.getStatus())) {
                        orderOrder.setIsPay("1");
                        orderOrder.setOrderStatus("5");
                        orderOrder.setIsExamine("1");
                        orderOrder.setIsProof("1");
                        orderOrder.setIsFinance("1");
                        orderOrder.setIsCar("1");
                    }

                    mallOrderOrderService.updateMallOrderOrder(orderOrder);
                }
            }

            System.out.println("线上订单修改orderStatus等=" + mallOrderOrders.size());
            return ApiResult.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResult.error("测试2异常");
        }
    }

    /**
     * 测试
     *
     * @param params 参数
     * @return ok
     */
    @GetMapping("/test")
    public ApiResult test(@RequestParam Map<String, Object> params) {
        try {
            String name = MapUtils.getString(params, "name");
            String phone = MapUtils.getString(params, "phone");

            // 极光推送
            // roleId：1-超级管理员，12-仓库管理员，13-财务，10-分公司管理员，11-业务员
            Map<String, Object> newParams = new HashMap<>();
            newParams.put("roleId", 1);
            String[] userName = sysUserMapper.selectUserNameByParams(newParams);
            if (userName.length > 0) {
                // jPushUtils.jPush(userName, name + phone +"下单，请及时审核", "新增线下订单");
            }
            return ApiResult.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResult.error("测试异常");
        }
    }

    /**
     * app用户登录
     *
     * @param param
     * @return
     */
    @PostMapping("/appUserLogin")
    @ApiOperation("app登录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "账号", dataType = "String"),
            @ApiImplicitParam(name = "password", value = "密码", dataType = "String")
    })
    public ApiResult appUserLogin(@RequestBody Map<String, Object> param) {
        if (!param.containsKey("account") || MapUtils.getString(param, "account") == null) {
            return ApiResult.error("请输入账号");
        }
        if (!param.containsKey("password") || MapUtils.getString(param, "password") == null) {
            return ApiResult.error("请输入密码");
        }
        try {
            return mallAppCompanyUserService.appUserLogin(param);
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResult.error("app用户登录异常");
        }
    }

    /**
     * 地址管理列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数据量
     * @param params   sysUserId 用户ID
     * @param params   addressType 地址类型：0-寄件人地址，1-收件人地址
     * @param params   keyword 搜索关键词
     * @return ok
     */
    @GetMapping("/getAddressManageList")
    public ApiResult getAddressManageList(@RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                                          @RequestParam(value = "pageSize", defaultValue = "100", required = false) Integer pageSize,
                                          @RequestParam Map<String, Object> params) {
        if (!params.containsKey("sysUserId") || StringUtils.isBlank(params.get("sysUserId").toString())) {
            return ApiResult.error("请先登录");
        }
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<MallAppAddress> list = mallAppAddressService.getAddressManageList(params);
            PageInfo<MallAppAddress> pageInfo = new PageInfo(list);
            return ApiResult.ok().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResult.error("地址管理列表异常");
        }
    }

    /**
     * 新增地址管理
     *
     * @param resourceDTO 地址管理对象
     * @return ok
     */
    @RepeatSubmit
    @RateLimiter(key = "API_addAddressManage", time = 5, count = 50)
    @PostMapping("/addAddressManage")
    public ApiResult addAddressManage(@RequestBody @Validated({MallAppAddressDTO.addMallAppAddressDTO.class}) MallAppAddressDTO resourceDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return ApiResult.allParameterErrors(bindingResult);
        }
        try {
            return mallAppAddressService.insertMallAppAddressByDTO(resourceDTO);
        } catch (Exception e) {
            return ApiResult.error("新增地址管理异常");
        }
    }

    /**
     * 修改地址管理
     *
     * @param resourceDTO 地址管理对象
     * @return ok
     */
    @RepeatSubmit
    @RateLimiter(key = "API_updateAddressManage", time = 5, count = 50)
    @PostMapping("/updateAddressManage")
    public ApiResult updateAddressManage(@RequestBody @Validated({MallAppAddressDTO.updateMallAppAddressDTO.class}) MallAppAddressDTO resourceDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return ApiResult.allParameterErrors(bindingResult);
        }
        try {
            return mallAppAddressService.updateMallAppAddressByDTO(resourceDTO);
        } catch (Exception e) {
            return ApiResult.error("修改地址管理异常");
        }
    }

    /**
     * 删除地址管理
     *
     * @param resourceDTO 地址管理对象
     * @return ok
     */
    @RepeatSubmit
    @RateLimiter(key = "API_deleteAddressManage", time = 5, count = 50)
    @PostMapping("/deleteAddressManage")
    public ApiResult deleteAddressManage(@RequestBody @Validated({MallAppAddressDTO.deleteMallAppAddressDTO.class}) MallAppAddressDTO resourceDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return ApiResult.allParameterErrors(bindingResult);
        }
        try {
            MallAppAddress mallAppAddress = mallAppAddressService.selectMallAppAddressByAddressId(resourceDTO.getAddressId());
            if (!resourceDTO.getSysUserId().equals(mallAppAddress.getSysUserId())) {
                return ApiResult.error("地址异常");
            }
            mallAppAddressService.deleteMallAppAddressByAddressId(resourceDTO.getAddressId());
            return ApiResult.ok("删除成功");
        } catch (Exception e) {
            return ApiResult.error("删除地址管理异常");
        }
    }

    /**
     * 立即下单
     *
     * @param resourceDTO 订单对象
     * @return ok
     */
    @RepeatSubmit
    @RateLimiter(key = "API_createOrderNow", time = 5, count = 50)
    @PostMapping("/createOrderNow")
    public ApiResult createOrderNow(@RequestBody @Validated({MallAppOrderOrderDTO.addMallAppOrderOrderDTO.class}) MallAppOrderOrderDTO resourceDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return ApiResult.allParameterErrors(bindingResult);
        }
        try {
            return mallAppOrderOrderService.insertMallAppOrderOrderByDTO(resourceDTO);
        } catch (Exception e) {
            return ApiResult.error("立即下单异常");
        }
    }

    /**
     * 业务员列表
     *
     * @param params sysUserId 用户ID
     * @return ok
     */
    @GetMapping("/getSalesmanList")
    public ApiResult getSalesmanList(@RequestParam Map<String, Object> params) {
        if (!params.containsKey("sysUserId") || StringUtils.isBlank(params.get("sysUserId").toString())) {
            return ApiResult.error("请先登录");
        }
        try {
            return ApiResult.ok().put("data", mallAppCompanyUserService.getSalesmanList(params));
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResult.error("业务员列表异常");
        }
    }

    /**
     * 订单状态列表
     *
     * @param params sysUserId 用户ID
     * @param params orderType 订单类型：0-线上订单，3-线下订单
     * @return ok
     */
    @GetMapping("/getOrderStatusList")
    public ApiResult getOrderStatusList(@RequestParam Map<String, Object> params) {
        if (!params.containsKey("sysUserId") || StringUtils.isBlank(params.get("sysUserId").toString())) {
            return ApiResult.error("请先登录");
        }
        if (!params.containsKey("orderType") || StringUtils.isBlank(params.get("orderType").toString())) {
            return ApiResult.error("请选择订单类型");
        }
        try {
            return ApiResult.ok().put("data", mallAppCompanyUserService.getOrderStatusList(params));
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResult.error("订单状态列表异常");
        }
    }

    /**
     * 商品单位列表
     *
     * @return ok
     */
    @GetMapping("/getGoodsUnitList")
    public ApiResult getGoodsUnitList() {
        try {
            MallAppGoodsUnit mallAppGoodsUnit = new MallAppGoodsUnit();
            mallAppGoodsUnit.setStatus("0");
            mallAppGoodsUnit.setDelFlag("0");
            return ApiResult.ok().put("data", mallAppGoodsUnitService.selectMallAppGoodsUnitList(mallAppGoodsUnit));
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResult.error("商品单位列表异常");
        }
    }

    /**
     * 订单列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数据量
     * @param params   sysUserId 用户ID
     * @param params   status 订单状态：-1-全部，0-未付款，1-已付款，2-待接单，3-待发货，4-已装车，5-已完成，,8-已取消
     * @param params   orderNo 订单号
     * @param params   keyword 搜索关键词
     * @param params   beginCreateAt 下单时间开始
     * @param params   endCreateAt 下单时间结束
     * @param params   salesmanId 业务员ID
     * @param params   orderType 订单类型：0-线上订单，3-线下订单
     * @return ok
     */
    @GetMapping("/getOrderList")
    public ApiResult getOrderList(@RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                                  @RequestParam(value = "pageSize", defaultValue = "100", required = false) Integer pageSize,
                                  @RequestParam Map<String, Object> params) {
        if (!params.containsKey("sysUserId") || StringUtils.isBlank(params.get("sysUserId").toString())) {
            return ApiResult.error("请先登录");
        }
        if (!params.containsKey("orderType") || StringUtils.isBlank(params.get("orderType").toString())) {
            return ApiResult.error("请选择订单类型");
        }
        try {
            params.put("pageNum", pageNum);
            params.put("pageSize", pageSize);
            List<Map<String, Object>> list = mallAppOrderOrderService.selectMallAppOrderOrderListByParams(params);
            PageInfo<Map<String, Object>> pageInfo = new PageInfo(list);
            return ApiResult.ok().put("data", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResult.error("订单列表异常");
        }
    }

    /**
     * 订单详情
     *
     * @param params sysUserId 用户ID
     *               orderId 订单ID
     *               orderType 订单类型：0-线上订单，3-线下订单
     * @return ok
     */
    @GetMapping("/getOrderInfo")
    public ApiResult getOrderInfo(@RequestParam Map<String, Object> params) {
        if (!params.containsKey("sysUserId") || StringUtils.isBlank(params.get("sysUserId").toString())) {
            return ApiResult.error("请先登录");
        }
        if (!params.containsKey("orderId") || StringUtils.isBlank(params.get("orderId").toString())) {
            return ApiResult.error("请先选择订单");
        }
        if (!params.containsKey("orderType") || StringUtils.isBlank(params.get("orderType").toString())) {
            return ApiResult.error("请先选择订单类型");
        }
        try {
            return mallAppOrderOrderService.selectMallAppOrderOrderByParams(params);
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResult.error("订单详情异常");
        }
    }

    /**
     * 删除订单
     *
     * @param resourceDTO 订单对象
     * @return ok
     */
    @RepeatSubmit
    @RateLimiter(key = "API_deleteOrder", time = 5, count = 50)
    @PostMapping("/deleteOrder")
    public ApiResult deleteOrder(@RequestBody @Validated({MallAppOrderOrderDTO.deleteMallAppOrderOrderDTO.class}) MallAppOrderOrderDTO resourceDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return ApiResult.allParameterErrors(bindingResult);
        }
        try {
            MallAppSalesmanAchievement appSalesmanAchievement = mallAppSalesmanAchievementService.selectMallAppSalesmanAchievementByOrderId(resourceDTO.getId());
            if (appSalesmanAchievement != null) {
                appSalesmanAchievement.setStatus("2");
                mallAppSalesmanAchievementService.updateMallAppSalesmanAchievement(appSalesmanAchievement);
            }
            return mallAppOrderOrderService.deleteMallAppOrderOrderById(resourceDTO.getId()) > 0 ? ApiResult.ok("删除成功") : ApiResult.error("删除异常");
        } catch (Exception e) {
            return ApiResult.error("删除订单异常");
        }
    }

    /**
     * 取消订单
     *
     * @param resourceDTO 订单对象
     * @return ok
     */
    @RepeatSubmit
    @RateLimiter(key = "API_cancelOrder", time = 5, count = 50)
    @PostMapping("/cancelOrder")
    public ApiResult cancelOrder(@RequestBody @Validated({MallAppOrderOrderDTO.cancelMallAppOrderOrderDTO.class}) MallAppOrderOrderDTO resourceDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return ApiResult.allParameterErrors(bindingResult);
        }
        try {
            MallAppOrderOrder mallAppOrderOrder = new MallAppOrderOrder();
            mallAppOrderOrder.setId(resourceDTO.getId());
            mallAppOrderOrder.setCancelAt(DateUtils.getTime());
            mallAppOrderOrder.setStatus("8");

            MallAppSalesmanAchievement appSalesmanAchievement = mallAppSalesmanAchievementService.selectMallAppSalesmanAchievementByOrderId(resourceDTO.getId());
            if (appSalesmanAchievement != null) {
                appSalesmanAchievement.setStatus("2");
                mallAppSalesmanAchievementService.updateMallAppSalesmanAchievement(appSalesmanAchievement);
            }
            return mallAppOrderOrderService.updateMallAppOrderOrder(mallAppOrderOrder) > 0 ? ApiResult.ok("取消成功") : ApiResult.error("取消异常");
        } catch (Exception e) {
            return ApiResult.error("取消订单异常");
        }
    }

    /**
     * 上传支付凭证
     *
     * @param resourceDTO 订单对象
     * @return ok
     */
    @RepeatSubmit
    @RateLimiter(key = "API_uploadOrderPayProof", time = 5, count = 50)
    @PostMapping("/uploadOrderPayProof")
    public ApiResult uploadOrderPayProof(@RequestBody @Validated({MallAppOrderOrderDTO.uploadOrderPayProofDTO.class}) MallAppOrderOrderDTO resourceDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return ApiResult.allParameterErrors(bindingResult);
        }
        try {
            return mallAppOrderOrderService.uploadOrderPayProof(resourceDTO);
        } catch (Exception e) {
            return ApiResult.error("上传支付凭证异常");
        }
    }

    /**
     * 编辑订单
     *
     * @param resourceDTO 订单对象
     * @return ok
     */
    @RepeatSubmit
    @RateLimiter(key = "API_uploadOrder", time = 5, count = 50)
    @PostMapping("/uploadOrder")
    public ApiResult uploadOrder(@RequestBody @Validated({MallAppOrderOrderDTO.updateMallAppOrderOrderDTO.class}) MallAppOrderOrderDTO resourceDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return ApiResult.allParameterErrors(bindingResult);
        }
        try {
            return mallAppOrderOrderService.uploadOrder(resourceDTO);
        } catch (Exception e) {
            return ApiResult.error("编辑订单异常");
        }
    }

    /**
     * 管理员审核订单
     *
     * @param resourceDTO 订单对象
     * @return ok
     */
    @RepeatSubmit
    @RateLimiter(key = "API_adminExamineOrder", time = 5, count = 50)
    @PostMapping("/adminExamineOrder")
    public ApiResult adminExamineOrder(@RequestBody @Validated({MallAppOrderOrderDTO.adminExamineOrderDTO.class}) MallAppOrderOrderDTO resourceDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return ApiResult.allParameterErrors(bindingResult);
        }
        try {
            return mallAppOrderOrderService.adminExamineOrder(resourceDTO);
        } catch (Exception e) {
            return ApiResult.error("管理员审核订单异常");
        }
    }

    /**
     * 仓管接单
     *
     * @param resourceDTO 订单对象
     * @return ok
     */
    @RepeatSubmit
    @RateLimiter(key = "API_warehouseManageOrder", time = 2, count = 3)
    @PostMapping("/warehouseManageOrder")
    public ApiResult warehouseManageOrder(@RequestBody @Validated({MallAppOrderOrderDTO.warehouseManageOrderDTO.class}) MallAppOrderOrderDTO resourceDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return ApiResult.allParameterErrors(bindingResult);
        }
        try {
            return mallAppOrderOrderService.warehouseManageOrder(resourceDTO);
        } catch (Exception e) {
            return ApiResult.error("接单异常");
        }
    }

    /**
     * 上传装车视频
     *
     * @param resourceDTO 订单对象
     * @return ok
     */
    @RepeatSubmit
    @RateLimiter(key = "API_uploadOrderCarVideo", time = 5, count = 50)
    @PostMapping("/uploadOrderCarVideo")
    public ApiResult uploadOrderCarVideo(@RequestBody @Validated({MallAppOrderOrderDTO.uploadOrderCarVideoDTO.class}) MallAppOrderOrderDTO resourceDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return ApiResult.allParameterErrors(bindingResult);
        }
        try {
            return mallAppOrderOrderService.uploadOrderCarVideoDTO(resourceDTO);
        } catch (Exception e) {
            return ApiResult.error("上传装车视频异常");
        }
    }

    /**
     * 财务审核
     *
     * @param resourceDTO 订单对象
     * @return ok
     */
    @RepeatSubmit
    @RateLimiter(key = "API_financeExamineOrder", time = 5, count = 50)
    @PostMapping("/financeExamineOrder")
    public ApiResult financeExamineOrder(@RequestBody @Validated({MallAppOrderOrderDTO.financeExamineOrderDTO.class}) MallAppOrderOrderDTO resourceDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return ApiResult.allParameterErrors(bindingResult);
        }
        try {
            return mallAppOrderOrderService.financeExamineOrder(resourceDTO);
        } catch (Exception e) {
            return ApiResult.error("财务审核异常");
        }
    }

    /**
     * 线下商品名称列表
     *
     * @param params   sysUserId 用户ID
     * @param params   keyword 搜索关键词
     * @return ok
     */
    @GetMapping("/getAppGoodsNameList")
    public ApiResult getAppGoodsNameList(@RequestParam Map<String, Object> params) {
        if (!params.containsKey("sysUserId") || StringUtils.isBlank(params.get("sysUserId").toString())) {
            return ApiResult.error("请先登录");
        }
        try {
            List<Map<String, Object>> list = mallAppOrderGoodsService.getAppGoodsNameList(params);
            return ApiResult.ok().put("data", list);
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResult.error("线下商品名称列表异常");
        }
    }

    /**
     * 相关信息详情
     *
     * @return ok
     */
    @GetMapping("/getRelevantInfo")
    public ApiResult getRelevantInfo(@RequestParam Map<String, Object> params) {
        try {
            return ApiResult.ok().put("data", mallConfigService.selectMallConfigByIdentifying(params.get("identifying").toString()));
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResult.error("相关信息详情异常");
        }

    }

    /**
     * 修改线上订单备注
     *
     * @param resourceDTO 订单对象
     * @return ok
     */
    @RepeatSubmit
    @RateLimiter(key = "API_uploadOnlineOrderRemarks", time = 5, count = 50)
    @PostMapping("/uploadOnlineOrderRemarks")
    public ApiResult uploadOnlineOrderRemarks(@RequestBody @Validated({MallOrderOrderDTO.uploadOnlineOrderRemarks.class}) MallOrderOrderDTO resourceDTO, BindingResult bindingResult) {
        // 参数校验
        if (bindingResult.hasErrors()) {
            return ApiResult.allParameterErrors(bindingResult);
        }
        try {
            return mallOrderOrderService.uploadOnlineOrderRemarks(resourceDTO);
        } catch (Exception e) {
            return ApiResult.error("修改线上订单备注异常");
        }
    }

}
