Commit f0496c04 authored by liqin's avatar liqin 💬

Merge branch 'master' of http://111.203.232.171:8888/licc/shop-mall into master

parents a5b1cf41 3b192d8c
......@@ -23,6 +23,8 @@ public enum ResultEnum {
CODETYPE_ERROR("1009","手机号码格式不正确"),
CODESEND_ERROR("1010","请相隔60S后再发送"),
FILE_NOT_LOGIN("2001", "未登录"),
FILE_NOT_HAVE_PERMISSION("2002", "没有权限"),
FAIL_ACCOUNT_LOCK("2003", "账号已被锁定"),
......
......@@ -5,19 +5,22 @@ import cn.wisenergy.common.enums.ResultEnum;
import org.springframework.stereotype.Component;
import java.io.Serializable;
import java.util.Map;
/**
* 返回信息包装类
* Created by m1991 on 2021/2/28 23:08
*/
@Component
public class Result<T> implements Serializable{
public class Result<T> implements Serializable {
public String code;
public String msg;
private T data;
private T wyz;
/**
* 无参构造
*/
......@@ -52,6 +55,21 @@ public class Result<T> implements Serializable{
this.data = data;
}
public T getWyz() {
return wyz;
}
public void setWyz(T wyz) {
this.wyz = wyz;
}
public Result(String code, String msg, T data, T wyz) {
this.code = code;
this.msg = msg;
this.data = data;
this.wyz = wyz;
}
/**
* 根据枚举创建一个Result
* @param resultEnum
......
......@@ -41,6 +41,19 @@ public class ResultUtils {
return Result;
}
/**
* 用于返回唯一值
* @param data
* @param wyz
* @return
*/
public static Result returnDataSuccess(Object data,String wyz) {
Result Result = new Result(ResultEnum.SUCCESS);
Result.setData(data);
Result.setWyz(wyz);
return Result;
}
/**
* 返回一个失败的Result
* @return
......
package cn.wisenergy.mapper;
import cn.wisenergy.model.app.AccountInfo;
import cn.wisenergy.model.app.LastMonthAccount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
......@@ -15,4 +14,27 @@ public interface LastAccountMapper extends BaseMapper<LastMonthAccount> {
* @return 账户信息
*/
LastMonthAccount getByUserIdAndTime(@Param("userId") String userId, @Param("yearMonth") String yearMonth);
/**
* 把 A 表的结构数据 复制给 B表
*
* @param oldTable A
* @param newTable B
*/
void copyTable(@Param("oldTable") String oldTable, @Param("newTable") String newTable);
/**
* 删除表
*
* @param tableName 表名
*/
void deleteTable(@Param("tableName") String tableName);
/**
* 更新表名
*
* @param oldTableName 旧表名
* @param newTableName 新表名
*/
void updateTableName(@Param("oldTableName") String oldTableName, @Param("newTableName") String newTableName);
}
......@@ -22,19 +22,43 @@ public interface ShopZxMapper extends BaseMapper<shopZx> {
*/
int zxadd(@Param("zxUrl") String zxUrl,@Param("userId") String userId,@Param("zxName") String zxName,@Param("zxField") String zxField,@Param("imgUrl") String imgUrl,@Param("zxAddress") String zxAddress);
/**
* 查询全部资讯
* @return
*/
List<shopZx> findAll();
/**分页 资讯内容倒叙查询
* PageSize int, --每页的记录数量,比如10条#{beginPos},#{pageSize}
* @param
* @return
*/
// List selectAll( @Param("beginPos") int beginPos,@Param("PageSize") int PageSize);
List<shopZx> selectPage();
/**
* 根据手机号删除资讯
* @param userId
* @return
*/
int deleteByPrimaryKey(Long userId);
/**
* 分页查询资讯
* 根据手机号查询资讯
* @param userId
* @return
*/
// List<shopZx> selectPage();
int insert(shopZx userId);
int insertSelective(shopZx userId);
shopZx selectByPrimaryKey(Long userId);
int updateByPrimaryKeySelective(shopZx userId);
int updateByPrimaryKey(shopZx userId);
}
......@@ -56,6 +56,10 @@
<if test="updateTime != null">and #{updateTime} &gt;= update_time</if>
</sql>
<delete id="deleteTable">
drop table ${tableName}
</delete>
<select id="getByUserIdAndTime" resultType="cn.wisenergy.model.app.LastMonthAccount">
select
......@@ -68,4 +72,14 @@
</where>
</select>
<update id="copyTable">
CREATE TABLE ${newTable} SELECT * FROM ${oldTable};
</update>
<update id="updateTableName">
rename table ${oldTableName} to ${newTableName};
</update>
</mapper>
\ No newline at end of file
......@@ -48,11 +48,11 @@
<!--</insert>-->
<!--资讯内容倒叙查询-->
<select id="selectAll" parameterType="java.lang.Integer" resultType="cn.wisenergy.model.app.shopZx">
<select id="findAll" parameterType="java.lang.Integer" resultType="cn.wisenergy.model.app.shopZx">
select zxid as zxid,zxUrl as zxUrl,
zxLikes as zxLikes,userid as userid,zxName as zxName,
zxShenHe as zxShenHe,zxField as zxField,zxDate as zxDate,
imgUrl as imgUrl,zxAddress as zxAddress from shop_zx order by zxid desc limit #{beginPos},#{pageSize}
imgUrl as imgUrl,zxAddress as zxAddress from shop_zx order by zxid desc limit #{pageNum},#{pageSize}
</select>
<!--资讯总记录数查询-->
......@@ -64,7 +64,7 @@
select zxid as zxid,zxUrl as zxUrl,
zxLikes as zxLikes,userid as userid,zxName as zxName,
zxShenHe as zxShenHe,zxField as zxField,zxDate as zxDate,
imgUrl as imgUrl,zxAddress as zxAddress from shop_zx order by zxid desc limit #{beginPos},#{pageSize}
imgUrl as imgUrl,zxAddress as zxAddress from shop_zx order by zxid desc limit #{pageNum},#{pageSize}
</select>
......
......@@ -52,4 +52,9 @@ public interface AccountService {
* @return true or false
*/
R<Boolean> progressPrizeCount();
/**
* 账户表镜像---每月更新一次,保存上一个的数据
*/
void mirrorImage();
}
......@@ -3,6 +3,7 @@ package cn.wisenergy.service.app;
import cn.wisenergy.common.utils.PageRequest;
import cn.wisenergy.common.utils.PageResult;
import cn.wisenergy.mapper.ShopZxMapper;
import cn.wisenergy.model.app.shopZx;
import org.springframework.core.io.Resource;
import org.springframework.web.multipart.MultipartFile;
......@@ -47,24 +48,31 @@ public interface UploadService {
String storeFile(MultipartFile file);
Resource loadFileAsResource(String fileName);
/**
* 查询资讯所有信息(分页——10条信息一页)
* @param
* 根据用户ID查找用户资讯
* @param userId
* @return
*/
Map getList(int beginPos, int pageSize);
// public Page<shopZx> find();
shopZx findByUserId(Long userId);
/**
* 分页查询接口
* 查询所有资讯
* @return
*/
List<shopZx> findAll();
/**
* 分页查询接口 资讯分页
* 这里统一封装了分页请求和结果,避免直接引入具体框架的分页对象, 如MyBatis或JPA的分页对象
* 从而避免因为替换ORM框架而导致服务层、控制层的分页接口也需要变动的情况,替换ORM框架也不会
* 影响服务层以上的分页接口,起到了解耦的作用
* @param pageRequest 自定义,统一分页查询请求
* @return PageResult 自定义,统一分页查询结果
*/
// PageResult findPage(PageRequest pageRequest);
PageResult findPage(PageRequest pageRequest);
}
......@@ -7,18 +7,17 @@ import cn.wisenergy.model.vo.AerialDeliveryVo;
import java.util.Map;
/**
* @author 86187
* @author 86187
* @ Description: 用户接口
* @ Author : 86187
* @ Date : 2021/1/6 16:08
* @author 86187
*/
public interface UserService {
/**
* 获取用户信息
*
* @param userId 用户id
* @return 用户信息
*/
......@@ -28,7 +27,6 @@ public interface UserService {
/**
* 获取用户信息
*
* @param userId 用户id
* @return 用户信息
*/
......@@ -59,21 +57,5 @@ public interface UserService {
*/
R<AerialDeliveryVo> queryAerialDelivery();
/**
* 设置用户头像
*
* @param userId 用户id
* @param headImage 头像地址url
* @return true or false
*/
R<Boolean> setHeadImage(String userId, String headImage);
/**
* 填写设置页面-邀请码
*
* @param userId 用户id
* @param inviteCode 邀请码
* @return true or false
*/
R<Boolean> fillInInviteCode(String userId, String inviteCode);
}
......@@ -55,6 +55,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
@Autowired
private ProgressPrizeMapper progressPrizeMapper;
@Autowired
private LastAccountMapper lastAccountMapper;
private static final String PATTERN = "yyyy-MM";
private static final Integer TWENTY = 20;
......@@ -282,6 +285,30 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
return R.ok(0, true);
}
@Override
public void mirrorImage() {
//1、把账户表account_info复制给表account_image CREATE TABLE table_2 SELECT * FROM table_1;
lastAccountMapper.copyTable("account_info", "account_image");
//删除上月备份
lastAccountMapper.deleteTable("account_backup");
//备份
lastAccountMapper.copyTable("account_info", "account_backup");
//2、把上月账户表last_month_account 复制给month_account_image
lastAccountMapper.copyTable("last_month_account", "month_account_image");
//3、删除last_month_account
lastAccountMapper.deleteTable("last_month_account");
//4、把account_image 更名为 last_month_account rename table table_2 to table_1;
lastAccountMapper.updateTableName("account_image", "last_month_account");
//5、删除month_account_image DROP table table_2;
lastAccountMapper.deleteTable("month_account_image");
}
public void getUser(List<User> list, String userId) {
User user = usersMapper.getByUserId(userId);
list.add(user);
......
......@@ -256,13 +256,6 @@ public class UploadServiceImpl implements UploadService {
}
/**
* 获取资讯分页数据
* @return
*/
// @Override
/**
* 多文件上传 TODO
*/
......@@ -321,8 +314,31 @@ public class UploadServiceImpl implements UploadService {
}
@Override
public Map getList(int beginPos, int pageSize) {
return null;
public shopZx findByUserId(Long userId) {
return shopZxMapper.selectByPrimaryKey(userId);
}
@Override
public List<shopZx> findAll() {
return shopZxMapper.findAll();
}
/**
* 调用分页插件完成分页
* @param pageRequest
* @return
*/
private PageInfo<shopZx> getPageInfo(PageRequest pageRequest) {
int pageNum = pageRequest.getPageNum();
int pageSize = pageRequest.getPageSize();
PageHelper.startPage(pageNum, pageSize);
List<shopZx> sysMenus = shopZxMapper.selectPage();
return new PageInfo<shopZx>(sysMenus);
}
@Override
public PageResult findPage(PageRequest pageRequest) {
return PageUtils.getPageResult(pageRequest, getPageInfo(pageRequest));
}
// @Override
......
package cn.wisenergy.web.admin.controller.app;
import cn.wisenergy.service.app.AccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author 86187
*/
@Api(tags = "表镜像管理")
@RestController
@RequestMapping("/image")
@Slf4j
public class LastAccountController {
@Autowired
private AccountService accountService;
@ApiOperation(value = "复制表-结构和数据", notes = "复制表-结构和数据", httpMethod = "PUT")
@PutMapping("/add")
public void copyTable(){
accountService.mirrorImage();
}
}
......@@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
/**
......@@ -27,7 +28,7 @@ import java.util.Map;
*/
@Api(tags = "登录/注册")
@Slf4j
@RequestMapping("/api/user")
@RequestMapping("api/user")
@RestController
public class LoginController {
@Autowired
......@@ -52,30 +53,41 @@ public class LoginController {
@ApiImplicitParam(name = "sms", value = "验证码", dataType = "String"),
@ApiImplicitParam(name = "userId", value = "用户手机号", required = true, dataType = "String")})
@RequestMapping("/login")
public Result loginBySms(String userId, String sms)throws Exception{
public Map loginBySms(@RequestParam String userId, @RequestParam String sms)throws Exception{
User users=null;
Map map=new HashMap();
String key= StringUtil.formatKeyWithPrefix(Constants.RedisKey.PROJECT_PRIFIX,Constants.RedisKey.SMS_PRIFIX,userId,Constants.Sms.CodeType.LOGIN_OR_REGISTER+"");
String redisCode=redisUtils.getValue(key);
if(StringUtil.isBlank(redisCode) || !sms.equals(redisCode)){
throw new BaseException(ResultEnum.FAIL_VERIFY);
map.put("code","1003");
map.put("msg","验证码错误");
// throw new BaseException(ResultEnum.FAIL_VERIFY);
return map;
}
redisUtils.delete(key);
//根据手机号判断用户是否存在
//不存在则保存用户信息--修改为提示用户注册
users=usersService.queryUsersByPhone(userId);
if(null==users){
throw new BaseException(ResultEnum.FAIL_ACCOUNT_NOT_EXIST);
// users=new User();
// users.setUserId(userId);
// usersService.qdtxAddUsers(users);;
//throw new BaseException(ResultEnum.FAIL_ACCOUNT_NOT_EXIST);
map.put("code","1005");
map.put("msg","账号不存在,请注册");
return map;
}
String token=createToken(users);
String token= null;
token = createToken(users);
if(!StringUtil.isBlank(token)){
return ResultUtils.returnDataSuccess(StringUtil.createSimpleMap("token",token));
String wyz=users.getInviteCode();
Map<String, Object> map1=StringUtil.createSimpleMap("token",token);
map1.put("wyz",wyz);
map1.put("code",0);
map1.put("msg","成功!");
return map1;
}
return ResultUtils.returnFail();
return (Map) ResultUtils.returnFail();
}
public String createToken(User users)throws Exception{
......@@ -87,21 +99,30 @@ public class LoginController {
redisUtils.set(tokenKey, JSONObject.toJSONString(usersDto),Constants.Duration.HALF_HOUR_INT);
return token;
}
@ApiOperation(value = "获取用户登录token信息", notes = "获取用户登录token信息", httpMethod = "POST", produces = "application/json; charset=UTF-8")
@RequestMapping("/info")
public Result info(HttpServletRequest request)throws Exception{
public Map info(HttpServletRequest request)throws Exception{
String token=request.getHeader("token");
String tokenKey=StringUtil.formatKeyWithPrefix(Constants.RedisKey.PROJECT_PRIFIX,Constants.RedisKey.TOKEN_PRIFIX,token);
String userDtoJson=redisUtils.getValue(tokenKey);
if(StringUtil.isBlank(userDtoJson)){
throw new BaseException(ResultEnum.FILE_NOT_LOGIN);
Map map=new HashMap();
map.put("code","2001");
map.put("msg","未登录");
return map;
///throw new BaseException(ResultEnum.FILE_NOT_LOGIN);
}
UsersDto usersDto=JSONObject.parseObject(userDtoJson,UsersDto.class);
usersDto.setPassword(null);
return ResultUtils.returnDataSuccess(userDtoJson);
return (Map) ResultUtils.returnDataSuccess(userDtoJson);
}
//用户注册
@ApiOperation(value = "用户注册", notes = "用户注册", httpMethod = "POST", produces = "application/json; charset=UTF-8")
@ApiImplicitParams({
......@@ -110,22 +131,37 @@ public class LoginController {
@ApiImplicitParam(name = "sms", value = "验证码",required = true, dataType = "String")
})
@RequestMapping("/register")
public Map register(@RequestParam String userId, String beInvitedCode, @RequestParam String sms)throws Exception {
public Map register(@RequestParam String userId,@RequestParam String beInvitedCode, @RequestParam String sms) {
User users=null;
String key= StringUtil.formatKeyWithPrefix(Constants.RedisKey.PROJECT_PRIFIX,Constants.RedisKey.SMS_PRIFIX,userId,Constants.Sms.CodeType.LOGIN_OR_REGISTER+"");
String redisCode=redisUtils.getValue(key);
if(StringUtil.isBlank(redisCode) || !sms.equals(redisCode)){
try {
throw new BaseException(ResultEnum.FAIL_VERIFY);
} catch (BaseException e) {
Map map=new HashMap();
map.put("code","1003");
map.put("msg","验证码错误");
// throw new BaseException(ResultEnum.FAIL_VERIFY);
return map;
}
}
redisUtils.delete(key);
//判断phone是否符合输入类型
if(!userId.matches(Constants.RegConstant.PHONE_REGSTR)){
try {
throw new BaseException(ResultEnum.PHONE_ERROR);
} catch (BaseException e) {
e.printStackTrace();
Map map=new HashMap();
map.put("code","1008");
map.put("msg","手机号码格式不正确");
// throw new BaseException(ResultEnum.FAIL_VERIFY);
return map;
}
}
// if(userId.equals())){
// throw new BaseException(ResultEnum.PHONE_ERROR);
// }
return usersService.userByZx(userId,beInvitedCode);
}
......
......@@ -10,8 +10,13 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
@Api(tags = "发送手机验证码 codeType 0注册/登录验证 1修改密码 2订单通知信息")
@Slf4j
@RequestMapping("/api/sms")
......@@ -36,13 +41,31 @@ public class SmsController {
@ApiImplicitParam(name = "phone", value = "用户手机号", required = true, dataType = "String"),
@ApiImplicitParam(name = "codeType", value = "验证码类型用途 0注册/登录验证 1修改密码 2订单通知信息", dataType = "Integer")})
@RequestMapping("/verifyCode")
public Result verifyCode(String phone, Integer codeType) throws Exception {
@ResponseBody
public Result verifyCode(@RequestParam String phone, @RequestParam Integer codeType) {
Map map=new HashMap();
//判断phone和codeType是否符合输入类型
if(!phone.matches(Constants.RegConstant.PHONE_REGSTR)){
try {
throw new BaseException(ResultEnum.PHONE_ERROR);
} catch (BaseException e) {
e.printStackTrace();
map.put("code","1005");
map.put("msg","账号不存在,请注册");
return (Result) map;
}
}
if(codeType!=Constants.Sms.CodeType.LOGIN_OR_REGISTER && codeType!=Constants.Sms.CodeType.PASS_UPDATE && codeType!=Constants.Sms.CodeType.ORDER_NOTICE){
try {
throw new BaseException(ResultEnum.CODETYPE_ERROR);
} catch (BaseException e) {
e.printStackTrace();
map.put("code","1009");
map.put("msg","手机号码格式不正确");
return (Result) map;
}
}
String key= StringUtil.formatKeyWithPrefix(Constants.RedisKey.PROJECT_PRIFIX,Constants.RedisKey.SMS_PRIFIX,phone,codeType+"");
......@@ -52,6 +75,6 @@ public class SmsController {
redisUtils.set(key,code,Constants.Duration.HALF_HOUR_INT);
boolean flag=smsUtils.sendMessage(phone,Constants.Sms.TemplateCode.LOGIN_SF_REGISTER,code);
return flag? ResultUtils.returnSuccess():ResultUtils.returnFail();
return (flag? ResultUtils.returnSuccess():ResultUtils.returnFail());
}
}
\ No newline at end of file
package cn.wisenergy.web.admin.controller.app;
import cn.wisenergy.common.utils.PageRequest;
import cn.wisenergy.common.utils.Result;
import cn.wisenergy.service.app.UploadService;
import io.swagger.annotations.Api;
......@@ -104,22 +105,37 @@ public class UploadController {
}
/**
* 资讯分页展示接口
* @param pageOffset
* @param pageSize
* @return
*/
@ApiOperation(value = "资讯信息接口", notes = "资讯信息接口", httpMethod = "GET", produces = "application/json; charset=UTF-8")
@ApiImplicitParams({
@ApiImplicitParam(name = "beginPos", value = "从几开始", required = true, dataType = "int"),
@ApiImplicitParam(name = "pageSize", value = "展示数量(条数)", required = true, dataType = "int")})
@RequestMapping(value = "/shop", method = {RequestMethod.POST, RequestMethod.GET})
public Result find(Integer beginPos, Integer pageSize) {
Map shopZxPage = uploadService.getList(beginPos, pageSize);
@GetMapping(value="/findByUserId")
public Object findByUserId(@RequestParam Long userId) {
return uploadService.findByUserId(userId);
}
@GetMapping(value="/findAll")
public Object findAll() {
return uploadService.findAll();
}
return new Result("0", "success", shopZxPage);
@ApiOperation(value = "资讯信息接口", notes = "资讯信息接口", httpMethod = "POST", produces = "application/json; charset=UTF-8")
@PostMapping(value="/findPage")
public Object findPage(@RequestBody PageRequest pageQuery) {
return uploadService.findPage(pageQuery);
}
// /**
// * 资讯分页展示接口
// * @param pageOffset
// * @param pageSize
// * @return
// */
// @ApiOperation(value = "资讯信息接口", notes = "资讯信息接口", httpMethod = "GET", produces = "application/json; charset=UTF-8")
// @ApiImplicitParams({
// @ApiImplicitParam(name = "beginPos", value = "从几开始", required = true, dataType = "int"),
// @ApiImplicitParam(name = "pageSize", value = "展示数量(条数)", required = true, dataType = "int")})
// @RequestMapping(value = "/shop", method = {RequestMethod.POST, RequestMethod.GET})
// public Result find(Integer beginPos, Integer pageSize) {
// Map shopZxPage = uploadService.getList(beginPos, pageSize);
//
// return new Result("0", "success", shopZxPage);
// }
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment