| | |
| | | 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.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; |
| | |
| | | @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(CompanyCreatOrUpdateRequest company) { |
| | | LoginUserInfo userInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | |
| | | 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 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 |
| | |
| | | queryWrapper.selectAll(Company.class) |
| | | .selectAs(SystemUser::getUsername,Company::getManagerUserName); |
| | | queryWrapper.select( |
| | | "(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," + |
| | | "(select count(su3.id) from system_user su3 where su3.COMPANY_ID = company.ID and su3.TYPE = 2) as anchorUserNum," + |
| | | "(select count(su4.id) from system_user su4 where su4.COMPANY_ID = company.ID and su3.TYPE = 1) as empUserNum," + |
| | | "(select count(goods.id) from goods where g.COMPANY_ID = company.ID )goodsNum"); |
| | | queryWrapper.eq(Company::getName,pageWrap.getModel().getName()) |
| | | .like(SystemUser::getUsername,pageWrap.getModel().getManagerUserName()) |
| | | .eq(Company::getStatus,pageWrap.getModel().getStatus()) |
| | | .between(Company::getOepnValidDate,pageWrap.getModel().getOepnValidDateStart(),pageWrap.getModel().getOepnValidDateEnd()); |
| | | return PageData.from(companyMapper.selectPage(page, queryWrapper)); |
| | | "(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 |