| | |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.doumee.biz.system.SystemDictBiz; |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | |
| | | import com.doumee.dao.business.join.CompanyJoinMapper; |
| | | import com.doumee.dao.business.model.Company; |
| | | import com.doumee.dao.business.model.dto.CompanyCreatOrUpdateRequest; |
| | | import com.doumee.dao.system.SystemDictMapper; |
| | | import com.doumee.dao.system.SystemUserMapper; |
| | | import com.doumee.dao.system.SystemUserRoleMapper; |
| | | import com.doumee.dao.system.model.SystemDict; |
| | | import com.doumee.dao.system.model.SystemDictData; |
| | | import com.doumee.dao.system.model.SystemUser; |
| | | import com.doumee.dao.system.model.SystemUserRole; |
| | | import com.doumee.service.business.CompanyService; |
| | | import com.doumee.service.system.SystemDictService; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import org.apache.commons.lang3.RandomStringUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | @Override |
| | | public Integer create(CompanyCreatOrUpdateRequest company) { |
| | | LoginUserInfo userInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | Company insert = new Company(); |
| | | |
| | | if (Objects.isNull(company.getManagerId())){ |
| | | if (StringUtils.isBlank(company.getManagerUserName())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"登录账号不允许为空"); |
| | | } |
| | | if (Objects.isNull(company.getOepnValidDate())){ |
| | |
| | | if (Objects.isNull(company.getUserNum())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"主播账号数量不允许为空"); |
| | | } |
| | | QueryWrapper<Company> wrapper = new QueryWrapper<>(); |
| | | wrapper.lambda() |
| | | .eq(Company::getDeleted,Boolean.FALSE) |
| | | .eq(Company::getName,company.getName()); |
| | | |
| | | Company company1 = companyMapper.selectOne(wrapper); |
| | | if (Objects.nonNull(company1)){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"企业已存在请重新输入"); |
| | | } |
| | | if(StringUtils.isNotBlank(company.getCreditCode())){ |
| | | wrapper.clear(); |
| | | wrapper.lambda() |
| | | .eq(Company::getDeleted,Boolean.FALSE) |
| | | .eq(Company::getCreditCode,company.getCreditCode()); |
| | | Company company2 = companyMapper.selectOne(wrapper); |
| | | if (Objects.nonNull(company2)){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"企业统一社会信用代码已存在请重新输入"); |
| | | } |
| | | } |
| | | Company insert = new Company(); |
| | | insert.setDeleted((byte)Constants.ZERO); |
| | | insert.setCreateUser(userInfo.getId()); |
| | | insert.setCreateTime(new Date()); |
| | |
| | | insert.setName(company.getName()); |
| | | insert.setShortName(company.getShortName()); |
| | | insert.setRemark(company.getRemark()); |
| | | insert.setManagerId(company.getManagerId()); |
| | | // insert.setManagerId(company.getManagerId()); |
| | | insert.setLinkname(company.getLinkname()); |
| | | insert.setLinkephone(company.getLinkephone()); |
| | | insert.setCreditCode(company.getCreditCode()); |
| | |
| | | insert.setOepnValidDate(company.getOepnValidDate()); |
| | | insert.setOepnType(company.getOepnType()); |
| | | insert.setSalesmanId(company.getSalesmanId()); |
| | | insert.setStatus(Constants.ZERO); |
| | | companyMapper.insert(insert); |
| | | |
| | | UpdateWrapper<SystemUser> systemUserQuery = new UpdateWrapper<>(); |
| | | systemUserQuery.lambda() |
| | | .eq(SystemUser::getId,company.getManagerId()) |
| | | .set(SystemUser::getCompanyId,insert.getId()); |
| | | systemUserMapper.update(null,systemUserQuery); |
| | | |
| | | //创建企业用户 |
| | | SystemUser companyUser = createCompanyUser(company, insert.getId()); |
| | | Company update = new Company(); |
| | | update.setId(insert.getId()); |
| | | update.setManagerId(companyUser.getId()); |
| | | companyMapper.updateById(update); |
| | | |
| | | SystemDictData dictData = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.COMPANY_MANAGE_ROLE); |
| | | |
| | | SystemUserRole systemUserRole = new SystemUserRole(); |
| | | systemUserRole.setUserId(company.getManagerId()); |
| | | systemUserRole.setUserId(companyUser.getId()); |
| | | systemUserRole.setRoleId(Integer.valueOf(dictData.getCode())); |
| | | systemUserRole.setCreateTime(new Date()); |
| | | systemUserRole.setUpdateTime(new Date()); |
| | | systemUserRole.setCreateUser(userInfo.getId()); |
| | | systemUserRole.setUpdateUser(userInfo.getId()); |
| | | systemUserRole.setDeleted(Boolean.FALSE); |
| | | |
| | | systemUserRoleMapper.insert(systemUserRole); |
| | | return company.getId(); |
| | | } |
| | | |
| | | private SystemUser createCompanyUser(CompanyCreatOrUpdateRequest company, Integer companyId){ |
| | | |
| | | QueryWrapper<SystemUser> query = new QueryWrapper<>(); |
| | | query.lambda() |
| | | .eq(SystemUser::getType,Constants.ONE) |
| | | .eq(SystemUser::getDeleted,Boolean.FALSE) |
| | | .eq(SystemUser::getUsername,company.getManagerUserName()); |
| | | Integer integer = systemUserMapper.selectCount(query); |
| | | if (integer > Constants.ZERO){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"账号已存在请重新输入账号"); |
| | | } |
| | | |
| | | LoginUserInfo userInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | SystemDictData dictDataPassword = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.DEFAULT_PASSWORD); |
| | | String salt = RandomStringUtils.randomAlphabetic(6); |
| | | SystemUser user = new SystemUser(); |
| | | user.setUsername(company.getManagerUserName()); |
| | | user.setPassword(Utils.Secure.encryptPassword(dictDataPassword.getCode(), salt)); |
| | | user.setSalt(salt); |
| | | user.setCompanyId(companyId); |
| | | user.setMobile(company.getLinkephone()); |
| | | user.setRealname(company.getLinkname()); |
| | | user.setType(Constants.ONE); |
| | | user.setCreateTime(new Date()); |
| | | user.setUpdateTime(new Date()); |
| | | user.setCreateUser(userInfo.getId()); |
| | | user.setUpdateUser(userInfo.getId()); |
| | | user.setDeleted(Boolean.FALSE); |
| | | user.setStatus(Constants.ZERO); |
| | | systemUserMapper.insert(user); |
| | | return user; |
| | | } |
| | | |
| | | @Override |
| | |
| | | .set(Company::getShortName,company.getShortName()) |
| | | .set(Company::getCreditCode,company.getCreditCode()) |
| | | .set(Company::getSalesmanId,company.getSalesmanId()) |
| | | .set(company.getOepnValidDate()!=null,Company::getOepnValidDate,company.getOepnValidDate()) |
| | | .set(company.getUserNum()!=null,Company::getUserNum,company.getUserNum()) |
| | | .set(Company::getLinkname,company.getLinkname()) |
| | | .set(Company::getLinkephone,company.getLinkephone()); |
| | | companyMapper.update(null,wrapper); |
| | |
| | | queryWrapper.selectAll(Company.class) |
| | | .selectAs(SystemUser::getUsername,Company::getManagerUserName); |
| | | queryWrapper.select( |
| | | "(select su1.USERNAME from system_user su1 where su1.id = t.MANAGER_ID) as managerUserName," + |
| | | "(select su1.USERNAME from system_user su1 where su1.id = t.MANAGER_ID) as managerUserName," + |
| | | "(select su2.REALNAME from system_user su2 where su2.id = t.SALESMAN_ID) as salesmanRealName," + |
| | | "(select count(su3.id) from system_user su3 where su3.COMPANY_ID = t.ID and su3.TYPE = 2) as anchorUserNum," + |
| | | "(select count(su4.id) from system_user su4 where su4.COMPANY_ID = t.ID and su4.TYPE = 1) as empUserNum," + |
| | | "(select count(g.id) from goods g where g.COMPANY_ID = t.ID )goodsNum"); |
| | | "(select count(su3.id) from system_user su3 where su3.deleted=0 and su3.COMPANY_ID = t.ID and su3.TYPE = 2) as anchorUserNum," + |
| | | "(select count(su4.id) from system_user su4 where su4.deleted=0 and su4.COMPANY_ID = t.ID and su4.TYPE = 1) as empUserNum," + |
| | | "(select count(g.id) from goods g where g.isdeleted=0 and g.COMPANY_ID = t.ID )goodsNum"); |
| | | queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getName()),Company::getName,pageWrap.getModel().getName()) |
| | | .like(StringUtils.isNotBlank(pageWrap.getModel().getManagerUserName()),SystemUser::getUsername,pageWrap.getModel().getManagerUserName()) |
| | | .eq(Objects.nonNull(pageWrap.getModel().getManagerUserName()),Company::getStatus,pageWrap.getModel().getStatus()) |
| | | .eq(Objects.nonNull(pageWrap.getModel().getStatus()),Company::getStatus,pageWrap.getModel().getStatus()) |
| | | .between((Objects.nonNull(pageWrap.getModel().getOepnValidDateStart()) && Objects.nonNull(pageWrap.getModel().getOepnValidDateEnd())), |
| | | Company::getOepnValidDate,pageWrap.getModel().getOepnValidDateStart(),pageWrap.getModel().getOepnValidDateEnd()); |
| | | Company::getOepnValidDate,pageWrap.getModel().getOepnValidDateStart(),pageWrap.getModel().getOepnValidDateEnd()) |
| | | .orderByDesc(Company::getCreateTime); |
| | | return PageData.from(companyJoinMapper.selectJoinPage(page,Company.class,queryWrapper)); |
| | | } |
| | | |