소스 검색

回音墙管理

jz.kai 4 년 전
부모
커밋
8a776de499

+ 18 - 0
common/src/main/java/com/jpsoft/enterprise/modules/base/dao/WhisperingWallDAO.java

@@ -0,0 +1,18 @@
+package com.jpsoft.enterprise.modules.base.dao;
+
+import java.util.List;
+import org.springframework.stereotype.Repository;
+import com.jpsoft.enterprise.modules.base.entity.WhisperingWall;
+import java.util.Map;
+import com.jpsoft.enterprise.modules.common.dto.Sort;
+
+@Repository
+public interface WhisperingWallDAO {
+	int insert(WhisperingWall entity);
+	int update(WhisperingWall entity);
+	int exist(String id);
+	WhisperingWall get(String id);
+	int delete(String id);
+	List<WhisperingWall> list();
+	List<WhisperingWall> search(Map<String,Object> searchParams,List<Sort> sortList);
+}

+ 53 - 0
common/src/main/java/com/jpsoft/enterprise/modules/base/entity/WhisperingWall.java

@@ -0,0 +1,53 @@
+package com.jpsoft.enterprise.modules.base.entity;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.text.SimpleDateFormat;
+import java.math.BigDecimal;
+import org.springframework.format.annotation.DateTimeFormat;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+/**
+  描述:base_whispering_wall的实体类
+ */
+@Data
+@ApiModel(value = "base_whispering_wall的实体类")
+public class WhisperingWall {
+        @ApiModelProperty(value = "编号")
+    private String id;
+        @ApiModelProperty(value = "提问")
+    private String question;
+        @ApiModelProperty(value = "提问人")
+    private String questionBy;
+        @DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
+	    @ApiModelProperty(value = "提问时间")
+    private Date questionTime;
+        @ApiModelProperty(value = "回答")
+    private String answer;
+        @ApiModelProperty(value = "回答人")
+    private String answerBy;
+        @DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
+	    @ApiModelProperty(value = "回答时间")
+    private Date answerTime;
+        @ApiModelProperty(value = "类型")
+    private Integer type;
+        @ApiModelProperty(value = "是否删除")
+    private Boolean delFlag;
+        @ApiModelProperty(value = "创建人")
+    private String createBy;
+        @DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
+	    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+        @ApiModelProperty(value = "更新人")
+    private String updateBy;
+        @DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
+	    @ApiModelProperty(value = "更新时间")
+    private Date updateTime;
+}

+ 17 - 0
common/src/main/java/com/jpsoft/enterprise/modules/base/service/WhisperingWallService.java

@@ -0,0 +1,17 @@
+package com.jpsoft.enterprise.modules.base.service;
+
+import java.util.List;
+import java.util.Map;
+import com.jpsoft.enterprise.modules.base.entity.WhisperingWall;
+import com.github.pagehelper.Page;
+import com.jpsoft.enterprise.modules.common.dto.Sort;
+
+public interface WhisperingWallService {
+	WhisperingWall get(String id);
+	boolean exist(String id);
+	int insert(WhisperingWall model);
+	int update(WhisperingWall model);
+	int delete(String id);
+	List<WhisperingWall> list();
+	Page<WhisperingWall> pageSearch(Map<String, Object> searchParams,int pageNum,int pageSize,boolean count,List<Sort> sortList);
+}

+ 70 - 0
common/src/main/java/com/jpsoft/enterprise/modules/base/service/impl/WhisperingWallServiceImpl.java

