Browse Source

新增营销团队开发

anderx 1 year ago
parent
commit
e9330ac861

+ 34 - 0
src/main/java/com/goafanti/admin/bo/SalesTeamBo.java

@@ -0,0 +1,34 @@
+package com.goafanti.admin.bo;
+
+import com.goafanti.common.model.SalesTeam;
+
+public class SalesTeamBo extends SalesTeam {
+
+    private String depName;
+    private String adminName;
+    private String superName;
+
+    public String getDepName() {
+        return depName;
+    }
+
+    public void setDepName(String depName) {
+        this.depName = depName;
+    }
+
+    public String getAdminName() {
+        return adminName;
+    }
+
+    public void setAdminName(String adminName) {
+        this.adminName = adminName;
+    }
+
+    public String getSuperName() {
+        return superName;
+    }
+
+    public void setSuperName(String superName) {
+        this.superName = superName;
+    }
+}

+ 25 - 10
src/main/java/com/goafanti/admin/controller/SalesTeamController.java

@@ -1,13 +1,18 @@
 package com.goafanti.admin.controller;
 
+import com.goafanti.admin.bo.SalesTeamBo;
 import com.goafanti.admin.service.SalesTeamService;
 import com.goafanti.common.bo.Result;
-import com.goafanti.common.controller.BaseController;
+import com.goafanti.common.controller.CertifyApiController;
 import com.goafanti.common.model.SalesTeam;
+import com.goafanti.common.utils.ParamUtils;
+import com.goafanti.core.mybatis.page.Pagination;
+import org.springframework.stereotype.Controller;
+import org.springframework.validation.BindingResult;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
 
@@ -17,9 +22,9 @@ import javax.annotation.Resource;
  * @author makejava
  * @since 2024-12-09 11:18:43
  */
