|
@@ -1,6 +1,7 @@
|
|
|
package cn.com.ty.lift.enterprise.custom.service.impl;
|
|
|
|
|
|
import cn.com.ty.lift.enterprise.custom.dao.entity.PropertyCompany;
|
|
|
+import cn.com.ty.lift.enterprise.custom.dao.entity.PropertyContact;
|
|
|
import cn.com.ty.lift.enterprise.custom.dao.entity.model.PropertyCompanyAndPropertyContactReq;
|
|
|
import cn.com.ty.lift.enterprise.custom.dao.entity.model.PropertyCompanyReq;
|
|
|
import cn.com.ty.lift.enterprise.custom.dao.mapper.PropertyCompanyMapper;
|
|
@@ -11,11 +12,11 @@ import cn.hutool.poi.excel.ExcelUtil;
|
|
|
import cn.hutool.poi.excel.ExcelWriter;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
@@ -23,7 +24,6 @@ import java.io.IOException;
|
|
|
import java.time.LocalDate;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -57,20 +57,29 @@ public class PropertyCompanyServiceImpl extends ServiceImpl<PropertyCompanyMappe
|
|
|
if (records.getRecords().isEmpty()) {
|
|
|
return RestResponse.success();
|
|
|
}
|
|
|
- return RestResponse.success(records, "成功");
|
|
|
+ return RestResponse.success(records);
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public RestResponse saveAll(PropertyCompanyAndPropertyContactReq req) {
|
|
|
- long id = IdWorker.getId();
|
|
|
- req.getPropertyCompany().setId(id);
|
|
|
- req.getPropertyContacts().forEach(contact -> contact.setPpCompanyId(id));
|
|
|
- if (this.save(req.getPropertyCompany()) && propertyContactService.saveBatch(req.getPropertyContacts())) {
|
|
|
- return RestResponse.success(null, "成功");
|
|
|
+ PropertyCompany propertyCompany = req.getPropertyCompany();
|
|
|
+ boolean ppc = save(propertyCompany);
|
|
|
+ if (!ppc) {
|
|
|
+ return RestResponse.fail("保存甲方公司失败");
|
|
|
+ }
|
|
|
+ List<PropertyContact> propertyContacts = req.getPropertyContacts();
|
|
|
+ propertyContacts.forEach(contact -> contact.setPpCompanyId(propertyCompany.getId()));
|
|
|
+ boolean ppt = propertyContactService.saveBatch(propertyContacts);
|
|
|
+ if (ppt) {
|
|
|
+ return RestResponse.success(true);
|
|
|
+ } else {
|
|
|
+ //强制手动事务回滚
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return RestResponse.fail("保存甲方联系人失败");
|
|
|
}
|
|
|
- return RestResponse.fail();
|
|
|
}
|
|
|
|
|
|
- @Transactional
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public RestResponse delete(Long id) {
|
|
|
PropertyCompany byId = this.getById(id);
|
|
|
if (null == byId) {
|
|
@@ -79,8 +88,8 @@ public class PropertyCompanyServiceImpl extends ServiceImpl<PropertyCompanyMappe
|
|
|
if (byId.getStatus() == 2) {
|
|
|
return RestResponse.success(null, "有正在服务的关联项目,无法删除");
|
|
|
}
|
|
|
- Map<String, Long> count = this.baseMapper.selectProjectCountForPPCompanyId(byId.getId());
|
|
|
- if (count != null && count.get("count") > 0L) {
|
|
|
+ long count = this.baseMapper.selectProjectCountForPPCompanyId(byId.getId());
|
|
|
+ if (count > 0) {
|
|
|
byId.setStatus(2);
|
|
|
this.updateById(byId);
|
|
|
return RestResponse.success(null, "有正在服务的关联项目,无法删除");
|
|
@@ -92,10 +101,10 @@ public class PropertyCompanyServiceImpl extends ServiceImpl<PropertyCompanyMappe
|
|
|
return RestResponse.fail();
|
|
|
}
|
|
|
|
|
|
- public void export(PropertyCompany propertyCompany, HttpServletResponse response) {
|
|
|
+ public void export(PropertyCompanyReq req, HttpServletResponse response) {
|
|
|
List<PropertyCompany> companies = this.list(new QueryWrapper<PropertyCompany>()
|
|
|
.select("id", "name", "mailing_address", "status")
|
|
|
- .eq("mt_company_id", propertyCompany.getMtCompanyId())
|
|
|
+ .eq("mt_company_id", req.getMtCompanyId())
|
|
|
.ne("status", 0));
|
|
|
List<List<?>> rows = new ArrayList<>();
|
|
|
//设置列头
|