package com.sqx.modules.artificer.controller.app;


import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sqx.common.utils.DateUtils;
import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
import com.sqx.map.CommonMapUtils;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.app.entity.UserEntity;
import com.sqx.modules.app.service.UserMoneyDetailsService;
import com.sqx.modules.app.service.UserService;
import com.sqx.modules.artificer.dao.ArtificerDao;
import com.sqx.modules.artificer.dao.UserRechargeDao;
import com.sqx.modules.artificer.entity.*;
import com.sqx.modules.artificer.service.*;
import com.sqx.modules.bl.collect.entity.CollectMassage;
import com.sqx.modules.bl.collect.service.CollectMassageService;
import com.sqx.modules.bl.pingjiaTag.entity.BlPingjiaTag;
import com.sqx.modules.bl.pingjiaTag.service.BlPingjiaTagService;
import com.sqx.modules.common.dao.CommonInfoDao;
import com.sqx.modules.common.entity.CommonInfo;
import com.sqx.modules.common.service.CommonInfoService;
import com.sqx.modules.message.entity.MessageInfo;
import com.sqx.modules.message.service.MessageService;
import com.sqx.modules.sys.entity.SysDictEntity;
import com.sqx.modules.sys.service.SysDictService;
import com.sqx.modules.trip.entity.Trip;
import com.sqx.modules.trip.service.TripService;
import com.sqx.modules.utils.HttpClientUtil;
import com.sqx.modules.utils.LonLatUtil;
import com.sqx.modules.utils.PeriodUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GlobalCoordinates;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Slf4j
@RestController
@RequestMapping("/app/artificer")
@Api(value = "技师管理", tags = {"技师管理"})
public class AppArtificerController {

    @Autowired
    private ArtificerService artificerService;
    @Autowired
    private ArtificerMassageService artificerMassageService;
    @Autowired
    private MassageTypeService massageTypeService;
    @Autowired
    private UserService userService;
    @Autowired
    private OrdersService ordersService;
    @Autowired
    private CollectArtificerService collectArtificerService;
    @Autowired
    private AgencyService agencyService;
    @Autowired
    private MessageService messageService;
    @Autowired
    private TripService tripService;
    @Autowired
    private SysDictService sysDictService;
    @Autowired
    private CommonInfoService commonInfoService;
    @Autowired
    private CommonInfoDao commonInfoDao;
    @Autowired
    private ArtificerDao artificerDao;
    @Autowired
    private BlArtificerZqhzService blArtificerZqhzService;
    @Autowired
    private BlPingjiaTagService blPingjiaTagService;
    @Autowired
    private UserRechargeDao userRechargeDao;
    @Autowired
    private CollectMassageService collectMassageService;
    @Autowired
    private UserMoneyDetailsService userMoneyDetailsService;

    @GetMapping("/selectMassageTypePage")
    @ApiOperation("查询按摩分类（分页）")
    public Result selectMassageTypePage(Integer page,Integer limit,Integer status,Integer sort,String city,Integer authentication,Integer by,String title,Long artificerId,Long userId,Long parentId,Long classifyId){
       return massageTypeService.selectMassageTypePage(page, limit, status, city, sort,authentication,by,title,artificerId,userId,parentId,classifyId);
    }



    @GetMapping("/selectMassageTypeQyPage")
    @ApiOperation("查询按摩分类（分页）")
    public Result selectMassageTypeQyPage(Integer page,Integer limit,String city,String title){
        return massageTypeService.selectMassageTypeQyPage(page, limit,city,title);
    }

    @GetMapping("/selectMassageTypeChildrenPage")
    @ApiOperation("查询按摩分类子项目（分页）")
    public Result selectMassageTypeChildrenPage(Integer page,Integer limit,Integer status,Integer sort,String city,Integer authentication,Integer by,String title,Long artificerId,Long userId,Long parentId,Long classifyId){
        return massageTypeService.selectMassageTypeChildrenPage(page, limit, status, city, sort,authentication,by,title,artificerId,userId,parentId,classifyId);
    }
    @GetMapping("/selectMassageTypeList")
    @ApiOperation("查询按摩分类（不带分页）")
    public Result selectMassageTypeList(Integer status,Integer sort,String city,Integer authentication,Integer by,String title,Long artificerId,Long userId,Long parentId,Long classifyId){
        return massageTypeService.selectMassageTypeList(status, city, sort,authentication,by,title,artificerId,userId,parentId,classifyId);
    }

