Commit 8aeef4e0 authored by gu-jinli1118's avatar gu-jinli1118
Browse files

20230831

parent 646116b0
Pipeline #31 failed with stages
in 0 seconds
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许,不可做商业用途!
*
* 版权所有,侵权必究!
*/
package com.yami.shop.admin.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
/**
* 商城配置文件
* @author lgh
*/
@Data
@Component
@PropertySource("classpath:admin.properties")
@ConfigurationProperties(prefix = "admin")
public class AdminConfig {
/**
* 数据中心ID
*/
private Integer datacenterId;
/**
* 终端ID
*/
private Integer workerId;
}
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许,不可做商业用途!
*
* 版权所有,侵权必究!
*/
package com.yami.shop.admin.config;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Swagger文档,只有在测试环境才会使用
* @author LGH
*/
@Configuration
public class SwaggerConfiguration {
@Bean
public GroupedOpenApi baseRestApi() {
return GroupedOpenApi.builder()
.group("接口文档")
.packagesToScan("com.yami").build();
}
@Bean
public OpenAPI springShopOpenApi() {
return new OpenAPI()
.info(new Info().title("Mall4j接口文档")
.description("Mall4j接口文档,openapi3.0 接口,用于前端对接")
.version("v0.0.1")
.license(new License().name("使用请遵守AGPL3.0授权协议").url("https://www.mall4j.com")));
}
}
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许,不可做商业用途!
*
* 版权所有,侵权必究!
*/
package com.yami.shop.admin.config;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* xxl-job config
* 为啥这里的代码要注释掉,因为很奇怪的,因为很多人都不会去下载xxl-job来跑定时任务。
* 原本用spring 的 quartz做定时任务的,但是文档写着要忽略数据库大小写,结果很多人根本不看文档,所以干脆就把这个quartz的删掉,然后通过xxl-job执行定时任务
* 那么又会带来一个问题,大家也不会看文档,也不会去下载xxl-job,所以要把这里面的代码注掉,要是有人需要的话,改下这里的连接配置,连上xxl-job即可。
* 毕竟你都能找到这个文件了,下载xxl-job,修改并启动xxl-job-admin,把取消订单,确认收货之类定时任务加入到里面即可咯。还要把下面的注释掉的代码打开,这样启动项目就会连接xxl-job执行定时任务了。
* @author FrozenWatermelon
* @date 2021/1/18
*/
@Configuration
public class XxlJobConfig {
private final Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);
@Value("${xxl-job.admin.addresses}")
private String adminAddresses;
@Value("${xxl-job.accessToken}")
private String accessToken;
@Value("${xxl-job.logPath}")
private String logPath;
@Value("${server.port}")
private int port;
@Autowired
private InetUtils inetUtils;
// @Bean
// public XxlJobSpringExecutor xxlJobExecutor() {
//
// logger.info(">>>>>>>>>>> xxl-job config init.");
// XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
// xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
// xxlJobSpringExecutor.setAppname("mall4j");
// // 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP
// xxlJobSpringExecutor.setIp(inetUtils.findFirstNonLoopbackAddress().getHostAddress());
// xxlJobSpringExecutor.setPort(port + 1000);
// xxlJobSpringExecutor.setAccessToken(accessToken);
// xxlJobSpringExecutor.setLogPath(logPath);
// xxlJobSpringExecutor.setLogRetentionDays(3);
// return xxlJobSpringExecutor;
// }
}
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许,不可做商业用途!
*
* 版权所有,侵权必究!
*/
package com.yami.shop.admin.controller;
import cn.hutool.core.util.StrUtil;
import com.anji.captcha.model.common.ResponseModel;
import com.anji.captcha.model.vo.CaptchaVO;
import com.anji.captcha.service.CaptchaService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.security.admin.dto.CaptchaAuthenticationDTO;
import com.yami.shop.security.common.bo.UserInfoInTokenBO;
import com.yami.shop.security.common.enums.SysTypeEnum;
import com.yami.shop.security.common.manager.PasswordCheckManager;
import com.yami.shop.security.common.manager.PasswordManager;
import com.yami.shop.security.common.manager.TokenStore;
import com.yami.shop.security.common.vo.TokenInfoVO;
import com.yami.shop.sys.constant.Constant;
import com.yami.shop.sys.model.SysMenu;
import com.yami.shop.sys.model.SysUser;
import com.yami.shop.sys.service.SysMenuService;
import com.yami.shop.sys.service.SysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import jakarta.validation.Valid;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @author FrozenWatermelon
* @date 2020/6/30
*/
@RestController
@Tag(name = "登录")
public class AdminLoginController {
@Autowired
private TokenStore tokenStore;
@Autowired
private SysUserService sysUserService;
@Autowired
private SysMenuService sysMenuService;
@Autowired
private PasswordCheckManager passwordCheckManager;
@Autowired
private CaptchaService captchaService;
@Autowired
private PasswordManager passwordManager;
@PostMapping("/adminLogin")
@Operation(summary = "账号密码 + 验证码登录(用于后台登录)" , description = "通过账号/手机号/用户名密码登录")
public ServerResponseEntity<?> login(
@Valid @RequestBody CaptchaAuthenticationDTO captchaAuthenticationDTO) {
// 登陆后台登录需要再校验一遍验证码
CaptchaVO captchaVO = new CaptchaVO();
captchaVO.setCaptchaVerification(captchaAuthenticationDTO.getCaptchaVerification());
ResponseModel response = captchaService.verification(captchaVO);
if (!response.isSuccess()) {
return ServerResponseEntity.showFailMsg("验证码有误或已过期");
}
SysUser sysUser = sysUserService.getByUserName(captchaAuthenticationDTO.getUserName());
if (sysUser == null) {
throw new YamiShopBindException("账号或密码不正确");
}
// 半小时内密码输入错误十次,已限制登录30分钟
String decryptPassword = passwordManager.decryptPassword(captchaAuthenticationDTO.getPassWord());
passwordCheckManager.checkPassword(SysTypeEnum.ADMIN,captchaAuthenticationDTO.getUserName(), decryptPassword, sysUser.getPassword());
// 不是店铺超级管理员,并且是禁用状态,无法登录
if (Objects.equals(sysUser.getStatus(),0)) {
// 未找到此用户信息
throw new YamiShopBindException("未找到此用户信息");
}
UserInfoInTokenBO userInfoInToken = new UserInfoInTokenBO();
userInfoInToken.setUserId(String.valueOf(sysUser.getUserId()));
userInfoInToken.setSysType(SysTypeEnum.ADMIN.value());
userInfoInToken.setEnabled(sysUser.getStatus() == 1);
userInfoInToken.setPerms(getUserPermissions(sysUser.getUserId()));
userInfoInToken.setNickName(sysUser.getUsername());
userInfoInToken.setShopId(sysUser.getShopId());
// 存储token返回vo
TokenInfoVO tokenInfoVO = tokenStore.storeAndGetVo(userInfoInToken);
return ServerResponseEntity.success(tokenInfoVO);
}
private Set<String> getUserPermissions(Long userId) {
List<String> permsList;
//系统管理员,拥有最高权限
if(userId == Constant.SUPER_ADMIN_ID){
List<SysMenu> menuList = sysMenuService.list(Wrappers.emptyWrapper());
permsList = menuList.stream().map(SysMenu::getPerms).collect(Collectors.toList());
}else{
permsList = sysUserService.queryAllPerms(userId);
}
return permsList.stream().flatMap((perms)->{
if (StrUtil.isBlank(perms)) {
return null;
}
return Arrays.stream(perms.trim().split(StrUtil.COMMA));
}
).collect(Collectors.toSet());
}
}
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许,不可做商业用途!
*
* 版权所有,侵权必究!
*/
package com.yami.shop.admin.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.enums.AreaLevelEnum;
import com.yami.shop.bean.model.Area;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import java.util.List;
import java.util.Objects;
/**
* @author lgh on 2018/10/26.
*/
@RestController
@RequestMapping("/admin/area")
public class AreaController {
@Autowired
private AreaService areaService;
/**
* 分页获取
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('admin:area:page')")
public ServerResponseEntity<IPage<Area>> page(Area area,PageParam<Area> page) {
IPage<Area> sysUserPage = areaService.page(page, new LambdaQueryWrapper<Area>());
return ServerResponseEntity.success(sysUserPage);
}
/**
* 获取省市
*/
@GetMapping("/list")
@PreAuthorize("@pms.hasPermission('admin:area:list')")
public ServerResponseEntity<List<Area>> list(Area area) {
List<Area> areas = areaService.list(new LambdaQueryWrapper<Area>()
.like(area.getAreaName() != null, Area::getAreaName, area.getAreaName()));
return ServerResponseEntity.success(areas);
}
/**
* 通过父级id获取区域列表
*/
@GetMapping("/listByPid")
public ServerResponseEntity<List<Area>> listByPid(Long pid) {
List<Area> list = areaService.listByPid(pid);
return ServerResponseEntity.success(list);
}
/**
* 获取信息
*/
@GetMapping("/info/{id}")
@PreAuthorize("@pms.hasPermission('admin:area:info')")
public ServerResponseEntity<Area> info(@PathVariable("id") Long id) {
Area area = areaService.getById(id);
return ServerResponseEntity.success(area);
}
/**
* 保存
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('admin:area:save')")
public ServerResponseEntity<Void> save(@Valid @RequestBody Area area) {
if (area.getParentId() != null) {
Area parentArea = areaService.getById(area.getParentId());
area.setLevel(parentArea.getLevel() + 1);
areaService.removeAreaCacheByParentId(area.getParentId());
}
areaService.save(area);
return ServerResponseEntity.success();
}
/**
* 修改
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('admin:area:update')")
public ServerResponseEntity<Void> update(@Valid @RequestBody Area area) {
Area areaDb = areaService.getById(area.getAreaId());
// 判断当前省市区级别,如果是1级、2级则不能修改级别,不能修改成别人的下级
if(Objects.equals(areaDb.getLevel(), AreaLevelEnum.FIRST_LEVEL.value()) && !Objects.equals(area.getLevel(),AreaLevelEnum.FIRST_LEVEL.value())){
throw new YamiShopBindException("不能改变一级行政地区的级别");
}
if(Objects.equals(areaDb.getLevel(),AreaLevelEnum.SECOND_LEVEL.value()) && !Objects.equals(area.getLevel(),AreaLevelEnum.SECOND_LEVEL.value())){
throw new YamiShopBindException("不能改变二级行政地区的级别");
}
hasSameName(area);
areaService.updateById(area);
areaService.removeAreaCacheByParentId(area.getParentId());
return ServerResponseEntity.success();
}
/**
* 删除
*/
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('admin:area:delete')")
public ServerResponseEntity<Void> delete(@PathVariable Long id) {
Area area = areaService.getById(id);
areaService.removeById(id);
areaService.removeAreaCacheByParentId(area.getParentId());
return ServerResponseEntity.success();
}
private void hasSameName(Area area) {
long count = areaService.count(new LambdaQueryWrapper<Area>()
.eq(Area::getParentId, area.getParentId())
.eq(Area::getAreaName, area.getAreaName())
.ne(Objects.nonNull(area.getAreaId()) && !Objects.equals(area.getAreaId(), 0L), Area::getAreaId, area.getAreaId())
);
if (count > 0) {
throw new YamiShopBindException("该地区已存在");
}
}
}
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许,不可做商业用途!
*
* 版权所有,侵权必究!
*/
package com.yami.shop.admin.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.enums.ProdPropRule;
import com.yami.shop.bean.model.ProdProp;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.admin.util.SecurityUtils;
import com.yami.shop.service.ProdPropService;
import org.springframework.beans.factory.annotation.Autowired;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import java.util.Objects;
/**
* 参数管理
* @author lgh
*/
@RestController
@RequestMapping("/admin/attribute")
public class AttributeController {
@Autowired
private ProdPropService prodPropService;
/**
* 分页获取
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('admin:attribute:page')")
public ServerResponseEntity<IPage<ProdProp>> page(ProdProp prodProp,PageParam<ProdProp> page){
prodProp.setRule(ProdPropRule.ATTRIBUTE.value());
prodProp.setShopId(SecurityUtils.getSysUser().getShopId());
IPage<ProdProp> prodPropPage = prodPropService.pagePropAndValue(prodProp,page);
return ServerResponseEntity.success(prodPropPage);
}
/**
* 获取信息
*/
@GetMapping("/info/{id}")
@PreAuthorize("@pms.hasPermission('admin:attribute:info')")
public ServerResponseEntity<ProdProp> info(@PathVariable("id") Long id){
ProdProp prodProp = prodPropService.getById(id);
return ServerResponseEntity.success(prodProp);
}
/**
* 保存
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('admin:attribute:save')")
public ServerResponseEntity<Void> save(@Valid ProdProp prodProp){
prodProp.setRule(ProdPropRule.ATTRIBUTE.value());
prodProp.setShopId(SecurityUtils.getSysUser().getShopId());
prodPropService.saveProdPropAndValues(prodProp);
return ServerResponseEntity.success();
}
/**
* 修改
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('admin:attribute:update')")
public ServerResponseEntity<Void> update(@Valid ProdProp prodProp){
ProdProp dbProdProp = prodPropService.getById(prodProp.getPropId());
if (!Objects.equals(dbProdProp.getShopId(), SecurityUtils.getSysUser().getShopId())) {
throw new YamiShopBindException("没有权限获取该商品规格信息");
}
prodProp.setRule(ProdPropRule.ATTRIBUTE.value());
prodProp.setShopId(SecurityUtils.getSysUser().getShopId());
prodPropService.updateProdPropAndValues(prodProp);
return ServerResponseEntity.success();
}
/**
* 删除
*/
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('admin:attribute:delete')")
public ServerResponseEntity<Void> delete(@PathVariable Long id){
prodPropService.deleteProdPropAndValues(id,ProdPropRule.ATTRIBUTE.value(),SecurityUtils.getSysUser().getShopId());
return ServerResponseEntity.success();
}
}
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许,不可做商业用途!
*
* 版权所有,侵权必究!
*/
package com.yami.shop.admin.controller;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.Brand;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import java.util.Objects;
/**
* 品牌管理
*
* @author lgh
*/
@RestController
@RequestMapping("/admin/brand")
public class BrandController {
@Autowired
private BrandService brandService;
/**
* 分页获取
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('admin:brand:page')")
public ServerResponseEntity<IPage<Brand>> page(Brand brand,PageParam<Brand> page) {
IPage<Brand> brands = brandService.page(page,
new LambdaQueryWrapper<Brand>()
.like(StrUtil.isNotBlank(brand.getBrandName()), Brand::getBrandName, brand.getBrandName()).orderByAsc(Brand::getFirstChar));
return ServerResponseEntity.success(brands);
}
/**
* 获取信息
*/
@GetMapping("/info/{id}")
@PreAuthorize("@pms.hasPermission('admin:brand:info')")
public ServerResponseEntity<Brand> info(@PathVariable("id") Long id) {
Brand brand = brandService.getById(id);
return ServerResponseEntity.success(brand);
}
/**
* 保存
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('admin:brand:save')")
public ServerResponseEntity<Void> save(@Valid Brand brand) {
Brand dbBrand = brandService.getByBrandName(brand.getBrandName());
if (dbBrand != null) {
throw new YamiShopBindException("该品牌名称已存在");
}
brandService.save(brand);
return ServerResponseEntity.success();
}
/**
* 修改
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('admin:brand:update')")
public ServerResponseEntity<Void> update(@Valid Brand brand) {
Brand dbBrand = brandService.getByBrandName(brand.getBrandName());
if (dbBrand != null && !Objects.equals(dbBrand.getBrandId(), brand.getBrandId())) {
throw new YamiShopBindException("该品牌名称已存在");
}
brandService.updateById(brand);
return ServerResponseEntity.success();
}
/**
* 删除
*/
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('admin:brand:delete')")
public ServerResponseEntity<Void> delete(@PathVariable Long id) {
brandService.deleteByBrand(id);
return ServerResponseEntity.success();
}
}
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许,不可做商业用途!
*
* 版权所有,侵权必究!
*/
package com.yami.shop.admin.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yami.shop.bean.model.Category;
import com.yami.shop.common.annotation.SysLog;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.security.admin.util.SecurityUtils;
import com.yami.shop.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/**
* 分类管理
* @author lgh
*
*/
@RestController
@RequestMapping("/prod/category")
public class CategoryController {
@Autowired
private CategoryService categoryService;
/**
* 获取菜单页面的表
* @return
*/
@GetMapping("/table")
@PreAuthorize("@pms.hasPermission('prod:category:page')")
public ServerResponseEntity<List<Category>> table(){
List<Category> categoryMenuList = categoryService.tableCategory(SecurityUtils.getSysUser().getShopId());
return ServerResponseEntity.success(categoryMenuList);
}
/**
* 获取分类信息
*/
@GetMapping("/info/{categoryId}")
public ServerResponseEntity<Category> info(@PathVariable("categoryId") Long categoryId){
Category category = categoryService.getById(categoryId);
return ServerResponseEntity.success(category);
}
/**
* 保存分类
*/
@SysLog("保存分类")
@PostMapping
@PreAuthorize("@pms.hasPermission('prod:category:save')")
public ServerResponseEntity<Void> save(@RequestBody Category category){
category.setShopId(SecurityUtils.getSysUser().getShopId());
category.setRecTime(new Date());
Category categoryName = categoryService.getOne(new LambdaQueryWrapper<Category>().eq(Category::getCategoryName,category.getCategoryName())
.eq(Category::getShopId,category.getShopId()));
if(categoryName != null){
throw new YamiShopBindException("类目名称已存在!");
}
categoryService.saveCategory(category);
return ServerResponseEntity.success();
}
/**
* 更新分类
*/
@SysLog("更新分类")
@PutMapping
@PreAuthorize("@pms.hasPermission('prod:category:update')")
public ServerResponseEntity<String> update(@RequestBody Category category){
category.setShopId(SecurityUtils.getSysUser().getShopId());
if (Objects.equals(category.getParentId(),category.getCategoryId())) {
return ServerResponseEntity.showFailMsg("分类的上级不能是自己本身");
}
Category categoryName = categoryService.getOne(new LambdaQueryWrapper<Category>().eq(Category::getCategoryName,category.getCategoryName())
.eq(Category::getShopId,category.getShopId()).ne(Category::getCategoryId,category.getCategoryId()));
if(categoryName != null){
throw new YamiShopBindException("类目名称已存在!");
}
Category categoryDb = categoryService.getById(category.getCategoryId());
// 如果从下线改成正常,则需要判断上级的状态
if (Objects.equals(categoryDb.getStatus(),0) && Objects.equals(category.getStatus(),1) && !Objects.equals(category.getParentId(),0L)){
Category parentCategory = categoryService.getOne(new LambdaQueryWrapper<Category>().eq(Category::getCategoryId, category.getParentId()));
if(Objects.isNull(parentCategory) || Objects.equals(parentCategory.getStatus(),0)){
// 修改失败,上级分类不存在或者不为正常状态
throw new YamiShopBindException("修改失败,上级分类不存在或者不为正常状态");
}
}
categoryService.updateCategory(category);
return ServerResponseEntity.success();
}
/**
* 删除分类
*/
@SysLog("删除分类")
@DeleteMapping("/{categoryId}")
@PreAuthorize("@pms.hasPermission('prod:category:delete')")
public ServerResponseEntity<String> delete(@PathVariable("categoryId") Long categoryId){
if (categoryService.count(new LambdaQueryWrapper<Category>().eq(Category::getParentId,categoryId)) >0) {
return ServerResponseEntity.showFailMsg("请删除子分类,再删除该分类");
}
categoryService.deleteCategory(categoryId);
return ServerResponseEntity.success();
}
/**
* 所有的
*/
@GetMapping("/listCategory")
public ServerResponseEntity<List<Category>> listCategory(){
return ServerResponseEntity.success(categoryService.list(new LambdaQueryWrapper<Category>()
.le(Category::getGrade, 2)
.eq(Category::getShopId, SecurityUtils.getSysUser().getShopId())
.orderByAsc(Category::getSeq)));
}
/**
* 所有的产品分类
*/
@GetMapping("/listProdCategory")
public ServerResponseEntity<List<Category>> listProdCategory(){
List<Category> categories = categoryService.treeSelect(SecurityUtils.getSysUser().getShopId(),2);
return ServerResponseEntity.success(categories);
}
}
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许,不可做商业用途!
*
* 版权所有,侵权必究!
*/
package com.yami.shop.admin.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yami.shop.bean.model.Delivery;
import com.yami.shop.service.DeliveryService;
/**
*
* @author lgh on 2018/11/26.
*/
@RestController
@RequestMapping("/admin/delivery")
public class DeliveryController {
@Autowired
private DeliveryService deliveryService;
/**
* 分页获取
*/
@GetMapping("/list")
public ServerResponseEntity<List<Delivery>> page(){
List<Delivery> list = deliveryService.list();
return ServerResponseEntity.success(list);
}
}
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许,不可做商业用途!
*
* 版权所有,侵权必究!
*/
package com.yami.shop.admin.controller;
import com.yami.shop.common.bean.Qiniu;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.ImgUploadUtil;
import com.yami.shop.service.AttachFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.Objects;
/**
* 文件上传 controller
* @author lgh
*
*/
@RestController
@RequestMapping("/admin/file")
public class FileController {
@Autowired
private AttachFileService attachFileService;
@Autowired
private Qiniu qiniu;
@Autowired
private ImgUploadUtil imgUploadUtil;
@PostMapping("/upload/element")
public ServerResponseEntity<String> uploadElementFile(@RequestParam("file") MultipartFile file) throws IOException{
if(file.isEmpty()){
return ServerResponseEntity.success();
}
String fileName = attachFileService.uploadFile(file);
return ServerResponseEntity.success(fileName);
}
@PostMapping("/upload/tinymceEditor")
public ServerResponseEntity<String> uploadTinymceEditorImages(@RequestParam("editorFile") MultipartFile editorFile) throws IOException{
String fileName = attachFileService.uploadFile(editorFile);
String data = "";
if (Objects.equals(imgUploadUtil.getUploadType(), 1)) {
data = imgUploadUtil.getUploadPath() + fileName;
} else if (Objects.equals(imgUploadUtil.getUploadType(), 2)) {
data = qiniu.getResourcesUrl() + fileName;
}
return ServerResponseEntity.success(data);
}
}
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许,不可做商业用途!
*
* 版权所有,侵权必究!
*/
package com.yami.shop.admin.controller;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.HotSearch;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.admin.util.SecurityUtils;
import com.yami.shop.service.HotSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import java.util.Date;
import java.util.List;
/**
*
* @author lgh on 2019/03/27.
*/
@RestController
@RequestMapping("/admin/hotSearch")
public class HotSearchController {
@Autowired
private HotSearchService hotSearchService;
/**
* 分页获取
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('admin:hotSearch:page')")
public ServerResponseEntity<IPage<HotSearch>> page(HotSearch hotSearch,PageParam<HotSearch> page){
IPage<HotSearch> hotSearchs = hotSearchService.page(page,new LambdaQueryWrapper<HotSearch>()
.eq(HotSearch::getShopId, SecurityUtils.getSysUser().getShopId())
.like(StrUtil.isNotBlank(hotSearch.getContent()), HotSearch::getContent,hotSearch.getContent())
.like(StrUtil.isNotBlank(hotSearch.getTitle()), HotSearch::getTitle,hotSearch.getTitle())
.eq(hotSearch.getStatus()!=null, HotSearch::getStatus,hotSearch.getStatus())
.orderByAsc(HotSearch::getSeq)
);
return ServerResponseEntity.success(hotSearchs);
}
/**
* 获取信息
*/
@GetMapping("/info/{id}")
public ServerResponseEntity<HotSearch> info(@PathVariable("id") Long id){
HotSearch hotSearch = hotSearchService.getById(id);
return ServerResponseEntity.success(hotSearch);
}
/**
* 保存
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('admin:hotSearch:save')")
public ServerResponseEntity<Void> save(@RequestBody @Valid HotSearch hotSearch){
hotSearch.setRecDate(new Date());
hotSearch.setShopId(SecurityUtils.getSysUser().getShopId());
hotSearchService.save(hotSearch);
//清除缓存
hotSearchService.removeHotSearchDtoCacheByShopId(SecurityUtils.getSysUser().getShopId());
return ServerResponseEntity.success();
}
/**
* 修改
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('admin:hotSearch:update')")
public ServerResponseEntity<Void> update(@RequestBody @Valid HotSearch hotSearch){
hotSearchService.updateById(hotSearch);
//清除缓存
hotSearchService.removeHotSearchDtoCacheByShopId(SecurityUtils.getSysUser().getShopId());
return ServerResponseEntity.success();
}
/**
* 删除
*/
@DeleteMapping
@PreAuthorize("@pms.hasPermission('admin:hotSearch:delete')")
public ServerResponseEntity<Void> delete(@RequestBody List<Long> ids){
hotSearchService.removeByIds(ids);
//清除缓存
hotSearchService.removeHotSearchDtoCacheByShopId(SecurityUtils.getSysUser().getShopId());
return ServerResponseEntity.success();
}
}
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许,不可做商业用途!
*
* 版权所有,侵权必究!
*/
package com.yami.shop.admin.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.IndexImg;
import com.yami.shop.bean.model.Product;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.admin.util.SecurityUtils;
import com.yami.shop.service.IndexImgService;
import com.yami.shop.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import java.util.Date;
import java.util.Objects;
/**
* @author lgh on 2018/11/26.
*/
@RestController
@RequestMapping("/admin/indexImg")
public class IndexImgController {
@Autowired
private IndexImgService indexImgService;
@Autowired
private ProductService productService;
/**
* 分页获取
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('admin:indexImg:page')")
public ServerResponseEntity<IPage<IndexImg>> page(IndexImg indexImg, PageParam<IndexImg> page) {
IPage<IndexImg> indexImgPage = indexImgService.page(page,
new LambdaQueryWrapper<IndexImg>()
.eq(indexImg.getStatus() != null, IndexImg::getStatus, indexImg.getStatus())
.orderByAsc(IndexImg::getSeq));
return ServerResponseEntity.success(indexImgPage);
}
/**
* 获取信息
*/
@GetMapping("/info/{imgId}")
@PreAuthorize("@pms.hasPermission('admin:indexImg:info')")
public ServerResponseEntity<IndexImg> info(@PathVariable("imgId") Long imgId) {
Long shopId = SecurityUtils.getSysUser().getShopId();
IndexImg indexImg = indexImgService.getOne(new LambdaQueryWrapper<IndexImg>().eq(IndexImg::getShopId, shopId).eq(IndexImg::getImgId, imgId));
if (Objects.nonNull(indexImg.getRelation())) {
Product product = productService.getProductByProdId(indexImg.getRelation());
indexImg.setPic(product.getPic());
indexImg.setProdName(product.getProdName());
}
return ServerResponseEntity.success(indexImg);
}
/**
* 保存
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('admin:indexImg:save')")
public ServerResponseEntity<Void> save(@RequestBody @Valid IndexImg indexImg) {
Long shopId = SecurityUtils.getSysUser().getShopId();
indexImg.setShopId(shopId);
indexImg.setUploadTime(new Date());
checkProdStatus(indexImg);
indexImgService.save(indexImg);
indexImgService.removeIndexImgCache();
return ServerResponseEntity.success();
}
/**
* 修改
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('admin:indexImg:update')")
public ServerResponseEntity<Void> update(@RequestBody @Valid IndexImg indexImg) {
checkProdStatus(indexImg);
indexImgService.saveOrUpdate(indexImg);
indexImgService.removeIndexImgCache();
return ServerResponseEntity.success();
}
/**
* 删除
*/
@DeleteMapping
@PreAuthorize("@pms.hasPermission('admin:indexImg:delete')")
public ServerResponseEntity<Void> delete(@RequestBody Long[] ids) {
indexImgService.deleteIndexImgByIds(ids);
indexImgService.removeIndexImgCache();
return ServerResponseEntity.success();
}
private void checkProdStatus(IndexImg indexImg) {
if (!Objects.equals(indexImg.getType(), 0)) {
return;
}
if (Objects.isNull(indexImg.getRelation())) {
throw new YamiShopBindException("请选择商品");
}
Product product = productService.getById(indexImg.getRelation());
if (Objects.isNull(product)) {
throw new YamiShopBindException("商品信息不存在");
}
if (!Objects.equals(product.getStatus(), 1)) {
throw new YamiShopBindException("该商品未上架,请选择别的商品");
}
}
}
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许,不可做商业用途!
*
* 版权所有,侵权必究!
*/
package com.yami.shop.admin.controller;
import java.util.Arrays;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yami.shop.common.util.PageParam;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.enums.MessageStatus;
import com.yami.shop.bean.model.Message;
import com.yami.shop.service.MessageService;
import cn.hutool.core.util.StrUtil;
/**
* @author lgh on 2018/10/15.
*/
@RestController
@RequestMapping("/admin/message")
public class MessageController {
@Autowired
private MessageService messageService;
/**
* 分页获取
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('admin:message:page')")
public ServerResponseEntity<IPage<Message>> page(Message message,PageParam<Message> page) {
IPage<Message> messages = messageService.page(page, new LambdaQueryWrapper<Message>()
.like(StrUtil.isNotBlank(message.getUserName()), Message::getUserName, message.getUserName())
.eq(message.getStatus() != null, Message::getStatus, message.getStatus()));
return ServerResponseEntity.success(messages);
}
/**
* 获取信息
*/
@GetMapping("/info/{id}")
@PreAuthorize("@pms.hasPermission('admin:message:info')")
public ServerResponseEntity<Message> info(@PathVariable("id") Long id) {
Message message = messageService.getById(id);
return ServerResponseEntity.success(message);
}
/**
* 保存
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('admin:message:save')")
public ServerResponseEntity<Void> save(@RequestBody Message message) {
messageService.save(message);
return ServerResponseEntity.success();
}
/**
* 修改
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('admin:message:update')")
public ServerResponseEntity<Void> update(@RequestBody Message message) {
messageService.updateById(message);
return ServerResponseEntity.success();
}
/**
* 公开留言
*/
@PutMapping("/release/{id}")
@PreAuthorize("@pms.hasPermission('admin:message:release')")
public ServerResponseEntity<Void> release(@PathVariable("id") Long id) {
Message message = new Message();
message.setId(id);
message.setStatus(MessageStatus.RELEASE.value());
messageService.updateById(message);
return ServerResponseEntity.success();
}
/**
* 取消公开留言
*/
@PutMapping("/cancel/{id}")
@PreAuthorize("@pms.hasPermission('admin:message:cancel')")
public ServerResponseEntity<Void> cancel(@PathVariable("id") Long id) {
Message message = new Message();
message.setId(id);
message.setStatus(MessageStatus.CANCEL.value());
messageService.updateById(message);
return ServerResponseEntity.success();
}
/**
* 删除
*/
@DeleteMapping("/{ids}")
@PreAuthorize("@pms.hasPermission('admin:message:delete')")
public ServerResponseEntity<Void> delete(@PathVariable Long[] ids) {
messageService.removeByIds(Arrays.asList(ids));
return ServerResponseEntity.success();
}
}
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许,不可做商业用途!
*
* 版权所有,侵权必究!
*/
package com.yami.shop.admin.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.Notice;
import com.yami.shop.common.annotation.SysLog;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.admin.util.SecurityUtils;
import com.yami.shop.service.NoticeService;
import lombok.AllArgsConstructor;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import java.util.Date;
/**
* 公告管理
*
* @author hzm
* @date
*/
@RestController
@AllArgsConstructor
@RequestMapping("/shop/notice")
public class NoticeController {
private final NoticeService noticeService;
/**
* 分页查询
*
* @param page 分页对象
* @param notice 公告管理
* @return 分页数据
*/
@GetMapping("/page")
public ServerResponseEntity<IPage<Notice>> getNoticePage(PageParam<Notice> page, Notice notice) {
IPage<Notice> noticePage = noticeService.page(page, new LambdaQueryWrapper<Notice>()
.eq(notice.getStatus() != null, Notice::getStatus, notice.getStatus())
.eq(notice.getIsTop()!=null,Notice::getIsTop,notice.getIsTop())
.like(notice.getTitle() != null, Notice::getTitle, notice.getTitle()).orderByDesc(Notice::getUpdateTime));
return ServerResponseEntity.success(noticePage);
}
/**
* 通过id查询公告管理
*
* @param id id
* @return 单个数据
*/
@GetMapping("/info/{id}")
public ServerResponseEntity<Notice> getById(@PathVariable("id") Long id) {
return ServerResponseEntity.success(noticeService.getById(id));
}
/**
* 新增公告管理
*
* @param notice 公告管理
* @return 是否新增成功
*/
@SysLog("新增公告管理")
@PostMapping
@PreAuthorize("@pms.hasPermission('shop:notice:save')")
public ServerResponseEntity<Boolean> save(@RequestBody @Valid Notice notice) {
notice.setShopId(SecurityUtils.getSysUser().getShopId());
if (notice.getStatus() == 1) {
notice.setPublishTime(new Date());
}
notice.setUpdateTime(new Date());
noticeService.removeNoticeList();
return ServerResponseEntity.success(noticeService.save(notice));
}
/**
* 修改公告管理
*
* @param notice 公告管理
* @return 是否修改成功
*/
@SysLog("修改公告管理")
@PutMapping
@PreAuthorize("@pms.hasPermission('shop:notice:update')")
public ServerResponseEntity<Boolean> updateById(@RequestBody @Valid Notice notice) {
Notice oldNotice = noticeService.getById(notice.getId());
if (oldNotice.getStatus() == 0 && notice.getStatus() == 1) {
notice.setPublishTime(new Date());
}
notice.setUpdateTime(new Date());
noticeService.removeNoticeList();
noticeService.removeNoticeById(notice.getId());
return ServerResponseEntity.success(noticeService.updateById(notice));
}
/**
* 通过id删除公告管理
*
* @param id id
* @return 是否删除成功
*/
@SysLog("删除公告管理")
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('shop:notice:delete')")
public ServerResponseEntity<Boolean> removeById(@PathVariable Long id) {
noticeService.removeNoticeList();
noticeService.removeNoticeById(id);
return ServerResponseEntity.success(noticeService.removeById(id));
}
}
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许,不可做商业用途!
*
* 版权所有,侵权必究!
*/
package com.yami.shop.admin.controller;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.IoUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.base.Objects;
import com.yami.shop.bean.enums.OrderStatus;
import com.yami.shop.bean.model.Order;
import com.yami.shop.bean.model.OrderItem;
import com.yami.shop.bean.model.UserAddrOrder;
import com.yami.shop.bean.param.DeliveryOrderParam;
import com.yami.shop.bean.param.OrderParam;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.admin.util.SecurityUtils;
import com.yami.shop.service.*;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Sheet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
* @author lgh on 2018/09/15.
*/
@Slf4j
@RestController
@RequestMapping("/order/order")
public class OrderController {
@Autowired
private OrderService orderService;
@Autowired
private OrderItemService orderItemService;
@Autowired
private UserAddrOrderService userAddrOrderService;
@Autowired
private ProductService productService;
@Autowired
private SkuService skuService;
/**
* 分页获取
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('order:order:page')")
public ServerResponseEntity<IPage<Order>> page(OrderParam orderParam,PageParam<Order> page) {
Long shopId = SecurityUtils.getSysUser().getShopId();
orderParam.setShopId(shopId);
IPage<Order> orderPage = orderService.pageOrdersDetailByOrderParam(page, orderParam);
return ServerResponseEntity.success(orderPage);
}
/**
* 获取信息
*/
@GetMapping("/orderInfo/{orderNumber}")
@PreAuthorize("@pms.hasPermission('order:order:info')")
public ServerResponseEntity<Order> info(@PathVariable("orderNumber") String orderNumber) {
Long shopId = SecurityUtils.getSysUser().getShopId();
Order order = orderService.getOrderByOrderNumber(orderNumber);
if (!Objects.equal(shopId, order.getShopId())) {
throw new YamiShopBindException("您没有权限获取该订单信息");
}
List<OrderItem> orderItems = orderItemService.getOrderItemsByOrderNumber(orderNumber);
order.setOrderItems(orderItems);
UserAddrOrder userAddrOrder = userAddrOrderService.getById(order.getAddrOrderId());
order.setUserAddrOrder(userAddrOrder);
return ServerResponseEntity.success(order);
}
/**
* 发货
*/
@PutMapping("/delivery")
@PreAuthorize("@pms.hasPermission('order:order:delivery')")
public ServerResponseEntity<Void> delivery(@RequestBody DeliveryOrderParam deliveryOrderParam) {
Long shopId = SecurityUtils.getSysUser().getShopId();
Order order = orderService.getOrderByOrderNumber(deliveryOrderParam.getOrderNumber());
if (!Objects.equal(shopId, order.getShopId())) {
throw new YamiShopBindException("您没有权限修改该订单信息");
}
Order orderParam = new Order();
orderParam.setOrderId(order.getOrderId());
orderParam.setDvyId(deliveryOrderParam.getDvyId());
orderParam.setDvyFlowId(deliveryOrderParam.getDvyFlowId());
orderParam.setDvyTime(new Date());
orderParam.setStatus(OrderStatus.CONSIGNMENT.value());
orderParam.setUserId(order.getUserId());
orderService.delivery(orderParam);
List<OrderItem> orderItems = orderItemService.getOrderItemsByOrderNumber(deliveryOrderParam.getOrderNumber());
for (OrderItem orderItem : orderItems) {
productService.removeProductCacheByProdId(orderItem.getProdId());
skuService.removeSkuCacheBySkuId(orderItem.getSkuId(),orderItem.getProdId());
}
return ServerResponseEntity.success();
}
/**
* 打印待发货的订单表
*
* @param order
* @param consignmentName 发件人姓名
* @param consignmentMobile 发货人手机号
* @param consignmentAddr 发货地址
*/
@GetMapping("/waitingConsignmentExcel")
@PreAuthorize("@pms.hasPermission('order:order:waitingConsignmentExcel')")
public void waitingConsignmentExcel(Order order, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime, String consignmentName, String consignmentMobile,
String consignmentAddr, HttpServletResponse response) {
Long shopId = SecurityUtils.getSysUser().getShopId();
order.setShopId(shopId);
order.setStatus(OrderStatus.PADYED.value());
List<Order> orders = orderService.listOrdersDetailByOrder(order, startTime, endTime);
//通过工具类创建writer
ExcelWriter writer = ExcelUtil.getBigWriter();
Sheet sheet = writer.getSheet();
sheet.setColumnWidth(0, 20 * 256);
sheet.setColumnWidth(1, 20 * 256);
sheet.setColumnWidth(2, 20 * 256);
sheet.setColumnWidth(3, 60 * 256);
sheet.setColumnWidth(4, 60 * 256);
sheet.setColumnWidth(7, 60 * 256);
sheet.setColumnWidth(8, 60 * 256);
sheet.setColumnWidth(9, 60 * 256);
// 待发货
String[] hearder = {"订单编号", "收件人", "手机", "收货地址", "商品名称", "数量", "发件人姓名", "发件人手机号", "发货地址", "备注"};
writer.merge(hearder.length - 1, "发货信息整理");
writer.writeRow(Arrays.asList(hearder));
int row = 1;
for (Order dbOrder : orders) {
UserAddrOrder addr = dbOrder.getUserAddrOrder();
String addrInfo = addr.getProvince() + addr.getCity() + addr.getArea() + addr.getAddr();
List<OrderItem> orderItems = dbOrder.getOrderItems();
row++;
for (OrderItem orderItem : orderItems) {
// 第0列开始
int col = 0;
writer.writeCellValue(col++, row, dbOrder.getOrderNumber());
writer.writeCellValue(col++, row, addr.getReceiver());
writer.writeCellValue(col++, row, addr.getMobile());
writer.writeCellValue(col++, row, addrInfo);
writer.writeCellValue(col++, row, orderItem.getProdName());
writer.writeCellValue(col++, row, orderItem.getProdCount());
writer.writeCellValue(col++, row, consignmentName);
writer.writeCellValue(col++, row, consignmentMobile);
writer.writeCellValue(col++, row, consignmentAddr);
writer.writeCellValue(col++, row, dbOrder.getRemarks());
}
}
writeExcel(response, writer);
}
/**
* 已销售订单
*
* @param order
*/
@GetMapping("/soldExcel")
@PreAuthorize("@pms.hasPermission('order:order:soldExcel')")
public void soldExcel(Order order, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime, HttpServletResponse response) {
Long shopId = SecurityUtils.getSysUser().getShopId();
order.setShopId(shopId);
order.setIsPayed(1);
List<Order> orders = orderService.listOrdersDetailByOrder(order, startTime, endTime);
//通过工具类创建writer
ExcelWriter writer = ExcelUtil.getBigWriter();
// 待发货
String[] hearder = {"订单编号", "下单时间", "收件人", "手机", "收货地址", "商品名称", "数量", "订单应付", "订单运费", "订单实付"};
Sheet sheet = writer.getSheet();
sheet.setColumnWidth(0, 20 * 256);
sheet.setColumnWidth(1, 20 * 256);
sheet.setColumnWidth(3, 20 * 256);
sheet.setColumnWidth(4, 60 * 256);
sheet.setColumnWidth(5, 60 * 256);
writer.merge(hearder.length - 1, "销售信息整理");
writer.writeRow(Arrays.asList(hearder));
int row = 1;
for (Order dbOrder : orders) {
UserAddrOrder addr = dbOrder.getUserAddrOrder();
String addrInfo = addr.getProvince() + addr.getCity() + addr.getArea() + addr.getAddr();
List<OrderItem> orderItems = dbOrder.getOrderItems();
int firstRow = row + 1;
int lastRow = row + orderItems.size();
int col = -1;
// 订单编号
mergeIfNeed(writer, firstRow, lastRow, ++col, col, dbOrder.getOrderNumber());
// 下单时间
mergeIfNeed(writer, firstRow, lastRow, ++col, col, dbOrder.getCreateTime());
// 收件人
mergeIfNeed(writer, firstRow, lastRow, ++col, col, addr.getReceiver());
// "手机"
mergeIfNeed(writer, firstRow, lastRow, ++col, col, addr.getMobile());
// "收货地址"
mergeIfNeed(writer, firstRow, lastRow, ++col, col, addrInfo);
int prodNameCol = ++col;
int prodCountCol = ++col;
for (OrderItem orderItem : orderItems) {
row++;
// 商品名称
writer.writeCellValue(prodNameCol, row, orderItem.getProdName());
// 数量
writer.writeCellValue(prodCountCol, row, orderItem.getProdCount());
}
// 订单应付
mergeIfNeed(writer, firstRow, lastRow, ++col, col, dbOrder.getTotal());
// 订单运费
mergeIfNeed(writer, firstRow, lastRow, ++col, col, dbOrder.getFreightAmount());
// 订单实付
mergeIfNeed(writer, firstRow, lastRow, ++col, col, dbOrder.getActualTotal());
}
writeExcel(response, writer);
}
/**
* 如果需要合并的话,就合并
*/
private void mergeIfNeed(ExcelWriter writer, int firstRow, int lastRow, int firstColumn, int lastColumn, Object content) {
if (content instanceof Date) {
content = DateUtil.format((Date) content, DatePattern.NORM_DATETIME_PATTERN);
}
if (lastRow - firstRow > 0 || lastColumn - firstColumn > 0) {
writer.merge(firstRow, lastRow, firstColumn, lastColumn, content, false);
} else {
writer.writeCellValue(firstColumn, firstRow, content);
}
}
private void writeExcel(HttpServletResponse response, ExcelWriter writer) {
//response为HttpServletResponse对象
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
//test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
response.setHeader("Content-Disposition", "attachment;filename=1.xls");
ServletOutputStream servletOutputStream = null;
try {
servletOutputStream = response.getOutputStream();
writer.flush(servletOutputStream);
servletOutputStream.flush();
} catch (IORuntimeException | IOException e) {
log.error("写出Excel错误:", e);
} finally {
IoUtil.close(writer);
}
}
}
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许,不可做商业用途!
*
* 版权所有,侵权必究!
*/
package com.yami.shop.admin.controller;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.PickAddr;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.response.ResponseEnum;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.admin.util.SecurityUtils;
import com.yami.shop.service.PickAddrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import java.util.Arrays;
import java.util.Objects;
/**
*
* @author lgh on 2018/10/17.
*/
@RestController
@RequestMapping("/shop/pickAddr")
public class PickAddrController {
@Autowired
private PickAddrService pickAddrService;
/**
* 分页获取
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('shop:pickAddr:page')")
public ServerResponseEntity<IPage<PickAddr>> page(PickAddr pickAddr,PageParam<PickAddr> page){
IPage<PickAddr> pickAddrs = pickAddrService.page(page,new LambdaQueryWrapper<PickAddr>()
.like(StrUtil.isNotBlank(pickAddr.getAddrName()),PickAddr::getAddrName,pickAddr.getAddrName())
.orderByDesc(PickAddr::getAddrId));
return ServerResponseEntity.success(pickAddrs);
}
/**
* 获取信息
*/
@GetMapping("/info/{id}")
@PreAuthorize("@pms.hasPermission('shop:pickAddr:info')")
public ServerResponseEntity<PickAddr> info(@PathVariable("id") Long id){
PickAddr pickAddr = pickAddrService.getById(id);
return ServerResponseEntity.success(pickAddr);
}
/**
* 保存
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('shop:pickAddr:save')")
public ServerResponseEntity<Void> save(@Valid @RequestBody PickAddr pickAddr){
pickAddr.setShopId(SecurityUtils.getSysUser().getShopId());
pickAddrService.save(pickAddr);
return ServerResponseEntity.success();
}
/**
* 修改
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('shop:pickAddr:update')")
public ServerResponseEntity<Void> update(@Valid @RequestBody PickAddr pickAddr){
PickAddr dbPickAddr = pickAddrService.getById(pickAddr.getAddrId());
if (!Objects.equals(dbPickAddr.getShopId(),SecurityUtils.getSysUser().getShopId())) {
throw new YamiShopBindException(ResponseEnum.UNAUTHORIZED);
}
pickAddrService.updateById(pickAddr);
return ServerResponseEntity.success();
}
/**
* 删除
*/
@DeleteMapping
@PreAuthorize("@pms.hasPermission('shop:pickAddr:delete')")
public ServerResponseEntity<Void> delete(@RequestBody Long[] ids){
pickAddrService.removeByIds(Arrays.asList(ids));
return ServerResponseEntity.success();
}
}
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许,不可做商业用途!
*
* 版权所有,侵权必究!
*/
package com.yami.shop.admin.controller;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yami.shop.bean.model.ProdComm;
import com.yami.shop.common.annotation.SysLog;
import com.yami.shop.common.util.Json;
import com.yami.shop.service.ProdCommService;
import lombok.AllArgsConstructor;
import jakarta.validation.Valid;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yami.shop.common.util.PageParam;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.Date;
/**
* 商品评论
*
* @author xwc
* @date 2019-04-19 10:43:57
*/
@RestController
@AllArgsConstructor
@RequestMapping("/prod/prodComm" )
public class ProdCommController {
private final ProdCommService prodCommService;
/**
* 分页查询
* @param page 分页对象
* @param prodComm 商品评论
* @return 分页数据
*/
@GetMapping("/page" )
@PreAuthorize("@pms.hasPermission('prod:prodComm:page')" )
public ServerResponseEntity<IPage<ProdComm>> getProdCommPage(PageParam page, ProdComm prodComm) {
return ServerResponseEntity.success(prodCommService.getProdCommPage(page,prodComm));
}
/**
* 通过id查询商品评论
* @param prodCommId id
* @return 单个数据
*/
@GetMapping("/info/{prodCommId}" )
@PreAuthorize("@pms.hasPermission('prod:prodComm:info')" )
public ServerResponseEntity<ProdComm> getById(@PathVariable("prodCommId" ) Long prodCommId) {
return ServerResponseEntity.success(prodCommService.getById(prodCommId));
}
/**
* 新增商品评论
* @param prodComm 商品评论
* @return 是否新增成功
*/
@SysLog("新增商品评论" )
@PostMapping
@PreAuthorize("@pms.hasPermission('prod:prodComm:save')" )
public ServerResponseEntity<Boolean> save(@RequestBody @Valid ProdComm prodComm) {
return ServerResponseEntity.success(prodCommService.save(prodComm));
}
/**
* 修改商品评论
* @param prodComm 商品评论
* @return 是否修改成功
*/
@SysLog("修改商品评论" )
@PutMapping
@PreAuthorize("@pms.hasPermission('prod:prodComm:update')" )
public ServerResponseEntity<Boolean> updateById(@RequestBody @Valid ProdComm prodComm) {
prodComm.setReplyTime(new Date());
return ServerResponseEntity.success(prodCommService.updateById(prodComm));
}
/**
* 通过id删除商品评论
* @param prodCommId id
* @return 是否删除成功
*/
@SysLog("删除商品评论" )
@DeleteMapping("/{prodCommId}" )
@PreAuthorize("@pms.hasPermission('prod:prodComm:delete')" )
public ServerResponseEntity<Boolean> removeById(@PathVariable Long prodCommId) {
return ServerResponseEntity.success(prodCommService.removeById(prodCommId));
}
}
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许,不可做商业用途!
*
* 版权所有,侵权必究!
*/
package com.yami.shop.admin.controller;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.ProdTag;
import com.yami.shop.common.annotation.SysLog;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.admin.util.SecurityUtils;
import com.yami.shop.service.ProdTagService;
import org.springframework.beans.factory.annotation.Autowired;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import java.util.Date;
import java.util.List;
/**
* 商品分组
*
* @author hzm
* @date 2019-04-18 09:08:36
*/
@RestController
@RequestMapping("/prod/prodTag")
public class ProdTagController {
@Autowired
private ProdTagService prodTagService;
/**
* 分页查询
*
* @param page 分页对象
* @param prodTag 商品分组标签
* @return 分页数据
*/
@GetMapping("/page")
public ServerResponseEntity<IPage<ProdTag>> getProdTagPage(PageParam<ProdTag> page, ProdTag prodTag) {
IPage<ProdTag> tagPage = prodTagService.page(
page, new LambdaQueryWrapper<ProdTag>()
.eq(prodTag.getStatus() != null, ProdTag::getStatus, prodTag.getStatus())
.like(prodTag.getTitle() != null, ProdTag::getTitle, prodTag.getTitle())
.orderByDesc(ProdTag::getSeq, ProdTag::getCreateTime));
return ServerResponseEntity.success(tagPage);
}
/**
* 通过id查询商品分组标签
*
* @param id id
* @return 单个数据
*/
@GetMapping("/info/{id}")
public ServerResponseEntity<ProdTag> getById(@PathVariable("id") Long id) {
return ServerResponseEntity.success(prodTagService.getById(id));
}
/**
* 新增商品分组标签
*
* @param prodTag 商品分组标签
* @return 是否新增成功
*/
@SysLog("新增商品分组标签")
@PostMapping
@PreAuthorize("@pms.hasPermission('prod:prodTag:save')")
public ServerResponseEntity<Boolean> save(@RequestBody @Valid ProdTag prodTag) {
// 查看是否相同的标签
List<ProdTag> list = prodTagService.list(new LambdaQueryWrapper<ProdTag>().like(ProdTag::getTitle, prodTag.getTitle()));
if (CollectionUtil.isNotEmpty(list)) {
throw new YamiShopBindException("标签名称已存在,不能添加相同的标签");
}
prodTag.setIsDefault(0);
prodTag.setProdCount(0L);
prodTag.setCreateTime(new Date());
prodTag.setUpdateTime(new Date());
prodTag.setShopId(SecurityUtils.getSysUser().getShopId());
prodTagService.removeProdTag();
return ServerResponseEntity.success(prodTagService.save(prodTag));
}
/**
* 修改商品分组标签
*
* @param prodTag 商品分组标签
* @return 是否修改成功
*/
@SysLog("修改商品分组标签")
@PutMapping
@PreAuthorize("@pms.hasPermission('prod:prodTag:update')")
public ServerResponseEntity<Boolean> updateById(@RequestBody @Valid ProdTag prodTag) {
prodTag.setUpdateTime(new Date());
prodTagService.removeProdTag();
return ServerResponseEntity.success(prodTagService.updateById(prodTag));
}
/**
* 通过id删除商品分组标签
*
* @param id id
* @return 是否删除成功
*/
@SysLog("删除商品分组标签")
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('prod:prodTag:delete')")
public ServerResponseEntity<Boolean> removeById(@PathVariable Long id) {
ProdTag prodTag = prodTagService.getById(id);
if (prodTag.getIsDefault() != 0) {
throw new YamiShopBindException("默认标签不能删除");
}
prodTagService.removeProdTag();
return ServerResponseEntity.success(prodTagService.removeById(id));
}
@GetMapping("/listTagList")
public ServerResponseEntity<List<ProdTag>> listTagList() {
return ServerResponseEntity.success(prodTagService.listProdTag());
}
}
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许,不可做商业用途!
*
* 版权所有,侵权必究!
*/
package com.yami.shop.admin.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.bean.model.ProdTagReference;
import com.yami.shop.common.annotation.SysLog;
import com.yami.shop.service.ProdTagReferenceService;
import lombok.AllArgsConstructor;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
/**
* 分组标签引用
*
* @author hzm
* @date 2019-04-18 16:28:01
*/
@RestController
@AllArgsConstructor
@RequestMapping("/generator/prodTagReference" )
public class ProdTagReferenceController {
private final ProdTagReferenceService prodTagReferenceService;
/**
* 分页查询
* @param page 分页对象
* @param prodTagReference 分组标签引用
* @return 分页数据
*/
@GetMapping("/page" )
public ServerResponseEntity<IPage<ProdTagReference>> getProdTagReferencePage(PageParam page, ProdTagReference prodTagReference) {
return ServerResponseEntity.success(prodTagReferenceService.page(page, new LambdaQueryWrapper<ProdTagReference>()));
}
/**
* 通过id查询分组标签引用
* @param referenceId id
* @return 单个数据
*/
@GetMapping("/info/{referenceId}" )
public ServerResponseEntity<ProdTagReference> getById(@PathVariable("referenceId" ) Long referenceId) {
return ServerResponseEntity.success(prodTagReferenceService.getById(referenceId));
}
/**
* 新增分组标签引用
* @param prodTagReference 分组标签引用
* @return 是否新增成功
*/
@SysLog("新增分组标签引用" )
@PostMapping
@PreAuthorize("@pms.hasPermission('generator:prodTagReference:save')" )
public ServerResponseEntity<Boolean> save(@RequestBody @Valid ProdTagReference prodTagReference) {
return ServerResponseEntity.success(prodTagReferenceService.save(prodTagReference));
}
/**
* 修改分组标签引用
* @param prodTagReference 分组标签引用
* @return 是否修改成功
*/
@SysLog("修改分组标签引用" )
@PutMapping
@PreAuthorize("@pms.hasPermission('generator:prodTagReference:update')" )
public ServerResponseEntity<Boolean> updateById(@RequestBody @Valid ProdTagReference prodTagReference) {
return ServerResponseEntity.success(prodTagReferenceService.updateById(prodTagReference));
}
/**
* 通过id删除分组标签引用
* @param referenceId id
* @return 是否删除成功
*/
@SysLog("删除分组标签引用" )
@DeleteMapping("/{referenceId}" )
@PreAuthorize("@pms.hasPermission('generator:prodTagReference:delete')" )
public ServerResponseEntity<Boolean> removeById(@PathVariable Long referenceId) {
return ServerResponseEntity.success(prodTagReferenceService.removeById(referenceId));
}
}
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许,不可做商业用途!
*
* 版权所有,侵权必究!
*/
package com.yami.shop.admin.controller;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.Product;
import com.yami.shop.bean.model.Sku;
import com.yami.shop.bean.param.ProductParam;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.Json;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.admin.util.SecurityUtils;
import com.yami.shop.service.BasketService;
import com.yami.shop.service.ProdTagReferenceService;
import com.yami.shop.service.ProductService;
import com.yami.shop.service.SkuService;
import cn.hutool.core.bean.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/**
* 商品列表、商品发布controller
*
* @author lgh
*/
@RestController
@RequestMapping("/prod/prod")
public class ProductController {
@Autowired
private ProductService productService;
@Autowired
private SkuService skuService;
@Autowired
private ProdTagReferenceService prodTagReferenceService;
@Autowired
private BasketService basketService;
/**
* 分页获取商品信息
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('prod:prod:page')")
public ServerResponseEntity<IPage<Product>> page(ProductParam product, PageParam<Product> page) {
IPage<Product> products = productService.page(page,
new LambdaQueryWrapper<Product>()
.like(StrUtil.isNotBlank(product.getProdName()), Product::getProdName, product.getProdName())
.eq(Product::getShopId, SecurityUtils.getSysUser().getShopId())
.eq(product.getStatus() != null, Product::getStatus, product.getStatus())
.orderByDesc(Product::getPutawayTime));
return ServerResponseEntity.success(products);
}
/**
* 获取信息
*/
@GetMapping("/info/{prodId}")
@PreAuthorize("@pms.hasPermission('prod:prod:info')")
public ServerResponseEntity<Product> info(@PathVariable("prodId") Long prodId) {
Product prod = productService.getProductByProdId(prodId);
if (!Objects.equals(prod.getShopId(), SecurityUtils.getSysUser().getShopId())) {
throw new YamiShopBindException("没有权限获取该商品规格信息");
}
List<Sku> skuList = skuService.listByProdId(prodId);
prod.setSkuList(skuList);
//获取分组标签
List<Long> listTagId = prodTagReferenceService.listTagIdByProdId(prodId);
prod.setTagList(listTagId);
return ServerResponseEntity.success(prod);
}
/**
* 保存
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('prod:prod:save')")
public ServerResponseEntity<String> save(@Valid @RequestBody ProductParam productParam) {
checkParam(productParam);
Product product = BeanUtil.copyProperties(productParam, Product.class);
product.setDeliveryMode(Json.toJsonString(productParam.getDeliveryModeVo()));
product.setShopId(SecurityUtils.getSysUser().getShopId());
product.setUpdateTime(new Date());
if (product.getStatus() == 1) {
product.setPutawayTime(new Date());
}
product.setCreateTime(new Date());
productService.saveProduct(product);
return ServerResponseEntity.success();
}
/**
* 修改
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('prod:prod:update')")
public ServerResponseEntity<String> update(@Valid @RequestBody ProductParam productParam) {
checkParam(productParam);
Product dbProduct = productService.getProductByProdId(productParam.getProdId());
if (!Objects.equals(dbProduct.getShopId(), SecurityUtils.getSysUser().getShopId())) {
return ServerResponseEntity.showFailMsg("无法修改非本店铺商品信息");
}
List<Sku> dbSkus = skuService.listByProdId(dbProduct.getProdId());
Product product = BeanUtil.copyProperties(productParam, Product.class);
product.setDeliveryMode(Json.toJsonString(productParam.getDeliveryModeVo()));
product.setUpdateTime(new Date());
if (dbProduct.getStatus() == 0 || productParam.getStatus() == 1) {
product.setPutawayTime(new Date());
}
dbProduct.setSkuList(dbSkus);
productService.updateProduct(product, dbProduct);
List<String> userIds = basketService.listUserIdByProdId(product.getProdId());
for (String userId : userIds) {
basketService.removeShopCartItemsCacheByUserId(userId);
}
for (Sku sku : dbSkus) {
skuService.removeSkuCacheBySkuId(sku.getSkuId(), sku.getProdId());
}
return ServerResponseEntity.success();
}
/**
* 删除
*/
public ServerResponseEntity<Void> delete(Long prodId) {
Product dbProduct = productService.getProductByProdId(prodId);
if (!Objects.equals(dbProduct.getShopId(), SecurityUtils.getSysUser().getShopId())) {
throw new YamiShopBindException("无法获取非本店铺商品信息");
}
List<Sku> dbSkus = skuService.listByProdId(dbProduct.getProdId());
// 删除商品
productService.removeProductByProdId(prodId);
for (Sku sku : dbSkus) {
skuService.removeSkuCacheBySkuId(sku.getSkuId(), sku.getProdId());
}
List<String> userIds = basketService.listUserIdByProdId(prodId);
for (String userId : userIds) {
basketService.removeShopCartItemsCacheByUserId(userId);
}
return ServerResponseEntity.success();
}
/**
* 批量删除
*/
@DeleteMapping
@PreAuthorize("@pms.hasPermission('prod:prod:delete')")
public ServerResponseEntity<Void> batchDelete(@RequestBody Long[] prodIds) {
for (Long prodId : prodIds) {
delete(prodId);
}
return ServerResponseEntity.success();
}
/**
* 更新商品状态
*/
@PutMapping("/prodStatus")
@PreAuthorize("@pms.hasPermission('prod:prod:status')")
public ServerResponseEntity<Void> shopStatus(@RequestParam Long prodId, @RequestParam Integer prodStatus) {
Product product = new Product();
product.setProdId(prodId);
product.setStatus(prodStatus);
if (prodStatus == 1) {
product.setPutawayTime(new Date());
}
productService.updateById(product);
productService.removeProductCacheByProdId(prodId);
List<String> userIds = basketService.listUserIdByProdId(prodId);
for (String userId : userIds) {
basketService.removeShopCartItemsCacheByUserId(userId);
}
return ServerResponseEntity.success();
}
private void checkParam(ProductParam productParam) {
if (CollectionUtil.isEmpty(productParam.getTagList())) {
throw new YamiShopBindException("请选择产品分组");
}
Product.DeliveryModeVO deliveryMode = productParam.getDeliveryModeVo();
boolean hasDeliverMode = deliveryMode != null
&& (deliveryMode.getHasShopDelivery() || deliveryMode.getHasUserPickUp());
if (!hasDeliverMode) {
throw new YamiShopBindException("请选择配送方式");
}
List<Sku> skuList = productParam.getSkuList();
boolean isAllUnUse = true;
for (Sku sku : skuList) {
if (sku.getStatus() == 1) {
isAllUnUse = false;
}
}
if (isAllUnUse) {
throw new YamiShopBindException("至少要启用一种商品规格");
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment