package com.xiaopeng.operation.controller;
|
|
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.util.DesensitizedUtil;
|
import com.xiaopeng.api.feignClient.account.SysGroupMenuClient;
|
import com.xiaopeng.api.model.account.SysUser;
|
import com.xiaopeng.api.model.operation.XpTargetedService;
|
import com.xiaopeng.api.model.operation.XpWhitelist;
|
import com.xiaopeng.api.query.operation.XpTargetedServiceQuery;
|
import com.xiaopeng.api.vo.account.LoginUser;
|
import com.xiaopeng.api.vo.operation.XpTargetedServiceVehicleVo;
|
import com.xiaopeng.api.vo.operation.XpTargetedServiceVo;
|
import com.xiaopeng.common.core.domain.R;
|
import com.xiaopeng.common.core.utils.bean.BeanUtils;
|
import com.xiaopeng.common.core.web.page.PageInfo;
|
import com.xiaopeng.common.security.service.TokenService;
|
import com.xiaopeng.operation.dto.WhitelistAddDto;
|
import com.xiaopeng.operation.dto.WhitelistEditDto;
|
import com.xiaopeng.operation.query.WhitelistPageListQuery;
|
import com.xiaopeng.operation.service.XpTargetedServiceService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.StringUtils;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import java.time.LocalDate;
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
@RestController
|
@RequestMapping("")
|
@Api(tags = "定向服务")
|
@Slf4j
|
public class XpTargetedServiceController {
|
|
@Resource
|
XpTargetedServiceService xpTargetedServiceService;
|
@Resource
|
private TokenService tokenService;
|
@Resource
|
private SysGroupMenuClient groupMenuClient;
|
|
|
@ApiOperation(value = "定向服务分页", tags = {"管理后台-定向服务分页"})
|
@PostMapping("/api/v1/targetedService/pageList")
|
public R<PageInfo<XpTargetedServiceVo>> pageList(@RequestBody XpTargetedServiceQuery query) {
|
PageInfo<XpTargetedServiceVo> pageList = xpTargetedServiceService.pageList(query);
|
return R.ok(pageList);
|
}
|
@ApiOperation(value = "定向服务-详情", tags = {"管理后台-定向服务详情"})
|
@GetMapping("/api/v1/targetedService/detail")
|
public R<XpTargetedServiceVo> detail(@RequestParam Long id) {
|
LoginUser loginUser = tokenService.getLoginUser();
|
if (id == null) {
|
return R.fail("ID不能为空");
|
}
|
XpTargetedServiceVo vo = xpTargetedServiceService.getById(id);
|
if (vo == null) {
|
return R.fail("数据不存在");
|
}
|
if(!loginUser.getPhoneDesensitizationExempt()){
|
vo.getWhitelistList().forEach(s->s.setAccount(DesensitizedUtil.mobilePhone(s.getAccount())));
|
}
|
|
return R.ok(vo);
|
}
|
|
|
/**
|
* 新增白名单
|
*/
|
@PostMapping("/api/v1/targetedService/add")
|
@ApiOperation(value = "定向服务-添加", tags = {"管理后台-定向服务添加"})
|
public R add(@Validated @RequestBody XpTargetedServiceVo dto) {
|
SysUser sysUser = tokenService.getLoginUser().getSysUser();
|
xpTargetedServiceService.add(dto, sysUser);
|
|
return R.ok();
|
}
|
|
/**
|
* 编辑白名单
|
*/
|
@PostMapping("/api/v1/targetedService/edit")
|
@ApiOperation(value = "定向服务-修改", tags = {"管理后台-定向服务修改"})
|
public R edit(@Validated @RequestBody XpTargetedServiceVo dto) {
|
if(dto.getId() == null){
|
return R.fail("ID不能为空");
|
}
|
XpTargetedService byId = xpTargetedServiceService.getById(dto.getId());
|
if(byId == null){
|
return R.fail("数据不存在");
|
}
|
|
SysUser sysUser = tokenService.getLoginUser().getSysUser();
|
xpTargetedServiceService.edit(dto, sysUser);
|
return R.ok();
|
}
|
|
/**
|
* 修改状态
|
*/
|
@PostMapping("/api/v1/targetedService/updateStatus")
|
@ApiOperation(value = "定向服务-修改状态", tags = {"管理后台-定向服务修改状态"})
|
public R updateStatus(@RequestParam Long id, @RequestParam Integer status) {
|
if (id == null) {
|
return R.fail("ID不能为空");
|
}
|
if (status == null) {
|
return R.fail("状态不能为空");
|
}
|
|
SysUser sysUser = tokenService.getLoginUser().getSysUser();
|
boolean b = xpTargetedServiceService.updateStatus(id, status, sysUser);
|
if(b){
|
return R.ok();
|
}
|
return R.fail("修改失败");
|
}
|
|
|
|
/**
|
* 批量删除
|
*/
|
@PostMapping("/api/v1/targetedService/deleteByIds")
|
@ApiOperation(value = "定向服务-批量删除", tags = {"管理后台-定向服务批量删除"})
|
public R deleteByIds(@RequestBody XpTargetedServiceQuery query ) {
|
if(CollUtil.isEmpty(query.getIds())){
|
return R.fail("ID列表不能为空");
|
}
|
SysUser sysUser = tokenService.getLoginUser().getSysUser();
|
return xpTargetedServiceService.deleteByIds(query.getIds(), sysUser);
|
}
|
|
/**
|
* 根据用户ID和城市编码获取
|
* @param appUserId 用户ID
|
* @param cityCode 城市编码
|
* @return
|
*/
|
@GetMapping("/logan/inner/v1/targetedService/findListByUserIdAndCityCode")
|
public R<List<XpTargetedServiceVehicleVo>> findListByUserIdAndCityCode(@RequestParam Long appUserId, @RequestParam String cityCode){
|
return R.ok(xpTargetedServiceService.findListByUserIdAndCityCode(appUserId,cityCode));
|
}
|
|
|
|
|
}
|