    @GetMapping("/selectMassageTypeById")
    @ApiOperation("查询详情")
    public Result selectMassageTypeById(Long massageTypeId,Long userId){
        if(userId!=null){
            //插入浏览历史
            CollectMassage collectMassage=new CollectMassage();
            collectMassage.setClassify(2);
            collectMassage.setUserId(userId);
            collectMassage.setProjectId(massageTypeId);
            collectMassage.setFlag(1);
            collectMassageService.insertCollect(collectMassage);
        }
        return massageTypeService.selectMassageTypeById(massageTypeId,userId);
    }

    @GetMapping("/selectArtificerList")
    @ApiOperation("查询技师列表")
    public Result selectArtificerList(Integer page, Integer limit, Long massageTypeId, String artificerName,
                                      String longitude,String latitude,Integer sort,Integer authentication,
                                      Integer by,String city,Long classifyId,String phone, Integer isStart,Integer technicianType,String isBack){
        return artificerService.selectArtificerList(page, limit, massageTypeId, artificerName,longitude,latitude,
                sort,authentication,by,1,city,classifyId,phone,1,isStart,technicianType,isBack);
    }


    @GetMapping("/selectArtificerMassageList")
    @ApiOperation("查询技师服务列表")
    public Result selectArtificerMassageList(Long artificerId,Integer status){
        return massageTypeService.selectArtificerMassageList(artificerId,status);
    }


    @GetMapping("/selectArtificerById")
    @ApiOperation("查询技师详情")
    public Result selectArtificerById(Long userId,Long artificerId,String longitude,String latitude){
        return Result.success().put("data",artificerService.selectArtificerById(userId,artificerId,longitude,latitude));
    }
    @GetMapping("/selectArtificerByArtificerId")
    @ApiOperation("查询技师详情by技师id")
    public Result selectArtificerByArtificerId(Long artificerId){
        return artificerService.selectArtificerByArtificerId(artificerId);
    }
    @Login
    @GetMapping("/selectArtificer")
    @ApiOperation("查询当前登陆用户技师")
    public Result selectArtificer(@RequestAttribute("userId") Long userId){
        return Result.success().put("data",artificerService.selectArtificerByUserId(userId));
    }

    @Login
    @GetMapping("/selectTaxiMoney")
    @ApiOperation("查询出行价格")
    public Result selectTaxiMoney(Long artificerId,String latitude,String longitude,String city){
        JSONObject adInfo = CommonMapUtils.getLocationToAdInfo(longitude, latitude);
        city = adInfo.getString("city");

        Trip trip = tripService.getOne(new QueryWrapper<Trip>().like("city", city));
        if(trip==null){
            return Result.error("当前地址暂无出行方式，请更换其他地址！");
        }
        return Result.success().put("data",ordersService.selectTaxiMoney(artificerId, latitude, longitude, city));
    }


    @Login
    @PostMapping("/insertOrders")
    @ApiOperation("添加订单")
    public Result insertOrders(@RequestBody Orders orders){
        return ordersService.insertOrders(orders);
    }

    @Login
    @PostMapping("/removeOrders")
    @ApiOperation("删除订单")
    public Result removeOrders(Long ordersId){
        return ordersService.removeOrders(ordersId);
    }

    @Login
    @PostMapping("/cancelOrdersMoney")
    @ApiOperation("取消订单扣钱")
    public Result cancelOrdersMoney(@RequestAttribute Long userId,Long ordersId){
        return ordersService.cancelOrdersMoney(userId,ordersId);
    }

    @Login
    @PostMapping("/deleteOrders")
    @ApiOperation("取消订单")
    public Result deleteOrders(@RequestAttribute Long userId,Long ordersId){
        return ordersService.cancelOrders(userId,ordersId);
    }

