Search in sources :

Example 91 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project yshopmall by guchengwuyue.

the class PictureServiceImpl method upload.

@Override
@Transactional(rollbackFor = Throwable.class)
public Picture upload(MultipartFile multipartFile, String username) {
    File file = FileUtil.toFile(multipartFile);
    // 验证是否重复上传
    Picture picture = this.getOne(new LambdaQueryWrapper<Picture>().eq(Picture::getMd5code, FileUtil.getMd5(file)));
    if (picture != null) {
        return picture;
    }
    HashMap<String, Object> paramMap = new HashMap<>(1);
    paramMap.put("smfile", file);
    // 上传文件
    String result = HttpRequest.post(YshopConstant.Url.SM_MS_URL + "/v2/upload").header("Authorization", token).form(paramMap).timeout(20000).execute().body();
    JSONObject jsonObject = JSONUtil.parseObj(result);
    if (!jsonObject.get(CODE).toString().equals(SUCCESS)) {
        throw new BadRequestException(TranslatorUtil.translate(jsonObject.get(MSG).toString()));
    }
    picture = JSON.parseObject(jsonObject.get("data").toString(), Picture.class);
    picture.setSize(FileUtil.getSize(Integer.parseInt(picture.getSize())));
    picture.setUsername(username);
    picture.setMd5code(FileUtil.getMd5(file));
    picture.setFilename(FileUtil.getFileNameNoEx(multipartFile.getOriginalFilename()) + "." + FileUtil.getExtensionName(multipartFile.getOriginalFilename()));
    this.save(picture);
    // 删除临时文件
    FileUtil.del(file);
    return picture;
}
Also used : JSONObject(cn.hutool.json.JSONObject) Picture(co.yixiang.modules.tools.domain.Picture) BadRequestException(co.yixiang.exception.BadRequestException) JSONObject(cn.hutool.json.JSONObject) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Transactional(org.springframework.transaction.annotation.Transactional)

Example 92 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project yshopmall by guchengwuyue.

the class MenuServiceImpl method update.

/**
 * 编辑
 *
 * @param resources /
 */
@Override
@CacheEvict(allEntries = true)
public void update(Menu resources) {
    if (resources.getId().equals(resources.getPid())) {
        throw new BadRequestException("上级不能为自己");
    }
    Menu menu = this.getById(resources.getId());
    ValidationUtil.isNull(menu.getId(), "Permission", "id", resources.getId());
    isExitHttp(resources);
    Menu menu1 = this.getOne(new LambdaQueryWrapper<Menu>().eq(Menu::getName, resources.getName()));
    if (menu1 != null && !menu1.getId().equals(menu.getId())) {
        throw new EntityExistException(Menu.class, "name", resources.getName());
    }
    if (StringUtils.isNotBlank(resources.getComponentName())) {
        menu1 = this.getOne(new LambdaQueryWrapper<Menu>().eq(Menu::getComponentName, resources.getComponentName()));
        if (menu1 != null && !menu1.getId().equals(menu.getId())) {
            throw new EntityExistException(Menu.class, "componentName", resources.getComponentName());
        }
    }
    menu.setId(resources.getId());
    menu.setName(resources.getName());
    menu.setComponent(resources.getComponent());
    menu.setPath(resources.getPath());
    menu.setIcon(resources.getIcon());
    menu.setIFrame(resources.getIFrame());
    menu.setPid(resources.getPid());
    menu.setSort(resources.getSort());
    menu.setCache(resources.getCache());
    menu.setHidden(resources.getHidden());
    menu.setComponentName(resources.getComponentName());
    menu.setPermission(resources.getPermission());
    menu.setType(resources.getType());
    this.saveOrUpdate(menu);
}
Also used : EntityExistException(co.yixiang.exception.EntityExistException) BadRequestException(co.yixiang.exception.BadRequestException) Menu(co.yixiang.modules.system.domain.Menu) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 93 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project yshopmall by guchengwuyue.

the class SysUserServiceImpl method updateAvatar.

/**
 * 修改头像
 *
 * @param multipartFile 文件
 */
