This commit is contained in:
clay 2020-12-19 21:21:56 +08:00
parent 1b0fba9fef
commit c80e84c1c7
9 changed files with 304 additions and 33 deletions

View File

@ -1,8 +1,10 @@
package live.tomey.api.express.controller;
import live.tomey.api.express.aop.Public;
import live.tomey.api.express.aop.Root;
import live.tomey.api.express.dto.MessageSelect;
import live.tomey.api.express.dto.Result;
import live.tomey.api.express.dto.SendMessage;
import live.tomey.api.express.dto.ServerResult;
import live.tomey.api.express.entity.Account;
import live.tomey.api.express.enums.OrderEnum;
@ -32,6 +34,43 @@ public class MessageController {
@Autowired
private MessageService messageService;
@Root
@RequestMapping(value = "sendmessage",method = RequestMethod.POST)
private Result sendMessage (HttpServletRequest request) {
try {
Integer msgwho = HttpServletRequestUtil.getInteger(request,"msgwho");
Integer msgOneGrade = HttpServletRequestUtil.getInteger(request,"msgOneGrade");
String phone = HttpServletRequestUtil.getString(request,"phone");
String msgTitle = HttpServletRequestUtil.getString(request,"msgTitle");
String content = HttpServletRequestUtil.getString(request,"content");
if (msgwho<1||msgwho>2){
return new Result(false,0,"msgwho值错误");
}
if (msgwho == 1 && (msgOneGrade<1||msgOneGrade>3)){
return new Result(false,0,"msgOneGrade值错误");
}
if (msgwho ==2 && phone == null){
return new Result(false,0,"发送对象电话不能为空");
}
if (msgTitle==null){
return new Result(false,0,"标题不能为空");
}
if (content==null){
return new Result(false,0,"内容不能为空");
}
SendMessage sendMessage = new SendMessage(msgwho,msgOneGrade,phone,msgTitle,content);
ServerResult serverResult = messageService.sendMessage(sendMessage);
if (serverResult.isStart()){
return new Result(true,1,"发送成功");
}else {
return new Result(false,-1,serverResult.getMsg());
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
return new Result(false, 0, "系统错误");
}
}
@Public
@RequestMapping(value = "getmessagecount", method = RequestMethod.POST)

View File

@ -14,6 +14,13 @@ import java.util.List;
* @date 2020/12/2 11:30
*/
public interface AccountDao {
/**
* 没有条件获取所有用户信息
* @return
*/
List<AccountRoot> queryAccount();
/**
* 获取所有的用户信息
*

View File

@ -13,6 +13,9 @@ import java.util.List;
* @date 2020/12/16 11:33
*/
public interface MessagesDao {
int sendMessages(List<Messages> messagesList);
/**
* 添加信息
* @param messages

View File

@ -20,6 +20,10 @@ public class AccountRoot {
private Date registrationTime;
private String ncryptedProble;
private String ncryptedAnswers;
private Integer orderNum;
private Integer takeOrder;
private Integer consumption;
private Integer earn;
public Integer getId() {
return id;
@ -100,4 +104,36 @@ public class AccountRoot {
public void setNcryptedAnswers(String ncryptedAnswers) {
this.ncryptedAnswers = ncryptedAnswers;
}
public Integer getOrderNum() {
return orderNum;
}
public void setOrderNum(Integer orderNum) {
this.orderNum = orderNum;
}
public Integer getConsumption() {
return consumption;
}
public void setConsumption(Integer consumption) {
this.consumption = consumption;
}
public Integer getEarn() {
return earn;
}
public void setEarn(Integer earn) {
this.earn = earn;
}
public Integer getTakeOrder() {
return takeOrder;
}
public void setTakeOrder(Integer takeOrder) {
this.takeOrder = takeOrder;
}
}

View File

@ -0,0 +1,63 @@
package live.tomey.api.express.dto;
/**
* @author clay
* @version 1.0
* @mail 20932067@zju.edu.cn
* @date 2020/12/18 22:21
*/
public class SendMessage {
private Integer msgwho;
private Integer msgOneGrade;
private String phone;
private String msgTitle;
private String content;
public SendMessage(Integer msgwho, Integer msgOneGrade, String phone, String msgTitle, String content) {
this.msgwho = msgwho;
this.msgOneGrade = msgOneGrade;
this.phone = phone;
this.msgTitle = msgTitle;
this.content = content;
}
public Integer getMsgwho() {
return msgwho;
}
public void setMsgwho(Integer msgwho) {
this.msgwho = msgwho;
}
public Integer getMsgOneGrade() {
return msgOneGrade;
}
public void setMsgOneGrade(Integer msgOneGrade) {
this.msgOneGrade = msgOneGrade;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getMsgTitle() {
return msgTitle;
}
public void setMsgTitle(String msgTitle) {
this.msgTitle = msgTitle;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}

View File

@ -1,6 +1,7 @@
package live.tomey.api.express.service;
import live.tomey.api.express.dto.MessageSelect;
import live.tomey.api.express.dto.SendMessage;
import live.tomey.api.express.dto.ServerResult;
import live.tomey.api.express.entity.Account;
@ -12,6 +13,8 @@ import live.tomey.api.express.entity.Account;
*/
public interface MessageService {
ServerResult sendMessage(SendMessage sendMessage);
/**
* 获取信息
*

View File

@ -1,8 +1,12 @@
package live.tomey.api.express.service.impl;
import live.tomey.api.express.dao.AccountDao;
import live.tomey.api.express.dao.MessagesDao;
import live.tomey.api.express.dto.AccountRoot;
import live.tomey.api.express.dto.MessageSelect;
import live.tomey.api.express.dto.SendMessage;
import live.tomey.api.express.dto.ServerResult;
import live.tomey.api.express.entity.Account;
import live.tomey.api.express.entity.Messages;
import live.tomey.api.express.service.MessageService;
import live.tomey.api.express.unit.PageCalculator;
@ -12,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
/**
@ -26,6 +31,44 @@ public class MessageServiceImpl implements MessageService {
@Autowired
private MessagesDao messagesDao;
@Autowired
private AccountDao accountDao;
@Override
@Transactional
public ServerResult sendMessage(SendMessage sendMessage) {
try {
List<Messages> messagesList = new ArrayList<>();
if (sendMessage.getMsgwho() == 1) {
List<AccountRoot> accountList = accountDao.queryAccount();
for (AccountRoot accountRoot : accountList) {
if (sendMessage.getMsgOneGrade() == 1) {
Messages messages = new Messages(accountRoot.getId(), sendMessage.getMsgTitle(), sendMessage.getContent());
messagesList.add(messages);
} else {
if (sendMessage.getMsgOneGrade() == accountRoot.getIdentityId()) {
Messages messages = new Messages(accountRoot.getId(), sendMessage.getMsgTitle(), sendMessage.getContent());
messagesList.add(messages);
}
}
}
} else {
Account account = accountDao.queryAccountForPhone(sendMessage.getPhone());
Messages messages = new Messages(account.getId(), sendMessage.getMsgTitle(), sendMessage.getContent());
messagesList.add(messages);
}
int conut = messagesDao.sendMessages(messagesList);
System.out.println(conut);
if (conut == messagesList.size()) {
return new ServerResult(true, "操作成功");
} else {
return new ServerResult(false, "操作失败");
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
return new ServerResult(false, "系统错误!");
}
}
@Override
@Transactional

View File

@ -3,7 +3,38 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="live.tomey.api.express.dao.AccountDao">
<select id="queryAccountList" parameterType="live.tomey.api.express.dto.AccountSelect" resultType="live.tomey.api.express.dto.AccountRoot">
<resultMap id="accountRootList" type="live.tomey.api.express.dto.AccountRoot">
<id property="id" column="id" javaType="Integer"/>
<result property="phone" column="phone" javaType="String"/>
<result property="username" column="username" javaType="String"/>
<result property="sex" column="sex" javaType="Integer"/>
<result property="birthday" column="birthday" javaType="java.util.Date"/>
<result property="identityId" column="identity_id" javaType="Integer"/>
<result property="registrationTime" column="registration_time" javaType="java.util.Date"/>
<result property="ncryptedProble" column="ncryptedProble" javaType="String"/>
<result property="ncryptedAnswers" column="ncryptedAnswers" javaType="String"/>
<collection property="orderNum" ofType="Integer" javaType="Integer" column="id" select="queryOrderNum"/>
<collection property="takeOrder" ofType="Integer" javaType="Integer" column="id" select="queryTakeOrder"/>
<collection property="consumption" ofType="Integer" javaType="Integer" column="id" select="queryConsumption"/>
<collection property="earn" ofType="Integer" javaType="Integer" column="id" select="queryEarn"/>
</resultMap>
<select id="queryTakeOrder" resultType="Integer" parameterType="Integer">
SELECT count(1) FROM w_order WHERE courier_id = #{id}
</select>
<select id="queryEarn" resultType="Integer" parameterType="Integer">
SELECT sum(price) FROM w_order WHERE courier_id = #{id} AND status = 4
</select>
<select id="queryConsumption" resultType="Integer" parameterType="Integer">
SELECT sum(price) FROM w_order WHERE account_id = #{id}
</select>
<select id="queryOrderNum" resultType="Integer" parameterType="Integer">
SELECT count(1) FROM w_order WHERE account_id = #{id}
</select>
<select id="queryAccountList" parameterType="live.tomey.api.express.dto.AccountSelect"
resultMap="accountRootList">
SELECT
id,
phone,
@ -29,6 +60,7 @@
<if test="accountSelect.email!=null">
AND w_account.email LIKE '%${accountSelect.email}%'
</if>
AND w_account.identity_id !=1
</where>
ORDER BY
w_account.registration_time DESC
@ -51,63 +83,88 @@
<if test="accountSelect.email!=null">
AND w_account.email LIKE '%${accountSelect.email}%'
</if>
AND w_account.identity_id !=1
</where>
</select>
<select id="queryAccount" resultType="live.tomey.api.express.dto.AccountRoot">
SELECT id,
phone,
username,
email,
sex,
birthday,
identity_id,
registration_time,
ncrypted_proble,
ncrypted_answers
FROM w_account
WHERE w_account.identity_id !=1
</select>
<select id="queryAccountForPhone" parameterType="String" resultType="live.tomey.api.express.entity.Account">
SELECT * FROM w_account WHERE phone = #{phone}
SELECT *
FROM w_account
WHERE phone = #{phone}
</select>
<select id="queryAccountForOrderId" parameterType="Integer" resultType="live.tomey.api.express.entity.Account">
SELECT * FROM w_account WHERE id IN(SELECT account_id FROM w_order WHERE id =#{orderId})
SELECT *
FROM w_account
WHERE id IN (SELECT account_id FROM w_order WHERE id = #{orderId})
</select>
<insert id="insertAccount" parameterType="live.tomey.api.express.entity.Account" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
INSERT INTO
w_account(
phone,
username,
password,
email,
sex,
identity_id,
registration_time
)
VALUES (
#{account.phone},
#{account.username},
#{account.password},
#{account.email},
#{account.sex},
#{account.identityId},
#{account.registrationTime}
)
<insert id="insertAccount" parameterType="live.tomey.api.express.entity.Account" useGeneratedKeys="true"
keyProperty="id" keyColumn="id">
INSERT INTO w_account(phone,
username,
password,
email,
sex,
identity_id,
registration_time)
VALUES (#{account.phone},
#{account.username},
#{account.password},
#{account.email},
#{account.sex},
#{account.identityId},
#{account.registrationTime})
</insert>
<update id="updateAccountIdentity">
UPDATE w_account SET identity_id = #{identityId} WHERE id = #{id}
UPDATE w_account
SET identity_id = #{identityId}
WHERE id = #{id}
</update>
<update id="updateAccountPassword">
UPDATE w_account SET password = #{password} WHERE id = #{id}
UPDATE w_account
SET password = #{password}
WHERE id = #{id}
</update>
<update id="updateAccountInfo" parameterType="live.tomey.api.express.entity.Account">
UPDATE w_account
<set>
<if test="account.username!=null"> username = #{account.username} ,</if>
<if test="account.email!=null"> email = #{account.email} ,</if>
<if test="account.sex>0"> sex = #{account.sex} ,</if>
<if test="account.birthday!=null"> birthday = #{account.birthday}</if>
<if test="account.username!=null">username = #{account.username} ,</if>
<if test="account.email!=null">email = #{account.email} ,</if>
<if test="account.sex>0">sex = #{account.sex} ,</if>
<if test="account.birthday!=null">birthday = #{account.birthday}</if>
</set>
WHERE id = #{account.id}
WHERE id = #{account.id}
</update>
<update id="updateEncrypted" parameterType="live.tomey.api.express.entity.Account">
UPDATE w_account SET ncrypted_proble = #{account.ncryptedProble},ncrypted_answers = #{account.ncryptedAnswers} WHERE id = #{account.id}
UPDATE w_account
SET ncrypted_proble = #{account.ncryptedProble},
ncrypted_answers = #{account.ncryptedAnswers}
WHERE id = #{account.id}
</update>
<select id="checkEncrypted" resultType="Integer" >
SELECT count(1) FROM w_account WHERE ncrypted_proble is not null AND phone = #{phone}
<select id="checkEncrypted" resultType="Integer">
SELECT count(1)
FROM w_account
WHERE ncrypted_proble is not null
AND phone = #{phone}
</select>
</mapper>

View File

@ -3,6 +3,26 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="live.tomey.api.express.dao.MessagesDao">
<insert id="sendMessages" parameterType="java.util.List">
INSERT INTO
w_message(
account_id,
title,
content,
is_read,
send_time
) VALUES
<foreach collection="list" item="message" index="index" separator=",">
(
#{message.accountId},
#{message.title},
#{message.content},
#{message.isRead},
#{message.sendTime}
)
</foreach>
</insert>
<insert id="insertMessage" parameterType="live.tomey.api.express.entity.Messages" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
INSERT INTO
w_message(