|
@@ -4,9 +4,12 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.ruixuan.common.constant.HttpStatus;
|
|
|
import com.ruixuan.common.core.controller.BaseController;
|
|
|
+import com.ruixuan.common.core.domain.AjaxResult;
|
|
|
+import com.ruixuan.common.core.domain.entity.SysUser;
|
|
|
import com.ruixuan.common.core.page.TableDataInfo;
|
|
|
import com.ruixuan.common.utils.Check;
|
|
|
import com.ruixuan.common.utils.DateUtils;
|
|
|
+import com.ruixuan.data.utils.ExportExcelUtils;
|
|
|
import com.ruixuan.isc.entity.KuaishouAccessToken;
|
|
|
import com.ruixuan.isc.entity.KuaishouRewardBaseInfo;
|
|
|
import com.ruixuan.isc.entity.KwaixiaodianItemGet;
|
|
@@ -21,12 +24,18 @@ import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import io.swagger.models.auth.In;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
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 org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@@ -91,8 +100,6 @@ public class KwaixiaodianItemGetController extends BaseController {
|
|
|
if (!Check.isNull(itemType)) {
|
|
|
requestMap.put("itemType", itemType);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
startPage();
|
|
|
List<KwaixiaodianItemGet> list = kwaixiaodianItemGetService.getItemList(requestMap);
|
|
|
rspData.setCode(HttpStatus.SUCCESS);
|
|
@@ -108,16 +115,67 @@ public class KwaixiaodianItemGetController extends BaseController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @GetMapping("/getShopList")
|
|
|
+ public JSONObject getShopList(Long userId) {
|
|
|
+
|
|
|
+ JSONObject returnJson = new JSONObject();
|
|
|
+ try {
|
|
|
+ if (Check.isNull(userId)) {
|
|
|
+ throw new Exception("请传入用户ID");
|
|
|
+ }
|
|
|
+ String roleId = sysRoleService.getRoleBYUserId(userId);
|
|
|
+ Long companyId = null;
|
|
|
+ if ("admin".equals(roleId)) { // 管理员查看所有
|
|
|
+ companyId = null;
|
|
|
+ } else {
|
|
|
+ companyId = kwaixiaodianItemGetService.getCompanyId(userId);
|
|
|
+ }
|
|
|
+ List<JSONObject> shopList = kwaixiaodianItemGetService.getShopList(companyId);
|
|
|
+ returnJson.put("code", 200);
|
|
|
+ returnJson.put("success", true);
|
|
|
+ returnJson.put("data", shopList);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ returnJson.put("code", 500);
|
|
|
+ returnJson.put("success", false);
|
|
|
+ returnJson.put("message", e.getMessage());
|
|
|
+ }
|
|
|
+ return returnJson;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 获取商品详情(open.item.get)
|
|
|
* https://open.kwaixiaodian.com/zone/new/docs/api?name=open.item.get&version=1
|
|
|
*/
|
|
|
- @GetMapping("/querykwaiItmInfo")
|
|
|
+ @PostMapping("/querykwaiItmInfo")
|
|
|
@ApiOperation(value = "获kwai商品详情")
|
|
|
- public JSONObject querykwaiItmInfo(@ApiParam("商品ID") @RequestParam(value = "itemId", required = false) Long itemId, @ApiParam("店铺ID") @RequestParam(value = "shopId", required = false) String shopId, @ApiParam("用户ID") @RequestParam(value = "userId", required = false) Long userId, @ApiParam("用户") @RequestParam(value = "userName", required = false) String userName, @ApiParam("用户") @RequestParam(value = "itemType", required = false) Integer itemType) {
|
|
|
+ public JSONObject querykwaiItmInfo(@RequestBody JSONObject requestJson) {
|
|
|
|
|
|
JSONObject returnJson = new JSONObject();
|
|
|
try {
|
|
|
+ Long itemId = requestJson.getLong("itemId");
|
|
|
+ if (Check.isNull(itemId)) {
|
|
|
+ throw new Exception("未传入商品ID");
|
|
|
+ }
|
|
|
+
|
|
|
+ String shopId = requestJson.getString("shopId");
|
|
|
+ if (Check.isNull(shopId)) {
|
|
|
+ throw new Exception("未传入小店ID");
|
|
|
+ }
|
|
|
+ Long userId = requestJson.getLong("userId");
|
|
|
+ if (Check.isNull(userId)) {
|
|
|
+ throw new Exception("未传入用户ID");
|
|
|
+ }
|
|
|
+ Integer itemType = requestJson.getInteger("itemType");
|
|
|
+ if (Check.isNull(itemType)) {
|
|
|
+ throw new Exception("未选择选品方式");
|
|
|
+ }
|
|
|
+ SysUser sysUser = sysUserService.selectUserById(userId);
|
|
|
+ if (Check.isNull(sysUser)) {
|
|
|
+ throw new Exception("用户信息为空");
|
|
|
+ }
|
|
|
KuaishouAccessToken token = accessTokenService.getKWaiAccessToken(shopId);
|
|
|
if (Check.isNull(token)) {
|
|
|
throw new Exception("未获取到授权信息,请联系管理员");
|
|
@@ -128,27 +186,214 @@ public class KwaixiaodianItemGetController extends BaseController {
|
|
|
throw new Exception("此商品已绑定");
|
|
|
}
|
|
|
|
|
|
- JSONObject jsonObject = kwaixiaodianItemGetService.querykwaiItmInfo(token, itemId, shopId, userId, userName, itemType);
|
|
|
+ JSONObject jsonObject = kwaixiaodianItemGetService.querykwaiItmInfo(token, itemId, shopId, userId, sysUser.getNickName(), itemType);
|
|
|
if (jsonObject.getBoolean("success")) {
|
|
|
returnJson.put("code", 200);
|
|
|
+ returnJson.put("success", true);
|
|
|
returnJson.put("message", "新增商品成功");
|
|
|
} else {
|
|
|
returnJson.put("code", 500);
|
|
|
+ returnJson.put("success", false);
|
|
|
returnJson.put("message", jsonObject.getString("message"));
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
returnJson.put("code", 500);
|
|
|
+ returnJson.put("success", false);
|
|
|
returnJson.put("message", e.getMessage());
|
|
|
}
|
|
|
return returnJson;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 获取订单列表(open.order.cursor.list)
|
|
|
- * https://open.kwaixiaodian.com/zone/new/docs/api?name=open.order.cursor.list&version=1
|
|
|
- */
|
|
|
+
|
|
|
+ @DeleteMapping("/{ids}")
|
|
|
+ public AjaxResult remove(@PathVariable Long[] ids) {
|
|
|
+ return toAjax(kwaixiaodianItemGetService.deleteById(ids));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping("/queryItemReport")
|
|
|
+ public TableDataInfo getDingPanMentorBusinessList(Long userId, String startDate, String endDate, String shopId, Long itemId, String itemTitle) {
|
|
|
+
|
|
|
+ TableDataInfo rspData = new TableDataInfo();
|
|
|
+ try {
|
|
|
+ Map<String, Object> requestMap = new HashMap<>();
|
|
|
+ if (Check.isNull(userId)) {
|
|
|
+ throw new Exception("请传入用户id");
|
|
|
+ }
|
|
|
+ if (Check.isNull(startDate)) {
|
|
|
+ throw new Exception("请传入开始日期");
|
|
|
+ }
|
|
|
+ if (Check.isNull(endDate)) {
|
|
|
+ throw new Exception("请传入结束日期");
|
|
|
+ }
|
|
|
+
|
|
|
+ String roleId = sysRoleService.getRoleBYUserId(userId);
|
|
|
+ if ("admin".equals(roleId)) { // 管理员查看所有
|
|
|
+
|
|
|
+ } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
|
|
|
+ Long companyId = kwaixiaodianItemGetService.getCompanyId(userId);
|
|
|
+ if (Check.isNull(companyId)) {
|
|
|
+ throw new Exception("此用户未查询到归属公司");
|
|
|
+ }
|
|
|
+ requestMap.put("companyId", companyId);
|
|
|
+ } else if ("industry_sale_manager".equals(roleId) || "industry_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 经理角色查看部门下所有成员数据
|
|
|
+ List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
|
|
|
+ if (Check.isNull(userIds)) {
|
|
|
+ throw new Exception("此用户未查询到部门成员信息");
|
|
|
+ }
|
|
|
+ requestMap.put("userIds", userIds);
|
|
|
+ } else if ("industry_sale".equals(roleId) || "industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 销售 采购 招商 查看自己的数据
|
|
|
+ List<Long> userIds = new ArrayList<>();
|
|
|
+ userIds.add(userId);
|
|
|
+ requestMap.put("userIds", userIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Check.isNull(shopId)) {
|
|
|
+ requestMap.put("shopId", shopId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Check.isNull(itemId)) {
|
|
|
+ requestMap.put("itemId", itemId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Check.isNull(itemTitle)) {
|
|
|
+ requestMap.put("itemTitle", itemTitle);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Long start = DateUtils.strDateToInt(startDate);
|
|
|
+ Long end = DateUtils.strDateToInt(endDate);
|
|
|
+ requestMap.put("start", start);
|
|
|
+ requestMap.put("end", end);
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
|
|
|
+ String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
|
|
|
+ String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
|
|
|
+ requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
|
|
|
+ requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
|
|
|
+ Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
|
|
|
+ if (start.equals(nowDate) && end.equals(nowDate)) {
|
|
|
+ Integer nowHour = DateUtils.getNowHour();
|
|
|
+ requestMap.put("nowHour", nowHour);
|
|
|
+ }
|
|
|
+ startPage();
|
|
|
+ List<JSONObject> data = orderCursorListService.queryItemReport(requestMap);
|
|
|
+ rspData.setCode(HttpStatus.SUCCESS);
|
|
|
+ rspData.setMsg("查询成功");
|
|
|
+ rspData.setRows(data);
|
|
|
+ rspData.setTotal(new PageInfo(data).getTotal());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ rspData.setCode(HttpStatus.ERROR);
|
|
|
+ rspData.setMsg(e.getMessage());
|
|
|
+ }
|
|
|
+ return rspData;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping("/exportItemReport")
|
|
|
+ public void exportItemReport(HttpServletRequest request, HttpServletResponse response, Long userId, String startDate, String endDate, String shopId, Long itemId, String itemTitle) throws IOException, ParseException {
|
|
|
+ Map<String, Object> requestMap = new HashMap<>();
|
|
|
+
|
|
|
+ if (Check.isNull(userId)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (Check.isNull(startDate)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (Check.isNull(endDate)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String roleId = sysRoleService.getRoleBYUserId(userId);
|
|
|
+ if ("admin".equals(roleId)) { // 管理员查看所有
|
|
|
+
|
|
|
+ } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
|
|
|
+ Long companyId = kwaixiaodianItemGetService.getCompanyId(userId);
|
|
|
+ if (Check.isNull(companyId)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ requestMap.put("companyId", companyId);
|
|
|
+ } else if ("industry_sale_manager".equals(roleId) || "industry_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 经理角色查看部门下所有成员数据
|
|
|
+ List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
|
|
|
+ if (Check.isNull(userIds)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ requestMap.put("userIds", userIds);
|
|
|
+ } else if ("industry_sale".equals(roleId) || "industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 销售 采购 招商 查看自己的数据
|
|
|
+ List<Long> userIds = new ArrayList<>();
|
|
|
+ userIds.add(userId);
|
|
|
+ requestMap.put("userIds", userIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Check.isNull(shopId)) {
|
|
|
+ requestMap.put("shopId", shopId);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(itemId)) {
|
|
|
+ requestMap.put("itemId", itemId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Check.isNull(itemTitle)) {
|
|
|
+ requestMap.put("itemTitle", itemTitle);
|
|
|
+ }
|
|
|
+
|
|
|
+ Long start = DateUtils.strDateToInt(startDate);
|
|
|
+ Long end = DateUtils.strDateToInt(endDate);
|
|
|
+ requestMap.put("start", start);
|
|
|
+ requestMap.put("end", end);
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
|
|
|
+ String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
|
|
|
+ String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
|
|
|
+ requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
|
|
|
+ requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
|
|
|
+ Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
|
|
|
+ if (start.equals(nowDate) && end.equals(nowDate)) {
|
|
|
+ Integer nowHour = DateUtils.getNowHour();
|
|
|
+ requestMap.put("nowHour", nowHour);
|
|
|
+ }
|
|
|
+ List<JSONObject> list = orderCursorListService.queryItemReport(requestMap);
|
|
|
+ List<List<Object>> exportList = new ArrayList<>();
|
|
|
+ if (!Check.isNull(list)) {
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ JSONObject data = list.get(i);
|
|
|
+ List<Object> export = new ArrayList();
|
|
|
+ export.add(data.getString("itemId"));
|
|
|
+ export.add(data.getString("itemTitle"));
|
|
|
+ export.add(data.getString("price"));
|
|
|
+ export.add(data.getString("orderNum"));
|
|
|
+ export.add(data.getString("orderNumRate"));
|
|
|
+ export.add(data.getString("validOrderNum"));
|
|
|
+ export.add(data.getString("validRadio"));
|
|
|
+ export.add(data.getString("totalFee"));
|
|
|
+ export.add(data.getString("validTotalFee"));
|
|
|
+ export.add(data.getString("deliveryNum"));
|
|
|
+ export.add(data.getString("deliveryRate"));
|
|
|
+ export.add(data.getString("notDeliveryNum"));
|
|
|
+ export.add(data.getString("expressFee"));
|
|
|
+ export.add(data.getString("userName"));
|
|
|
+ export.add(data.getString("itemPicUrl"));
|
|
|
+ exportList.add(export);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String[] headers = {"商品ID", "商品标题", "商品价格", "单量", "单量环比", "有效单量", "有效率", "GVM", "有效GMV", "发货数", "发货率", "未发货数", "运费", "绑定人", "商品图片"};
|
|
|
+ OutputStream os = response.getOutputStream();
|
|
|
+ ExportExcelUtils eeu = new ExportExcelUtils();
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook();
|
|
|
+ eeu.exportExcel(workbook, 0, "商品数据", headers, exportList);
|
|
|
+ this.setResponseHeader(response, "商品数据.xls");
|
|
|
+ try {
|
|
|
+ workbook.write(os);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ os.flush();
|
|
|
+ os.close();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@GetMapping("/querykwaiOrderList")
|
|
|
@ApiOperation(value = "获kwai订单列表")
|
|
|
public void querykwaiOrderList(@ApiParam("店铺ID") @RequestParam(value = "shopId", required = false) String shopId, @ApiParam("1按创建时间查找 2按更新时间查找") @RequestParam(value = "queryType", required = false) Integer queryType, @ApiParam("开始日期") @RequestParam(value = "beginDate", required = false) String beginDate, @ApiParam("结束日期(间隔不大于7天)") @RequestParam(value = "endDate", required = false) String endDate
|
|
@@ -207,11 +452,19 @@ public class KwaixiaodianItemGetController extends BaseController {
|
|
|
orderCursorListService.queryShop(shopId);
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
- String date0 = DateUtils.getDate();
|
|
|
- String date1 = DateUtils.getSubtractTime(new Date(), 30);
|
|
|
-
|
|
|
- System.out.println(date0);
|
|
|
- System.out.println(date1);
|
|
|
+ public void setResponseHeader(HttpServletResponse response, String fileName) {
|
|
|
+ try {
|
|
|
+ try {
|
|
|
+ fileName = new String(fileName.getBytes(), "ISO8859-1");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ response.setContentType("application/octet-stream;charset=ISO8859-1");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
|
|
|
+ response.addHeader("Pargam", "no-cache");
|
|
|
+ response.addHeader("Cache-Control", "no-cache");
|
|
|
+ } catch (Exception ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
}
|