    @Login
    @PostMapping("/cancelSupplementOrders")
    @ApiOperation("变成待补单或全额退待补单")
    public Result cancelSupplementOrders(@RequestAttribute Long userId,Long ordersId,Integer isAuto,Integer type){
        return ordersService.cancelSupplementOrders(userId,ordersId,isAuto,type);
    }

//    @Login
    @GetMapping("/selectOrdersDetails")
    @ApiOperation("查询订单详情")
    public Result selectOrdersDetails(Long ordersId){
        return ordersService.selectOrdersDetails(ordersId);
    }

    @Login
    @PostMapping("/updateOrders")
    @ApiOperation("修改订单")
    public Result updateOrders(@RequestBody Orders orders){
        return ordersService.updateOrders(orders);
    }

    @Login
    @GetMapping("/selectOrdersList")
    @ApiOperation("查询订单列表")
    public Result selectOrdersList(Long userId,Integer page,Integer limit,Integer status,String city,
                                   String name,String phone,Long artificerId,Long parentId,String startTime,
                                   String endTime,Integer isAdd,String ordersNo,String artificerName,
                                   String oneUserName,String oneArtificerUserName,
                                   String startServeTime,String endServeTime,Integer overTimeOrders,Long shopId,
                                   String shopName,Integer warning,String title,String classifyId, Long userPackageId){
        return ordersService.selectOrdersList(userId, page, limit, status, city, name, phone,
                artificerId, parentId, startTime, endTime, isAdd, ordersNo, artificerName,
                oneUserName, oneArtificerUserName, startServeTime, endServeTime,overTimeOrders,shopId,shopName,warning,title,classifyId, userPackageId);
    }

    @Login
    @GetMapping("/selectAppOrdersList")
    @ApiOperation("查询订单列表")
    public Result selectAppOrdersList(@RequestAttribute("userId") Long userId,
                                      Integer page,Integer limit,
                                      Integer status,Long userPackageId){
        return ordersService.selectAppOrdersList(userId, page, limit, status, userPackageId);
    }

    @Login
    @GetMapping("/selectOrdersLists")
    @ApiOperation("查询订单列表")
    public Result selectOrdersLists(Long userId,Integer page,Integer limit,Integer status,String city,
                                   String userName,String phone,Long artificerId,Long parentId,String startTime,String endTime,
                                   Integer isAdd,String ordersNo,String artificerName,
                                   String oneUserName,String oneArtificerUserName,
                                   String startServeTime,String endServeTime,Integer overTimeOrders,Long shopId,
                                    String shopName,Integer warning,String title,String classifyId, Long userPackageId){
        return ordersService.selectOrdersList(userId, page, limit, status, city, userName, phone, artificerId,
                parentId, startTime, endTime, isAdd, ordersNo, artificerName, oneUserName, oneArtificerUserName,
                startServeTime, endServeTime,overTimeOrders,shopId,shopName,warning,title,classifyId, userPackageId);
    }

    @Login
    @PostMapping("/payOrders")
    @ApiOperation("钱包支付订单")
    public Result payOrders(Long ordersId,Integer type){
        return ordersService.payOrders(ordersId,type);
    }

    @Login
    @PostMapping("/payUserVip")
    @ApiOperation("钱包支付会员")
    public Result payUserVip(@RequestAttribute("userId") Long userId,Long vipDetailsId){
        return ordersService.payUserVip(userId,vipDetailsId);
    }

    @Login
    @ApiOperation("查看技师订单")
    @GetMapping(value = "selectArtificerOrder")
    public Result selectArtificerOrder(@RequestAttribute Long userId, Integer status, Integer page, Integer limit){
        return ordersService.selectArtificerOrder(userId, status, page, limit);
    }



