Browse Source

阿米巴开发

anderx 3 years ago
parent
commit
fd10dc9ea9

+ 222 - 0
src/main/java/com/goafanti/ambSystem/bo/InputAmb.java

@@ -0,0 +1,222 @@
+package com.goafanti.ambSystem.bo;
+
+import com.goafanti.common.constant.ErrorConstants;
+import com.goafanti.common.model.AmbSystem;
+import com.goafanti.common.utils.Param;
+
+import javax.validation.constraints.NotNull;
+import java.util.Date;
+
+public class InputAmb extends AmbSystem {
+    /**
+     * 部门id
+     */
+
+    private Long id;
+
+    /**
+     * 父部门id
+     */
+    @Param(name="上级部门")
+    @NotNull(message = "{"+ ErrorConstants.PARAM_EMPTY_ERROR+"}")
+    private Long parentId;
+
+    /**
+     * 祖级列表
+     */
+    private String ancestors;
+
+    /**
+     * 部门名称
+     */
+    @Param(name="吧名称")
+    @NotNull(message = "{"+ ErrorConstants.PARAM_EMPTY_ERROR+"}")
+    private String name;
+
+    /**
+     * 显示顺序
+     */
+    private Integer orderNum;
+
+    /**
+     * 负责人
+     */
+    @Param(name="巴负责人")
+    @NotNull(message = "{"+ ErrorConstants.PARAM_EMPTY_ERROR+"}")
+    private String leader;
+
+    /**
+     * 部门状态(0正常 1停用)
+     */
+    private String status;
+
+    /**
+     * 创建者
+     */
+    private String createBy;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+    /**
+     * 更新者
+     */
+    private String updateBy;
+
+    /**
+     * 更新时间
+     */
+    private Date updateTime;
+
+    /**
+     * 层级 0=集团,1=管综经开总,2=大区总,3=区总,4=事业部总,5=战区总,6=巴总
+     */
+    private Integer lvl;
+
+    /**
+     * 财务id
+     */
+    @Param(name="财务负责人")
+    @NotNull(message = "{"+ ErrorConstants.PARAM_EMPTY_ERROR+"}")
+    private String financeId;
+
+    /**
+     * 祖级名称
+     */
+    private String ancestorsNames;
+
+    private Integer pageNo;
+    private Integer pageSize;
+
+    public Integer getPageNo() {
+        return pageNo;
+    }
+
+    public void setPageNo(Integer pageNo) {
+        this.pageNo = pageNo;
+    }
+
+    public Integer getPageSize() {
+        return pageSize;
+    }
+
+    public void setPageSize(Integer pageSize) {
+        this.pageSize = pageSize;
+    }
+
+    private static final long serialVersionUID = 1L;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getParentId() {
+        return parentId;
+    }
+
+    public void setParentId(Long parentId) {
+        this.parentId = parentId;
+    }
+
+    public String getAncestors() {
+        return ancestors;
+    }
+
+    public void setAncestors(String ancestors) {
+        this.ancestors = ancestors;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Integer getOrderNum() {
+        return orderNum;
+    }
+
+    public void setOrderNum(Integer orderNum) {
+        this.orderNum = orderNum;
+    }
+
+    public String getLeader() {
+        return leader;
+    }
+
+    public void setLeader(String leader) {
+        this.leader = leader;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+    public String getCreateBy() {
+        return createBy;
+    }
+
+    public void setCreateBy(String createBy) {
+        this.createBy = createBy;
+    }
+
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+    public String getUpdateBy() {
+        return updateBy;
+    }
+
+    public void setUpdateBy(String updateBy) {
+        this.updateBy = updateBy;
+    }
+
+    public Date getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(Date updateTime) {
+        this.updateTime = updateTime;
+    }
+
+    public Integer getLvl() {
+        return lvl;
+    }
+
+    public void setLvl(Integer lvl) {
+        this.lvl = lvl;
+    }
+
+    public String getFinanceId() {
+        return financeId;
+    }
+
+    public void setFinanceId(String financeId) {
+        this.financeId = financeId;
+    }
+
+    public String getAncestorsNames() {
+        return ancestorsNames;
+    }
+
+    public void setAncestorsNames(String ancestorsNames) {
+        this.ancestorsNames = ancestorsNames;
+    }
+}

+ 6 - 0
src/main/java/com/goafanti/ambSystem/bo/OutAmb.java

@@ -0,0 +1,6 @@
+package com.goafanti.ambSystem.bo;
+
+import com.goafanti.common.model.AmbSystem;
+
+public class OutAmb extends AmbSystem {
+}

+ 0 - 44
src/main/java/com/goafanti/ambSystem/comtroller/AmbApiController.java

@@ -1,44 +0,0 @@
-package com.goafanti.ambSystem.comtroller;
-
-import com.alibaba.fastjson.JSONObject;
-import com.goafanti.admin.service.AdminService;
-import com.goafanti.ambSystem.service.AmbService;
-import com.goafanti.cognizance.bo.*;
-import com.goafanti.cognizance.service.*;
-import com.goafanti.common.bo.Result;
-import com.goafanti.common.constant.AFTConstants;
-import com.goafanti.common.constant.ErrorConstants;
-import com.goafanti.common.controller.CertifyApiController;
-import com.goafanti.common.enums.*;
-import com.goafanti.common.model.*;
-import com.goafanti.common.utils.*;
-import com.goafanti.copyright.bo.CopyrightInfoDetail;
-import com.goafanti.copyright.service.CopyrightInfoService;
-import com.goafanti.core.shiro.token.TokenManager;
-import com.goafanti.patent.service.PatentInfoService;
-import com.goafanti.user.bo.*;
-import com.goafanti.user.service.UserService;
-import com.goafanti.user.service.*;
-import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Controller;
-import org.springframework.validation.BindingResult;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.validation.Valid;
-import java.math.BigDecimal;
-import java.text.ParseException;
-import java.util.*;
-
-@Controller
-@RequestMapping(value = "/api/amb")
-public class AmbApiController extends CertifyApiController {
-	@Autowired
-	private AmbService ambService;
-}

+ 54 - 0
src/main/java/com/goafanti/ambSystem/controller/AmbApiController.java

@@ -0,0 +1,54 @@
+package com.goafanti.ambSystem.controller;
+
+import com.goafanti.ambSystem.bo.InputAmb;
+import com.goafanti.ambSystem.service.AmbService;
+import com.goafanti.common.bo.Result;
+import com.goafanti.common.constant.ErrorConstants;
+import com.goafanti.common.controller.CertifyApiController;
+import com.goafanti.common.utils.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.BindingResult;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+
+@RestController
+@RequestMapping(value = "/api/admin/amb")
+public class AmbApiController extends CertifyApiController {
+	@Autowired
+	private AmbService ambService;
+
+	@RequestMapping(value="/add",method = RequestMethod.POST)
+	public Result addAmb(@Validated InputAmb in,BindingResult bindingResult){
+		Result res =new Result();
+		if (bindingResult.hasErrors()) {
+			res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
+					ParamUtils.getParamName(in,bindingResult.getFieldError().getField())));
+			return res;
+		}
+		res.data(ambService.addAmb(in));
+		return res;
+	}
+
+	@RequestMapping(value="/update",method = RequestMethod.POST)
+	public Result updateAmb( InputAmb in){
+		Result res =new Result();
+		if (in.getId()==null){
+			res.getError().add(getErrorMessageParams(ErrorConstants.PARAM_EMPTY_ERROR,"巴编号"));
+			return res;
+		}
+		res.data(ambService.updateAmb(in));
+		return res;
+	}
+
+
+	@RequestMapping(value="/select",method = RequestMethod.GET)
+	public Result selectAmb( InputAmb in){
+		Result res =new Result();
+		res.data(ambService.selectAmb(in));
+		return res;
+	}
+
+}

