diff --git a/user-client/src/main/java/com/hp/user/client/entity/CustomerCompanyVO.java b/user-client/src/main/java/com/hp/user/client/entity/CustomerCompanyVO.java index 64ed363..980661c 100644 --- a/user-client/src/main/java/com/hp/user/client/entity/CustomerCompanyVO.java +++ b/user-client/src/main/java/com/hp/user/client/entity/CustomerCompanyVO.java @@ -92,6 +92,10 @@ public class CustomerCompanyVO { * 审核状态;1待审核;2审核通过;3审核未通过 */ private Short status; + /** + * 企业对应服务商Id + */ + private String serviceProviderId; public CustomerCompanyVO(){} @@ -277,4 +281,12 @@ public class CustomerCompanyVO { public void setStatus(Short status) { this.status = status; } + + public String getServiceProviderId() { + return serviceProviderId; + } + + public void setServiceProviderId(String serviceProviderId) { + this.serviceProviderId = serviceProviderId; + } } diff --git a/user-client/src/main/java/com/hp/user/client/entity/CustomerServiceProviderEnterpriseVO.java b/user-client/src/main/java/com/hp/user/client/entity/CustomerServiceProviderEnterpriseVO.java index 676c87e..107916c 100644 --- a/user-client/src/main/java/com/hp/user/client/entity/CustomerServiceProviderEnterpriseVO.java +++ b/user-client/src/main/java/com/hp/user/client/entity/CustomerServiceProviderEnterpriseVO.java @@ -10,6 +10,7 @@ package com.hp.user.client.entity; */ public class CustomerServiceProviderEnterpriseVO { + private String id; /** * 服务商Id */ @@ -19,13 +20,22 @@ public class CustomerServiceProviderEnterpriseVO { */ private String enterpriseId; - private CustomerServiceProviderEnterpriseVO(){} + public CustomerServiceProviderEnterpriseVO(){} - public CustomerServiceProviderEnterpriseVO(String serviceProviderId, String enterpriseId) { + public CustomerServiceProviderEnterpriseVO(String id, String serviceProviderId, String enterpriseId) { + this.id = id; this.serviceProviderId = serviceProviderId; this.enterpriseId = enterpriseId; } + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + public String getServiceProviderId() { return serviceProviderId; } diff --git a/user-client/src/main/java/com/hp/user/client/service/CustomerServiceProviderEnterpriseService.java b/user-client/src/main/java/com/hp/user/client/service/CustomerServiceProviderEnterpriseService.java index 7937720..2132cc4 100644 --- a/user-client/src/main/java/com/hp/user/client/service/CustomerServiceProviderEnterpriseService.java +++ b/user-client/src/main/java/com/hp/user/client/service/CustomerServiceProviderEnterpriseService.java @@ -1,5 +1,9 @@ package com.hp.user.client.service; +import com.hp.user.client.entity.CustomerServiceProviderEnterpriseVO; + +import java.util.List; + /** *

* 企业和服务商的关系 服务类 @@ -9,5 +13,12 @@ package com.hp.user.client.service; * @since 2020-11-20 */ public interface CustomerServiceProviderEnterpriseService { + public boolean insert(CustomerServiceProviderEnterpriseVO cs); + public boolean update(CustomerServiceProviderEnterpriseVO cs); + public boolean delete(String csId); + public CustomerServiceProviderEnterpriseVO queryCsByCompanyIdAndServiceProviderId(String companyId,String serviceProviderId); + public String queryServiceProviderIdByCompanyId(String companyId); + public boolean insertBatch(List csVOList); + public boolean deleteBatch(List enterpriseIdList); } diff --git a/user-service/src/main/java/com/hp/user/service/controller/CompanyController.java b/user-service/src/main/java/com/hp/user/service/controller/CompanyController.java index a436e63..2df8dfd 100644 --- a/user-service/src/main/java/com/hp/user/service/controller/CompanyController.java +++ b/user-service/src/main/java/com/hp/user/service/controller/CompanyController.java @@ -3,6 +3,8 @@ package com.hp.user.service.controller; import com.hp.user.client.entity.*; import com.hp.user.client.service.AuditService; import com.hp.user.client.service.CustomerCompanyService; +import com.hp.user.client.service.CustomerServiceProviderEnterpriseService; +import com.hp.user.service.entity.CustomerServiceProviderEnterprise; import com.hp.user.service.utils.HttpResult; import com.hp.user.service.utils.IdWorker; @@ -12,7 +14,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; +import java.util.ArrayList; import java.util.Date; +import java.util.List; @Api(tags = "企业/服务商API接口") @RestController @@ -22,6 +26,8 @@ public class CompanyController { private CustomerCompanyService customerCompanyService; @Autowired private AuditService auditService; + @Autowired + private CustomerServiceProviderEnterpriseService csService; /** * 添加企业/服务商 @@ -29,15 +35,36 @@ public class CompanyController { * @param company 企业/服务商信息 * @return HttpResult */ - @ApiOperation(value = "新增企业/服务商", notes = "提示:要指定审核状态 status;服务商type=0,企业type=1", httpMethod = "POST") + @ApiOperation(value = "新增企业/服务商", notes = "提示:要指定审核状态 status;服务商type=0,企业type=1;若新增企业,则需要填serviceProviderIds", httpMethod = "POST") @PostMapping("/addCompany") @Transactional - public HttpResult addCompany(@RequestBody CustomerCompanyVO company) { + public HttpResult addCompany(@RequestBody CustomerCompanyVO company, @RequestParam String serviceProviderId) { company.setCustomerId(IdWorker.generactorId().toString()); - boolean flag = customerCompanyService.insert(company); - if (flag) return HttpResult.success(company.getCustomerId()); + boolean flag1 = true, flag2 = true; + flag1 = customerCompanyService.insert(company); + if (serviceProviderId != null) { + CustomerServiceProviderEnterpriseVO temp = new CustomerServiceProviderEnterpriseVO(IdWorker.generactorId().toString(), serviceProviderId, company.getCustomerId()); + flag2 = csService.insert(temp); + } + if (flag1 && flag2) return HttpResult.success(company.getCustomerId()); else return HttpResult.fail("添加失败"); } +// public HttpResult addCompany(@RequestBody CustomerCompanyVO company, @RequestBody List serviceProviderIds) { +// company.setCustomerId(IdWorker.generactorId().toString()); +// boolean flag1 = true, flag2 = true; +// flag1 = customerCompanyService.insert(company); +// if (serviceProviderIds != null) { +// List csList=new ArrayList<>(); +// CustomerServiceProviderEnterpriseVO temp; +// for(String serviceProviderId:serviceProviderIds){ +// temp = new CustomerServiceProviderEnterpriseVO(IdWorker.generactorId().toString(), serviceProviderId, company.getCustomerId()); +// csList.add(temp); +// } +// flag2=csService.insertBatch(csList); +// } +// if (flag1 && flag2) return HttpResult.success(company.getCustomerId()); +// else return HttpResult.fail("添加失败"); +// } /** * 更新企业/服务商信息 @@ -45,11 +72,18 @@ public class CompanyController { * @param company 企业/服务商信息 * @return HttpResult */ - @ApiOperation(value = "更新企业/服务商信息") + @ApiOperation(value = "更新企业/服务商信息", notes = "若更新企业,则需要填serviceProviderId") @PostMapping("/updateCompany") - public HttpResult updateCompany(@RequestBody CustomerCompanyVO company) { - boolean flag = customerCompanyService.update(company); - if (flag) return HttpResult.success(); + @Transactional + public HttpResult updateCompany(@RequestBody CustomerCompanyVO company, @RequestParam String serviceProviderId) { + boolean flag1 = true, flag2 = true; + flag1 = customerCompanyService.update(company); + if (serviceProviderId != null) { + CustomerServiceProviderEnterpriseVO cs = csService.queryCsByCompanyIdAndServiceProviderId(company.getCustomerId(), serviceProviderId); + cs.setServiceProviderId(serviceProviderId); + flag2 = csService.update(cs); + } + if (flag1 && flag2) return HttpResult.success(); else return HttpResult.fail("更新失败"); } @@ -59,11 +93,16 @@ public class CompanyController { * @param companyId 企业Id * @return HttpResult */ - @ApiOperation(value = "删除企业/服务商") + @ApiOperation(value = "删除企业/服务商", notes = "若删除企业,则需要填serviceProviderId") @GetMapping("/deleteCompanyByCompanyId") - public HttpResult deleteCompanyByCompanyId(@RequestParam String companyId) { - boolean flag = customerCompanyService.delete(companyId); - if (flag) return HttpResult.success(); + public HttpResult deleteCompanyByCompanyId(@RequestParam String companyId, @RequestParam String serviceProviderId) { + boolean flag1 = true, flag2 = true; + flag1 = customerCompanyService.delete(companyId); + if (serviceProviderId != null) { + CustomerServiceProviderEnterpriseVO cs = csService.queryCsByCompanyIdAndServiceProviderId(companyId, serviceProviderId); + flag2 = csService.delete(cs.getId()); + } + if (flag1 && flag2) return HttpResult.success(); else return HttpResult.fail("删除失败"); } @@ -73,31 +112,35 @@ public class CompanyController { * @param companyId 企业Id * @return HttpResult */ - @ApiOperation(value = "根据企业/服务商Id 查询某企业/服务商信息") + @ApiOperation(value = "根据企业/服务商Id 查询某企业/服务商信息", notes = "服务商type为0,企业type为1") @GetMapping("/queryCompanyByCompanyId") - public HttpResult queryCompanyByCompanyId(@RequestParam String companyId) { + public HttpResult queryCompanyByCompanyId(@RequestParam String companyId, @RequestParam Integer type) { CustomerCompanyVO companyVO = customerCompanyService.queryCompanyByCompanyId(companyId); + if(type==1){ + companyVO.setServiceProviderId(csService.queryServiceProviderIdByCompanyId(companyId)); + } if (companyVO != null) return HttpResult.success(companyVO); else return HttpResult.fail("查询失败/已被删除"); } - /** - * 分页查询所有企业信息 - * - * @param current 要查询页数 - * @param size 一页的行数 - * @return HttpResult - */ - @ApiOperation(value = "分页查询所有企业/服务商", notes = "输入的current为要查询的页数,size为一页的行数,返回的total为总行数,服务商type为0,企业type为1") - @GetMapping("/queryAllCompanyByPage") - public HttpResult queryAllCompanyByPage(@RequestParam Long current, @RequestParam Integer size, @RequestParam Integer type) { - CompanyPage companyPage = customerCompanyService.getCompanysPage(current, size, type); - if (companyPage != null) return HttpResult.success(companyPage); - else return HttpResult.fail("查询失败"); - } +// /** +// * 分页查询所有企业信息 +// * +// * @param current 要查询页数 +// * @param size 一页的行数 +// * @return HttpResult +// */ +// @ApiOperation(value = "分页查询所有企业/服务商", notes = "输入的current为要查询的页数,size为一页的行数,返回的total为总行数,服务商type为0,企业type为1") +// @GetMapping("/queryAllCompanyByPage") +// public HttpResult queryAllCompanyByPage(@RequestParam Long current, @RequestParam Integer size, @RequestParam Integer type) { +// CompanyPage companyPage = customerCompanyService.getCompanysPage(current, size, type); +// if (companyPage != null) return HttpResult.success(companyPage); +// else return HttpResult.fail("查询失败"); +// } /** * 根据服务商姓名分页查询服务商 + * * @param name 服务商名称 * @param current 要查询页数 * @param size 一页的行数 @@ -141,8 +184,8 @@ public class CompanyController { @Transactional public HttpResult becomeContractUser(@RequestBody CustomerCompanyVO company, @RequestBody boolean willing) { company.setCustomerId(IdWorker.generactorId().toString()); - company.setType((short)1); // 企业 - company.setStatus((short)1); // 未审核 + company.setType((short) 1); // 企业 + company.setStatus((short) 1); // 未审核 AuditVO audit = new AuditVO(); audit.setAuditId(IdWorker.generactorId().toString()); audit.setUserId(company.getCustomerId()); @@ -174,6 +217,7 @@ public class CompanyController { /** * 根据企业姓名、审核状态、提交时间分页查询认证企业 + * * @param name 企业名称 * @param status 审核状态 * @param startTime 提交时间的开始间隔 diff --git a/user-service/src/main/java/com/hp/user/service/dao/CustomerServiceProviderEnterpriseMapper.java b/user-service/src/main/java/com/hp/user/service/dao/CustomerServiceProviderEnterpriseMapper.java index 8897a22..8ba4fec 100644 --- a/user-service/src/main/java/com/hp/user/service/dao/CustomerServiceProviderEnterpriseMapper.java +++ b/user-service/src/main/java/com/hp/user/service/dao/CustomerServiceProviderEnterpriseMapper.java @@ -2,6 +2,9 @@ package com.hp.user.service.dao; import com.hp.user.service.entity.CustomerServiceProviderEnterprise; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** *

@@ -12,5 +15,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; * @since 2020-11-20 */ public interface CustomerServiceProviderEnterpriseMapper extends BaseMapper { - + int insertBatch(@Param("csList") List csList); + int deleteBatch(@Param("enterpriseIdList") List enterpriseIdList); } diff --git a/user-service/src/main/java/com/hp/user/service/entity/CustomerCompany.java b/user-service/src/main/java/com/hp/user/service/entity/CustomerCompany.java index 7a297a1..2905643 100644 --- a/user-service/src/main/java/com/hp/user/service/entity/CustomerCompany.java +++ b/user-service/src/main/java/com/hp/user/service/entity/CustomerCompany.java @@ -282,8 +282,4 @@ public class CustomerCompany implements Serializable { public Short getStatus() { return status; } - - public void setStatus(Short status) { - this.status = status; - } } diff --git a/user-service/src/main/java/com/hp/user/service/entity/CustomerServiceProviderEnterprise.java b/user-service/src/main/java/com/hp/user/service/entity/CustomerServiceProviderEnterprise.java index cf89047..c0f7a62 100644 --- a/user-service/src/main/java/com/hp/user/service/entity/CustomerServiceProviderEnterprise.java +++ b/user-service/src/main/java/com/hp/user/service/entity/CustomerServiceProviderEnterprise.java @@ -24,7 +24,7 @@ public class CustomerServiceProviderEnterprise implements Serializable { * Id */ @TableId(value = "id") - private String Id; + private String id; /** * 服务商Id */ @@ -34,20 +34,20 @@ public class CustomerServiceProviderEnterprise implements Serializable { */ private String enterpriseId; - private CustomerServiceProviderEnterprise(){} + public CustomerServiceProviderEnterprise(){} public CustomerServiceProviderEnterprise(String id, String serviceProviderId, String enterpriseId) { - Id = id; + this.id = id; this.serviceProviderId = serviceProviderId; this.enterpriseId = enterpriseId; } public String getId() { - return Id; + return id; } public void setId(String id) { - Id = id; + this.id = id; } public String getServiceProviderId() { diff --git a/user-service/src/main/java/com/hp/user/service/impl/CustomerCompanyServiceImpl.java b/user-service/src/main/java/com/hp/user/service/impl/CustomerCompanyServiceImpl.java index 5170cff..9c9fd24 100644 --- a/user-service/src/main/java/com/hp/user/service/impl/CustomerCompanyServiceImpl.java +++ b/user-service/src/main/java/com/hp/user/service/impl/CustomerCompanyServiceImpl.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; import com.hp.user.client.entity.*; import com.hp.user.client.service.CustomerCompanyService; +import com.hp.user.client.service.CustomerServiceProviderEnterpriseService; import com.hp.user.service.dao.CustomerCompanyMapper; import com.hp.user.service.dao.CustomerServiceProviderEnterpriseMapper; import com.hp.user.service.entity.CompanyAudit; @@ -34,6 +35,8 @@ public class CustomerCompanyServiceImpl implements CustomerCompanyService { private CustomerCompanyMapper customerCompanyMapper; @Autowired private CustomerServiceProviderEnterpriseMapper customerServiceProviderEnterpriseMapper; + @Autowired + private CustomerServiceProviderEnterpriseService csService; @Override public boolean insert(CustomerCompanyVO company) { @@ -165,6 +168,7 @@ public class CustomerCompanyServiceImpl implements CustomerCompanyService { for (CustomerCompany company : companys) { t = new CustomerCompanyVO(); BeanUtils.copyProperties(company, t); + t.setServiceProviderId(csService.queryServiceProviderIdByCompanyId(company.getCustomerId())); companyVOs.add(t); } companyPage.setCompanyList(companyVOs); diff --git a/user-service/src/main/java/com/hp/user/service/impl/CustomerServiceProviderEnterpriseServiceImpl.java b/user-service/src/main/java/com/hp/user/service/impl/CustomerServiceProviderEnterpriseServiceImpl.java index a20d255..e60668b 100644 --- a/user-service/src/main/java/com/hp/user/service/impl/CustomerServiceProviderEnterpriseServiceImpl.java +++ b/user-service/src/main/java/com/hp/user/service/impl/CustomerServiceProviderEnterpriseServiceImpl.java @@ -1,8 +1,19 @@ package com.hp.user.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; +import com.hp.user.client.entity.CustomerServiceProviderEnterpriseVO; import com.hp.user.client.service.CustomerServiceProviderEnterpriseService; +import com.hp.user.service.dao.CustomerServiceProviderEnterpriseMapper; +import com.hp.user.service.entity.CustomerServiceProviderEnterprise; +import com.hp.user.service.entity.Station; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; + /** *

* 企业和服务商的关系 服务实现类 @@ -13,5 +24,66 @@ import org.springframework.stereotype.Service; */ @Service public class CustomerServiceProviderEnterpriseServiceImpl implements CustomerServiceProviderEnterpriseService { + @Autowired + private CustomerServiceProviderEnterpriseMapper csMapper; + @Override + public boolean insert(CustomerServiceProviderEnterpriseVO cs) { + CustomerServiceProviderEnterprise temp = new CustomerServiceProviderEnterprise(); + BeanUtils.copyProperties(cs,temp); + return SqlHelper.retBool(csMapper.insert(temp)); + } + + @Override + public boolean update(CustomerServiceProviderEnterpriseVO cs) { + CustomerServiceProviderEnterprise temp = new CustomerServiceProviderEnterprise(); + BeanUtils.copyProperties(cs,temp); + return SqlHelper.retBool(csMapper.updateById(temp)); + } + + @Override + public boolean delete(String csId) { + return SqlHelper.retBool(csMapper.deleteById(csId)); + } + + @Override + public CustomerServiceProviderEnterpriseVO queryCsByCompanyIdAndServiceProviderId(String companyId, String serviceProviderId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("service_provider_id",serviceProviderId); + wrapper.eq("enterprise_id",companyId); + CustomerServiceProviderEnterprise cs = csMapper.selectOne(wrapper); + CustomerServiceProviderEnterpriseVO temp = new CustomerServiceProviderEnterpriseVO(); + if(cs == null) return null; + else { + BeanUtils.copyProperties(cs,temp); + return temp; + } + } + + @Override + public String queryServiceProviderIdByCompanyId(String companyId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("enterprise_id",companyId); + CustomerServiceProviderEnterprise cs = csMapper.selectOne(wrapper); + if(cs == null) return null; + else { + return cs.getServiceProviderId(); + } + } + + @Override + public boolean insertBatch(List csVOList) { + List csList = new ArrayList<>(); + CustomerServiceProviderEnterprise temp; + for(CustomerServiceProviderEnterpriseVO cs:csVOList){ + temp=new CustomerServiceProviderEnterprise(); + BeanUtils.copyProperties(cs,temp); + csList.add(temp); + } + return SqlHelper.retBool(csMapper.insertBatch(csList)); + } + @Override + public boolean deleteBatch(List enterpriseIdList) { + return SqlHelper.retBool(csMapper.deleteBatch(enterpriseIdList)); + } } diff --git a/user-service/src/main/resources/mapper/CustomerServiceProviderEnterpriseMapper.xml b/user-service/src/main/resources/mapper/CustomerServiceProviderEnterpriseMapper.xml index 3c78128..377441c 100644 --- a/user-service/src/main/resources/mapper/CustomerServiceProviderEnterpriseMapper.xml +++ b/user-service/src/main/resources/mapper/CustomerServiceProviderEnterpriseMapper.xml @@ -1,5 +1,16 @@ - + + insert into r_customer_service_provider_enterprise values + + (#{cs.id},#{cs.serviceProviderId},#{cs.enterpriseId}) + + + + delete from r_customer_service_provider_enterprise WHERE enterprise_id IN + + #{id} + +