Antiloveg %!s(int64=8) %!d(string=hai) anos
pai
achega
f51c43af0c

+ 15 - 1
schema/2017-06-06.sql

@@ -1,3 +1,17 @@
 alter table `admin` 
 add column `superior_id` varchar(36) null comment '上级管理用户ID',
-add column `city` varchar(16) null comment '所在市';
+add column `city` varchar(16) null comment '所在市';
+
+CREATE TABLE .`admin_location` (
+  `id` VARCHAR(36) NOT NULL,
+  `admin_id` VARCHAR(36) NOT NULL COMMENT '管理员ID',
+  `province` INT(2) NOT NULL COMMENT '省份',
+  `city` INT(3) NULL COMMENT '市',
+  PRIMARY KEY (`id`))
+ENGINE = InnoDB
+COMMENT = '管理员地区';
+
+alter table user_identity
+modify column `province` int(2) null comment '所在地-省份',
+modify column `city` int(3) null comment '所在地--市',
+modify column `area` int(4) null comment '所在地--区';

+ 4 - 3
src/main/java/com/goafanti/admin/bo/AdminLocationBo.java

@@ -3,7 +3,7 @@ package com.goafanti.admin.bo;
 public class AdminLocationBo {
 	private Integer province;
 	
-	private Integer city;
+	private String city;
 
 	public Integer getProvince() {
 		return province;
@@ -13,14 +13,15 @@ public class AdminLocationBo {
 		this.province = province;
 	}
 
-	public Integer getCity() {
+	public String getCity() {
 		return city;
 	}
 
-	public void setCity(Integer city) {
+	public void setCity(String city) {
 		this.city = city;
 	}
 
+
 	
 	
 

+ 50 - 17
src/main/java/com/goafanti/admin/controller/AdminApiController.java

@@ -100,6 +100,7 @@ import com.goafanti.common.enums.UserFields;
 import com.goafanti.common.enums.UserIdentityFields;
 import com.goafanti.common.enums.UserLevel;
 import com.goafanti.common.model.Admin;
+import com.goafanti.common.model.AdminLocation;
 import com.goafanti.common.model.OrgActivity;
 import com.goafanti.common.model.OrgActivityCost;
 import com.goafanti.common.model.OrgAnnualReport;
@@ -420,32 +421,64 @@ public class AdminApiController extends CertifyApiController {
 				res.getError().add(buildError(ErrorConstants.USER_ALREADY_EXIST, "当前用户已注册!"));
 				return res;
 			}
-			
-			
+
 			Admin ad = new Admin();
 			BeanUtils.copyProperties(admin, ad);
 			ad.setId(UUID.randomUUID().toString());
 			JSONArray locations = jo.getJSONArray("locations");
-			//List<>
-			for (int i = 0; i<locations.size(); i++){
-				AdminLocationBo alb=locations.getJSONObject(i).toJavaObject(AdminLocationBo.class);
-				if  (null == alb.getProvince()){
-					res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "省份为空", "省份"));
+			List<AdminLocation> adminLocationList = new ArrayList<>();
+			AdminLocation al = null;
+			for (int i = 0; i < locations.size(); i++) {
+				AdminLocationBo alb = locations.getJSONObject(i).toJavaObject(AdminLocationBo.class);
+				Integer province = alb.getProvince();
+				String city = alb.getCity();
+				if (null == province) {
+					res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "省份为空", "所在省份"));
+					return res;
+				}
+
+				if (province.intValue() > AFTConstants.PROVINCEMAXNUM) {
+					res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "所在省份"));
 					return res;
 				}
+
+				if (!StringUtils.isBlank(city)) {
+					String[] arr = city.trim().split(",|,");
+					if (null != arr && arr.length > 0) {
+						for (String s : arr) {
+							Integer c = Integer.valueOf(s);
+							if (c.intValue() > AFTConstants.CITYMAXNUM) {
+								res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "所在市"));
+								return res;
+							}
+
+							al = new AdminLocation();
+							al.setId(UUID.randomUUID().toString());
+							al.setAdminId(ad.getId());
+							al.setProvince(province);
+							al.setCity(c);
+							adminLocationList.add(al);
+						}
+					}
+				} else {
+					al = new AdminLocation();
+					al.setId(UUID.randomUUID().toString());
+					al.setAdminId(ad.getId());
+					al.setProvince(province);
+					adminLocationList.add(al);
+				}
 			}
-		}
 
