| | |
| | | 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.core.model.LoginUserInfo; |
| | | import com.doumee.core.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.business.CompanyMapper; |
| | | 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.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 系统-企业信息表Service实现 |
| | |
| | | @Autowired |
| | | private CompanyMapper companyMapper; |
| | | |
| | | @Autowired |
| | | private CompanyJoinMapper companyJoinMapper; |
| | | |
| | | @Autowired |
| | | private SystemUserMapper systemUserMapper; |
| | | |
| | | |
| | | @Autowired |
| | | private SystemUserRoleMapper systemUserRoleMapper; |
| | | |
| | | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | |
| | | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) |
| | | @Override |
| | | public Integer create(Company company) { |
| | | companyMapper.insert(company); |
| | | public Integer create(CompanyCreatOrUpdateRequest company) { |
| | | LoginUserInfo userInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | Company insert = new Company(); |
| | | |
| | | if (Objects.isNull(company.getManagerId())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"登录账号不允许为空"); |
| | | } |
| | | if (Objects.isNull(company.getOepnValidDate())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"有效期不允许为空"); |
| | | } |
| | | if (Objects.isNull(company.getUserNum())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"主播账号数量不允许为空"); |
| | | } |
| | | |
| | | insert.setDeleted((byte)Constants.ZERO); |
| | | insert.setCreateUser(userInfo.getId()); |
| | | insert.setCreateTime(new Date()); |
| | | insert.setUpdateUser(userInfo.getId()); |
| | | insert.setUpdateTime(new Date()); |
| | | insert.setName(company.getName()); |
| | | insert.setShortName(company.getShortName()); |
| | | insert.setRemark(company.getRemark()); |
| | | insert.setManagerId(company.getManagerId()); |
| | | insert.setLinkname(company.getLinkname()); |
| | | insert.setLinkephone(company.getLinkephone()); |
| | | insert.setCreditCode(company.getCreditCode()); |
| | | insert.setUserNum(company.getUserNum()); |
| | | insert.setOepnValidDate(company.getOepnValidDate()); |
| | | insert.setOepnType(company.getOepnType()); |
| | | insert.setSalesmanId(company.getSalesmanId()); |
| | | companyMapper.insert(insert); |
| | | |
| | | UpdateWrapper<SystemUser> systemUserQuery = new UpdateWrapper<>(); |
| | | systemUserQuery.lambda() |
| | | .eq(SystemUser::getId,company.getManagerId()) |
| | | .set(SystemUser::getCompanyId,insert.getId()); |
| | | systemUserMapper.update(null,systemUserQuery); |
| | | |
| | | |
| | | SystemDictData dictData = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.COMPANY_MANAGE_ROLE); |
| | | |
| | | SystemUserRole systemUserRole = new SystemUserRole(); |
| | | systemUserRole.setUserId(company.getManagerId()); |
| | | 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(); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void updateById(CompanyCreatOrUpdateRequest company) { |
| | | UpdateWrapper<Company> wrapper = new UpdateWrapper<>(); |
| | | wrapper.lambda().eq(Company::getId,company.getId()) |
| | | .set(Company::getName,company.getName()) |
| | | .set(Company::getShortName,company.getShortName()) |
| | | .set(Company::getCreditCode,company.getCreditCode()) |
| | | .set(Company::getSalesmanId,company.getSalesmanId()) |
| | | .set(Company::getLinkname,company.getLinkname()) |
| | | .set(Company::getLinkephone,company.getLinkephone()); |
| | | companyMapper.update(null,wrapper); |
| | | } |
| | | |
| | | @Override |
| | | public void updateById(Company company) { |
| | | companyMapper.updateById(company); |
| | | } |
| | |
| | | @Override |
| | | public Company findById(Integer id) { |
| | | return companyMapper.selectById(id); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Company findPlatformById(Integer id) { |
| | | |
| | | QueryWrapper<Company> wrapper = new QueryWrapper<>(); |
| | | wrapper.select("company.*," + |
| | | "(select su1.USERNAME from system_user su1 where su1.id = company.MANAGER_ID) as managerUserName," + |
| | | "(select su2.REALNAME from system_user su2 where su2.id = company.SALESMAN_ID) as salesmanRealName") |
| | | .lambda().eq(Company::getId,id); |
| | | return companyMapper.selectOne(wrapper); |
| | | } |
| | | |
| | | @Override |
| | |
| | | return PageData.from(companyMapper.selectPage(page, queryWrapper)); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public PageData<Company> findPlatformPage(PageWrap<Company> pageWrap) { |
| | | IPage<Company> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); |
| | | MPJLambdaWrapper<Company> queryWrapper = new MPJLambdaWrapper<>(); |
| | | Utils.MP.blankToNull(pageWrap.getModel()); |
| | | queryWrapper.leftJoin(SystemUser.class,SystemUser::getId,Company::getManagerId); |
| | | 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 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"); |
| | | 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()) |
| | | .between((Objects.nonNull(pageWrap.getModel().getOepnValidDateStart()) && Objects.nonNull(pageWrap.getModel().getOepnValidDateEnd())), |
| | | Company::getOepnValidDate,pageWrap.getModel().getOepnValidDateStart(),pageWrap.getModel().getOepnValidDateEnd()); |
| | | return PageData.from(companyJoinMapper.selectJoinPage(page,Company.class,queryWrapper)); |
| | | } |
| | | |
| | | @Override |
| | | public long count(Company company) { |
| | | QueryWrapper<Company> wrapper = new QueryWrapper<>(company); |