|  |  |  | 
|---|
|  |  |  | 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.SystemUserMapper; | 
|---|
|  |  |  | import com.doumee.dao.system.model.SystemUser; | 
|---|
|  |  |  | import com.doumee.service.business.CompanyService; | 
|---|
|  |  |  | import com.github.yulichang.wrapper.MPJLambdaWrapper; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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); | 
|---|
|  |  |  | 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 | 
|---|