Commit f81095bf by 丁伟峰

容量查询、预约订单相关的接口代码实现

1 parent 51156bcc
Showing with 331 additions and 78 deletions
...@@ -19,18 +19,14 @@ package com.alibaba.cloud.integration.order.controller; ...@@ -19,18 +19,14 @@ package com.alibaba.cloud.integration.order.controller;
import com.alibaba.cloud.integration.common.BusinessException; import com.alibaba.cloud.integration.common.BusinessException;
import com.alibaba.cloud.integration.common.Result; import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.dto.OrderCreateReqDTO; import com.alibaba.cloud.integration.order.dto.OrderCreateReqDTO;
import com.alibaba.cloud.integration.order.dto.TimeRangeReqDTO; import com.alibaba.cloud.integration.order.dto.CapacityQueryReqDTO;
import com.alibaba.cloud.integration.order.service.OrderService; import com.alibaba.cloud.integration.order.service.OrderService;
import com.alibaba.cloud.integration.order.service.ProductService; import com.alibaba.cloud.integration.order.service.CapacityQueryService;
import com.alibaba.cloud.integration.order.service.TimeRangeService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
/**
* @author TrevorLink
*/
@RestController @RestController
public class OrderCreateController { public class OrderCreateController {
...@@ -38,10 +34,7 @@ public class OrderCreateController { ...@@ -38,10 +34,7 @@ public class OrderCreateController {
private OrderService orderService; private OrderService orderService;
@Autowired @Autowired
private ProductService productService; private CapacityQueryService capacityQueryService;
@Autowired
private TimeRangeService timeRangeService;
@PostMapping("/order/service/create") @PostMapping("/order/service/create")
public Result<?> createOrder(@Validated @RequestBody OrderCreateReqDTO orderCreateReqDTO) { public Result<?> createOrder(@Validated @RequestBody OrderCreateReqDTO orderCreateReqDTO) {
...@@ -58,18 +51,18 @@ public class OrderCreateController { ...@@ -58,18 +51,18 @@ public class OrderCreateController {
public Result<?> getParameter() { public Result<?> getParameter() {
Result<?> res = null; Result<?> res = null;
try { try {
res = productService.getProductCategoryList(); res = orderService.initParameter();
} catch (BusinessException e) { } catch (BusinessException e) {
return Result.failed(e.getMessage()); return Result.failed(e.getMessage());
} }
return res; return res;
} }
@PostMapping("/order/service/timerange") @PostMapping("/order/service/capacity/query")
public Result<?> getTimerange(@Validated @RequestBody TimeRangeReqDTO timeRangeReqDTO) { public Result<?> capacityQuery(@Validated @RequestBody CapacityQueryReqDTO capacityQueryReqDTO) {
Result<?> res = null; Result<?> res = null;
try { try {
res = timeRangeService.getTimeRangeData(timeRangeReqDTO); res = capacityQueryService.getOneCapacityData(capacityQueryReqDTO);
} catch (BusinessException e) { } catch (BusinessException e) {
return Result.failed(e.getMessage()); return Result.failed(e.getMessage());
} }
......
package com.alibaba.cloud.integration.order.dao; package com.alibaba.cloud.integration.order.dao;
import com.alibaba.cloud.integration.order.entity.CapacityTeamStatEntity; import com.alibaba.cloud.integration.order.entity.CapacityTeamStatEntity;
import org.hibernate.annotations.Where;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@Repository
public interface CapacityTeamStatDao extends JpaRepository<CapacityTeamStatEntity, Long> { public interface CapacityTeamStatDao extends JpaRepository<CapacityTeamStatEntity, Long> {
List<CapacityTeamStatEntity> findAllByTeamIdAndSkillTagAndWorkdayBetween(String teamId, String skill, String beginDate, String endDate); List<CapacityTeamStatEntity> findAllByTeamIdAndLayerAndWorkdayBetween(String teamId, String layer, String beginDate, String endDate);
} }
package com.alibaba.cloud.integration.order.dao;
import com.alibaba.cloud.integration.order.entity.MapBlockInfoEntity;
import org.hibernate.annotations.Where;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
@Repository
@Where(clause = "status = 1")
public interface MapBlockInfoDao extends JpaRepository<MapBlockInfoEntity, Integer> {
@Query("select s.teamId from MapBlockInfoEntity s where s.blockId = :blockId and s.layer = :layer")
String getTeamidByBlockidAndLayer(String blockId, String layer);
}
...@@ -3,5 +3,5 @@ package com.alibaba.cloud.integration.order.dao; ...@@ -3,5 +3,5 @@ package com.alibaba.cloud.integration.order.dao;
import com.alibaba.cloud.integration.order.entity.OrderRequestEntity; import com.alibaba.cloud.integration.order.entity.OrderRequestEntity;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
public interface OrderReqeustDao extends JpaRepository <OrderRequestEntity, Long> { public interface OrderRequestDao extends JpaRepository <OrderRequestEntity, Long> {
} }
...@@ -2,6 +2,12 @@ package com.alibaba.cloud.integration.order.dao; ...@@ -2,6 +2,12 @@ package com.alibaba.cloud.integration.order.dao;
import com.alibaba.cloud.integration.order.entity.ProductCategoryEntity; import com.alibaba.cloud.integration.order.entity.ProductCategoryEntity;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface ProductCategoryDao extends JpaRepository<ProductCategoryEntity, Long> { public interface ProductCategoryDao extends JpaRepository<ProductCategoryEntity, Long> {
ProductCategoryEntity getProductCategoryEntityByBrandAndTypeAndSkill(String brand, String type, String skill);
@Query("select p.layer from ProductCategoryEntity p where p.brand = :brand and p.type = :type and p.skill = :skill")
String getLayerByBrandAndTypeAndSkill(String brand, String type, String skill);
} }
...@@ -3,9 +3,12 @@ package com.alibaba.cloud.integration.order.dto; ...@@ -3,9 +3,12 @@ package com.alibaba.cloud.integration.order.dto;
import lombok.Data; import lombok.Data;
@Data @Data
public class TimeRangeReqDTO { public class CapacityQueryReqDTO {
private String location; private String location;
private String categoryId; private String address;
private String brand;
private String type;
private String skill;
private String beginDate; private String beginDate;
private String endDate; private String endDate;
} }
package com.alibaba.cloud.integration.order.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
@Data
@Accessors(chain = true)
public class CapacityQueryRespDTO {
private String beginDate;
private String endDate;
private String remark;
private List<LegendDTO> legend;
private List<CalendarDTO> calendar;
@Data
@Accessors(chain = true)
public static class LegendDTO {
private int type;
private String memo;
}
@Data
@Accessors(chain = true)
public static class CalendarDTO {
private String week;
private String date;
private List<TimeDTO> times;
}
@Data
@Accessors(chain = true)
public static class TimeDTO {
private String text;
private String begin;
private String end;
private int type;
}
}
...@@ -9,7 +9,8 @@ public class OrderCreateReqDTO { ...@@ -9,7 +9,8 @@ public class OrderCreateReqDTO {
private String address; private String address;
private LocationDTO location; private LocationDTO location;
private String brand; private String brand;
private String catalogId; private String type;
private String skill;
private String faultDescribe; private String faultDescribe;
private String expectBegin; private String expectBegin;
private String expectEnd; private String expectEnd;
......
...@@ -8,7 +8,6 @@ import java.util.List; ...@@ -8,7 +8,6 @@ import java.util.List;
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class ParameterRespDTO { public class ParameterRespDTO {
private List<BrandDTO> brands;
private List<KeyValueDTO> priorities; private List<KeyValueDTO> priorities;
private List<KeyValueDTO> standardTags; private List<KeyValueDTO> standardTags;
} }
...@@ -35,7 +35,7 @@ public class CapacityTeamStatEntity implements Serializable { ...@@ -35,7 +35,7 @@ public class CapacityTeamStatEntity implements Serializable {
private String teamId; private String teamId;
private String skillTag; private String layer;
private Integer engineerCount; private Integer engineerCount;
...@@ -67,4 +67,4 @@ public class CapacityTeamStatEntity implements Serializable { ...@@ -67,4 +67,4 @@ public class CapacityTeamStatEntity implements Serializable {
private Date updateTime; private Date updateTime;
} }
\ No newline at end of file
package com.alibaba.cloud.integration.order.entity;
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Entity
@Data
@Table(name="map_block_Info")
public class MapBlockInfoEntity {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
/**
* 主键
*/
private Integer id;
/**
* 区块id
*/
private String blockId;
/**
* 区块名称
*/
private String blockName;
/**
* 归属分部
*/
private String subsectionId;
/**
* 归属小组
*/
private String groupId;
/**
* 所在城市id
*/
private String cityCode;
/**
* 面数据
*/
private String areaData;
/**
* 类型(1自然行政片区,2自定义片区)
*/
private int kind;
/**
* 关联小队id
*/
private String teamId;
/**
* 图标标签,[基础图层,ggn] -- 与map_layer.layer 对应
*/
private String layer;
/**
* 状态(0无效 1有效)
*/
private int status;
/**
* 备注
*/
private String memo;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
public MapBlockInfoEntity() {}
}
...@@ -23,76 +23,64 @@ public class ProductCategoryEntity { ...@@ -23,76 +23,64 @@ public class ProductCategoryEntity {
/** /**
* 小组id * 小组id
*/ */
@Column(name="product_category_id")
private String productCategoryId; private String productCategoryId;
/** /**
* 品牌 * 品牌
*/ */
@Column(name="brand")
private String brand; private String brand;
/** /**
* 产品类别 * 产品类别
*/ */
@Column(name="type")
private String type; private String type;
/** /**
* 服务类型 * 服务类型
*/ */
@Column(name="skill")
private String skill; private String skill;
/** /**
* 所需工时(分钟) * 所需工时(分钟)
*/ */
@Column(name="take_time")
private Integer takeTime; private Integer takeTime;
/** /**
* 所需人数 * 所需人数
*/ */
@Column(name="take_engineer")
private Integer takeEngineer; private Integer takeEngineer;
/** /**
* 是否需要低压电工证 * 是否需要低压电工证
*/ */
@Column(name="low_electrician_cert")
private int lowElectricianCert; private int lowElectricianCert;
/** /**
* 是否需要燃气证 * 是否需要燃气证
*/ */
@Column(name="gas_cert")
private int gasCert; private int gasCert;
/** /**
* 图层标签 * 图层标签
*/ */
@Column(name="tag") private String layer;
private String tag;
/** /**
* 备注 * 备注
*/ */
@Column(name="memo")
private String memo; private String memo;
/** /**
* 创建时间 * 创建时间
*/ */
@Column(name="create_time")
private Date createTime; private Date createTime;
/** /**
* 更新时间 * 更新时间
*/ */
@Column(name="update_time")
private Date updateTime; private Date updateTime;
public ProductCategoryEntity() { public ProductCategoryEntity() {
} }
} }
\ No newline at end of file
package com.alibaba.cloud.integration.order.service;
import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.dto.CapacityQueryReqDTO;
import com.fasterxml.jackson.core.JsonProcessingException;
public interface CapacityQueryService {
/**
* 单条容量查询
* @param capacityQueryReqDTO
* @return
* @throws JsonProcessingException
*/
Result<?> getOneCapacityData(CapacityQueryReqDTO capacityQueryReqDTO);
}
...@@ -25,6 +25,8 @@ import com.alibaba.cloud.integration.order.dto.OrderCreateReqDTO; ...@@ -25,6 +25,8 @@ import com.alibaba.cloud.integration.order.dto.OrderCreateReqDTO;
*/ */
public interface OrderService { public interface OrderService {
Result<?> initParameter();
Result<?> createOrder(OrderCreateReqDTO orderCreateReqDTO) Result<?> createOrder(OrderCreateReqDTO orderCreateReqDTO)
throws BusinessException; throws BusinessException;
......
package com.alibaba.cloud.integration.order.service;
import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.dto.TimeRangeReqDTO;
public interface TimeRangeService {
Result<?> getTimeRangeData(TimeRangeReqDTO timeRangeReqDTO);
}
...@@ -2,15 +2,21 @@ package com.alibaba.cloud.integration.order.service.impl; ...@@ -2,15 +2,21 @@ package com.alibaba.cloud.integration.order.service.impl;
import com.alibaba.cloud.integration.common.Result; import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.dao.CapacityTeamStatDao; import com.alibaba.cloud.integration.order.dao.CapacityTeamStatDao;
import com.alibaba.cloud.integration.order.dto.CalendarDTO; import com.alibaba.cloud.integration.order.dao.MapBlockInfoDao;
import com.alibaba.cloud.integration.order.dto.TimeDTO; import com.alibaba.cloud.integration.order.dao.ProductCategoryDao;
import com.alibaba.cloud.integration.order.dto.TimeRangeReqDTO; import com.alibaba.cloud.integration.order.dto.CapacityQueryReqDTO;
import com.alibaba.cloud.integration.order.dto.TimeRangeRespDTO; import com.alibaba.cloud.integration.order.dto.CapacityQueryRespDTO;
import com.alibaba.cloud.integration.order.entity.CapacityTeamStatEntity; import com.alibaba.cloud.integration.order.entity.CapacityTeamStatEntity;
import com.alibaba.cloud.integration.order.service.TimeRangeService; import com.alibaba.cloud.integration.order.service.CapacityQueryService;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import java.time.DayOfWeek; import java.time.DayOfWeek;
import java.time.LocalDate; import java.time.LocalDate;
...@@ -20,22 +26,30 @@ import java.util.*; ...@@ -20,22 +26,30 @@ import java.util.*;
@Service @Service
@Slf4j @Slf4j
public class TimeRangeServiceImpl implements TimeRangeService { public class CapacityQueryServiceImpl implements CapacityQueryService {
private final String[] fullDay = {"08:00", "18:00"}; private final String[] fullDay = {"08:00", "18:00"};
@Autowired @Autowired
private CapacityTeamStatDao capacityTeamStatDao; private CapacityTeamStatDao capacityTeamStatDao;
@Autowired
private ProductCategoryDao productCategoryDao;
@Autowired
private MapBlockInfoDao mapBlockInfoDao;
@Override @Override
public Result<?> getTimeRangeData(TimeRangeReqDTO reqDTO) { public Result<?> getOneCapacityData(CapacityQueryReqDTO reqDTO) {
/* /*
location ==> [layer_info] ==> team ==> (+skill) ==> [capacity_team_stat] location ==> [layer_info] ==> team ==> (+skill) ==> [capacity_team_stat]
*/ */
String teamId = getTeamByLayer(reqDTO.getLocation()); String layer = productCategoryDao.getLayerByBrandAndTypeAndSkill(reqDTO.getBrand(), reqDTO.getType(), reqDTO.getSkill());
TimeRangeRespDTO timeRangeRespDTO = new TimeRangeRespDTO(); String teamId = getTeamByLayer(reqDTO.getLocation(), reqDTO.getAddress(), layer);
timeRangeRespDTO.setBeginDate(timeRangeRespDTO.getBeginDate()).setEndDate(reqDTO.getEndDate()); CapacityQueryRespDTO capacityQueryRespDTO = new CapacityQueryRespDTO();
timeRangeRespDTO.setCalendar(getTimeRangeByTeamSkill(teamId, reqDTO.getCategoryId(), reqDTO.getBeginDate(), reqDTO.getEndDate())); capacityQueryRespDTO.setBeginDate(capacityQueryRespDTO.getBeginDate()).setEndDate(reqDTO.getEndDate());
return Result.success(timeRangeRespDTO); capacityQueryRespDTO.setCalendar(getTimeRangeByTeamSkill(teamId, reqDTO.getSkill(), reqDTO.getBeginDate(), reqDTO.getEndDate()));
capacityQueryRespDTO.setRemark(String.format("%s-%s", teamId, layer));
return Result.success(capacityQueryRespDTO);
} }
/** /**
...@@ -45,9 +59,53 @@ public class TimeRangeServiceImpl implements TimeRangeService { ...@@ -45,9 +59,53 @@ public class TimeRangeServiceImpl implements TimeRangeService {
* @param location * @param location
* @return * @return
*/ */
private String getTeamByLayer(String location) { private String getTeamByLayer(String location, String address, String layer) {
// todo // todo 由于saas的分单接口尚未完成,目前仅仅是调用分单获取
return null; // 创建RestTemplate实例
RestTemplate restTemplate = new RestTemplate();
// 设置请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
// 构建请求参数
String url;
MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
params.add("ak", "284c57cbabad4755a9c657885a8df3e2");
if (location != null && !location.isEmpty()) {
url = "https://pea-test.bshg.com.cn/v2/xyfendan";
params.add("coordinate", location);
} else {
url = "https://pea-test.bshg.com.cn/v2/fendan";
params.add("addresses", String.format("[{\"address\":\"%s\"}]", address));
}
params.add("need_district", "true");
params.add("need_layer", "true");
params.add("related_point_fields", "");
params.add("area_fields", "名称,唯一编号");
// 构建请求实体
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers);
// 发送POST请求
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
// 获取响应结果
String responseBody = responseEntity.getBody();
// 使用Jackson库解析JSON数据
ObjectMapper objectMapper = new ObjectMapper();
try {
JsonNode responseJson = objectMapper.readTree(responseBody);
// 获取areaResults[0]的值
JsonNode areaResult = responseJson.get("result").get(0).get("areaResults").get(0);
// 将areaResult转换为JSON字符串
// todo 分单接口其实也应该直接返回 图层
return mapBlockInfoDao.getTeamidByBlockidAndLayer(areaResult.get("field2").toString(), layer);
} catch (Exception e) {
return null;
}
} }
private int getSpanType(int capLeft, int capTotal) { private int getSpanType(int capLeft, int capTotal) {
...@@ -82,23 +140,23 @@ public class TimeRangeServiceImpl implements TimeRangeService { ...@@ -82,23 +140,23 @@ public class TimeRangeServiceImpl implements TimeRangeService {
* 根据工作队、技能,返回对应时间段内的容量 * 根据工作队、技能,返回对应时间段内的容量
* *
* @param teamId * @param teamId
* @param skill * @param layer
* @param beginDate * @param beginDate
* @param endDate * @param endDate
* @return * @return
*/ */
private List<CalendarDTO> getTimeRangeByTeamSkill(String teamId, String skill, String beginDate, String endDate) { private List<CapacityQueryRespDTO.CalendarDTO> getTimeRangeByTeamSkill(String teamId, String layer, String beginDate, String endDate) {
Map<String, CalendarDTO> dayMaps = new HashMap<>(); Map<String, CapacityQueryRespDTO.CalendarDTO> dayMaps = new HashMap<>();
List<CapacityTeamStatEntity> capacityTeamStatEntityList = capacityTeamStatDao.findAllByTeamIdAndSkillTagAndWorkdayBetween(teamId, skill, beginDate, endDate); List<CapacityTeamStatEntity> capacityTeamStatEntityList = capacityTeamStatDao.findAllByTeamIdAndLayerAndWorkdayBetween(teamId, layer, beginDate, endDate);
for (CapacityTeamStatEntity e : capacityTeamStatEntityList) { for (CapacityTeamStatEntity e : capacityTeamStatEntityList) {
TimeDTO timeDTO = new TimeDTO(); CapacityQueryRespDTO.TimeDTO timeDTO = new CapacityQueryRespDTO.TimeDTO();
timeDTO.setType(getSpanType(e.getCapLeft(), e.getCapTotal())); timeDTO.setType(getSpanType(e.getCapLeft(), e.getCapTotal()));
Object[] timeSpans = getTimeSpanInfo(e.getWorkday(), e.getTimeSpan(), e.getTimeSpanDetail()); Object[] timeSpans = getTimeSpanInfo(e.getWorkday(), e.getTimeSpan(), e.getTimeSpanDetail());
timeDTO.setText((String) timeSpans[0]); timeDTO.setText((String) timeSpans[0]);
timeDTO.setBegin((String) timeSpans[1]); timeDTO.setBegin((String) timeSpans[1]);
timeDTO.setEnd((String) timeSpans[2]); timeDTO.setEnd((String) timeSpans[2]);
if (!dayMaps.containsKey(e.getWorkday())) { if (!dayMaps.containsKey(e.getWorkday())) {
CalendarDTO calendarDTO = new CalendarDTO(); CapacityQueryRespDTO.CalendarDTO calendarDTO = new CapacityQueryRespDTO.CalendarDTO();
calendarDTO.setDate(e.getWorkday()); calendarDTO.setDate(e.getWorkday());
calendarDTO.setWeek(getWeekday(e.getWorkday())); calendarDTO.setWeek(getWeekday(e.getWorkday()));
dayMaps.put(e.getWorkday(), calendarDTO); dayMaps.put(e.getWorkday(), calendarDTO);
...@@ -114,4 +172,5 @@ public class TimeRangeServiceImpl implements TimeRangeService { ...@@ -114,4 +172,5 @@ public class TimeRangeServiceImpl implements TimeRangeService {
DayOfWeek weekday = date.getDayOfWeek(); DayOfWeek weekday = date.getDayOfWeek();
return String.format("周%s", weekday.getDisplayName(TextStyle.SHORT, Locale.CHINA)); return String.format("周%s", weekday.getDisplayName(TextStyle.SHORT, Locale.CHINA));
} }
} }
...@@ -17,30 +17,73 @@ ...@@ -17,30 +17,73 @@
package com.alibaba.cloud.integration.order.service.impl; package com.alibaba.cloud.integration.order.service.impl;
import com.alibaba.cloud.integration.common.Result; import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.dao.OrderReqeustDao; import com.alibaba.cloud.integration.order.dao.OrderRequestDao;
import com.alibaba.cloud.integration.order.dao.OrderTagStrategyDao;
import com.alibaba.cloud.integration.order.dao.ProductCategoryDao;
import com.alibaba.cloud.integration.order.dto.KeyValueDTO;
import com.alibaba.cloud.integration.order.dto.LocationDTO; import com.alibaba.cloud.integration.order.dto.LocationDTO;
import com.alibaba.cloud.integration.order.dto.OrderCreateReqDTO; import com.alibaba.cloud.integration.order.dto.OrderCreateReqDTO;
import com.alibaba.cloud.integration.order.dto.ParameterRespDTO;
import com.alibaba.cloud.integration.order.entity.OrderRequestEntity; import com.alibaba.cloud.integration.order.entity.OrderRequestEntity;
import com.alibaba.cloud.integration.order.feign.AccountServiceFeignClient; import com.alibaba.cloud.integration.order.entity.ProductCategoryEntity;
import com.alibaba.cloud.integration.order.feign.StorageServiceFeignClient;
import com.alibaba.cloud.integration.order.mapper.OrderMapper;
import com.alibaba.cloud.integration.order.service.OrderService; import com.alibaba.cloud.integration.order.service.OrderService;
import io.seata.core.context.RootContext; import io.seata.core.context.RootContext;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Slf4j @Slf4j
@Service @Service
public class OrderServiceImpl implements OrderService { public class OrderServiceImpl implements OrderService {
@Autowired @Autowired
private OrderReqeustDao orderReqeustDao; private OrderRequestDao orderRequestDao;
@Autowired
private OrderTagStrategyDao orderTagStrategyDao;
@Autowired
private ProductCategoryDao productCategoryDao;
private List<KeyValueDTO> getPriorities() {
List<KeyValueDTO> listPriorities = new ArrayList<>();
int prioritiesLevels = 10;
for (int i = 0; i <= prioritiesLevels; i++) {
String label;
if (i == 0) {
label = "最低";
} else if (i == prioritiesLevels) {
label = "最高";
} else {
label = String.format("优先级%d", i);
}
listPriorities.add(new KeyValueDTO().setLabel(label).setValue(String.valueOf(i)));
}
return listPriorities;
}
private List<KeyValueDTO> getStandardTags() {
List<KeyValueDTO> tagList = new ArrayList<>();
for (String tag : orderTagStrategyDao.getAllTags()) {
tagList.add(new KeyValueDTO().setLabel(tag).setValue(tag));
}
return tagList;
}
@Override
public Result<?> initParameter() {
ParameterRespDTO respDTO = new ParameterRespDTO();
respDTO.setPriorities(getPriorities()).setStandardTags(getStandardTags());
return Result.success(respDTO);
}
@Override @Override
@GlobalTransactional
public Result<?> createOrder(OrderCreateReqDTO req) { public Result<?> createOrder(OrderCreateReqDTO req) {
log.info("[createOrder] current XID: {}", RootContext.getXID()); log.info("[createOrder] current XID: {}", RootContext.getXID());
...@@ -49,7 +92,13 @@ public class OrderServiceImpl implements OrderService { ...@@ -49,7 +92,13 @@ public class OrderServiceImpl implements OrderService {
entity.setPhone(req.getPhone()); entity.setPhone(req.getPhone());
entity.setAddress(req.getAddress()); entity.setAddress(req.getAddress());
entity.setBrand(req.getBrand()); entity.setBrand(req.getBrand());
entity.setCategoryId(req.getCatalogId());
ProductCategoryEntity categoryEntity = productCategoryDao.getProductCategoryEntityByBrandAndTypeAndSkill(req.getBrand(), req.getType(), req.getSkill());
if (categoryEntity == null) {
throw new RuntimeException("产品代码不存在!");
}
String catalogId = categoryEntity.getProductCategoryId();
entity.setCategoryId(catalogId);
entity.setFaultDescribe(req.getFaultDescribe()); entity.setFaultDescribe(req.getFaultDescribe());
entity.setExpectTimeBegin(req.getExpectBegin()); entity.setExpectTimeBegin(req.getExpectBegin());
entity.setExpectTimeEnd(req.getExpectEnd()); entity.setExpectTimeEnd(req.getExpectEnd());
...@@ -59,7 +108,7 @@ public class OrderServiceImpl implements OrderService { ...@@ -59,7 +108,7 @@ public class OrderServiceImpl implements OrderService {
entity.setProvince(location.getProvince()); entity.setProvince(location.getProvince());
entity.setCity(location.getCity()); entity.setCity(location.getCity());
entity.setCounty(location.getCountry()); entity.setCounty(location.getCountry());
orderReqeustDao.save(entity);
// 根据orderTags, 解析保存到type、skill等字段 // 根据orderTags, 解析保存到type、skill等字段
String[] l = req.getLocation().getLocation().split(","); String[] l = req.getLocation().getLocation().split(",");
entity.setX(l[0]); entity.setX(l[0]);
...@@ -67,6 +116,7 @@ public class OrderServiceImpl implements OrderService { ...@@ -67,6 +116,7 @@ public class OrderServiceImpl implements OrderService {
// todo 服务单状态、预约状态等 // todo 服务单状态、预约状态等
entity.setStatus(""); entity.setStatus("");
entity.setAppointmentStatus(""); entity.setAppointmentStatus("");
orderRequestDao.save(entity);
return Result.success(null); return Result.success(null);
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!