| package com.xzx.gc.user.controller;  | 
|   | 
| import cn.hutool.core.bean.BeanUtil;  | 
| import cn.hutool.core.collection.CollUtil;  | 
| import cn.hutool.core.convert.Convert;  | 
| import cn.hutool.core.util.NumberUtil;  | 
| import com.xzx.gc.common.Result;  | 
| import com.xzx.gc.common.constant.CommonEnum;  | 
| import com.xzx.gc.common.constant.Constants;  | 
| import com.xzx.gc.common.dto.log.OperationAppLog;  | 
| import com.xzx.gc.common.request.BaseController;  | 
| import com.xzx.gc.common.utils.BusinessUtil;  | 
| import com.xzx.gc.common.utils.IdUtils;  | 
| import com.xzx.gc.entity.*;  | 
| import com.xzx.gc.model.JsonResult;  | 
| import com.xzx.gc.model.admin.ExportParamModel;  | 
| import com.xzx.gc.model.admin.StorageModel;  | 
| import com.xzx.gc.model.admin.UserModel;  | 
| import com.xzx.gc.model.admin.XzxCityPartnerModel;  | 
| import com.xzx.gc.model.order.PackageSiteLimitDto;  | 
| import com.xzx.gc.user.service.*;  | 
| import com.xzx.gc.util.PreventManyCommit;  | 
| import com.xzx.gc.util.SessionUtil;  | 
| import io.swagger.annotations.Api;  | 
| import io.swagger.annotations.ApiImplicitParam;  | 
| import io.swagger.annotations.ApiImplicitParams;  | 
| import io.swagger.annotations.ApiOperation;  | 
| import org.springframework.beans.factory.annotation.Autowired;  | 
| import org.springframework.http.MediaType;  | 
| import org.springframework.validation.annotation.Validated;  | 
| import org.springframework.web.bind.annotation.PostMapping;  | 
| import org.springframework.web.bind.annotation.RequestBody;  | 
| import org.springframework.web.bind.annotation.ResponseBody;  | 
| import org.springframework.web.bind.annotation.RestController;  | 
|   | 
| import javax.servlet.http.HttpServletRequest;  | 
| import javax.servlet.http.HttpServletResponse;  | 
| import java.util.ArrayList;  | 
| import java.util.HashMap;  | 
| import java.util.List;  | 
| import java.util.Map;  | 
|   | 
| @RestController  | 
| @Api(tags = {"合伙人管理"})  | 
| public class CityPartnerController extends BaseController {  | 
|   | 
|   | 
|     @Autowired  | 
|     private IdUtils idUtils;  | 
|   | 
|     @Autowired  | 
|     private CityPartnerService cityPartnerService;  | 
|       | 
|     @Autowired  | 
|     private SessionUtil sessionUtil;  | 
|   | 
|     @Autowired  | 
|     private PackageSiteService packageSiteService;  | 
|   | 
|     @Autowired  | 
|     private BusinessUtil businessUtil;  | 
|   | 
|     @Autowired  | 
|     private OtherUserService otherUserService;  | 
|   | 
|     @Autowired  | 
|     private AccountService accountService;  | 
|   | 
|     @Autowired  | 
|     private PartnerAccountService partnerAccountService;  | 
|   | 
|     @Autowired  | 
|     private UserService userService;  | 
|   | 
|     @PostMapping( "/admin/front/cityPartner/getCityPartnerName.json")  | 
|     @ApiOperation(value="生成合伙人账号", notes="test: 仅0有正确返回")  | 
|     public JsonResult<String> getCityPartnerName(HttpServletRequest request){  | 
|         String id=idUtils.generate("ZH",4);  | 
|         return JsonResult.success(id);  | 
|     }  | 
|   | 
|     @PostMapping( "/admin/front/cityPartner/addCityPartner.json")  | 
|     @ApiOperation(value="添加合伙人", notes="test: 仅0有正确返回")  | 
|     public JsonResult<String> addCityPartner(@RequestBody XzxCityPartnerModel model, HttpServletRequest request){  | 
|         JsonResult<String> stringJsonResult = cityPartnerService.addPartner(model);  | 
|         if(stringJsonResult.getCode()==0){  | 
|             OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))  | 
|                     .methodName(Constants.USER_MODUL_NAME).operateAction("添加合伙人-"+stringJsonResult.getData()).build();  | 
|             mqUtil.sendApp(build);  | 
|         }  | 
|         return  stringJsonResult;  | 
|     }  | 
|   | 
|     @PostMapping("/admin/front/cityPartner/queryCityPartner.do")  | 
|     @ApiOperation(value="查询合伙人列表(打包站列表 参数看partnerType)", notes="test: 仅0有正确返回")  | 
|     @ApiImplicitParams({  | 
|             @ApiImplicitParam(paramType="query", name = "page", value = "页码", required = true, dataType = "int"),  | 
|             @ApiImplicitParam(paramType="query", name = "limit", value = "每页条数", required = true, dataType = "int"),  | 
|             @ApiImplicitParam(paramType="query", name = "startTime", value = "开始时间", required = true, dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "endTime", value = "结束时间", required = true, dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "name", value = "姓名、手机号", required = true, dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "prohibit", value = "是否禁用(1:禁用,0:启用)", required = true, dataType = "Integer"),  | 
|             @ApiImplicitParam(paramType="query", name = "partnerType", value = "合伙类型(1:合伙人。2:打包站)", required = true, dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "packingStation", value = "打包站名称", required = true, dataType = "String")  | 
|   | 
|     })  | 
|     public JsonResult<Map<String, Object>> queryCityPartner(@RequestBody XzxCityPartnerModel model){  | 
|         Map<String, Object> map =  cityPartnerService.queryCityPartner(model);  | 
|         return JsonResult.success(map);  | 
|     }  | 
|     @PostMapping("/admin/front/cityPartner/queryPartnerAccount.json")  | 
|     @ApiOperation(value="查询合伙人账户余额", notes="test: 仅0有正确返回")  | 
|     @ApiImplicitParams({  | 
|             @ApiImplicitParam(paramType="query", name = "id", value = "合伙人ID(如果不传,需要合伙人登陆)", required = true, dataType = "String"),  | 
|     })  | 
|     public JsonResult<Map<String,Object>> queryPartnerAccount(@RequestBody XzxCityPartnerModel model){  | 
|         Map<String,Object> map = new HashMap<>();  | 
|   | 
|         if(null!=model){  | 
|             if(null!=model.getId()&&!"".equals(model.getId())){  | 
|                 map=cityPartnerService.queryPartnerAccount(model.getId());  | 
|             }else{  | 
|                 CoreUser user = sessionUtil.getCurrentUser();  | 
|                 if(user.getId()==1){  | 
|                     return JsonResult.success(map);  | 
|                 }else{  | 
|                     CoreUser user1 = cityPartnerService.queryPartnerAdmin(user.getId());  | 
|                     if(user1!=null){  | 
|                         return JsonResult.success(map);  | 
|                     }  | 
|                 }  | 
|                 CityPartner partner = cityPartnerService.queryById(user.getId());  | 
|                 if(null!=partner){  | 
|                     map=cityPartnerService.queryPartnerAccount(partner.getUserId());  | 
|                 }else{  | 
|                     return JsonResult.success(map);  | 
|                 }  | 
|   | 
|             }  | 
|         }else{  | 
|             CoreUser user = sessionUtil.getCurrentUser();  | 
|             if(user.getId()==1){  | 
|                 return JsonResult.success(map);  | 
|             }else{  | 
|                 user = cityPartnerService.queryPartnerAdmin(user.getId());  | 
|                 if(user!=null){  | 
|                     return JsonResult.success(map);  | 
|                 }  | 
|             }  | 
|             map=cityPartnerService.queryPartnerAccount(user.getId().toString());  | 
|         }  | 
|         return JsonResult.success(map);  | 
|     }  | 
|   | 
|   | 
|     @PostMapping("/admin/front/cityPartner/updateCityPartner.json")  | 
|     @ApiOperation(value="修改合伙人", notes="test: 仅0有正确返回")  | 
|     public JsonResult<String> updateCityPartner(@RequestBody XzxCityPartnerModel model,HttpServletRequest request){  | 
|         JsonResult<String> stringJsonResult = cityPartnerService.updatePartner(model);  | 
|         if(stringJsonResult.getCode()==0){  | 
|             OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))  | 
|                     .methodName(Constants.USER_MODUL_NAME).operateAction("修改合伙人-"+model.getId()).build();  | 
|             mqUtil.sendApp(build);  | 
|         }  | 
|         return stringJsonResult;  | 
|     }  | 
|   | 
|     @PostMapping("/admin/front/cityPartner/queryAllPartnerList.do")  | 
|     @ApiOperation(value="查询合伙人和打包站列表", notes="test: 仅0有正确返回")  | 
|     public JsonResult<List<CityPartner>> queryAllPartnerList(){  | 
|         CoreUser user = sessionUtil.getCurrentUser();  | 
|         List<CityPartner> cityPartners = new ArrayList<>();  | 
|         if(user.getId()==1){  | 
|             cityPartners = cityPartnerService.queryAllCityPartnerList(null);  | 
|         }else{  | 
|             CoreUser user1 = cityPartnerService.queryPartnerAdmin(user.getId());  | 
|             //CityPartner partner = new CityPartner();  | 
|             if(user1!=null){  | 
|   | 
|                 cityPartners = cityPartnerService.queryAllCityPartnerList(null);  | 
|             }else{  | 
|                 //partner.setId(Integer.parseInt(user.getId()+""));  | 
|                 cityPartners = cityPartnerService.queryAllCityPartnerList(user.getId()+"");  | 
|                 /*CityPartner partner = cityPartnerService.queryById(user.getId());  | 
|                 cityPartners.add(partner);*/  | 
|             }  | 
|         }  | 
|         return JsonResult.success(cityPartners);  | 
|     }  | 
|   | 
|     @PostMapping( "/admin/front/cityPartner/updatePartnerProhibit.json")  | 
|     @ApiOperation(value="后台合伙人是否启用接口", notes="test: 仅0有正确返回")  | 
|     @ApiImplicitParams({  | 
|             @ApiImplicitParam(paramType="query", name ="id", value = "合伙人Id", required = true, dataType = "String"),  | 
|             @ApiImplicitParam(paramType="query", name = "prohibit", value = "是否启用", required = true, dataType = "String")  | 
|     })  | 
|     public JsonResult<String> updatePartnerProhibit(@RequestBody XzxCityPartnerModel model,HttpServletRequest request){  | 
|         JsonResult jsonResult = cityPartnerService.updatePartnerProhibit(model);  | 
|         if(jsonResult.getCode()==0){  | 
|             OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))  | 
|                     .methodName(Constants.USER_MODUL_NAME).operateAction("后台合伙人是否启用接口-"+model.getId()).build();  | 
|             mqUtil.sendApp(build);  | 
|         }  | 
|         return jsonResult;  | 
|     }  | 
|   | 
|   | 
|     @PostMapping( "/admin/front/cityPartner/queryPartnerName.json")  | 
|     @ApiOperation(value="查询合伙人姓名", notes="test: 仅0有正确返回")  | 
|     public JsonResult<Map<String,Object>> queryPartnerName(){  | 
|         List<String> partnerIds = cityPartnerService.queryPartnerByCurrent();  | 
|         List<CityPartner> list = cityPartnerService.queryPartnerName(partnerIds);  | 
|         Map<String,Object> map = new HashMap<>();  | 
|         map.put("data",list);  | 
|         map.put("code",0);  | 
|         return JsonResult.success(map);  | 
|     }  | 
|   | 
|   | 
|     @PostMapping( "/admin/front/cityPartner/queryPackageByPartner.json")  | 
|     @ApiOperation(value="查询打包站", notes="test: 仅0有正确返回")  | 
|     public JsonResult<Map<String,Object>> queryPackageByPartner(@RequestBody UserModel model){  | 
|         List<String> partnerIds = new ArrayList<>();  | 
|         if(null!=model.getPartnerId()&&!"".equals(model.getPartnerId())){  | 
|             partnerIds.add(model.getPartnerId());  | 
|         }else{  | 
|             partnerIds = cityPartnerService.queryPartnerByCurrent();  | 
|         }  | 
|         List<CityPartner> list = cityPartnerService.queryPackageByPartner(partnerIds);  | 
|         Map<String,Object> map = new HashMap<>();  | 
|         map.put("data",list);  | 
|         map.put("code",0);  | 
|         return JsonResult.success(map);  | 
|     }  | 
|   | 
|     /**  | 
|      * 删除  | 
|      * @param model  | 
|      * @return  | 
|      */  | 
|     @PostMapping("/admin/front/cityPartner/delPartner.json")  | 
|     @PreventManyCommit(time = 10)  | 
|     @ApiOperation(value="电子围栏管理-删除合伙人", notes="test: 仅0有正确返回")  | 
|     @ApiImplicitParams({  | 
|             @ApiImplicitParam(paramType="query", name = "id", value = "合伙人Id",  dataType = "Integer")  | 
|     })  | 
|     public JsonResult<String> delPartner(@RequestBody XzxCityPartnerModel model,HttpServletRequest request){  | 
|   | 
|         JsonResult<String> stringJsonResult = cityPartnerService.deletePartner(model);  | 
|         if(stringJsonResult.getCode()==0) {  | 
|             OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))  | 
|                     .methodName(Constants.ORDER_MODUL_NAME).operateAction("删除合伙人-" + model.getId()).build();  | 
|             mqUtil.sendApp(build);  | 
|   | 
|         }  | 
|         return stringJsonResult;  | 
|   | 
|     }  | 
|   | 
|     @PostMapping("/packageSite/limit")  | 
|     @ApiOperation(value = "额度管理显示")  | 
|     public Result<PackageSiteLimitDto> limit(HttpServletRequest request){  | 
|         String userId=getUserId(request);  | 
|   | 
|         PackageSiteLimitDto packageSiteLimitDto=new PackageSiteLimitDto();  | 
|         List<AccountInfo> list=new ArrayList<>();  | 
|         OtherUserInfo byId = otherUserService.findById(userId);  | 
|   | 
|         AccountInfo byUserId = accountService.findByUserId(userId);  | 
|         byUserId.setName(byId.getName());  | 
|   | 
|         if(byUserId==null){  | 
|             return Result.error(-1,"账户被禁用");  | 
|         }  | 
|         list.add(byUserId);  | 
|   | 
|         //打包站id  | 
|         String partnerId = byId.getPartnerId();  | 
|   | 
|   | 
|         PartnerAccount byPartnerId = partnerAccountService.findByPartnerId(partnerId);  | 
|   | 
|         packageSiteLimitDto.setHbb(businessUtil.changeMoney(byPartnerId.getHbb()));  | 
|         packageSiteLimitDto.setOverdraftLimit(businessUtil.changeMoney(byPartnerId.getOverdraftLimit()));  | 
|         packageSiteLimitDto.setAll(businessUtil.changeMoney(NumberUtil.add(packageSiteLimitDto.getHbb(),packageSiteLimitDto.getOverdraftLimit())));  | 
|         packageSiteLimitDto.setPartnerAccountId(byPartnerId.getAccount());  | 
|   | 
|         List<OtherUserInfo> byUserTypeAndPartner = otherUserService.findByUserTypeAndPartner(CommonEnum.打包员.getValue(), partnerId);  | 
|   | 
|         if(CollUtil.isNotEmpty(byUserTypeAndPartner)){  | 
|             for (OtherUserInfo otherUserInfo : byUserTypeAndPartner) {  | 
|                 AccountInfo byUserId1 = accountService.findByUserId(otherUserInfo.getUserId());  | 
|                 if(byUserId1!=null){  | 
|                     byUserId1.setName(otherUserInfo.getName());  | 
|                     byUserId1.setOverdraftLimit(businessUtil.changeMoney(byUserId1.getOverdraftLimit()));  | 
|                     list.add(byUserId1);  | 
|                 }  | 
|             }  | 
|         }  | 
|   | 
|         packageSiteLimitDto.setAccountInfos(list);  | 
|         return Result.success(packageSiteLimitDto);  | 
|     }  | 
|   | 
|   | 
|     @PostMapping("/packageSite/limitUpdate")  | 
|     @ApiOperation(value = "修改额度管理")  | 
|     public Result limitUpdate(HttpServletRequest request, @Validated @RequestBody PackageSiteLimitDto packageSiteLimitDto){  | 
|         Result result = packageSiteService.updateLimit(packageSiteLimitDto);  | 
|         if(result.getCode()==0){  | 
|             String mobilePhone = userService.findOtherByUserId(getUserId(request),1);  | 
|             OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(mobilePhone)  | 
|                     .methodName(Constants.ORDER_MODUL_NAME).operateAction("修改额度管理-"+packageSiteLimitDto.getPartnerAccountId()).build();  | 
|             mqUtil.sendApp(build);  | 
|         }  | 
|         return result;  | 
|     }  | 
|   | 
|     @PostMapping("/packageSite/find")  | 
|     @ApiOperation(value = "查询所属打包站")  | 
|     public Result<CityPartner> find(HttpServletRequest request){  | 
|         //打包站ID  | 
|         String userId = getUserId(request);  | 
|         OtherUserInfo byId1 = otherUserService.findById(userId);  | 
|         String partnerId = byId1.getPartnerId();  | 
|         CityPartner byId = cityPartnerService.findById(Convert.toInt(partnerId));  | 
|         return Result.success(byId);  | 
|     }  | 
|   | 
|     @PostMapping("/packageSite/limitRecovery")  | 
|     @ApiOperation(value = "打包站恢复额度申请")  | 
|     public Result limitRecovery(HttpServletRequest request){  | 
|         String userId = getUserId(request);  | 
|         OtherUserInfo byId1 = otherUserService.findById(userId);  | 
|         String partnerId = byId1.getPartnerId();  | 
|         Result result = packageSiteService.limitRecovery(partnerId, userId);  | 
|         if(result.getCode()==0){  | 
|             OperationAppLog build = OperationAppLog.builder().appPrograme(getFrontClient(request)).opreateName(byId1.getMobilePhone())  | 
|                     .methodName(Constants.ORDER_MODUL_NAME).operateAction("打包站恢复额度申请-"+partnerId).build();  | 
|             mqUtil.sendApp(build);  | 
|         }  | 
|         return result;  | 
|     }  | 
|   | 
|   | 
|     /**  | 
|      * 查询入库员数据  | 
|      * @param userModel  | 
|      * @return  | 
|      */  | 
|     @PostMapping("/admin/front/packageSite/queryPackageStorageList.do")  | 
|     @ApiOperation(value="数据统计-打包站数据", notes="test: 仅0有正确返回")  | 
|     public JsonResult<Map<String, Object>> queryPackageStorageList(@RequestBody UserModel userModel){  | 
|         Map<String,Object> resultMap = otherUserService.queryPackageStorageList(userModel);  | 
|         return JsonResult.success(resultMap);  | 
|     }  | 
|   | 
|   | 
|     @ApiOperation(value = "打包站导出",produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)  | 
|     @PostMapping(value = "/admin/front/packageSite/export")  | 
|     public void fileExport(@RequestBody ExportParamModel exportParamModel, HttpServletRequest request, HttpServletResponse response) {  | 
|         List<List<String>> rows = new ArrayList<>();  | 
|         //标题  | 
|         List<String> header = CollUtil.newArrayList("打包站", "手机号", "订单量", "订单入库重量", "订单入库金额", "手动入库重量", "手动入库金额");  | 
|         rows.add(header);  | 
|   | 
|         //组装数据  | 
|         UserModel userModel = new UserModel(exportParamModel);  | 
|         Map<String,Object> result = otherUserService.queryPackageStorageList(userModel);  | 
|         List<Map<String,Object>>  storageList = (  List<Map<String,Object>>) result.get("data");  | 
|         if (CollUtil.isNotEmpty(storageList)) {  | 
|             for (Map<String,Object> m:storageList) {  | 
|                 List<String> list = new ArrayList<>();  | 
|                 if(null!=m.get("delFlag")){  | 
|                     if(m.get("delFlag").toString().equals("1")){  | 
|                         m.put("storageName",m.get("storageName").toString()+"(已删除)");  | 
|                     }  | 
|                 }  | 
|                 list.add(m.get("storageName").toString());  | 
|                 list.add(m.get("storageUserPhone").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("storagemoney").toString());  | 
|                 rows.add(list);  | 
|   | 
|             }  | 
|         }  | 
|   | 
|         //导出  | 
|         export(rows,response);  | 
|   | 
|         OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))  | 
|                 .methodName(Constants.USER_MODUL_NAME).operateAction("打包站导出").build();  | 
|         mqUtil.sendApp(build);  | 
|     }  | 
|     | 
| }  |