Ver Fonte

客户配置api更新

shudonghui há 1 ano atrás
pai
commit
f0cc5e1fc8

+ 13 - 1
sop-business/src/main/java/com/qmth/sop/business/bean/result/SysCustomResult.java

@@ -1,6 +1,7 @@
 package com.qmth.sop.business.bean.result;
 
 import com.qmth.sop.business.entity.SysCustom;
+import com.qmth.sop.business.entity.SysCustomAddr;
 import io.swagger.annotations.ApiModelProperty;
 
 import java.io.Serializable;
@@ -30,7 +31,18 @@ public class SysCustomResult extends SysCustom implements Serializable {
     private String createName;
 
     @ApiModelProperty(value = "项目角色配置")
-    private List<SysLevelRoleResult>  roleList= new ArrayList<>();;
+    private List<SysLevelRoleResult>  roleList= new ArrayList<>();
+
+    @ApiModelProperty(value = "校区地址")
+    private List<SysCustomAddr>  addrList= new ArrayList<>();
+
+    public List<SysCustomAddr> getAddrList() {
+        return addrList;
+    }
+
+    public void setAddrList(List<SysCustomAddr> addrList) {
+        this.addrList = addrList;
+    }
 
     public List<SysLevelRoleResult> getRoleList() {
         return roleList;

+ 101 - 0
sop-business/src/main/java/com/qmth/sop/business/entity/SysCustomAddr.java

@@ -0,0 +1,101 @@
+package com.qmth.sop.business.entity;
+
+import java.io.Serializable;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.sop.common.base.BaseEntity;
+import com.qmth.sop.common.contant.SystemConstant;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import org.hibernate.validator.constraints.NotBlank;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * 客户表 模型.
+ * 
+ * @author: shudonghui
+ * @date: 2023-08-30 08:30:30
+ * @version: 1.0
+ * @email: shudonghui@qmth.com.cn
+ * @Company: www.qmth.com.cn
+ */
+@ApiModel(value = "sys_custom_addr对象", description = "客户表")
+public class SysCustomAddr implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+
+	@JsonSerialize(using = ToStringSerializer.class)
+	@ApiModelProperty(value = "主键")
+	@TableId(value = "id")
+	private Long id;
+
+  	@ApiModelProperty(value = "客户ID")
+	@JsonSerialize(using = ToStringSerializer.class)
+	@NotNull(message = "客户ID不能为空")
+  	private long customId;
+  	@ApiModelProperty(value = "地址")
+	@NotBlank(message = "地址不能为空")
+  	private String address;
+  	@ApiModelProperty(value = "经度")
+	@NotBlank(message = "经度不能为空")
+  	private String longitude;
+  	@ApiModelProperty(value = "纬度")
+	@NotBlank(message = "纬度不能为空")
+  	private String latitude;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public long getCustomId() {
+		return customId;
+	}
+
+	public void setCustomId(long customId) {
+		this.customId = customId;
+	}
+
+	/**
+	 * 地址
+	 */	
+  	public void setAddress(String address) {
+		this.address = address;
+  	}
+ 	/**
+	 * 地址
+	 */	 	
+  	public String getAddress() {
+		return address;
+  	}
+	/**
+	 * 经度
+	 */	
+  	public void setLongitude(String longitude) {
+		this.longitude = longitude;
+  	}
+ 	/**
+	 * 经度
+	 */	 	
+  	public String getLongitude() {
+		return longitude;
+  	}
+	/**
+	 * 纬度
+	 */	
+  	public void setLatitude(String latitude) {
+		this.latitude = latitude;
+  	}
+ 	/**
+	 * 纬度
+	 */	 	
+  	public String getLatitude() {
+		return latitude;
+  	}
+}

+ 28 - 0
sop-business/src/main/java/com/qmth/sop/business/mapper/SysCustomAddrMapper.java

@@ -0,0 +1,28 @@
+package com.qmth.sop.business.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.qmth.sop.business.entity.SysCustomAddr;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Param;
+import java.util.Map;
+
+/**
+ * 客户表 Mapper 接口.
+ * 
+ * @author: shudonghui
+ * @date: 2023-08-30 08:30:31
+ * @version: 1.0
+ * @email: shudonghui@qmth.com.cn
+ * @Company: www.qmth.com.cn
+ */
+public interface SysCustomAddrMapper extends BaseMapper<SysCustomAddr> {
+
+	/**
+	 * 查询列表
+	 * @param iPage
+	 * @return
+	 */
+	public IPage<SysCustomAddr> query(IPage<Map> iPage, @Param("query") String query);
+
+}

+ 43 - 0
sop-business/src/main/java/com/qmth/sop/business/service/SysCustomAddrService.java

@@ -0,0 +1,43 @@
+package com.qmth.sop.business.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.sop.business.entity.SysCustomAddr;
+import java.util.Map;
+
+/**
+ * 客户表 服务类
+ *
+ * @author: shudonghui
+ * @date: 2023-08-30 08:30:31
+ * @version: 1.0
+ * @email: shudonghui@qmth.com.cn
+ * @Company: www.qmth.com.cn
+ */
+public interface SysCustomAddrService extends IService<SysCustomAddr>{
+
+    /**
+    * 查询列表
+    *
+    * @param iPage
+    * @return
+    */
+    IPage<SysCustomAddr> query(IPage<Map> iPage,String query);
+
+    /**
+    * 新增修改客户表
+    *
+    * @param sysCustomAddr
+    */
+    Boolean saveSysCustomAddr(SysCustomAddr sysCustomAddr);
+
+
+    /**
+    * 删除客户表
+    *
+    * @param id
+    */
+    Boolean delete(Long id);
+
+
+}

+ 1 - 4
sop-business/src/main/java/com/qmth/sop/business/service/SysCustomService.java

@@ -28,10 +28,7 @@ public interface SysCustomService extends IService<SysCustom>{
     */
     IPage<SysCustomResult>  query(Page<Map> iPage, ProductTypeEnum type, Long managerId, String name, Long levelId);
 
-    void add(SysCustom sysCustom);
-
-    void update(SysCustom sysCustom);
-
     void delete(Long id);
 
+    boolean saveCustom(SysCustomResult sysCustom);
 }

+ 88 - 0
sop-business/src/main/java/com/qmth/sop/business/service/impl/SysCustomAddrServiceImpl.java

@@ -0,0 +1,88 @@
+package com.qmth.sop.business.service.impl;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.boot.api.exception.ApiException;
+import com.qmth.sop.business.entity.SysCustomAddr;
+import com.qmth.sop.business.entity.SysUser;
+import com.qmth.sop.business.mapper.SysCustomAddrMapper;
+import com.qmth.sop.business.service.SysCustomAddrService;
+import com.qmth.sop.common.contant.SystemConstant;
+import com.qmth.sop.common.enums.ExceptionResultEnum;
+import com.qmth.sop.common.enums.FieldUniqueEnum;
+import com.qmth.sop.common.util.ResultUtil;
+import com.qmth.sop.common.util.ServletUtil;
+import org.springframework.dao.DuplicateKeyException;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * 客户表 服务实现.
+ *
+ * @author: shudonghui
+ * @date: 2023-08-30 08:30:31
+ * @version: 1.0
+ * @email: shudonghui@qmth.com.cn
+ * @Company: www.qmth.com.cn
+ */
+@Service
+public class SysCustomAddrServiceImpl extends ServiceImpl<SysCustomAddrMapper, SysCustomAddr> implements SysCustomAddrService{
+
+
+		/**
+		* 查询列表
+		*
+		* @param iPage
+		* @return
+		*/
+		@Override
+		public IPage<SysCustomAddr> query(IPage<Map> iPage,String query) {
+				return this.baseMapper.query(iPage,query);
+		}
+		/**
+		* 新增修改客户表
+		*
+		* @param sysCustomAddr
+		*/
+		@Override
+		@Transactional
+		public Boolean saveSysCustomAddr(SysCustomAddr sysCustomAddr) {
+			try {
+				SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
+				if (Objects.isNull(sysCustomAddr.getId())) {// 新增
+					//sysCustomAddr.insertInfo(sysUser.getId());
+				} else { // 修改
+					//sysCustomAddr.updateInfo(sysUser.getId());
+				}
+				return saveOrUpdate(sysCustomAddr);
+			} catch (Exception e) {
+				if (e instanceof DuplicateKeyException) {
+				String errorColumn = e.getCause().toString();
+				String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
+				throw ExceptionResultEnum.SQL_ERROR.exception("[" + FieldUniqueEnum.convertToTitle(columnStr) + "]数据不允许重复插入");
+				} else if (e instanceof ApiException) {
+				ResultUtil.error((ApiException) e, e.getMessage());
+				} else {
+				ResultUtil.error(e.getMessage());
+				}
+			}
+			return null;
+
+		}
+
+		/**
+		* 删除客户表
+		*
+		* @param id
+		*/
+		@Override
+		@Transactional
+		public Boolean delete(Long id) {
+			return this.removeById(id);
+		}
+
+}

+ 45 - 15
sop-business/src/main/java/com/qmth/sop/business/service/impl/SysCustomServiceImpl.java

@@ -4,14 +4,21 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.boot.api.exception.ApiException;
 import com.qmth.sop.business.bean.result.SysCustomResult;
 import com.qmth.sop.business.entity.SysCustom;
+import com.qmth.sop.business.entity.SysCustomAddr;
 import com.qmth.sop.business.entity.SysUser;
 import com.qmth.sop.business.mapper.SysCustomMapper;
+import com.qmth.sop.business.service.SysCustomAddrService;
 import com.qmth.sop.business.service.SysCustomService;
 import com.qmth.sop.business.service.SysLevelRoleService;
+import com.qmth.sop.common.enums.ExceptionResultEnum;
+import com.qmth.sop.common.enums.FieldUniqueEnum;
 import com.qmth.sop.common.enums.ProductTypeEnum;
+import com.qmth.sop.common.util.ResultUtil;
 import com.qmth.sop.common.util.ServletUtil;
+import org.springframework.dao.DuplicateKeyException;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -33,6 +40,9 @@ public class SysCustomServiceImpl extends ServiceImpl<SysCustomMapper, SysCustom
     @Resource
     SysLevelRoleService sysLevelRoleService;
 
+    @Resource
+    SysCustomAddrService sysCustomAddrService;
+
     /**
      * 查询列表
      *
@@ -43,28 +53,47 @@ public class SysCustomServiceImpl extends ServiceImpl<SysCustomMapper, SysCustom
     public IPage<SysCustomResult> query(Page<Map> iPage, ProductTypeEnum type, Long managerId, String name, Long levelId) {
         IPage<SysCustomResult> sysCustomResultIPage = this.baseMapper.query(iPage, Objects.nonNull(type) ? type.name() : null, Objects.nonNull(managerId) ? managerId : null, name, Objects.nonNull(levelId) ? levelId : null);
         sysCustomResultIPage.getRecords().forEach(e -> {
-            e.setRoleList(sysLevelRoleService.getList(e.getId()));
+            e.setRoleList(sysLevelRoleService.getList(e.getLevelId()));
+            e.setAddrList(sysCustomAddrService.list(new QueryWrapper<SysCustomAddr>().lambda().eq(SysCustomAddr::getCustomId,e.getId())));
         });
         return  sysCustomResultIPage;
     }
 
-    @Override
-    @Transactional
-    public void add(SysCustom sysCustom) {
-        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
-        sysCustom.setCreateId(sysUser.getId());
-        sysCustom.setCreateTime(System.currentTimeMillis());
-        this.saveOrUpdate(sysCustom);
-
-    }
 
+    /**
+     * 新增修改客户表
+     *
+     * @param sysCustom
+     */
     @Override
     @Transactional
-    public void update(SysCustom sysCustom) {
-        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
-        sysCustom.setUpdateId(sysUser.getId());
-        sysCustom.setUpdateTime(System.currentTimeMillis());
-        this.saveOrUpdate(sysCustom);
+    public boolean saveCustom(SysCustomResult sysCustom) {
+        try {
+            SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
+            if (Objects.isNull(sysCustom.getId())) {// 新增
+                sysCustom.insertInfo(sysUser.getId());
+            } else { // 修改
+                sysCustom.updateInfo(sysUser.getId());
+                sysCustomAddrService.remove(new QueryWrapper<SysCustomAddr>().lambda().eq(SysCustomAddr::getCustomId,sysCustom.getId()));
+            }
+            sysCustom.getAddrList().forEach(e->{
+                e.setCustomId(sysCustom.getId());
+                sysCustomAddrService.saveOrUpdate(e);
+            });
+            return saveOrUpdate(sysCustom);
+        } catch (Exception e) {
+            if (e instanceof DuplicateKeyException) {
+                String errorColumn = e.getCause().toString();
+                String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
+                throw ExceptionResultEnum.SQL_ERROR.exception("[" + FieldUniqueEnum.convertToTitle(columnStr) + "]数据不允许重复插入");
+            } else if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
+        }
+        return false;
+
     }
 
 
@@ -75,4 +104,5 @@ public class SysCustomServiceImpl extends ServiceImpl<SysCustomMapper, SysCustom
     }
 
 
+
 }

+ 10 - 0
sop-business/src/main/resources/mapper/SysCustomAddrMapper.xml

@@ -0,0 +1,10 @@
+<?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.qmth.sop.business.mapper.SysCustomAddrMapper">
+
+    <select id="query" resultType="com.qmth.sop.business.entity.SysCustomAddr">
+        select * from sys_custom_addr a
+
+        order by a.create_time desc
+    </select>
+</mapper>

+ 14 - 6
sop-server/src/main/java/com/qmth/sop/server/api/SysCustomController.java

@@ -7,7 +7,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.sop.business.bean.result.SysCustomResult;
 import com.qmth.sop.business.entity.SysCustom;
+import com.qmth.sop.business.entity.SysCustomAddr;
 import com.qmth.sop.business.entity.TBTask;
+import com.qmth.sop.business.service.SysCustomAddrService;
 import com.qmth.sop.business.service.SysCustomService;
 import com.qmth.sop.business.service.TBTaskService;
 import com.qmth.sop.business.templete.execute.AsyncSysCustomImportService;
@@ -52,6 +54,9 @@ public class SysCustomController {
     @Resource
     TBTaskService tbTaskService;
 
+    @Resource
+    SysCustomAddrService sysCustomAddrService;
+
 
 
     @ApiOperation(value = "客户表查询接口")
@@ -72,11 +77,11 @@ public class SysCustomController {
     @ApiOperation(value = "新增客户表接口")
     @RequestMapping(value = "/add", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "新增客户表信息", response = Object.class)})