+ 8 - 0
src/main/java/com/goafanti/ambSystem/service/AmbService.java

@@ -1,4 +1,12 @@
 package com.goafanti.ambSystem.service;
 
+import com.goafanti.ambSystem.bo.InputAmb;
+import com.goafanti.core.mybatis.page.Pagination;
+
 public interface AmbService {
+    int addAmb(InputAmb in);
+
+    int updateAmb(InputAmb in);
+
+    Pagination<?> selectAmb(InputAmb in);
 }

+ 68 - 1
src/main/java/com/goafanti/ambSystem/service/Impl/AmbServiceImpl.java

@@ -1,8 +1,75 @@
 package com.goafanti.ambSystem.service.Impl;
 
+import com.goafanti.ambSystem.bo.InputAmb;
+import com.goafanti.ambSystem.bo.OutAmb;
 import com.goafanti.ambSystem.service.AmbService;
+import com.goafanti.common.dao.AmbSystemMapper;
+import com.goafanti.common.model.AmbSystem;
+import com.goafanti.core.mybatis.BaseMybatisDao;
+import com.goafanti.core.mybatis.page.Pagination;
+import com.goafanti.core.shiro.token.TokenManager;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+
 @Service
-public class AmbServiceImpl implements AmbService {
+public class AmbServiceImpl extends BaseMybatisDao<AmbSystemMapper> implements AmbService {
+    @Autowired
+    private AmbSystemMapper ambSystemMapper;
+
+    @Override
+    public int addAmb(InputAmb in) {
+        AmbSystem parentAmb = ambSystemMapper.selectByPrimaryKey(in.getParentId());
+        in.setLvl(parentAmb.getLvl()+1);
+        in.setAncestors(parentAmb.getAncestors()+","+parentAmb.getId());
+        in.setAncestorsNames(getAncestorsNames(in.getAncestors()));
+        in.setStatus("0");
+        in.setCreateBy(TokenManager.getAdminId());
+        in.setCreateTime(new Date());
+        return ambSystemMapper.insertSelective(in);
+    }
+
+    @Override
+    public int updateAmb(InputAmb in) {
+        if (in.getParentId()!=null){
+            AmbSystem parentAmb = ambSystemMapper.selectByPrimaryKey(in.getParentId());
+            in.setLvl(parentAmb.getLvl()+1);
+            in.setAncestors(parentAmb.getAncestors()+","+parentAmb.getId());
+            in.setAncestorsNames(getAncestorsNames(in.getAncestors()));
+        }
+        in.setUpdateBy(TokenManager.getAdminId());
+        in.setUpdateTime(new Date());
+        return ambSystemMapper.updateByPrimaryKeySelective(in);
+    }
+
+    @Override
+    public Pagination<OutAmb> selectAmb(InputAmb in) {
+        HashMap<String, Object> param = new HashMap<>();
+        param.put("name",in.getName());
+        param.put("lvl",in.getLvl());
+        param.put("ancestors",in.getAncestors());
+        return (Pagination<OutAmb>) findPage("selectAmbSystemList","selectAmbSystemCount",param,in.getPageNo(),in.getPageSize());
+    }
+
+    private String getAncestorsNames(String ancestors) {
+        String[] split = ancestors.split(",");
+        List<String> list = Arrays.asList(split);
+        List<AmbSystem> ancestorsList = ambSystemMapper.getAncestorsList(list);
+        StringBuffer sb=new StringBuffer();
+        for (AmbSystem ambSystem : ancestorsList) {
+            for (String s : list) {
+                if (!ambSystem.getId().toString().equals("1")){
+                    if (ambSystem.getId().toString().equals(s)){
+                        sb=sb.append(ambSystem.getName()).append(",");
+                        break;
+                    }
+                }
+            }
+        }
+        return sb.substring(0,sb.length()-1);
+    }
 }

+ 4 - 0
src/main/java/com/goafanti/common/controller/BaseController.java

@@ -103,6 +103,10 @@ public class BaseController {
 		}
 		return (String) msg;
 	}