-@RestController
-@RequestMapping("/api/admin/salesTeam")
-public class SalesTeamController extends BaseController {
+@Controller
+@RequestMapping(value = "/api/admin/salesTeam")
+public class AdminSalesTeamController extends CertifyApiController {
     /**
      * 服务对象
      */
@@ -30,12 +35,22 @@ public class SalesTeamController extends BaseController {
     /**
      * 新增数据
      *
-     * @param salesTeam 实体
+     * @param in 实体
      * @return 新增结果
      */
-    @PostMapping("/add")
-    public Result add(SalesTeam salesTeam) {
-        return new Result<>().data(this.salesTeamService.insert(salesTeam));
+    @PostMapping(value = "/add")
+    public Result add(@Validated SalesTeam in, BindingResult bindingResult) {
+        Result res = new Result();
+        if (bindingResult.hasErrors()) {
+            String param=bindingResult.getFieldError().getField();
+            res.getError().add(buildError(ParamUtils.getParamMsg(in,param),ParamUtils.getParamName(in,param)));
+            return res;
+        }
+        if (salesTeamService.checkName(in)){
+            res.getError().add(buildError("团队名称已经存在。"));
+            return res;
+        }
+        return res.data(this.salesTeamService.insert(in));
     }
 
 
@@ -80,7 +95,7 @@ public class SalesTeamController extends BaseController {
      * @return
      */
     @GetMapping("/list")
-    public Result<SalesTeam> list(SalesTeam in, Integer pageNo, Integer pageSize) {
+    public Result<Pagination<SalesTeamBo>> list(SalesTeam in, Integer pageNo, Integer pageSize) {
         return new Result<>().data(this.salesTeamService.list(in, pageNo, pageSize));
     }
 

+ 3 - 1
src/main/java/com/goafanti/admin/service/SalesTeamService.java

@@ -1,5 +1,6 @@
 package com.goafanti.admin.service;
 
+import com.goafanti.admin.bo.SalesTeamBo;
 import com.goafanti.common.model.SalesTeam;
 
 /**
@@ -16,7 +17,7 @@ public interface SalesTeamService {
      * @param id 主键
      * @return 实例对象
      */
-    SalesTeam queryById(Integer id);
+    SalesTeamBo queryById(Integer id);
 
 
     /**
@@ -51,4 +52,5 @@ public interface SalesTeamService {
      */
     Object list(SalesTeam in, Integer pageNo, Integer pageSize);
 
+    boolean checkName(SalesTeam name);
 }

+ 17 - 9
src/main/java/com/goafanti/admin/service/impl/SalesTeamServiceImpl.java

@@ -1,5 +1,6 @@
 package com.goafanti.admin.service.impl;
 
+import com.goafanti.admin.bo.SalesTeamBo;
 import com.goafanti.admin.service.SalesTeamService;
 import com.goafanti.common.dao.SalesTeamMapper;
 import com.goafanti.common.model.SalesTeam;
@@ -8,8 +9,7 @@ import com.goafanti.core.mybatis.page.Pagination;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.Date;
 
 /**
  * 营销团队(SalesTeam)表服务实现类
@@ -24,11 +24,18 @@ public class SalesTeamServiceImpl extends BaseMybatisDao<SalesTeamMapper> implem
 
 
     @Override
-    public Pagination<SalesTeam> list(SalesTeam salesTeam, Integer pageNo, Integer pageSize) {
-        Map<String, Object> params = new HashMap<>();
-        params.put("in", salesTeam);
-        return (Pagination<SalesTeam>) findPage("findSalesTeamList",
-                "findSalesTeamCount", params, pageNo, pageSize);
+    public Pagination<SalesTeamBo> list(SalesTeam salesTeam, Integer pageNo, Integer pageSize) {
+        return (Pagination<SalesTeamBo>) findPage("findSalesTeamList",
+                "findSalesTeamCount", salesTeam, pageNo, pageSize);
+    }
+
+    @Override
+    public boolean checkName(SalesTeam in) {
+        SalesTeam salesTeam = salesTeamMapper.queryByName(in.getName());
+        if (salesTeam != null){
+            return !salesTeam.getId().equals(in.getId());
+        }
+        return false;
     }
 
     /**
@@ -38,8 +45,8 @@ public class SalesTeamServiceImpl extends BaseMybatisDao<SalesTeamMapper> implem
      * @return 实例对象
      */
     @Override
-    public SalesTeam queryById(Integer id) {
-        return this.salesTeamMapper.queryById(id);
+    public SalesTeamBo queryById(Integer id) {
+        return this.salesTeamMapper.queryDetailsById(id);
     }
 
 
@@ -51,6 +58,7 @@ public class SalesTeamServiceImpl extends BaseMybatisDao<SalesTeamMapper> implem
      */
     @Override
     public SalesTeam insert(SalesTeam salesTeam) {
+        salesTeam.setCreateTime(new Date());
         this.salesTeamMapper.insert(salesTeam);
         return salesTeam;
     }

+ 4 - 0
src/main/java/com/goafanti/common/dao/SalesTeamMapper.java

@@ -1,5 +1,6 @@
 package com.goafanti.common.dao;
 
+import com.goafanti.admin.bo.SalesTeamBo;
 import com.goafanti.common.model.SalesTeam;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.data.domain.Pageable;
@@ -81,5 +82,8 @@ public interface SalesTeamMapper {
      */
     int deleteById(Integer id);
 
+    SalesTeam queryByName(String name);
+
+    SalesTeamBo queryDetailsById(Integer id);
 }
 

+ 26 - 42
src/main/java/com/goafanti/common/mapper/SalesTeamMapper.xml

@@ -26,35 +26,20 @@
     </select>
 
     <!--查询指定行数据-->
-    <select id="findSalesTeamList" resultMap="SalesTeamMap">
-        select
-        <include refid="SalesTeamAllSql"/>
-
-        from sales_team
+    <select id="findSalesTeamList" resultType="com.goafanti.admin.bo.SalesTeamBo">
+        select a.id, a.name, a.aid, a.lvl, a.dep_id depId, a.super_id superId, a.status, a.create_time createTime,
+        b.name adminName,c.name depName,d.name superName
+        from sales_team a left join admin b on a.aid=b.id left join department c on a.dep_id=c.id
+        left join sales_team d on a.super_id=d.id
         <where>
-            <if test="id != null">
-                and id = #{id}
-            </if>
-            <if test="name != null and name != ''">
-                and name = #{name}
-            </if>
             <if test="aid != null and aid != ''">
-                and aid = #{aid}
-            </if>
-            <if test="lvl != null">
-                and lvl = #{lvl}
+                and a.aid = #{aid}
             </if>
             <if test="depId != null and depId != ''">
-                and dep_id = #{depId}
-            </if>
-            <if test="superId != null">
-                and super_id = #{superId}
+                and a.dep_id = #{depId}
             </if>
             <if test="status != null">
-                and status = #{status}
-            </if>
-            <if test="createTime != null">
-                and create_time = #{createTime}
+                and a.status = #{status}
             </if>
         </where>
         <if test="page_sql != null">
@@ -65,35 +50,21 @@
     <!--统计总行数-->
     <select id="findSalesTeamCount" resultType="java.lang.Integer">
         select count(1)
-        from sales_team
+        from sales_team a
         <where>
-            <if test="id != null">
-                and id = #{id}
-            </if>
-            <if test="name != null and name != ''">
-                and name = #{name}
-            </if>
             <if test="aid != null and aid != ''">
-                and aid = #{aid}
-            </if>
-            <if test="lvl != null">
-                and lvl = #{lvl}
+                and a.aid = #{aid}
             </if>
             <if test="depId != null and depId != ''">
-                and dep_id = #{depId}
-            </if>
-            <if test="superId != null">
-                and super_id = #{superId}
+                and a.dep_id = #{depId}
             </if>
             <if test="status != null">
-                and status = #{status}
-            </if>
-            <if test="createTime != null">
-                and create_time = #{createTime}
+                and a.status = #{status}
             </if>
         </where>
     </select>
 
+
     <!--新增所有列-->
     <insert id="insert" keyProperty="id" useGeneratedKeys="true">
         insert into sales_team(name, aid, lvl, dep_id, super_id, status, create_time)
@@ -162,5 +133,18 @@
         where id = #{id}
     </delete>
 
+    <select id="queryByName" resultMap="SalesTeamMap">
+        select
+        <include refid="SalesTeamAllSql"/>
+        from sales_team
+        where name = #{name}
+    </select>
+    <select id="queryDetailsById" resultType="com.goafanti.admin.bo.SalesTeamBo">
+        select a.id, a.name, a.aid, a.lvl, a.dep_id depId, a.super_id superId, a.status, a.create_time createTime,
+               b.name adminName,c.name depName,d.name superName
+        from sales_team a left join admin b on a.aid=b.id left join department c on a.dep_id=c.id
+        left join sales_team d on a.super_id=d.id
+    where a.id = #{id}
+    </select>
 </mapper>
 

+ 9 - 0
src/main/java/com/goafanti/common/model/SalesTeam.java

@@ -1,5 +1,9 @@
 package com.goafanti.common.model;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.goafanti.common.utils.Param;
+
+import javax.validation.constraints.NotNull;
 import java.io.Serializable;
 import java.util.Date;
 
@@ -19,6 +23,8 @@ public class SalesTeam implements Serializable {
     /**
      * 团队名称
      */
+    @NotNull
+    @Param(name = "团队名称")
     private String name;
     /**
      * 团队队长编号
@@ -31,6 +37,8 @@ public class SalesTeam implements Serializable {
     /**
      * 部门编号
      */
+    @NotNull
+    @Param(name = "部门编号")
     private String depId;
     /**
      * 上级团队
@@ -102,6 +110,7 @@ public class SalesTeam implements Serializable {
         this.status = status;
     }
 
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     public Date getCreateTime() {
         return createTime;
     }

+ 1 - 2
src/main/java/com/goafanti/order/service/impl/OrderInvoiceServiceImpl.java

@@ -164,8 +164,7 @@ public class OrderInvoiceServiceImpl extends BaseMybatisDao<TOrderInvoiceMapper>
 	@Override
 	public boolean checkAmount(TOrderInvoice t) {
 		TOrderNew tn=tOrderNewMapper.queryById(t.getOrderNo());
-
-			String i=tOrderInvoiceMapper.checkApplyAmount(t.getOrderNo(),t.getId());//新建时直接查所有数据,修改时除掉修改订单
+		String i=tOrderInvoiceMapper.checkApplyAmount(t.getOrderNo(),t.getId());//新建时直接查所有数据,修改时除掉修改订单
 			//处理精度问题
 		BigDecimal q=t.getAmount().add(new BigDecimal(i)).setScale(4, BigDecimal.ROUND_DOWN);;
 		BigDecimal w=tn.getTotalAmount();