    @PostMapping("/accomplishOrders")
    @ApiOperation("完成订单")
    public Result accomplishOrders(Long ordersId,String accomplishLongitude,String accomplishLatitude,String jsFwcn,String  jsPjtag,String jsTsbz,String earlyFinishReason){
        return ordersService.accomplishOrders(ordersId,2,accomplishLongitude,accomplishLatitude, jsFwcn,  jsPjtag, jsTsbz,earlyFinishReason);
    }

    @PostMapping("/startOrders")
    @ApiOperation("开始服务")
    public Result startOrders(Long ordersId,String startLongitude,String startLatitude,String startImg,String startRemark){
        return ordersService.startOrders(ordersId,startLongitude,startLatitude,startImg,startRemark);
    }

    @PostMapping("/artificerStartOrEndTime")
    @ApiOperation("技师出发或到达")
    public Result artificerStartOrEndTime(Long ordersId){
        return ordersService.artificerStartOrEndTime(ordersId);
    }


    @Login
    @PostMapping("/insertCollect")
    @ApiOperation("添加取消收藏")
    public Result insertCollect(@RequestBody CollectArtificer collectArtificer){
        collectArtificer.setClassify(1);
        return collectArtificerService.insertCollect(collectArtificer);
    }

    @Login
    @GetMapping("/selectCollectList")
    @ApiOperation("查看收藏列表")
    public Result selectCollectList(@RequestAttribute("userId") Long userId,Integer page,Integer limit,String longitude,String latitude){
        return collectArtificerService.selectCollectList(userId, page, limit,longitude,latitude);
    }

    @Login
    @ApiOperation("技师添加服务")
    @PostMapping(value = "insertArtificerMassage")
    public Result insertArtificerMassage(@RequestAttribute Long userId, String artificerMassages){
        return artificerMassageService.insertArtificerMassage(artificerMassages, userId);
    }

    @Login
    @ApiOperation("技师修改服务")
    @PostMapping(value = "updateArtificerMassage")
    public Result updateArtificerMassage(@RequestAttribute Long userId, @RequestBody ArtificerMassage artificerMassage){
        Artificer artificer = artificerService.selectArtificerByUserId(userId);
        artificerMassage.setArtificerId(artificer.getArtificerId());
        ArtificerMassage artificerMassage1 = artificerMassageService.getById(artificerMassage.getArtificerMassageId());
        if(!artificerMassage1.getStatus().equals(artificerMassage.getStatus())){
            if(artificerMassage.getStatus().equals(1)){
                MassageType massageType = massageTypeService.getById(artificerMassage1.getMassageTypeId());
                if(massageType.getStatus().equals(2)){
                    return Result.error("系统下架了此服务，暂不支持上架，如有疑问请联系客服！");
                }
            }
        }
        return artificerMassageService.updateArtificerMassage(artificerMassage);
    }

    @Login
    @ApiOperation("技师删除服务")
    @PostMapping(value = "deleteArtificerMassage")
    public Result deleteArtificerMassage(Long id){

        return artificerMassageService.deleteArtificerMassage(id);
    }

    @Login
    @ApiOperation("回显技师已添加的服务")
    @GetMapping(value = "selectArtificerMassage")
    public Result selectArtificerMassage(@RequestAttribute Long userId, Integer page, Integer limit, Integer status){
        Artificer artificer = artificerService.selectArtificerByUserId(userId);
        if(artificer == null){
            return Result.success();
        }
        return artificerMassageService.selectArtificerMassage(artificer.getArtificerId(), page, limit, status);
    }

    @Login
    @ApiOperation("查看商户主页信息")
    @GetMapping(value = "selectArtificerIndex")
    public Result selectArtificerIndex(@RequestAttribute Long userId,String startTime,String endTime){
        Artificer artificer = artificerService.selectArtificerByUserId(userId);
        if(artificer == null){
            return Result.success();
        }
        return ordersService.selectArtificerIndex(artificer.getArtificerId(),startTime,endTime);
    }

    @Login
    @ApiOperation("技师今日订单")
    @GetMapping(value = "selectTodayOrder")
    public Result selectTodayOrder(@RequestAttribute Long userId, Integer page, Integer limit,Integer type,String startTime,String endTime){
        Artificer artificer = artificerService.selectArtificerByUserId(userId);
        return ordersService.selectTodayOrder(artificer.getArtificerId(), page, limit,type,startTime,endTime);
    }