@@ -0,0 +1,70 @@
+package com.jpsoft.enterprise.modules.base.service.impl;
+
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import javax.annotation.Resource;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+import com.jpsoft.enterprise.modules.base.dao.WhisperingWallDAO;
+import com.jpsoft.enterprise.modules.base.entity.WhisperingWall;
+import com.jpsoft.enterprise.modules.base.service.WhisperingWallService;
+import com.github.pagehelper.Page;
+import com.jpsoft.enterprise.modules.common.dto.Sort;
+import com.github.pagehelper.PageHelper;
+
+@Transactional
+@Component(value="whisperingWallService")
+public class WhisperingWallServiceImpl implements WhisperingWallService {
+	@Resource(name="whisperingWallDAO")
+	private WhisperingWallDAO whisperingWallDAO;
+
+	@Override
+	public WhisperingWall get(String id) {
+		// TODO Auto-generated method stub
+		return whisperingWallDAO.get(id);
+	}
+
+	@Override
+	public int insert(WhisperingWall model) {
+		// TODO Auto-generated method stub
+		//model.setId(UUID.randomUUID().toString());
+		
+		return whisperingWallDAO.insert(model);
+	}
+
+	@Override
+	public int update(WhisperingWall model) {
+		// TODO Auto-generated method stub
+		return whisperingWallDAO.update(model);		
+	}
+
+	@Override
+	public int delete(String id) {
+		// TODO Auto-generated method stub
+		return whisperingWallDAO.delete(id);
+	}
+
+	@Override
+	public boolean exist(String id) {
+		// TODO Auto-generated method stub
+		int count = whisperingWallDAO.exist(id);
+		
+		return count > 0 ? true : false;
+	}
+	
+	@Override
+	public List<WhisperingWall> list() {
+		// TODO Auto-generated method stub
+		return whisperingWallDAO.list();
+	}
+		
+	@Override
+	public Page<WhisperingWall> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
+        Page<WhisperingWall> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
+            whisperingWallDAO.search(searchParams,sortList);
+        });
+        
+        return page;
+	}
+}

+ 117 - 0
common/src/main/resources/mapper/base/WhisperingWall.xml

