提交 0740a564 作者: 张小凤

Demand(update)

上级 a04e06cb
package com.mmc.oms.controller.demand;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mmc.oms.common.publicinterface.Insert;
import com.mmc.oms.common.publicinterface.Update;
import com.mmc.oms.common.result.ResultBody;
import com.mmc.oms.controller.BaseController;
import com.mmc.oms.model.vo.demand.CommonPaymentVO;
import com.mmc.oms.model.vo.demand.DemandReleaseOrderVO;
import com.mmc.oms.service.demand.DemandReleaseOrderService;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.util.Date;
/**
* @Author small
* @Date 2023/7/25 15:04
* @Version 1.0
*/
@Api(tags = {"需求发布订单"})
@RestController
@RequestMapping("/releaseOrder")
public class DemandReleaseOrderController extends BaseController {
@Autowired
private DemandReleaseOrderService releaseOrderService;
@ApiIgnore
@ApiOperation(value = "小程序——需求发布订单")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@PostMapping("/publish")
public ResultBody publish(@RequestBody @Validated(value = {Insert.class}) DemandReleaseOrderVO demandReleaseOrderVO, HttpServletRequest request) {
demandReleaseOrderVO.setUserAccountId(this.getCurrentAccount(request).getUserAccountId());
return releaseOrderService.publish(demandReleaseOrderVO, request);
}
@ApiOperation(value = "订单支付")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@PostMapping("/orderPayment")
public ResultBody orderPayment(@RequestBody @Validated CommonPaymentVO commonPaymentVO, HttpServletRequest request) {
return releaseOrderService.orderPayment(commonPaymentVO, request,this.getCurrentAccount(request).getUserAccountId());
}
}
package com.mmc.oms.dao.demand;
import com.mmc.oms.entity.demand.DemandReleaseOrderDO;
import org.apache.ibatis.annotations.Mapper;
/**
* @Author small
* @Date 2023/7/25 15:53
* @Version 1.0
*/
@Mapper
public interface DemandReleaseOrderDao {
void addRequirementsInfo(DemandReleaseOrderDO requirementsInfoDO);
DemandReleaseOrderDO orderPayment(String orderNumber);
}
package com.mmc.oms.entity.demand;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mmc.oms.common.publicinterface.Insert;
import com.mmc.oms.common.publicinterface.Update;
import com.mmc.oms.model.vo.demand.DemandReleaseOrderVO;
import com.mmc.oms.model.vo.demand.OrderRequestParamsVO;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
* @Author small
* @Date 2023/7/25 15:51
* @Version 1.0
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DemandReleaseOrderDO implements Serializable {
private static final long serialVersionUID = -1811974173256250060L;
private Integer id;
private Integer requirementTypeId;
private Integer userAccountId;
private Integer provinceCode;
private Integer cityCode;
private Integer districtCode;
private String publishName;
private String publishPhone;
private String requireDescription;
private Integer deleted;
//是否解决
private Boolean solved;
private Date createTime;
private Date updateTime;
@ApiModelProperty(value = "任务标题", example = "任务标题001", required = true)
@NotBlank(message = "任务标题不能为空", groups = {Insert.class, Update.class})
@Size(max = 15, message = "任务标题限制15个字")
private String taskTitle;
@ApiModelProperty(value = "任务开始时间", example = "2023-07-25", required = true)
@NotNull(message = "任务开始时间不能为空", groups = {Insert.class, Update.class})
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date taskStartTime;
@ApiModelProperty(value = "任务结束时间", example = "2023-07-26", required = true)
@NotNull(message = "任务开始时间不能为空", groups = {Insert.class, Update.class})
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date taskEndTime;
@ApiModelProperty(value = "任务地址", example = "广东省深圳市", required = true)
@NotBlank(message = "任务地址不能为空", groups = {Insert.class, Update.class})
private String taskAddress;
@ApiModelProperty(value = "任务经度", example = "23.344324", required = true)
@NotNull(message = "任务经度不能为空", groups = {Insert.class, Update.class})
private Double longitude;
@ApiModelProperty(value = "任务纬度", example = "44.344324", required = true)
@NotNull(message = "任务纬度不能为空", groups = {Insert.class, Update.class})
private Double latitude;
@ApiModelProperty(value = "描述图片", example = "http://,http://", required = false)
private String requireUrl;
@ApiModelProperty(value = "类型名称",example = "航拍摄影")
private String requirementTypeName;
@ApiModelProperty(value = "订单编号",example = "R202307251459553408130")
private String orderNumber;
@ApiModelProperty(value = "应支付金额 单位元", example = "1.00")
private BigDecimal paramMoney;
@ApiModelProperty(value = "发布者id", example = "1", required = true)
private Integer publishAccountId;
public DemandReleaseOrderDO(DemandReleaseOrderVO requirementsInfoVO) {
this.requirementTypeId = requirementsInfoVO.getRequirementTypeId();
this.requirementTypeName=requirementsInfoVO.getRequirementTypeName();
this.userAccountId = requirementsInfoVO.getUserAccountId();
this.publishName = requirementsInfoVO.getPublishName();
this.publishPhone = requirementsInfoVO.getPublishPhone();
this.requireDescription = requirementsInfoVO.getRequireDescription();
this.taskStartTime = requirementsInfoVO.getTaskStartTime();
this.taskEndTime = requirementsInfoVO.getTaskEndTime();
this.taskTitle = requirementsInfoVO.getTaskTitle();
this.taskAddress = requirementsInfoVO.getTaskAddress();
this.longitude = requirementsInfoVO.getLongitude();
this.latitude = requirementsInfoVO.getLatitude();
this.requireUrl = requirementsInfoVO.getRequireUrl();
this.orderNumber=requirementsInfoVO.getOrderNumber();
this.paramMoney=requirementsInfoVO.getParamMoney();
this.publishAccountId=requirementsInfoVO.getPublishAccountId();
}
public OrderRequestParamsVO buildOrderRequestParamsVO() {
return OrderRequestParamsVO.builder().orderNo(this.orderNumber).description(this.requireDescription).
orderPort(3)
.build();
}
}
package com.mmc.oms.model.vo.demand;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author small
* @Date 2023/7/25 17:32
* @Version 1.0
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CommonPaymentVO {
@ApiModelProperty(value = "订单编号",example = "R202307251459553408130")
private String orderNumber;
@ApiModelProperty(value = "订单来源 0:产品商城 1:租赁订单 2:培训订单 3发布需求 ...其他后续加")
private Integer orderPort;
}
package com.mmc.oms.model.vo.demand;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.util.Date;
/**
* @Author small
* @Date 2023/7/25 15:43
* @Version 1.0
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class DemandReleaseOrderVO {
private static final long serialVersionUID = -447951390213113317L;
@ApiModelProperty(value = "需求类型id", example = "1", required = true)
private Integer requirementTypeId;
@ApiModelProperty(value = "任务标题", example = "任务标题001", required = true)
private String taskTitle;
@ApiModelProperty(value = "任务开始时间", example = "2023-07-25", required = true)
private Date taskStartTime;
@ApiModelProperty(value = "任务结束时间", example = "2023-07-26", required = true)
private Date taskEndTime;
@ApiModelProperty(value = "任务地址", example = "广东省深圳市", required = true)
private String taskAddress;
@ApiModelProperty(value = "任务经度", example = "23.344324", required = true)
private Double longitude;
@ApiModelProperty(value = "任务纬度", example = "44.344324", required = true)
private Double latitude;
@ApiModelProperty(value = "需求描述", example = "描述一下", required = true)
private String requireDescription;
@ApiModelProperty(value = "描述图片", example = "http://,http://", required = false)
private String requireUrl;
@ApiModelProperty(value = "发布者姓名", example = "张三")
private String publishName;
@ApiModelProperty(value = "发布者电话", example = "1892994543", required = true)
private String publishPhone;
@ApiModelProperty(value = "发布者id", example = "1", required = true)
private Integer publishAccountId;
/**
* 后台获取token里面的用户id
*/
@ApiModelProperty(value = "token用户id")
private Integer userAccountId;
@ApiModelProperty(value = "类型名称")
private String requirementTypeName;
@ApiModelProperty(value = "订单编号",example = "R202307251459553408130")
private String orderNumber;
@ApiModelProperty(value = "应支付金额 单位元", example = "1.00")
private BigDecimal paramMoney;
}
package com.mmc.oms.model.vo.demand;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @Author small
* @Date 2023/7/25 17:39
* @Version 1.0
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class OrderRequestParamsVO implements Serializable {
@ApiModelProperty(value = "订单编号")
private String orderNo;
@ApiModelProperty(value = "商品描述")
private String description;
@ApiModelProperty(value = "订单金额(分为单位)")
private Integer amount;
@ApiModelProperty(value = "订单来源 0:产品商城 1:租赁订单 2:培训订单 ...其他后续加")
private Integer orderPort;
}
package com.mmc.oms.service.demand;
import com.mmc.oms.common.result.ResultBody;
import com.mmc.oms.model.vo.demand.CommonPaymentVO;
import com.mmc.oms.model.vo.demand.DemandReleaseOrderVO;
import javax.servlet.http.HttpServletRequest;
/**
* @Author small
* @Date 2023/7/25 15:48
* @Version 1.0
*/
public interface DemandReleaseOrderService {
ResultBody publish(DemandReleaseOrderVO demandReleaseOrderVO, HttpServletRequest request);
ResultBody orderPayment(CommonPaymentVO commonPaymentVO, HttpServletRequest request, Integer userAccountId);
}
package com.mmc.oms.service.demand.Impl;
import com.alibaba.fastjson.JSONObject;
import com.mmc.oms.common.ResultEnum;
import com.mmc.oms.common.result.ResultBody;
import com.mmc.oms.dao.demand.DemandReleaseOrderDao;
import com.mmc.oms.entity.demand.DemandReleaseOrderDO;
import com.mmc.oms.model.vo.demand.CommonPaymentVO;
import com.mmc.oms.model.vo.demand.DemandReleaseOrderVO;
import com.mmc.oms.model.vo.demand.OrderRequestParamsVO;
import com.mmc.oms.service.demand.DemandReleaseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
/**
* @Author small
* @Date 2023/7/25 15:49
* @Version 1.0
*/
@Service
public class DemandReleaseOrderServiceImpl implements DemandReleaseOrderService {
@Autowired
private DemandReleaseOrderDao releaseOrderDao;
@Autowired
private RestTemplate restTemplate;
@Value("${payment.url}")
private String paymentUrl;
@Override
public ResultBody publish(DemandReleaseOrderVO demandReleaseOrderVO, HttpServletRequest request) {
DemandReleaseOrderDO requirementsInfoDO = new DemandReleaseOrderDO(demandReleaseOrderVO);
releaseOrderDao.addRequirementsInfo(requirementsInfoDO);
return ResultBody.success();
}
@Override
public ResultBody orderPayment(CommonPaymentVO commonPaymentVO, HttpServletRequest request, Integer userAccountId) {
String token = request.getHeader("token");
ResultBody resultBody=null;
if ("3".equals(commonPaymentVO.getOrderPort().toString())){
DemandReleaseOrderDO demandReleaseOrderDO = releaseOrderDao.orderPayment(commonPaymentVO.getOrderNumber());
BigDecimal paramMoney = demandReleaseOrderDO.getParamMoney();
BigDecimal multiply = paramMoney.multiply(new BigDecimal(100));
int i = multiply.intValue();
OrderRequestParamsVO orderRequestParamsVO = demandReleaseOrderDO.buildOrderRequestParamsVO();
orderRequestParamsVO.setAmount(i);
resultBody = releaseOrder(orderRequestParamsVO, token);
if (!resultBody.getCode().equals("200")){
return resultBody;
}
}
return resultBody;
}
public ResultBody releaseOrder(OrderRequestParamsVO orderRequestParamsVO, String token) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("token", token);
HttpEntity<String> entity = new HttpEntity<>(JSONObject.toJSONString(orderRequestParamsVO), headers);
ResponseEntity<Object> exchange = null;
Map<String , Object> map = new HashMap<>();
try {
exchange = restTemplate.exchange(paymentUrl + "wechat/pay", HttpMethod.POST, entity, Object.class);
map.put("Ok", exchange.getBody());
} catch (RestClientException e) {
return ResultBody.error(ResultEnum.THIRD_PARTY_ERRORS);
}
return ResultBody.success(map);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mmc.oms.dao.demand.DemandReleaseOrderDao">
<insert id="addRequirementsInfo" parameterType="com.mmc.oms.entity.demand.DemandReleaseOrderDO"
keyProperty="id" useGeneratedKeys="true">
INSERT INTO demand_release_order(requirement_type_id, user_account_id, publish_name, publish_phone,publish_account_id,
require_description, create_time,
update_time, task_title, task_start_time, task_end_time, task_address, longitude,
latitude, require_url,order_number,param_money,requirement_type_name)
VALUES (#{requirementTypeId}, #{userAccountId}, #{publishName}, #{publishPhone},#{publishAccountId},
#{requireDescription}, NOW(),
NOW(), #{taskTitle}, #{taskStartTime}, #{taskEndTime}, #{taskAddress}, #{longitude},
#{latitude}, #{requireUrl},#{orderNumber},#{paramMoney},#{requirementTypeName});
</insert>
<select id="orderPayment" resultType="com.mmc.oms.entity.demand.DemandReleaseOrderDO">
select * from demand_release_order where order_number=#{orderNumber}
</select>
</mapper>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论