123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546 |
- package com.ruixuan.isc.controller;
- 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;
- import com.ruixuan.isc.service.IAccessTokenService;
- import com.ruixuan.isc.service.IKwaixiaodianItemGetService;
- import com.ruixuan.isc.service.IKwaixiaodianOrderCursorListService;
- import com.ruixuan.system.service.ISysDeptService;
- import com.ruixuan.system.service.ISysRoleService;
- import com.ruixuan.system.service.ISysUserService;
- import io.swagger.annotations.Api;
- 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.*;
- 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.*;
- /**
- * kwaixiaodian商品详情Controller
- *
- * @date 2024-10-28
- */
- @Api(tags = "Kwaixiaodian")
- @RestController
- @RequestMapping("/kwaixiaodian/item")
- @Slf4j
- public class KwaixiaodianItemGetController extends BaseController {
- @Autowired
- private IKwaixiaodianItemGetService kwaixiaodianItemGetService;
- @Autowired
- private IKwaixiaodianOrderCursorListService orderCursorListService;
- @Autowired
- private IAccessTokenService accessTokenService;
- @Autowired
- private ISysRoleService sysRoleService;
- @Autowired
- private ISysDeptService sysDeptService;
- @Autowired
- private ISysUserService sysUserService;
- @GetMapping(value = "/{id}")
- public AjaxResult getInfo(@PathVariable("id") Long id)
- {
- return AjaxResult.success(kwaixiaodianItemGetService.selectKwaixiaodianItemGetById(id));
- }
- @PutMapping
- public AjaxResult edit(@RequestBody KwaixiaodianItemGet kwaixiaodianItemGet)
- {
- return toAjax(kwaixiaodianItemGetService.updateKwaixiaodianItemGet(kwaixiaodianItemGet));
- }
- @GetMapping("/list")
- public TableDataInfo list(Long itemId, String title, Integer itemType, Long userId) {
- TableDataInfo rspData = new TableDataInfo();
- try {
- if (Check.isNull(userId)) {
- throw new Exception("请传入用户ID");
- }
- Map<String, Object> requestMap = new HashMap<>();
- 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(itemId)) {
- requestMap.put("itemId", itemId);
- }
- if (!Check.isNull(title)) {
- requestMap.put("title", title);
- }
- if (!Check.isNull(itemType)) {
- requestMap.put("itemType", itemType);
- }
- startPage();
- List<KwaixiaodianItemGet> list = kwaixiaodianItemGetService.getItemList(requestMap);
- rspData.setCode(HttpStatus.SUCCESS);
- rspData.setMsg("查询成功");
- rspData.setRows(list);
- rspData.setTotal(new PageInfo(list).getTotal());
- } catch (Exception e) {
- e.printStackTrace();
- rspData.setCode(HttpStatus.ERROR);
- rspData.setMsg(e.getMessage());
- }
- return rspData;
- }
- @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;
- }
- @GetMapping("/getCourtshipPurchaseIds")
- public JSONObject getCourtshipPurchaseIds(Long userId) {
- JSONObject returnJson = new JSONObject();
- try {
- if (Check.isNull(userId)) {
- throw new Exception("请传入用户ID");
- }
- Long companyId = kwaixiaodianItemGetService.getCompanyId(userId);
- List<JSONObject> userIds = kwaixiaodianItemGetService.getCourtshipPurchaseIds(companyId);
- returnJson.put("code", 200);
- returnJson.put("success", true);
- returnJson.put("data", userIds);
- } 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
- */
- @PostMapping("/querykwaiItmInfo")
- @ApiOperation(value = "获kwai商品详情")
- 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("未选择选品方式");
- }
- Long courtshipPurchaseId = requestJson.getLong("courtshipPurchaseId");
- SysUser sysUser = sysUserService.selectUserById(userId);
- if (Check.isNull(sysUser)) {
- throw new Exception("用户信息为空");
- }
- KuaishouAccessToken token = accessTokenService.getKWaiAccessToken(shopId);
- if (Check.isNull(token)) {
- throw new Exception("未获取到授权信息,请联系管理员");
- }
- Long companyId = token.getCompanyId();
- Integer count = kwaixiaodianItemGetService.checkItem(companyId, itemId);
- if (count >= 1) {
- throw new Exception("此商品已绑定");
- }
- JSONObject jsonObject = kwaixiaodianItemGetService.querykwaiItmInfo(token, itemId, shopId, userId, sysUser.getNickName(), itemType, courtshipPurchaseId);
- 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;
- }
- @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, Integer itemType) {
- 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)) { // 销售经理角色查看部门下所有成员数据
- List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
- if (Check.isNull(userIds)) {
- throw new Exception("此用户未查询到部门成员信息");
- }
- requestMap.put("userIds", userIds);
- } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
- List<Long> userIds = new ArrayList<>();
- userIds.add(userId);
- requestMap.put("userIds", userIds);
- } else if ("industry_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据
- List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
- if (Check.isNull(courtshipPurchaseIds)) {
- throw new Exception("此用户未查询到部门成员信息");
- }
- requestMap.put("courtshipPurchaseIds", courtshipPurchaseIds);
- } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据
- List<Long> courtshipPurchaseIds = new ArrayList<>();
- courtshipPurchaseIds.add(userId);
- requestMap.put("courtshipPurchaseIds", courtshipPurchaseIds);
- }
- if (!Check.isNull(shopId)) {
- requestMap.put("shopId", shopId);
- }
- if (!Check.isNull(itemId)) {
- requestMap.put("itemId", itemId);
- }
- if (!Check.isNull(itemTitle)) {
- requestMap.put("itemTitle", itemTitle);
- }
- if (!Check.isNull(itemType)) {
- requestMap.put("itemType", itemType);
- }
- 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, Integer itemType) 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)) { // 销售经理角色查看部门下所有成员数据
- List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
- if (Check.isNull(userIds)) {
- return;
- }
- requestMap.put("userIds", userIds);
- } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
- List<Long> userIds = new ArrayList<>();
- userIds.add(userId);
- requestMap.put("userIds", userIds);
- } else if ("industry_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据
- List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
- if (Check.isNull(courtshipPurchaseIds)) {
- return;
- }
- requestMap.put("courtshipPurchaseIds", courtshipPurchaseIds);
- } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据
- List<Long> courtshipPurchaseIds = new ArrayList<>();
- courtshipPurchaseIds.add(userId);
- requestMap.put("courtshipPurchaseIds", courtshipPurchaseIds);
- }
- if (!Check.isNull(shopId)) {
- requestMap.put("shopId", shopId);
- }
- if (!Check.isNull(itemId)) {
- requestMap.put("itemId", itemId);
- }
- if (!Check.isNull(itemTitle)) {
- requestMap.put("itemTitle", itemTitle);
- }
- if (!Check.isNull(itemType)) {
- requestMap.put("itemType", itemType);
- }
- 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("itemType"));
- export.add(data.getString("orderNum"));
- export.add(data.getString("orderNumRate"));
- export.add(data.getString("validOrderNum"));
- export.add(data.getString("validRadio"));
- export.add(data.getString("effOrderNum"));
- 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("courtshipPurchaseName"));
- 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
- ) {
- try {
- orderCursorListService.querykwaiOrderList(shopId.trim(), queryType, beginDate, endDate, "");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- @GetMapping("/queryNowdayKWaiOrderList")
- @ApiOperation(value = "获当天kwai订单")
- public void queryNowdayKWaiOrderList(@ApiParam("店铺ID") @RequestParam(value = "shopId", required = false) String shopId) {
- try {
- orderCursorListService.queryNowdayKWaiOrderList(shopId.trim(), "");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * 获取订单列表(open.order.cursor.list)
- * https://open.kwaixiaodian.com/zone/new/docs/api?name=open.order.cursor.list&version=1
- */
- @GetMapping("/querykwaiOrderListMonth")
- @ApiOperation(value = "获kwai订单列表月度数据")
- public void querykwaiOrderListMonth(@ApiParam("店铺ID") @RequestParam(value = "shopId", required = false) String shopId) {
- String date1 = DateUtils.getDate();
- String date0 = DateUtils.getSubtractTime(new Date(), 89);
- List<String> allDatesOfTwoTimes = DateUtils.getAllDatesOfTwoTimes(date0, date1);
- for (String date : allDatesOfTwoTimes) {
- orderCursorListService.querykwaiOrderList(shopId.trim(), 1, date, date, "");
- logger.info("shopId:{},日期:{} 执行-----ok", shopId, date);
- }
- }
- /**
- * 获取带货口碑分信息(open.score.master.get)
- * https://open.kwaixiaodian.com/zone/new/docs/api?name=open.score.master.get&version=1
- */
- @GetMapping("/queryMasterScore")
- @ApiOperation(value = "获取带货口碑分信息")
- public void queryMasterScore(@ApiParam("店铺ID") @RequestParam(value = "shopId", required = false) String shopId) {
- orderCursorListService.queryMaster(shopId);
- }
- /**
- * 获取店铺体验分信息(open.score.shop.get)
- * https://open.kwaixiaodian.com/zone/new/docs/api?name=open.score.master.get&version=1
- */
- @GetMapping("/queryShopScore")
- @ApiOperation(value = "获取店铺体验分信息")
- public void queryShopScore(@ApiParam("店铺ID") @RequestParam(value = "shopId", required = false) String shopId) {
- orderCursorListService.queryShop(shopId);
- }
- 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();
- }
- }
- }
|