    @Login
    @PostMapping("/insertAgency")
    @ApiOperation("申请成为按摩师")
    public Result insertAgency(@RequestBody Agency agency){
        return agencyService.insertAgency(agency);
    }

    @Login
    @GetMapping("/selectAgencyById")
    @ApiOperation("查询申请记录")
    public Result selectAgencyById(@RequestAttribute Long userId){
        return Result.success().put("data",agencyService.selectAgencyByUserId(userId));
    }

    @Login
    @GetMapping("/selectArtificerMoney")
    @ApiOperation("技师收益")
    public Result selectArtificerMoney(@RequestAttribute Long userId){
        Artificer artificer = artificerService.selectArtificerByUserId(userId);
        if(artificer == null){
            return Result.success();
        }
        return artificerService.selectArtificerMoney(userId,artificer.getArtificerId());
    }

    @Login
    @PostMapping("/updateArtificer")
    @ApiOperation("技师上线下线")
    public Result updateArtificer(@RequestAttribute Long userId,String longitude,String latitude,String city){
        Artificer artificer = artificerService.selectArtificerByUserId(userId);
        UserEntity userEntity = userService.selectUserById(userId);
        String value = commonInfoService.findOne(320).getValue();
        if("是".equals(value)){
            if(userEntity.getIsCashDeposit()==null || !userEntity.getIsCashDeposit().equals(2)){
                return Result.error("当前账号未缴纳保证金，暂无法上线接单！");
            }
        }
        if(userEntity.getIsAuthentication()==null || !userEntity.getIsAuthentication().equals(2)){
            return Result.error("当前账号未实名认证，暂无法上线接单！");
        }
        artificer.setLongitude(longitude);
        artificer.setLatitude(latitude);
        artificer.setCity(city);
        if(artificer.getStatus()==1){
            artificer.setStatus(2);
//            Integer i = Integer.valueOf(commonInfoDao.findOne(100000).getValue());
//            Date upTime = artificer.getUpTime();
//            long betweenDay = DateUtil.between(upTime, new Date(), DateUnit.MINUTE);
//            int i1 = new Long(betweenDay).intValue();
//            int count = i1 / i;
//            if(count>0){
//                UserRecharge userRecharge = new UserRecharge();
//                userRecharge.setArtificerId(artificer.getArtificerId());
//                userRecharge.setUserRecharge(new BigDecimal(count));
//                userRecharge.setType("1");
//                userRecharge.setUserId(userId);
//                upTime = DateUtil.offsetMinute(upTime, i1);
//                userRecharge.setCreateTime(upTime.toString());
//                userRechargeDao.insert(userRecharge);
//            }
        }else{
            String value1 = commonInfoService.findOne(385).getValue();
            BigDecimal minScore = new BigDecimal(value1);
            if(artificer.getCreditScore().doubleValue()<minScore.doubleValue()){
                return Result.error("当前信誉分过低，请联系客服进行处理！");
            }
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String time = simpleDateFormat.format(new Date());
            MessageInfo messageInfo = messageService.selectMessageByUserIdAndTime(userId, time);
            if(messageInfo==null){
                return Result.error("您今天还没签到，请签到后进行上线！");
            }
            artificer.setUpTime(new Date());
            artificer.setStatus(1);
        }
        artificerService.updateById(artificer);
        return Result.success();
    }
    @Login
    @PostMapping("/offline")
    @ApiOperation("技师下线")
    public Result offline(@RequestAttribute Long userId){
        Artificer artificer = artificerService.selectArtificerByUserId(userId);
        artificer.setStatus(2);
//        Integer i = Integer.valueOf(commonInfoDao.findOne(100000).getValue());
//        Date upTime = artificer.getUpTime();
//        long betweenDay = DateUtil.between(upTime, new Date(), DateUnit.MINUTE);
//        int i1 = new Long(betweenDay).intValue();
//        int count = i1 / i;
//        if(count>0){
//            UserRecharge userRecharge = new UserRecharge();
//            userRecharge.setArtificerId(artificer.getArtificerId());
//            userRecharge.setUserRecharge(new BigDecimal(count));
//            userRecharge.setType("1");
//            userRecharge.setUserId(userId);
//            upTime = DateUtil.offsetMinute(upTime, i1);
//            userRecharge.setCreateTime(upTime.toString());
//            userRechargeDao.insert(userRecharge);
//        }
        artificerService.updateById(artificer);
        return Result.success();
    }
    @Login
    @PostMapping("/timing")
    @ApiOperation("10分钟定时请求接口加1积分")
    public Result timing(Long artificerId){
        artificerService.timing(artificerId);
        return Result.success();
    }

//    @Login
    @PostMapping("/integral")
    @ApiOperation("积分")
    public Result integral(String artificerId,String type,Integer current,Integer size,String date,Integer fundType){
        return Result.success(artificerService.integral(artificerId,type,current,size,date,fundType));
    }