+	protected Error getErrorMessageParams(String key,Object... params) {
+		String msg = (String) errorResource.getProperty(key);
+		return  new Error(MessageFormat.format( msg, params));
+	}
 
 	protected String getErrorMessage(String key, Object... obj) {
 		return MessageFormat.format(getErrorMessage(key), obj);

+ 5 - 1
src/main/java/com/goafanti/common/dao/AmbSystemMapper.java

@@ -2,6 +2,8 @@ package com.goafanti.common.dao;
 
 import com.goafanti.common.model.AmbSystem;
 
+import java.util.List;
+
 public interface AmbSystemMapper {
     int deleteByPrimaryKey(Long id);
 
@@ -14,4 +16,6 @@ public interface AmbSystemMapper {
     int updateByPrimaryKeySelective(AmbSystem record);
 
     int updateByPrimaryKey(AmbSystem record);
-}
+
+    List<AmbSystem> getAncestorsList(List<String> list);
+}

+ 20 - 11
src/main/java/com/goafanti/common/mapper/AmbSystemMapper.xml

@@ -18,11 +18,11 @@
     <result column="ancestors_names" jdbcType="VARCHAR" property="ancestorsNames" />
   </resultMap>
   <sql id="Base_Column_List">
-    id, parent_id, ancestors, `name`, order_num, leader, `status`, create_by, create_time, 
+    id, parent_id, ancestors, `name`, order_num, leader, `status`, create_by, create_time,
     update_by, update_time, lvl, finance_id, ancestors_names
   </sql>
   <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
-    select 
+    select
     <include refid="Base_Column_List" />
     from amb_system
     where id = #{id,jdbcType=BIGINT}
@@ -32,15 +32,15 @@
     where id = #{id,jdbcType=BIGINT}
   </delete>
   <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.AmbSystem" useGeneratedKeys="true">
-    insert into amb_system (parent_id, ancestors, `name`, 
-      order_num, leader, `status`, 
-      create_by, create_time, update_by, 
-      update_time, lvl, finance_id, 
+    insert into amb_system (parent_id, ancestors, `name`,
+      order_num, leader, `status`,
+      create_by, create_time, update_by,
+      update_time, lvl, finance_id,
       ancestors_names)
-    values (#{parentId,jdbcType=BIGINT}, #{ancestors,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, 
-      #{orderNum,jdbcType=INTEGER}, #{leader,jdbcType=VARCHAR}, #{status,jdbcType=CHAR}, 
-      #{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=VARCHAR}, 
-      #{updateTime,jdbcType=TIMESTAMP}, #{lvl,jdbcType=INTEGER}, #{financeId,jdbcType=VARCHAR}, 
+    values (#{parentId,jdbcType=BIGINT}, #{ancestors,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
+      #{orderNum,jdbcType=INTEGER}, #{leader,jdbcType=VARCHAR}, #{status,jdbcType=CHAR},
+      #{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=VARCHAR},
+      #{updateTime,jdbcType=TIMESTAMP}, #{lvl,jdbcType=INTEGER}, #{financeId,jdbcType=VARCHAR},
       #{ancestorsNames,jdbcType=VARCHAR})
   </insert>
   <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.AmbSystem" useGeneratedKeys="true">
@@ -190,4 +190,13 @@
       ancestors_names = #{ancestorsNames,jdbcType=VARCHAR}
     where id = #{id,jdbcType=BIGINT}
   </update>
-</mapper>
+
+  <select id="getAncestorsList" resultType="com.goafanti.common.model.AmbSystem">
+    select id,name
+    from amb_system
+    where id in
+    <foreach close=")" collection="list" item="id" open="(" separator=",">
+      #{id}
+    </foreach>
+  </select>
+</mapper>

+ 5 - 5
src/main/resources/props/config_local.properties

@@ -1,12 +1,12 @@
 dev.name=local
 jdbc.driverClassName=com.mysql.jdbc.Driver
 #jdbc.url=jdbc\:mysql://localhost:3306/aft20220318?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
-#jdbc.url=jdbc\:mysql://localhost:3306/aft?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
-#jdbc.username=root
-#jdbc.password=123456
-jdbc.url=jdbc:mysql://101.37.32.31:3306/aft?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
+jdbc.url=jdbc\:mysql://localhost:3306/aft?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
 jdbc.username=root
-jdbc.password=aftdev
+jdbc.password=123456
+#jdbc.url=jdbc:mysql://101.37.32.31:3306/aft?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
+#jdbc.username=root
+#jdbc.password=aftdev
 jdbc.validationQuery=SELECT 'x'
 jdbc.initialSize=3
 jdbc.maxActive=20

+ 1 - 1
src/main/resources/shiro_base_auth.ini

@@ -25,4 +25,4 @@
 /admin/**=admin
 /role/**=admin,permission
 /permission/**=admin,permission
-/**=login
+/**=login