@Override
public void updateAvatar(MultipartFile multipartFile) {
    User user = this.getOne(new LambdaQueryWrapper<User>().eq(User::getUsername, SecurityUtils.getUsername()));
    UserAvatar userAvatar = userAvatarService.getOne(new LambdaQueryWrapper<UserAvatar>().eq(UserAvatar::getId, user.getAvatarId()));
    String oldPath = "";
    if (userAvatar != null) {
        oldPath = userAvatar.getPath();
    } else {
        userAvatar = new UserAvatar();
    }
    File file = FileUtil.upload(multipartFile, avatar);
    assert file != null;
    userAvatar.setRealName(file.getName());
    userAvatar.setPath(file.getPath());
    userAvatar.setSize(FileUtil.getSize(multipartFile.getSize()));
    userAvatarService.saveOrUpdate(userAvatar);
    user.setAvatarId(userAvatar.getId());
    this.saveOrUpdate(user);
    if (StringUtils.isNotBlank(oldPath)) {
        FileUtil.del(oldPath);
    }
}
Also used : UserAvatar(co.yixiang.modules.system.domain.UserAvatar) User(co.yixiang.modules.system.domain.User) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 94 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project yshopmall by guchengwuyue.

the class YxStoreProductServiceImpl method setResult.

@Override
@Transactional(rollbackFor = Exception.class)
public void setResult(Map<String, Object> map, Long id) {
    YxStoreProductAttrResult yxStoreProductAttrResult = new YxStoreProductAttrResult();
    yxStoreProductAttrResult.setProductId(id);
    yxStoreProductAttrResult.setResult(JSON.toJSONString(map));
    yxStoreProductAttrResult.setChangeTime(new Date());
    yxStoreProductAttrResultService.remove(new LambdaQueryWrapper<YxStoreProductAttrResult>().eq(YxStoreProductAttrResult::getProductId, id));
    yxStoreProductAttrResultService.saveOrUpdate(yxStoreProductAttrResult);
}
Also used : YxStoreProductAttrResult(co.yixiang.modules.shop.domain.YxStoreProductAttrResult) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Transactional(org.springframework.transaction.annotation.Transactional)

Example 95 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project yshopmall by guchengwuyue.

the class DeptController method update.

@Log("修改部门")
@ApiOperation("修改部门")
@PutMapping
@PreAuthorize("@el.check('admin','dept:edit')")
public ResponseEntity<Object> update(@Validated @RequestBody Dept resources) {
    if (resources.getId().equals(resources.getPid())) {
        throw new BadRequestException("上级不能为自己");
    }
    Dept dept = deptService.getOne(new LambdaQueryWrapper<Dept>().eq(Dept::getId, resources.getId()));
    ValidationUtil.isNull(dept.getId(), "Dept", "id", resources.getId());
    resources.setId(dept.getId());
    deptService.saveOrUpdate(resources);
    return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) Dept(co.yixiang.modules.system.domain.Dept) BadRequestException(co.yixiang.exception.BadRequestException) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Log(co.yixiang.modules.logging.aop.log.Log) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)381 Transactional (org.springframework.transaction.annotation.Transactional)60 JSONObject (com.alibaba.fastjson.JSONObject)52 Result (org.jeecg.common.api.vo.Result)50 ArrayList (java.util.ArrayList)42 List (java.util.List)30 Map (java.util.Map)29 Collectors (java.util.stream.Collectors)26 Service (org.springframework.stereotype.Service)24 LoginUser (org.jeecg.common.system.vo.LoginUser)22 SysPermission (org.jeecg.modules.system.entity.SysPermission)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)22 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)21 IPage (com.baomidou.mybatisplus.core.metadata.IPage)20 HashMap (java.util.HashMap)20 SysUser (org.jeecg.modules.system.entity.SysUser)20 ApiOperation (io.swagger.annotations.ApiOperation)19 ServiceException (cn.lili.common.exception.ServiceException)18 ServiceImpl (com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)18 Autowired (org.springframework.beans.factory.annotation.Autowired)18