Browse Source

achievement_demand_count

Antiloveg 8 years ago
parent
commit
2f932f83ae

+ 8 - 0
schema/2017-06-21.sql

@@ -0,0 +1,8 @@
+CREATE TABLE `achievement_demand_count` (
+  `id` VARCHAR(36) NOT NULL,
+  `uid` VARCHAR(36) NOT NULL COMMENT '用户ID',
+  `achievement_count` INT(4) NULL COMMENT '已发布科技成果数量',
+  `demand_count` INT(4) NULL COMMENT '已发布科技需求数量',
+  PRIMARY KEY (`id`))
+ENGINE = InnoDB
+COMMENT = '用户已发布科技成果及已发布科技需求数量';

+ 1 - 1
src/main/java/com/goafanti/achievement/controller/AchievementApiController.java

@@ -292,7 +292,7 @@ public class AchievementApiController extends CertifyApiController {
 	@RequestMapping(value = "/delete", method = RequestMethod.POST)
 	private Result delete(@RequestParam(name = "ids[]", required = false) String[] ids) {
 		Result res = new Result();
-		if (ids == null || ids.length < 1) {
+		if (ids == null || ids.length != 1) {
 			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", ""));
 		} else {
 			List<AchievementOrder> list = achievementOrderService.selectAchievementOrderByAchievementId(ids[0]);

+ 44 - 7
src/main/java/com/goafanti/achievement/service/impl/AchievementServiceImpl.java

@@ -22,6 +22,7 @@ import com.goafanti.achievement.bo.AchievementPartnerListBo;
 import com.goafanti.achievement.bo.AchievementUserOwnerDetailBo;
 import com.goafanti.achievement.service.AchievementService;
 import com.goafanti.common.constant.AFTConstants;
+import com.goafanti.common.dao.AchievementDemandCountMapper;
 import com.goafanti.common.dao.AchievementDemandMapper;
 import com.goafanti.common.dao.AchievementKeywordMapper;
 import com.goafanti.common.dao.AchievementMapper;
@@ -38,6 +39,7 @@ import com.goafanti.common.enums.NoticeStatus;
 import com.goafanti.common.enums.UserType;
 import com.goafanti.common.model.Achievement;
 import com.goafanti.common.model.AchievementDemand;
+import com.goafanti.common.model.AchievementDemandCount;
 import com.goafanti.common.model.AchievementKeyword;
 import com.goafanti.common.model.Admin;
 import com.goafanti.common.model.Notice;
@@ -55,17 +57,19 @@ import com.goafanti.portal.bo.AchievementSearchListBo;
 public class AchievementServiceImpl extends BaseMybatisDao<AchievementMapper> implements AchievementService {
 
 	@Autowired
-	private AchievementMapper			achievementMapper;
+	private AchievementMapper				achievementMapper;
 	@Autowired
-	private UserRoleMapper				userRoleMapper;
+	private UserRoleMapper					userRoleMapper;
 	@Autowired
-	private NoticeMapper				noticeMapper;
+	private NoticeMapper					noticeMapper;
 	@Autowired
-	private AchievementKeywordMapper	achievementKeywordMapper;
+	private AchievementKeywordMapper		achievementKeywordMapper;
 	@Autowired
-	private AchievementDemandMapper		achievementDemandMapper;
+	private AchievementDemandMapper			achievementDemandMapper;
 	@Autowired
-	private DemandKeywordMapper			demandKeywordMapper;
+	private DemandKeywordMapper				demandKeywordMapper;
+	@Autowired
+	private AchievementDemandCountMapper	achievementDemandCountMapper;
 
 	@SuppressWarnings("unchecked")
 	@Override
@@ -146,6 +150,16 @@ public class AchievementServiceImpl extends BaseMybatisDao<AchievementMapper> im
 	public int deleteByPrimaryKey(List<String> id) {
 		achievementKeywordMapper.batchDeleteByAchievementIds(id);
 		achievementDemandMapper.batchDeleteByAchievementIds(id);
+		for (String s : id) {
+			Achievement a = achievementMapper.selectByPrimaryKey(s);
+			if (null != a && StringUtils.isNotBlank(a.getOwnerId())) {
+				AchievementDemandCount adc = achievementDemandCountMapper.selectByUid(a.getOwnerId());
+				if (null != adc) {
+					adc.setAchievementCount(adc.getAchievementCount() - 1);
+					achievementDemandCountMapper.updateByPrimaryKeySelective(adc);
+				}
+			}
+		}
 		return achievementMapper.batchDeleteByPrimaryKey(id);
 	}
 
@@ -184,7 +198,7 @@ public class AchievementServiceImpl extends BaseMybatisDao<AchievementMapper> im
 
 		if (!StringUtils.isBlank(releaseDateEndDate)) {
 			try {
-				rEnd = DateUtils.addDays(DateUtils.parseDate(releaseDateEndDate, AFTConstants.YYYYMMDD),1);
+				rEnd = DateUtils.addDays(DateUtils.parseDate(releaseDateEndDate, AFTConstants.YYYYMMDD), 1);
 			} catch (ParseException e) {
 			}
 		}
@@ -241,6 +255,21 @@ public class AchievementServiceImpl extends BaseMybatisDao<AchievementMapper> im
 			a.setReleaseDate(now.getTime());
 			a.setReleaseStatus(DemandReleaseStatus.RELEASED.getCode());
 			a.setTechBrokerId(techBroderId);
+			String ownerId = a.getOwnerId();
+			if (StringUtils.isNotBlank(ownerId)) {
+				AchievementDemandCount adc = achievementDemandCountMapper.selectByUid(ownerId);
+				if (null == adc) {
+					AchievementDemandCount achievementDemandCount = new AchievementDemandCount();
+					achievementDemandCount.setId(UUID.randomUUID().toString());
+					achievementDemandCount.setUid(ownerId);
+					achievementDemandCount.setAchievementCount(AFTConstants.ACHIEVEMENT_DEMAND_FIRST_COUNT);
+					achievementDemandCount.setDemandCount(AFTConstants.ACHIEVEMENT_DEMAND_INIT_COUNT);
+					achievementDemandCountMapper.insert(achievementDemandCount);
+				} else {
+					adc.setAchievementCount(adc.getAchievementCount() + 1);
+					achievementDemandCountMapper.updateByPrimaryKeySelective(adc);
+				}
+			}
 		} else {
 			a.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
 		}
@@ -253,7 +282,15 @@ public class AchievementServiceImpl extends BaseMybatisDao<AchievementMapper> im
 		a.setAuditStatus(AchievementAuditStatus.CREATE.getCode());
 		a.setReleaseStatus(AchievementReleaseStatus.UNRELEASE.getCode());
 		achievementDemandMapper.deleteByAchievementId(a.getId());
+		achievementKeywordMapper.batchDeleteByAchievementId(a.getId());
 		achievementMapper.updateByPrimaryKeySelective(a);
+		if (StringUtils.isNotBlank(a.getOwnerId())) {
+			AchievementDemandCount adc = achievementDemandCountMapper.selectByUid(a.getOwnerId());
+			if (null != adc) {
+				adc.setAchievementCount(adc.getAchievementCount() - 1);
+				achievementDemandCountMapper.updateByPrimaryKeySelective(adc);
+			}
+		}
 		return achievementMapper.updateReleaseDate(a.getId());
 	}
 

+ 28 - 20
src/main/java/com/goafanti/admin/controller/AdminAchievementApiController.java

@@ -23,6 +23,7 @@ import org.springframework.web.multipart.MultipartFile;
 import com.alibaba.fastjson.JSON;
 import com.goafanti.achievement.bo.AchievementImportBo;
 import com.goafanti.achievement.bo.InputAchievement;
+import com.goafanti.achievement.service.AchievementOrderService;
 import com.goafanti.achievement.service.AchievementService;
 import com.goafanti.admin.service.AftFileService;
 import com.goafanti.common.bo.Result;
@@ -32,10 +33,12 @@ import com.goafanti.common.controller.CertifyApiController;
 import com.goafanti.common.enums.AchievementAuditStatus;
 import com.goafanti.common.enums.AchievementFields;
 import com.goafanti.common.enums.AchievementImportFields;
+import com.goafanti.common.enums.AchievementOrderStatus;
 import com.goafanti.common.enums.AchievementReleaseStatus;
 import com.goafanti.common.enums.AttachmentType;
 import com.goafanti.common.enums.DeleteStatus;
 import com.goafanti.common.model.Achievement;
+import com.goafanti.common.model.AchievementOrder;
 import com.goafanti.common.model.AftFile;
 import com.goafanti.common.utils.LoggerUtils;
 import com.goafanti.common.utils.StringUtils;
@@ -46,12 +49,14 @@ import com.goafanti.user.service.UserService;
 @RequestMapping(value = "/api/admin/achievement")
 public class AdminAchievementApiController extends CertifyApiController {
 	@Resource
-	private AchievementService	achievementService;
+	private AchievementService		achievementService;
 	@Resource
-	private UserService			userService;
+	private UserService				userService;
 	@Resource
-	private AftFileService		aftFileService;
-	
+	private AftFileService			aftFileService;
+	@Resource
+	private AchievementOrderService	achievementOrderService;
+
 	/**
 	 * 个人成果列表
 	 */
@@ -94,7 +99,7 @@ public class AdminAchievementApiController extends CertifyApiController {
 				category, status, releaseDateStartDate, releaseDateEndDate, releaseStatus, pNo, pSize));
 		return res;
 	}
-	
+
 	/**
 	 * 个人成果所有人列表
 	 */
@@ -120,7 +125,7 @@ public class AdminAchievementApiController extends CertifyApiController {
 		res.setData(userService.selectAchievementOrgOwner(name));
 		return res;
 	}
-	
+
 	/**
 	 * 个人成果详情详情
 	 */
@@ -149,7 +154,6 @@ public class AdminAchievementApiController extends CertifyApiController {
 		return res;
 	}
 
-	
 	/**
 	 * 新增成果
 	 */
@@ -210,22 +214,22 @@ public class AdminAchievementApiController extends CertifyApiController {
 		achievementService.updateAchievement(a, keywords);
 		return res;
 	}
-	
+
 	/**
 	 * 科技成果匹配科技需求
 	 */
 	@RequestMapping(value = "/matchDemand", method = RequestMethod.POST)
-	public Result matchDemand(String id){
+	public Result matchDemand(String id) {
 		Result res = new Result();
 		if (StringUtils.isBlank(id)) {
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果ID", "成果ID"));
 			return res;
 		}
-		
+
 		Achievement a = achievementService.selectByPrimaryKey(id);
 		if (null == a || !AchievementAuditStatus.AUDITED.getCode().equals(a.getAuditStatus())
 				|| !DeleteStatus.UNDELETE.getCode().equals(a.getDeletedSign())
-				|| !AchievementReleaseStatus.RELEASED.getCode().equals(a.getReleaseStatus())){
+				|| !AchievementReleaseStatus.RELEASED.getCode().equals(a.getReleaseStatus())) {
 			res.getError().add(buildError("", "当前状态无法匹配!"));
 			return res;
 		}
@@ -238,14 +242,14 @@ public class AdminAchievementApiController extends CertifyApiController {
 	 */
 	@SuppressWarnings("unchecked")
 	@RequestMapping(value = "/importAchievement", method = RequestMethod.POST)
-	public Result importAchievement(@RequestParam(name = "data", required = false)String d) {
+	public Result importAchievement(@RequestParam(name = "data", required = false) String d) {
 		Result res = new Result();
 		List<AchievementImportBo> data = JSON.parseArray(d, AchievementImportBo.class);
 		if (data == null || data.isEmpty()) {
 			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "导入数据"));
 			return res;
 		}
-		
+
 		if (data.size() > AFTConstants.IMPORTMAXLENTH) {
 			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "导入数据量"));
 			return res;
@@ -337,8 +341,6 @@ public class AdminAchievementApiController extends CertifyApiController {
 		return res;
 	}
 
-	
-
 	/**
 	 * 成果撤消发布(下架)
 	 */
@@ -436,15 +438,21 @@ public class AdminAchievementApiController extends CertifyApiController {
 	@RequestMapping(value = "/delete", method = RequestMethod.POST)
 	private Result delete(@RequestParam(name = "ids[]", required = false) String[] ids) {
 		Result res = new Result();
-		if (ids == null || ids.length < 1) {
+		if (ids == null || ids.length != 1) {
 			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", ""));
 		} else {
+			List<AchievementOrder> list = achievementOrderService.selectAchievementOrderByAchievementId(ids[0]);
+			for (AchievementOrder order : list) {
+				if (!AchievementOrderStatus.CREATE.getCode().equals(order.getStatus())) {
+					res.getError().add(buildError("", "当前科技成果有订单,无法删除!"));
+					return res;
+				}
+			}
 			res.setData(achievementService.deleteByPrimaryKey(Arrays.asList(ids)));
 		}
 		return res;
 	}
 
-	
 	private Result disposeInputAchievement(Result res, InputAchievement ia, String[] keywords) {
 		if (StringUtils.isBlank(ia.getName())) {
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果名称", "成果名称"));
@@ -505,13 +513,13 @@ public class AdminAchievementApiController extends CertifyApiController {
 
 	private Result disposeImportAchievement(Result res, List<AchievementImportBo> data) {
 		Field[] field = AchievementImportBo.class.getDeclaredFields();
-		for (AchievementImportBo bo: data) {
+		for (AchievementImportBo bo : data) {
 			for (Field f : field) {
 				f.setAccessible(true);
 				try {
 					if (!f.getName().equals("keywords") && (f.get(bo) == null || "".equals(f.get(bo)))) {
-						res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", AchievementImportFields
-								.getFieldDesc(f.getName())));
+						res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "",
+								AchievementImportFields.getFieldDesc(f.getName())));
 						return res;
 					}
 				} catch (IllegalArgumentException | IllegalAccessException e) {

+ 20 - 8
src/main/java/com/goafanti/admin/controller/AdminDemandApiController.java

@@ -33,14 +33,17 @@ import com.goafanti.common.enums.DemandAuditStatus;
 import com.goafanti.common.enums.DemandDataCategory;
 import com.goafanti.common.enums.DemandFields;
 import com.goafanti.common.enums.DemandImportFields;
+import com.goafanti.common.enums.DemandOrderStatus;
 import com.goafanti.common.enums.DemandReleaseStatus;
 import com.goafanti.common.model.AftFile;
 import com.goafanti.common.model.Demand;
+import com.goafanti.common.model.DemandOrder;
 import com.goafanti.common.utils.LoggerUtils;
 import com.goafanti.common.utils.StringUtils;
 import com.goafanti.core.shiro.token.TokenManager;
 import com.goafanti.demand.bo.DemandImportBo;
 import com.goafanti.demand.bo.InputDemand;
+import com.goafanti.demand.service.DemandOrderService;
 import com.goafanti.demand.service.DemandService;
 import com.goafanti.user.service.UserService;
 
@@ -48,17 +51,19 @@ import com.goafanti.user.service.UserService;
 @RequestMapping(value = "/api/admin/demand")
 public class AdminDemandApiController extends CertifyApiController {
 	@Resource
-	private DemandService	demandService;
+	private DemandService		demandService;
 	@Resource
-	private UserService		userService;
+	private UserService			userService;
 	@Resource
-	private AftFileService	aftFileService;
+	private AftFileService		aftFileService;
+	@Resource
+	private DemandOrderService	demandOrderService;
 
 	/**
 	 * 科技需求匹配科技成果
 	 */
-	@RequestMapping(value="/matchAchievement", method = RequestMethod.POST)
-	public Result matchAchievement(String id){
+	@RequestMapping(value = "/matchAchievement", method = RequestMethod.POST)
+	public Result matchAchievement(String id) {
 		Result res = new Result();
 		if (StringUtils.isBlank(id)) {
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求ID", "成果ID"));
@@ -66,8 +71,8 @@ public class AdminDemandApiController extends CertifyApiController {
 		}
 		Demand d = demandService.selectByPrimaryKey(id);
 		if (null == d || !DemandReleaseStatus.RELEASED.getCode().equals(d.getReleaseStatus())
-				|| !DeleteStatus.UNDELETE.getCode().equals(d.getDeletedSign()) 
-				|| !DemandAuditStatus.AUDITED.getCode().equals(d.getAuditStatus())){
+				|| !DeleteStatus.UNDELETE.getCode().equals(d.getDeletedSign())
+				|| !DemandAuditStatus.AUDITED.getCode().equals(d.getAuditStatus())) {
 			res.getError().add(buildError("", "当前状态无法匹配!"));
 			return res;
 		}
@@ -435,9 +440,16 @@ public class AdminDemandApiController extends CertifyApiController {
 	@RequestMapping(value = "/delete", method = RequestMethod.POST)
 	public Result delete(@RequestParam(name = "ids[]", required = false) String[] ids) {
 		Result res = new Result();
-		if (ids == null || ids.length < 1) {
+		if (ids == null || ids.length != 1) {
 			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", ""));
 		} else {
+			List<DemandOrder> list = demandOrderService.selectDemandOrderByDemandId(ids[0]);
+			for (DemandOrder order : list) {
+				if (!DemandOrderStatus.CREATE.getCode().equals(order.getStatus())) {
+					res.getError().add(buildError("", "当前科技需求有订单,无法删除!"));
+					return res;
+				}
+			}
 			res.setData(demandService.deleteByPrimaryKey(Arrays.asList(ids)));
 		}
 		return res;

+ 25 - 21
src/main/java/com/goafanti/common/constant/AFTConstants.java

@@ -1,44 +1,48 @@
 package com.goafanti.common.constant;
 
 public class AFTConstants {
-	public static final String	YYYYMMDDHHMMSS		= "yyyy-MM-dd HH:mm:ss";
+	public static final String	YYYYMMDDHHMMSS					= "yyyy-MM-dd HH:mm:ss";
 
-	public static final String	YYYYMMDD			= "yyyy-MM-dd";
+	public static final String	YYYYMMDD						= "yyyy-MM-dd";
 
-	public static final String	YYYY				= "yyyy";
-	
-	public static final String	MMDD				= "MM-dd";
+	public static final String	YYYY							= "yyyy";
 
-	public static final String	INITIALPASSWORD		= "123456";				// 初始密码
+	public static final String	MMDD							= "MM-dd";
 
-	public static final String	SUPERADMIN			= "999999";				// 超级管理员
+	public static final String	INITIALPASSWORD					= "123456";				// 初始密码
 
-	public static final String	AREAADMIN			= "99999";				// 地区管理员
+	public static final String	SUPERADMIN						= "999999";				// 超级管理员
 
-	public static final String	AUDITORADMIN		= "9999";				// 审核
+	public static final String	AREAADMIN						= "99999";				// 地区管理
 
-	public static final String	MANAGERADMIN		= "4";					// 客户经理
+	public static final String	AUDITORADMIN					= "9999";				// 审核员
 
-	public static final String	SALESMANAGERADMIN	= "5";					// 营销经理
+	public static final String	MANAGERADMIN					= "4";					// 客户经理
 
-	public static final String	SALESMANADMIN		= "6";					// 营销员
+	public static final String	SALESMANAGERADMIN				= "5";					// 营销经理
 
-	public static final String	TECHBROKER			= "7";					// 技术经纪人
+	public static final String	SALESMANADMIN					= "6";					// 营销员
 
-	public static final String	PATENTINFO			= "专利申请管理";
+	public static final String	TECHBROKER						= "7";					// 技术经纪人
 
-	public static final String	COGNIZANCE			= "高企认定管理";
+	public static final String	PATENTINFO						= "专利申请管理";
 
-	public static final String	COPYRIGHT			= "软著申请管理";
+	public static final String	COGNIZANCE						= "高企认定管理";
 
-	public static final String	TECHPROJECT			= "科技项目申报管理";
+	public static final String	COPYRIGHT						= "软著申请管理";
 
-	public static final int		KEYWORDLENTH		= 16;
+	public static final String	TECHPROJECT						= "科技项目申报管理";
 
-	public static final int		IMPORTMAXLENTH		= 1000;					// 科技需求&科技成果批量导入最大数据量
+	public static final int		KEYWORDLENTH					= 16;
 
-	public static final int		PROVINCEMAXNUM		= 99;
+	public static final int		IMPORTMAXLENTH					= 1000;					// 科技需求&科技成果批量导入最大数据量
 
-	public static final int		CITYMAXNUM			= 999;
+	public static final int		PROVINCEMAXNUM					= 99;
+
+	public static final int		CITYMAXNUM						= 999;
+
+	public static final Integer	ACHIEVEMENT_DEMAND_INIT_COUNT	= 0;
+
+	public static final Integer	ACHIEVEMENT_DEMAND_FIRST_COUNT	= 1;
 
 }

+ 19 - 0
src/main/java/com/goafanti/common/dao/AchievementDemandCountMapper.java

@@ -0,0 +1,19 @@
+package com.goafanti.common.dao;
+
+import com.goafanti.common.model.AchievementDemandCount;
+
+public interface AchievementDemandCountMapper {
+    int deleteByPrimaryKey(String id);
+
+    int insert(AchievementDemandCount record);
+
+    int insertSelective(AchievementDemandCount record);
+
+    AchievementDemandCount selectByPrimaryKey(String id);
+
+    int updateByPrimaryKeySelective(AchievementDemandCount record);
+
+    int updateByPrimaryKey(AchievementDemandCount record);
+
+	AchievementDemandCount selectByUid(String uid);
+}

+ 89 - 0
src/main/java/com/goafanti/common/mapper/AchievementDemandCountMapper.xml

@@ -0,0 +1,89 @@
+<?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.AchievementDemandCountMapper" >
+  <resultMap id="BaseResultMap" type="com.goafanti.common.model.AchievementDemandCount" >
+    <id column="id" property="id" jdbcType="VARCHAR" />
+    <result column="uid" property="uid" jdbcType="VARCHAR" />
+    <result column="achievement_count" property="achievementCount" jdbcType="INTEGER" />
+    <result column="demand_count" property="demandCount" jdbcType="INTEGER" />
+  </resultMap>
+  <sql id="Base_Column_List" >
+    id, uid, achievement_count, demand_count
+  </sql>
+  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
+    select 
+    <include refid="Base_Column_List" />
+    from achievement_demand_count
+    where id = #{id,jdbcType=VARCHAR}
+  </select>
+  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
+    delete from achievement_demand_count
+    where id = #{id,jdbcType=VARCHAR}
+  </delete>
+  <insert id="insert" parameterType="com.goafanti.common.model.AchievementDemandCount" >
+    insert into achievement_demand_count (id, uid, achievement_count, 
+      demand_count)
+    values (#{id,jdbcType=VARCHAR}, #{uid,jdbcType=VARCHAR}, #{achievementCount,jdbcType=INTEGER}, 
+      #{demandCount,jdbcType=INTEGER})
+  </insert>
+  <insert id="insertSelective" parameterType="com.goafanti.common.model.AchievementDemandCount" >
+    insert into achievement_demand_count
+    <trim prefix="(" suffix=")" suffixOverrides="," >
+      <if test="id != null" >
+        id,
+      </if>
+      <if test="uid != null" >
+        uid,
+      </if>
+      <if test="achievementCount != null" >
+        achievement_count,
+      </if>
+      <if test="demandCount != null" >
+        demand_count,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides="," >
+      <if test="id != null" >
+        #{id,jdbcType=VARCHAR},
+      </if>
+      <if test="uid != null" >
+        #{uid,jdbcType=VARCHAR},
+      </if>
+      <if test="achievementCount != null" >
+        #{achievementCount,jdbcType=INTEGER},
+      </if>
+      <if test="demandCount != null" >
+        #{demandCount,jdbcType=INTEGER},
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.AchievementDemandCount" >
+    update achievement_demand_count
+    <set >
+      <if test="uid != null" >
+        uid = #{uid,jdbcType=VARCHAR},
+      </if>
+      <if test="achievementCount != null" >
+        achievement_count = #{achievementCount,jdbcType=INTEGER},
+      </if>
+      <if test="demandCount != null" >
+        demand_count = #{demandCount,jdbcType=INTEGER},
+      </if>
+    </set>
+    where id = #{id,jdbcType=VARCHAR}
+  </update>
+  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.AchievementDemandCount" >
+    update achievement_demand_count
+    set uid = #{uid,jdbcType=VARCHAR},
+      achievement_count = #{achievementCount,jdbcType=INTEGER},
+      demand_count = #{demandCount,jdbcType=INTEGER}
+    where id = #{id,jdbcType=VARCHAR}
+  </update>
+  
+   <select id="selectByUid" resultMap="BaseResultMap" parameterType="java.lang.String" >
+    select 
+    <include refid="Base_Column_List" />
+    from achievement_demand_count
+    where uid = #{uid,jdbcType=VARCHAR}
+  </select>
+</mapper>

+ 2 - 3
src/main/java/com/goafanti/common/mapper/AchievementMapper.xml

@@ -1007,10 +1007,10 @@
   		and a.maturity = #{maturity,jdbcType=INTEGER}
   	</if>
   	<if test="transferPriceLower != null">
-  		and a.transfer_price <![CDATA[ > ]]> #{transferPriceLower,jdbcType=DECIMAL}
+  		and a.transfer_price <![CDATA[ >= ]]> #{transferPriceLower,jdbcType=DECIMAL}
   	</if>
   	<if test="transferPriceUpper != null">
-  		and a.transfer_price <![CDATA[ < ]]> #{transferPriceUpper,jdbcType=DECIMAL}
+  		and a.transfer_price <![CDATA[ <= ]]> #{transferPriceUpper,jdbcType=DECIMAL}
   	</if>
   	<if test="transferMode != null">
   		and a.transfer_mode = #{transferMode,jdbcType=INTEGER}
@@ -1044,7 +1044,6 @@
   	<if test="category != null">
   		and a.category = #{category,jdbcType=INTEGER}
   	</if>
-  	
   	<if test="maturity != maturity">
   		and a.maturity = #{maturity,jdbcType=INTEGER}
   	</if>

+ 6 - 25
src/main/java/com/goafanti/common/mapper/OrganizationIdentityMapper.xml

@@ -1152,20 +1152,17 @@
 	
 	
 	<select id="findSearchSubscriberListByPage" parameterType="String" resultType="com.goafanti.portal.bo.OrgSubscriberListBo">
-	 	SELECT 
-		 	x.uid, x.unitName, count(a.id) as achievementNum, 
-		 	count(d.id) as demandNum, x.identityId, x.logoUrl,
-		 	x.province
-		FROM
-		(
 			SELECT
 				u.id as uid, oi.unit_name as unitName, u.number,
 				oi.id as identityId, info.logo_url as logoUrl,
-				oi.licence_province as province
+				oi.licence_province as province,
+				adc.achievement_count as achievementNum,
+				adc.demand_count as demandNum
 			FROM
 				<![CDATA[ user ]]> u
 			LEFT JOIN organization_identity oi ON oi.uid = u.id
 			LEFT JOIN organization_info info on info.uid = u.id
+			LEFT JOIN achievement_demand_count adc on adc.uid = u.id
 			WHERE
 				u.type = 1
 			<if test="null != level and level==1 ">
@@ -1189,13 +1186,6 @@
 			<if test="name != null">
 				AND oi.unit_name like CONCAT('%', #{name,jdbcType=VARCHAR}, '%')
 			</if>
-		) x
-		LEFT JOIN achievement a ON a.owner_id = x.uid AND a.release_status = 1
-		AND a.audit_status = 3 AND a.deleted_sign = 0
-		LEFT JOIN demand d ON d.employer_id = x.uid AND d.audit_status = 3
-		AND d.release_status = 1 AND d.deleted_sign = 0
-		GROUP BY
-			x.uid 
 		ORDER BY x.number 
 		<if test="page_sql!=null">
 			${page_sql}
@@ -1204,13 +1194,9 @@
   
   <select id="findSearchSubscriberCount" parameterType="String" resultType="java.lang.Integer">
 	 	SELECT 
-		 	count(DISTINCT(x.uid))
+		 	count(1)
 		FROM
-		(
-			SELECT
-				u.id as uid
-			FROM
-				<![CDATA[ user ]]> u
+		<![CDATA[ user ]]> u
 			LEFT JOIN organization_identity oi ON oi.uid = u.id
 			LEFT JOIN organization_info info on info.uid = u.id
 			WHERE
@@ -1236,11 +1222,6 @@
 			<if test="name != null">
 				AND oi.unit_name like CONCAT('%', #{name,jdbcType=VARCHAR}, '%')
 			</if>
-		) x
-		LEFT JOIN achievement a ON a.owner_id = x.uid AND a.release_status = 1
-		AND a.audit_status = 3 AND a.deleted_sign = 0
-		LEFT JOIN demand d ON d.employer_id = x.uid AND d.audit_status = 3
-		AND d.release_status = 1 AND d.deleted_sign = 0
   </select>
 
 </mapper>

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

@@ -393,21 +393,18 @@
  </select>
 	
  <select id="findSearchSubscriberListByPage" parameterType="String" resultType="com.goafanti.portal.bo.UserSubscriberListBo">
- 	SELECT 
-	 	x.uid, x.username, count(a.id) as achievementNum, 
-	 	count(d.id) as demandNum, x.province,
-	 	x.personPortraitUrl, x.identityId
-	FROM
-	(
 		SELECT
 			u.id as uid, ui.username, u.number,
 			ui.id as identityId, ui.province,
-			info.person_portrait_url as personPortraitUrl
+			info.person_portrait_url as personPortraitUrl,
+			adc.achievement_count as achievementNum,
+			adc.demand_count as demandNum
 		FROM
 			<![CDATA[ user ]]> u
 		LEFT JOIN user_identity ui ON ui.uid = u.id
 		LEFT JOIN user_career uc ON uc.uid = u.id
 		LEFT JOIN user_info info ON info.uid = u.id
+		LEFT JOIN achievement_demand_count adc ON adc.uid = u.id
 		WHERE
 			u.type = 0
 		<if test="null != level and level==1 ">
@@ -431,15 +428,8 @@
 		<if test="name != null">
 			AND ui.username like CONCAT('%', #{name,jdbcType=VARCHAR}, '%')
 		</if>
-	) x
-	LEFT JOIN achievement a ON a.owner_id = x.uid AND a.release_status = 1
-	AND a.audit_status = 3 AND a.deleted_sign = 0
-	LEFT JOIN demand d ON d.employer_id = x.uid AND d.audit_status = 3
-	AND d.release_status = 1 AND d.deleted_sign = 0
-	GROUP BY
-		x.uid 
 	ORDER BY 
-		x.number
+		u.number
 	<if test="page_sql!=null">
 		${page_sql}
 	</if>
@@ -447,12 +437,8 @@
  
 	 <select id="findSearchSubscriberCount" parameterType="String" resultType="java.lang.Integer">
 	 	SELECT 
-		 	count(distinct(x.uid))
+		 	count(1)
 		FROM
-		(
-			SELECT
-				u.id as uid
-			FROM
 			<![CDATA[ user ]]> u
 			LEFT JOIN user_identity ui ON ui.uid = u.id
 			LEFT JOIN user_career uc ON uc.uid = u.id
@@ -479,11 +465,6 @@
 			<if test="name != null">
 				AND ui.username like CONCAT('%', #{name,jdbcType=VARCHAR}, '%')
 			</if>
-		) x
-		LEFT JOIN achievement a ON a.owner_id = x.uid AND a.release_status = 1
-		AND a.audit_status = 3 AND a.deleted_sign = 0
-		LEFT JOIN demand d ON d.employer_id = x.uid AND d.audit_status = 3
-		AND d.release_status = 1 AND d.deleted_sign = 0
 	 </select>
   
 </mapper>

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

@@ -0,0 +1,52 @@
+package com.goafanti.common.model;
+
+public class AchievementDemandCount {
+    private String id;
+
+    /**
+    * 用户ID
+    */
+    private String uid;
+
+    /**
+    * 已发布科技成果数量
+    */
+    private Integer achievementCount;
+
+    /**
+    * 已发布科技需求数量
+    */
+    private Integer demandCount;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getUid() {
+        return uid;
+    }
+
+    public void setUid(String uid) {
+        this.uid = uid;
+    }
+
+    public Integer getAchievementCount() {
+        return achievementCount;
+    }
+
+    public void setAchievementCount(Integer achievementCount) {
+        this.achievementCount = achievementCount;
+    }
+
+    public Integer getDemandCount() {
+        return demandCount;
+    }
+
+    public void setDemandCount(Integer demandCount) {
+        this.demandCount = demandCount;
+    }
+}

+ 50 - 15
src/main/java/com/goafanti/demand/service/impl/DemandServiceImpl.java

@@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
 
 import com.goafanti.achievement.bo.AchievementDemandListBo;
 import com.goafanti.common.constant.AFTConstants;
+import com.goafanti.common.dao.AchievementDemandCountMapper;
 import com.goafanti.common.dao.AchievementDemandMapper;
 import com.goafanti.common.dao.AchievementKeywordMapper;
 import com.goafanti.common.dao.DemandKeywordMapper;
@@ -33,6 +34,7 @@ import com.goafanti.common.enums.NoticeReadStatus;
 import com.goafanti.common.enums.NoticeStatus;
 import com.goafanti.common.enums.UserType;
 import com.goafanti.common.model.AchievementDemand;
+import com.goafanti.common.model.AchievementDemandCount;
 import com.goafanti.common.model.Demand;
 import com.goafanti.common.model.DemandKeyword;
 import com.goafanti.common.model.Notice;
@@ -55,19 +57,21 @@ import com.goafanti.portal.bo.DemandSearchListBo;
 @Service
 public class DemandServiceImpl extends BaseMybatisDao<DemandMapper> implements DemandService {
 	@Autowired
-	private DemandMapper				demandMapper;
+	private DemandMapper					demandMapper;
 	@Autowired
-	private UserMapper					userMapper;
+	private UserMapper						userMapper;
 	@Autowired
-	private UserRoleMapper				userRoleMapper;
+	private UserRoleMapper					userRoleMapper;
 	@Autowired
-	private NoticeMapper				noticeMapper;
+	private NoticeMapper					noticeMapper;
 	@Autowired
-	private DemandKeywordMapper			demandKeywordMapper;
+	private DemandKeywordMapper				demandKeywordMapper;
 	@Autowired
-	private AchievementDemandMapper		achievementDemandMapper;
+	private AchievementDemandMapper			achievementDemandMapper;
 	@Autowired
-	private AchievementKeywordMapper	achievementKeywordMapper;
+	private AchievementKeywordMapper		achievementKeywordMapper;
+	@Autowired
+	private AchievementDemandCountMapper	achievementDemandCountMapper;
 
 	@SuppressWarnings("unchecked")
 	@Override
@@ -199,6 +203,16 @@ public class DemandServiceImpl extends BaseMybatisDao<DemandMapper> implements D
 	public int deleteByPrimaryKey(List<String> id) {
 		demandKeywordMapper.batchDeleteByDemandIds(id);
 		achievementDemandMapper.batchDeleteByDemandIds(id);
+		for (String s : id) {
+			Demand d = demandMapper.selectByPrimaryKey(s);
+			if (null != d && StringUtils.isNotBlank(d.getEmployerId())) {
+				AchievementDemandCount adc = achievementDemandCountMapper.selectByUid(d.getEmployerId());
+				if (null != adc) {
+					adc.setDemandCount(adc.getDemandCount() - 1);
+					achievementDemandCountMapper.updateByPrimaryKeySelective(adc);
+				}
+			}
+		}
 		return demandMapper.batchDeleteByPrimaryKey(id);
 	}
 
@@ -241,8 +255,15 @@ public class DemandServiceImpl extends BaseMybatisDao<DemandMapper> implements D
 		demandMapper.updateByPrimaryKeySelective(d);
 		demandKeywordMapper.batchDeleteByDemandId(d.getId());
 		achievementDemandMapper.deleteByDemandId(d.getId());
+		if (StringUtils.isNotBlank(d.getEmployerId())) {
+			AchievementDemandCount adc = achievementDemandCountMapper.selectByUid(d.getEmployerId());
+			if (null != adc) {
+				adc.setDemandCount(adc.getDemandCount() - 1);
+				achievementDemandCountMapper.updateByPrimaryKeySelective(adc);
+			}
+		}
 		return demandMapper.updateReleaseDate(d.getId());
-		
+
 	}
 
 	@Override
@@ -254,6 +275,21 @@ public class DemandServiceImpl extends BaseMybatisDao<DemandMapper> implements D
 			d.setReleaseDate(now.getTime());
 			d.setReleaseStatus(DemandReleaseStatus.RELEASED.getCode());
 			d.setTechBrokerId(techBroderId);
+			String employerId = d.getEmployerId();
+			if (StringUtils.isNotBlank(employerId)) {
+				AchievementDemandCount adc = achievementDemandCountMapper.selectByUid(employerId);
+				if (null == adc) {
+					AchievementDemandCount achievementDemandCount = new AchievementDemandCount();
+					achievementDemandCount.setId(UUID.randomUUID().toString());
+					achievementDemandCount.setUid(employerId);
+					achievementDemandCount.setDemandCount(AFTConstants.ACHIEVEMENT_DEMAND_FIRST_COUNT);
+					achievementDemandCount.setAchievementCount(AFTConstants.ACHIEVEMENT_DEMAND_INIT_COUNT);
+					achievementDemandCountMapper.insert(achievementDemandCount);
+				} else {
+					adc.setDemandCount(adc.getDemandCount() + 1);
+					achievementDemandCountMapper.updateByPrimaryKeySelective(adc);
+				}
+			}
 		} else {
 			d.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
 		}
@@ -402,7 +438,7 @@ public class DemandServiceImpl extends BaseMybatisDao<DemandMapper> implements D
 
 		if (!StringUtils.isBlank(validityPeriodEndDate)) {
 			try {
-				vEnd = DateUtils.addDays(DateUtils.parseDate(validityPeriodEndDate, AFTConstants.YYYYMMDD),1);
+				vEnd = DateUtils.addDays(DateUtils.parseDate(validityPeriodEndDate, AFTConstants.YYYYMMDD), 1);
 			} catch (ParseException e) {
 			}
 		}
@@ -416,7 +452,7 @@ public class DemandServiceImpl extends BaseMybatisDao<DemandMapper> implements D
 
 		if (!StringUtils.isBlank(releaseDateEndDate)) {
 			try {
-				rEnd = DateUtils.addDays(DateUtils.parseDate(releaseDateEndDate, AFTConstants.YYYYMMDD),1);
+				rEnd = DateUtils.addDays(DateUtils.parseDate(releaseDateEndDate, AFTConstants.YYYYMMDD), 1);
 			} catch (ParseException e) {
 			}
 		}
@@ -580,9 +616,9 @@ public class DemandServiceImpl extends BaseMybatisDao<DemandMapper> implements D
 	@Override
 	public Pagination<DemandPartnerListBo> lisePartnerDemand(String employerId, Integer pNo, Integer pSize) {
 		Map<String, Object> params = new HashMap<>();
-		
+
 		params.put("employerId", employerId);
-		
+
 		if (pNo == null || pNo < 0) {
 			pNo = 1;
 		}
@@ -590,7 +626,7 @@ public class DemandServiceImpl extends BaseMybatisDao<DemandMapper> implements D
 		if (pSize == null || pSize < 0 || pSize > 10) {
 			pSize = 10;
 		}
-		
+
 		return (Pagination<DemandPartnerListBo>) findPage("findPartnerDemandListByPage", "findPartnerDemandCount",
 				params, pNo, pSize);
 	}
@@ -599,7 +635,7 @@ public class DemandServiceImpl extends BaseMybatisDao<DemandMapper> implements D
 	public DemandPortalDetailBo findUserPortalDemandDetail(String id) {
 		return demandMapper.findUserPortalDemandDetail(id);
 	}
-	
+
 	@Override
 	public DemandPortalDetailBo findOrgPortalDemandDetail(String id) {
 		return demandMapper.findOrgPortalDemandDetail(id);
@@ -610,5 +646,4 @@ public class DemandServiceImpl extends BaseMybatisDao<DemandMapper> implements D
 		return demandMapper.findByIndustryCategoryA(industryCategoryA, id);
 	}
 
-
 }

+ 4 - 3
src/main/java/com/goafanti/portal/controller/PortalSearchApiController.java

@@ -77,8 +77,8 @@ public class PortalSearchApiController extends BaseApiController {
 	 * 用户搜索
 	 */
 	@RequestMapping(value = "/subscriberList", method = RequestMethod.GET)
-	public Result subscriberSearchList(String name, Integer level, Integer type, String field, Integer province, Integer city,
-			Integer area, String pageNo, String pageSize) {
+	public Result subscriberSearchList(String name, Integer level, Integer type, String field, Integer province,
+			Integer city, Integer area, String pageNo, String pageSize) {
 		Result res = new Result();
 		if (null == type) {
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "用户类型"));
@@ -106,7 +106,8 @@ public class PortalSearchApiController extends BaseApiController {
 		if (UserType.PERSONAL.getCode().equals(type)) {
 			res.setData(userIdentityService.listSubscriber(name, level, field, province, city, area, pNo, pSize));
 		} else {
-			res.setData(organizationIdentityService.listSubscriber(name, level, field, province, city, area, pNo, pSize));
+			res.setData(
+					organizationIdentityService.listSubscriber(name, level, field, province, city, area, pNo, pSize));
 		}
 		return res;
 	}