New file |
| | |
| | | package com.panzhihua.service_community.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.panzhihua.service_community.dao.SysUserMapper; |
| | | import com.panzhihua.service_community.entity.ComBatteryStore; |
| | | import com.panzhihua.service_community.dao.ComBatteryStoreMapper; |
| | | import com.panzhihua.service_community.entity.SysUser; |
| | | import com.panzhihua.service_community.service.ComBatteryStoreService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springframework.beans.BeanUtils; |
| | | import com.panzhihua.common.model.dtos.common.*; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
| | | import org.springframework.stereotype.Service; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * title: 电动车商城-商家表表服务实现类 |
| | | * <p> |
| | | * projectName 成都呐喊信息技术有限公司-智慧社区项目 |
| | | * <p> |
| | | * description: 电动车商城-商家表表服务实现类 |
| | | * |
| | | * @author lyq |
| | | * @date 2022-03-28 13:44:45 |
| | | */ |
| | | @Service("comBatteryStoreService") |
| | | public class ComBatteryStoreServiceImpl extends ServiceImpl<ComBatteryStoreMapper, ComBatteryStore> implements ComBatteryStoreService { |
| | | |
| | | @Resource |
| | | private SysUserMapper userDao; |
| | | |
| | | /** |
| | | * description queryByPage 分页查询 |
| | | * |
| | | * @param comBatteryStore 请求参数 |
| | | * @return 分页查询列表数据 |
| | | * @author lyq |
| | | * @date 2022-03-28 13:44:45 |
| | | */ |
| | | @Override |
| | | public R queryByPage(PageComBatteryStoreDto comBatteryStore) { |
| | | return R.ok(this.baseMapper.queryAllByLimit(comBatteryStore, new Page(comBatteryStore.getPageNum(), comBatteryStore.getPageSize()))); |
| | | } |
| | | |
| | | /** |
| | | * description insert 新增数据 |
| | | * |
| | | * @param comBatteryStore 请求参数 |
| | | * @return 新增结果 |
| | | * @author lyq |
| | | * @date 2022-03-28 13:44:45 |
| | | */ |
| | | @Override |
| | | public R insert(AddComBatteryStoreDto comBatteryStore) { |
| | | ComBatteryStore entity = new ComBatteryStore(); |
| | | BeanUtils.copyProperties(comBatteryStore, entity); |
| | | Integer storeAccountCount = this.baseMapper.getStoreUserCountByAccount(comBatteryStore.getAccount()); |
| | | if(storeAccountCount > 0){ |
| | | return R.fail("该账号已存在"); |
| | | } |
| | | Integer storePhoneCount = this.baseMapper.getStoreUserCountByPhone(comBatteryStore.getAccount()); |
| | | if(storePhoneCount > 0){ |
| | | return R.fail("该手机号已注册,不可重复注册"); |
| | | } |
| | | if (this.baseMapper.insert(entity) > 0) { |
| | | //新增电动车商城商家账号 |
| | | SysUser sysUser = new SysUser(); |
| | | sysUser.setType(20); |
| | | sysUser.setStatus(SysUser.Status.YES); |
| | | sysUser.setAccount(comBatteryStore.getAccount()); |
| | | String encode = new BCryptPasswordEncoder().encode(comBatteryStore.getPassword()); |
| | | sysUser.setPassword(encode); |
| | | sysUser.setPhone(comBatteryStore.getRegPhone()); |
| | | sysUser.setName(comBatteryStore.getName() + "管理员"); |
| | | sysUser.setPlaintextPassword(comBatteryStore.getPassword()); |
| | | sysUser.setCommunityId(entity.getId()); |
| | | userDao.insert(sysUser); |
| | | return R.ok(); |
| | | } |
| | | return R.fail("添加失败"); |
| | | } |
| | | |
| | | /** |
| | | * description update 修改数据 |
| | | * |
| | | * @param editDto 请求参数 |
| | | * @return 修改结果 |
| | | * @author lyq |
| | | * @date 2022-03-28 13:44:45 |
| | | */ |
| | | @Override |
| | | public R update(EditComBatteryStoreDto editDto) { |
| | | ComBatteryStore entity = this.baseMapper.selectById(editDto.getId()); |
| | | if (entity == null) { |
| | | return R.fail("未查询到该记录"); |
| | | } |
| | | BeanUtils.copyProperties(editDto, entity); |
| | | //注册手机不可修改 |
| | | entity.setRegPhone(null); |
| | | if (this.baseMapper.updateById(entity) > 0) { |
| | | return R.ok(); |
| | | } |
| | | return R.fail("修改失败"); |
| | | } |
| | | |
| | | /** |
| | | * description deleteById 通过主键删除数据 |
| | | * |
| | | * @param id 主键id |
| | | * @return 删除结果 |
| | | * @author lyq |
| | | * @date 2022-03-28 13:44:45 |
| | | */ |
| | | @Override |
| | | public R deleteById(Long id) { |
| | | ComBatteryStore entity = new ComBatteryStore(); |
| | | entity.setId(id); |
| | | entity.setIsDel(ComBatteryStore.IsDel.YES); |
| | | if (this.baseMapper.updateById(entity) > 0) { |
| | | //同时删除账号 |
| | | this.baseMapper.deleteStoreUserByStoreId(id); |
| | | return R.ok(); |
| | | } |
| | | return R.fail("删除失败"); |
| | | } |
| | | |
| | | /** |
| | | * description detailById 查询详情 |
| | | * |
| | | * @param id 主键id |
| | | * @return 详情数据 |
| | | * @author lyq |
| | | * @date 2022-03-28 13:44:45 |
| | | */ |
| | | @Override |
| | | public R detailById(Long id) { |
| | | return R.ok(this.baseMapper.queryById(id)); |
| | | } |
| | | |
| | | /** |
| | | * description queryByPage 查询列表 |
| | | * |
| | | * @param comBatteryStore 请求参数 |
| | | * @return 列表数据 |
| | | * @author lyq |
| | | * @date 2022-03-28 13:44:45 |
| | | */ |
| | | @Override |
| | | public R queryByList(PageComBatteryStoreDto comBatteryStore) { |
| | | return R.ok(this.baseMapper.queryAllByList(comBatteryStore)); |
| | | } |
| | | |
| | | /** |
| | | * 修改人员密码 |
| | | * @param storeId 商户id |
| | | * @param passWord 用户需要修改的密码 |
| | | * @return 重置密码结果 |
| | | */ |
| | | @Override |
| | | public R resetPassword(Long storeId, String passWord) { |
| | | String encode = new BCryptPasswordEncoder().encode(passWord); |
| | | int update = userDao.updatePassWord(storeId,passWord,encode); |
| | | if (update > 0) { |
| | | ComBatteryStore entity = new ComBatteryStore(); |
| | | entity.setId(storeId); |
| | | entity.setPassword(passWord); |
| | | this.baseMapper.updateById(entity); |
| | | return R.ok(); |
| | | } |
| | | return R.fail(); |
| | | } |
| | | } |