Bladeren bron

bug修复

renruixin 3 jaren geleden
bovenliggende
commit
50fe4c5a0f

+ 0 - 3
src/main/java/com/metro/entity/po/Account.java

@@ -79,9 +79,6 @@ public class Account {
      */
     @TableField(value = "create_time", fill = FieldFill.INSERT)
     private LocalDateTime createTime;
-    public void setCreateTime(LocalDateTime createTime) {
-        this.createTime = LocalDateTime.now();
-    }
     /*
     * 创建人
     * */

+ 1 - 3
src/main/java/com/metro/entity/po/Police.java

@@ -73,9 +73,7 @@ public class Police {
      */
     @TableField(value = "create_time", fill = FieldFill.INSERT)
     private LocalDateTime createTime;
-    public void setCreateTime(LocalDateTime createTime) {
-        this.createTime = LocalDateTime.now();
-    }
+
     /*
      * 创建人
      * */

+ 0 - 1
src/main/java/com/metro/entity/ro/Police/DetailPoliceResp.java

@@ -42,5 +42,4 @@ public class DetailPoliceResp {
     @ApiModelProperty(value = "修改时间")
     private LocalDateTime updateTime;
 
-
 }

+ 5 - 10
src/main/java/com/metro/entity/ro/Police/SelectPoliceLevelResp.java

@@ -23,27 +23,22 @@ import java.util.List;
 public class SelectPoliceLevelResp implements Serializable {
 
     @ApiModelProperty(value = "Id")
-    private Integer id;
-
-    @ApiModelProperty(value = "分局Id")
-    private String companyId;
+    private String id;
 
     @ApiModelProperty(value = "分局名称")
-    private String companyName;
+    private String name;
 
     @ApiModelProperty("派出所")
     private List<BranchList> branchList;
 
     @Data
+    @Accessors(chain = true)
     public static class BranchList implements Serializable {
 
         @ApiModelProperty(value = "Id")
-        private Integer id;
-
-        @ApiModelProperty(value = "派出所Id")
-        private String branchId;
+        private String id;
 
         @ApiModelProperty(value = "派出所名称")
-        private String branchName;
+        private String name;
     }
 }

+ 1 - 1
src/main/java/com/metro/entity/ro/Police/SelectPolicePageReq.java

@@ -22,7 +22,7 @@ import java.io.Serializable;
 public class SelectPolicePageReq extends BaseEntity implements Serializable {
 
     @ApiModelProperty("派出所名称")
-    private String companyId;
+    private String companyName;
 
     @ApiModelProperty("姓名")
     private String userName;

+ 6 - 0
src/main/java/com/metro/entity/ro/account/LoginAccountResp.java

@@ -33,6 +33,12 @@ public class LoginAccountResp {
     @ApiModelProperty("用户类型")
     private Integer type;
 
+    @ApiModelProperty("分局Id")
+    private String companyId;
+
+    @ApiModelProperty("派出所Id")
+    private String branchId;
+
     @ApiModelProperty(value = "token")
     private String token;
 

+ 0 - 2
src/main/java/com/metro/entity/ro/account/UpdateAccountReq.java

@@ -41,11 +41,9 @@ public class UpdateAccountReq implements Serializable {
     private String password;
 
     @ApiModelProperty(value = "部门Id")
-    @NotEmpty(message = "部门Id不能为空")
     private String companyId;
 
     @ApiModelProperty(value = "地区Id")
-    @NotNull(message = "请选择地区")
     private Integer areaId;
 
     @ApiModelProperty(value = "详细地址")

+ 27 - 15
src/main/java/com/metro/service/impl/AccountServiceImpl.java

@@ -10,6 +10,7 @@ import com.metro.constant.UserConstant;
 import com.metro.entity.model.UserOperateModel;
 import com.metro.entity.po.Account;
 import com.metro.entity.po.Area;
+import com.metro.entity.po.Company;
 import com.metro.entity.ro.account.*;
 import com.metro.exception.BusinessException;
 import com.metro.mapper.AccountsMapper;
@@ -77,8 +78,8 @@ public class AccountServiceImpl extends BaseService implements AccountService {
         Map<Integer, String> areaMap = areaMapper.selectList(new LambdaQueryWrapper<Area>().in(Area::getId, areaIdSet)).stream().collect(Collectors.toMap(Area::getId, p ->
                 Join.join("-", areaMapper.selectList(new LambdaQueryWrapper<Area>().in(Area::getId, StringUtils.split(p.getDistrictSqe(), ","))).stream().map(Area::getName).collect(Collectors.toList()))
         ));
-        return selectPage.convert(p -> MapperManager.mapper(p, SelectAccountPageResp.class, q ->{
-            if(getAccountInfo().getType()== 3 || getAccountInfo().getType()== 4){
+        return selectPage.convert(p -> MapperManager.mapper(p, SelectAccountPageResp.class, q -> {
+            if (getAccountInfo().getType() == 3 || getAccountInfo().getType() == 4) {
                 q.setCompanyId(companysMapper.selectById(p.getId()).getCompanyId());
                 q.setBranchId(p.getCompanyId());
             }
@@ -107,11 +108,14 @@ public class AccountServiceImpl extends BaseService implements AccountService {
         if (!StringUtil.isChinese(req.getUserName())) throw new BusinessException(UserConstant.NOT_CHINESE_USERNAME);
         Account account = accountsMapper.selectOne(new LambdaQueryWrapper<Account>().eq(Account::getAccount, req.getAccount()).eq(Account::getIsDelete, UserConstant.NOT_DELETE));
         if (ObjectUtil.isNotEmpty(account)) throw new BusinessException(account.getAccount() + "已经存在!不能注册");
-        return new InsertAccountResp().setCount(accountsMapper.insert(MapperManager.mapper(req, Account.class, p -> p.setPassword(MD5UtilNew.string2MD5(req.getPassword())).setType(getAccountInfo().getType()+1))));
+        return new InsertAccountResp().setCount(accountsMapper.insert(MapperManager.mapper(req, Account.class, p -> {
+            p.setPassword(MD5UtilNew.string2MD5(req.getPassword())).setCreateTime(LocalDateTime.now());
+            Integer type = getAccountInfo().getType();
+            if (type == BigDecimal.ROUND_CEILING) p.setType(type);
+            else p.setType(type + 1);
+        })));
     }
 
-
-
     /**
      * 校验账号是否存在
      *
@@ -165,9 +169,9 @@ public class AccountServiceImpl extends BaseService implements AccountService {
         String finalCityId = cityId;
         String finalprovinceId = provinceId;
         return MapperManager.mapper(account, DetailAccountResp.class, p -> {
-            if(getAccountInfo().getType()== 3 || getAccountInfo().getType()== 4){
-           p.setCompanyId(companysMapper.selectById(account.getId()).getCompanyId());
-           p.setBranchId(account.getCompanyId());
+            if (getAccountInfo().getType() == 3 || getAccountInfo().getType() == 4) {
+                p.setCompanyId(companysMapper.selectById(account.getId()).getCompanyId());
+                p.setBranchId(account.getCompanyId());
             }
             p.setAreaId(finalAreaId);
             p.setCityId(finalCityId);
@@ -184,10 +188,10 @@ public class AccountServiceImpl extends BaseService implements AccountService {
     @Override
     public UpdateAccountResp update(UpdateAccountReq req) {
         Integer id = getAccountInfo().getId();
-        return getUpdateAccountResp(req, accountsMapper,id);
+        return getUpdateAccountResp(req, accountsMapper, id);
     }
 
-    static UpdateAccountResp getUpdateAccountResp(UpdateAccountReq req, AccountsMapper accountsMapper,Integer id) {
+    static UpdateAccountResp getUpdateAccountResp(UpdateAccountReq req, AccountsMapper accountsMapper, Integer id) {
         if (!StringUtil.isChinese(req.getUserName())) throw new BusinessException(UserConstant.NOT_CHINESE_USERNAME);
         Account account = accountsMapper.selectOne(new LambdaQueryWrapper<Account>().eq(Account::getAccount, req.getAccount()).eq(Account::getIsDelete, UserConstant.NOT_DELETE));
         if (ObjectUtil.isEmpty(account)) throw new BusinessException(account.getAccount() + "不存在!不能修改");
@@ -267,11 +271,19 @@ public class AccountServiceImpl extends BaseService implements AccountService {
         if (ObjectUtil.isEmpty(account)) throw new BusinessException("账号不存在!请先注册");
         if (!MD5UtilNew.string2MD5(req.getPassword()).equals(account.getPassword()))
             throw new BusinessException("密码不对!请重新输入");
-        return MapperManager.mapper(account, LoginAccountResp.class, p -> p.setToken(JWTUtils.sign(account.getId().toString(), account.getPassword(), DateUtils.addDays(new Date(), 1))));
+        return MapperManager.mapper(account, LoginAccountResp.class, p -> {
+            p.setToken(JWTUtils.sign(account.getId().toString(), account.getPassword(), DateUtils.addDays(new Date(), 1)));
+            if (account.getType() == 3 || account.getType() == 4) {
+                Company company = companysMapper.selectById(account.getCompanyId());
+                p.setCompanyId(ObjectUtil.isNotEmpty(company) ? company.getCompanyId() : null);
+                p.setBranchId(account.getCompanyId());
+            } else if (account.getType() == 2) {
+                p.setCompanyId(account.getCompanyId());
+            }
+        });
     }
 
 
-
     /**
      * 获取用户信息
      *
@@ -287,12 +299,12 @@ public class AccountServiceImpl extends BaseService implements AccountService {
     /**
      * 导入用户数据
      *
-     * @param userList  用户数据列表
+     * @param userList 用户数据列表
      * @return 结果
      */
     @Override
     @Transactional
-    public String importUser(List<UserOperateModel> userList,String type) {
+    public String importUser(List<UserOperateModel> userList, String type) {
         if (CollectionUtils.isEmpty(userList)) {
             throw new ServiceException("导入用户数据不能为空!");
         }
@@ -310,7 +322,7 @@ public class AccountServiceImpl extends BaseService implements AccountService {
                     BeanValidators.validateWithException(validator, user);
                     successNum++;
                     Account mapper = MapperManager.mapper(user, Account.class, p -> {
-                        p.setPassword(MD5UtilNew.string2MD5(user.getPassword())).setAreaId(3230).setType(Integer.valueOf(type)).setCreateTime(LocalDateTime.now());
+                        p.setPassword(MD5UtilNew.string2MD5(user.getPassword())).setAreaId(getAccountInfo().getAreaId()).setType(Integer.valueOf(type)).setCreateTime(LocalDateTime.now());
                     });
                     accountsMapper.insert(mapper);
                     successMsg.append("<br/>" + successNum + "、账号 " + user.getAccount() + " 导入成功");

+ 29 - 21
src/main/java/com/metro/service/impl/PoliceServiceImpl.java

@@ -59,18 +59,25 @@ public class PoliceServiceImpl extends BaseService implements PoliceService {
     public IPage<SelectPolicePageResp> page(SelectPolicePageReq req) {
         Page<Company> companyPage = companysMapper.selectPage(new Page<>(req.getPageNum(), req.getPageSize()), pageWrapper(req));
         if (CollectionUtils.isEmpty(companyPage.getRecords())) return new Page<>();
+
         List<Account> accounts = accountsMapper.selectList(new LambdaQueryWrapper<Account>()
                 .like(StringUtils.isNotEmpty(req.getAddress()), Account::getAddress, req.getAddress())
                 .like(StringUtils.isNotEmpty(req.getUserName()), Account::getUserName, req.getUserName())
                 .like(StringUtils.isNotEmpty(req.getPhone()), Account::getPhone, req.getPhone())
-                .in(Account::getCompanyId, companyPage.getRecords().stream().map(Company::getCompanyId).collect(Collectors.toSet())));
+                .in(Account::getCompanyId,
+                        companysMapper.selectList(new LambdaQueryWrapper<Company>()
+                                .in(Company::getCompanyId, companyPage.getRecords().stream().map(Company::getCompanyId).collect(Collectors.toSet())))
+                                .stream().map(Company::getId).collect(Collectors.toSet())
+                ));
         if (CollectionUtils.isEmpty(accounts)) return new Page<>();
         Map<String, Account> collect = accounts.stream().collect(Collectors.toMap(Account::getCompanyId, p -> p, (t1, t2) -> t1));
         return companyPage.convert(p -> MapperManager.mapper(p, SelectPolicePageResp.class, q -> {
             q.setCompanyName(p.getBranchName()).setId(p.getId());
             if (!CollectionUtils.isEmpty(collect)) {
-                Account account = collect.get(p.getId()+"");
-                q.setCreateTime(account.getCreateTime()).setAddress(account.getAddress()).setPhone(account.getPhone()).setUserName(account.getUserName());
+                Account account = collect.get(p.getId() + "");
+                if (ObjectUtil.isNotEmpty(account)) {
+                    q.setCreateTime(account.getCreateTime()).setAddress(account.getAddress()).setPhone(account.getPhone()).setUserName(account.getUserName());
+                }
             }
         }));
     }
@@ -81,7 +88,7 @@ public class PoliceServiceImpl extends BaseService implements PoliceService {
     private LambdaQueryWrapper<Company> pageWrapper(SelectPolicePageReq req) {
         LambdaQueryWrapper<Company> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(Company::getCompanyId, getAccountInfo().getCompanyId());
-        wrapper.like(Company::getBranchName, req.getCompanyId());
+        wrapper.like(StringUtils.isNotEmpty(req.getCompanyName()), Company::getBranchName, req.getCompanyName());
         return wrapper;
     }
 
@@ -91,16 +98,17 @@ public class PoliceServiceImpl extends BaseService implements PoliceService {
     @Override
     @Transactional
     public InsertPoliceResp add(InsertPoliceReq req) {
-        if(getAccountInfo().getType() != 2) throw new BusinessException("非分局管理员不能注册");
+        if (getAccountInfo().getType() != 2) throw new BusinessException("非分局管理员不能注册");
         Police account = mapper.selectOne(new LambdaQueryWrapper<Police>().eq(Police::getAccount, req.getAccount()).eq(Police::getIsDelete, UserConstant.NOT_DELETE));
         if (ObjectUtil.isNotEmpty(account)) throw new BusinessException(account.getAccount() + "已经存在!不能注册");
-        int insert = mapper.insert(MapperManager.mapper(req, Police.class, p -> p.setPassword(MD5UtilNew.string2MD5(req.getPassword())).setType(getAccountInfo().setAreaId(getAccountInfo().getAreaId()).getType() + 1)));
-        if (insert == BigDecimal.ZERO.intValue()) throw new BusinessException("创建派出所管理员账号异常!");
         List<Company> companies = companysMapper.selectList(new LambdaQueryWrapper<Company>().eq(Company::getCompanyId, getAccountInfo().getCompanyId()).eq(Company::getBranchName, req.getBranchName()));
         if (!CollectionUtils.isEmpty(companies)) throw new BusinessException("派出所已经存在,请重新填写派所名");
         Company company = companysMapper.selectList(new LambdaQueryWrapper<Company>().eq(Company::getCompanyId, getAccountInfo().getCompanyId()).orderByDesc(Company::getBranchId)).stream().findFirst().orElse(null);
-        int insert1 = companysMapper.insert(company.setCompanyId(Integer.valueOf(company.getBranchId()) + 1 + "").setBranchName(req.getBranchName()));
+        int insert1 = companysMapper.insert(company.setBranchId(String.valueOf(Integer.valueOf(company.getBranchId()) + 1)).setCompanyId(getAccountInfo().getCompanyId()).setBranchName(req.getBranchName()));
         if (insert1 == BigDecimal.ZERO.intValue()) throw new BusinessException("创建派出所失败!");
+        int insert = mapper.insert(MapperManager.mapper(req, Police.class, p -> p.setPassword(MD5UtilNew.string2MD5(req.getPassword()))
+                .setCreateTime(LocalDateTime.now()).setCompanyId(company.getId() + "").setType(getAccountInfo().setAreaId(getAccountInfo().getAreaId()).getType() + 1)));
+        if (insert == BigDecimal.ZERO.intValue()) throw new BusinessException("创建派出所管理员账号异常!");
         return new InsertPoliceResp().setCount(insert + insert1);
     }
 
@@ -109,9 +117,9 @@ public class PoliceServiceImpl extends BaseService implements PoliceService {
      * */
     @Override
     public DetailPoliceResp detail(DetailPoliceReq req) {
-        if(getAccountInfo().getType() != 2) throw new BusinessException("非分局管理员不能修改!");
+        if (getAccountInfo().getType() != 2) throw new BusinessException("非分局管理员不能修改!");
         Company selectOne = companysMapper.selectOne(new LambdaQueryWrapper<Company>().eq(Company::getId, req.getId()));
-        if(ObjectUtils.isEmpty(selectOne)) throw new BusinessException("未获取到派出所信息");
+        if (ObjectUtils.isEmpty(selectOne)) throw new BusinessException("未获取到派出所信息");
         Police police = mapper.selectList(new LambdaQueryWrapper<Police>().eq(Police::getId, selectOne.getId()).eq(Police::getIsDelete, UserConstant.NOT_DELETE)).stream().findFirst().orElse(null);
         return MapperManager.mapper(police, DetailPoliceResp.class, p -> p.setBranchName(selectOne.getBranchName()));
     }
@@ -122,17 +130,17 @@ public class PoliceServiceImpl extends BaseService implements PoliceService {
     @Override
     @Transactional
     public UpdatePoliceResp update(UpdatePoliceReq req) {
-        if(getAccountInfo().getType() != 2) throw new BusinessException("非分局管理员不能修改!");
+        if (getAccountInfo().getType() != 2) throw new BusinessException("非分局管理员不能修改!");
         Police account = mapper.selectOne(new LambdaQueryWrapper<Police>().eq(Police::getAccount, req.getAccount()).eq(Police::getIsDelete, UserConstant.NOT_DELETE));
         if (ObjectUtil.isEmpty(account)) throw new BusinessException(account.getAccount() + "不存在!不能修改");
-        int insert = mapper.update(MapperManager.mapper(req, Police.class, p -> p.setPassword(MD5UtilNew.string2MD5(req.getPassword())).setUpdateTime(LocalDateTime.now())),new LambdaQueryWrapper<Police>().eq(Police::getAccount,account.getAccount())
-                .eq(Police::getIsDelete,UserConstant.NOT_DELETE));
+        int insert = mapper.update(MapperManager.mapper(req, Police.class, p -> p.setPassword(MD5UtilNew.string2MD5(req.getPassword())).setUpdateTime(LocalDateTime.now())), new LambdaQueryWrapper<Police>().eq(Police::getAccount, account.getAccount())
+                .eq(Police::getIsDelete, UserConstant.NOT_DELETE));
         if (insert == BigDecimal.ZERO.intValue()) throw new BusinessException("修改派出所管理员账号异常!");
-        Company selectOne = companysMapper.selectOne(new LambdaQueryWrapper<Company>().eq(Company::getId, req.getId()).ne(Company::getBranchName,req.getBranchName()));
+        Company selectOne = companysMapper.selectOne(new LambdaQueryWrapper<Company>().eq(Company::getId, req.getId()).ne(Company::getBranchName, req.getBranchName()));
         if (ObjectUtils.isEmpty(selectOne)) throw new BusinessException("派出所已经存在,请重新填写派所名");
         int insert1 = companysMapper.updateById(new Company().setBranchName(req.getBranchName()).setId(req.getId()));
         if (insert1 == BigDecimal.ZERO.intValue()) throw new BusinessException("修改派出所失败!");
-        return new UpdatePoliceResp().setCount(insert+insert1);
+        return new UpdatePoliceResp().setCount(insert + insert1);
     }
 
     /*
@@ -141,11 +149,11 @@ public class PoliceServiceImpl extends BaseService implements PoliceService {
     @Override
     @Transactional
     public DeleteAccountResp delete(DeleteAccountReq req) {
-        if(getAccountInfo().getType() != 2) throw new BusinessException("非分局管理员不能删除!");
+        if (getAccountInfo().getType() != 2) throw new BusinessException("非分局管理员不能删除!");
         Company selectOne = companysMapper.selectOne(new LambdaQueryWrapper<Company>().eq(Company::getId, req.getId()));
-        if(ObjectUtils.isEmpty(selectOne)) throw new BusinessException("未获取到派出所信息");
+        if (ObjectUtils.isEmpty(selectOne)) throw new BusinessException("未获取到派出所信息");
         List<Police> police = mapper.selectList(new LambdaQueryWrapper<Police>().eq(Police::getId, selectOne.getId()).eq(Police::getIsDelete, UserConstant.NOT_DELETE));
-        if(CollectionUtils.isEmpty(police)) throw new BusinessException("派出所下有用户,不能删除");
+        if (CollectionUtils.isEmpty(police)) throw new BusinessException("派出所下有用户,不能删除");
         return new DeleteAccountResp().setCount(companysMapper.deleteById(req.getId()));
     }
 
@@ -161,14 +169,14 @@ public class PoliceServiceImpl extends BaseService implements PoliceService {
         if (CollectionUtils.isEmpty(companies)) return Lists.newArrayList();
         ArrayList<Company> companyList = companies.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Company::getCompanyId))), ArrayList::new));
         if (!req.getIsQueryBranch()) {
-            return companyList.stream().map(p -> MapperManager.mapper(p, SelectPoliceLevelResp.class)).collect(Collectors.toList());
+            return companyList.stream().map(p -> MapperManager.mapper(p, SelectPoliceLevelResp.class, q -> q.setId(p.getCompanyId()).setName(p.getCompanyName()))).collect(Collectors.toList());
         }
         return companyList.stream().map(p -> MapperManager.mapper(p, SelectPoliceLevelResp.class, q -> {
             List<Company> selectList = companysMapper.selectList(new LambdaQueryWrapper<Company>().eq(Company::getCompanyId, p.getCompanyId())
                     .eq(StringUtils.isNotEmpty(req.getBranchId()), Company::getId, req.getBranchId()));
             if (!CollectionUtils.isEmpty(selectList)) {
-                q.setBranchList(selectList.stream().map(
-                        t -> MapperManager.mapper(t, SelectPoliceLevelResp.BranchList.class)
+                q.setId(p.getCompanyId()).setName(p.getCompanyName()).setBranchList(selectList.stream().map(
+                        t -> MapperManager.mapper(t, SelectPoliceLevelResp.BranchList.class, m -> m.setId(t.getBranchId()).setName(t.getBranchName()))
                 ).collect(Collectors.toList()));
             }
         })).collect(Collectors.toList());