@@ -0,0 +1,117 @@
+<?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">
+<!-- namespace必须指向DAO接口 -->
+<mapper namespace="com.jpsoft.enterprise.modules.base.dao.WhisperingWallDAO">
+	<resultMap id="WhisperingWallMap" type="com.jpsoft.enterprise.modules.base.entity.WhisperingWall">
+		<id property="id" column="id_" />
+			<result property="question" column="question_" />
+			<result property="questionBy" column="question_by" />
+			<result property="questionTime" column="question_time" />
+			<result property="answer" column="answer_" />
+			<result property="answerBy" column="answer_by" />
+			<result property="answerTime" column="answer_time" />
+			<result property="type" column="type_" />
+			<result property="delFlag" column="del_flag" />
+			<result property="createBy" column="create_by" />
+			<result property="createTime" column="create_time" />
+			<result property="updateBy" column="update_by" />
+			<result property="updateTime" column="update_time" />
+			</resultMap>
+	<insert id="insert" parameterType="com.jpsoft.enterprise.modules.base.entity.WhisperingWall">
+	<!--
+	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
+		select sys_guid() from dual
+	</selectKey>
+	-->
+	<![CDATA[
+		insert into base_whispering_wall
+	    (id_,question_,question_by,question_time,answer_,answer_by,answer_time,type_,del_flag,create_by,create_time,update_by,update_time)
+		values
+		(
+#{id,jdbcType=VARCHAR}
+,#{question,jdbcType=VARCHAR}
+,#{questionBy,jdbcType=VARCHAR}
+,#{questionTime,jdbcType= TIMESTAMP }
+,#{answer,jdbcType=VARCHAR}
+,#{answerBy,jdbcType=VARCHAR}
+,#{answerTime,jdbcType= TIMESTAMP }
+,#{type,jdbcType= NUMERIC }
+,#{delFlag,jdbcType= NUMERIC }
+,#{createBy,jdbcType=VARCHAR}
+,#{createTime,jdbcType= TIMESTAMP }
+,#{updateBy,jdbcType=VARCHAR}
+,#{updateTime,jdbcType= TIMESTAMP }
+		)
+	]]>
+	</insert>
+	<delete id="delete" parameterType="string">
+		delete from base_whispering_wall where id_=#{id,jdbcType=VARCHAR}
+	</delete>
+	<update id="update" parameterType="com.jpsoft.enterprise.modules.base.entity.WhisperingWall">
+		update base_whispering_wall
+		<set>
+				<if test="question!=null">
+		question_=#{question,jdbcType=VARCHAR},
+		</if>
+				<if test="questionBy!=null">
+		question_by=#{questionBy,jdbcType=VARCHAR},
+		</if>
+				<if test="questionTime!=null">
+		question_time=#{questionTime,jdbcType= TIMESTAMP },
+		</if>
+				<if test="answer!=null">
+		answer_=#{answer,jdbcType=VARCHAR},
+		</if>
+				<if test="answerBy!=null">
+		answer_by=#{answerBy,jdbcType=VARCHAR},
+		</if>
+				<if test="answerTime!=null">
+		answer_time=#{answerTime,jdbcType= TIMESTAMP },
+		</if>
+				<if test="type!=null">
+		type_=#{type,jdbcType= NUMERIC },
+		</if>
+				<if test="delFlag!=null">
+		del_flag=#{delFlag,jdbcType= NUMERIC },
+		</if>
+				<if test="createBy!=null">
+		create_by=#{createBy,jdbcType=VARCHAR},
+		</if>
+				<if test="createTime!=null">
+		create_time=#{createTime,jdbcType= TIMESTAMP },
+		</if>
+				<if test="updateBy!=null">
+		update_by=#{updateBy,jdbcType=VARCHAR},
+		</if>
+				<if test="updateTime!=null">
+		update_time=#{updateTime,jdbcType= TIMESTAMP },
+		</if>
+		</set>
+	where id_=#{id}
+	</update>
+	<select id="get" parameterType="string" resultMap="WhisperingWallMap">
+		select 
+id_,question_,question_by,question_time,answer_,answer_by,answer_time,type_,del_flag,create_by,create_time,update_by,update_time		from base_whispering_wall where id_=#{0}
+	</select>
+	<select id="exist" parameterType="string" resultType="int">
+		select count(*) from base_whispering_wall where id_=#{0}
+	</select>
+	<select id="list" resultMap="WhisperingWallMap">
+		select * from base_whispering_wall
+	</select>
+	<select id="search" parameterType="hashmap" resultMap="WhisperingWallMap">
+		<![CDATA[
+			select * from base_whispering_wall
+		]]>
+		<where>
+			del_flag=0
+			<if test="searchParams.id != null">
+				and ID_ like #{searchParams.id}
+			</if>
+		</where>
+		<foreach item="sort" collection="sortList"  open="order by" separator=",">
+	        ${sort.name} ${sort.order}
+	 	</foreach>
+	</select>
+</mapper>

+ 233 - 0
web/src/main/java/com/jpsoft/enterprise/modules/base/controller/WhisperingWallController.java

@@ -0,0 +1,233 @@
+package com.jpsoft.enterprise.modules.base.controller;
+
+import com.github.pagehelper.Page;
+import com.jpsoft.enterprise.modules.common.utils.PojoUtils;
+import com.jpsoft.enterprise.modules.common.dto.Sort;
+import com.jpsoft.enterprise.modules.common.dto.MessageResult;
+import com.jpsoft.enterprise.modules.base.entity.WhisperingWall;
+import com.jpsoft.enterprise.modules.base.service.WhisperingWallService;
+import com.jpsoft.enterprise.modules.sys.entity.User;
+import com.jpsoft.enterprise.modules.sys.service.UserService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+@RestController
+@RequestMapping("/base/whisperingWall")
+@Api(description = "whisperingWall")
+public class WhisperingWallController {
+    private Logger logger = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private WhisperingWallService whisperingWallService;
+    @Autowired
+    private UserService userService;
+
+    @ApiOperation(value="创建空记录")
+    @GetMapping("create")
+    public MessageResult<WhisperingWall> create(){
+        MessageResult<WhisperingWall> msgResult = new MessageResult<>();
+
+        WhisperingWall whisperingWall = new WhisperingWall();
+
+        msgResult.setData(whisperingWall);
+        msgResult.setResult(true);
+
+        return msgResult;
+    }
+    
+    @ApiOperation(value="添加信息")
+    @PostMapping("add")
+    public MessageResult<WhisperingWall> add(@RequestBody WhisperingWall whisperingWall,@RequestAttribute String subject){
+        MessageResult<WhisperingWall> msgResult = new MessageResult<>();
+
+        try {
+            whisperingWall.setId(UUID.randomUUID().toString());
+            whisperingWall.setDelFlag(false);
+            whisperingWall.setCreateBy(subject);
+            whisperingWall.setCreateTime(new Date());
+            
+            int affectCount = whisperingWallService.insert(whisperingWall);
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(whisperingWall);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("数据库添加失败");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+    @ApiOperation(value="获取信息")
+    @GetMapping("edit/{id}")
+    public MessageResult<WhisperingWall> edit(@PathVariable("id") String id){
+        MessageResult<WhisperingWall> msgResult = new MessageResult<>();
+
+        try {
+            WhisperingWall whisperingWall = whisperingWallService.get(id);
+
+            if (whisperingWall != null) {
+                msgResult.setResult(true);
+                msgResult.setData(whisperingWall);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("数据库不存在该记录!");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+    @ApiOperation(value="更新用户")
+    @PostMapping("update")
+    public MessageResult<WhisperingWall> update(@RequestBody WhisperingWall whisperingWall,@RequestAttribute String subject){
+        MessageResult<WhisperingWall> msgResult = new MessageResult<>();
+
+        try {
+            User user = userService.get(subject);
+
+            whisperingWall.setAnswerBy(user.getCompanyId());
+            whisperingWall.setAnswerTime(new Date());
+            whisperingWall.setUpdateBy(subject);
+            whisperingWall.setUpdateTime(new Date());
+            
+            int affectCount = whisperingWallService.update(whisperingWall);
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(whisperingWall);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("数据库更新失败");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+	@ApiOperation(value="删除")
+    @PostMapping("delete/{id}")
+    public MessageResult<Integer> delete(@PathVariable("id") String id,@RequestAttribute String subject){
+        MessageResult<Integer> msgResult = new MessageResult<>();
+
+        try {
+            WhisperingWall whisperingWall = whisperingWallService.get(id);
+            whisperingWall.setDelFlag(true);
+            whisperingWall.setUpdateBy(subject);
+            whisperingWall.setUpdateTime(new Date());
+
+            int affectCount = whisperingWallService.update(whisperingWall);
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(affectCount);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("删除失败");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+
+    @ApiOperation(value="批量删除")
+    @PostMapping("batchDelete")
+    public MessageResult<Integer> batchDelete(@RequestBody List<String> idList,@RequestAttribute String subject){
+        MessageResult<Integer> msgResult = new MessageResult<>();
+
+        try {
+            int affectCount = 0;
+
+            for (String id : idList) {
+                WhisperingWall whisperingWall = whisperingWallService.get(id);
+                whisperingWall.setDelFlag(true);
+                whisperingWall.setUpdateBy(subject);
+                whisperingWall.setUpdateTime(new Date());
+
+                affectCount += whisperingWallService.update(whisperingWall);
+            }
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(affectCount);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("删除失败");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+    @ApiOperation(value="列表")
+    @RequestMapping(value = "pageList",method = RequestMethod.POST)
+    public MessageResult<Map> pageList(
+            String id,
+            @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
+            @RequestParam(value="pageSize",defaultValue="20") int pageSize,
+            @RequestAttribute String subject){
+
+        //当前用户ID
+        System.out.println(subject);
+
+        MessageResult<Map> msgResult = new MessageResult<>();
+
+        Map<String,Object> searchParams = new HashMap<>();
+
+        List<Sort> sortList = new ArrayList<>();
+        sortList.add(new Sort("id_","asc"));
+
+        if (StringUtils.isNotEmpty(id)) {
+            searchParams.put("id","%" + id + "%");
+        }
+
+        Page<WhisperingWall> page = whisperingWallService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
+
+        msgResult.setResult(true);
+        msgResult.setData(PojoUtils.pageWrapper(page));
+
+        return msgResult;
+    }
+}

+ 109 - 0
web/src/main/java/com/jpsoft/enterprise/modules/mobile/controller/WhisperingWallApiController.java

@@ -0,0 +1,109 @@
+package com.jpsoft.enterprise.modules.mobile.controller;
+
+import com.jpsoft.enterprise.modules.base.entity.PersonInfo;
+import com.jpsoft.enterprise.modules.base.entity.WhisperingWall;
+import com.jpsoft.enterprise.modules.base.service.PersonInfoService;
+import com.jpsoft.enterprise.modules.base.service.WhisperingWallService;
+import com.jpsoft.enterprise.modules.common.dto.MessageResult;
+import com.jpsoft.enterprise.modules.common.dto.Sort;
+import com.jpsoft.enterprise.modules.sys.service.UserService;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.*;
+
+@RestController
+@RequestMapping("/mobile/whisperingWallApi")
+@Slf4j
+public class WhisperingWallApiController {
+    @Autowired
+    private WhisperingWallService whisperingWallService;
+    @Autowired
+    private PersonInfoService personInfoService;
+
+    @ApiOperation(value="提问")
+    @PostMapping("questions")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "question", value = "问题", required = true, paramType = "form"),
+            @ApiImplicitParam(name = "type", value = "类型", required = true, paramType = "form")
+    })
+    public MessageResult<WhisperingWall> questions(String question, int type, @RequestAttribute String subject){
+        MessageResult<WhisperingWall> msgResult = new MessageResult<>();
+
+        try {
+            PersonInfo personInfo = personInfoService.get(subject);
+
+            WhisperingWall whisperingWall = new WhisperingWall();
+            whisperingWall.setId(UUID.randomUUID().toString());
+            whisperingWall.setQuestion(question);
+            whisperingWall.setQuestionBy(personInfo.getCompanyId());
+            whisperingWall.setQuestionTime(new Date());
+            whisperingWall.setType(type);
+            whisperingWall.setDelFlag(false);
+            whisperingWall.setCreateBy(subject);
+            whisperingWall.setCreateTime(new Date());
+
+            int affectCount = whisperingWallService.insert(whisperingWall);
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(whisperingWall);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("数据库添加失败");
+            }
+        }
+        catch(Exception ex){
+            log.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+    @ApiOperation(value="回答")
+    @PostMapping("answers")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "编号", required = true, paramType = "form"),
+            @ApiImplicitParam(name = "answer", value = "回答", required = true, paramType = "form")
+    })
+    public MessageResult<WhisperingWall> answers(String id,String answer,@RequestAttribute String subject){
+        MessageResult<WhisperingWall> msgResult = new MessageResult<>();
+
+        try {
+            PersonInfo personInfo = personInfoService.get(subject);
+
+            WhisperingWall whisperingWall = whisperingWallService.get(id);
+            whisperingWall.setAnswer(answer);
+            whisperingWall.setAnswerBy(personInfo.getCompanyId());
+            whisperingWall.setAnswerTime(new Date());
+            whisperingWall.setUpdateBy(subject);
+            whisperingWall.setUpdateTime(new Date());
+
+            int affectCount = whisperingWallService.update(whisperingWall);
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(whisperingWall);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("数据库更新失败");
+            }
+        }
+        catch(Exception ex){
+            log.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+}