You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
277 lines
8.1 KiB
Java
277 lines
8.1 KiB
Java
package com.kiisoo.ic.employee.controller;
|
|
|
|
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 lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.imageio.ImageIO;
|
|
import javax.servlet.ServletOutputStream;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.awt.*;
|
|
import java.awt.image.BufferedImage;
|
|
import java.io.*;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.UUID;
|
|
|
|
/**
|
|
* @Description: 用户管理controller
|
|
* @Auther: yechenhao
|
|
* @Date: 2020/4/7 0002 10:06
|
|
* @Version: v1
|
|
*/
|
|
@Controller
|
|
@RequestMapping("/user")
|
|
@Slf4j
|
|
public class EmployeeController extends BaseController {
|
|
|
|
@Autowired
|
|
private EmployeeService employeeService;
|
|
|
|
|
|
/**
|
|
* 新增成员
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
@RequestMapping(value = "list",method = RequestMethod.POST)
|
|
@ResponseBody
|
|
public Map<String,Object> listUser(){
|
|
try {
|
|
List<PrivilageCpUserDO> privilageCpUserDOS = employeeService.listUser();
|
|
return data(privilageCpUserDOS);
|
|
}catch (Exception e){
|
|
log.error("添加用户失败",e);
|
|
return fail();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 同步客户数据
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
@RequestMapping(value = "sync/custommer",method = RequestMethod.GET)
|
|
@ResponseBody
|
|
public Map<String,Object> syncCustoemr(){
|
|
try {
|
|
employeeService.syncCustoemr();
|
|
return success();
|
|
}catch (Exception e){
|
|
log.error("同步客户数据失败",e);
|
|
return fail();
|
|
}
|
|
}
|
|
/**
|
|
* 同步客户数据
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
@RequestMapping(value = "sync/custommer/cpuserid",method = RequestMethod.GET)
|
|
@ResponseBody
|
|
public Map<String,Object> syncCustoemrByCpUserIds(@RequestParam("cpUserIds")String cpUserIds){
|
|
try {
|
|
employeeService.syncCustoemrByCpUserIds(cpUserIds);
|
|
return success();
|
|
}catch (Exception e){
|
|
log.error("同步客户数据失败",e);
|
|
return fail();
|
|
}
|
|
}
|
|
/**
|
|
* 清理客户数据
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
@RequestMapping(value = "clean/custommer",method = RequestMethod.GET)
|
|
@ResponseBody
|
|
public Map<String,Object> cleanCustomerRelation(){
|
|
try {
|
|
employeeService.cleanCustomerRelation();
|
|
return success();
|
|
}catch (Exception e){
|
|
log.error("清理客户数据失败",e);
|
|
return fail();
|
|
}
|
|
}
|
|
/**
|
|
* 清理店铺客户数据
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
@RequestMapping(value = "clean/store/custommer",method = RequestMethod.GET)
|
|
@ResponseBody
|
|
public Map<String,Object> cleanCustomerRelation(@RequestParam("storeCode") String storeCode){
|
|
try {
|
|
employeeService.cleanCustomerRelationByStoreCode(storeCode);
|
|
return success();
|
|
}catch (Exception e){
|
|
log.error("清理店铺客户数据失败",e);
|
|
return fail();
|
|
}
|
|
}
|
|
/**
|
|
* 清理店铺客户数据
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
@RequestMapping(value = "clean/company/custommer",method = RequestMethod.GET)
|
|
@ResponseBody
|
|
public Map<String,Object> cleanCustomerRelation(@RequestParam("companyId") Long companyId){
|
|
try {
|
|
employeeService.cleanCustomerRelationBycompanyId(companyId);
|
|
return success();
|
|
}catch (Exception e){
|
|
log.error("清理店铺客户数据失败",e);
|
|
return fail();
|
|
}
|
|
}
|
|
/**
|
|
* 下载图片
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
@RequestMapping(value = "img/download",method = RequestMethod.POST)
|
|
public void listUser(@RequestParam("url")String url,HttpServletResponse response){
|
|
BufferedInputStream in = null;
|
|
try {
|
|
|
|
in = new BufferedInputStream(employeeService.getInputStream(url));
|
|
String fileName = UUID.randomUUID().toString().replace("-","");
|
|
File file = new File(fileName + ".png");
|
|
//字节流转图片对象
|
|
Image bi = ImageIO.read(in);
|
|
//构建图片流
|
|
BufferedImage tag = new BufferedImage(300, 300, BufferedImage.TYPE_INT_RGB);
|
|
//绘制改变尺寸后的图
|
|
tag.getGraphics().drawImage(bi, 0, 0, 300, 300, null);
|
|
//输出流
|
|
BufferedOutputStream image = new BufferedOutputStream(new FileOutputStream(file));
|
|
|
|
ImageIO.write(tag, "PNG", image);
|
|
|
|
in.close();
|
|
image.close();
|
|
|
|
|
|
//将文件输入到response
|
|
ServletOutputStream outputStream = response.getOutputStream();
|
|
byte[] buffer = new byte[1024];
|
|
File zipFile = new File(fileName + ".png");
|
|
FileInputStream inStream = new FileInputStream(zipFile);
|
|
int lenNew;
|
|
while ((lenNew = inStream.read(buffer)) > 0) {
|
|
outputStream.write(buffer, 0, lenNew);
|
|
}
|
|
//删除文件,清理空间
|
|
file.delete();
|
|
zipFile.delete();
|
|
outputStream.flush();
|
|
|
|
}catch (Exception e){
|
|
log.error("下载图片",e);
|
|
}finally {
|
|
try {
|
|
in.close();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* 新增成员
|
|
* @param response 请求响应
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
@RequestMapping(value = "qrCode",method = RequestMethod.GET)
|
|
public void downLoadQrCode(HttpServletResponse response){
|
|
try {
|
|
employeeService.downLoadQrCode(response);
|
|
}catch (Exception e){
|
|
log.error("下载二维码",e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 同步成员
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
@RequestMapping(value = "sync",method = RequestMethod.GET)
|
|
@ResponseBody
|
|
public Map<String,Object> syncUser(){
|
|
try {
|
|
employeeService.syncUser();
|
|
return data(null);
|
|
}catch (Exception e){
|
|
log.error("添加用户失败",e);
|
|
return fail();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 新增成员
|
|
* @param employee 成员实体
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
@RequestMapping(value = "add",method = RequestMethod.POST)
|
|
@ResponseBody
|
|
public Map<String,Object> addUser(EmployeeDO employee){
|
|
try {
|
|
//标识是否同步发邮件和短信
|
|
if (null != employee.getCheckbox() && employee.getCheckbox().length >0){
|
|
employee.setToInvite(true);
|
|
}
|
|
String code = employeeService.addUser(employee);
|
|
return data(code);
|
|
}catch (Exception e){
|
|
log.error("添加用户失败",e);
|
|
return fail();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 修改成员
|
|
* @param employee 成员实体
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
@RequestMapping(value = "update",method = RequestMethod.POST)
|
|
@ResponseBody
|
|
public Map<String,Object> updateUser(@RequestBody EmployeeDO employee){
|
|
try {
|
|
Boolean hasAdd = employeeService.updateUser(employee);
|
|
return data(hasAdd);
|
|
}catch (Exception e){
|
|
log.error("修改用户失败",e);
|
|
return fail();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除成员
|
|
* @param cpUserId 成员id
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
@RequestMapping(value = "delete",method = RequestMethod.POST)
|
|
@ResponseBody
|
|
public Map<String,Object> deleteUser(@RequestParam("cpUserId") Long cpUserId){
|
|
try {
|
|
Boolean hasAdd = employeeService.deleteUser(cpUserId);
|
|
return data(hasAdd);
|
|
}catch (Exception e){
|
|
log.error("删除用户失败",e);
|
|
return fail();
|
|
}
|
|
}
|
|
}
|