xiaoyong931011
2021-08-02 8269efac48716a328c12a4e836a4efb4a5f277d9
gc-user/src/main/java/com/xzx/gc/user/controller/AdminDistribController.java
@@ -1,7 +1,9 @@
package com.xzx.gc.user.controller;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.xzx.gc.common.constant.CommonEnum;
import com.xzx.gc.common.constant.Constants;
import com.xzx.gc.common.dto.log.OperationAppLog;
@@ -52,6 +54,43 @@
    @Autowired
    private UserHeadRelateMapper userHeadRelateMapper;
    /**
     * 查看积分运行设置详情
     */
    @PostMapping(Constants.ADMIN_VIEW_PREFIX + "/distrib/scoreSetting.json")
    @ApiResponses({@ApiResponse( code = 200, message = "success", response = ViewScoreSettingVo.class)})
    @ApiOperation(value="运营管理-查看积分运行设置详情", notes="test: 仅0有正确返回")
    public JsonResult<ViewScoreSettingVo> viewScoreSetting(@RequestBody ViewScoreSettingDto viewScoreSettingDto) {
        ViewScoreSettingVo viewScoreSettingVo = distribService.viewScoreSetting("积分运行设置");
        return JsonResult.success(viewScoreSettingVo);
    }
    /**
     * 更新积分运行设置
     */
    @PostMapping(Constants.ADMIN_VIEW_PREFIX + "/distrib/updateScoreSetting.json")
    @ApiOperation(value="运营管理--更新积分运行设置", notes="test: 仅0有正确返回")
    public JsonResult updateScoreSetting(@RequestBody UpdateScoreSetting model, HttpServletRequest request) {
        RedPaperRule redPaperRule = redPaperRuleMapper.selectByRuleName("积分运行设置");
        if(ObjectUtil.isEmpty(redPaperRule)){
            distribService.addScoreSetting(model);
            OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))
                    .methodName(Constants.USER_MODUL_NAME).operateAction("运营管理--新增积分运行设置").build();
            mqUtil.sendApp(build);
        }else{
            Integer id = model.getId();
            if(redPaperRule.getId() != id){
                return JsonResult.failMessage("规则不存在!");
            }
            distribService.updateScoreSetting(model);
            OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))
                    .methodName(Constants.USER_MODUL_NAME).operateAction("运营管理--更新积分运行设置-" + model.getId()).build();
            mqUtil.sendApp(build);
        }
        return  JsonResult.success("操作成功!");
    }
    /**
     * 查看分銷系統设置详情
@@ -106,33 +145,46 @@
    @ApiOperation(value="分銷系統管理--新增团长", notes="test: 仅0有正确返回")
    public JsonResult adddistrib(@RequestBody AdddistribDto model, HttpServletRequest request) {
        String id = model.getId();
        AccountInfo accountInfo = accountMapper.selectByPrimaryKey(id);
        if(ObjectUtil.isEmpty(accountInfo)){
            return JsonResult.failMessage("账户不存在!");
        List<String> ids = StrUtil.split(id, ',');
//        AccountInfo accountInfo = accountMapper.selectByPrimaryKey(id);
        List<AccountInfo> accountInfos = accountMapper.selectAccountInfoByIds(ids);
        if (CollUtil.isNotEmpty(accountInfos)) {
            for (AccountInfo accountInfo : accountInfos) {
//                if(ObjectUtil.isEmpty(accountInfo)){
//                    return JsonResult.failMessage("账户不存在!");
//                }
                if(ObjectUtil.isEmpty(accountInfo.getIsHead())
                        || accountInfo.getIsHead() == 1){
                    return JsonResult.failMessage(accountInfo.getAccountName() + "账户不能重复添加!");
                }
                if(ObjectUtil.isEmpty(accountInfo.getDelFlag())
                        || accountInfo.getDelFlag() == 1){
                    return JsonResult.failMessage(accountInfo.getAccountName() + "账户已删除!");
                }
                if(ObjectUtil.isEmpty(accountInfo.getIsProhibit())
                        || "1".equals(accountInfo.getIsProhibit())){
                    return JsonResult.failMessage(accountInfo.getAccountName() + "账户已冻结!");
                }
                //团员不能当团长
                String userId = accountInfo.getUserId();
                UserHeadRelate userHeadRelate = userHeadRelateMapper.selectMemberByUserId(userId);
                if(ObjectUtil.isNotEmpty(userHeadRelate)){
                    return JsonResult.failMessage(accountInfo.getAccountName() + "账户不能申请成为团长!");
                }
//                distribService.adddistrib(accountInfo.getAccountId());
                accountInfo.setIsHead(1);
                accountMapper.updateByPrimaryKey(accountInfo);
                OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))
                        .methodName(Constants.USER_MODUL_NAME).operateAction("分銷系統管理--新增团长-"+id).build();
                mqUtil.sendApp(build);
            }
            return  JsonResult.success("操作成功!");
        } else {
            return JsonResult.failMessage("参数错误");
        }
        if(ObjectUtil.isEmpty(accountInfo.getIsHead())
                || accountInfo.getIsHead() == 1){
            return JsonResult.failMessage("账户不能重复添加!");
        }
        if(ObjectUtil.isEmpty(accountInfo.getDelFlag())
                || accountInfo.getDelFlag() == 1){
            return JsonResult.failMessage("账户已删除!");
        }
        if(ObjectUtil.isEmpty(accountInfo.getIsProhibit())
                || accountInfo.getIsProhibit() == "1"){
            return JsonResult.failMessage("账户已冻结!");
        }
        //团员不能当团长
        String userId = accountInfo.getUserId();
        UserHeadRelate userHeadRelate = userHeadRelateMapper.selectMemberByUserId(userId);
        if(ObjectUtil.isNotEmpty(userHeadRelate)){
            return JsonResult.failMessage("账户不能申请成为团长!");
        }
        distribService.adddistrib(model);
        OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))
                    .methodName(Constants.USER_MODUL_NAME).operateAction("分銷系統管理--新增团长-"+id).build();
        mqUtil.sendApp(build);
        return  JsonResult.success("操作成功!");
    }
    @ApiOperation(value = "团长列表")
@@ -214,32 +266,28 @@
        return JsonResult.success(distribService.distribDataList(distribDataListDto));
    }
    @ApiOperation(value = "团长数据--列表导出")
    @PostMapping(value = Constants.ADMIN_VIEW_PREFIX + "/distrib/export.json")
    public void fileExport(@RequestBody DistribDataListDto distribDataListDto, HttpServletRequest request, HttpServletResponse response) {
    @ApiOperation(value = "团长数据--列表导出",produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    @PostMapping(value = Constants.ADMIN_VIEW_PREFIX + "/distrib/distribDataExport.json")
    public void distribDataExport(@RequestBody ExportDistribDataListDto distribDataListDto, HttpServletRequest request, HttpServletResponse response) {
        List<List<String>> rows = new ArrayList<>();
        List<String> header=new ArrayList<>();
        //标题
        header=CollUtil.newArrayList( "团长名称", "手机号", "身份", "团员数量", "交易单数", "累计收益积分", "累计收益(元)", "累计订单重量(kg)","累计数量(家电)");
        header=CollUtil.newArrayList( "团长名称", "手机号", "身份", "团员数量", "交易单数", "累计积分收益", "累计环保币收益", "累计订单重量(kg)","累计订单数量(家电)");
        rows.add(header);
        Map<String, Object> stringObjectMap = distribService.distribDataList(distribDataListDto);
        List<Map<String,Object>>  storageModels=(List<Map<String,Object>>) stringObjectMap.get("data");
        if (CollUtil.isNotEmpty(storageModels)) {
            for(Map<String,Object> m : storageModels){
        Map<String, Object> stringObjectMap = distribService.distribDataExport(distribDataListDto);
        List<DistribDataListVo> distribDataListVos = (List<DistribDataListVo>) stringObjectMap.get("data");
        if (CollUtil.isNotEmpty(distribDataListVos)) {
            for(DistribDataListVo m : distribDataListVos){
                List<String> list = new ArrayList<>();
                if(null!=m.get("delFlag")){
                    if(m.get("delFlag").toString().equals("1")){
                        m.put("name",m.get("name").toString()+"(已删除)");
                    }
                }
                list.add(m.get("name").toString());
                list.add(m.get("storageuserphone").toString());
                list.add(m.get("storageName").toString());
                list.add(m.get("orderNum").toString());
                list.add(m.get("storageweight").toString());
                list.add(m.get("storagemoney").toString());
                list.add(m.get("recycleweight").toString());
                list.add(m.get("recyclemoney").toString());
                list.add(m.getNickname());
                list.add(m.getPhone());
                list.add("团长");
                list.add(m.getCnt().toString());
                list.add(m.getOrderCnt());
                list.add(m.getScore());
                list.add(m.getAmount());
                list.add(m.getKg());
                list.add(m.getJdsl());
                rows.add(list);
            }
        }