    @PostMapping("/stored/value")
    @ApiOperation("储值积分")
    public Result storedValue(String date,String type,String artificerId){
        return Result.success(artificerService.storedValue(date,type,artificerId));
    }


    @Login
    @PostMapping("/updateArtificerTripWay")
    @ApiOperation("修改技师出行方式")
    public Result updateArtificerTripWay(@RequestAttribute Long userId,Integer tripWay,Integer tripWayNum){
        Artificer artificer = artificerService.selectArtificerByUserId(userId);
        artificer.setTripWay(tripWay);
        artificer.setTripWayNum(tripWayNum);
        artificerService.updateById(artificer);
        return Result.success();
    }

    @Login
    @PostMapping("/signIn")
    @ApiOperation("签到")
    public Result signIn(@RequestAttribute Long userId,String longitude,String latitude,String city,String address){
        return artificerService.signIn(userId,longitude,latitude,city,address);
    }


    @GetMapping("/selectTeamOrdersList")
    @ApiOperation("获取团队订单")
    public Result selectTeamOrdersList(Long userId, Integer page, Integer limit, Integer type, Integer status){
        return ordersService.selectTeamOrdersList(page,limit,userId,type,status);
    }


    @GetMapping("/selectTeamUserList")
    @ApiOperation("获取团队列表")
    public Result selectTeamUserList(Long userId, Integer page, Integer limit, Integer type){
        UserEntity user = userService.selectUserById(userId);
        return ordersService.selectTeamUserList(page,limit,user.getInvitationCode(),type,userId);
    }

    @GetMapping("/selectTeamStatistics")
    @ApiOperation("团队统计")
    public Result selectTeamStatistics(Long userId,Integer type){
        UserEntity user = userService.selectUserById(userId);
        Double teamMoney = ordersService.selectOrdersMoneyCountByUserId(user.getUserId(), type,null);
        Integer teamCount = ordersService.selectUserCountByInvitationCode(user.getInvitationCode(), type);
        Map<String,Object> result=new HashMap<>();
        result.put("teamMoney",teamMoney);
        result.put("teamCount",teamCount);
        return Result.success().put("data",result);
    }


    /**
     * 查询附近技师列表
     * @param page 第几页
     * @param limit 每页几条
     * @param longitude 精度
     * @param latitude 维度
     * @param city 城市
     * @return
     */
    @GetMapping("/getHomeArtificerList")
    @ApiOperation("首页技师-明星和附近技师")
    public Result getHomeArtificerList(Integer page, Integer limit, Integer isStart,Integer status, String city, String longitude, String latitude){
        return artificerService.getHomeArtificerList(page,limit,isStart,status,city,longitude,latitude);
    }


