Prechádzať zdrojové kódy

Merge remote-tracking branch 'origin/master'

weifanli 3 rokov pred
rodič
commit
db7b94f52a

+ 6 - 4
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/controller/AppVersionInfoController.java

@@ -15,9 +15,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import com.yonge.cooleshow.biz.dal.entity.AppVersionInfo;
+import com.yonge.cooleshow.biz.dal.queryInfo.AppVersionInfoQueryInfo;
 import com.yonge.cooleshow.biz.dal.service.AppVersionInfoService;
 import com.yonge.cooleshow.common.controller.BaseController;
-import com.yonge.cooleshow.common.page.QueryInfo;
+import com.yonge.cooleshow.common.entity.HttpResponseResult;
+import com.yonge.cooleshow.common.page.PageInfo;
 
 @RequestMapping("appVersionInfo")
 @Api(tags = "APP版本信息服务")
@@ -30,14 +32,14 @@ public class AppVersionInfoController extends BaseController {
 	@ApiOperation("分页查询")
 	@GetMapping(value = "/list")
 	@PreAuthorize("@pcs.hasPermissions('appVersionInfo/list')")
-	public Object getList(QueryInfo queryInfo) {
+	public HttpResponseResult<PageInfo<AppVersionInfo>> getList(AppVersionInfoQueryInfo queryInfo) {
 		return succeed(appVersionInfoService.queryPage(queryInfo));
 	}
 
 	@ApiOperation("根据app客户端查询对象")
 	@ApiImplicitParam(name = "platform", value = "平台名称", required = true, dataType = "String", paramType = "path")
 	@GetMapping(value = "/queryByPlatform")
-	public Object queryByPlatform(String platform) {
+	public HttpResponseResult<AppVersionInfo> queryByPlatform(String platform) {
 		List<AppVersionInfo> list = appVersionInfoService.queryNewestByPlatform(platform);
 		if (list.size() > 0) {
 			return succeed(list.get(0));
@@ -49,7 +51,7 @@ public class AppVersionInfoController extends BaseController {
 	@ApiImplicitParam(name = "id", value = "ID编号", required = true, dataType = "Integer", paramType = "path")
 	@GetMapping(value = "/query")
 	@PreAuthorize("@pcs.hasPermissions('appVersionInfo/query')")
-	public Object query(Long id) {
+	public HttpResponseResult<AppVersionInfo> query(Long id) {
 		return succeed(appVersionInfoService.get(id));
 	}
 

+ 25 - 1
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/controller/SubjectController.java

@@ -4,6 +4,9 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 
+import java.util.Map;
+import java.util.stream.Collectors;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -43,11 +46,32 @@ public class SubjectController extends BaseController {
 		return succeed(subjectService.get(id));
 	}
 
+	@ApiOperation(value = "删除指定科目")
+	@PostMapping("/delete/{id}")
+	@PreAuthorize("@pcs.hasPermissions('subject/get')")
+	public HttpResponseResult<Subject> delete(@ApiParam(value = "科目编号", required = true) @PathVariable("id") Long id) {
+		subjectService.deleteById(id);
+		return succeed();
+	}
+
 	@ApiOperation(value = "分页查询科目列表")
 	@GetMapping("/queryPage")
 	@PreAuthorize("@pcs.hasPermissions('subject/queryPage')")
 	public HttpResponseResult<PageInfo<Subject>> queryPage(SubjectQueryInfo queryInfo) {
-		return succeed(subjectService.queryPage(queryInfo));
+		PageInfo<Subject> pageInfo = subjectService.queryPage(queryInfo);
+
+		Map<Long, Subject> map = subjectService.findBySubjectByIdList(pageInfo.getRows().stream().map(t -> t.getParentSubjectId()).collect(Collectors.toList())).stream()
+				.collect(Collectors.toMap(Subject::getId, t -> t));
+
+		pageInfo.getRows().forEach(row -> {
+
+			if(row.getParentSubjectId() != null && row.getParentSubjectId() > 0) {
+				row.setParentSubjectName(map.get(row.getParentSubjectId()).getName());
+			}
+
+		});
+
+		return succeed(pageInfo);
 	}
 
 	@ApiOperation(value = "分页查询科目树状列表")

+ 2 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dao/SubjectDao.java

@@ -30,5 +30,7 @@ public interface SubjectDao extends BaseDAO<Long, Subject> {
     List<Subject> findBySubjectByIdList(@Param("subjectIdList") String subjectIdList);
 
     List<Subject> findBySubjectIds(@Param("subjectIds") List<Long> subjectIds);
+    
+    int deleteById(Long id);
 
 }

+ 20 - 25
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/entity/Subject.java

@@ -2,7 +2,6 @@ package com.yonge.cooleshow.biz.dal.entity;
 
 import io.swagger.annotations.ApiModelProperty;
 
-import java.math.BigDecimal;
 import java.util.List;
 
 import org.apache.commons.lang3.builder.ToStringBuilder;
@@ -29,6 +28,8 @@ public class Subject {
 	@ApiModelProperty(value = "父级编号",required = false)
 	private Long parentSubjectId;
 	
+	private String parentSubjectName;
+	
 	@ApiModelProperty(value = "图片地址",required = false)
 	private String img;
 	
@@ -38,42 +39,20 @@ public class Subject {
 	/**  */
 	private java.util.Date updateTime;
 	
+	private String desc;
+	
 	/**  */
 	@ApiModelProperty(value = "是否删除1是,0否",required = false)
 	private YesOrNoEnum delFlag;
 
 	/**  */
-	@ApiModelProperty(value = "课程费用",required = false)
-	private BigDecimal fee;
-
-	/**  */
-	@ApiModelProperty(value = "对内1对外2",required = false)
-	private Integer tenantId = 1;
-
-	/**  */
 	@ApiModelProperty(value = "子节点列表",required = false)
 	private List<Subject> subjects;
 
-	public Integer getTenantId() {
-		return tenantId;
-	}
-
-	public void setTenantId(Integer tenantId) {
-		this.tenantId = tenantId;
-	}
-
 	public List<Subject> getSubjects() {
 		return subjects;
 	}
 
-	public BigDecimal getFee() {
-		return fee;
-	}
-
-	public void setFee(BigDecimal fee) {
-		this.fee = fee;
-	}
-
 	public void setSubjects(List<Subject> subjects) {
 		this.subjects = subjects;
 	}
@@ -110,6 +89,14 @@ public class Subject {
 		return this.parentSubjectId;
 	}
 			
+	public String getParentSubjectName() {
+		return parentSubjectName;
+	}
+
+	public void setParentSubjectName(String parentSubjectName) {
+		this.parentSubjectName = parentSubjectName;
+	}
+
 	public void setCreateTime(java.util.Date createTime){
 		this.createTime = createTime;
 	}
@@ -142,6 +129,14 @@ public class Subject {
 		this.img = img;
 	}
 
+	public String getDesc() {
+		return desc;
+	}
+
+	public void setDesc(String desc) {
+		this.desc = desc;
+	}
+
 	@Override
 	public String toString() {
 		return ToStringBuilder.reflectionToString(this);

+ 36 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/queryInfo/AppVersionInfoQueryInfo.java

@@ -0,0 +1,36 @@
+package com.yonge.cooleshow.biz.dal.queryInfo;
+
+import com.yonge.cooleshow.common.page.QueryInfo;
+
+public class AppVersionInfoQueryInfo extends QueryInfo {
+
+	private String version;
+	
+	private String platform;
+	
+	private String status;
+
+	public String getVersion() {
+		return version;
+	}
+
+	public void setVersion(String version) {
+		this.version = version;
+	}
+
+	public String getPlatform() {
+		return platform;
+	}
+
+	public void setPlatform(String platform) {
+		this.platform = platform;
+	}
+
+	public String getStatus() {
+		return status;
+	}
+
+	public void setStatus(String status) {
+		this.status = status;
+	}
+}

+ 2 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/SubjectService.java

@@ -17,6 +17,8 @@ public interface SubjectService extends BaseService<Long, Subject> {
 	 * @return
 	 */
 	PageInfo<Subject> queryPageTree(SubjectQueryInfo queryInfo);
+    
+    int deleteById(Long id);
 
 	/**
 	 * 修改、新增科目树状列表

+ 6 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/SubjectServiceImpl.java

@@ -4,6 +4,7 @@ import java.util.*;
 import java.util.stream.Collectors;
 
 import com.yonge.cooleshow.biz.dal.vo.SubjectSelectVo;
+
 import org.apache.commons.beanutils.BeanUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -39,6 +40,11 @@ public class SubjectServiceImpl extends BaseServiceImpl<Long, Subject> implement
     }
 
     @Override
+	public int deleteById(Long id) {
+		return subjectDao.deleteById(id);
+	}
+
+	@Override
     public void upSetSubject(Subject subject) {
         if (subject.getDelFlag() == YesOrNoEnum.YES) {
             subjectDao.delete(subject.getId());

+ 116 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/support/DistributedLock.java

@@ -0,0 +1,116 @@
+package com.yonge.cooleshow.biz.dal.support;
+
+import org.redisson.api.RLock;
+import org.redisson.api.RedissonClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Objects;
+import java.util.concurrent.*;
+
+/**
+ * 分布式竞争锁
+ *
+ * @author hgw
+ */
+public class DistributedLock {
+    private final static Logger log = LoggerFactory.getLogger(DistributedLock.class);
+
+    private final RedissonClient redissonClient;
+
+    private static final long DEFAULT_TIMEOUT = 60L;// key过期时间默认1分钟后
+
+    private static final TimeUnit DEFAULT_TIME_UNIT = TimeUnit.SECONDS;//默认过期时间单位-秒钟
+
+    private DistributedLock(RedissonClient redissonClient) {
+        this.redissonClient = redissonClient;
+    }
+
+    public static DistributedLock of(RedissonClient redissonClient) {
+        return new DistributedLock(redissonClient);
+    }
+
+    /**
+     * 分布式锁-默认锁60秒
+     *
+     * @param lockName lockKey
+     * @param runnable 任务
+     * @return true 锁成功  false 锁失败
+     */
+    public boolean runIfLockCanGet(final String lockName, Runnable runnable) {
+        return runIfLockCanGet(lockName, runnable, DEFAULT_TIMEOUT, DEFAULT_TIME_UNIT);
+    }
+
+    /**
+     * 分布式锁
+     *
+     * @param lockName lockKey
+     * @param runnable 任务
+     * @param timeout  超时时间
+     * @param unit     超时时间单位
+     * @return true 锁成功  false 锁失败
+     */
+    public boolean runIfLockCanGet(final String lockName, Runnable runnable, final long timeout, TimeUnit unit) {
+        RLock lock = redissonClient.getLock(lockName);
+        if (Objects.isNull(lock)) {
+            log.info("runIfLockCanGet lock is null lockName : {}", lockName);
+            return false;
+        }
+        try {
+            if (lock.tryLock(0, timeout, unit)) {
+                if (Objects.nonNull(runnable)) {
+                    runnable.run();
+                }
+                return true;
+            } else {
+                return false;
+            }
+        } catch (Exception e) {
+            log.error("runIfLockCanGet error lockName : {}", lockName, e);
+            throw new RuntimeException("runIfLockCanGet error lockName :" + lockName, e);
+        } finally {
+            unlock(lock);
+        }
+    }
+
+    /**
+     * 分布式锁-异步
+     *
+     * @param lockName lockKey
+     * @param callable 任务
+     * @param timeout  超时时间
+     * @param unit     超时时间单位
+     * @return true 锁成功  false 锁失败
+     */
+    public <T> Future<T> callIfLockCanGet(final String lockName, Callable<T> callable, final long timeout, TimeUnit unit) {
+        RLock lock = redissonClient.getLock(lockName);
+        if (Objects.isNull(lock)) {
+            log.info("callIfLockCanGet lock is null lockName : {}", lockName);
+            return null;
+        }
+        ExecutorService executor = Executors.newCachedThreadPool();
+        try {
+            if (lock.tryLock(0, timeout, unit)) {
+                return executor.submit(callable);
+            } else {
+                return null;
+            }
+        } catch (Exception e) {
+            log.error("callIfLockCanGet error lockKey {}", lockName);
+            throw new RuntimeException("任务执行异常");
+        } finally {
+            executor.shutdown();
+            unlock(lock);
+        }
+    }
+
+    /**
+     * 解锁
+     */
+    private void unlock(RLock lock) {
+        if (lock.getHoldCount() != 0) {
+            lock.unlock();
+        }
+    }
+
+}

+ 0 - 6
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/support/WrapperUtil.java

@@ -37,12 +37,6 @@ public class WrapperUtil {
                 .orElse(null);
     }
 
-    public static Integer toInt(String str) {
-        return Optional.ofNullable(str)
-                .map(Integer::valueOf)
-                .orElse(null);
-    }
-
     public static <O> Optional<Integer> intOptional(Optional<O> optional) {
         return optional
                 .map(String::valueOf)

+ 16 - 4
cooleshow-user/user-biz/src/main/resources/config/mybatis/AppVersionInfoMapper.xml

@@ -91,8 +91,14 @@
 	<select id="queryPage" resultMap="AppVersionInfo" parameterType="map">
 		SELECT * FROM app_version_info
 		<where>
-			<if test="search != null and search != ''">
-				platform_ LIKE CONCAT('%',#{search},'%')
+			<if test="version != null and version != ''">
+				and version_ = #{version}
+			</if>
+			<if test="platform != null and platform != ''">
+				and platform_ = #{platform}
+			</if>
+			<if test="status != null and status != ''">
+				and status_ = #{status}
 			</if>
 		</where>
 		ORDER BY status_ DESC
@@ -103,8 +109,14 @@
 	<select id="queryCount" resultType="int">
 		SELECT COUNT(*) FROM app_version_info
 		<where>
-			<if test="search != null and search != ''">
-				platform_ LIKE CONCAT('%',#{search},'%')
+			<if test="version != null and version != ''">
+				and version_ = #{version}
+			</if>
+			<if test="platform != null and platform != ''">
+				and platform_ = #{platform}
+			</if>
+			<if test="status != null and status != ''">
+				and status_ = #{status}
 			</if>
 		</where>
 	</select>

+ 10 - 3
cooleshow-user/user-biz/src/main/resources/config/mybatis/SubjectMapper.xml

@@ -12,6 +12,7 @@
         <result column="code_" property="code"/>
         <result column="parent_subject_id_" property="parentSubjectId"/>
         <result column="img_" property="img"/>
+        <result column="desc_" property="desc"/>
         <result column="create_time_" property="createTime"/>
         <result column="update_time_" property="updateTime"/>
         <result column="del_flag_" property="delFlag" typeHandler="com.yonge.cooleshow.common.dal.CustomEnumTypeHandler"/>
@@ -30,8 +31,8 @@
     <!-- 向数据库增加一条记录 -->
     <insert id="insert" parameterType="com.yonge.cooleshow.biz.dal.entity.Subject" useGeneratedKeys="true" keyColumn="id"
             keyProperty="id">
-        INSERT INTO subject (id_,name_,code_,parent_subject_id_,img_,create_time_,update_time_)
-        VALUES(#{id},#{name},#{code},#{parentSubjectId},#{img},now(),now())
+        INSERT INTO subject (id_,name_,code_,parent_subject_id_,img_,create_time_,update_time_,desc_)
+        VALUES(#{id},#{name},#{code},#{parentSubjectId},#{img},now(),now(),#{desc})
     </insert>
 
     <!-- 根据主键查询一条记录 -->
@@ -56,6 +57,9 @@
             <if test="name != null">
                 name_ = #{name},
             </if>
+            <if test="desc != null">
+                desc_ = #{desc},
+            </if>
         </set>
         WHERE id_ = #{id}
     </update>
@@ -114,6 +118,9 @@
       </foreach>
     </select>
 
-
+	<delete id="deleteById">
+		update subject set del_flag_ = 1 where id_ = #{id};
+		update subject set del_flag_ = 1 where parent_subject_id_ = #{id};
+	</delete>
 
 </mapper>