package cc.mrbird.febs.dapp.controller;
|
|
|
import cc.mrbird.febs.common.annotation.ControllerEndpoint;
|
import cc.mrbird.febs.common.controller.BaseController;
|
import cc.mrbird.febs.common.entity.FebsResponse;
|
import cc.mrbird.febs.common.entity.QueryRequest;
|
import cc.mrbird.febs.common.utils.OssUtils;
|
import cc.mrbird.febs.dapp.dto.*;
|
import cc.mrbird.febs.dapp.entity.*;
|
import cc.mrbird.febs.dapp.mapper.DappMemberDao;
|
import cc.mrbird.febs.dapp.mapper.MallAddressInfoMapper;
|
import cc.mrbird.febs.dapp.mapper.MallOrderInfoMapper;
|
import cc.mrbird.febs.dapp.service.IAdminMallGoodsService;
|
import cc.mrbird.febs.dapp.service.IMallNewsInfoService;
|
import cc.mrbird.febs.dapp.utils.ExcelSheetPO;
|
import cc.mrbird.febs.dapp.utils.ExcelUtil;
|
import cc.mrbird.febs.dapp.utils.ExcelVersion;
|
import cc.mrbird.febs.dapp.utils.ResponseHeadUtil;
|
import cc.mrbird.febs.dapp.vo.AdminMallGoodsCategoryTreeVo;
|
import cc.mrbird.febs.dapp.vo.MallOrderItemVo;
|
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.StrUtil;
|
import lombok.RequiredArgsConstructor;
|
import lombok.extern.slf4j.Slf4j;
|
import net.coobird.thumbnailator.Thumbnails;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
import sun.misc.BASE64Encoder;
|
|
import javax.imageio.ImageIO;
|
import javax.servlet.http.HttpServletResponse;
|
import javax.validation.Valid;
|
import javax.validation.constraints.NotNull;
|
import java.awt.image.BufferedImage;
|
import java.io.ByteArrayOutputStream;
|
import java.io.File;
|
import java.io.IOException;
|
import java.io.OutputStream;
|
import java.net.URLEncoder;
|
import java.util.*;
|
|
@Slf4j
|
@Validated
|
@RestController
|
@RequiredArgsConstructor
|
@RequestMapping(value = "/admin/goods")
|
public class AdminMallGoodsController extends BaseController {
|
|
private final IAdminMallGoodsService adminMallGoodsService;
|
private final MallOrderInfoMapper mallOrderInfoMapper;
|
private final MallAddressInfoMapper mallAddressInfoMapper;
|
private final DappMemberDao dappMemberDao;
|
|
|
/**
|
* 商品分类-选择
|
*/
|
@GetMapping("categorys/tree")
|
@ControllerEndpoint(exceptionMessage = "获取分类失败")
|
public List<AdminMallGoodsCategoryTreeVo> getParentCategorys(){
|
return adminMallGoodsService.getParentCategorys();
|
}
|
|
/**
|
* 商品分类列表
|
* @param mallGoodsCategory
|
* @param request
|
* @return
|
*/
|
@GetMapping("categoryList")
|
public FebsResponse getCategoryList(MallGoodsCategory mallGoodsCategory, QueryRequest request) {
|
Map<String, Object> data = getDataTable(adminMallGoodsService.getCategoryList(mallGoodsCategory, request));
|
return new FebsResponse().success().data(data);
|
}
|
|
/**
|
* 商品分类-新增
|
*/
|
@PostMapping("addCategory")
|
@ControllerEndpoint(operation = " 商品分类-新增", exceptionMessage = "操作失败")
|
public FebsResponse addCategory(@Valid MallGoodsCategory mallGoodsCategory) {
|
return adminMallGoodsService.addCategory(mallGoodsCategory);
|
}
|
|
/**
|
* 商品分类-编辑
|
*/
|
@PostMapping("updateCategory")
|
@ControllerEndpoint(operation = " 商品分类-编辑", exceptionMessage = "操作失败")
|
public FebsResponse updateCategory(@Valid MallGoodsCategory mallGoodsCategory) {
|
return adminMallGoodsService.updateCategory(mallGoodsCategory);
|
}
|
|
/**
|
* 商品分类-删除
|
*/
|
@GetMapping("delCategary/{id}")
|
@ControllerEndpoint(operation = " 商品分类-删除", exceptionMessage = "操作失败")
|
public FebsResponse delCategary(@NotNull(message = "{required}") @PathVariable Long id) {
|
return adminMallGoodsService.delCategary(id);
|
}
|
|
/**
|
* 图片上传
|
* @return
|
*/
|
@PostMapping(value = "/uploadFileBase64")
|
@ControllerEndpoint(operation = "图片上传", exceptionMessage = "上传失败")
|
public Map<String,Object> uploadFileBase64(@RequestBody @Validated MultipartFile file) {
|
if (file.isEmpty()) {
|
new FebsResponse().message("上传文件为空");
|
}
|
String base64EncoderImg = "";
|
BASE64Encoder base64Encoder =new BASE64Encoder();
|
List<String> imageFuffixStr = StrUtil.splitTrim(file.getOriginalFilename(), ".");
|
String imageFuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
|
if("jpg".equals(imageFuffixStr.get(1))){
|
try {
|
//输出到BufferedImage
|
BufferedImage bufferedImage = Thumbnails.of(file.getInputStream())
|
// 图片大小(长宽)压缩比例 从0-1,1表示原图
|
.scale(1f)
|
// 图片质量压缩比例 从0-1,越接近1质量越好
|
.outputQuality(1f)
|
.asBufferedImage();
|
//对内存中的图片文件进行Base64处理
|
ByteArrayOutputStream newBaos = new ByteArrayOutputStream();//io流
|
ImageIO.write(bufferedImage, "jpg", newBaos);//写入流中
|
byte[] bytes = newBaos.toByteArray();//转换成字节
|
base64EncoderImg = base64Encoder.encode(bytes);
|
// base64EncoderImg = URLEncoder.encode(new BASE64Encoder().encode(bytes), "UTF-8");
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}else{
|
try {
|
base64EncoderImg = base64Encoder.encode(file.getBytes());
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
//文件加密
|
// String imageFuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
|
// String imageFuffix = ".png";
|
String imageNames = System.currentTimeMillis() + IdUtil.simpleUUID() + imageFuffix;
|
String imageName = "uploadeFile/" + imageNames;
|
OssUtils.uploadFileWithBase64(base64EncoderImg, imageName);
|
String bucket_name ="https://excoin.oss-cn-hangzhou.aliyuncs.com";
|
String url = bucket_name + "/" + imageName;
|
|
Map<String,Object> map = new HashMap<String,Object>();
|
Map<String,Object> map2 = new HashMap<String,Object>();
|
map.put("code",0);//0表示成功,1失败
|
map.put("msg","上传成功");//提示消息
|
map.put("data",map2);
|
map2.put("src",url);//图片url
|
map2.put("title",imageNames);//图片名称,这个会显示在输入框里
|
return map;
|
}
|
/**
|
* 商品列表
|
* @param mallGoods
|
* @param request
|
* @return
|
*/
|
@GetMapping("goodsList")
|
public FebsResponse getGoodsList(MallGoods mallGoods, QueryRequest request) {
|
Map<String, Object> data = getDataTable(adminMallGoodsService.getCategoryListInPage(mallGoods, request));
|
return new FebsResponse().success().data(data);
|
}
|
/**
|
* 商品-新增
|
*/
|
@PostMapping("addMallGoods")
|
@ControllerEndpoint(operation = " 商品-新增", exceptionMessage = "新增失败")
|
public FebsResponse addMallGoods(@RequestBody @Valid AddMallGoodsDto addMallGoodsDto) {
|
return adminMallGoodsService.addMallGoods(addMallGoodsDto);
|
}
|
/**
|
* 商品-上架
|
*/
|
@GetMapping("upMallGoods/{id}")
|
@ControllerEndpoint(operation = " 商品-上架", exceptionMessage = "上架失败")
|
public FebsResponse upMallGoods(@NotNull(message = "{required}") @PathVariable Long id) {
|
return adminMallGoodsService.upMallGoods(id);
|
}
|
/**
|
* 商品-下架
|
*/
|
@GetMapping("downMallGoods/{id}")
|
@ControllerEndpoint(operation = " 商品-下架", exceptionMessage = "下架失败")
|
public FebsResponse downMallGoods(@NotNull(message = "{required}") @PathVariable Long id) {
|
return adminMallGoodsService.downMallGoods(id);
|
}
|
/**
|
* 商品-删除
|
*/
|
@GetMapping("delMallGoods/{id}")
|
@ControllerEndpoint(operation = " 商品-删除", exceptionMessage = "删除失败")
|
public FebsResponse delMallGoods(@NotNull(message = "{required}") @PathVariable Long id) {
|
return adminMallGoodsService.delMallGoods(id);
|
}
|
/**
|
* 商品-编辑
|
*/
|
@PostMapping("updateMallGoods")
|
@ControllerEndpoint(operation = "商品-编辑", exceptionMessage = "操作失败")
|
public FebsResponse updateMallGoods(@RequestBody @Valid MallGoodsUpdateDto mallGoodsUpdateDto) {
|
return adminMallGoodsService.updateMallGoods(mallGoodsUpdateDto);
|
}
|
/**
|
* 订单列表
|
*
|
* @param mallOrderInfo
|
* @param request
|
* @return
|
*/
|
@GetMapping("orderList")
|
public FebsResponse getOrderList(MallOrderInfoDto mallOrderInfo, QueryRequest request) {
|
Map<String, Object> data = getDataTable(adminMallGoodsService.getOrderListInPage(mallOrderInfo, request));
|
return new FebsResponse().success().data(data);
|
}
|
/**
|
* 订单列表-资金流水
|
*/
|
@GetMapping("/orderMoneyFlow")
|
public FebsResponse orderMoneyFlow(QueryRequest request, MallOrderInfo mallOrderInfo, Integer parentId) {
|
if (parentId == null) {
|
ViewAdminMallGoodsController.idOrderMoneyFlow = 0;
|
}
|
mallOrderInfo.setId(ViewAdminMallGoodsController.idOrderMoneyFlow);
|
Map<String, Object> dataTable = getDataTable(adminMallGoodsService.orderMoneyFlow(request, mallOrderInfo));
|
return new FebsResponse().success().data(dataTable);
|
}
|
|
/**
|
* 订单列表-发货
|
*/
|
@PostMapping("deliverGoods")
|
@ControllerEndpoint(operation = "订单列表-发货", exceptionMessage = "操作失败")
|
public FebsResponse deliverGoods(@Valid DeliverGoodsDto deliverGoodsDto) {
|
return adminMallGoodsService.deliverGoods(deliverGoodsDto);
|
}
|
|
/**
|
* 订单列表-删除订单
|
*
|
* @param id
|
* @return
|
*/
|
@GetMapping("delOrder/{id}")
|
@ControllerEndpoint(operation = "订单列表-删除订单", exceptionMessage = "操作失败")
|
public FebsResponse delOrder(@NotNull(message = "{required}") @PathVariable Long id) {
|
return adminMallGoodsService.delOrder(id);
|
}
|
|
@GetMapping(value = "/findDicByType/{type}")
|
public FebsResponse findDicByType(@PathVariable("type") String type) {
|
return new FebsResponse().success().data(adminMallGoodsService.findDataDicByType(type));
|
}
|
|
@PostMapping(value = "/bonusSystemSetting")
|
public FebsResponse bonusSystemSetting(@RequestBody Map<String, Object> map) {
|
adminMallGoodsService.bonusSystemSetting(map);
|
return new FebsResponse().success().message("设置成功");
|
}
|
|
@PostMapping(value = "/hlmBasicPerk")
|
public FebsResponse hlmBasicPerk(HlmBasicPerkDto hlmBasicPerkDto) {
|
adminMallGoodsService.hlmBasicPerk(hlmBasicPerkDto);
|
return new FebsResponse().success();
|
}
|
|
|
|
/**
|
* 轮播图---列表
|
*/
|
@GetMapping("platformBanner")
|
public FebsResponse platformBanner(PlatformBanner platformBannerEntity, QueryRequest request) {
|
Map<String, Object> data = getDataTable(adminMallGoodsService.findPlatformBannerInPage(platformBannerEntity, request));
|
return new FebsResponse().success().data(data);
|
}
|
|
/**
|
* 轮播图---确认
|
* @return
|
*/
|
@PostMapping("platformBannerConfirm")
|
@ControllerEndpoint(operation = "轮播图---确认", exceptionMessage = "设置失败")
|
public FebsResponse platformBannerConfirm(@Valid PlatformBanner platformBannerEntity) {
|
return adminMallGoodsService.platformBannerConfirm(platformBannerEntity);
|
}
|
|
/**
|
* 轮播图---删除
|
* @return
|
*/
|
@GetMapping("platformBannerDelete/{id}")
|
@ControllerEndpoint(operation = "轮播图---删除", exceptionMessage = "删除失败")
|
public FebsResponse platformBannerDelete(@NotNull(message = "{required}") @PathVariable Long id) {
|
return adminMallGoodsService.platformBannerDelete(id);
|
}
|
|
/**
|
* 轮播图---新增
|
*/
|
@PostMapping("platformBannerAdds")
|
@ControllerEndpoint(operation = "轮播图---新增", exceptionMessage = "新增失败")
|
public FebsResponse platformBannerAdds(@Valid PlatformBanner platformBannerEntity) {
|
adminMallGoodsService.platformBannerAdd(platformBannerEntity);
|
return new FebsResponse().success();
|
}
|
|
private final IMallNewsInfoService mallNewsInfoService;
|
|
/**
|
* 新闻中心-列表
|
* @param mallNewsInfo
|
* @param request
|
* @return
|
*/
|
@GetMapping("getNewInfoList")
|
public FebsResponse getNewInfoList(MallNewsInfo mallNewsInfo, QueryRequest request) {
|
Map<String, Object> data = getDataTable(mallNewsInfoService.getNewInfoList(mallNewsInfo, request));
|
return new FebsResponse().success().data(data);
|
}
|
|
/**
|
* 新闻中心-新增
|
*/
|
@PostMapping("addNewsInfo")
|
@ControllerEndpoint(operation = " 新闻中心-新增", exceptionMessage = "操作失败")
|
public FebsResponse addNewsInfo(@Valid MallNewsInfoDto mallNewsInfoDto) {
|
return mallNewsInfoService.addNewsInfo(mallNewsInfoDto);
|
}
|
|
/**
|
* 新闻中心-删除
|
*/
|
@GetMapping("delNewsInfo/{id}")
|
@ControllerEndpoint(operation = " 新闻中心-删除", exceptionMessage = "操作失败")
|
public FebsResponse delNewsInfo(@NotNull(message = "{required}") @PathVariable Long id) {
|
return mallNewsInfoService.delNewsInfo(id);
|
}
|
|
/**
|
* 新闻中心-更新
|
*/
|
@PostMapping("updateNewsInfo")
|
@ControllerEndpoint(operation = "新闻中心-更新", exceptionMessage = "操作失败")
|
public FebsResponse updateNewsInfo(@Valid MallNewsInfoDto mallNewsInfoDto) {
|
return mallNewsInfoService.updateNewsInfo(mallNewsInfoDto);
|
}
|
|
|
@GetMapping("findNewsCategoryList")
|
@ControllerEndpoint(operation = "新闻分类列表", exceptionMessage = "获取失败")
|
public FebsResponse findNewsCategoryList(MallNewsCategory mallNewsCategory, QueryRequest request) {
|
return new FebsResponse().success().data(getDataTable(mallNewsInfoService.findNewsCategoryInPage(mallNewsCategory, request)));
|
}
|
|
@PostMapping("addOrModifyNewsCategory")
|
@ControllerEndpoint(operation = "新闻分类", exceptionMessage = "新增失败")
|
public FebsResponse addOrModifyNewsCategory(MallNewsCategory mallNewsCategory) {
|
mallNewsInfoService.addOrModifyNewsCategory(mallNewsCategory);
|
return new FebsResponse().success().message("新增成功");
|
}
|
|
/**
|
* 新闻分类-删除
|
*/
|
@GetMapping("delNewsCategoryInfo/{id}")
|
@ControllerEndpoint(operation = "新闻分类-删除", exceptionMessage = "操作失败")
|
public FebsResponse delNewsCategoryInfo(@NotNull(message = "{required}") @PathVariable Long id) {
|
return mallNewsInfoService.delNewsCategoryInfo(id);
|
}
|
|
@GetMapping(value = "findAllCategoryList")
|
public FebsResponse findAllCategoryList() {
|
List<MallNewsCategory> categories = mallNewsInfoService.findAllCategory();
|
return new FebsResponse().success().data(categories);
|
}
|
|
@PostMapping(value = "/topNews/{id}")
|
public FebsResponse topNews(@PathVariable Long id) {
|
MallNewsInfo mallNewsInfo = new MallNewsInfo();
|
mallNewsInfo.setIsTop(1);
|
mallNewsInfo.setId(id);
|
mallNewsInfoService.updateById(mallNewsInfo);
|
return new FebsResponse().success();
|
}
|
|
@PostMapping(value = "/unTopNews/{id}")
|
public FebsResponse unTopNews(@PathVariable Long id) {
|
MallNewsInfo mallNewsInfo = new MallNewsInfo();
|
mallNewsInfo.setIsTop(2);
|
mallNewsInfo.setId(id);
|
mallNewsInfoService.updateById(mallNewsInfo);
|
return new FebsResponse().success();
|
}
|
|
@GetMapping("exportOrderList")
|
@ControllerEndpoint(operation = "订单列表", exceptionMessage = "导出失败")
|
public FebsResponse exportOrderList(MallOrderInfo mallOrderInfo, HttpServletResponse response) throws IOException {
|
|
List<ExcelSheetPO> res = new ArrayList<>();
|
ExcelSheetPO orderSheet = new ExcelSheetPO();
|
String title = "订单列表";
|
orderSheet.setSheetName(title);
|
orderSheet.setTitle(title);
|
String[] header = {"订单编号", "收货姓名", "收货电话", "收货地址", "提货方式","订单状态","发货状态","下单时间", "商品详情", "金额", "物流单号", "物流公司", "物流公司码"};
|
orderSheet.setHeaders(header);
|
|
QueryRequest request = new QueryRequest();
|
request.setPageNum(1);
|
request.setPageSize(9999);
|
List<MallOrderInfo> dataList = new ArrayList<>();
|
String orderIds = mallOrderInfo.getOrderIds();
|
List<String> ids = StrUtil.splitTrim(orderIds, ",");
|
for(String id : ids){
|
long orderId = Long.parseLong(id);
|
MallOrderInfo mallOrderInfo1 = mallOrderInfoMapper.selectById(orderId);
|
if(ObjectUtil.isNotEmpty(mallOrderInfo1)
|
&& MallOrderInfo.DELIVER_STATUS_WAIT == mallOrderInfo1.getDeliverState()
|
&& 1 == mallOrderInfo1.getDeliverType()){
|
dataList.add(mallOrderInfo1);
|
}
|
}
|
List<List<Object>> list = new ArrayList<>();
|
if (dataList.size() > 0) {
|
for (MallOrderInfo item : dataList) {
|
List<Object> temp = new ArrayList<>();
|
temp.add(item.getOrderNo());
|
MallAddressInfo mallAddressInfo = mallAddressInfoMapper.selectById(item.getAddressId());
|
// temp.add(item.getAmount());
|
// temp.add(DateUtil.format(item.getOrderTime(), "yyyy-MM-dd HH:mm:ss"));
|
// temp.add("快递配送");
|
temp.add(mallAddressInfo.getName());
|
temp.add(mallAddressInfo.getPhone());
|
temp.add(mallAddressInfo.getArea()+mallAddressInfo.getAddress());
|
temp.add("快递寄送");
|
temp.add("已支付");
|
temp.add("待发货");
|
temp.add(DateUtil.format(item.getPayTime(),"yyyy-MM-dd HH:mm:ss"));
|
|
List<MallOrderItemVo> mallOrderItemVoList = dappMemberDao.selectMallOrderItemVoByOrderId(item.getId());
|
if (CollUtil.isNotEmpty(mallOrderItemVoList)) {
|
StringBuilder sb = new StringBuilder();
|
for (MallOrderItemVo itemItem : mallOrderItemVoList) {
|
if (StrUtil.isNotBlank(sb)) {
|
sb.append(";" + itemItem.getGoodsName()+"-"+itemItem.getPrice() + "*" + itemItem.getCnt());
|
} else {
|
sb.append(itemItem.getGoodsName()+"-"+itemItem.getPrice() + "*" + itemItem.getCnt());
|
}
|
}
|
temp.add(sb.toString());
|
} else {
|
temp.add("");
|
}
|
temp.add(item.getAmount());
|
list.add(temp);
|
}
|
}
|
orderSheet.setDataList(list);
|
res.add(orderSheet);
|
response = ResponseHeadUtil.setExcelHead(response);
|
response.setHeader("Content-Disposition",
|
"attachment;filename=" + URLEncoder.encode(title + DateUtil.format(new Date(), "yyyyMMDDHHmmss") + ".xlsx".trim(), "UTF-8"));
|
OutputStream os = response.getOutputStream();
|
ExcelUtil.createWorkbookAtOutStream(ExcelVersion.V2007, res, os, true);
|
return null;
|
}
|
|
@PostMapping(value = "/importDeliver")
|
@ControllerEndpoint(operation = "导入发货", exceptionMessage = "导入失败")
|
public FebsResponse importDeliver(@RequestBody MultipartFile file) throws IOException {
|
if (file.isEmpty()) {
|
return new FebsResponse().fail();
|
}
|
|
String fileName = file.getOriginalFilename();
|
String dirPath = "/home/javaweb/webresource/";
|
|
File saveFile = new File(new File(dirPath).getAbsolutePath() + File.separator + fileName);
|
if (!saveFile.exists()) {
|
if (!saveFile.getParentFile().exists()) {
|
saveFile.getParentFile().mkdirs();
|
}
|
}
|
|
file.transferTo(saveFile);
|
|
List<ExcelSheetPO> data = ExcelUtil.readExcel(saveFile, null, null);
|
if (CollUtil.isEmpty(data)) {
|
return new FebsResponse().fail();
|
}
|
|
List<List<Object>> dataList = data.get(0).getDataList();
|
|
int expressNoIndex = -1;
|
int expressComIndex = -1;
|
int expressCodeIndex = -1;
|
for (int i = 1; i < dataList.size(); i++) {
|
List<Object> objects = dataList.get(i);
|
|
String expressNo = "";
|
String expressCom = "";
|
for (int j = 0; j < objects.size(); j++) {
|
Object obj = objects.get(j);
|
if ("物流单号".equals(obj)) {
|
expressNoIndex = j;
|
}
|
|
if ("物流公司".equals(obj)) {
|
expressComIndex = j;
|
}
|
|
if ("物流公司码".equals(obj)) {
|
expressCodeIndex = j;
|
}
|
|
if (j == expressNoIndex) {
|
expressNo = (String) objects.get(j);
|
}
|
|
if (j == expressComIndex) {
|
expressCom = (String) objects.get(j);
|
}
|
|
}
|
|
if (StrUtil.isNotBlank(expressNo) && StrUtil.isNotBlank(expressCom)) {
|
String orderNo = (String) objects.get(0);
|
|
DeliverGoodsDto deliverGoods = new DeliverGoodsDto();
|
deliverGoods.setOrderNo(orderNo);
|
deliverGoods.setExpressCom(expressCom);
|
deliverGoods.setExpressNo(expressNo);
|
adminMallGoodsService.deliverGoodsByOrderNo(deliverGoods);
|
}
|
|
|
}
|
return new FebsResponse().success();
|
}
|
|
|
|
}
|