xiaoyong931011
2022-09-22 d040c0f42d6799e2a89ea2dcbd5e3b0f97bffc2a
src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallTeamLeaderServiceImpl.java
@@ -4,34 +4,50 @@
import cc.mrbird.febs.common.entity.QueryRequest;
import cc.mrbird.febs.common.enumerates.FlowTypeEnum;
import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum;
import cc.mrbird.febs.common.properties.XcxProperties;
import cc.mrbird.febs.common.utils.HttpCurlUtil;
import cc.mrbird.febs.common.utils.SpringContextHolder;
import cc.mrbird.febs.mall.conversion.MallElectronicFenceConversion;
import cc.mrbird.febs.mall.conversion.MallTeamLeaderConversion;
import cc.mrbird.febs.mall.dto.AdminLeaderAddDto;
import cc.mrbird.febs.mall.dto.AdminLeaderAddFenceDto;
import cc.mrbird.febs.mall.dto.AdminLeaderUpdateDto;
import cc.mrbird.febs.mall.dto.ApiApplayLeaderDto;
import cc.mrbird.febs.mall.entity.MallGoodsCategory;
import cc.mrbird.febs.mall.entity.MallLeaderStock;
import cc.mrbird.febs.mall.entity.MallMember;
import cc.mrbird.febs.mall.entity.MallTeamLeader;
import cc.mrbird.febs.mall.entity.*;
import cc.mrbird.febs.mall.mapper.*;
import cc.mrbird.febs.mall.service.IAdminMallTeamLeaderService;
import cc.mrbird.febs.mall.service.IMallElectronicFenceService;
import cc.mrbird.febs.mall.vo.AdminMallActSetVo;
import cc.mrbird.febs.mall.vo.AdminMallTeamLeaderVo;
import cc.mrbird.febs.mall.vo.AdminSelectListLeaderVo;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.Consts;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.HttpClientUtils;
import org.apache.http.entity.ContentType;
import org.apache.http.message.BasicNameValuePair;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
@Slf4j
@Service
@@ -43,6 +59,10 @@
    private final MallGoodsMapper mallGoodsMapper;
    private final MallMemberMapper mallMemberMapper;
    private final MallMoneyFlowMapper mallMoneyFlowMapper;
    private final MallElectronicFenceMapper mallElectronicFenceMapper;
    private final IMallElectronicFenceService iMallElectronicFenceService;
    private final SpringContextHolder springContextHolder;
    private final XcxProperties xcxProperties = SpringContextHolder.getBean(XcxProperties.class);
    @Override
    public IPage<AdminMallTeamLeaderVo> getLeaderListInPage(MallTeamLeader mallTeamLeader, QueryRequest request) {
@@ -67,6 +87,10 @@
    public AdminMallTeamLeaderVo getMallTeamLederInfoById(long id) {
        MallTeamLeader mallTeamLeader = this.baseMapper.selectById(id);
        AdminMallTeamLeaderVo adminMallTeamLeaderVo = MallTeamLeaderConversion.INSTANCE.entityToVo(mallTeamLeader);
        MallElectronicFence mallElectronicFence = mallElectronicFenceMapper.selectByTeamLeaderCode(mallTeamLeader.getUniqueCode());
        if(ObjectUtil.isNotEmpty(mallElectronicFence)){
            adminMallTeamLeaderVo.setLonglatiarr(mallElectronicFence.getLonglatiarr());
        }
        return adminMallTeamLeaderVo;
    }
@@ -74,6 +98,9 @@
    public FebsResponse leaderUpdate(MallTeamLeader mallTeamLeader) {
        Long id = mallTeamLeader.getId();
        MallTeamLeader mallTeamLeaders = this.baseMapper.selectById(id);
        if(1 == mallTeamLeaders.getOnlineState()){
            return new FebsResponse().fail().message("请先让团长离线");
        }
        if(ObjectUtil.isEmpty(mallTeamLeaders)){
            return new FebsResponse().fail().message("团长信息不存在,刷新重试");
        }
@@ -82,10 +109,10 @@
//            return new FebsResponse().fail().message("只有【待审核】状态才能提交!");
//        }
        Double bonusPercent = Double.parseDouble(mallTeamLeader.getBonusPercent());
        if(1 <= bonusPercent || 0 > bonusPercent){
            return new FebsResponse().fail().message("请输入合适的百分比小数");
        }
//        Double bonusPercent = Double.parseDouble(mallTeamLeader.getBonusPercent());
//        if(1 <= bonusPercent || 0 > bonusPercent){
//            return new FebsResponse().fail().message("请输入合适的百分比小数");
//        }
        int isOk = mallTeamLeader.getIsOk();
        if(MallTeamLeader.STATE_YES == isOk){
            mallTeamLeader.setState(MallTeamLeader.STATE_YES);
@@ -103,7 +130,7 @@
    @Override
    public List<AdminSelectListLeaderVo> selectList(MallTeamLeader mallTeamLeader) {
        List<AdminSelectListLeaderVo> list = new ArrayList<>();
        List<MallTeamLeader> mallTeamLeaders = this.baseMapper.getMallTeamLeaderList();
        List<MallTeamLeader> mallTeamLeaders = this.baseMapper.getAllMallTeamLeaderList();
        if(CollUtil.isNotEmpty(mallTeamLeaders)){
            for(MallTeamLeader teamLeader : mallTeamLeaders){
                AdminSelectListLeaderVo adminSelectListLeaderVo = new AdminSelectListLeaderVo();
@@ -118,6 +145,9 @@
    @Override
    public FebsResponse leaderCancel(Long id) {
        MallTeamLeader mallTeamLeader = this.baseMapper.selectById(id);
        if(1 == mallTeamLeader.getOnlineState()){
            return new FebsResponse().fail().message("请先让团长离线");
        }
        if(ObjectUtil.isEmpty(mallTeamLeader)){
            return new FebsResponse().fail().message("团长信息不存在");
        }
@@ -155,10 +185,10 @@
        if(CollUtil.isNotEmpty(mallTeamLeaderCancel)){
            return new FebsResponse().fail().message("当前用户无法申请");
        }
        Double bonusPercent = Double.parseDouble(adminLeaderAddDto.getBonusPercent());
        if(1 <= bonusPercent || 0 > bonusPercent){
            return new FebsResponse().fail().message("请输入合适的百分比小数");
        }
//        Double bonusPercent = Double.parseDouble(adminLeaderAddDto.getBonusPercent());
//        if(1 <= bonusPercent || 0 > bonusPercent){
//            return new FebsResponse().fail().message("请输入合适的百分比小数");
//        }
        MallTeamLeader mallTeamLeader = MallTeamLeaderConversion.INSTANCE.adminDtoToEntity(adminLeaderAddDto);
        mallTeamLeader.setUniqueCode(mallMember.getInviteId());
        mallTeamLeader.setMemberId(memberId);
@@ -198,4 +228,136 @@
        this.baseMapper.updateById(mallTeamLeader);
        return new FebsResponse().success();
    }
    public static void main(String[] args) {
        String ss = "{\"results\":[{\"name\":\"yiyuanshucai\",\"sid\":792477},{\"name\":\"yiyuanshucai1\",\"sid\":792477}]}";
        String serviceName = "";
        JSONObject jsonObject = JSONUtil.parseObj(ss);
        String results = jsonObject.get("results").toString();
        JSONArray jsonArray = JSONUtil.parseArray(results);
        System.out.print(jsonArray);
        for(Object jsonArray1 : jsonArray){
            System.out.print(jsonArray1);
            JSONObject jsonObject1 = JSONUtil.parseObj(jsonArray1);
            String name = jsonObject1.get("name").toString();
            System.out.print(name);
            if("yiyuanshucai".equals(name)){
                serviceName= name;
                break;
            }
        }
//            String name = jsonObjectStr.get("name").toString();
//            String sid = jsonObjectStr.get("sid").toString();
//            if("yiyuanshucai".equals(name)){
//                System.out.print(name);
//                System.out.print(sid);
//            }
    }
    @Override
    @Transactional
    public FebsResponse addFence(AdminLeaderAddFenceDto adminLeaderAddFenceDto) {
        Long id = adminLeaderAddFenceDto.getId();
        MallTeamLeader mallTeamLeader = this.baseMapper.selectById(id);
        if(1 == mallTeamLeader.getOnlineState()){
            return new FebsResponse().fail().message("请先让团长离线");
        }
        //如果电子围栏表为空,
        //先查询服务是否已经创建,
        //没有,再创建服务。
        List<MallElectronicFence> mallElectronicFences = mallElectronicFenceMapper.selectList(new QueryWrapper<>());
        String serviceId = "";
        if(CollUtil.isEmpty(mallElectronicFences)){
            String resultStr = iMallElectronicFenceService.trackServiceInfo(xcxProperties.getGaodeKey());
            if("fail".equals(resultStr)){
                return new FebsResponse().fail().message("高德地图查询服务失败");
            }
            log.info(resultStr);
            if("null".equals(resultStr) || StrUtil.isBlank(resultStr)){
                serviceId = iMallElectronicFenceService.trackServiceAdd(xcxProperties.getGaodeKey(), xcxProperties.getServiceName());
            }else{
                JSONObject jsonObject = JSONUtil.parseObj(resultStr);
                String results = jsonObject.get("results").toString();
                JSONArray jsonArray = JSONUtil.parseArray(results);
                for(Object jsonArray1 : jsonArray){
                    JSONObject jsonObject1 = JSONUtil.parseObj(jsonArray1);
                    String name = jsonObject1.get("name").toString();
                    String sid = jsonObject1.get("sid").toString();
                    if(xcxProperties.getServiceName().equals(name)){
                        serviceId= sid;
                        break;
                    }
                }
            }
        }else{
            serviceId = mallElectronicFences.get(0).getServiceId();
        }
        if("fail".equals(serviceId)){
            return new FebsResponse().fail().message("高德地图创建服务失败");
        }
        String uniqueCode = mallTeamLeader.getUniqueCode();
        MallElectronicFence mallElectronicFence = mallElectronicFenceMapper.selectByTeamLeaderCode(uniqueCode);
        if(ObjectUtil.isEmpty(mallElectronicFence)){
            //新增
            //新增围栏
            String fenceId = iMallElectronicFenceService.fenceAdd(xcxProperties.getGaodeKey(), serviceId
                    , mallTeamLeader.getUniqueCode()+"_fence", adminLeaderAddFenceDto.getLonglatiarr());
            if("fail".equals(fenceId)){
                return new FebsResponse().fail().message("高德地图创建多边形围栏失败");
            }
            MallElectronicFence mallElectronicFenceAdd = new MallElectronicFence();
            mallElectronicFenceAdd.setFenceName(mallTeamLeader.getUniqueCode()+"_fence");
            mallElectronicFenceAdd.setFenceType(4);
            mallElectronicFenceAdd.setGid(fenceId);
            mallElectronicFenceAdd.setProhibit(1);
            mallElectronicFenceAdd.setDelFlag(1);
            mallElectronicFenceAdd.setGKey(xcxProperties.getGaodeKey());
            mallElectronicFenceAdd.setLonglatiarr(adminLeaderAddFenceDto.getLonglatiarr());
            mallElectronicFenceAdd.setTeamLeaderCode(uniqueCode);
            mallElectronicFenceAdd.setServiceId(serviceId);
            mallElectronicFenceMapper.insert(mallElectronicFenceAdd);
        }else{
            String fenceUpdate = iMallElectronicFenceService.fenceUpdate(xcxProperties.getGaodeKey(), serviceId,
                    mallElectronicFence.getGid(), mallElectronicFence.getFenceName(),
                    adminLeaderAddFenceDto.getLonglatiarr());
            if("fail".equals(fenceUpdate)){
                return new FebsResponse().fail().message("高德地图更新多边形围栏失败");
            }
            mallElectronicFence.setLonglatiarr(adminLeaderAddFenceDto.getLonglatiarr());
            mallElectronicFenceMapper.updateById(mallElectronicFence);
        }
        return new FebsResponse().success();
    }
    @Override
    public FebsResponse startOnline(Long id) {
        MallTeamLeader mallTeamLeader = this.baseMapper.selectById(id);
        if(ObjectUtil.isEmpty(mallTeamLeader)){
            return new FebsResponse().fail().message("团长信息不存在,刷新重试");
        }
        Integer state = mallTeamLeader.getState();
        if(1!=state){
            return new FebsResponse().fail().message("目前还不是团长,无法操作");
        }
//        MallElectronicFence mallElectronicFence = mallElectronicFenceMapper.selectByTeamLeaderCode(mallTeamLeader.getUniqueCode());
//        if(ObjectUtil.isEmpty(mallElectronicFence)){
//            return new FebsResponse().fail().message("请先设置配送范围");
//        }
        mallTeamLeader.setOnlineState(1);
        this.baseMapper.updateById(mallTeamLeader);
        return new FebsResponse().success();
    }
    @Override
    public FebsResponse closeOnline(Long id) {
        MallTeamLeader mallTeamLeader = this.baseMapper.selectById(id);
        if(ObjectUtil.isEmpty(mallTeamLeader)){
            return new FebsResponse().fail().message("团长信息不存在,刷新重试");
        }
        mallTeamLeader.setOnlineState(2);
        this.baseMapper.updateById(mallTeamLeader);
        return new FebsResponse().success();
    }
}