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;
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations