|
@@ -1,10 +1,28 @@
|
|
package com.management.platform.service.impl;
|
|
package com.management.platform.service.impl;
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.management.platform.entity.Contacts;
|
|
import com.management.platform.entity.Contacts;
|
|
|
|
+import com.management.platform.entity.User;
|
|
|
|
+import com.management.platform.entity.vo.ContactsVo;
|
|
import com.management.platform.mapper.ContactsMapper;
|
|
import com.management.platform.mapper.ContactsMapper;
|
|
|
|
+import com.management.platform.mapper.UserMapper;
|
|
import com.management.platform.service.ContactsService;
|
|
import com.management.platform.service.ContactsService;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.management.platform.util.HttpRespMsg;
|
|
|
|
+import org.apache.ibatis.annotations.Mapper;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -16,5 +34,55 @@ import org.springframework.stereotype.Service;
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
public class ContactsServiceImpl extends ServiceImpl<ContactsMapper, Contacts> implements ContactsService {
|
|
public class ContactsServiceImpl extends ServiceImpl<ContactsMapper, Contacts> implements ContactsService {
|
|
|
|
+ @Resource
|
|
|
|
+ private ContactsMapper contactsMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private UserMapper userMapper;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ public HttpRespMsg addContacts(Contacts contacts, HttpServletRequest request) {
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ String token = String.valueOf(request.getHeader("Token"));
|
|
|
|
+ User user = userMapper.selectById(token);
|
|
|
|
+ Integer companyId = user.getCompanyId();
|
|
|
|
+
|
|
|
|
+ LambdaQueryWrapper<Contacts> lqw_contacts = new LambdaQueryWrapper<>();
|
|
|
|
+ lqw_contacts.eq(Contacts::getCustomId,contacts.getCustomId()).eq(Contacts::getName,contacts.getName());
|
|
|
|
+ Contacts selectedOne = contactsMapper.selectOne(lqw_contacts);
|
|
|
|
+ if (selectedOne!=null){
|
|
|
|
+ httpRespMsg.setError("已存在该客户!");
|
|
|
|
+ }
|
|
|
|
+ contacts.setCompanyId(companyId)
|
|
|
|
+ .setOwnerId(user.getId())//添加时默认
|
|
|
|
+ .setIsDelete(0)
|
|
|
|
+ .setCreateTime(LocalDateTime.now());
|
|
|
|
+ int insert = contactsMapper.insert(contacts);
|
|
|
|
+ if (insert<=0){
|
|
|
|
+ httpRespMsg.setError("添加失败!");
|
|
|
|
+ }
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg pageContacts(Integer pageIndex, Integer pageSize, String customName, String name, String phone, String ownerName, HttpServletRequest request) {
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ map.put("customName", customName);
|
|
|
|
+ map.put("name", name);
|
|
|
|
+ map.put("phone", phone);
|
|
|
|
+ map.put("ownerName", ownerName);
|
|
|
|
+ String token = String.valueOf(request.getHeader("Token"));
|
|
|
|
+ User user = userMapper.selectById(token);
|
|
|
|
+ map.put("companyId",user.getCompanyId());
|
|
|
|
+ Page<ContactsVo> pageContacts = contactsMapper.pageContacts(new Page(pageIndex, pageSize), map);
|
|
|
|
+ List<ContactsVo> contactsVoList = pageContacts.getRecords();
|
|
|
|
+
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ msg.setData(contactsVoList);
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|