xiaoyong931011
2021-07-07 dc3beb5e2c9c62bfc40330201ace94f781d28fd2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
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);
    }
  
}