    /**
     * 技师首页获取当期订单，加钟订单，充值订单
     * @param userId 技师id
     * @param page 第几页
     * @param limit 每页几条
     * @param orderType 类型 1当期 2加钟 3充值
     * @param isSfwc 0不包含 1包含  空为全部
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return
     */
    @ApiOperation("技师首页获取当期订单，加钟订单，充值订单")
    @GetMapping("/getOrderTypeList")
    public Result getOrderTypeList(Long userId,Integer page, Integer limit,Integer orderType,Integer isSfwc,String startTime,String endTime){
        if(page == null){
            page = 0;
        }
        if(limit == null){
            limit = 10;
        }
        if(StringUtils.isNotEmpty(endTime)){
            endTime = endTime+" 23:59:59";
        }else{
            return Result.error("结束时间不能为空");
        }
        if(userId == null){
            return Result.error("您未登录，请登录后进行查询");
        }
        if(orderType == null){
            return Result.error("查询类型为空");
        }

        return artificerService.getOrderTypeList(userId,page,limit,orderType,isSfwc,startTime,endTime);
    }

    /**
     * 技师确认接单
     * @param ordersId 订单id
     * @return
     */
    @ApiOperation("技师确认接单")
    @GetMapping("/jishiQueren")
    public Result jishiQueren(Long ordersId){
        Result result = ordersService.jishiQueren(ordersId);
        return result;
    }


    /**
     * 拒单申请
     * @param ordersId 订单id
     * @param refusalContent 拒单内容
     * @return
     */
    @ApiOperation("技师拒单申请")
    @GetMapping("/jishiJdsq")
    public Result jishiJdsq(Long ordersId,String refusalContent){
        Orders orders = new Orders();
        orders.setOrdersId(ordersId);
        orders.setRefusalContent(refusalContent);
        orders.setStatus(9);//拒单申请
        ordersService.updateById(orders);
        return Result.success("拒单申请已提交，请等待客户审核！");
    }

    @ApiOperation("技师获取评价标签")
    @GetMapping("/getPingjiaTagList")
    public Result getPingjiaTagList(){
        List<BlPingjiaTag> list = blPingjiaTagService.list();
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("data",list);
        return Result.success(map);
    }


    @ApiOperation("技师获取往期列表")
    @GetMapping("/getZqhzList")
    public Result getZqhzList(Long userId){
        QueryWrapper<BlArtificerZqhz> blArtificerZqhzQueryWrapper = new QueryWrapper<>();
        blArtificerZqhzQueryWrapper.eq("artificer_id", userId);
        List<BlArtificerZqhz> list = blArtificerZqhzService.list(blArtificerZqhzQueryWrapper);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<Map<String,String>> listMap = new ArrayList<>();
        for(BlArtificerZqhz par:list){
            Map<String,String> map = new HashMap<>();
            map.put("text",sdf.format(par.getStartTime())+" 至 "+sdf.format(par.getEndTime()));
            map.put("label",sdf.format(par.getStartTime())+" 至 "+sdf.format(par.getEndTime()));
            listMap.add(map);
        }
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("data",listMap);
        return Result.success(map);
    }


    @ApiOperation("技师获取积分列表")
    @GetMapping("/getJifenList")
    public Result getJifenList(Long userId,String startTime,String endTime){
        return Result.success(artificerService.getJifenList(userId,startTime,endTime));
    }


    @Login
    @ApiOperation("技师获取钱包明细列表")
    @GetMapping(value = "selectArtificerQianbao")
    public Result selectArtificerQianbao(@RequestAttribute Long userId,String fundData,Integer fundType,Integer page, Integer limit) throws ParseException {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        Period period = new Period();
        period.setFundData(sdf.parse(fundData));
        period.setFundType(fundType);
        period = PeriodUtil.calculationPeriod(period);
        String startTime = sdf.format(period.getStartFundData());
        String endTime = sdf.format(period.getEndFundData());
        Artificer artificer = artificerService.selectArtificerByUserId(userId);
        return userMoneyDetailsService.selectArtificerQianbao(artificer.getArtificerId(),startTime,endTime,page, limit);
    }


    @Login
    @ApiOperation("修改技师生活照")
    @PostMapping("/updateShz")
    public Result updateShz(@RequestAttribute Long userId,@RequestBody Artificer artificer){
        artificer.setUserId(userId);
        return artificerService.updateShz(artificer);
    }
}