-		Calendar now = Calendar.getInstance();
-		now.set(Calendar.MILLISECOND, 0);
-		
-		
-		/*ad.setCreateTime(now.getTime());
-		if (StringUtils.isBlank(ad.getPassword())) {
-			ad.setPassword(AFTConstants.INITIALPASSWORD);
+			Calendar now = Calendar.getInstance();
+			now.set(Calendar.MILLISECOND, 0);
+
+			ad.setCreateTime(now.getTime());
+			if (StringUtils.isBlank(ad.getPassword())) {
+				ad.setPassword(AFTConstants.INITIALPASSWORD);
+			}
+			ad.setPassword(passwordUtil.getEncryptPwd(ad));
+			res.setData(adminService.insertNewAdmin(ad, adminLocationList));
 		}
-		ad.setPassword(passwordUtil.getEncryptPwd(ad));
-		adminService.insert(ad);*/
 
 		return res;
 	}

+ 4 - 0
src/main/java/com/goafanti/admin/service/AdminService.java

@@ -5,6 +5,7 @@ import java.util.Map;
 
 import com.goafanti.admin.bo.AdminDetail;
 import com.goafanti.common.model.Admin;
+import com.goafanti.common.model.AdminLocation;
 import com.goafanti.core.mybatis.page.Pagination;
 
 public interface AdminService {
@@ -56,4 +57,7 @@ public interface AdminService {
 
 	Map<String, String> selectTechBroder();
 
+	int insertNewAdmin(Admin ad, List<AdminLocation> adminLocationList);
+
+
 }

+ 15 - 7
src/main/java/com/goafanti/admin/service/impl/AdminServiceImpl.java

@@ -12,9 +12,11 @@ import org.springframework.stereotype.Service;
 import com.goafanti.admin.bo.AdminDetail;
 import com.goafanti.admin.service.AdminService;
 import com.goafanti.common.constant.AFTConstants;
+import com.goafanti.common.dao.AdminLocationMapper;
 import com.goafanti.common.dao.AdminMapper;
 import com.goafanti.common.dao.UserRoleMapper;
 import com.goafanti.common.model.Admin;
+import com.goafanti.common.model.AdminLocation;
 import com.goafanti.common.utils.StringUtils;
 import com.goafanti.core.mybatis.BaseMybatisDao;
 import com.goafanti.core.mybatis.page.Pagination;
@@ -26,6 +28,8 @@ public class AdminServiceImpl extends BaseMybatisDao<AdminMapper> implements Adm
 	private AdminMapper		adminMapper;
 	@Autowired
 	private UserRoleMapper	userRoleMapper;
+	@Autowired
+	private AdminLocationMapper	adminLocationMapper;
 
 	@Override
 	public List<Admin> selectAllAdmin() {
@@ -179,25 +183,29 @@ public class AdminServiceImpl extends BaseMybatisDao<AdminMapper> implements Adm
 	public Map<String, String> selectSalesman() {
 		return disposeAdminList(adminMapper.selectSalesman());
 	}
-	
+
 	@Override
 	public Map<String, String> selectContractManager() {
 		return disposeAdminList(adminMapper.selectContractManager());
 	}
-	
+
 	@Override
 	public Map<String, String> selectTechBroder() {
 		return disposeAdminList(adminMapper.selectTechBroder());
 	}
-	
-	private Map<String, String> disposeAdminList(List<Admin> list){
+
+	@Override
+	public int insertNewAdmin(Admin ad, List<AdminLocation> adminLocationList) {
+		adminLocationMapper.insertBatch(adminLocationList);
+		return adminMapper.insert(ad);
+	}
+
+	private Map<String, String> disposeAdminList(List<Admin> list) {
 		Map<String, String> map = new TreeMap<String, String>();
 		for (Admin o : list) {
-			map.put(o.getId(), o.getName()+ " " + (null == o.getPosition() ? "" : o.getPosition()));
+			map.put(o.getId(), o.getName() + " " + (null == o.getPosition() ? "" : o.getPosition()));
 		}
 		return map;
 	}
 
-	
-
 }

+ 4 - 0
src/main/java/com/goafanti/common/constant/AFTConstants.java

@@ -33,4 +33,8 @@ public class AFTConstants {
 
 	public static final int		IMPORTMAXLENTH		= 1000;					// 科技需求&科技成果批量导入最大数据量
 
+	public static final int		PROVINCEMAXNUM		= 99;
+
+	public static final int		CITYMAXNUM			= 999;
+
 }

+ 21 - 0
src/main/java/com/goafanti/common/dao/AdminLocationMapper.java

@@ -0,0 +1,21 @@
+package com.goafanti.common.dao;
+
+import java.util.List;
+
+import com.goafanti.common.model.AdminLocation;
+
+public interface AdminLocationMapper {
+    int deleteByPrimaryKey(String id);
+
+    int insert(AdminLocation record);
+
+    int insertSelective(AdminLocation record);
+
+    AdminLocation selectByPrimaryKey(String id);
+
+    int updateByPrimaryKeySelective(AdminLocation record);
+
+    int updateByPrimaryKey(AdminLocation record);
+
+	void insertBatch(List<AdminLocation> adminLocationList);
+}

+ 95 - 0
src/main/java/com/goafanti/common/mapper/AdminLocationMapper.xml

@@ -0,0 +1,95 @@
+<?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.goafanti.common.dao.AdminLocationMapper" >
+  <resultMap id="BaseResultMap" type="com.goafanti.common.model.AdminLocation" >
+    <id column="id" property="id" jdbcType="VARCHAR" />
+    <result column="admin_id" property="adminId" jdbcType="VARCHAR" />
+    <result column="province" property="province" jdbcType="INTEGER" />
+    <result column="city" property="city" jdbcType="INTEGER" />
+  </resultMap>
+  <sql id="Base_Column_List" >
+    id, admin_id, province, city
+  </sql>
+  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
+    select 
+    <include refid="Base_Column_List" />
+    from admin_location
+    where id = #{id,jdbcType=VARCHAR}
+  </select>
+  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
+    delete from admin_location
+    where id = #{id,jdbcType=VARCHAR}
+  </delete>
+  <insert id="insert" parameterType="com.goafanti.common.model.AdminLocation" >
+    insert into admin_location (id, admin_id, province, 
+      city)
+    values (#{id,jdbcType=VARCHAR}, #{adminId,jdbcType=VARCHAR}, #{province,jdbcType=INTEGER}, 
+      #{city,jdbcType=INTEGER})
+  </insert>
+  <insert id="insertSelective" parameterType="com.goafanti.common.model.AdminLocation" >
+    insert into admin_location
+    <trim prefix="(" suffix=")" suffixOverrides="," >
+      <if test="id != null" >
+        id,
+      </if>
+      <if test="adminId != null" >
+        admin_id,
+      </if>
+      <if test="province != null" >
+        province,
+      </if>
+      <if test="city != null" >
+        city,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides="," >
+      <if test="id != null" >
+        #{id,jdbcType=VARCHAR},
+      </if>
+      <if test="adminId != null" >
+        #{adminId,jdbcType=VARCHAR},
+      </if>
+      <if test="province != null" >
+        #{province,jdbcType=INTEGER},
+      </if>
+      <if test="city != null" >
+        #{city,jdbcType=INTEGER},
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.AdminLocation" >
+    update admin_location
+    <set >
+      <if test="adminId != null" >
+        admin_id = #{adminId,jdbcType=VARCHAR},
+      </if>
+      <if test="province != null" >
+        province = #{province,jdbcType=INTEGER},
+      </if>
+      <if test="city != null" >
+        city = #{city,jdbcType=INTEGER},
+      </if>
+    </set>
+    where id = #{id,jdbcType=VARCHAR}
+  </update>
+  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.AdminLocation" >
+    update admin_location
+    set admin_id = #{adminId,jdbcType=VARCHAR},
+      province = #{province,jdbcType=INTEGER},
+      city = #{city,jdbcType=INTEGER}
+    where id = #{id,jdbcType=VARCHAR}
+  </update>
+  
+  <insert id="insertBatch" parameterType="com.goafanti.common.model.AdminLocation">
+    insert into admin_location 
+    	(id, admin_id, 
+    	province, city)
+    values 
+    <foreach item="item" index="index" collection="list" separator=",">
+      (
+      	#{item.id,jdbcType=VARCHAR}, #{item.adminId,jdbcType=VARCHAR}, 
+      	#{item.province,jdbcType=INTEGER}, #{item.city,jdbcType=INTEGER}
+      )
+    </foreach>
+  </insert>
+</mapper>

+ 12 - 12
src/main/java/com/goafanti/common/mapper/UserIdentityMapper.xml

@@ -12,9 +12,9 @@
     <result column="positive_id_url" property="positiveIdUrl" jdbcType="VARCHAR" />
     <result column="opposite_id_url" property="oppositeIdUrl" jdbcType="VARCHAR" />
     <result column="aft_username" property="aftUsername" jdbcType="VARCHAR" />
-    <result column="province" property="province" jdbcType="VARCHAR" />
-    <result column="city" property="city" jdbcType="VARCHAR" />
-    <result column="area" property="area" jdbcType="VARCHAR" />
+    <result column="province" property="province" jdbcType="INTEGER" />
+    <result column="city" property="city" jdbcType="INTEGER" />
+    <result column="area" property="area" jdbcType="INTEGER" />
     <result column="contact_mobile" property="contactMobile" jdbcType="VARCHAR" />
     <result column="bank_name" property="bankName" jdbcType="VARCHAR" />
     <result column="bank_account" property="bankAccount" jdbcType="VARCHAR" />
@@ -158,13 +158,13 @@
         #{aftUsername,jdbcType=VARCHAR},
       </if>
       <if test="province != null" >
-        #{province,jdbcType=VARCHAR},
+        #{province,jdbcType=INTEGER},
       </if>
       <if test="city != null" >
-        #{city,jdbcType=VARCHAR},
+        #{city,jdbcType=INTEGER},
       </if>
       <if test="area != null" >
-        #{area,jdbcType=VARCHAR},
+        #{area,jdbcType=INTEGER},
       </if>
       <if test="contactMobile != null" >
         #{contactMobile,jdbcType=VARCHAR},
@@ -226,13 +226,13 @@
         aft_username = #{aftUsername,jdbcType=VARCHAR},
       </if>
       <if test="province != null" >
-        province = #{province,jdbcType=VARCHAR},
+        province = #{province,jdbcType=INTEGER},
       </if>
       <if test="city != null" >
-        city = #{city,jdbcType=VARCHAR},
+        city = #{city,jdbcType=INTEGER},
       </if>
       <if test="area != null" >
-        area = #{area,jdbcType=VARCHAR},
+        area = #{area,jdbcType=INTEGER},
       </if>
       <if test="contactMobile != null" >
         contact_mobile = #{contactMobile,jdbcType=VARCHAR},
@@ -275,9 +275,9 @@
       positive_id_url = #{positiveIdUrl,jdbcType=VARCHAR},
       opposite_id_url = #{oppositeIdUrl,jdbcType=VARCHAR},
       aft_username = #{aftUsername,jdbcType=VARCHAR},
-      province = #{province,jdbcType=VARCHAR},
-      city = #{city,jdbcType=VARCHAR},
-      area = #{area,jdbcType=VARCHAR},
+      province = #{province,jdbcType=INTEGER},
+      city = #{city,jdbcType=INTEGER},
+      area = #{area,jdbcType=INTEGER},
       contact_mobile = #{contactMobile,jdbcType=VARCHAR},
       bank_name = #{bankName,jdbcType=VARCHAR},
       bank_account = #{bankAccount,jdbcType=VARCHAR},

+ 52 - 0
src/main/java/com/goafanti/common/model/AdminLocation.java

@@ -0,0 +1,52 @@
+package com.goafanti.common.model;
+
+public class AdminLocation {
+    private String id;
+
+    /**
+    * 管理员ID
+    */
+    private String adminId;
+
+    /**
+    * 省份
+    */
+    private Integer province;
+
+    /**
+    * 市
+    */
+    private Integer city;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getAdminId() {
+        return adminId;
+    }
+
+    public void setAdminId(String adminId) {
+        this.adminId = adminId;
+    }
+
+    public Integer getProvince() {
+        return province;
+    }
+
+    public void setProvince(Integer province) {
+        this.province = province;
+    }
+
+    public Integer getCity() {
+        return city;
+    }
+
+    public void setCity(Integer city) {
+        this.city = city;
+    }
+}

+ 29 - 25
src/main/java/com/goafanti/common/model/UserIdentity.java

@@ -57,17 +57,17 @@ public class UserIdentity {
     /**
     * 所在地-省份
     */
-    private String province;
+    private Integer province;
 
     /**
     * 所在地--市
     */
-    private String city;
+    private Integer city;
 
     /**
     * 所在地--区
     */
-    private String area;
+    private Integer area;
 
     /**
     * 联系方式
@@ -194,31 +194,35 @@ public class UserIdentity {
         this.aftUsername = aftUsername;
     }
 
-    public String getProvince() {
-        return province;
-    }
-
-    public void setProvince(String province) {
-        this.province = province;
-    }
-
-    public String getCity() {
-        return city;
-    }
-
-    public void setCity(String city) {
-        this.city = city;
-    }
+    @JsonFormat(shape = Shape.STRING)
+    public Integer getProvince() {
+		return province;
+	}
+    
+    
+	public void setProvince(Integer province) {
+		this.province = province;
+	}
+	
+	 @JsonFormat(shape = Shape.STRING)
+	public Integer getCity() {
+		return city;
+	}
 
-    public String getArea() {
-        return area;
-    }
+	public void setCity(Integer city) {
+		this.city = city;
+	}
+	
+	 @JsonFormat(shape = Shape.STRING)
+	public Integer getArea() {
+		return area;
+	}
 
-    public void setArea(String area) {
-        this.area = area;
-    }
+	public void setArea(Integer area) {
+		this.area = area;
+	}
 
-    public String getContactMobile() {
+	public String getContactMobile() {
         return contactMobile;
     }