后端管理系统代码
This commit is contained in:
parent
1eda356524
commit
d7f2732837
|
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
/target/
|
||||
/storage/
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>dts-admin-api</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package com.qiguliuxing.dts.admin.dao;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class AccountVo implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = 1567048369574496965L;
|
||||
|
||||
private Integer userId;
|
||||
|
||||
private BigDecimal remainAmount;
|
||||
|
||||
private BigDecimal totalAmount;
|
||||
|
||||
public Integer getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Integer userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public BigDecimal getRemainAmount() {
|
||||
return remainAmount;
|
||||
}
|
||||
|
||||
public void setRemainAmount(BigDecimal remainAmount) {
|
||||
this.remainAmount = remainAmount;
|
||||
}
|
||||
|
||||
public BigDecimal getTotalAmount() {
|
||||
return totalAmount;
|
||||
}
|
||||
|
||||
public void setTotalAmount(BigDecimal totalAmount) {
|
||||
this.totalAmount = totalAmount;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,352 @@
|
|||
package com.qiguliuxing.dts.admin.service;
|
||||
|
||||
import static com.qiguliuxing.dts.admin.util.AdminResponseCode.GOODS_NAME_EXIST;
|
||||
import static com.qiguliuxing.dts.admin.util.AdminResponseCode.GOODS_UPDATE_NOT_ALLOWED;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.qiguliuxing.dts.admin.dao.GoodsAllinone;
|
||||
import com.qiguliuxing.dts.admin.util.CatVo;
|
||||
import com.qiguliuxing.dts.core.qcode.QCodeService;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.db.domain.DtsBrand;
|
||||
import com.qiguliuxing.dts.db.domain.DtsCategory;
|
||||
import com.qiguliuxing.dts.db.domain.DtsGoods;
|
||||
import com.qiguliuxing.dts.db.domain.DtsGoodsAttribute;
|
||||
import com.qiguliuxing.dts.db.domain.DtsGoodsProduct;
|
||||
import com.qiguliuxing.dts.db.domain.DtsGoodsSpecification;
|
||||
import com.qiguliuxing.dts.db.service.DtsBrandService;
|
||||
import com.qiguliuxing.dts.db.service.DtsCartService;
|
||||
import com.qiguliuxing.dts.db.service.DtsCategoryService;
|
||||
import com.qiguliuxing.dts.db.service.DtsGoodsAttributeService;
|
||||
import com.qiguliuxing.dts.db.service.DtsGoodsProductService;
|
||||
import com.qiguliuxing.dts.db.service.DtsGoodsService;
|
||||
import com.qiguliuxing.dts.db.service.DtsGoodsSpecificationService;
|
||||
import com.qiguliuxing.dts.db.service.DtsOrderGoodsService;
|
||||
|
||||
@Service
|
||||
public class AdminGoodsService {
|
||||
private final Log logger = LogFactory.getLog(AdminGoodsService.class);
|
||||
|
||||
@Autowired
|
||||
private DtsGoodsService goodsService;
|
||||
@Autowired
|
||||
private DtsGoodsSpecificationService specificationService;
|
||||
@Autowired
|
||||
private DtsGoodsAttributeService attributeService;
|
||||
@Autowired
|
||||
private DtsGoodsProductService productService;
|
||||
@Autowired
|
||||
private DtsCategoryService categoryService;
|
||||
@Autowired
|
||||
private DtsBrandService brandService;
|
||||
@Autowired
|
||||
private DtsCartService cartService;
|
||||
@Autowired
|
||||
private DtsOrderGoodsService orderGoodsService;
|
||||
|
||||
@Autowired
|
||||
private QCodeService qCodeService;
|
||||
|
||||
public Object list(String goodsSn, String name,
|
||||
Integer page, Integer limit, String sort, String order) {
|
||||
List<DtsGoods> goodsList = goodsService.querySelective(goodsSn, name, page, limit, sort, order);
|
||||
long total = PageInfo.of(goodsList).getTotal();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", goodsList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
private Object validate(GoodsAllinone goodsAllinone) {
|
||||
DtsGoods goods = goodsAllinone.getGoods();
|
||||
String name = goods.getName();
|
||||
if (StringUtils.isEmpty(name)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
String goodsSn = goods.getGoodsSn();
|
||||
if (StringUtils.isEmpty(goodsSn)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
// 品牌商可以不设置,如果设置则需要验证品牌商存在
|
||||
Integer brandId = goods.getBrandId();
|
||||
if (brandId != null && brandId != 0) {
|
||||
if (brandService.findById(brandId) == null) {
|
||||
return ResponseUtil.badArgumentValue();
|
||||
}
|
||||
}
|
||||
// 分类可以不设置,如果设置则需要验证分类存在
|
||||
Integer categoryId = goods.getCategoryId();
|
||||
if (categoryId != null && categoryId != 0) {
|
||||
if (categoryService.findById(categoryId) == null) {
|
||||
return ResponseUtil.badArgumentValue();
|
||||
}
|
||||
}
|
||||
|
||||
DtsGoodsAttribute[] attributes = goodsAllinone.getAttributes();
|
||||
for (DtsGoodsAttribute attribute : attributes) {
|
||||
String attr = attribute.getAttribute();
|
||||
if (StringUtils.isEmpty(attr)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
String value = attribute.getValue();
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
}
|
||||
|
||||
DtsGoodsSpecification[] specifications = goodsAllinone.getSpecifications();
|
||||
for (DtsGoodsSpecification specification : specifications) {
|
||||
String spec = specification.getSpecification();
|
||||
if (StringUtils.isEmpty(spec)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
String value = specification.getValue();
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
}
|
||||
|
||||
DtsGoodsProduct[] products = goodsAllinone.getProducts();
|
||||
for (DtsGoodsProduct product : products) {
|
||||
Integer number = product.getNumber();
|
||||
if (number == null || number < 0) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
BigDecimal price = product.getPrice();
|
||||
if (price == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
String[] productSpecifications = product.getSpecifications();
|
||||
if (productSpecifications.length == 0) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑商品
|
||||
* <p>
|
||||
* TODO
|
||||
* 目前商品修改的逻辑是
|
||||
* 1. 更新Dts_goods表
|
||||
* 2. 逻辑删除Dts_goods_specification、Dts_goods_attribute、Dts_goods_product
|
||||
* 3. 添加Dts_goods_specification、Dts_goods_attribute、Dts_goods_product
|
||||
* <p>
|
||||
* 这里商品三个表的数据采用删除再添加的策略是因为
|
||||
* 商品编辑页面,支持管理员添加删除商品规格、添加删除商品属性,因此这里仅仅更新是不可能的,
|
||||
* 只能删除三个表旧的数据,然后添加新的数据。
|
||||
* 但是这里又会引入新的问题,就是存在订单商品货品ID指向了失效的商品货品表。
|
||||
* 因此这里会拒绝管理员编辑商品,如果订单或购物车中存在商品。
|
||||
* 所以这里可能需要重新设计。
|
||||
*/
|
||||
@Transactional
|
||||
public Object update(GoodsAllinone goodsAllinone) {
|
||||
Object error = validate(goodsAllinone);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
|
||||
DtsGoods goods = goodsAllinone.getGoods();
|
||||
DtsGoodsAttribute[] attributes = goodsAllinone.getAttributes();
|
||||
DtsGoodsSpecification[] specifications = goodsAllinone.getSpecifications();
|
||||
DtsGoodsProduct[] products = goodsAllinone.getProducts();
|
||||
|
||||
Integer id = goods.getId();
|
||||
// 检查是否存在购物车商品或者订单商品
|
||||
// 如果存在则拒绝修改商品。
|
||||
if (orderGoodsService.checkExist(id)) {
|
||||
logger.warn("商品已经在订单中,不能修改");
|
||||
return ResponseUtil.fail(GOODS_UPDATE_NOT_ALLOWED, "商品已经在订单中,不能修改");
|
||||
}
|
||||
if (cartService.checkExist(id)) {
|
||||
logger.warn("商品已经在购物车中,不能修改");
|
||||
return ResponseUtil.fail(GOODS_UPDATE_NOT_ALLOWED, "商品已经在购物车中,不能修改");
|
||||
}
|
||||
|
||||
//将生成的分享图片地址写入数据库
|
||||
String url = qCodeService.createGoodShareImage(goods.getId().toString(), goods.getPicUrl(), goods.getName());
|
||||
goods.setShareUrl(url);
|
||||
|
||||
// 商品基本信息表Dts_goods
|
||||
if (goodsService.updateById(goods) == 0) {
|
||||
logger.error("更新数据失败");
|
||||
throw new RuntimeException("更新数据失败");
|
||||
}
|
||||
|
||||
Integer gid = goods.getId();
|
||||
specificationService.deleteByGid(gid);
|
||||
attributeService.deleteByGid(gid);
|
||||
productService.deleteByGid(gid);
|
||||
|
||||
// 商品规格表Dts_goods_specification
|
||||
for (DtsGoodsSpecification specification : specifications) {
|
||||
specification.setGoodsId(goods.getId());
|
||||
specificationService.add(specification);
|
||||
}
|
||||
|
||||
// 商品参数表Dts_goods_attribute
|
||||
for (DtsGoodsAttribute attribute : attributes) {
|
||||
attribute.setGoodsId(goods.getId());
|
||||
attributeService.add(attribute);
|
||||
}
|
||||
|
||||
// 商品货品表Dts_product
|
||||
for (DtsGoodsProduct product : products) {
|
||||
product.setGoodsId(goods.getId());
|
||||
productService.add(product);
|
||||
}
|
||||
qCodeService.createGoodShareImage(goods.getId().toString(), goods.getPicUrl(), goods.getName());
|
||||
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Object delete(DtsGoods goods) {
|
||||
Integer id = goods.getId();
|
||||
if (id == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
Integer gid = goods.getId();
|
||||
goodsService.deleteById(gid);
|
||||
specificationService.deleteByGid(gid);
|
||||
attributeService.deleteByGid(gid);
|
||||
productService.deleteByGid(gid);
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Object create(GoodsAllinone goodsAllinone) {
|
||||
Object error = validate(goodsAllinone);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
|
||||
DtsGoods goods = goodsAllinone.getGoods();
|
||||
DtsGoodsAttribute[] attributes = goodsAllinone.getAttributes();
|
||||
DtsGoodsSpecification[] specifications = goodsAllinone.getSpecifications();
|
||||
DtsGoodsProduct[] products = goodsAllinone.getProducts();
|
||||
|
||||
String name = goods.getName();
|
||||
if (goodsService.checkExistByName(name)) {
|
||||
logger.error("商品名已经存在");
|
||||
return ResponseUtil.fail(GOODS_NAME_EXIST, "商品名已经存在");
|
||||
}
|
||||
|
||||
// 商品基本信息表Dts_goods
|
||||
goodsService.add(goods);
|
||||
|
||||
//将生成的分享图片地址写入数据库
|
||||
String url = qCodeService.createGoodShareImage(goods.getId().toString(), goods.getPicUrl(), goods.getName());
|
||||
if (!StringUtils.isEmpty(url)) {
|
||||
goods.setShareUrl(url);
|
||||
if (goodsService.updateById(goods) == 0) {
|
||||
logger.error("更新数据失败");
|
||||
throw new RuntimeException("更新数据失败");
|
||||
}
|
||||
}
|
||||
|
||||
// 商品规格表Dts_goods_specification
|
||||
for (DtsGoodsSpecification specification : specifications) {
|
||||
specification.setGoodsId(goods.getId());
|
||||
specificationService.add(specification);
|
||||
}
|
||||
|
||||
// 商品参数表Dts_goods_attribute
|
||||
for (DtsGoodsAttribute attribute : attributes) {
|
||||
attribute.setGoodsId(goods.getId());
|
||||
attributeService.add(attribute);
|
||||
}
|
||||
|
||||
// 商品货品表Dts_product
|
||||
for (DtsGoodsProduct product : products) {
|
||||
product.setGoodsId(goods.getId());
|
||||
productService.add(product);
|
||||
}
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
public Object list2() {
|
||||
// http://element-cn.eleme.io/#/zh-CN/component/cascader
|
||||
// 管理员设置“所属分类”
|
||||
List<DtsCategory> l1CatList = categoryService.queryL1();
|
||||
List<CatVo> categoryList = new ArrayList<>(l1CatList.size());
|
||||
|
||||
for (DtsCategory l1 : l1CatList) {
|
||||
CatVo l1CatVo = new CatVo();
|
||||
l1CatVo.setValue(l1.getId());
|
||||
l1CatVo.setLabel(l1.getName());
|
||||
|
||||
List<DtsCategory> l2CatList = categoryService.queryByPid(l1.getId());
|
||||
List<CatVo> children = new ArrayList<>(l2CatList.size());
|
||||
for (DtsCategory l2 : l2CatList) {
|
||||
CatVo l2CatVo = new CatVo();
|
||||
l2CatVo.setValue(l2.getId());
|
||||
l2CatVo.setLabel(l2.getName());
|
||||
children.add(l2CatVo);
|
||||
}
|
||||
l1CatVo.setChildren(children);
|
||||
|
||||
categoryList.add(l1CatVo);
|
||||
}
|
||||
|
||||
// http://element-cn.eleme.io/#/zh-CN/component/select
|
||||
// 管理员设置“所属品牌商”
|
||||
List<DtsBrand> list = brandService.all();
|
||||
List<Map<String, Object>> brandList = new ArrayList<>(l1CatList.size());
|
||||
for (DtsBrand brand : list) {
|
||||
Map<String, Object> b = new HashMap<>(2);
|
||||
b.put("value", brand.getId());
|
||||
b.put("label", brand.getName());
|
||||
brandList.add(b);
|
||||
}
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("categoryList", categoryList);
|
||||
data.put("brandList", brandList);
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
public Object detail(Integer id) {
|
||||
DtsGoods goods = goodsService.findById(id);
|
||||
List<DtsGoodsProduct> products = productService.queryByGid(id);
|
||||
List<DtsGoodsSpecification> specifications = specificationService.queryByGid(id);
|
||||
List<DtsGoodsAttribute> attributes = attributeService.queryByGid(id);
|
||||
|
||||
Integer categoryId = goods.getCategoryId();
|
||||
DtsCategory category = categoryService.findById(categoryId);
|
||||
Integer[] categoryIds = new Integer[]{};
|
||||
if (category != null) {
|
||||
Integer parentCategoryId = category.getPid();
|
||||
categoryIds = new Integer[]{parentCategoryId, categoryId};
|
||||
}
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("goods", goods);
|
||||
data.put("specifications", specifications);
|
||||
data.put("products", products);
|
||||
data.put("attributes", attributes);
|
||||
data.put("categoryIds", categoryIds);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,255 @@
|
|||
package com.qiguliuxing.dts.admin.service;
|
||||
|
||||
import static com.qiguliuxing.dts.admin.util.AdminResponseCode.ORDER_CONFIRM_NOT_ALLOWED;
|
||||
import static com.qiguliuxing.dts.admin.util.AdminResponseCode.ORDER_REFUND_FAILED;
|
||||
import static com.qiguliuxing.dts.admin.util.AdminResponseCode.ORDER_REPLY_EXIST;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
|
||||
import com.github.binarywang.wxpay.bean.result.WxPayRefundResult;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.qiguliuxing.dts.core.notify.NotifyService;
|
||||
import com.qiguliuxing.dts.core.notify.NotifyType;
|
||||
import com.qiguliuxing.dts.core.util.JacksonUtil;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.db.domain.DtsComment;
|
||||
import com.qiguliuxing.dts.db.domain.DtsOrder;
|
||||
import com.qiguliuxing.dts.db.domain.DtsOrderGoods;
|
||||
import com.qiguliuxing.dts.db.domain.UserVo;
|
||||
import com.qiguliuxing.dts.db.service.DtsCommentService;
|
||||
import com.qiguliuxing.dts.db.service.DtsGoodsProductService;
|
||||
import com.qiguliuxing.dts.db.service.DtsOrderGoodsService;
|
||||
import com.qiguliuxing.dts.db.service.DtsOrderService;
|
||||
import com.qiguliuxing.dts.db.service.DtsUserService;
|
||||
import com.qiguliuxing.dts.db.util.OrderUtil;
|
||||
|
||||
@Service
|
||||
public class AdminOrderService {
|
||||
private final Log logger = LogFactory.getLog(AdminOrderService.class);
|
||||
|
||||
@Autowired
|
||||
private DtsOrderGoodsService orderGoodsService;
|
||||
@Autowired
|
||||
private DtsOrderService orderService;
|
||||
@Autowired
|
||||
private DtsGoodsProductService productService;
|
||||
@Autowired
|
||||
private DtsUserService userService;
|
||||
@Autowired
|
||||
private DtsCommentService commentService;
|
||||
@Autowired
|
||||
private WxPayService wxPayService;
|
||||
@Autowired
|
||||
private NotifyService notifyService;
|
||||
|
||||
public Object list(Integer userId, String orderSn, List<Short> orderStatusArray,
|
||||
Integer page, Integer limit, String sort, String order) {
|
||||
List<DtsOrder> orderList = orderService.querySelective(userId, orderSn, orderStatusArray, page, limit, sort, order);
|
||||
long total = PageInfo.of(orderList).getTotal();
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", orderList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
public Object detail(Integer id) {
|
||||
DtsOrder order = orderService.findById(id);
|
||||
List<DtsOrderGoods> orderGoods = orderGoodsService.queryByOid(id);
|
||||
UserVo user = userService.findUserVoById(order.getUserId());
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("order", order);
|
||||
data.put("orderGoods", orderGoods);
|
||||
data.put("user", user);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单退款
|
||||
* <p>
|
||||
* 1. 检测当前订单是否能够退款;
|
||||
* 2. 微信退款操作;
|
||||
* 3. 设置订单退款确认状态;
|
||||
* 4. 订单商品库存回库。
|
||||
* <p>
|
||||
* TODO
|
||||
* 虽然接入了微信退款API,但是从安全角度考虑,建议开发者删除这里微信退款代码,采用以下两步走步骤:
|
||||
* 1. 管理员登录微信官方支付平台点击退款操作进行退款
|
||||
* 2. 管理员登录Dts管理后台点击退款操作进行订单状态修改和商品库存回库
|
||||
*
|
||||
* @param body 订单信息,{ orderId:xxx }
|
||||
* @return 订单退款操作结果
|
||||
*/
|
||||
@Transactional
|
||||
public Object refund(String body) {
|
||||
Integer orderId = JacksonUtil.parseInteger(body, "orderId");
|
||||
String refundMoney = JacksonUtil.parseString(body, "refundMoney");
|
||||
if (orderId == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
if (StringUtils.isEmpty(refundMoney)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
DtsOrder order = orderService.findById(orderId);
|
||||
if (order == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
if (order.getActualPrice().compareTo(new BigDecimal(refundMoney)) != 0) {
|
||||
return ResponseUtil.badArgumentValue();
|
||||
}
|
||||
|
||||
// 如果订单不是退款状态,则不能退款
|
||||
if (!order.getOrderStatus().equals(OrderUtil.STATUS_REFUND)) {
|
||||
return ResponseUtil.fail(ORDER_CONFIRM_NOT_ALLOWED, "订单不能确认收货");
|
||||
}
|
||||
|
||||
// 微信退款
|
||||
WxPayRefundRequest wxPayRefundRequest = new WxPayRefundRequest();
|
||||
wxPayRefundRequest.setOutTradeNo(order.getOrderSn());
|
||||
wxPayRefundRequest.setOutRefundNo("refund_" + order.getOrderSn());
|
||||
// 元转成分
|
||||
Integer totalFee = order.getActualPrice().multiply(new BigDecimal(100)).intValue();
|
||||
wxPayRefundRequest.setTotalFee(totalFee);
|
||||
wxPayRefundRequest.setRefundFee(totalFee);
|
||||
|
||||
/** 为了账号安全,暂时屏蔽api退款
|
||||
WxPayRefundResult wxPayRefundResult = null;
|
||||
try {
|
||||
wxPayRefundResult = wxPayService.refund(wxPayRefundRequest);
|
||||
} catch (WxPayException e) {
|
||||
e.printStackTrace();
|
||||
return ResponseUtil.fail(ORDER_REFUND_FAILED, "订单退款失败");
|
||||
}
|
||||
if (!wxPayRefundResult.getReturnCode().equals("SUCCESS")) {
|
||||
logger.warn("refund fail: " + wxPayRefundResult.getReturnMsg());
|
||||
return ResponseUtil.fail(ORDER_REFUND_FAILED, "订单退款失败");
|
||||
}
|
||||
if (!wxPayRefundResult.getResultCode().equals("SUCCESS")) {
|
||||
logger.warn("refund fail: " + wxPayRefundResult.getReturnMsg());
|
||||
return ResponseUtil.fail(ORDER_REFUND_FAILED, "订单退款失败");
|
||||
}
|
||||
*/
|
||||
|
||||
// 设置订单取消状态
|
||||
order.setOrderStatus(OrderUtil.STATUS_REFUND_CONFIRM);
|
||||
if (orderService.updateWithOptimisticLocker(order) == 0) {
|
||||
throw new RuntimeException("更新数据已失效");
|
||||
}
|
||||
|
||||
// 商品货品数量增加
|
||||
List<DtsOrderGoods> orderGoodsList = orderGoodsService.queryByOid(orderId);
|
||||
for (DtsOrderGoods orderGoods : orderGoodsList) {
|
||||
Integer productId = orderGoods.getProductId();
|
||||
Short number = orderGoods.getNumber();
|
||||
if (productService.addStock(productId, number) == 0) {
|
||||
throw new RuntimeException("商品货品库存增加失败");
|
||||
}
|
||||
}
|
||||
|
||||
//TODO 发送邮件和短信通知,这里采用异步发送
|
||||
// 退款成功通知用户, 例如“您申请的订单退款 [ 单号:{1} ] 已成功,请耐心等待到账。”
|
||||
// 注意订单号只发后6位
|
||||
notifyService.notifySmsTemplate(order.getMobile(), NotifyType.REFUND, new String[]{order.getOrderSn().substring(8, 14)});
|
||||
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发货
|
||||
* 1. 检测当前订单是否能够发货
|
||||
* 2. 设置订单发货状态
|
||||
*
|
||||
* @param body 订单信息,{ orderId:xxx, shipSn: xxx, shipChannel: xxx }
|
||||
* @return 订单操作结果
|
||||
* 成功则 { errno: 0, errmsg: '成功' }
|
||||
* 失败则 { errno: XXX, errmsg: XXX }
|
||||
*/
|
||||
public Object ship(String body) {
|
||||
Integer orderId = JacksonUtil.parseInteger(body, "orderId");
|
||||
String shipSn = JacksonUtil.parseString(body, "shipSn");
|
||||
String shipChannel = JacksonUtil.parseString(body, "shipChannel");
|
||||
if (orderId == null || shipSn == null || shipChannel == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
DtsOrder order = orderService.findById(orderId);
|
||||
if (order == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
// 如果订单不是已付款状态,则不能发货
|
||||
if (!order.getOrderStatus().equals(OrderUtil.STATUS_PAY)) {
|
||||
return ResponseUtil.fail(ORDER_CONFIRM_NOT_ALLOWED, "订单不能确认收货");
|
||||
}
|
||||
|
||||
order.setOrderStatus(OrderUtil.STATUS_SHIP);
|
||||
order.setShipSn(shipSn);
|
||||
order.setShipChannel(shipChannel);
|
||||
order.setShipTime(LocalDateTime.now());
|
||||
if (orderService.updateWithOptimisticLocker(order) == 0) {
|
||||
return ResponseUtil.updatedDateExpired();
|
||||
}
|
||||
|
||||
//TODO 发送邮件和短信通知,这里采用异步发送
|
||||
// 发货会发送通知短信给用户: *
|
||||
// "您的订单已经发货,快递公司 {1},快递单 {2} ,请注意查收"
|
||||
notifyService.notifySmsTemplate(order.getMobile(), NotifyType.SHIP, new String[]{shipChannel, shipSn});
|
||||
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 回复订单商品
|
||||
*
|
||||
* @param body 订单信息,{ orderId:xxx }
|
||||
* @return 订单操作结果
|
||||
* 成功则 { errno: 0, errmsg: '成功' }
|
||||
* 失败则 { errno: XXX, errmsg: XXX }
|
||||
*/
|
||||
public Object reply(String body) {
|
||||
Integer commentId = JacksonUtil.parseInteger(body, "commentId");
|
||||
if (commentId == null || commentId == 0) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
// 目前只支持回复一次
|
||||
if (commentService.findById(commentId) != null) {
|
||||
return ResponseUtil.fail(ORDER_REPLY_EXIST, "订单商品已回复!");
|
||||
}
|
||||
String content = JacksonUtil.parseString(body, "content");
|
||||
if (StringUtils.isEmpty(content)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
// 创建评价回复
|
||||
DtsComment comment = new DtsComment();
|
||||
comment.setType((byte) 2);
|
||||
comment.setValueId(commentId);
|
||||
comment.setContent(content);
|
||||
comment.setUserId(0); // 评价回复没有用
|
||||
comment.setStar((short) 0); // 评价回复没有用
|
||||
comment.setHasPicture(false); // 评价回复没有用
|
||||
comment.setPicUrls(new String[]{}); // 评价回复没有用
|
||||
commentService.save(comment);
|
||||
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
package com.qiguliuxing.dts.admin.shiro;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.shiro.authc.AccountException;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.authc.AuthenticationInfo;
|
||||
import org.apache.shiro.authc.AuthenticationToken;
|
||||
import org.apache.shiro.authc.SimpleAuthenticationInfo;
|
||||
import org.apache.shiro.authc.UnknownAccountException;
|
||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||
import org.apache.shiro.authz.AuthorizationException;
|
||||
import org.apache.shiro.authz.AuthorizationInfo;
|
||||
import org.apache.shiro.authz.SimpleAuthorizationInfo;
|
||||
import org.apache.shiro.realm.AuthorizingRealm;
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.qiguliuxing.dts.core.util.bcrypt.BCryptPasswordEncoder;
|
||||
import com.qiguliuxing.dts.db.domain.DtsAdmin;
|
||||
import com.qiguliuxing.dts.db.service.DtsAdminService;
|
||||
import com.qiguliuxing.dts.db.service.DtsPermissionService;
|
||||
import com.qiguliuxing.dts.db.service.DtsRoleService;
|
||||
|
||||
/**
|
||||
* 授权相关服务-shiro
|
||||
* @author qiguliuxing
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class AdminAuthorizingRealm extends AuthorizingRealm {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AdminAuthorizingRealm.class);
|
||||
@Autowired
|
||||
private DtsAdminService adminService;
|
||||
@Autowired
|
||||
private DtsRoleService roleService;
|
||||
@Autowired
|
||||
private DtsPermissionService permissionService;
|
||||
|
||||
@Override
|
||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
|
||||
if (principals == null) {
|
||||
throw new AuthorizationException("PrincipalCollection method argument cannot be null.");
|
||||
}
|
||||
|
||||
DtsAdmin admin = (DtsAdmin) getAvailablePrincipal(principals);
|
||||
Integer[] roleIds = admin.getRoleIds();
|
||||
Set<String> roles = roleService.queryByIds(roleIds);
|
||||
Set<String> permissions = permissionService.queryByRoleIds(roleIds);
|
||||
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
|
||||
info.setRoles(roles);
|
||||
info.setStringPermissions(permissions);
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
|
||||
|
||||
UsernamePasswordToken upToken = (UsernamePasswordToken) token;
|
||||
String username = upToken.getUsername();
|
||||
String password=new String(upToken.getPassword());
|
||||
|
||||
if (StringUtils.isEmpty(username)) {
|
||||
throw new AccountException("用户名不能为空");
|
||||
}
|
||||
if (StringUtils.isEmpty(password)) {
|
||||
throw new AccountException("密码不能为空");
|
||||
}
|
||||
|
||||
List<DtsAdmin> adminList = adminService.findAdmin(username);
|
||||
Assert.state(adminList.size() < 2, "同一个用户名存在两个账户");
|
||||
if (adminList.size() == 0) {
|
||||
logger.error("找不到用户("+username+")的帐号信息");
|
||||
throw new UnknownAccountException("找不到用户("+username+")的帐号信息");
|
||||
}
|
||||
DtsAdmin admin = adminList.get(0);
|
||||
|
||||
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
||||
if (!encoder.matches(password, admin.getPassword())) {
|
||||
logger.error("找不到用户("+username+")的帐号信息");
|
||||
throw new UnknownAccountException("找不到用户("+username+")的帐号信息");
|
||||
}
|
||||
|
||||
return new SimpleAuthenticationInfo(admin,password,getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.qiguliuxing.dts.admin.shiro;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
|
||||
import org.apache.shiro.web.servlet.ShiroHttpServletRequest;
|
||||
import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
|
||||
import org.apache.shiro.web.util.WebUtils;
|
||||
|
||||
import com.alibaba.druid.util.StringUtils;
|
||||
|
||||
public class AdminWebSessionManager extends DefaultWebSessionManager {
|
||||
|
||||
public static final String LOGIN_TOKEN_KEY = "X-Dts-Admin-Token";
|
||||
private static final String REFERENCED_SESSION_ID_SOURCE = "Stateless request";
|
||||
|
||||
@Override
|
||||
protected Serializable getSessionId(ServletRequest request, ServletResponse response) {
|
||||
String id = WebUtils.toHttp(request).getHeader(LOGIN_TOKEN_KEY);
|
||||
if (!StringUtils.isEmpty(id)) {
|
||||
request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_SOURCE, REFERENCED_SESSION_ID_SOURCE);
|
||||
request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID, id);
|
||||
request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_IS_VALID, Boolean.TRUE);
|
||||
return id;
|
||||
} else {
|
||||
return super.getSessionId(request, response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package com.qiguliuxing.dts.admin.util;
|
||||
|
||||
public class AdminResponseCode {
|
||||
public static final Integer ADMIN_INVALID_NAME = 601;
|
||||
public static final Integer ADMIN_INVALID_PASSWORD = 602;
|
||||
public static final Integer ADMIN_NAME_EXIST = 602;
|
||||
public static final Integer ADMIN_ALTER_NOT_ALLOWED = 603;
|
||||
public static final Integer ADMIN_DELETE_NOT_ALLOWED = 604;
|
||||
public static final Integer ADMIN_INVALID_ACCOUNT = 605;
|
||||
public static final Integer GOODS_UPDATE_NOT_ALLOWED = 610;
|
||||
public static final Integer GOODS_NAME_EXIST = 611;
|
||||
public static final Integer ORDER_CONFIRM_NOT_ALLOWED = 620;
|
||||
public static final Integer ORDER_REFUND_FAILED = 621;
|
||||
public static final Integer ORDER_REPLY_EXIST = 622;
|
||||
public static final Integer USER_INVALID_NAME = 630;
|
||||
public static final Integer USER_INVALID_PASSWORD = 631;
|
||||
public static final Integer USER_INVALID_MOBILE = 632;
|
||||
public static final Integer USER_NAME_EXIST = 633;
|
||||
public static final Integer USER_MOBILE_EXIST = 634;
|
||||
public static final Integer ROLE_NAME_EXIST = 640;
|
||||
public static final Integer ROLE_SUPER_SUPERMISSION = 641;
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.core.validator.Order;
|
||||
import com.qiguliuxing.dts.core.validator.Sort;
|
||||
import com.qiguliuxing.dts.db.domain.DtsAd;
|
||||
import com.qiguliuxing.dts.db.service.DtsAdService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/ad")
|
||||
@Validated
|
||||
public class AdminAdController {
|
||||
private final Log logger = LogFactory.getLog(AdminAdController.class);
|
||||
|
||||
@Autowired
|
||||
private DtsAdService adService;
|
||||
|
||||
@RequiresPermissions("admin:ad:list")
|
||||
@RequiresPermissionsDesc(menu={"推广管理" , "广告管理"}, button="查询")
|
||||
@GetMapping("/list")
|
||||
public Object list(String name, String content,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
List<DtsAd> adList = adService.querySelective(name, content, page, limit, sort, order);
|
||||
long total = PageInfo.of(adList).getTotal();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", adList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
private Object validate(DtsAd ad) {
|
||||
String name = ad.getName();
|
||||
if (StringUtils.isEmpty(name)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
String content = ad.getContent();
|
||||
if (StringUtils.isEmpty(content)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:ad:create")
|
||||
@RequiresPermissionsDesc(menu={"推广管理" , "广告管理"}, button="添加")
|
||||
@PostMapping("/create")
|
||||
public Object create(@RequestBody DtsAd ad) {
|
||||
Object error = validate(ad);
|
||||
if (error != null) {
|
||||
logger.error("广告管理 添加校验不通过!");
|
||||
return error;
|
||||
}
|
||||
adService.add(ad);
|
||||
return ResponseUtil.ok(ad);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:ad:read")
|
||||
@RequiresPermissionsDesc(menu={"推广管理" , "广告管理"}, button="详情")
|
||||
@GetMapping("/read")
|
||||
public Object read(@NotNull Integer id) {
|
||||
DtsAd brand = adService.findById(id);
|
||||
return ResponseUtil.ok(brand);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:ad:update")
|
||||
@RequiresPermissionsDesc(menu={"推广管理" , "广告管理"}, button="编辑")
|
||||
@PostMapping("/update")
|
||||
public Object update(@RequestBody DtsAd ad) {
|
||||
Object error = validate(ad);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
if (adService.updateById(ad) == 0) {
|
||||
return ResponseUtil.updatedDataFailed();
|
||||
}
|
||||
|
||||
return ResponseUtil.ok(ad);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:ad:delete")
|
||||
@RequiresPermissionsDesc(menu={"推广管理" , "广告管理"}, button="删除")
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody DtsAd ad) {
|
||||
Integer id = ad.getId();
|
||||
if (id == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
adService.deleteById(id);
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.core.validator.Order;
|
||||
import com.qiguliuxing.dts.core.validator.Sort;
|
||||
import com.qiguliuxing.dts.db.domain.DtsAddress;
|
||||
import com.qiguliuxing.dts.db.service.DtsAddressService;
|
||||
import com.qiguliuxing.dts.db.service.DtsRegionService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/address")
|
||||
@Validated
|
||||
public class AdminAddressController {
|
||||
|
||||
@Autowired
|
||||
private DtsAddressService addressService;
|
||||
@Autowired
|
||||
private DtsRegionService regionService;
|
||||
|
||||
private Map<String, Object> toVo(DtsAddress address) {
|
||||
Map<String, Object> addressVo = new HashMap<>();
|
||||
addressVo.put("id", address.getId());
|
||||
addressVo.put("userId", address.getUserId());
|
||||
addressVo.put("name", address.getName());
|
||||
addressVo.put("mobile", address.getMobile());
|
||||
addressVo.put("isDefault", address.getIsDefault());
|
||||
addressVo.put("provinceId", address.getProvinceId());
|
||||
addressVo.put("cityId", address.getCityId());
|
||||
addressVo.put("areaId", address.getAreaId());
|
||||
addressVo.put("address", address.getAddress());
|
||||
String province = regionService.findById(address.getProvinceId()).getName();
|
||||
String city = regionService.findById(address.getCityId()).getName();
|
||||
String area = regionService.findById(address.getAreaId()).getName();
|
||||
addressVo.put("province", province);
|
||||
addressVo.put("city", city);
|
||||
addressVo.put("area", area);
|
||||
return addressVo;
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:address:list")
|
||||
@RequiresPermissionsDesc(menu={"用户管理" , "收货地址"}, button="查询")
|
||||
@GetMapping("/list")
|
||||
public Object list(Integer userId, String name,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
|
||||
List<DtsAddress> addressList = addressService.querySelective(userId, name, page, limit, sort, order);
|
||||
long total = PageInfo.of(addressList).getTotal();
|
||||
|
||||
List<Map<String, Object>> addressVoList = new ArrayList<>(addressList.size());
|
||||
for (DtsAddress address : addressList) {
|
||||
Map<String, Object> addressVo = toVo(address);
|
||||
addressVoList.add(addressVo);
|
||||
}
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", addressVoList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,149 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import static com.qiguliuxing.dts.admin.util.AdminResponseCode.ADMIN_INVALID_NAME;
|
||||
import static com.qiguliuxing.dts.admin.util.AdminResponseCode.ADMIN_INVALID_PASSWORD;
|
||||
import static com.qiguliuxing.dts.admin.util.AdminResponseCode.ADMIN_NAME_EXIST;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.core.util.RegexUtil;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.core.util.bcrypt.BCryptPasswordEncoder;
|
||||
import com.qiguliuxing.dts.core.validator.Order;
|
||||
import com.qiguliuxing.dts.core.validator.Sort;
|
||||
import com.qiguliuxing.dts.db.domain.DtsAdmin;
|
||||
import com.qiguliuxing.dts.db.service.DtsAdminService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/admin")
|
||||
@Validated
|
||||
public class AdminAdminController {
|
||||
private final Log logger = LogFactory.getLog(AdminAdminController.class);
|
||||
|
||||
@Autowired
|
||||
private DtsAdminService adminService;
|
||||
|
||||
@RequiresPermissions("admin:admin:list")
|
||||
@RequiresPermissionsDesc(menu={"系统管理" , "管理员管理"}, button="查询")
|
||||
@GetMapping("/list")
|
||||
public Object list(String username,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
List<DtsAdmin> adminList = adminService.querySelective(username, page, limit, sort, order);
|
||||
long total = PageInfo.of(adminList).getTotal();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", adminList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
private Object validate(DtsAdmin admin) {
|
||||
String name = admin.getUsername();
|
||||
if (StringUtils.isEmpty(name)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
if (!RegexUtil.isUsername(name)) {
|
||||
logger.error("管理员名称不符合规定");
|
||||
return ResponseUtil.fail(ADMIN_INVALID_NAME, "管理员名称不符合规定");
|
||||
}
|
||||
String password = admin.getPassword();
|
||||
if (StringUtils.isEmpty(password) || password.length() < 6) {
|
||||
logger.error("管理员密码长度不能小于6");
|
||||
return ResponseUtil.fail(ADMIN_INVALID_PASSWORD, "管理员密码长度不能小于6");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:admin:create")
|
||||
@RequiresPermissionsDesc(menu={"系统管理" , "管理员管理"}, button="添加")
|
||||
@PostMapping("/create")
|
||||
public Object create(@RequestBody DtsAdmin admin) {
|
||||
Object error = validate(admin);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
|
||||
String username = admin.getUsername();
|
||||
List<DtsAdmin> adminList = adminService.findAdmin(username);
|
||||
if (adminList.size() > 0) {
|
||||
logger.error("管理员已经存在");
|
||||
return ResponseUtil.fail(ADMIN_NAME_EXIST, "管理员已经存在");
|
||||
}
|
||||
|
||||
String rawPassword = admin.getPassword();
|
||||
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
||||
String encodedPassword = encoder.encode(rawPassword);
|
||||
admin.setPassword(encodedPassword);
|
||||
adminService.add(admin);
|
||||
return ResponseUtil.ok(admin);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:admin:read")
|
||||
@RequiresPermissionsDesc(menu={"系统管理" , "管理员管理"}, button="详情")
|
||||
@GetMapping("/read")
|
||||
public Object read(@NotNull Integer id) {
|
||||
DtsAdmin admin = adminService.findById(id);
|
||||
return ResponseUtil.ok(admin);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:admin:update")
|
||||
@RequiresPermissionsDesc(menu={"系统管理" , "管理员管理"}, button="编辑")
|
||||
@PostMapping("/update")
|
||||
public Object update(@RequestBody DtsAdmin admin) {
|
||||
Object error = validate(admin);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
|
||||
Integer anotherAdminId = admin.getId();
|
||||
if (anotherAdminId == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
String rawPassword = admin.getPassword();
|
||||
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
||||
String encodedPassword = encoder.encode(rawPassword);
|
||||
admin.setPassword(encodedPassword);
|
||||
|
||||
if (adminService.updateById(admin) == 0) {
|
||||
return ResponseUtil.updatedDataFailed();
|
||||
}
|
||||
|
||||
return ResponseUtil.ok(admin);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:admin:delete")
|
||||
@RequiresPermissionsDesc(menu={"系统管理" , "管理员管理"}, button="删除")
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody DtsAdmin admin) {
|
||||
Integer anotherAdminId = admin.getId();
|
||||
if (anotherAdminId == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
adminService.deleteById(anotherAdminId);
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,157 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import static com.qiguliuxing.dts.admin.util.AdminResponseCode.ADMIN_INVALID_ACCOUNT;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.authc.LockedAccountException;
|
||||
import org.apache.shiro.authc.UnknownAccountException;
|
||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||
import org.apache.shiro.authz.annotation.RequiresAuthentication;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.qiguliuxing.dts.admin.util.Permission;
|
||||
import com.qiguliuxing.dts.admin.util.PermissionUtil;
|
||||
import com.qiguliuxing.dts.core.util.JacksonUtil;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.db.domain.DtsAdmin;
|
||||
import com.qiguliuxing.dts.db.service.DtsPermissionService;
|
||||
import com.qiguliuxing.dts.db.service.DtsRoleService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/auth")
|
||||
@Validated
|
||||
public class AdminAuthController {
|
||||
private final Log logger = LogFactory.getLog(AdminAuthController.class);
|
||||
|
||||
@Autowired
|
||||
private DtsRoleService roleService;
|
||||
@Autowired
|
||||
private DtsPermissionService permissionService;
|
||||
|
||||
/*
|
||||
* { username : value, password : value }
|
||||
*/
|
||||
@PostMapping("/login")
|
||||
public Object login(@RequestBody String body) {
|
||||
String username = JacksonUtil.parseString(body, "username");
|
||||
String password = JacksonUtil.parseString(body, "password");
|
||||
|
||||
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
Subject currentUser = SecurityUtils.getSubject();
|
||||
try {
|
||||
currentUser.login(new UsernamePasswordToken(username, password));
|
||||
} catch (UnknownAccountException uae) {
|
||||
logger.error("用户帐号或密码不正确");
|
||||
return ResponseUtil.fail(ADMIN_INVALID_ACCOUNT, "用户帐号或密码不正确");
|
||||
} catch (LockedAccountException lae) {
|
||||
logger.error("用户帐号已锁定不可用");
|
||||
return ResponseUtil.fail(ADMIN_INVALID_ACCOUNT, "用户帐号已锁定不可用");
|
||||
|
||||
} catch (AuthenticationException ae) {
|
||||
logger.error("认证失败");
|
||||
return ResponseUtil.fail(ADMIN_INVALID_ACCOUNT, "认证失败");
|
||||
}
|
||||
return ResponseUtil.ok(currentUser.getSession().getId());
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
@RequiresAuthentication
|
||||
@PostMapping("/logout")
|
||||
public Object login() {
|
||||
Subject currentUser = SecurityUtils.getSubject();
|
||||
currentUser.logout();
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
|
||||
@RequiresAuthentication
|
||||
@GetMapping("/info")
|
||||
public Object info() {
|
||||
Subject currentUser = SecurityUtils.getSubject();
|
||||
DtsAdmin admin = (DtsAdmin) currentUser.getPrincipal();
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("name", admin.getUsername());
|
||||
data.put("avatar", admin.getAvatar());
|
||||
|
||||
Integer[] roleIds = admin.getRoleIds();
|
||||
Set<String> roles = roleService.queryByIds(roleIds);
|
||||
Set<String> permissions = permissionService.queryByRoleIds(roleIds);
|
||||
data.put("roles", roles);
|
||||
// NOTE
|
||||
// 这里需要转换perms结构,因为对于前端而已API形式的权限更容易理解
|
||||
data.put("perms", toAPI(permissions));
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
private HashMap<String, String> systemPermissionsMap = null;
|
||||
|
||||
private Collection<String> toAPI(Set<String> permissions) {
|
||||
if (systemPermissionsMap == null) {
|
||||
systemPermissionsMap = new HashMap<>();
|
||||
final String basicPackage = "com.qiguliuxing.dts.admin";
|
||||
List<Permission> systemPermissions = PermissionUtil.listPermission(context, basicPackage);
|
||||
for (Permission permission : systemPermissions) {
|
||||
String perm = permission.getRequiresPermissions().value()[0];
|
||||
String api = permission.getApi();
|
||||
systemPermissionsMap.put(perm, api);
|
||||
}
|
||||
}
|
||||
|
||||
Collection<String> apis = new HashSet<>();
|
||||
for (String perm : permissions) {
|
||||
String api = systemPermissionsMap.get(perm);
|
||||
apis.add(api);
|
||||
|
||||
if (perm.equals("*")) {
|
||||
apis.clear();
|
||||
apis.add("*");
|
||||
return apis;
|
||||
// return systemPermissionsMap.values();
|
||||
|
||||
}
|
||||
}
|
||||
return apis;
|
||||
}
|
||||
|
||||
@GetMapping("/401")
|
||||
public Object page401() {
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
@GetMapping("/index")
|
||||
public Object pageIndex() {
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
@GetMapping("/403")
|
||||
public Object page403() {
|
||||
return ResponseUtil.unauthz();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.core.validator.Order;
|
||||
import com.qiguliuxing.dts.core.validator.Sort;
|
||||
import com.qiguliuxing.dts.db.domain.DtsBrand;
|
||||
import com.qiguliuxing.dts.db.service.DtsBrandService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/brand")
|
||||
@Validated
|
||||
public class AdminBrandController {
|
||||
|
||||
@Autowired
|
||||
private DtsBrandService brandService;
|
||||
|
||||
@RequiresPermissions("admin:brand:list")
|
||||
@RequiresPermissionsDesc(menu={"商场管理" , "品牌管理"}, button="查询")
|
||||
@GetMapping("/list")
|
||||
public Object list(String id, String name,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
List<DtsBrand> brandList = brandService.querySelective(id, name, page, limit, sort, order);
|
||||
long total = PageInfo.of(brandList).getTotal();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", brandList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
private Object validate(DtsBrand brand) {
|
||||
String name = brand.getName();
|
||||
if (StringUtils.isEmpty(name)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
String desc = brand.getDesc();
|
||||
if (StringUtils.isEmpty(desc)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
BigDecimal price = brand.getFloorPrice();
|
||||
if (price == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:brand:create")
|
||||
@RequiresPermissionsDesc(menu={"商场管理" , "品牌管理"}, button="添加")
|
||||
@PostMapping("/create")
|
||||
public Object create(@RequestBody DtsBrand brand) {
|
||||
Object error = validate(brand);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
brandService.add(brand);
|
||||
return ResponseUtil.ok(brand);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:brand:read")
|
||||
@RequiresPermissionsDesc(menu={"商场管理" , "品牌管理"}, button="详情")
|
||||
@GetMapping("/read")
|
||||
public Object read(@NotNull Integer id) {
|
||||
DtsBrand brand = brandService.findById(id);
|
||||
return ResponseUtil.ok(brand);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:brand:update")
|
||||
@RequiresPermissionsDesc(menu={"商场管理" , "品牌管理"}, button="编辑")
|
||||
@PostMapping("/update")
|
||||
public Object update(@RequestBody DtsBrand brand) {
|
||||
Object error = validate(brand);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
if (brandService.updateById(brand) == 0) {
|
||||
return ResponseUtil.updatedDataFailed();
|
||||
}
|
||||
return ResponseUtil.ok(brand);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:brand:delete")
|
||||
@RequiresPermissionsDesc(menu={"商场管理" , "品牌管理"}, button="删除")
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody DtsBrand brand) {
|
||||
Integer id = brand.getId();
|
||||
if (id == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
brandService.deleteById(id);
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,137 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.core.validator.Order;
|
||||
import com.qiguliuxing.dts.core.validator.Sort;
|
||||
import com.qiguliuxing.dts.db.domain.DtsCategory;
|
||||
import com.qiguliuxing.dts.db.service.DtsCategoryService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/category")
|
||||
@Validated
|
||||
public class AdminCategoryController {
|
||||
|
||||
@Autowired
|
||||
private DtsCategoryService categoryService;
|
||||
|
||||
@RequiresPermissions("admin:category:list")
|
||||
@RequiresPermissionsDesc(menu={"商场管理" , "类目管理"}, button="查询")
|
||||
@GetMapping("/list")
|
||||
public Object list(String id, String name,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
List<DtsCategory> collectList = categoryService.querySelective(id, name, page, limit, sort, order);
|
||||
long total = PageInfo.of(collectList).getTotal();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", collectList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
private Object validate(DtsCategory category) {
|
||||
String name = category.getName();
|
||||
if (StringUtils.isEmpty(name)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
String level = category.getLevel();
|
||||
if (StringUtils.isEmpty(level)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
if (!level.equals("L1") && !level.equals("L2")) {
|
||||
return ResponseUtil.badArgumentValue();
|
||||
}
|
||||
|
||||
Integer pid = category.getPid();
|
||||
if (level.equals("L2") && (pid == null)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:category:create")
|
||||
@RequiresPermissionsDesc(menu={"商场管理" , "类目管理"}, button="添加")
|
||||
@PostMapping("/create")
|
||||
public Object create(@RequestBody DtsCategory category) {
|
||||
Object error = validate(category);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
categoryService.add(category);
|
||||
return ResponseUtil.ok(category);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:category:read")
|
||||
@RequiresPermissionsDesc(menu={"商场管理" , "类目管理"}, button="详情")
|
||||
@GetMapping("/read")
|
||||
public Object read(@NotNull Integer id) {
|
||||
DtsCategory category = categoryService.findById(id);
|
||||
return ResponseUtil.ok(category);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:category:update")
|
||||
@RequiresPermissionsDesc(menu={"商场管理" , "类目管理"}, button="编辑")
|
||||
@PostMapping("/update")
|
||||
public Object update(@RequestBody DtsCategory category) {
|
||||
Object error = validate(category);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (categoryService.updateById(category) == 0) {
|
||||
return ResponseUtil.updatedDataFailed();
|
||||
}
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:category:delete")
|
||||
@RequiresPermissionsDesc(menu={"商场管理" , "类目管理"}, button="删除")
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody DtsCategory category) {
|
||||
Integer id = category.getId();
|
||||
if (id == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
categoryService.deleteById(id);
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:category:list")
|
||||
@GetMapping("/l1")
|
||||
public Object catL1() {
|
||||
// 所有一级分类目录
|
||||
List<DtsCategory> l1CatList = categoryService.queryL1();
|
||||
List<Map<String, Object>> data = new ArrayList<>(l1CatList.size());
|
||||
for (DtsCategory category : l1CatList) {
|
||||
Map<String, Object> d = new HashMap<>(2);
|
||||
d.put("value", category.getId());
|
||||
d.put("label", category.getName());
|
||||
data.add(d);
|
||||
}
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.core.validator.Order;
|
||||
import com.qiguliuxing.dts.core.validator.Sort;
|
||||
import com.qiguliuxing.dts.db.domain.DtsCollect;
|
||||
import com.qiguliuxing.dts.db.service.DtsCollectService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/collect")
|
||||
@Validated
|
||||
public class AdminCollectController {
|
||||
|
||||
@Autowired
|
||||
private DtsCollectService collectService;
|
||||
|
||||
|
||||
@RequiresPermissions("admin:collect:list")
|
||||
@RequiresPermissionsDesc(menu={"用户管理" , "用户收藏"}, button="查询")
|
||||
@GetMapping("/list")
|
||||
public Object list(String userId, String valueId,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
List<DtsCollect> collectList = collectService.querySelective(userId, valueId, page, limit, sort, order);
|
||||
long total = PageInfo.of(collectList).getTotal();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", collectList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.core.validator.Order;
|
||||
import com.qiguliuxing.dts.core.validator.Sort;
|
||||
import com.qiguliuxing.dts.db.domain.DtsComment;
|
||||
import com.qiguliuxing.dts.db.service.DtsCommentService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/comment")
|
||||
@Validated
|
||||
public class AdminCommentController {
|
||||
|
||||
@Autowired
|
||||
private DtsCommentService commentService;
|
||||
|
||||
@RequiresPermissions("admin:comment:list")
|
||||
@RequiresPermissionsDesc(menu={"商品管理" , "评论管理"}, button="查询")
|
||||
@GetMapping("/list")
|
||||
public Object list(String userId, String valueId,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
List<DtsComment> brandList = commentService.querySelective(userId, valueId, page, limit, sort, order);
|
||||
long total = PageInfo.of(brandList).getTotal();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", brandList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:comment:delete")
|
||||
@RequiresPermissionsDesc(menu={"商品管理" , "评论管理"}, button="删除")
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody DtsComment comment) {
|
||||
Integer id = comment.getId();
|
||||
if (id == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
commentService.deleteById(id);
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,132 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.core.validator.Order;
|
||||
import com.qiguliuxing.dts.core.validator.Sort;
|
||||
import com.qiguliuxing.dts.db.domain.DtsCoupon;
|
||||
import com.qiguliuxing.dts.db.domain.DtsCouponUser;
|
||||
import com.qiguliuxing.dts.db.service.DtsCouponService;
|
||||
import com.qiguliuxing.dts.db.service.DtsCouponUserService;
|
||||
import com.qiguliuxing.dts.db.util.CouponConstant;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/coupon")
|
||||
@Validated
|
||||
public class AdminCouponController {
|
||||
|
||||
@Autowired
|
||||
private DtsCouponService couponService;
|
||||
@Autowired
|
||||
private DtsCouponUserService couponUserService;
|
||||
|
||||
@RequiresPermissions("admin:coupon:list")
|
||||
@RequiresPermissionsDesc(menu={"推广管理" , "优惠券管理"}, button="查询")
|
||||
@GetMapping("/list")
|
||||
public Object list(String name, Short type, Short status,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
List<DtsCoupon> couponList = couponService.querySelective(name, type, status, page, limit, sort, order);
|
||||
long total = PageInfo.of(couponList).getTotal();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", couponList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:coupon:listuser")
|
||||
@RequiresPermissionsDesc(menu={"推广管理" , "优惠券管理"}, button="查询用户")
|
||||
@GetMapping("/listuser")
|
||||
public Object listuser(Integer userId, Integer couponId, Short status,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
List<DtsCouponUser> couponList = couponUserService.queryList(userId, couponId, status, page, limit, sort, order);
|
||||
long total = PageInfo.of(couponList).getTotal();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", couponList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
private Object validate(DtsCoupon coupon) {
|
||||
String name = coupon.getName();
|
||||
if(StringUtils.isEmpty(name)){
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:coupon:create")
|
||||
@RequiresPermissionsDesc(menu={"推广管理" , "优惠券管理"}, button="添加")
|
||||
@PostMapping("/create")
|
||||
public Object create(@RequestBody DtsCoupon coupon) {
|
||||
Object error = validate(coupon);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
|
||||
// 如果是兑换码类型,则这里需要生存一个兑换码
|
||||
if (coupon.getType().equals(CouponConstant.TYPE_CODE)){
|
||||
String code = couponService.generateCode();
|
||||
coupon.setCode(code);
|
||||
}
|
||||
|
||||
couponService.add(coupon);
|
||||
return ResponseUtil.ok(coupon);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:coupon:read")
|
||||
@RequiresPermissionsDesc(menu={"推广管理" , "优惠券管理"}, button="详情")
|
||||
@GetMapping("/read")
|
||||
public Object read(@NotNull Integer id) {
|
||||
DtsCoupon coupon = couponService.findById(id);
|
||||
return ResponseUtil.ok(coupon);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:coupon:update")
|
||||
@RequiresPermissionsDesc(menu={"推广管理" , "优惠券管理"}, button="编辑")
|
||||
@PostMapping("/update")
|
||||
public Object update(@RequestBody DtsCoupon coupon) {
|
||||
Object error = validate(coupon);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
if (couponService.updateById(coupon) == 0) {
|
||||
return ResponseUtil.updatedDataFailed();
|
||||
}
|
||||
return ResponseUtil.ok(coupon);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:coupon:delete")
|
||||
@RequiresPermissionsDesc(menu={"推广管理" , "优惠券管理"}, button="删除")
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody DtsCoupon coupon) {
|
||||
couponService.deleteById(coupon.getId());
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.db.service.DtsGoodsProductService;
|
||||
import com.qiguliuxing.dts.db.service.DtsGoodsService;
|
||||
import com.qiguliuxing.dts.db.service.DtsOrderService;
|
||||
import com.qiguliuxing.dts.db.service.DtsUserService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/dashboard")
|
||||
@Validated
|
||||
public class AdminDashbordController {
|
||||
|
||||
@Autowired
|
||||
private DtsUserService userService;
|
||||
@Autowired
|
||||
private DtsGoodsService goodsService;
|
||||
@Autowired
|
||||
private DtsGoodsProductService productService;
|
||||
@Autowired
|
||||
private DtsOrderService orderService;
|
||||
|
||||
@GetMapping("")
|
||||
public Object info() {
|
||||
int userTotal = userService.count();
|
||||
int goodsTotal = goodsService.count();
|
||||
int productTotal = productService.count();
|
||||
int orderTotal = orderService.count();
|
||||
Map<String, Integer> data = new HashMap<>();
|
||||
data.put("userTotal", userTotal);
|
||||
data.put("goodsTotal", goodsTotal);
|
||||
data.put("productTotal", productTotal);
|
||||
data.put("orderTotal", orderTotal);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.core.validator.Order;
|
||||
import com.qiguliuxing.dts.core.validator.Sort;
|
||||
import com.qiguliuxing.dts.db.domain.DtsFeedback;
|
||||
import com.qiguliuxing.dts.db.service.DtsFeedbackService;
|
||||
|
||||
/**
|
||||
* @author qiguliuxing
|
||||
* @date 2018/8/26 1:11
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admin/feedback")
|
||||
@Validated
|
||||
public class AdminFeedbackController {
|
||||
|
||||
@Autowired
|
||||
private DtsFeedbackService feedbackService;
|
||||
|
||||
@RequiresPermissions("admin:feedback:list")
|
||||
@RequiresPermissionsDesc(menu={"用户管理" , "意见反馈"}, button="查询")
|
||||
@GetMapping("/list")
|
||||
public Object list(Integer userId, String username,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
List<DtsFeedback> feedbackList = feedbackService.querySelective(userId, username, page, limit, sort, order);
|
||||
long total = PageInfo.of(feedbackList).getTotal();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", feedbackList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.core.validator.Order;
|
||||
import com.qiguliuxing.dts.core.validator.Sort;
|
||||
import com.qiguliuxing.dts.db.domain.DtsFootprint;
|
||||
import com.qiguliuxing.dts.db.service.DtsFootprintService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/footprint")
|
||||
@Validated
|
||||
public class AdminFootprintController {
|
||||
|
||||
@Autowired
|
||||
private DtsFootprintService footprintService;
|
||||
|
||||
@RequiresPermissions("admin:footprint:list")
|
||||
@RequiresPermissionsDesc(menu={"用户管理" , "用户足迹"}, button="查询")
|
||||
@GetMapping("/list")
|
||||
public Object list(String userId, String goodsId,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
List<DtsFootprint> footprintList = footprintService.querySelective(userId, goodsId, page, limit, sort, order);
|
||||
long total = PageInfo.of(footprintList).getTotal();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", footprintList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.admin.dao.GoodsAllinone;
|
||||
import com.qiguliuxing.dts.admin.service.AdminGoodsService;
|
||||
import com.qiguliuxing.dts.core.validator.Order;
|
||||
import com.qiguliuxing.dts.core.validator.Sort;
|
||||
import com.qiguliuxing.dts.db.domain.DtsGoods;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/goods")
|
||||
@Validated
|
||||
public class AdminGoodsController {
|
||||
|
||||
@Autowired
|
||||
private AdminGoodsService adminGoodsService;
|
||||
|
||||
/**
|
||||
* 查询商品
|
||||
*
|
||||
* @param goodsSn
|
||||
* @param name
|
||||
* @param page
|
||||
* @param limit
|
||||
* @param sort
|
||||
* @param order
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("admin:goods:list")
|
||||
@RequiresPermissionsDesc(menu = {"商品管理", "商品管理"}, button = "查询")
|
||||
@GetMapping("/list")
|
||||
public Object list(String goodsSn, String name,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
return adminGoodsService.list(goodsSn, name, page, limit, sort, order);
|
||||
}
|
||||
|
||||
@GetMapping("/catAndBrand")
|
||||
public Object list2() {
|
||||
return adminGoodsService.list2();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑商品
|
||||
*
|
||||
* @param goodsAllinone
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("admin:goods:update")
|
||||
@RequiresPermissionsDesc(menu = {"商品管理", "商品管理"}, button = "编辑")
|
||||
@PostMapping("/update")
|
||||
public Object update(@RequestBody GoodsAllinone goodsAllinone) {
|
||||
return adminGoodsService.update(goodsAllinone);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品
|
||||
*
|
||||
* @param goods
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("admin:goods:delete")
|
||||
@RequiresPermissionsDesc(menu = {"商品管理", "商品管理"}, button = "删除")
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody DtsGoods goods) {
|
||||
return adminGoodsService.delete(goods);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加商品
|
||||
*
|
||||
* @param goodsAllinone
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("admin:goods:create")
|
||||
@RequiresPermissionsDesc(menu = {"商品管理", "商品管理"}, button = "上架")
|
||||
@PostMapping("/create")
|
||||
public Object create(@RequestBody GoodsAllinone goodsAllinone) {
|
||||
return adminGoodsService.create(goodsAllinone);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品详情
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("admin:goods:read")
|
||||
@RequiresPermissionsDesc(menu = {"商品管理", "商品管理"}, button = "详情")
|
||||
@GetMapping("/detail")
|
||||
public Object detail(@NotNull Integer id) {
|
||||
return adminGoodsService.detail(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,179 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.core.validator.Order;
|
||||
import com.qiguliuxing.dts.core.validator.Sort;
|
||||
import com.qiguliuxing.dts.db.domain.DtsGoods;
|
||||
import com.qiguliuxing.dts.db.domain.DtsGroupon;
|
||||
import com.qiguliuxing.dts.db.domain.DtsGrouponRules;
|
||||
import com.qiguliuxing.dts.db.service.DtsGoodsService;
|
||||
import com.qiguliuxing.dts.db.service.DtsGrouponRulesService;
|
||||
import com.qiguliuxing.dts.db.service.DtsGrouponService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/groupon")
|
||||
@Validated
|
||||
public class AdminGrouponController {
|
||||
|
||||
@Autowired
|
||||
private DtsGrouponRulesService rulesService;
|
||||
@Autowired
|
||||
private DtsGoodsService goodsService;
|
||||
@Autowired
|
||||
private DtsGrouponService grouponService;
|
||||
|
||||
@RequiresPermissions("admin:groupon:read")
|
||||
@RequiresPermissionsDesc(menu={"推广管理" , "团购管理"}, button="详情")
|
||||
@GetMapping("/listRecord")
|
||||
public Object listRecord(String grouponId,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
List<DtsGroupon> grouponList = grouponService.querySelective(grouponId, page, limit, sort, order);
|
||||
long total = PageInfo.of(grouponList).getTotal();
|
||||
|
||||
List<Map<String, Object>> records = new ArrayList<>();
|
||||
for (DtsGroupon groupon : grouponList) {
|
||||
try {
|
||||
Map<String, Object> RecordData = new HashMap<>();
|
||||
List<DtsGroupon> subGrouponList = grouponService.queryJoinRecord(groupon.getId());
|
||||
DtsGrouponRules rules = rulesService.queryById(groupon.getRulesId());
|
||||
DtsGoods goods = goodsService.findById(rules.getGoodsId());
|
||||
|
||||
RecordData.put("groupon", groupon);
|
||||
RecordData.put("subGroupons", subGrouponList);
|
||||
RecordData.put("rules", rules);
|
||||
RecordData.put("goods", goods);
|
||||
|
||||
records.add(RecordData);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", records);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:groupon:list")
|
||||
@RequiresPermissionsDesc(menu={"推广管理" , "团购管理"}, button="查询")
|
||||
@GetMapping("/list")
|
||||
public Object list(String goodsId,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
List<DtsGrouponRules> rulesList = rulesService.querySelective(goodsId, page, limit, sort, order);
|
||||
long total = PageInfo.of(rulesList).getTotal();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", rulesList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
private Object validate(DtsGrouponRules grouponRules) {
|
||||
Integer goodsId = grouponRules.getGoodsId();
|
||||
if (goodsId == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
BigDecimal discount = grouponRules.getDiscount();
|
||||
if (discount == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
Integer discountMember = grouponRules.getDiscountMember();
|
||||
if (discountMember == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
LocalDateTime expireTime = grouponRules.getExpireTime();
|
||||
if (expireTime == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:groupon:update")
|
||||
@RequiresPermissionsDesc(menu={"推广管理" , "团购管理"}, button="编辑")
|
||||
@PostMapping("/update")
|
||||
public Object update(@RequestBody DtsGrouponRules grouponRules) {
|
||||
Object error = validate(grouponRules);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
|
||||
Integer goodsId = grouponRules.getGoodsId();
|
||||
DtsGoods goods = goodsService.findById(goodsId);
|
||||
if (goods == null) {
|
||||
return ResponseUtil.badArgumentValue();
|
||||
}
|
||||
|
||||
grouponRules.setGoodsName(goods.getName());
|
||||
grouponRules.setPicUrl(goods.getPicUrl());
|
||||
|
||||
if (rulesService.updateById(grouponRules) == 0) {
|
||||
return ResponseUtil.updatedDataFailed();
|
||||
}
|
||||
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:groupon:create")
|
||||
@RequiresPermissionsDesc(menu={"推广管理" , "团购管理"}, button="添加")
|
||||
@PostMapping("/create")
|
||||
public Object create(@RequestBody DtsGrouponRules grouponRules) {
|
||||
Object error = validate(grouponRules);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
|
||||
Integer goodsId = grouponRules.getGoodsId();
|
||||
DtsGoods goods = goodsService.findById(goodsId);
|
||||
if (goods == null) {
|
||||
return ResponseUtil.badArgumentValue();
|
||||
}
|
||||
|
||||
grouponRules.setGoodsName(goods.getName());
|
||||
grouponRules.setPicUrl(goods.getPicUrl());
|
||||
|
||||
rulesService.createRules(grouponRules);
|
||||
|
||||
return ResponseUtil.ok(grouponRules);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:groupon:delete")
|
||||
@RequiresPermissionsDesc(menu={"推广管理" , "团购管理"}, button="删除")
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody DtsGrouponRules grouponRules) {
|
||||
Integer id = grouponRules.getId();
|
||||
if (id == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
rulesService.delete(id);
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.core.validator.Order;
|
||||
import com.qiguliuxing.dts.core.validator.Sort;
|
||||
import com.qiguliuxing.dts.db.domain.DtsSearchHistory;
|
||||
import com.qiguliuxing.dts.db.service.DtsSearchHistoryService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/history")
|
||||
public class AdminHistoryController {
|
||||
|
||||
@Autowired
|
||||
private DtsSearchHistoryService searchHistoryService;
|
||||
|
||||
@RequiresPermissions("admin:history:list")
|
||||
@RequiresPermissionsDesc(menu={"用户管理" , "搜索历史"}, button="查询")
|
||||
@GetMapping("/list")
|
||||
public Object list(String userId, String keyword,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
List<DtsSearchHistory> footprintList = searchHistoryService.querySelective(userId, keyword, page, limit, sort, order);
|
||||
long total = PageInfo.of(footprintList).getTotal();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", footprintList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresAuthentication;
|
||||
import org.apache.shiro.authz.annotation.RequiresGuest;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import org.apache.shiro.authz.annotation.RequiresUser;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/index")
|
||||
public class AdminIndexController {
|
||||
|
||||
@RequestMapping("/index")
|
||||
public Object index() {
|
||||
return ResponseUtil.ok("hello world, this is admin service");
|
||||
}
|
||||
|
||||
@RequiresGuest
|
||||
@RequestMapping("/guest")
|
||||
public Object guest() {
|
||||
return ResponseUtil.ok("hello world, this is admin service");
|
||||
}
|
||||
|
||||
@RequiresAuthentication
|
||||
@RequestMapping("/authn")
|
||||
public Object authn() {
|
||||
return ResponseUtil.ok("hello world, this is admin service");
|
||||
}
|
||||
|
||||
@RequiresUser
|
||||
@RequestMapping("/user")
|
||||
public Object user() {
|
||||
return ResponseUtil.ok("hello world, this is admin service");
|
||||
}
|
||||
|
||||
@RequiresRoles("admin")
|
||||
@RequestMapping("/admin")
|
||||
public Object admin() {
|
||||
return ResponseUtil.ok("hello world, this is admin service");
|
||||
}
|
||||
|
||||
@RequiresRoles("admin2")
|
||||
@RequestMapping("/admin2")
|
||||
public Object admin2() {
|
||||
return ResponseUtil.ok("hello world, this is admin service");
|
||||
}
|
||||
|
||||
@RequiresPermissions("index:permission:read")
|
||||
@RequiresPermissionsDesc(menu={"其他" , "权限测试"}, button="权限读")
|
||||
@GetMapping("/read")
|
||||
public Object read() {
|
||||
return ResponseUtil.ok("hello world, this is admin service");
|
||||
}
|
||||
|
||||
@RequiresPermissions("index:permission:write")
|
||||
@RequiresPermissionsDesc(menu={"其他" , "权限测试"}, button="权限写")
|
||||
@PostMapping("/write")
|
||||
public Object write() {
|
||||
return ResponseUtil.ok("hello world, this is admin service");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.core.validator.Order;
|
||||
import com.qiguliuxing.dts.core.validator.Sort;
|
||||
import com.qiguliuxing.dts.db.domain.DtsIssue;
|
||||
import com.qiguliuxing.dts.db.service.DtsIssueService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/issue")
|
||||
@Validated
|
||||
public class AdminIssueController {
|
||||
|
||||
@Autowired
|
||||
private DtsIssueService issueService;
|
||||
|
||||
@RequiresPermissions("admin:issue:list")
|
||||
@RequiresPermissionsDesc(menu={"商场管理" , "通用问题"}, button="查询")
|
||||
@GetMapping("/list")
|
||||
public Object list(String question,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
List<DtsIssue> issueList = issueService.querySelective(question, page, limit, sort, order);
|
||||
long total = PageInfo.of(issueList).getTotal();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", issueList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
private Object validate(DtsIssue issue) {
|
||||
String question = issue.getQuestion();
|
||||
if (StringUtils.isEmpty(question)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
String answer = issue.getAnswer();
|
||||
if (StringUtils.isEmpty(answer)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:issue:create")
|
||||
@RequiresPermissionsDesc(menu={"商场管理" , "通用问题"}, button="添加")
|
||||
@PostMapping("/create")
|
||||
public Object create(@RequestBody DtsIssue issue) {
|
||||
Object error = validate(issue);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
issueService.add(issue);
|
||||
return ResponseUtil.ok(issue);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:issue:read")
|
||||
@GetMapping("/read")
|
||||
public Object read(@NotNull Integer id) {
|
||||
DtsIssue issue = issueService.findById(id);
|
||||
return ResponseUtil.ok(issue);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:issue:update")
|
||||
@RequiresPermissionsDesc(menu={"商场管理" , "通用问题"}, button="编辑")
|
||||
@PostMapping("/update")
|
||||
public Object update(@RequestBody DtsIssue issue) {
|
||||
Object error = validate(issue);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
if (issueService.updateById(issue) == 0) {
|
||||
return ResponseUtil.updatedDataFailed();
|
||||
}
|
||||
|
||||
return ResponseUtil.ok(issue);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:issue:delete")
|
||||
@RequiresPermissionsDesc(menu={"商场管理" , "通用问题"}, button="删除")
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody DtsIssue issue) {
|
||||
Integer id = issue.getId();
|
||||
if (id == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
issueService.deleteById(id);
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.core.validator.Order;
|
||||
import com.qiguliuxing.dts.core.validator.Sort;
|
||||
import com.qiguliuxing.dts.db.domain.DtsKeyword;
|
||||
import com.qiguliuxing.dts.db.service.DtsKeywordService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/keyword")
|
||||
@Validated
|
||||
public class AdminKeywordController {
|
||||
|
||||
@Autowired
|
||||
private DtsKeywordService keywordService;
|
||||
|
||||
@RequiresPermissions("admin:keyword:list")
|
||||
@RequiresPermissionsDesc(menu={"商场管理" , "关键词"}, button="查询")
|
||||
@GetMapping("/list")
|
||||
public Object list(String keyword, String url,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
List<DtsKeyword> brandList = keywordService.querySelective(keyword, url, page, limit, sort, order);
|
||||
long total = PageInfo.of(brandList).getTotal();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", brandList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
private Object validate(DtsKeyword keywords) {
|
||||
String keyword = keywords.getKeyword();
|
||||
if (StringUtils.isEmpty(keyword)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
String url = keywords.getUrl();
|
||||
if (StringUtils.isEmpty(url)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:keyword:create")
|
||||
@RequiresPermissionsDesc(menu={"商场管理" , "关键词"}, button="添加")
|
||||
@PostMapping("/create")
|
||||
public Object create(@RequestBody DtsKeyword keywords) {
|
||||
Object error = validate(keywords);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
keywordService.add(keywords);
|
||||
return ResponseUtil.ok(keywords);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:keyword:read")
|
||||
@RequiresPermissionsDesc(menu={"商场管理" , "关键词"}, button="详情")
|
||||
@GetMapping("/read")
|
||||
public Object read(@NotNull Integer id) {
|
||||
DtsKeyword brand = keywordService.findById(id);
|
||||
return ResponseUtil.ok(brand);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:keyword:update")
|
||||
@RequiresPermissionsDesc(menu={"商场管理" , "关键词"}, button="编辑")
|
||||
@PostMapping("/update")
|
||||
public Object update(@RequestBody DtsKeyword keywords) {
|
||||
Object error = validate(keywords);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
if (keywordService.updateById(keywords) == 0) {
|
||||
return ResponseUtil.updatedDataFailed();
|
||||
}
|
||||
return ResponseUtil.ok(keywords);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:keyword:delete")
|
||||
@RequiresPermissionsDesc(menu={"商场管理" , "关键词"}, button="删除")
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody DtsKeyword keyword) {
|
||||
Integer id = keyword.getId();
|
||||
if (id == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
keywordService.deleteById(id);
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.admin.service.AdminOrderService;
|
||||
import com.qiguliuxing.dts.core.validator.Order;
|
||||
import com.qiguliuxing.dts.core.validator.Sort;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/order")
|
||||
@Validated
|
||||
public class AdminOrderController {
|
||||
|
||||
@Autowired
|
||||
private AdminOrderService adminOrderService;
|
||||
|
||||
/**
|
||||
* 查询订单
|
||||
*
|
||||
* @param userId
|
||||
* @param orderSn
|
||||
* @param orderStatusArray
|
||||
* @param page
|
||||
* @param limit
|
||||
* @param sort
|
||||
* @param order
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("admin:order:list")
|
||||
@RequiresPermissionsDesc(menu = {"商场管理", "订单管理"}, button = "查询")
|
||||
@GetMapping("/list")
|
||||
public Object list(Integer userId, String orderSn,
|
||||
@RequestParam(required = false) List<Short> orderStatusArray,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
return adminOrderService.list(userId, orderSn, orderStatusArray, page, limit, sort, order);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单详情
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("admin:order:read")
|
||||
@RequiresPermissionsDesc(menu = {"商场管理", "订单管理"}, button = "详情")
|
||||
@GetMapping("/detail")
|
||||
public Object detail(@NotNull Integer id) {
|
||||
return adminOrderService.detail(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单退款
|
||||
*
|
||||
* @param body 订单信息,{ orderId:xxx }
|
||||
* @return 订单退款操作结果
|
||||
*/
|
||||
@RequiresPermissions("admin:order:refund")
|
||||
@RequiresPermissionsDesc(menu = {"商场管理", "订单管理"}, button = "订单退款")
|
||||
@PostMapping("/refund")
|
||||
public Object refund(@RequestBody String body) {
|
||||
return adminOrderService.refund(body);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发货
|
||||
*
|
||||
* @param body 订单信息,{ orderId:xxx, shipSn: xxx, shipChannel: xxx }
|
||||
* @return 订单操作结果
|
||||
*/
|
||||
@RequiresPermissions("admin:order:ship")
|
||||
@RequiresPermissionsDesc(menu = {"商场管理", "订单管理"}, button = "订单发货")
|
||||
@PostMapping("/ship")
|
||||
public Object ship(@RequestBody String body) {
|
||||
return adminOrderService.ship(body);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 回复订单商品
|
||||
*
|
||||
* @param body 订单信息,{ orderId:xxx }
|
||||
* @return 订单操作结果
|
||||
*/
|
||||
@RequiresPermissions("admin:order:reply")
|
||||
@RequiresPermissionsDesc(menu = {"商场管理", "订单管理"}, button = "订单商品回复")
|
||||
@PostMapping("/reply")
|
||||
public Object reply(@RequestBody String body) {
|
||||
return adminOrderService.reply(body);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import static com.qiguliuxing.dts.admin.util.AdminResponseCode.ADMIN_INVALID_ACCOUNT;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresAuthentication;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.qiguliuxing.dts.core.util.JacksonUtil;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.core.util.bcrypt.BCryptPasswordEncoder;
|
||||
import com.qiguliuxing.dts.db.domain.DtsAdmin;
|
||||
import com.qiguliuxing.dts.db.service.DtsAdminService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/profile")
|
||||
@Validated
|
||||
public class AdminProfileController {
|
||||
|
||||
@Autowired
|
||||
private DtsAdminService adminService;
|
||||
|
||||
@RequiresAuthentication
|
||||
@PostMapping("/password")
|
||||
public Object create(@RequestBody String body) {
|
||||
String oldPassword = JacksonUtil.parseString(body, "oldPassword");
|
||||
String newPassword = JacksonUtil.parseString(body, "newPassword");
|
||||
if (StringUtils.isEmpty(oldPassword)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
if (StringUtils.isEmpty(newPassword)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
Subject currentUser = SecurityUtils.getSubject();
|
||||
DtsAdmin admin = (DtsAdmin) currentUser.getPrincipal();
|
||||
|
||||
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
||||
if (!encoder.matches(oldPassword, admin.getPassword())) {
|
||||
return ResponseUtil.fail(ADMIN_INVALID_ACCOUNT, "账号密码不对");
|
||||
}
|
||||
|
||||
String encodedNewPassword = encoder.encode(newPassword);
|
||||
admin.setPassword(encodedNewPassword);
|
||||
|
||||
adminService.updateById(admin);
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.core.validator.Order;
|
||||
import com.qiguliuxing.dts.core.validator.Sort;
|
||||
import com.qiguliuxing.dts.db.domain.DtsRegion;
|
||||
import com.qiguliuxing.dts.db.service.DtsRegionService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/region")
|
||||
@Validated
|
||||
public class AdminRegionController {
|
||||
|
||||
@Autowired
|
||||
private DtsRegionService regionService;
|
||||
|
||||
@GetMapping("/clist")
|
||||
public Object clist(@NotNull Integer id) {
|
||||
List<DtsRegion> regionList = regionService.queryByPid(id);
|
||||
return ResponseUtil.ok(regionList);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public Object list(String name, Integer code,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort(accepts = {"id"}) @RequestParam(defaultValue = "id") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
List<DtsRegion> regionList = regionService.querySelective(name, code, page, limit, sort, order);
|
||||
long total = PageInfo.of(regionList).getTotal();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", regionList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,225 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import static com.qiguliuxing.dts.admin.util.AdminResponseCode.ROLE_NAME_EXIST;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.admin.util.AdminResponseCode;
|
||||
import com.qiguliuxing.dts.admin.util.PermVo;
|
||||
import com.qiguliuxing.dts.admin.util.Permission;
|
||||
import com.qiguliuxing.dts.admin.util.PermissionUtil;
|
||||
import com.qiguliuxing.dts.core.util.JacksonUtil;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.core.validator.Order;
|
||||
import com.qiguliuxing.dts.core.validator.Sort;
|
||||
import com.qiguliuxing.dts.db.domain.DtsPermission;
|
||||
import com.qiguliuxing.dts.db.domain.DtsRole;
|
||||
import com.qiguliuxing.dts.db.service.DtsPermissionService;
|
||||
import com.qiguliuxing.dts.db.service.DtsRoleService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/role")
|
||||
@Validated
|
||||
public class AdminRoleController {
|
||||
|
||||
@Autowired
|
||||
private DtsRoleService roleService;
|
||||
@Autowired
|
||||
private DtsPermissionService permissionService;
|
||||
|
||||
@RequiresPermissions("admin:role:list")
|
||||
@RequiresPermissionsDesc(menu={"系统管理" , "角色管理"}, button="角色查询")
|
||||
@GetMapping("/list")
|
||||
public Object list(String name,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
List<DtsRole> roleList = roleService.querySelective(name, page, limit, sort, order);
|
||||
long total = PageInfo.of(roleList).getTotal();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", roleList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
@GetMapping("/options")
|
||||
public Object options(){
|
||||
List<DtsRole> roleList = roleService.queryAll();
|
||||
|
||||
List<Map<String, Object>> options = new ArrayList<>(roleList.size());
|
||||
for (DtsRole role : roleList) {
|
||||
Map<String, Object> option = new HashMap<>(2);
|
||||
option.put("value", role.getId());
|
||||
option.put("label", role.getName());
|
||||
options.add(option);
|
||||
}
|
||||
|
||||
return ResponseUtil.ok(options);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:role:read")
|
||||
@RequiresPermissionsDesc(menu={"系统管理" , "角色管理"}, button="角色详情")
|
||||
@GetMapping("/read")
|
||||
public Object read(@NotNull Integer id) {
|
||||
DtsRole role = roleService.findById(id);
|
||||
return ResponseUtil.ok(role);
|
||||
}
|
||||
|
||||
|
||||
private Object validate(DtsRole role) {
|
||||
String name = role.getName();
|
||||
if (StringUtils.isEmpty(name)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:role:create")
|
||||
@RequiresPermissionsDesc(menu={"系统管理" , "角色管理"}, button="角色添加")
|
||||
@PostMapping("/create")
|
||||
public Object create(@RequestBody DtsRole role) {
|
||||
Object error = validate(role);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (roleService.checkExist(role.getName())){
|
||||
return ResponseUtil.fail(ROLE_NAME_EXIST, "角色已经存在");
|
||||
}
|
||||
|
||||
roleService.add(role);
|
||||
|
||||
return ResponseUtil.ok(role);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:role:update")
|
||||
@RequiresPermissionsDesc(menu={"系统管理" , "角色管理"}, button="角色编辑")
|
||||
@PostMapping("/update")
|
||||
public Object update(@RequestBody DtsRole role) {
|
||||
Object error = validate(role);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
|
||||
roleService.updateById(role);
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:role:delete")
|
||||
@RequiresPermissionsDesc(menu={"系统管理" , "角色管理"}, button="角色删除")
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody DtsRole role) {
|
||||
Integer id = role.getId();
|
||||
if (id == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
roleService.deleteById(id);
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
private List<PermVo> systemPermissions = null;
|
||||
private Set<String> systemPermissionsString = null;
|
||||
|
||||
private List<PermVo> getSystemPermissions(){
|
||||
final String basicPackage = "com.qiguliuxing.dts.admin";
|
||||
if(systemPermissions == null){
|
||||
List<Permission> permissions = PermissionUtil.listPermission(context, basicPackage);
|
||||
systemPermissions = PermissionUtil.listPermVo(permissions);
|
||||
systemPermissionsString = PermissionUtil.listPermissionString(permissions);
|
||||
}
|
||||
return systemPermissions;
|
||||
}
|
||||
|
||||
private Set<String> getAssignedPermissions(Integer roleId){
|
||||
// 这里需要注意的是,如果存在超级权限*,那么这里需要转化成当前所有系统权限。
|
||||
// 之所以这么做,是因为前端不能识别超级权限,所以这里需要转换一下。
|
||||
Set<String> assignedPermissions = null;
|
||||
if(permissionService.checkSuperPermission(roleId)){
|
||||
getSystemPermissions();
|
||||
assignedPermissions = systemPermissionsString;
|
||||
}
|
||||
else{
|
||||
assignedPermissions = permissionService.queryByRoleId(roleId);
|
||||
}
|
||||
|
||||
return assignedPermissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员的权限情况
|
||||
*
|
||||
* @return 系统所有权限列表和管理员已分配权限
|
||||
*/
|
||||
@RequiresPermissions("admin:role:permission:get")
|
||||
@RequiresPermissionsDesc(menu={"系统管理" , "角色管理"}, button="权限详情")
|
||||
@GetMapping("/permissions")
|
||||
public Object getPermissions(Integer roleId) {
|
||||
List<PermVo> systemPermissions = getSystemPermissions();
|
||||
Set<String> assignedPermissions = getAssignedPermissions(roleId);
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("systemPermissions", systemPermissions);
|
||||
data.put("assignedPermissions", assignedPermissions);
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新管理员的权限
|
||||
*
|
||||
* @param body
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("admin:role:permission:update")
|
||||
@RequiresPermissionsDesc(menu={"系统管理" , "角色管理"}, button="权限变更")
|
||||
@PostMapping("/permissions")
|
||||
public Object updatePermissions(@RequestBody String body) {
|
||||
Integer roleId = JacksonUtil.parseInteger(body, "roleId");
|
||||
List<String> permissions = JacksonUtil.parseStringList(body, "permissions");
|
||||
if(roleId == null || permissions == null){
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
// 如果修改的角色是超级权限,则拒绝修改。
|
||||
if(permissionService.checkSuperPermission(roleId)){
|
||||
return ResponseUtil.fail(AdminResponseCode.ROLE_SUPER_SUPERMISSION, "当前角色的超级权限不能变更");
|
||||
}
|
||||
|
||||
// 先删除旧的权限,再更新新的权限
|
||||
permissionService.deleteByRoleId(roleId);
|
||||
for(String permission : permissions){
|
||||
DtsPermission DtsPermission = new DtsPermission();
|
||||
DtsPermission.setRoleId(roleId);
|
||||
DtsPermission.setPermission(permission);
|
||||
permissionService.add(DtsPermission);
|
||||
}
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.admin.util.StatVo;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.db.service.StatService;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@RestController
|
||||
@RequestMapping("/admin/stat")
|
||||
@Validated
|
||||
public class AdminStatController {
|
||||
|
||||
@Autowired
|
||||
private StatService statService;
|
||||
|
||||
@RequiresPermissions("admin:stat:user")
|
||||
@RequiresPermissionsDesc(menu={"统计管理" , "用户统计"}, button="查询")
|
||||
@GetMapping("/user")
|
||||
public Object statUser() {
|
||||
List<Map> rows = statService.statUser();
|
||||
String[] columns = new String[]{"day", "users"};
|
||||
StatVo statVo = new StatVo();
|
||||
statVo.setColumns(columns);
|
||||
statVo.setRows(rows);
|
||||
return ResponseUtil.ok(statVo);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:stat:order")
|
||||
@RequiresPermissionsDesc(menu={"统计管理" , "订单统计"}, button="查询")
|
||||
@GetMapping("/order")
|
||||
public Object statOrder() {
|
||||
List<Map> rows = statService.statOrder();
|
||||
String[] columns = new String[]{"day", "orders", "customers", "amount", "pcr"};
|
||||
StatVo statVo = new StatVo();
|
||||
statVo.setColumns(columns);
|
||||
statVo.setRows(rows);
|
||||
|
||||
return ResponseUtil.ok(statVo);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:stat:goods")
|
||||
@RequiresPermissionsDesc(menu={"统计管理" , "商品统计"}, button="查询")
|
||||
@GetMapping("/goods")
|
||||
public Object statGoods() {
|
||||
List<Map> rows = statService.statGoods();
|
||||
String[] columns = new String[]{"day", "orders", "products", "amount"};
|
||||
StatVo statVo = new StatVo();
|
||||
statVo.setColumns(columns);
|
||||
statVo.setRows(rows);
|
||||
return ResponseUtil.ok(statVo);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
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 com.github.pagehelper.PageInfo;
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.core.storage.StorageService;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.core.validator.Order;
|
||||
import com.qiguliuxing.dts.core.validator.Sort;
|
||||
import com.qiguliuxing.dts.db.domain.DtsStorage;
|
||||
import com.qiguliuxing.dts.db.service.DtsStorageService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/storage")
|
||||
@Validated
|
||||
public class AdminStorageController {
|
||||
|
||||
@Autowired
|
||||
private StorageService storageService;
|
||||
@Autowired
|
||||
private DtsStorageService DtsStorageService;
|
||||
|
||||
@RequiresPermissions("admin:storage:list")
|
||||
@RequiresPermissionsDesc(menu={"系统管理" , "对象存储"}, button="查询")
|
||||
@GetMapping("/list")
|
||||
public Object list(String key, String name,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
List<DtsStorage> storageList = DtsStorageService.querySelective(key, name, page, limit, sort, order);
|
||||
long total = PageInfo.of(storageList).getTotal();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", storageList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:storage:create")
|
||||
@RequiresPermissionsDesc(menu={"系统管理" , "对象存储"}, button="上传")
|
||||
@PostMapping("/create")
|
||||
public Object create(@RequestParam("file") MultipartFile file) throws IOException {
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
String url = storageService.store(file.getInputStream(), file.getSize(), file.getContentType(), originalFilename);
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("url", url);
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:storage:read")
|
||||
@RequiresPermissionsDesc(menu={"系统管理" , "对象存储"}, button="详情")
|
||||
@PostMapping("/read")
|
||||
public Object read(@NotNull Integer id) {
|
||||
DtsStorage storageInfo = DtsStorageService.findById(id);
|
||||
if (storageInfo == null) {
|
||||
return ResponseUtil.badArgumentValue();
|
||||
}
|
||||
return ResponseUtil.ok(storageInfo);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:storage:update")
|
||||
@RequiresPermissionsDesc(menu={"系统管理" , "对象存储"}, button="编辑")
|
||||
@PostMapping("/update")
|
||||
public Object update(@RequestBody DtsStorage DtsStorage) {
|
||||
if (DtsStorageService.update(DtsStorage) == 0) {
|
||||
return ResponseUtil.updatedDataFailed();
|
||||
}
|
||||
return ResponseUtil.ok(DtsStorage);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:storage:delete")
|
||||
@RequiresPermissionsDesc(menu={"系统管理" , "对象存储"}, button="删除")
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody DtsStorage DtsStorage) {
|
||||
String key = DtsStorage.getKey();
|
||||
if (StringUtils.isEmpty(key)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
DtsStorageService.deleteByKey(key);
|
||||
storageService.delete(key);
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.core.validator.Order;
|
||||
import com.qiguliuxing.dts.core.validator.Sort;
|
||||
import com.qiguliuxing.dts.db.domain.DtsTopic;
|
||||
import com.qiguliuxing.dts.db.service.DtsTopicService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/topic")
|
||||
@Validated
|
||||
public class AdminTopicController {
|
||||
|
||||
@Autowired
|
||||
private DtsTopicService topicService;
|
||||
|
||||
@RequiresPermissions("admin:topic:list")
|
||||
@RequiresPermissionsDesc(menu={"推广管理" , "专题管理"}, button="查询")
|
||||
@GetMapping("/list")
|
||||
public Object list(String title, String subtitle,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
List<DtsTopic> topicList = topicService.querySelective(title, subtitle, page, limit, sort, order);
|
||||
long total = PageInfo.of(topicList).getTotal();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", topicList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
|
||||
private Object validate(DtsTopic topic) {
|
||||
String title = topic.getTitle();
|
||||
if (StringUtils.isEmpty(title)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
String content = topic.getContent();
|
||||
if (StringUtils.isEmpty(content)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
BigDecimal price = topic.getPrice();
|
||||
if (price == null) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:topic:create")
|
||||
@RequiresPermissionsDesc(menu={"推广管理" , "专题管理"}, button="添加")
|
||||
@PostMapping("/create")
|
||||
public Object create(@RequestBody DtsTopic topic) {
|
||||
Object error = validate(topic);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
topicService.add(topic);
|
||||
return ResponseUtil.ok(topic);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:topic:read")
|
||||
@RequiresPermissionsDesc(menu={"推广管理" , "专题管理"}, button="详情")
|
||||
@GetMapping("/read")
|
||||
public Object read(@NotNull Integer id) {
|
||||
DtsTopic topic = topicService.findById(id);
|
||||
return ResponseUtil.ok(topic);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:topic:update")
|
||||
@RequiresPermissionsDesc(menu={"推广管理" , "专题管理"}, button="编辑")
|
||||
@PostMapping("/update")
|
||||
public Object update(@RequestBody DtsTopic topic) {
|
||||
Object error = validate(topic);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
if (topicService.updateById(topic) == 0) {
|
||||
return ResponseUtil.updatedDataFailed();
|
||||
}
|
||||
return ResponseUtil.ok(topic);
|
||||
}
|
||||
|
||||
@RequiresPermissions("admin:topic:delete")
|
||||
@RequiresPermissionsDesc(menu={"推广管理" , "专题管理"}, button="删除")
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody DtsTopic topic) {
|
||||
topicService.deleteById(topic.getId());
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package com.qiguliuxing.dts.admin.web;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
|
||||
import com.qiguliuxing.dts.core.util.ResponseUtil;
|
||||
import com.qiguliuxing.dts.core.validator.Order;
|
||||
import com.qiguliuxing.dts.core.validator.Sort;
|
||||
import com.qiguliuxing.dts.db.domain.DtsUser;
|
||||
import com.qiguliuxing.dts.db.service.DtsUserService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/user")
|
||||
@Validated
|
||||
public class AdminUserController {
|
||||
|
||||
@Autowired
|
||||
private DtsUserService userService;
|
||||
|
||||
@RequiresPermissions("admin:user:list")
|
||||
@RequiresPermissionsDesc(menu={"用户管理" , "会员管理"}, button="查询")
|
||||
@GetMapping("/list")
|
||||
public Object list(String username, String mobile,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer limit,
|
||||
@Sort @RequestParam(defaultValue = "add_time") String sort,
|
||||
@Order @RequestParam(defaultValue = "desc") String order) {
|
||||
List<DtsUser> userList = userService.querySelective(username, mobile, page, limit, sort, order);
|
||||
long total = PageInfo.of(userList).getTotal();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("total", total);
|
||||
data.put("items", userList);
|
||||
|
||||
return ResponseUtil.ok(data);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue