Antiloveg hace 8 años
padre
commit
814c144f74

+ 10 - 0
schema/2017-04-02.sql

@@ -0,0 +1,10 @@
+CREATE TABLE `notice` (
+  `id` VARCHAR(36) NOT NULL,
+  `aid` VARCHAR(36) NULL,
+  `notice_type` VARCHAR(16) NULL COMMENT '通知类型',
+  `content` VARCHAR(36) NULL COMMENT '通知内容',
+  `create_time` DATETIME NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+  `readed` INT(1) NULL,
+  PRIMARY KEY (`id`))
+ENGINE = InnoDB
+COMMENT = '流转状态通知表';

+ 92 - 2
src/main/java/com/goafanti/admin/controller/AdminApiController.java

@@ -162,6 +162,96 @@ public class AdminApiController extends CertifyApiController {
 	private AdminService					adminService;
 	@Resource
 	private OrgTechCenterDetailService		orgTechCenterDetailService;
+	
+	/**
+	 * 管理员修改本人信息
+	 * @param admin
+	 * @param bindingResult
+	 * @return
+	 */
+	@RequestMapping(value = "/updateAdminInfo", method = RequestMethod.POST)
+	public Result updateAdminInfo(@Valid InputAdmin admin, String pwd, BindingResult bindingResult){
+		Result res = new Result();
+		if (!checkAdminLogin(res)) {
+			return res;
+		}
+		
+		if (TokenManager.hasRole("999999")) {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "超级管理员"));
+			return res;
+		}
+		
+		if (bindingResult.hasErrors()) {
+			res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
+					AdminFields.getFieldDesc(bindingResult.getFieldError().getField())));
+			return res;
+		}
+		
+		if (StringUtils.isBlank(admin.getId())){
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "用户id"));
+			return res;
+		}
+		
+		if (StringUtils.isBlank(admin.getMobile())) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "登录帐号为空", "登录帐号"));
+			return res;
+		}
+
+		if (StringUtils.isBlank(admin.getName())) {
+			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "用户名为空", "用户名"));
+			return res;
+		}
+		
+		Admin a = adminService.selectByMobile(admin.getMobile().trim());
+		if (!TokenManager.getAdminId().equals(a.getId())) {
+			res.getError().add(buildError(ErrorConstants.USER_ALREADY_EXIST, "当前用户已注册!"));
+			return res;
+		}
+		
+		Admin ad = new Admin();
+		BeanUtils.copyProperties(admin, ad);
+		Admin aa = adminService.selectByPrimaryKey(TokenManager.getAdminId());
+		ad.setMobile(ad.getMobile().trim());
+		ad.setCreateTime(aa.getCreateTime());
+		
+		if (!StringUtils.isBlank(ad.getPassword())){
+			if (StringUtils.isBlank(pwd)){
+				res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "原密码"));
+				return res;
+			}
+			if (!aa.getPassword().equals(passwordUtil.getEncryptPwd(pwd, aa.getCreateTime()))) {
+				res.getError().add(buildError(ErrorConstants.PWD_NOT_MATCH_ERROR,"","原密码"));
+				return res;
+			}
+		} else {
+			ad.setPassword(aa.getPassword());
+		}
+		ad.setPassword(passwordUtil.getEncryptPwd(ad));
+		res.setData(adminService.updateByPrimaryKey(ad));
+		return res;
+	}
+	
+	
+	/**
+	 * 管理员本人信息详情
+	 * @param id
+	 * @return
+	 */
+	@RequestMapping(value = "/adminInfo", method = RequestMethod.GET)
+	public Result adminInfo(){
+		Result res = new Result();
+		if (!checkAdminLogin(res)) {
+			return res;
+		}
+		if (TokenManager.hasRole("999999")) {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "超级管理员"));
+			return res;
+		}
+		res.setData(adminService.selectByPrimaryKey(TokenManager.getAdminId()));
+		return res;
+	}
+	
+	
 
 	/**
 	 * 管理员列表
@@ -214,12 +304,12 @@ public class AdminApiController extends CertifyApiController {
 			return res;
 		}
 
-		if (null == admin.getMobile()) {
+		if (StringUtils.isBlank(admin.getMobile())) {
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "登录帐号为空", "登录帐号"));
 			return res;
 		}
 
-		if (null == admin.getName()) {
+		if (StringUtils.isBlank(admin.getName())) {
 			res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "用户名为空", "用户名"));
 			return res;
 		}

+ 81 - 0
src/main/java/com/goafanti/admin/controller/AdminNoticeApiController.java

@@ -0,0 +1,81 @@
+package com.goafanti.admin.controller;
+
+import javax.annotation.Resource;
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.goafanti.admin.service.NoticeService;
+import com.goafanti.common.bo.Result;
+import com.goafanti.common.controller.CertifyApiController;
+import com.goafanti.common.utils.StringUtils;
+import com.goafanti.core.shiro.token.TokenManager;
+@RestController
+@RequestMapping(value = "/api/admin/notice")
+public class AdminNoticeApiController extends CertifyApiController{
+	
+	@Resource
+	private NoticeService noticeService;
+	
+	/**
+	 * 未读通知数量
+	 * @return
+	 */
+	@RequestMapping(value = "/unreadCount", method = RequestMethod.GET)
+	public Result unreadCount(){
+		Result res = new Result();
+		if (!checkAdminLogin(res)) {
+			return res;
+		}
+		
+		
+		res.setData(noticeService.findUnreadNoticeCount());
+		return res;
+	}
+	
+	/**
+	 * 
+	 * 未读通知列表
+	 * @return
+	 */
+	@RequestMapping(value = "/unread", method = RequestMethod.GET)
+	public Result unread(String pageNo, String pageSize){
+		Result res = new Result();
+		if (!checkAdminLogin(res)) {
+			return res;
+		}
+		Integer pNo = 1;
+		Integer pSize = 10;
+		if (StringUtils.isNumeric(pageSize)) {
+			pSize = Integer.parseInt(pageSize);
+		}
+		if (StringUtils.isNumeric(pageNo)) {
+			pNo = Integer.parseInt(pageNo);
+		}
+		res.setData(noticeService.ListUnreadNoticeByAid(pNo, pSize, TokenManager.getAdminId()));
+		return res;
+	}
+	
+	/**
+	 * 已读通知列表
+	 * @return
+	 */
+	@RequestMapping(value = "/readed", method = RequestMethod.GET)
+	public Result readed(String pageNo, String pageSize){
+		Result res = new Result();
+		if (!checkAdminLogin(res)) {
+			return res;
+		}
+		Integer pNo = 1;
+		Integer pSize = 10;
+		if (StringUtils.isNumeric(pageSize)) {
+			pSize = Integer.parseInt(pageSize);
+		}
+		if (StringUtils.isNumeric(pageNo)) {
+			pNo = Integer.parseInt(pageNo);
+		}
+		res.setData(noticeService.ListReadedNoticeByAid(pNo, pSize, TokenManager.getAdminId()));
+		return res;
+	}
+}

+ 14 - 0
src/main/java/com/goafanti/admin/service/NoticeService.java

@@ -0,0 +1,14 @@
+package com.goafanti.admin.service;
+
+import com.goafanti.common.model.Notice;
+import com.goafanti.core.mybatis.page.Pagination;
+
+public interface NoticeService {
+
+	Pagination<Notice> ListUnreadNoticeByAid(Integer pageNo, Integer pageSize, String adminId);
+
+	Pagination<Notice> ListReadedNoticeByAid(Integer pNo, Integer pSize, String adminId);
+
+	int findUnreadNoticeCount();
+
+}

+ 3 - 2
src/main/java/com/goafanti/admin/service/impl/AdminServiceImpl.java

@@ -16,6 +16,7 @@ import com.goafanti.common.model.Admin;
 import com.goafanti.common.utils.StringUtils;
 import com.goafanti.core.mybatis.BaseMybatisDao;
 import com.goafanti.core.mybatis.page.Pagination;
+import com.goafanti.core.shiro.token.TokenManager;
 
 @Service
 public class AdminServiceImpl extends BaseMybatisDao<AdminMapper> implements AdminService {
@@ -45,9 +46,9 @@ public class AdminServiceImpl extends BaseMybatisDao<AdminMapper> implements Adm
 			Integer pageSize) {
 		Map<String, Object> params = new HashMap<>();
 
-		/*if (!TokenManager.hasRole("999999")) {
+		if (!TokenManager.hasRole("999999")) {
 			return null;
-		}*/
+		}
 
 		if (StringUtils.isNotBlank(province)) {
 			params.put("province", province);

+ 71 - 0
src/main/java/com/goafanti/admin/service/impl/NoticeServiceImpl.java

@@ -0,0 +1,71 @@
+package com.goafanti.admin.service.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.goafanti.admin.service.NoticeService;
+import com.goafanti.common.dao.NoticeMapper;
+import com.goafanti.common.model.Notice;
+import com.goafanti.core.mybatis.BaseMybatisDao;
+import com.goafanti.core.mybatis.page.Pagination;
+import com.goafanti.core.shiro.token.TokenManager;
+
+@Service
+public class NoticeServiceImpl extends BaseMybatisDao<NoticeMapper> implements NoticeService {
+	@Autowired
+	private NoticeMapper noticeMapper;
+
+	@SuppressWarnings("unchecked")
+	@Override
+	public Pagination<Notice> ListUnreadNoticeByAid(Integer pageNo, Integer pageSize, String aid) {
+		Map<String, Object> params = new HashMap<>();
+
+		if (!TokenManager.hasRole("999999")) {
+			params.put("aid", aid);
+		}
+
+		if (pageNo == null || pageNo < 0) {
+			pageNo = 1;
+		}
+
+		if (pageSize == null || pageSize < 0) {
+			pageSize = 10;
+		}
+		return (Pagination<Notice>) findPage("findUnreadNoticeListByPage", "findUnreadNoticeCount", params, pageNo,
+				pageSize);
+	}
+
+	@SuppressWarnings("unchecked")
+	@Override
+	public Pagination<Notice> ListReadedNoticeByAid(Integer pageNo, Integer pageSize, String aid) {
+		Map<String, Object> params = new HashMap<>();
+
+		if (!TokenManager.hasRole("999999")) {
+			params.put("aid", aid);
+		}
+
+		if (pageNo == null || pageNo < 0) {
+			pageNo = 1;
+		}
+
+		if (pageSize == null || pageSize < 0) {
+			pageSize = 10;
+		}
+		return (Pagination<Notice>) findPage("findReadedNoticeListByPage", "findReadedNoticeCount", params, pageNo,
+				pageSize);
+	}
+
+	@Override
+	public int findUnreadNoticeCount() {
+		String aid = null;
+		if (!TokenManager.hasRole("999999")) {
+			aid = TokenManager.getAdminId();
+		}
+		System.out.println(aid);
+
+		return noticeMapper.selectUnreadedCount(aid);
+	}
+}

+ 22 - 0
src/main/java/com/goafanti/common/dao/NoticeMapper.java

@@ -0,0 +1,22 @@
+package com.goafanti.common.dao;
+
+import com.goafanti.common.model.Notice;
+
+public interface NoticeMapper {
+    int deleteByPrimaryKey(String id);
+
+    int insert(Notice record);
+
+    int insertSelective(Notice record);
+
+    Notice selectByPrimaryKey(String id);
+
+    int updateByPrimaryKeySelective(Notice record);
+
+    int updateByPrimaryKey(Notice record);
+
+
+	int findUnreadNoticeCount(String aid);
+
+	int selectUnreadedCount(String aid);
+}

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

@@ -143,7 +143,7 @@
   	 select 
     <include refid="Base_Column_List" />
     from admin
-    where 1 = 1
+    where id <![CDATA[ <> ]]> '1'
     <if test = "province != null">
     	and province = #{province,jdbcType=VARCHAR}
     </if>
@@ -164,7 +164,7 @@
   
   <select id = "findAdminCount" parameterType="java.lang.String" resultType="java.lang.Integer">
    select count(1) from admin
-    where 1 = 1
+     where id <![CDATA[ <> ]]> '1'
     <if test = "province != null">
     	and province = #{province,jdbcType=VARCHAR}
     </if>

+ 157 - 0
src/main/java/com/goafanti/common/mapper/NoticeMapper.xml

@@ -0,0 +1,157 @@
+<?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.NoticeMapper" >
+  <resultMap id="BaseResultMap" type="com.goafanti.common.model.Notice" >
+    <id column="id" property="id" jdbcType="VARCHAR" />
+    <result column="aid" property="aid" jdbcType="VARCHAR" />
+    <result column="notice_type" property="noticeType" jdbcType="VARCHAR" />
+    <result column="content" property="content" jdbcType="VARCHAR" />
+    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
+    <result column="readed" property="readed" jdbcType="INTEGER" />
+  </resultMap>
+  <sql id="Base_Column_List" >
+    id, aid, notice_type, content, create_time, readed
+  </sql>
+  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
+    select 
+    <include refid="Base_Column_List" />
+    from notice
+    where id = #{id,jdbcType=VARCHAR}
+  </select>
+  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
+    delete from notice
+    where id = #{id,jdbcType=VARCHAR}
+  </delete>
+  <insert id="insert" parameterType="com.goafanti.common.model.Notice" >
+    insert into notice (id, aid, notice_type, 
+      content, create_time, readed
+      )
+    values (#{id,jdbcType=VARCHAR}, #{aid,jdbcType=VARCHAR}, #{noticeType,jdbcType=VARCHAR}, 
+      #{content,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{readed,jdbcType=INTEGER}
+      )
+  </insert>
+  <insert id="insertSelective" parameterType="com.goafanti.common.model.Notice" >
+    insert into notice
+    <trim prefix="(" suffix=")" suffixOverrides="," >
+      <if test="id != null" >
+        id,
+      </if>
+      <if test="aid != null" >
+        aid,
+      </if>
+      <if test="noticeType != null" >
+        notice_type,
+      </if>
+      <if test="content != null" >
+        content,
+      </if>
+      <if test="createTime != null" >
+        create_time,
+      </if>
+      <if test="readed != null" >
+        readed,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides="," >
+      <if test="id != null" >
+        #{id,jdbcType=VARCHAR},
+      </if>
+      <if test="aid != null" >
+        #{aid,jdbcType=VARCHAR},
+      </if>
+      <if test="noticeType != null" >
+        #{noticeType,jdbcType=VARCHAR},
+      </if>
+      <if test="content != null" >
+        #{content,jdbcType=VARCHAR},
+      </if>
+      <if test="createTime != null" >
+        #{createTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="readed != null" >
+        #{readed,jdbcType=INTEGER},
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.Notice" >
+    update notice
+    <set >
+      <if test="aid != null" >
+        aid = #{aid,jdbcType=VARCHAR},
+      </if>
+      <if test="noticeType != null" >
+        notice_type = #{noticeType,jdbcType=VARCHAR},
+      </if>
+      <if test="content != null" >
+        content = #{content,jdbcType=VARCHAR},
+      </if>
+      <if test="createTime != null" >
+        create_time = #{createTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="readed != null" >
+        readed = #{readed,jdbcType=INTEGER},
+      </if>
+    </set>
+    where id = #{id,jdbcType=VARCHAR}
+  </update>
+  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.Notice" >
+    update notice
+    set aid = #{aid,jdbcType=VARCHAR},
+      notice_type = #{noticeType,jdbcType=VARCHAR},
+      content = #{content,jdbcType=VARCHAR},
+      create_time = #{createTime,jdbcType=TIMESTAMP},
+      readed = #{readed,jdbcType=INTEGER}
+    where id = #{id,jdbcType=VARCHAR}
+  </update>
+  
+  <select id="findUnreadNoticeListByPage" parameterType="java.lang.String" resultMap="BaseResultMap">
+     select  
+     <include refid="Base_Column_List" />
+    from notice
+    where readed = 0 
+    <if test="aid != null">
+    	and aid = #{aid,jdbcType=VARCHAR}
+    </if>
+    <if test="page_sql!=null">
+		${page_sql}
+	</if>
+  </select>
+  
+   <select id="findUnreadNoticeCount" resultType="java.lang.Integer" parameterType="java.lang.String">
+ 	select count(1) 
+ 	 from notice
+    where readed = 0 
+    <if test="aid != null">
+    	and aid = #{aid,jdbcType=VARCHAR}
+    </if>
+  </select>
+  
+  <select id="findReadedNoticeListByPage" parameterType="java.lang.String" resultMap="BaseResultMap">
+     select  
+     <include refid="Base_Column_List" />
+    from notice
+    where readed = 1 
+    <if test="aid != null">
+    and aid = #{aid,jdbcType=VARCHAR}
+    </if>
+    <if test="page_sql!=null">
+		${page_sql}
+	</if>
+  </select>
+  
+   <select id="findReadedNoticeCount" resultType="java.lang.Integer" parameterType="java.lang.String">
+ 	select count(1) 
+ 	 from notice
+    where readed = 1 
+    <if test="aid != null">
+    and aid = #{aid,jdbcType=VARCHAR}
+    </if>
+  </select>
+  
+  <select id="selectUnreadedCount" resultType="java.lang.Integer" parameterType="java.lang.String">
+   select count(1) from notice where readed = 0 
+   <if test="_parameter">
+    	and aid = #{_parameter,jdbcType=VARCHAR}
+   </if>
+  </select>
+</mapper>

+ 87 - 0
src/main/java/com/goafanti/common/model/Notice.java

@@ -0,0 +1,87 @@
+package com.goafanti.common.model;
+
+import java.util.Date;
+
+import org.apache.commons.lang3.time.DateFormatUtils;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+public class Notice {
+    private String id;
+
+    private String aid;
+
+    /**
+    * 通知类型
+    */
+    private String noticeType;
+
+    /**
+    * 通知内容
+    */
+    private String content;
+
+    /**
+    * 创建时间
+    */
+    private Date createTime;
+    
+    private Integer readed;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getAid() {
+        return aid;
+    }
+
+    public void setAid(String aid) {
+        this.aid = aid;
+    }
+
+    public String getNoticeType() {
+        return noticeType;
+    }
+
+    public void setNoticeType(String noticeType) {
+        this.noticeType = noticeType;
+    }
+
+    public String getContent() {
+        return content;
+    }
+
+    public void setContent(String content) {
+        this.content = content;
+    }
+
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+    
+    @JsonIgnore
+    public Integer getReaded() {
+        return readed;
+    }
+
+    public void setReaded(Integer readed) {
+        this.readed = readed;
+    }
+    
+    public String getCreateTimeFormattedDate(){
+		if (this.createTime == null) {
+			return null;
+		} else {
+			return DateFormatUtils.format(this.getCreateTime(), "yyyy-MM-dd");
+		}
+	}
+}