| | |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.BOMFeedbakMapper; |
| | | import com.whyc.pojo.DocLog; |
| | | import com.whyc.mapper.DocUserMapper; |
| | | import com.whyc.pojo.BOMFeedback; |
| | | import com.whyc.pojo.DocUser; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.CommonUtil; |
| | | import com.whyc.util.MailUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.mail.MessagingException; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.Date; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | public class BOMFeedbakService { |
| | | @Autowired(required = false) |
| | | private BOMFeedbakMapper mapper; |
| | | @Autowired |
| | | private MailUtil mailUtil; |
| | | @Resource |
| | | private DocUserMapper userMapper; |
| | | //统计 |
| | | public Map<String, Integer> getFkStatistic(DocUser user,Map<String, Integer> map) { |
| | | int sendFk=0; |
| | |
| | | } |
| | | return new Response().set(1,bl,msg); |
| | | } |
| | | |
| | | /** |
| | | * 提交反馈: |
| | | * 1.记录数据库保存 |
| | | * 2.附件存储 |
| | | * 3.邮件发送 |
| | | * @param feedback bom问题反馈 |
| | | * @return response |
| | | */ |
| | | public Response submitFeedback(BOMFeedback feedback) throws IOException, MessagingException { |
| | | MultipartFile multipartFile = feedback.getMultipartFile(); |
| | | Date date = new Date(); |
| | | if(multipartFile!=null){ |
| | | //存储文件 |
| | | String rootFile = CommonUtil.getRootFile(); |
| | | long time = date.getTime(); |
| | | String originalFilename = multipartFile.getOriginalFilename(); |
| | | String fileName = originalFilename.substring(0, originalFilename.lastIndexOf(".")); |
| | | String suffix = originalFilename.substring(originalFilename.lastIndexOf(".")); |
| | | String feedbackPath = "feedback_bom" + File.separator + fileName + "_" + time + suffix; |
| | | File file = new File(rootFile + feedbackPath); |
| | | if (!file.exists()){ |
| | | file.mkdirs(); |
| | | } |
| | | multipartFile.transferTo(file); |
| | | feedback.setFile("doc_file"+File.separator+feedbackPath); |
| | | } |
| | | //保存 |
| | | feedback.setCreateTime(date); |
| | | feedback.setConfirmStatus(0); |
| | | mapper.insert(feedback); |
| | | //发送邮件 |
| | | String receiverIds = feedback.getReceiverIds(); |
| | | String[] receiverIdsSplit = receiverIds.split(","); |
| | | List<String> receiverMailList = new LinkedList<>(); |
| | | |
| | | Integer senderId = feedback.getSenderId(); |
| | | String senderName = null; |
| | | |
| | | List<DocUser> docUsers = userMapper.selectList(null); |
| | | for (DocUser docUser:docUsers){ |
| | | if(docUser.getId().intValue() == senderId){ |
| | | senderName = docUser.getName(); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | for (String receiverId:receiverIdsSplit){ |
| | | for (DocUser docUser:docUsers){ |
| | | if(docUser.getId().intValue() == Integer.parseInt(receiverId)){ |
| | | receiverMailList.add(docUser.getMail()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | String subject = "Bom问题反馈-"+senderName; |
| | | String content = feedback.getContent(); |
| | | mailUtil.sendMailBatch(senderName,receiverMailList,subject,content); |
| | | return new Response().set(1,true,"反馈完成"); |
| | | } |
| | | |
| | | } |