|
|
|
@ -1,7 +1,8 @@ |
|
|
|
|
package com.order.controller.business; |
|
|
|
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.fasterxml.jackson.databind.util.BeanUtil; |
|
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
|
import com.hfkj.common.exception.ErrorCode; |
|
|
|
@ -9,31 +10,44 @@ import com.hfkj.common.exception.ErrorHelp; |
|
|
|
|
import com.hfkj.common.exception.SysCode; |
|
|
|
|
import com.hfkj.common.security.SessionObject; |
|
|
|
|
import com.hfkj.common.security.UserCenter; |
|
|
|
|
import com.hfkj.common.utils.OrderUtil; |
|
|
|
|
import com.hfkj.common.utils.DateUtil; |
|
|
|
|
import com.hfkj.common.utils.ResponseMsgUtil; |
|
|
|
|
import com.hfkj.config.CommonSysConst; |
|
|
|
|
import com.hfkj.entity.BsOrderGoods; |
|
|
|
|
import com.hfkj.entity.FileRecords; |
|
|
|
|
import com.hfkj.entity.GoodsLogistics; |
|
|
|
|
import com.hfkj.entity.GoodsUserAddress; |
|
|
|
|
import com.hfkj.model.ResponseData; |
|
|
|
|
import com.hfkj.model.SecUserSessionObject; |
|
|
|
|
import com.hfkj.model.order.orderExport.OrderGoodsExportModel; |
|
|
|
|
import com.hfkj.service.file.FileRecordsService; |
|
|
|
|
import com.hfkj.service.goods.BsOrderGoodsService; |
|
|
|
|
import com.hfkj.service.goods.GoodsUserAddressService; |
|
|
|
|
import com.hfkj.service.order.BsOrderService; |
|
|
|
|
import com.hfkj.sysenum.SecUserObjectTypeEnum; |
|
|
|
|
import com.hfkj.sysenum.order.OrderGoodsStatusEnum; |
|
|
|
|
import com.hfkj.sysenum.fileRecords.FileRecordsEnum; |
|
|
|
|
import com.hfkj.sysenum.order.OrderChildStatusEnum; |
|
|
|
|
import com.hfkj.sysenum.order.OrderLogisticsStatusEnum; |
|
|
|
|
import com.hfkj.sysenum.order.OrderPayChannelEnum; |
|
|
|
|
import com.hfkj.sysenum.order.OrderPayTypeEnum; |
|
|
|
|
import io.swagger.annotations.Api; |
|
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
|
import org.apache.commons.beanutils.BeanUtils; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
|
import org.springframework.stereotype.Controller; |
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Objects; |
|
|
|
|
import java.io.File; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.concurrent.ArrayBlockingQueue; |
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor; |
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
|
@RequestMapping(value="/orderGoods") |
|
|
|
@ -51,6 +65,12 @@ public class BsOrderGoodsController { |
|
|
|
|
@Resource |
|
|
|
|
private BsOrderService orderService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private FileRecordsService fileRecordsService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private GoodsUserAddressService addressService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value="/getListGoods",method = RequestMethod.GET) |
|
|
|
|
@ResponseBody |
|
|
|
@ -66,6 +86,7 @@ public class BsOrderGoodsController { |
|
|
|
|
@RequestParam(value = "logisticsStatus" , required = false) String logisticsStatus, |
|
|
|
|
@RequestParam(value = "payType" , required = false) Integer payType, |
|
|
|
|
@RequestParam(value = "status" , required = false) Integer status, |
|
|
|
|
@RequestParam(value = "merId" , required = false) Long merId, |
|
|
|
|
@RequestParam(value = "createTimeS" , required = false) Long createTimeS, |
|
|
|
|
@RequestParam(value = "createTimeE" , required = false) Long createTimeE, |
|
|
|
|
@RequestParam(value = "pageNum" , required = true) Integer pageNum, |
|
|
|
@ -76,7 +97,9 @@ public class BsOrderGoodsController { |
|
|
|
|
SecUserSessionObject userModel = (SecUserSessionObject) sessionObject.getObject(); |
|
|
|
|
|
|
|
|
|
Map<String , Object> map = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
if (userModel.getAccount().getObjectType().equals(SecUserObjectTypeEnum.type1.getCode())) { |
|
|
|
|
map.put("merId", merId); |
|
|
|
|
} |
|
|
|
|
if (userModel.getAccount().getObjectType().equals(SecUserObjectTypeEnum.type2.getCode())) { |
|
|
|
|
map.put("merId", userModel.getAccount().getObjectId()); |
|
|
|
|
} |
|
|
|
@ -104,6 +127,155 @@ public class BsOrderGoodsController { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value="/exportGoodsOrder",method = RequestMethod.GET) |
|
|
|
|
@ResponseBody |
|
|
|
|
@ApiOperation(value = "导出商品订单") |
|
|
|
|
public ResponseData exportGoodsOrder(@RequestParam(value = "logisticsNo" , required = false) String logisticsNo, |
|
|
|
|
@RequestParam(value = "goodsType" , required = false) Long goodsType, |
|
|
|
|
@RequestParam(value = "goodsBrand" , required = false) Long goodsBrand, |
|
|
|
|
@RequestParam(value = "orderNo" , required = false) String orderNo, |
|
|
|
|
@RequestParam(value = "childOrderNo" , required = false) String childOrderNo, |
|
|
|
|
@RequestParam(value = "userPhone" , required = false) String userPhone, |
|
|
|
|
@RequestParam(value = "goodsSpecsName" , required = false) String goodsSpecsName, |
|
|
|
|
@RequestParam(value = "goodsName" , required = false) String goodsName, |
|
|
|
|
@RequestParam(value = "logisticsStatus" , required = false) String logisticsStatus, |
|
|
|
|
@RequestParam(value = "payType" , required = false) Integer payType, |
|
|
|
|
@RequestParam(value = "status" , required = false) Integer status, |
|
|
|
|
@RequestParam(value = "merId" , required = false) Long merId, |
|
|
|
|
@RequestParam(value = "createTimeS" , required = false) Long createTimeS, |
|
|
|
|
@RequestParam(value = "createTimeE" , required = false) Long createTimeE, HttpServletRequest request) { |
|
|
|
|
// 插入下载记录
|
|
|
|
|
FileRecords fileRecords = new FileRecords(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
SessionObject sessionObject = userCenter.getSessionObject(request); |
|
|
|
|
SecUserSessionObject userModel = (SecUserSessionObject) sessionObject.getObject(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String , Object> map = new HashMap<>(); |
|
|
|
|
if (userModel.getAccount().getObjectType().equals(SecUserObjectTypeEnum.type1.getCode())) { |
|
|
|
|
map.put("merId", merId); |
|
|
|
|
} |
|
|
|
|
if (userModel.getAccount().getObjectType().equals(SecUserObjectTypeEnum.type2.getCode())) { |
|
|
|
|
map.put("merId", userModel.getAccount().getObjectId()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
map.put("logisticsNo", logisticsNo); |
|
|
|
|
map.put("goodsType", goodsType); |
|
|
|
|
map.put("goodsBrand", goodsBrand); |
|
|
|
|
map.put("orderNo", orderNo); |
|
|
|
|
map.put("childOrderNo", childOrderNo); |
|
|
|
|
map.put("userPhone", userPhone); |
|
|
|
|
map.put("logisticsStatus", logisticsStatus); |
|
|
|
|
map.put("goodsSpecsName", goodsSpecsName); |
|
|
|
|
map.put("goodsName", goodsName); |
|
|
|
|
map.put("payType", payType); |
|
|
|
|
map.put("createTimeS", createTimeS); |
|
|
|
|
map.put("createTimeE", createTimeE); |
|
|
|
|
map.put("status", status); |
|
|
|
|
|
|
|
|
|
String dataSting = ""; |
|
|
|
|
if (createTimeE != null) { |
|
|
|
|
dataSting = DateUtil.date2String(DateUtil.long2Date(createTimeS) , DateUtil.Y_M_D) + "-" + DateUtil.date2String(DateUtil.long2Date(createTimeE) , DateUtil.Y_M_D); |
|
|
|
|
} else { |
|
|
|
|
dataSting = DateUtil.date2String(new Date(), DateUtil.Y_M_D); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String fileUrl = CommonSysConst.getSysConfig().getFileUrl(); |
|
|
|
|
String pathName = "/temporary/" + userModel.getAccount().getId() + "/" + FileRecordsEnum.status1.getName() + "交易数据导出" + dataSting +".xlsx"; |
|
|
|
|
|
|
|
|
|
if (fileRecordsService.findExported(map.toString() , userModel.getAccount().getId())) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System , ErrorCode.COMMON_ERROR , "相同导出内容请勿重复点击!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileRecords.setCreateTime(new Date()); |
|
|
|
|
fileRecords.setBusinessType(FileRecordsEnum.status1.getCode()); |
|
|
|
|
fileRecords.setDownloadConditions(map.toString()); |
|
|
|
|
fileRecords.setOpId(userModel.getAccount().getId()); |
|
|
|
|
fileRecords.setOpName(userModel.getAccount().getUserName()); |
|
|
|
|
fileRecords.setStatus(2); |
|
|
|
|
fileRecords.setDownloadStatus(2); |
|
|
|
|
fileRecords.setFileUrl(CommonSysConst.getSysConfig().getDomainName() + "/filesystem" + pathName); |
|
|
|
|
fileRecords.setType("2"); |
|
|
|
|
fileRecords.setTitle(FileRecordsEnum.status1.getName() + "交易数据导出" + dataSting + ".xls"); |
|
|
|
|
fileRecordsService.create(fileRecords); |
|
|
|
|
|
|
|
|
|
// 创建线程
|
|
|
|
|
ThreadPoolExecutor executor = new ThreadPoolExecutor( |
|
|
|
|
2, // 核心线程数
|
|
|
|
|
5, // 最大线程数
|
|
|
|
|
1, // 线程空闲时间
|
|
|
|
|
TimeUnit.MINUTES, // 时间单位
|
|
|
|
|
new ArrayBlockingQueue<>(5), // 任务队列
|
|
|
|
|
new ThreadPoolExecutor.CallerRunsPolicy() // 拒绝策略
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// 提交任务给线程池
|
|
|
|
|
executor.execute(() -> { |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
List<BsOrderGoods> list = bsOrderGoodsService.getList(map); |
|
|
|
|
List<OrderGoodsExportModel> goodsExportModels = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
for (BsOrderGoods bsOrderGoods : list) { |
|
|
|
|
OrderGoodsExportModel orderGoodsExportModel = new OrderGoodsExportModel(); |
|
|
|
|
|
|
|
|
|
BeanUtils.copyProperties(orderGoodsExportModel, bsOrderGoods); |
|
|
|
|
if (bsOrderGoods.getIntegralDiscountPrice() != null) { |
|
|
|
|
orderGoodsExportModel.setIntegralDiscountPrice(BigDecimal.valueOf(bsOrderGoods.getIntegralDiscountPrice()).divide(new BigDecimal(100))); |
|
|
|
|
} |
|
|
|
|
if (bsOrderGoods.getPayChannel() != null) { |
|
|
|
|
orderGoodsExportModel.setPayChannel(OrderPayChannelEnum.getData(bsOrderGoods.getPayChannel()).getName()); |
|
|
|
|
} |
|
|
|
|
if (bsOrderGoods.getPayType() != null) { |
|
|
|
|
orderGoodsExportModel.setPayType(OrderPayTypeEnum.getData(bsOrderGoods.getPayType()).getName()); |
|
|
|
|
} |
|
|
|
|
if (bsOrderGoods.getStatus() != null) { |
|
|
|
|
orderGoodsExportModel.setTradeStatus(OrderChildStatusEnum.getData(bsOrderGoods.getStatus()).getName()); |
|
|
|
|
} |
|
|
|
|
goodsExportModels.add(orderGoodsExportModel); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
File file = new File(fileUrl); |
|
|
|
|
if (!file.exists()) { |
|
|
|
|
file.mkdirs(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
EasyExcel.write(fileUrl+pathName) |
|
|
|
|
.head(OrderGoodsExportModel.class) |
|
|
|
|
.sheet(fileRecords.getTitle()) |
|
|
|
|
.doWrite(goodsExportModels); |
|
|
|
|
|
|
|
|
|
fileRecords.setStatus(1); |
|
|
|
|
fileRecords.setUpdateTime(new Date()); |
|
|
|
|
fileRecordsService.update(fileRecords); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
fileRecords.setStatus(3); |
|
|
|
|
fileRecords.setUpdateTime(new Date()); |
|
|
|
|
fileRecordsService.update(fileRecords); |
|
|
|
|
log.error("error!",e); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// 关闭线程池
|
|
|
|
|
executor.shutdown(); |
|
|
|
|
return ResponseMsgUtil.success(fileRecords); |
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
fileRecords.setStatus(3); |
|
|
|
|
fileRecords.setUpdateTime(new Date()); |
|
|
|
|
fileRecordsService.update(fileRecords); |
|
|
|
|
log.error("error!",e); |
|
|
|
|
return ResponseMsgUtil.exception(e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@RequestMapping(value="/updateLogisticsNo",method = RequestMethod.POST) |
|
|
|
|
@ResponseBody |
|
|
|
|
@ApiOperation(value = "更新物流订单号") |
|
|
|
@ -154,7 +326,13 @@ public class BsOrderGoodsController { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "暂未发货!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
GoodsLogistics logistics = (GoodsLogistics) bsOrderGoodsService.getLogisticsMsg(orderGoods.getLogisticsNo()); |
|
|
|
|
GoodsUserAddress userAddress = addressService.queryDetail(orderGoods.getDeliveryAddressId()); |
|
|
|
|
|
|
|
|
|
if (userAddress == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System , ErrorCode.COMMON_ERROR , "暂无物流信息!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
GoodsLogistics logistics = (GoodsLogistics) bsOrderGoodsService.getLogisticsMsg(orderGoods.getLogisticsNo() , userAddress.getPhone()); |
|
|
|
|
|
|
|
|
|
if (logistics.getLogisticsStatus() != null) { |
|
|
|
|
orderGoods.setLogisticsStatus(logistics.getLogisticsStatus()); |
|
|
|
|