|
@@ -1,6 +1,5 @@
|
|
|
package cn.com.ty.lift.enterprise.custom.service.impl;
|
|
|
|
|
|
-import cn.com.ty.lift.common.constants.ApiConstants;
|
|
|
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;
|
|
@@ -8,6 +7,9 @@ import cn.com.ty.lift.enterprise.custom.dao.entity.model.PropertyCompanyReq;
|
|
|
import cn.com.ty.lift.enterprise.custom.dao.mapper.PropertyCompanyMapper;
|
|
|
import cn.com.ty.lift.enterprise.custom.service.PropertyCompanyService;
|
|
|
import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.poi.excel.BigExcelWriter;
|
|
|
+import cn.hutool.poi.excel.ExcelUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
@@ -17,6 +19,12 @@ import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.*;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* (甲方公司)客户表 服务实现类
|
|
@@ -26,16 +34,17 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
* @since 2019-11-11
|
|
|
*/
|
|
|
@Service
|
|
|
-@Transactional
|
|
|
@AllArgsConstructor
|
|
|
public class PropertyCompanyServiceImpl extends ServiceImpl<PropertyCompanyMapper, PropertyCompany> implements PropertyCompanyService {
|
|
|
private final PropertyContactServiceImpl propertyContactService;
|
|
|
|
|
|
+ @Transactional
|
|
|
public RestResponse delete(Long id) {
|
|
|
PropertyCompany byId = this.getById(id);
|
|
|
if (byId.getStatus() == 2) {
|
|
|
return RestResponse.success(null, "有正在服务的关联项目,无法删除");
|
|
|
- } else if (this.getBaseMapper().selectProjectCount(byId.getId()) != null && this.getBaseMapper().selectProjectCount(byId.getId()).get("count") > 0L) {
|
|
|
+ } else if (this.getBaseMapper().selectProjectCount(byId.getId()) != null
|
|
|
+ && this.getBaseMapper().selectProjectCount(byId.getId()).get("count") > 0L) {
|
|
|
byId.setStatus(2);
|
|
|
this.updateById(byId);
|
|
|
return RestResponse.success(null, "有正在服务的关联项目,无法删除");
|
|
@@ -66,31 +75,93 @@ public class PropertyCompanyServiceImpl extends ServiceImpl<PropertyCompanyMappe
|
|
|
if (records.getRecords().isEmpty()) {
|
|
|
return RestResponse.success();
|
|
|
}
|
|
|
- return RestResponse.success(records,"成功");
|
|
|
+ return RestResponse.success(records, "成功");
|
|
|
}
|
|
|
|
|
|
+ @Transactional
|
|
|
public RestResponse saveAll(PropertyCompanyAndPropertyContactReq req) {
|
|
|
long id = IdWorker.getId();
|
|
|
req.getPropertyCompany().setId(id);
|
|
|
- req.getPropertyContacts().forEach(contact -> {
|
|
|
- contact.setPpCompanyId(id);
|
|
|
- });
|
|
|
+ req.getPropertyContacts().forEach(contact -> contact.setPpCompanyId(id));
|
|
|
if (this.save(req.getPropertyCompany()) && propertyContactService.saveBatch(req.getPropertyContacts())) {
|
|
|
return RestResponse.success(null, "成功");
|
|
|
}
|
|
|
return RestResponse.fail();
|
|
|
}
|
|
|
|
|
|
- public RestResponse export() {
|
|
|
- return RestResponse.success(null, ApiConstants.RESULT_ERROR, "待实现");
|
|
|
+ public void export(PropertyCompany company, HttpServletResponse res) {
|
|
|
+ String fileName = "客户管理表" + LocalDate.now().toString() + ".xlsx";
|
|
|
+ List<PropertyCompany> companies = this.list(new QueryWrapper<PropertyCompany>()
|
|
|
+ .select("id", "name", "mailing_address", "status")
|
|
|
+ .eq("mt_company_id", company.getMtCompanyId())
|
|
|
+ .ne("status", 0));
|
|
|
+
|
|
|
+ List<List<?>> rows = new ArrayList<>();
|
|
|
+
|
|
|
+ companies.forEach(c -> {
|
|
|
+ List<?> row = CollUtil.newArrayList(c.getId(), c.getName(), c.getMailingAddress(), c.getStatus());
|
|
|
+ rows.add(row);
|
|
|
+ });
|
|
|
+ BigExcelWriter writer = ExcelUtil.getBigWriter(System.getProperty("user.dir") + "/" + fileName);
|
|
|
+ System.out.println(System.getProperty("user.dir") + "/" + fileName);
|
|
|
+ // 一次性写出内容,使用默认样式
|
|
|
+ writer.write(rows);
|
|
|
+ // 关闭writer,释放内存
|
|
|
+ writer.close();
|
|
|
+
|
|
|
+ res.setHeader("Content-Disposition", "attachment; filename=" + fileName);
|
|
|
+ res.setHeader("content-type", "application/x-msdownload;");
|
|
|
+ res.setContentType("text/plain; charset=utf-8");
|
|
|
+ byte[] buff = new byte[1024];
|
|
|
+ BufferedInputStream bis = null;
|
|
|
+ OutputStream os = null;
|
|
|
+
|
|
|
+ File file = new File(System.getProperty("user.dir") + "/" + fileName);
|
|
|
+ try {
|
|
|
+ os = res.getOutputStream();
|
|
|
+ bis = new BufferedInputStream(new FileInputStream(file));
|
|
|
+ int i = bis.read(buff);
|
|
|
+
|
|
|
+ while (i != -1) {
|
|
|
+ os.write(buff, 0, buff.length);
|
|
|
+ os.flush();
|
|
|
+ i = bis.read(buff);
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ if (os != null) {
|
|
|
+ try {
|
|
|
+ os.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (bis != null) {
|
|
|
+ try {
|
|
|
+ bis.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (file.exists()) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- //更新客户公司和客户联系人的status
|
|
|
+ /**
|
|
|
+ * @param req
|
|
|
+ * @return RestResponse
|
|
|
+ * @description 更新客户公司和客户联系人的status.
|
|
|
+ * @date 2019/12/31 10:18
|
|
|
+ */
|
|
|
@Transactional
|
|
|
public RestResponse updateStatus(PropertyCompanyReq req) {
|
|
|
PropertyCompany companyById = this.getById(req.getPropertyCompanyId());
|
|
|
PropertyContact contactById = propertyContactService.getById(req.getPropertyContactId());
|
|
|
- if (companyById == null | contactById == null) {
|
|
|
+ if (companyById == null || contactById == null) {
|
|
|
return RestResponse.failParam();
|
|
|
}
|
|
|
companyById.setStatus(2);
|