-    public Result add(@Valid @ApiParam(value = "客户信息", required = true) @RequestBody(required = true) SysCustom sysCustom, BindingResult bindingResult) throws InterruptedException {
+    public Result add(@Valid @ApiParam(value = "客户信息", required = true) @RequestBody(required = true) SysCustomResult sysCustom, BindingResult bindingResult) throws InterruptedException {
         if (bindingResult.hasErrors()) {
             return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
         }
-        sysCustomService.add(sysCustom);
+        sysCustomService.saveCustom(sysCustom);
         return ResultUtil.ok();
     }
 
@@ -84,11 +89,11 @@ public class SysCustomController {
     @ApiOperation(value = "修改客户表接口")
     @RequestMapping(value = "/update", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "修改客户表信息", response = Object.class)})
-    public Result update(@Valid @ApiParam(value = "客户信息", required = true) @RequestBody(required = true) SysCustom sysCustom, BindingResult bindingResult) throws InterruptedException {
+    public Result update(@Valid @ApiParam(value = "客户信息", required = true) @RequestBody(required = true) SysCustomResult sysCustom, BindingResult bindingResult) throws InterruptedException {
         if (bindingResult.hasErrors()) {
             return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
         }
-        sysCustomService.update(sysCustom);
+        sysCustomService.saveCustom(sysCustom);
         return ResultUtil.ok();
     }
 
@@ -109,9 +114,12 @@ public class SysCustomController {
 
     @ApiOperation(value = "获取单个客户")
     @RequestMapping(value = "/get", method = RequestMethod.GET)
-    @ApiResponses({@ApiResponse(code = 200, message = "获取单个客户", response = SysCustom.class)})
+    @ApiResponses({@ApiResponse(code = 200, message = "获取单个客户", response = SysCustomResult.class)})
     public Result detail(@ApiParam(value = "客户id", required = true) @RequestParam(required = true) long id) {
-        return ResultUtil.ok(sysCustomService.getById(id));
+        SysCustom sysCustom = sysCustomService.getById(id);
+        SysCustomResult sysCustomResult = JSON.toJavaObject((JSON) JSON.toJSON(sysCustom), SysCustomResult.class);
+        sysCustomResult.setAddrList(sysCustomAddrService.list(new QueryWrapper<SysCustomAddr>().lambda().eq(SysCustomAddr::getCustomId,sysCustomResult.getId())));
+        return ResultUtil.ok(sysCustomResult);
     }