新增推广人员修改推广人员接口开发
parent
52e40ed637
commit
7551b11b28
@ -0,0 +1,72 @@
|
||||
package com.kiisoo.ic.store.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.kiisoo.ic.common.BaseController;
|
||||
import com.kiisoo.ic.employee.entity.EmployeeDO;
|
||||
import com.kiisoo.ic.employee.entity.PrivilageCpUserDO;
|
||||
import com.kiisoo.ic.employee.service.EmployeeService;
|
||||
import com.kiisoo.ic.store.entity.PoiStoreStaff;
|
||||
import com.kiisoo.ic.store.entity.PoiStoreStaffVO;
|
||||
import com.kiisoo.ic.store.service.PoiStoreStaffService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 门店人员信息
|
||||
* @Auther: yinliujiang
|
||||
* @Date: 2020/4/9
|
||||
* @Version: v1
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/store/staff")
|
||||
@Slf4j
|
||||
public class StoreStaffController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private PoiStoreStaffService poiStoreStaffService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询店铺人员列表
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
* @throws
|
||||
*/
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Map<String, Object> staffList(int pageNum, int pageSize, long userId, Long shopId, Long regionId) {
|
||||
try {
|
||||
IPage<PoiStoreStaffVO> storeStaffIs = poiStoreStaffService.getStaffByUserAndDate( pageNum, pageSize, userId, shopId, regionId);
|
||||
return data(storeStaffIs);
|
||||
} catch (Exception e) {
|
||||
log.error("获取店铺人员", e);
|
||||
return fail();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询店铺人员列表
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
* @throws
|
||||
*/
|
||||
@RequestMapping(value = "/add", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Map<String, Object> addStaff(PoiStoreStaffVO poiStoreStaffVO) {
|
||||
try {
|
||||
poiStoreStaffService.addStaff(poiStoreStaffVO);
|
||||
return success();
|
||||
} catch (Exception e) {
|
||||
log.error("获取店铺人员", e);
|
||||
return fail();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
package com.kiisoo.ic.store.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Description: 门店人员信息
|
||||
* @Author: Caps
|
||||
* @Date 2020-04-07
|
||||
*/
|
||||
@Data
|
||||
public class PoiStoreStaffVO {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
*/
|
||||
private Long storeId;
|
||||
|
||||
/**
|
||||
* 店铺人员, 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* 店铺code
|
||||
*/
|
||||
private String storeCode;
|
||||
/**
|
||||
* 人员code
|
||||
*/
|
||||
private String staffCode;
|
||||
|
||||
/**
|
||||
* 1 店长 2 副店长 3 店长助理 4 导购
|
||||
*/
|
||||
private Long type;
|
||||
|
||||
/**
|
||||
* 企业微信openID
|
||||
*/
|
||||
private String epWechatOpenId;
|
||||
|
||||
/**
|
||||
* 企业微信导购二维码
|
||||
*/
|
||||
private String epWechatQrCode;
|
||||
|
||||
/**
|
||||
* 企业微信配置ID
|
||||
*/
|
||||
private String epWechatConfigId;
|
||||
|
||||
/**
|
||||
* 状态 1 有效 2 无效
|
||||
*/
|
||||
private Long status;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 是否删除: 0 false 1 true
|
||||
*/
|
||||
private Integer deleted;
|
||||
/**
|
||||
* 人员名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 人员电话
|
||||
*/
|
||||
private String mobil;
|
||||
/**
|
||||
* 店铺名称
|
||||
*/
|
||||
private String storeName;
|
||||
|
||||
/**
|
||||
* 角色
|
||||
*/
|
||||
private String role;
|
||||
/**
|
||||
* 账号
|
||||
*/
|
||||
private String login;
|
||||
|
||||
private Long roleId;
|
||||
}
|
@ -0,0 +1,177 @@
|
||||
package com.kiisoo.ic.store.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.kiisoo.ic.customer.entity.OpCustomerEnterpriseWechat;
|
||||
import com.kiisoo.ic.domain.service.PrivilageDomainService;
|
||||
import com.kiisoo.ic.employee.entity.QrCodeDO;
|
||||
import com.kiisoo.ic.employee.entity.QrCodeVO;
|
||||
import com.kiisoo.ic.employee.service.QrCodeService;
|
||||
import com.kiisoo.ic.store.entity.PoiStore;
|
||||
import com.kiisoo.ic.store.entity.PoiStoreStaff;
|
||||
import com.kiisoo.ic.store.entity.PoiStoreStaffVO;
|
||||
import com.kiisoo.ic.store.mapper.PoiStoreDOMapper;
|
||||
import com.kiisoo.ic.store.mapper.PoiStoreStaffDOMapper;
|
||||
import com.kiisoo.ic.system.bean.AccountBean;
|
||||
import com.kiisoo.ic.system.bean.PrivilageUserBean;
|
||||
import com.kiisoo.ic.system.entity.PrivilageAccountDO;
|
||||
import com.kiisoo.ic.system.entity.PrivilageUserDO;
|
||||
import com.kiisoo.ic.system.enums.AccountEnum;
|
||||
import com.kiisoo.ic.system.mapper.PrivilageUserDOMapper;
|
||||
import com.kiisoo.ic.system.service.PrivilageAccountService;
|
||||
import com.kiisoo.ic.system.service.PrivilageRoleService;
|
||||
import com.kiisoo.ic.system.service.PrivilageUserRoleService;
|
||||
import com.kiisoo.ic.system.service.PrivilageUserService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 店铺
|
||||
*/
|
||||
@Service
|
||||
public class PoiStoreStaffService {
|
||||
|
||||
@Autowired
|
||||
private PoiStoreStaffDOMapper poiStoreStaffDOMapper;
|
||||
@Autowired
|
||||
private PrivilageDomainService privilageDomainService;
|
||||
@Autowired
|
||||
private PoiStoreService poiStoreService;
|
||||
@Autowired
|
||||
private PrivilageUserDOMapper privilageUserDOMapper;
|
||||
@Autowired
|
||||
private PoiStoreDOMapper poiStoreDOMapper;
|
||||
@Autowired
|
||||
private PrivilageAccountService privilageAccountService;
|
||||
@Autowired
|
||||
private PrivilageUserService privilageUserService;
|
||||
@Autowired
|
||||
private PrivilageUserRoleService privilageUserRoleService;
|
||||
@Autowired
|
||||
private QrCodeService qrCodeService;
|
||||
/**
|
||||
* 根据条件查询导购信息
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param shopId 店铺id
|
||||
* @param regionId 区域id
|
||||
*/
|
||||
public IPage<PoiStoreStaffVO> getStaffByUserAndDate(int pageNum, int pageSize, long userId, Long shopId, Long regionId) {
|
||||
List<Long> shopIds = new ArrayList<>();
|
||||
//根据店铺查询所有扫码客户信息
|
||||
QueryWrapper<PoiStoreStaff> wrapper = new QueryWrapper<>();
|
||||
//如果有店铺则查店铺
|
||||
if (shopId != null) {
|
||||
shopIds.add(shopId);
|
||||
} else if (regionId != null) {
|
||||
//如果有区域则查区域店铺
|
||||
List<PoiStore> shops = poiStoreService.getRegionShop(regionId);
|
||||
shopIds = shops.stream().map(p -> p.getId()).collect(Collectors.toList());
|
||||
} else {
|
||||
//查询用户权限店铺
|
||||
shopIds = new ArrayList<>(privilageDomainService.listUserDatePermission(userId));
|
||||
}
|
||||
wrapper.in("store_id", shopIds);
|
||||
//状态有效
|
||||
wrapper.eq("status", 1);
|
||||
wrapper.orderByDesc("id");
|
||||
//返回店铺对应的导购
|
||||
IPage<PoiStoreStaff> poiStoreStaffs = poiStoreStaffDOMapper.selectPage(new Page<>(pageNum, pageSize), wrapper);
|
||||
IPage<PoiStoreStaffVO> resultList = new Page<>();
|
||||
List<PoiStoreStaffVO> list = new ArrayList<>();
|
||||
BeanUtils.copyProperties(poiStoreStaffs, resultList);
|
||||
List<PoiStoreStaff> records = poiStoreStaffs.getRecords();
|
||||
records.forEach(poiStoreStaff -> {
|
||||
PoiStoreStaffVO poiStoreStaffVO = new PoiStoreStaffVO();
|
||||
BeanUtils.copyProperties(poiStoreStaff, poiStoreStaffVO);
|
||||
PrivilageUserBean privilageUserBean = privilageUserDOMapper.selectUserInfoAndRoleInfo(poiStoreStaff.getUserId());
|
||||
poiStoreStaffVO.setName(privilageUserBean.getName());
|
||||
poiStoreStaffVO.setMobil(privilageUserBean.getMobil());
|
||||
poiStoreStaffVO.setRole(privilageUserBean.getRoleName());
|
||||
PoiStore poiStore = poiStoreDOMapper.selectById(poiStoreStaff.getStoreId());
|
||||
poiStoreStaffVO.setStoreName(poiStore.getName());
|
||||
list.add(poiStoreStaffVO);
|
||||
});
|
||||
resultList.setTotal(poiStoreStaffs.getTotal());
|
||||
resultList.setRecords(list);
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加店铺人员
|
||||
* @param poiStoreStaffVO
|
||||
*/
|
||||
public int addStaff(PoiStoreStaffVO poiStoreStaffVO) throws Exception {
|
||||
//添加一个用户
|
||||
PrivilageUserDO privilageUserDO = new PrivilageUserDO();
|
||||
BeanUtils.copyProperties(poiStoreStaffVO,privilageUserDO);
|
||||
Long userId = privilageUserService.addUser(privilageUserDO);
|
||||
if (null == userId ) return 0;
|
||||
//添加用户和角色的关系
|
||||
privilageUserRoleService.insertUserRoleRelation(userId,poiStoreStaffVO.getRoleId());
|
||||
//添加一个账号
|
||||
privilageAccountService.insertAccount(poiStoreStaffVO.getLogin(), AccountEnum.ACCOUNT_FIRST_PWD.getDescribe(),userId);
|
||||
//去生成一个推广人员二维码
|
||||
|
||||
QrCodeVO qrCodeVO = parseQrCode(poiStoreStaffVO);
|
||||
//添加一个店铺人员
|
||||
PoiStoreStaff poiStoreStaff = new PoiStoreStaff();
|
||||
BeanUtils.copyProperties(poiStoreStaffVO,poiStoreStaff);
|
||||
poiStoreStaff.setUserId(userId);
|
||||
poiStoreStaff.setType(poiStoreStaffVO.getRoleId());
|
||||
poiStoreStaff.setEpWechatQrCode(qrCodeVO.getQr_code());
|
||||
poiStoreStaff.setEpWechatConfigId(qrCodeVO.getConfig_id());
|
||||
return poiStoreStaffDOMapper.insert(poiStoreStaff);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改推广人信息
|
||||
*/
|
||||
public int ediStaff(PoiStoreStaffVO poiStoreStaffVO) throws Exception {
|
||||
//修改用户信息
|
||||
long userId = poiStoreStaffVO.getUserId();
|
||||
PrivilageUserDO privilageUserDO = new PrivilageUserDO();
|
||||
BeanUtils.copyProperties(poiStoreStaffVO,privilageUserDO);
|
||||
privilageUserService.updateById(privilageUserDO);
|
||||
//保存用户角色
|
||||
privilageUserRoleService.saveUserRole(userId, poiStoreStaffVO.getRoleId());
|
||||
//修改店铺人员信息
|
||||
PoiStoreStaff oldStaffInfo = poiStoreStaffDOMapper.selectById(poiStoreStaffVO.getId());
|
||||
PoiStoreStaff poiStoreStaff = new PoiStoreStaff();
|
||||
//修改了所属店铺
|
||||
if (!oldStaffInfo.getStoreId().equals(poiStoreStaffVO.getStoreId())){
|
||||
// 判断条件是否重新修改二维码
|
||||
QrCodeVO qrCodeVO = parseQrCode(poiStoreStaffVO);
|
||||
poiStoreStaff.setEpWechatQrCode(qrCodeVO.getQr_code());
|
||||
poiStoreStaff.setEpWechatConfigId(qrCodeVO.getConfig_id());
|
||||
}
|
||||
BeanUtils.copyProperties(poiStoreStaffVO,poiStoreStaff);
|
||||
poiStoreStaff.setType(poiStoreStaffVO.getRoleId());
|
||||
return poiStoreStaffDOMapper.insert(poiStoreStaff);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成企业微信二维码
|
||||
*/
|
||||
public QrCodeVO parseQrCode(PoiStoreStaffVO poiStoreStaffVO) throws Exception {
|
||||
QrCodeDO qrCodeDO = new QrCodeDO();
|
||||
qrCodeDO.setType(1);
|
||||
qrCodeDO.setScene(2);
|
||||
//查询店铺店长编码
|
||||
String staffCode = poiStoreStaffDOMapper.selectShopManagerByShop(poiStoreStaffVO.getStoreId());
|
||||
String[] data = new String[1];
|
||||
//选择店铺对应店长的编码
|
||||
data[0] = (staffCode);
|
||||
qrCodeDO.setUser(data);
|
||||
//店铺编码-导购编码
|
||||
qrCodeDO.setState(poiStoreStaffVO.getStoreCode() +"-"+poiStoreStaffVO.getStaffCode());
|
||||
return qrCodeService.getQrCode(qrCodeDO);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package com.kiisoo.ic.system.bean;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 用户表
|
||||
* @author jinchaofan
|
||||
* @since 2020-02-19
|
||||
*/
|
||||
@Data
|
||||
|
||||
public class PrivilageUserBean implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@TableId(value = "id",type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 电话
|
||||
*/
|
||||
private String mobil;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 地址
|
||||
*/
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 角色名
|
||||
*/
|
||||
private String roleName;
|
||||
|
||||
/**
|
||||
* 角色id
|
||||
*/
|
||||
private Long roleId;
|
||||
/**
|
||||
* 角色码
|
||||
*/
|
||||
private String roleCode;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.kiisoo.ic.system.mapper.PrivilageUserDOMapper">
|
||||
|
||||
<select id="selectUserInfoAndRoleInfo" resultType="com.kiisoo.ic.system.bean.PrivilageUserBean">
|
||||
select t1.id ,t1.name, t1.mobil,t3.name as roleName, t3.id as roleId, t3.code as roleCode
|
||||
from privilage_user t1, privilage_user_role t2, privilage_role t3
|
||||
where t1.id = t2.user_id
|
||||
and t2.role_id = t3.id
|
||||
and t1.id = #{userId}
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue