package com.ruoyi.admin.controller;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.ruoyi.admin.entity.Franchisee;
|
import com.ruoyi.admin.service.FranchiseeService;
|
import com.ruoyi.common.core.constant.Constants;
|
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.exception.GlobalException;
|
import com.ruoyi.common.core.utils.StringUtils;
|
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
/**
|
* <p>
|
* 加盟商信息表 前端控制器
|
* </p>
|
*
|
* @author hjl
|
* @since 2024-05-29
|
*/
|
@RestController
|
@RequestMapping("/franchisee")
|
@Api(tags = {"后台-加盟商管理"})
|
public class FranchiseeController {
|
|
@Resource
|
private FranchiseeService franchiseeService;
|
|
/**
|
* 加盟商信息分页列表
|
*
|
* @param pageNum 页码
|
* @param pageSize 每页显示条数
|
*/
|
@RequiresPermissions("franchisee")
|
@ApiOperation(value = "加盟商信息分页查询列表", tags = {"后台-加盟商管理"})
|
@GetMapping(value = "/page")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "加盟商名称", name = "name", dataType = "String"),
|
@ApiImplicitParam(value = "管理员", name = "head", dataType = "String"),
|
@ApiImplicitParam(value = "手机号码", name = "phone", dataType = "String"),
|
@ApiImplicitParam(value = "管辖城市", name = "city", dataType = "String"),
|
@ApiImplicitParam(value = "页码", name = "pageNum", dataType = "Integer", required = true),
|
@ApiImplicitParam(value = "每页条数", name = "pageSize", dataType = "Integer", required = true)
|
})
|
public R<IPage<Franchisee>> queryPageList(String name, String head, String phone, String city,
|
@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
|
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
|
LambdaQueryChainWrapper<Franchisee> wrapper = franchiseeService.lambdaQuery();
|
wrapper = StringUtils.isNotBlank(name) ? wrapper.like(Franchisee::getName, name) : wrapper;
|
wrapper = StringUtils.isNotBlank(head) ? wrapper.like(Franchisee::getHead, head) : wrapper;
|
wrapper = StringUtils.isNotBlank(phone) ? wrapper.like(Franchisee::getHeadPhone, phone) : wrapper;
|
wrapper = StringUtils.isNotBlank(city) ? wrapper.like(Franchisee::getCity, city) : wrapper;
|
return R.ok(wrapper.eq(Franchisee::getIsDelete, 0)
|
.orderByDesc(Franchisee::getCreateTime).page(Page.of(pageNum, pageSize)));
|
}
|
|
/**
|
* 加盟商信息详情
|
*
|
* @param id 加盟商信息id
|
*/
|
@RequiresPermissions("franchisee")
|
@ApiOperation(value = "加盟商信息详情", tags = {"后台-加盟商管理"})
|
@GetMapping(value = "/detail")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "加盟商信息id", name = "id", dataType = "Integer", required = true)
|
})
|
public R<Franchisee> detail(@RequestParam Integer id) {
|
return R.ok(franchiseeService.getById(id));
|
}
|
|
/**
|
* 新增加盟商信息
|
*
|
* @param franchisee 加盟商信息信息
|
*/
|
@RequiresPermissions("franchisee")
|
@ApiOperation(value = "新增加盟商信息", tags = {"后台-加盟商管理"})
|
@PostMapping(value = "/save")
|
public R<String> save(@RequestBody @Validated Franchisee franchisee) {
|
checkFranchisee(franchisee);
|
if (null == franchisee.getAdminPassword() || StringUtils.isBlank(franchisee.getAdminPassword())) {
|
throw new GlobalException("请输入管理员初始密码!");
|
}
|
//franchisee.setCityStr(String.valueOf(franchisee.getCityArr()));
|
return franchiseeService.save(franchisee) ? R.ok() : R.fail();
|
}
|
|
/**
|
* 修改加盟商信息
|
*
|
* @param franchisee 加盟商信息信息
|
*/
|
@RequiresPermissions("franchisee")
|
@ApiOperation(value = "修改加盟商信息", tags = {"后台-加盟商管理"})
|
@PostMapping(value = "/update")
|
public R<String> update(@RequestBody @Validated Franchisee franchisee) {
|
checkFranchisee(franchisee);
|
return franchiseeService.updateById(franchisee) ? R.ok() : R.fail();
|
}
|
|
/**
|
* 启用/关闭加盟商
|
*
|
* @param id 加盟商id
|
* @param enable 启用/关闭
|
*/
|
@RequiresPermissions("franchisee")
|
@ApiOperation(value = "启用/关闭加盟商", tags = {"后台-加盟商管理"})
|
@GetMapping(value = "/enable")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "加盟商id", name = "id", dataType = "Integer", required = true),
|
@ApiImplicitParam(value = "0:关闭;1:启用", name = "enable", dataType = "Integer", required = true)
|
})
|
public R<String> enable(@RequestParam Integer id, @RequestParam Integer enable) {
|
boolean update = franchiseeService.lambdaUpdate().set(Franchisee::getIsEnable, enable)
|
.eq(Franchisee::getId, id).update();
|
return update ? R.ok() : R.fail();
|
}
|
|
/**
|
* 校验加盟商所管辖城市并加密登录密码
|
*
|
* @param franchisee 加盟商信息
|
*/
|
private void checkFranchisee(Franchisee franchisee) {
|
String city = franchisee.getCity();
|
List<String> cityList = Arrays.stream(city.split(",")).collect(Collectors.toList());
|
for (String c : cityList) {
|
Franchisee one = franchiseeService.lambdaQuery().like(Franchisee::getCity, c)
|
.eq(Franchisee::getIsDelete, 0).one();
|
if (null != one) {
|
throw new GlobalException("当前所选城市中 " + c + " 已有加盟商所管辖!");
|
}
|
}
|
// MD5加密登录密码(新)
|
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
String md5Password = passwordEncoder.encode(Constants.DEFAULT_PASSWORD);
|
franchisee.setAdminPassword(md5Password);
|
}
|
|
/**
|
* 根据id批量删除加盟商信息
|
*
|
* @param ids 加盟商信息多条id拼接
|
*/
|
@RequiresPermissions("franchisee")
|
@ApiOperation(value = "批量删除加盟商信息", tags = {"后台-加盟商管理"})
|
@GetMapping(value = "/batchDelete")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "多条加盟商信息id ',' 拼接", name = "ids", dataType = "String", required = true)
|
})
|
public R<String> batchDelete(@RequestParam String ids) {
|
List<String> idList = Arrays.stream(ids.split(",")).collect(Collectors.toList());
|
List<Franchisee> list = franchiseeService.lambdaQuery().in(Franchisee::getId, idList).list();
|
list.forEach(data -> data.setIsDelete(1));
|
return franchiseeService.updateBatchById(list) ? R.ok() : R.fail();
|
}
|
|
}
|