nickchange
2023-10-10 ee9cb0da4a43bcf523ebb157678f64a2895fba1a
cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/UserMgrController.java
@@ -2,12 +2,6 @@
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dsh.course.feignClient.account.model.Company;
import com.dsh.course.feignClient.activity.CompanyClient;
import com.dsh.course.feignClient.activity.DriverClient;
import com.dsh.course.feignClient.activity.model.CompanyInfoRes;
import com.dsh.course.feignClient.activity.model.CompanyQueryStateAndFlgReq;
import com.dsh.course.feignClient.activity.model.UpdateCompanyDriverReq;
import com.dsh.course.mapper.UserMapper;
import com.dsh.guns.config.UserExt;
import com.dsh.guns.config.properties.GunsProperties;
@@ -25,7 +19,6 @@
import com.dsh.guns.core.exception.GunsException;
import com.dsh.guns.core.log.LogObjectHolder;
import com.dsh.guns.core.util.SinataUtil;
import com.dsh.guns.core.util.ToolUtil;
import com.dsh.guns.modular.system.controller.util.MD5;
import com.dsh.guns.modular.system.factory.UserFactory;
import com.dsh.guns.modular.system.model.Role;
@@ -33,6 +26,8 @@
import com.dsh.guns.modular.system.service.IRoleService;
import com.dsh.guns.modular.system.service.IUserService;
import com.dsh.guns.modular.system.transfer.UserDto;
import com.dsh.guns.modular.system.util.OssUploadUtil;
import com.dsh.guns.modular.system.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@@ -40,10 +35,9 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.naming.NoPermissionException;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.File;
import java.util.*;
/**
@@ -64,14 +58,9 @@
    @Autowired
    private IUserService userService;
    @Resource
    private DriverClient itDriverService;
    @Autowired
    private IRoleService roleService;
    @Resource
    private CompanyClient itCompanyService;
    /**
@@ -167,7 +156,6 @@
        if (user.getPassword().equals(oldMd5)) {
            String newMd5 = MD5.md5(newPwd);
            user.setPassword(newMd5);
            user.setPassWordUpdate(new Date());
            user.updateById();
            return SUCCESS_TIP;
        } else {
@@ -231,11 +219,6 @@
        User objectUser = UserFactory.createUser(user);
        //查找平台所属公司
        //Search for the company that owns the platform.
        Company company = itCompanyService.getCompanyByTypeAndFlag(new CompanyQueryStateAndFlgReq(1,3));
        if (SinataUtil.isNotEmpty(company)){
            objectUser.setObjectId(company.getId());
        }
        objectUser.setPassWordUpdate(new Date());
        this.userService.save(objectUser);
        return SUCCESS_TIP;
@@ -348,28 +331,6 @@
        assertAuth(userId);
        this.userService.setStatus(userId, ManagerStatus.FREEZED.getCode());
        User user = userService.getById(userId);
        if (user.getRoleType() == 2){
            //查询分公司 Query branch office
            CompanyInfoRes company = itCompanyService.queryById(user.getObjectId());
            company.setState(1);
            itCompanyService.updateCompany(company);
            //设置该分公司下的所有司机状态
            //Set the status of all drivers under this branch
            itDriverService.updateCompanyDriverState(new UpdateCompanyDriverReq(3,company.getId()));
        }else if (user.getRoleType() == 3){
            //查询加盟商
            //Search for franchisees
            CompanyInfoRes franchisee = itCompanyService.queryById(user.getObjectId());
            franchisee.setState(1);
            itCompanyService.updateCompany(franchisee);
            //设置该加盟商下的所有司机状态
            //Set the status of all drivers under this franchisee
            itDriverService.updateFranchiseeDriverState(new UpdateCompanyDriverReq(3,franchisee.getId()));
        }
        return SUCCESS_TIP;
    }
@@ -387,29 +348,6 @@
        assertAuth(userId);
        this.userService.setStatus(userId, ManagerStatus.OK.getCode());
        User user = userService.getById(userId);
        if (user.getRoleType() == 2){
            //查询分公司
            //Query branch office
            CompanyInfoRes company = itCompanyService.queryById(user.getObjectId());
            company.setState(0);
            itCompanyService.updateCompany(company);
            //设置该分公司下的所有司机状态
            ////Set the status of all drivers under this branch
            itDriverService.updateCompanyDriverState(new UpdateCompanyDriverReq(2,company.getId()));
        }else if (user.getRoleType() == 3){
            //查询加盟商
            ////Search for franchisees
            CompanyInfoRes franchisee = itCompanyService.queryById(user.getObjectId());
            franchisee.setState(0);
            itCompanyService.updateCompany(franchisee);
            //设置该加盟商下的所有司机状态
            //Set the status of all drivers under this branch
            itDriverService.updateFranchiseeDriverState(new UpdateCompanyDriverReq(2,franchisee.getId()));
        }
        return SUCCESS_TIP;
    }
@@ -439,21 +377,57 @@
    /**
     * 上传图片
     */
    @RequestMapping(method = RequestMethod.POST, path = "/upload")
    @RequestMapping(method = RequestMethod.POST, path = "/uploadImg")
    @ResponseBody
    public String upload(@RequestPart("file") MultipartFile picture) {
        String pictureName = UUID.randomUUID().toString() + "." + ToolUtil.getFileSuffix(picture.getOriginalFilename());
    public String uploadImg(@RequestPart("file") MultipartFile picture) {
        String pictureName = "";
        try {
            String fileSavePath = gunsProperties.getFileUploadPath();
            picture.transferTo(new File(fileSavePath + pictureName));
        } catch (Exception e) {
            throw new GunsException(BizExceptionEnum.UPLOAD_ERROR);
            pictureName = OssUploadUtil.ossUpload("img/", picture);
        }catch (Exception e){
            e.printStackTrace();
        }
        return pictureName;
    }
    /**
     * 上传图片
     */
    /**
     * 上传图片Amis
     */
    @RequestMapping(method = RequestMethod.POST, path = "/uploadImgAmis")
    @ResponseBody
    public ResultUtil uploadImgAmis(@RequestPart("file") MultipartFile picture, HttpServletResponse response) {
        String value = "";
        try {
            value = OssUploadUtil.ossUpload("img/", picture);
        }catch (Exception e){
            e.printStackTrace();
        }
        System.out.println("图片返回地址-------"+value);
        Map<String, String> map = new HashMap<>();
        map.put("value",value);
//        return  ResultUtil.success(0,map);
        return  ResultUtil.getResult(0,null,null,map);
    }
    @RequestMapping(method = RequestMethod.POST, path = "/uploadFile")
    @ResponseBody
    public String uploadFile(@RequestPart("file") MultipartFile picture) {
        String pictureName = "";
        try {
            pictureName = OssUploadUtil.ossUpload("video/", picture);
        }catch (Exception e){
            e.printStackTrace();
        }
        return pictureName;
    }
    /**
     * 判断当前登录的用户是否有操作这个用户的权限
     */
    private void assertAuth(Integer userId) {