Commit f5b89732 authored by kretee's avatar kretee

feat: order表添加字段,address表添加字段

parent 796b966f
......@@ -14,7 +14,13 @@ public enum BizCodeEnum {
/**
* 订单分组
*/
SERVICE_ORDER_NOT_EXIST("订单不存在");
SERVICE_ORDER_NOT_EXIST("订单不存在"),
/**
* 区域分组
*/
SERVICE_AREA_NOT_EXIST("区域不存在");
@Getter
private String msg;
......
package com.onsiteservice.core.exception;
import com.onsiteservice.constant.enums.BizCodeEnum;
import lombok.Getter;
import lombok.Setter;
......@@ -29,6 +30,10 @@ public class ServiceException extends RuntimeException {
super(message);
}
public ServiceException(BizCodeEnum biz) {
super(biz.getMsg());
}
/**
* 自定义传入code状态码和异常信息
*/
......
package com.onsiteservice.dao.mapper.service;
import com.onsiteservice.dao.common.Mapper;
import com.onsiteservice.entity.area.ServiceArea;
public interface ServiceAreaMapper extends Mapper<ServiceArea> {
}
\ No newline at end of file
<?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.onsiteservice.dao.mapper.service.ServiceAreaMapper">
<resultMap id="BaseResultMap" type="com.onsiteservice.entity.area.ServiceArea">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="BIGINT" property="id" />
<result column="code" jdbcType="VARCHAR" property="code" />
<result column="parent_code" jdbcType="VARCHAR" property="parentCode" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="name_path" jdbcType="VARCHAR" property="namePath" />
<result column="level" jdbcType="VARCHAR" property="level" />
<result column="center" jdbcType="VARCHAR" property="center" />
<result column="enabled" jdbcType="BIT" property="enabled" />
<result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
</resultMap>
</mapper>
\ No newline at end of file
......@@ -42,6 +42,18 @@ public class ServiceAddress implements Serializable {
@ApiModelProperty("手机或电话")
private String phone;
/**
* 区域id
*/
@ApiModelProperty("区域id")
private Long areaId;
/**
* 区域名称路径
*/
@ApiModelProperty("区域名称路径")
private String namePath;
/**
* 地址
*/
......
package com.onsiteservice.entity.area;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
@ApiModel("服务区域")
@Table(name = "service_area")
public class ServiceArea implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty("主键")
private Long id;
/**
* 编码
*/
@ApiModelProperty("编码")
private String code;
/**
* 父编码
*/
@Column(name = "parent_code")
@ApiModelProperty("父编码")
private String parentCode;
/**
* 名称
*/
@ApiModelProperty("名称")
private String name;
/**
* 名称路径
*/
@Column(name = "name_path")
@ApiModelProperty("名称路径")
private String namePath;
/**
* 市区街道 city district street
*/
@ApiModelProperty("市区街道 city district street")
private String level;
/**
* 经度,纬度
*/
@ApiModelProperty("经度,纬度")
private String center;
/**
* 是否启用
*/
@ApiModelProperty("是否启用")
private Boolean enabled;
/**
* 修改时间
*/
@Column(name = "modify_time")
@ApiModelProperty("修改时间")
private Date modifyTime;
/**
* 创建时间
*/
@Column(name = "create_time")
@ApiModelProperty("创建时间")
private Date createTime;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
......@@ -24,6 +24,13 @@ public class ServiceOrder implements Serializable {
@ApiModelProperty("主键")
private Long id;
/**
* 订单号
*/
@Column(name = "order_no")
@ApiModelProperty("订单号")
private String orderNo;
/**
* 账号
*/
......
......@@ -20,6 +20,18 @@ public class SaveServiceAddressDTO {
@ApiModelProperty(value = "手机或电话", required = true)
private String phone;
/**
* 区域id
*/
@ApiModelProperty(value = "区域id", required = true)
private Long areaId;
/**
* 区域名称路径
*/
@ApiModelProperty(value = "区域名称路径", required = true)
private String namePath;
/**
* 地址
*/
......
......@@ -23,6 +23,18 @@ public class UpdateServiceAddressDTO {
@ApiModelProperty(value = "手机或电话", required = true)
private String phone;
/**
* 区域id
*/
@ApiModelProperty(value = "区域id", required = true)
private Long areaId;
/**
* 区域名称路径
*/
@ApiModelProperty(value = "区域名称路径", required = true)
private String namePath;
/**
* 地址
*/
......
package com.onsiteservice.miniapp.controller.address.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
......@@ -19,6 +20,16 @@ public class ServiceAddressVO {
*/
private String phone;
/**
* 区域id
*/
private Long areaId;
/**
* 区域名称路径
*/
private String namePath;
/**
* 地址
*/
......
......@@ -16,6 +16,8 @@ public class ServiceOrderVO {
private Long id;
private String orderNo;
private Long accountNo;
/**
......
package com.onsiteservice.miniapp.controller.service;
import com.onsiteservice.entity.area.ServiceArea;
import com.onsiteservice.miniapp.service.service.ServiceAreaService;
import com.onsiteservice.core.result.Result;
import com.onsiteservice.dao.common.page.PageInfoVO;
import com.onsiteservice.dao.common.page.PageParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.NonNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
import javax.validation.constraints.Positive;
import static com.onsiteservice.core.result.ResultGenerator.success;
import static com.onsiteservice.core.result.ResultGenerator.fail;
/**
* @author 潘维吉
* @date 2022-07-08 09:11
* @description ServiceAreaController控制类
*/
@ApiIgnore
@Api(tags = "ServiceAreaController")
@RestController
@RequestMapping("/service/area")
@Validated
public class ServiceAreaController {
@Resource
private ServiceAreaService serviceAreaService;
@ApiOperation(value = "分页查询列表", notes = "作者: 潘维吉")
@PostMapping("/page")
public Result<PageInfoVO> getPage(@RequestBody @NonNull @Validated PageParams param) {
return success(serviceAreaService.getPage(param), "获取分页列表");
}
@ApiOperation(value = "根据id查询", notes = "作者: 潘维吉")
@GetMapping("/{id}")
public Result<ServiceArea> getDetails(@PathVariable @Positive Long id) {
return success(serviceAreaService.selectByPrimaryKey(id), "根据id获取详情");
}
@ApiOperation(value = "新增或修改", notes = "作者: 潘维吉")
@PostMapping("/save-or-update")
public Result saveOrUpdate(@RequestBody @NonNull @Validated ServiceArea serviceArea) {
return success(serviceAreaService.saveOrUpdate(serviceArea), serviceArea.getId() == null ? "新增成功" : "修改成功");
}
@ApiOperation(value = "根据id删除", notes = "作者: 潘维吉")
@DeleteMapping("/{id}")
public Result deleteById(@PathVariable @Positive Long id) {
return success(serviceAreaService.deleteByPrimaryKey(id), "删除成功");
}
}
package com.onsiteservice.miniapp.service.address;
import com.onsiteservice.constant.enums.BizCodeEnum;
import com.onsiteservice.core.exception.ServiceException;
import com.onsiteservice.core.result.Result;
import com.onsiteservice.core.result.ResultGenerator;
import com.onsiteservice.dao.mapper.service.ServiceAreaMapper;
import com.onsiteservice.entity.address.ServiceAddress;
import com.onsiteservice.entity.area.ServiceArea;
import com.onsiteservice.miniapp.controller.address.dto.PageServiceAddressDTO;
import com.onsiteservice.miniapp.controller.address.dto.SaveServiceAddressDTO;
import com.onsiteservice.miniapp.controller.address.dto.UpdateServiceAddressDTO;
......@@ -20,6 +24,7 @@ import tk.mybatis.mapper.entity.Condition;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import static com.onsiteservice.core.result.ResultGenerator.success;
......@@ -28,9 +33,14 @@ import static com.onsiteservice.core.result.ResultGenerator.success;
@Transactional(rollbackFor = Exception.class)
public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
@Resource
private ServiceAddressBizMapper serviceAddressBizMapper;
@Resource
private ServiceAreaMapper serviceAreaMapper;
/**
* 分页查询列表
*/
......@@ -60,6 +70,8 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
public int save(SaveServiceAddressDTO dto, Long userId) {
checkServiceArea(dto.getAreaId());
ServiceAddress serviceAddress = AttrCopyUtils.copy(dto, new ServiceAddress());
serviceAddress.setAccountNo(userId);
return this.insertSelective(serviceAddress);
......@@ -67,9 +79,23 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
public int update(UpdateServiceAddressDTO dto) {
checkServiceArea(dto.getAreaId());
ServiceAddress serviceAddress = AttrCopyUtils.copy(dto, new ServiceAddress());
return this.updateByPrimaryKey(serviceAddress);
}
/**
* 判断区域存在
*
* @param areaId 区域id
*/
private void checkServiceArea(long areaId){
ServiceArea serviceArea = serviceAreaMapper.selectByPrimaryKey(areaId);
if (Objects.isNull(serviceArea)) {
throw new ServiceException(BizCodeEnum.SERVICE_AREA_NOT_EXIST);
}
}
}
......@@ -16,6 +16,7 @@ import com.onsiteservice.miniapp.controller.order.vo.ServiceOrderVO;
import com.onsiteservice.miniapp.mapper.order.ServiceOrderBizMapper;
import com.onsiteservice.miniapp.service.address.ServiceAddressService;
import com.onsiteservice.util.AttrCopyUtils;
import com.onsiteservice.util.RandomUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -62,7 +63,10 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
public int save(SaveServiceOrderDTO dto, Long uid) {
ServiceOrder serviceOrder = AttrCopyUtils.copy(dto, new ServiceOrder());
// 账户号
serviceOrder.setAccountNo(uid);
// 订单号
serviceOrder.setOrderNo(RandomUtils.orderNum());
return this.insertSelective(serviceOrder);
}
......@@ -71,7 +75,7 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
ServiceOrder serviceOrder = this.selectByPrimaryKey(dto.getId());
// 找不到订单
if (Objects.isNull(serviceOrder)) {
throw new ServiceException(BizCodeEnum.SERVICE_ORDER_NOT_EXIST.getMsg());
throw new ServiceException(BizCodeEnum.SERVICE_ORDER_NOT_EXIST);
}
// 估价价格
......
package com.onsiteservice.miniapp.service.service;
import com.onsiteservice.entity.area.ServiceArea;
import com.onsiteservice.dao.mapper.service.ServiceAreaMapper;
import com.onsiteservice.miniapp.mapper.service.ServiceAreaBizMapper;
import com.onsiteservice.dao.common.AbstractMapper;
import com.onsiteservice.dao.common.page.PageParams;
import com.onsiteservice.dao.common.page.PageInfoVO;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
/**
* @author 潘维吉
* @date 2022-07-08 09:11
* @description ServiceAreaService服务类
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class ServiceAreaService extends AbstractMapper<ServiceArea> {
@Resource
private ServiceAreaMapper serviceAreaMapper;
@Resource
private ServiceAreaBizMapper serviceAreaBizMapper;
/**
* 分页查询列表
*/
public PageInfoVO getPage(PageParams param) {
PageHelper.startPage(param.getPage(), param.getSize());
return new PageInfoVO(this.selectAll());
}
/**
* 保存或更新方法
*/
public int saveOrUpdate(ServiceArea serviceArea) {
if (serviceArea.getId() == null) {
return this.insertSelective(serviceArea);
} else {
return this.updateByPrimaryKeySelective(serviceArea);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment