10 changed files with 525 additions and 7 deletions
@ -0,0 +1,139 @@ |
|||
/** |
|||
* Copyright 2018 人人开源 https://www.renren.io
|
|||
* <p> |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* <p> |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* <p> |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.controller; |
|||
|
|||
import com.elink.esua.epdc.commons.tools.enums.BehaviorEnum; |
|||
import com.elink.esua.epdc.commons.tools.page.PageData; |
|||
import com.elink.esua.epdc.commons.tools.utils.Result; |
|||
import com.elink.esua.epdc.commons.tools.validator.AssertUtils; |
|||
import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils; |
|||
import com.elink.esua.epdc.commons.tools.validator.group.AddGroup; |
|||
import com.elink.esua.epdc.commons.tools.validator.group.DefaultGroup; |
|||
import com.elink.esua.epdc.commons.tools.validator.group.UpdateGroup; |
|||
import com.elink.esua.epdc.dto.UserSignDTO; |
|||
import com.elink.esua.epdc.pointcommons.tools.annotation.RecordUserBehavior; |
|||
import com.elink.esua.epdc.service.UserService; |
|||
import com.elink.esua.epdc.service.UserSignService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.Map; |
|||
|
|||
|
|||
/** |
|||
* 用户签到表 |
|||
* |
|||
* @author qu qu@elink-cn.com |
|||
* @since v1.0.0 2020-07-21 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("usersign") |
|||
public class UserSignController { |
|||
|
|||
@Autowired |
|||
private UserSignService userSignService; |
|||
|
|||
@Autowired |
|||
private UserService userService; |
|||
|
|||
@GetMapping("page") |
|||
public Result<PageData<UserSignDTO>> page(@RequestParam Map<String, Object> params){ |
|||
PageData<UserSignDTO> page = userSignService.page(params); |
|||
return new Result<PageData<UserSignDTO>>().ok(page); |
|||
} |
|||
|
|||
@GetMapping("{id}") |
|||
public Result<UserSignDTO> get(@PathVariable("id") String id){ |
|||
UserSignDTO data = userSignService.get(id); |
|||
return new Result<UserSignDTO>().ok(data); |
|||
} |
|||
|
|||
@PostMapping |
|||
public Result save(@RequestBody UserSignDTO dto){ |
|||
//效验数据
|
|||
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); |
|||
userSignService.save(dto); |
|||
return new Result(); |
|||
} |
|||
|
|||
@PutMapping |
|||
public Result update(@RequestBody UserSignDTO dto){ |
|||
//效验数据
|
|||
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); |
|||
userSignService.update(dto); |
|||
return new Result(); |
|||
} |
|||
|
|||
@DeleteMapping |
|||
public Result delete(@RequestBody String[] ids){ |
|||
//效验数据
|
|||
AssertUtils.isArrayEmpty(ids, "id"); |
|||
userSignService.delete(ids); |
|||
return new Result(); |
|||
} |
|||
|
|||
/** |
|||
* @Description 根据用户ID获取用户签到信息 |
|||
* @Author zy |
|||
* @Date 2020/7/21 |
|||
* @Param [userId] |
|||
* @return com.elink.esua.epdc.commons.tools.utils.Result<com.elink.esua.epdc.dto.UserSignDTO> |
|||
**/ |
|||
@GetMapping("getUserSignInfoByUserId/{userId}") |
|||
public Result<UserSignDTO> getUserSignInfoByUserId(@PathVariable("userId") String userId){ |
|||
return new Result<UserSignDTO>().ok(userSignService.getUserSignInfoByUserId(userId)); |
|||
} |
|||
/** |
|||
* @Description 更新或新增签到时间和连续签到次数 |
|||
* @Author zy |
|||
* @Date 2020/7/21 |
|||
* @Param [userSignDTO] |
|||
* @return com.elink.esua.epdc.commons.tools.utils.Result |
|||
**/ |
|||
@GetMapping("saveOrUpdateSignById") |
|||
public Result saveOrUpdateSignById(@RequestBody UserSignDTO userSignDTO){ |
|||
return userSignService.saveOrUpdateSignById(userSignDTO); |
|||
} |
|||
|
|||
/** |
|||
* @Description 签到加积分操作 |
|||
* @Author zy |
|||
* @Date 2020/7/21 |
|||
* @Param [userSignDTO] |
|||
**/ |
|||
@GetMapping("addSignPoints") |
|||
@RecordUserBehavior(behavior = BehaviorEnum.USER_SIGN,referenceId = "#{userSignDTO.getId}",userId = "#{userSignDTO.getUserId}",gridId = "#{userSignDTO.getGridId}") |
|||
public Result addSignPoints(@RequestBody UserSignDTO userSignDTO){ |
|||
Result<Long> userGridIdByUserId = userService.getUserGridIdByUserId(userSignDTO.getUserId()); |
|||
userSignDTO.setGridId(userGridIdByUserId.getData()); |
|||
return new Result(); |
|||
} |
|||
/** |
|||
* @Description 连续签到加积分 |
|||
* @Author zy |
|||
* @Date 2020/7/21 |
|||
* @Param [userSignDTO] |
|||
**/ |
|||
@GetMapping("addConsequentSignPoints") |
|||
@RecordUserBehavior(behavior = BehaviorEnum.USER_CONSEQUENT_SIGN,referenceId = "#{userSignDTO.getId}",userId = "#{userSignDTO.getUserId}",gridId = "#{userSignDTO.getGridId}") |
|||
public Result addConsequentSignPoints(@RequestBody UserSignDTO userSignDTO){ |
|||
Result<Long> userGridIdByUserId = userService.getUserGridIdByUserId(userSignDTO.getUserId()); |
|||
userSignDTO.setGridId(userGridIdByUserId.getData()); |
|||
return new Result(); |
|||
} |
|||
} |
@ -0,0 +1,41 @@ |
|||
/** |
|||
* Copyright 2018 人人开源 https://www.renren.io
|
|||
* <p> |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* <p> |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* <p> |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.dao; |
|||
|
|||
import com.elink.esua.epdc.commons.mybatis.dao.BaseDao; |
|||
import com.elink.esua.epdc.dto.UserSignDTO; |
|||
import com.elink.esua.epdc.entity.UserSignEntity; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
/** |
|||
* 用户签到表 |
|||
* |
|||
* @author qu qu@elink-cn.com |
|||
* @since v1.0.0 2020-07-21 |
|||
*/ |
|||
@Mapper |
|||
public interface UserSignDao extends BaseDao<UserSignEntity> { |
|||
/** |
|||
* @Description 根据用户ID获取用户签到信息 |
|||
* @Author zy |
|||
* @Date 2020/7/21 |
|||
* @Param [userId] |
|||
* @return com.elink.esua.epdc.dto.UserSignDTO |
|||
**/ |
|||
UserSignDTO selectUserSignInfoByUserId(String userId); |
|||
} |
@ -0,0 +1,55 @@ |
|||
/** |
|||
* Copyright 2018 人人开源 https://www.renren.io
|
|||
* <p> |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* <p> |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* <p> |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import com.elink.esua.epdc.commons.mybatis.entity.BaseEpdcEntity; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 用户签到表 |
|||
* |
|||
* @author qu qu@elink-cn.com |
|||
* @since v1.0.0 2020-07-21 |
|||
*/ |
|||
@Data |
|||
@EqualsAndHashCode(callSuper=false) |
|||
@TableName("epdc_user_sign") |
|||
public class UserSignEntity extends BaseEpdcEntity { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* 用户ID |
|||
*/ |
|||
private String userId; |
|||
|
|||
/** |
|||
* 连续签到天数 |
|||
*/ |
|||
private Integer consequentSignDays; |
|||
|
|||
/** |
|||
* 最近签到时间 |
|||
*/ |
|||
private Date lastSignTime; |
|||
|
|||
} |
@ -0,0 +1,112 @@ |
|||
/** |
|||
* Copyright 2018 人人开源 https://www.renren.io
|
|||
* <p> |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* <p> |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* <p> |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.service; |
|||
|
|||
import com.elink.esua.epdc.commons.mybatis.service.BaseService; |
|||
import com.elink.esua.epdc.commons.tools.page.PageData; |
|||
import com.elink.esua.epdc.commons.tools.utils.Result; |
|||
import com.elink.esua.epdc.dto.UserSignDTO; |
|||
import com.elink.esua.epdc.entity.UserSignEntity; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 用户签到表 |
|||
* |
|||
* @author qu qu@elink-cn.com |
|||
* @since v1.0.0 2020-07-21 |
|||
*/ |
|||
public interface UserSignService extends BaseService<UserSignEntity> { |
|||
|
|||
/** |
|||
* 默认分页 |
|||
* |
|||
* @param params |
|||
* @return PageData<UserSignDTO> |
|||
* @author generator |
|||
* @date 2020-07-21 |
|||
*/ |
|||
PageData<UserSignDTO> page(Map<String, Object> params); |
|||
|
|||
/** |
|||
* 默认查询 |
|||
* |
|||
* @param params |
|||
* @return java.util.List<UserSignDTO> |
|||
* @author generator |
|||
* @date 2020-07-21 |
|||
*/ |
|||
List<UserSignDTO> list(Map<String, Object> params); |
|||
|
|||
/** |
|||
* 单条查询 |
|||
* |
|||
* @param id |
|||
* @return UserSignDTO |
|||
* @author generator |
|||
* @date 2020-07-21 |
|||
*/ |
|||
UserSignDTO get(String id); |
|||
|
|||
/** |
|||
* 默认保存 |
|||
* |
|||
* @param dto |
|||
* @return void |
|||
* @author generator |
|||
* @date 2020-07-21 |
|||
*/ |
|||
void save(UserSignDTO dto); |
|||
|
|||
/** |
|||
* 默认更新 |
|||
* |
|||
* @param dto |
|||
* @return void |
|||
* @author generator |
|||
* @date 2020-07-21 |
|||
*/ |
|||
void update(UserSignDTO dto); |
|||
|
|||
/** |
|||
* 批量删除 |
|||
* |
|||
* @param ids |
|||
* @return void |
|||
* @author generator |
|||
* @date 2020-07-21 |
|||
*/ |
|||
void delete(String[] ids); |
|||
/** |
|||
* @Description 根据用户ID获取用户签到信息 |
|||
* @Author zy |
|||
* @Date 2020/7/21 |
|||
* @Param [userId] |
|||
* @return com.elink.esua.epdc.dto.UserSignDTO |
|||
**/ |
|||
UserSignDTO getUserSignInfoByUserId(String userId); |
|||
/** |
|||
* @Description 更新签到时间和连续签到次数 |
|||
* @Author zy |
|||
* @Date 2020/7/21 |
|||
* @Param [userSignDTO] |
|||
* @return void |
|||
**/ |
|||
Result saveOrUpdateSignById(UserSignDTO userSignDTO); |
|||
} |
@ -0,0 +1,118 @@ |
|||
/** |
|||
* Copyright 2018 人人开源 https://www.renren.io
|
|||
* <p> |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* <p> |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* <p> |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|||
import com.elink.esua.epdc.commons.tools.constant.FieldConstant; |
|||
import com.elink.esua.epdc.commons.tools.page.PageData; |
|||
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; |
|||
import com.elink.esua.epdc.commons.tools.utils.Result; |
|||
import com.elink.esua.epdc.dao.UserSignDao; |
|||
import com.elink.esua.epdc.dto.UserSignDTO; |
|||
import com.elink.esua.epdc.entity.UserSignEntity; |
|||
import com.elink.esua.epdc.service.UserSignService; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 用户签到表 |
|||
* |
|||
* @author qu qu@elink-cn.com |
|||
* @since v1.0.0 2020-07-21 |
|||
*/ |
|||
@Service |
|||
public class UserSignServiceImpl extends BaseServiceImpl<UserSignDao, UserSignEntity> implements UserSignService { |
|||
|
|||
@Override |
|||
public PageData<UserSignDTO> page(Map<String, Object> params) { |
|||
IPage<UserSignEntity> page = baseDao.selectPage( |
|||
getPage(params, FieldConstant.CREATED_TIME, false), |
|||
getWrapper(params) |
|||
); |
|||
return getPageData(page, UserSignDTO.class); |
|||
} |
|||
|
|||
@Override |
|||
public List<UserSignDTO> list(Map<String, Object> params) { |
|||
List<UserSignEntity> entityList = baseDao.selectList(getWrapper(params)); |
|||
|
|||
return ConvertUtils.sourceToTarget(entityList, UserSignDTO.class); |
|||
} |
|||
|
|||
private QueryWrapper<UserSignEntity> getWrapper(Map<String, Object> params){ |
|||
String id = (String)params.get(FieldConstant.ID_HUMP); |
|||
|
|||
QueryWrapper<UserSignEntity> wrapper = new QueryWrapper<>(); |
|||
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); |
|||
|
|||
return wrapper; |
|||
} |
|||
|
|||
@Override |
|||
public UserSignDTO get(String id) { |
|||
UserSignEntity entity = baseDao.selectById(id); |
|||
return ConvertUtils.sourceToTarget(entity, UserSignDTO.class); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public void save(UserSignDTO dto) { |
|||
UserSignEntity entity = ConvertUtils.sourceToTarget(dto, UserSignEntity.class); |
|||
insert(entity); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public void update(UserSignDTO dto) { |
|||
UserSignEntity entity = ConvertUtils.sourceToTarget(dto, UserSignEntity.class); |
|||
updateById(entity); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public void delete(String[] ids) { |
|||
// 逻辑删除(@TableLogic 注解)
|
|||
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|||
} |
|||
|
|||
@Override |
|||
public UserSignDTO getUserSignInfoByUserId(String userId) { |
|||
return baseDao.selectUserSignInfoByUserId(userId); |
|||
} |
|||
|
|||
@Override |
|||
public Result saveOrUpdateSignById(UserSignDTO userSignDTO) { |
|||
UserSignEntity entity = ConvertUtils.sourceToTarget(userSignDTO, UserSignEntity.class); |
|||
if(StringUtils.isNotBlank(entity.getId())){ |
|||
updateById(entity); |
|||
return new Result(); |
|||
} else { |
|||
insert(entity); |
|||
return new Result().ok(entity.getId()); |
|||
} |
|||
} |
|||
|
|||
} |
@ -0,0 +1,23 @@ |
|||
<?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.elink.esua.epdc.dao.UserSignDao"> |
|||
|
|||
<resultMap type="com.elink.esua.epdc.entity.UserSignEntity" id="userSignMap"> |
|||
<result property="id" column="ID"/> |
|||
<result property="userId" column="USER_ID"/> |
|||
<result property="consequentSignDays" column="CONSEQUENT_SIGN_DAYS"/> |
|||
<result property="lastSignTime" column="LAST_SIGN_TIME"/> |
|||
<result property="delFlag" column="DEL_FLAG"/> |
|||
<result property="revision" column="REVISION"/> |
|||
<result property="createdBy" column="CREATED_BY"/> |
|||
<result property="createdTime" column="CREATED_TIME"/> |
|||
<result property="updatedBy" column="UPDATED_BY"/> |
|||
<result property="updatedTime" column="UPDATED_TIME"/> |
|||
</resultMap> |
|||
<select id="selectUserSignInfoByUserId" resultType="com.elink.esua.epdc.dto.UserSignDTO"> |
|||
select ID,USER_ID,CONSEQUENT_SIGN_DAYS,LAST_SIGN_TIME from epdc_user_sign where DEL_FLAG = '0' and USER_ID = #{userId} |
|||
</select> |
|||
|
|||
|
|||
</mapper> |
Loading…
Reference in new issue