Commit 0de62006 authored by 吴卿华's avatar 吴卿华

Merge remote-tracking branch 'origin/master'

parents 0b5887c3 a3bc6699
package com.zehong.web.controller.transaction;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zehong.common.annotation.Log;
import com.zehong.common.core.controller.BaseController;
import com.zehong.common.core.domain.AjaxResult;
import com.zehong.common.enums.BusinessType;
import com.zehong.system.domain.TPurchase;
import com.zehong.system.service.ITPurchaseService;
import com.zehong.common.utils.poi.ExcelUtil;
import com.zehong.common.core.page.TableDataInfo;
/**
* 外部采购(报销)申请Controller
*
* @author zehong
* @date 2023-06-16
*/
@RestController
@RequestMapping("/system/purchase")
public class TPurchaseController extends BaseController
{
@Autowired
private ITPurchaseService tPurchaseService;
/**
* 查询外部采购(报销)申请列表
*/
@PreAuthorize("@ss.hasPermi('system:purchase:list')")
@GetMapping("/list")
public TableDataInfo list(TPurchase tPurchase)
{
startPage();
List<TPurchase> list = tPurchaseService.selectTPurchaseList(tPurchase);
return getDataTable(list);
}
/**
* 导出外部采购(报销)申请列表
*/
@PreAuthorize("@ss.hasPermi('system:purchase:export')")
@Log(title = "外部采购(报销)申请", businessType = BusinessType.EXPORT)
@GetMapping("/export")
public AjaxResult export(TPurchase tPurchase)
{
List<TPurchase> list = tPurchaseService.selectTPurchaseList(tPurchase);
ExcelUtil<TPurchase> util = new ExcelUtil<TPurchase>(TPurchase.class);
return util.exportExcel(list, "外部采购(报销)申请数据");
}
/**
* 获取外部采购(报销)申请详细信息
*/
@PreAuthorize("@ss.hasPermi('system:purchase:query')")
@GetMapping(value = "/{purchaseId}")
public AjaxResult getInfo(@PathVariable("purchaseId") Long purchaseId)
{
return AjaxResult.success(tPurchaseService.selectTPurchaseById(purchaseId));
}
/**
* 新增外部采购(报销)申请
*/
@PreAuthorize("@ss.hasPermi('system:purchase:add')")
@Log(title = "外部采购(报销)申请", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody TPurchase tPurchase)
{
return toAjax(tPurchaseService.insertTPurchase(tPurchase));
}
/**
* 修改外部采购(报销)申请
*/
@PreAuthorize("@ss.hasPermi('system:purchase:edit')")
@Log(title = "外部采购(报销)申请", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody TPurchase tPurchase)
{
return toAjax(tPurchaseService.updateTPurchase(tPurchase));
}
/**
* 删除外部采购(报销)申请
*/
@PreAuthorize("@ss.hasPermi('system:purchase:remove')")
@Log(title = "外部采购(报销)申请", businessType = BusinessType.DELETE)
@DeleteMapping("/{purchaseIds}")
public AjaxResult remove(@PathVariable Long[] purchaseIds)
{
return toAjax(tPurchaseService.deleteTPurchaseByIds(purchaseIds));
}
}
......@@ -59,6 +59,11 @@
<artifactId>precision-effect-system</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -97,7 +97,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
// 过滤请求
.authorizeRequests()
// 对于登录login 验证码captchaImage 允许匿名访问
.antMatchers("/login", "/captchaImage").anonymous()
.antMatchers("/login", "/captchaImage", "/webSocket/**").anonymous()
.antMatchers(
HttpMethod.GET,
"/*.html",
......
package com.zehong.framework.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
/**
* @author geng
* webScocket
*/
@Configuration
public class WebSocketConfig {
@Bean
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
}
package com.zehong.framework.web.domain.server;
import javax.websocket.Session;
import java.util.concurrent.atomic.AtomicInteger;
/**
* <websocket信息对象>
* <用于存储secket连接信息>
* @author wzh
* @version 2018-07-08 18:49
* @see [相关类/方法] (可选)
**/
public class WebSocketBean {
/**
* 连接session对象
*/
private Session session;
/**
* 用户id
*/
private Long userId;
/**
* 连接错误次数
*/
private AtomicInteger erroerLinkCount = new AtomicInteger(0);
public int getErroerLinkCount() {
// 线程安全,以原子方式将当前值加1,注意:这里返回的是自增前的值
return erroerLinkCount.getAndIncrement();
}
public void cleanErrorNum()
{
// 清空计数
erroerLinkCount = new AtomicInteger(0);
}
public Session getSession() {
return session;
}
public void setSession(Session session) {
this.session = session;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
}
\ No newline at end of file
package com.zehong.framework.web.service;
import com.alibaba.fastjson.JSONArray;
import com.zehong.common.utils.spring.SpringUtils;
import com.zehong.framework.web.domain.server.WebSocketBean;
import com.zehong.system.domain.SysNotice;
import com.zehong.system.service.ISysNoticeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
/**
* @author geng
* webSocket工具类
*/
@Component
@ServerEndpoint("/webSocket/{roles}/{userId}")
public class WebSocketServer {
private static final Logger log = LoggerFactory.getLogger(WebSocketServer.class);
/**
* 错误最大重试次数
*/
private static final int MAX_ERROR_NUM = 10;
/**
* 用来存放每个客户端对应的webSocket对象。
*/
private static Map<String,List<WebSocketBean>> webSocketInfo;
static
{
// concurrent包的线程安全map
webSocketInfo = new ConcurrentHashMap<>();
}
@OnOpen
public void onOpen(Session session, @PathParam("roles") String roles, @PathParam("userId") String userId) {
for(String role : roles.split(",")){
WebSocketBean bean = new WebSocketBean();
bean.setSession(session);
bean.setUserId(Long.valueOf(userId));
if(webSocketInfo.containsKey(role)){
List<WebSocketBean> beans = webSocketInfo.get(role);
// 连接成功当前对象放入webSocket对象集合
beans.add(bean);
sendMessage(bean,initNotice(userId));
return;
}
List<WebSocketBean> beans = new ArrayList<>();
beans.add(bean);
webSocketInfo.put(role,beans);
sendMessage(bean,initNotice(userId));
}
log.info("客户端连接服务器session id :"+session.getId()+",当前连接数:" + webSocketInfo.size());
}
private String initNotice(String userId){
SysNotice notice = new SysNotice();
notice.setUserId(Long.valueOf(userId));
ISysNoticeService sysNoticeService = SpringUtils.getBean(ISysNoticeService.class);
List<SysNotice> notices = sysNoticeService.selectNoticeList(notice);
if(CollectionUtils.isEmpty(notices)){
return "";
}
return JSONArray.toJSONString(notices);
}
@OnClose
public void onClose(Session session) {
// 客户端断开连接移除websocket对象
for (Map.Entry<String, List<WebSocketBean>> entry : webSocketInfo.entrySet()) {
List<WebSocketBean> beans = entry.getValue().stream().filter(item ->item.getSession().getId().equals(session.getId())).collect(Collectors.toList());
entry.getValue().removeAll(beans);
}
log.info("客户端断开连接,当前连接数:" + webSocketInfo.size());
}
@OnMessage
public void onMessage(Session session, String message) {
log.info("客户端 session id: "+session.getId()+",消息:" + message);
// 此方法为客户端给服务器发送消息后进行的处理,可以根据业务自己处理,这里返回页面
//sendMessage(session, "服务端返回" + message);
}
@OnError
public void onError(Session session, Throwable throwable) {
log.error("发生错误"+ throwable.getMessage(),throwable);
}
/**
* 查找发送消息用户
* @param role 角色
* @param userId 用户id
* @param message 消息体
*/
public void findMessageUser(String role,Long userId, String message) {
List<WebSocketBean> beans = webSocketInfo.get(role);
if(!CollectionUtils.isEmpty(beans)){
//发送给指定角色
if(null == userId){
beans.forEach(item ->{
sendMessage(item,message);
});
return;
}
//发送给指定用户
List<WebSocketBean> userBean = beans.stream().filter(item -> item.getUserId().equals(userId)).collect(Collectors.toList());
userBean.stream().forEach(item -> {
sendMessage(item,message);
});
}
}
/**
* 发送消息
* @param bean webSocket对象
* @param message 消息体
*/
private void sendMessage(WebSocketBean bean, String message) {
try{
// 发送消息
bean.getSession().getBasicRemote().sendText(message);
// 清空错误计数
bean.cleanErrorNum();
}catch (Exception e){
log.error("发送消息失败"+ e.getMessage(),e);
int errorNum = bean.getErroerLinkCount();
// 小于最大重试次数重发
if(errorNum <= MAX_ERROR_NUM){
sendMessage(bean, message);
}else{
log.error("发送消息失败超过最大次数");
// 清空错误计数
bean.cleanErrorNum();
}
}
}
}
package com.zehong.system.domain;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.zehong.common.annotation.Excel;
import com.zehong.common.core.domain.BaseEntity;
/**
* 通知公告 sys_notice
* 通知公告对象 sys_notice
*
* @author zehong
* @date 2023-06-16
*/
public class SysNotice extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 公告ID */
private Long noticeId;
private Integer noticeId;
/** 公告标题 */
@Excel(name = "公告标题")
private String noticeTitle;
/** 公告类型(1通知 2公告) */
@Excel(name = "公告类型", readConverterExp = "1=通知,2=公告")
private String noticeType;
/** 公告内容 */
@Excel(name = "公告内容")
private String noticeContent;
/** 用户id */
@Excel(name = "用户id")
private Long userId;
/** 公告状态(0正常 1关闭) */
@Excel(name = "公告状态", readConverterExp = "0=正常,1=关闭")
private String status;
public Long getNoticeId()
public void setNoticeId(Integer noticeId)
{
return noticeId;
this.noticeId = noticeId;
}
public void setNoticeId(Long noticeId)
public Integer getNoticeId()
{
this.noticeId = noticeId;
return noticeId;
}
public void setNoticeTitle(String noticeTitle)
{
this.noticeTitle = noticeTitle;
}
@NotBlank(message = "公告标题不能为空")
@Size(min = 0, max = 50, message = "公告标题不能超过50个字符")
public String getNoticeTitle()
{
return noticeTitle;
}
public void setNoticeType(String noticeType)
{
this.noticeType = noticeType;
......@@ -61,7 +65,6 @@ public class SysNotice extends BaseEntity
{
return noticeType;
}
public void setNoticeContent(String noticeContent)
{
this.noticeContent = noticeContent;
......@@ -71,7 +74,15 @@ public class SysNotice extends BaseEntity
{
return noticeContent;
}
public void setUserId(Long userId)
{
this.userId = userId;
}
public Long getUserId()
{
return userId;
}
public void setStatus(String status)
{
this.status = status;
......@@ -89,6 +100,7 @@ public class SysNotice extends BaseEntity
.append("noticeTitle", getNoticeTitle())
.append("noticeType", getNoticeType())
.append("noticeContent", getNoticeContent())
.append("userId", getUserId())
.append("status", getStatus())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
......
package com.zehong.system.domain;
import java.math.BigDecimal;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.zehong.common.annotation.Excel;
import com.zehong.common.core.domain.BaseEntity;
/**
* 外部采购(报销)申请对象 t_purchase
*
* @author zehong
* @date 2023-06-16
*/
public class TPurchase extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 采购主键 */
private Long purchaseId;
/** 采购申请部门 */
@Excel(name = "采购申请部门")
private Long purchaseDeptId;
public Long getHandled_by_user_id() {
return handled_by_user_id;
}
public void setHandled_by_user_id(Long handled_by_user_id) {
this.handled_by_user_id = handled_by_user_id;
}
private Long handled_by_user_id;
/** 采购名称 */
@Excel(name = "采购名称")
private String purchaseName;
/** 规格 */
@Excel(name = "规格")
private String specifications;
/** 型号 */
@Excel(name = "型号")
private String modelType;
/** 用途说明 */
@Excel(name = "用途说明")
private String applicationDescription;
/** 使用人 */
@Excel(name = "使用人")
private Long userId;
/** 单价 */
@Excel(name = "单价")
private BigDecimal price;
/** 数量 */
@Excel(name = "数量")
private Long count;
/** 总价 */
@Excel(name = "总价")
private BigDecimal total;
/** 采购申请部门长 */
@Excel(name = "采购申请部门长")
private Long purchaseDeptManagerId;
/** 审批人 */
@Excel(name = "审批人")
private Long approvedUserId;
/** 是否删除:0否,1是 */
@Excel(name = "是否删除:0否,1是")
private String isDel;
/** 采购状态:0.待部门长审核 1.核算部审批 2.完成 3.驳回 */
@Excel(name = "采购状态:0.待部门长审核 1.核算部审批 2.完成 3.驳回")
private String purchaseStatus;
/** 审核时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "审核时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date approvedTime;
public void setPurchaseId(Long purchaseId)
{
this.purchaseId = purchaseId;
}
public Long getPurchaseId()
{
return purchaseId;
}
public void setPurchaseDeptId(Long purchaseDeptId)
{
this.purchaseDeptId = purchaseDeptId;
}
public Long getPurchaseDeptId()
{
return purchaseDeptId;
}
public void setPurchaseName(String purchaseName)
{
this.purchaseName = purchaseName;
}
public String getPurchaseName()
{
return purchaseName;
}
public void setSpecifications(String specifications)
{
this.specifications = specifications;
}
public String getSpecifications()
{
return specifications;
}
public void setModelType(String modelType)
{
this.modelType = modelType;
}
public String getModelType()
{
return modelType;
}
public void setApplicationDescription(String applicationDescription)
{
this.applicationDescription = applicationDescription;
}
public String getApplicationDescription()
{
return applicationDescription;
}
public void setUserId(Long userId)
{
this.userId = userId;
}
public Long getUserId()
{
return userId;
}
public void setPrice(BigDecimal price)
{
this.price = price;
}
public BigDecimal getPrice()
{
return price;
}
public void setCount(Long count)
{
this.count = count;
}
public Long getCount()
{
return count;
}
public void setTotal(BigDecimal total)
{
this.total = total;
}
public BigDecimal getTotal()
{
return total;
}
public void setPurchaseDeptManagerId(Long purchaseDeptManagerId)
{
this.purchaseDeptManagerId = purchaseDeptManagerId;
}
public Long getPurchaseDeptManagerId()
{
return purchaseDeptManagerId;
}
public void setApprovedUserId(Long approvedUserId)
{
this.approvedUserId = approvedUserId;
}
public Long getApprovedUserId()
{
return approvedUserId;
}
public void setIsDel(String isDel)
{
this.isDel = isDel;
}
public String getIsDel()
{
return isDel;
}
public void setPurchaseStatus(String purchaseStatus)
{
this.purchaseStatus = purchaseStatus;
}
public String getPurchaseStatus()
{
return purchaseStatus;
}
public void setApprovedTime(Date approvedTime)
{
this.approvedTime = approvedTime;
}
public Date getApprovedTime()
{
return approvedTime;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("purchaseId", getPurchaseId())
.append("purchaseDeptId", getPurchaseDeptId())
.append("purchaseName", getPurchaseName())
.append("specifications", getSpecifications())
.append("modelType", getModelType())
.append("applicationDescription", getApplicationDescription())
.append("userId", getUserId())
.append("price", getPrice())
.append("count", getCount())
.append("total", getTotal())
.append("purchaseDeptManagerId", getPurchaseDeptManagerId())
.append("approvedUserId", getApprovedUserId())
.append("remark", getRemark())
.append("createTime", getCreateTime())
.append("isDel", getIsDel())
.append("updateTime", getUpdateTime())
.append("purchaseStatus", getPurchaseStatus())
.append("approvedTime", getApprovedTime())
.toString();
}
}
package com.zehong.system.mapper;
import java.util.List;
import com.zehong.system.domain.TPurchase;
/**
* 外部采购(报销)申请Mapper接口
*
* @author zehong
* @date 2023-06-16
*/
public interface TPurchaseMapper
{
/**
* 查询外部采购(报销)申请
*
* @param purchaseId 外部采购(报销)申请ID
* @return 外部采购(报销)申请
*/
public TPurchase selectTPurchaseById(Long purchaseId);
/**
* 查询外部采购(报销)申请列表
*
* @param tPurchase 外部采购(报销)申请
* @return 外部采购(报销)申请集合
*/
public List<TPurchase> selectTPurchaseList(TPurchase tPurchase);
/**
* 新增外部采购(报销)申请
*
* @param tPurchase 外部采购(报销)申请
* @return 结果
*/
public int insertTPurchase(TPurchase tPurchase);
/**
* 修改外部采购(报销)申请
*
* @param tPurchase 外部采购(报销)申请
* @return 结果
*/
public int updateTPurchase(TPurchase tPurchase);
/**
* 删除外部采购(报销)申请
*
* @param purchaseId 外部采购(报销)申请ID
* @return 结果
*/
public int deleteTPurchaseById(Long purchaseId);
/**
* 批量删除外部采购(报销)申请
*
* @param purchaseIds 需要删除的数据ID
* @return 结果
*/
public int deleteTPurchaseByIds(Long[] purchaseIds);
}
package com.zehong.system.service;
import java.util.List;
import com.zehong.system.domain.TPurchase;
/**
* 外部采购(报销)申请Service接口
*
* @author zehong
* @date 2023-06-16
*/
public interface ITPurchaseService
{
/**
* 查询外部采购(报销)申请
*
* @param purchaseId 外部采购(报销)申请ID
* @return 外部采购(报销)申请
*/
public TPurchase selectTPurchaseById(Long purchaseId);
/**
* 查询外部采购(报销)申请列表
*
* @param tPurchase 外部采购(报销)申请
* @return 外部采购(报销)申请集合
*/
public List<TPurchase> selectTPurchaseList(TPurchase tPurchase);
/**
* 新增外部采购(报销)申请
*
* @param tPurchase 外部采购(报销)申请
* @return 结果
*/
public int insertTPurchase(TPurchase tPurchase);
/**
* 修改外部采购(报销)申请
*
* @param tPurchase 外部采购(报销)申请
* @return 结果
*/
public int updateTPurchase(TPurchase tPurchase);
/**
* 批量删除外部采购(报销)申请
*
* @param purchaseIds 需要删除的外部采购(报销)申请ID
* @return 结果
*/
public int deleteTPurchaseByIds(Long[] purchaseIds);
/**
* 删除外部采购(报销)申请信息
*
* @param purchaseId 外部采购(报销)申请ID
* @return 结果
*/
public int deleteTPurchaseById(Long purchaseId);
}
package com.zehong.system.service.impl;
import java.util.List;
import com.zehong.common.core.domain.entity.SysUser;
import com.zehong.common.utils.DateUtils;
import com.zehong.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zehong.system.mapper.TPurchaseMapper;
import com.zehong.system.domain.TPurchase;
import com.zehong.system.service.ITPurchaseService;
/**
* 外部采购(报销)申请Service业务层处理
*
* @author zehong
* @date 2023-06-16
*/
@Service
public class TPurchaseServiceImpl implements ITPurchaseService
{
@Autowired
private TPurchaseMapper tPurchaseMapper;
/**
* 查询外部采购(报销)申请
*
* @param purchaseId 外部采购(报销)申请ID
* @return 外部采购(报销)申请
*/
@Override
public TPurchase selectTPurchaseById(Long purchaseId)
{
return tPurchaseMapper.selectTPurchaseById(purchaseId);
}
/**
* 查询外部采购(报销)申请列表
*
* @param tPurchase 外部采购(报销)申请
* @return 外部采购(报销)申请
*/
@Override
public List<TPurchase> selectTPurchaseList(TPurchase tPurchase)
{
return tPurchaseMapper.selectTPurchaseList(tPurchase);
}
/**
* 新增外部采购(报销)申请
*
* @param tPurchase 外部采购(报销)申请
* @return 结果
*/
@Override
public int insertTPurchase(TPurchase tPurchase)
{
tPurchase.setCreateTime(DateUtils.getNowDate());
SysUser user = SecurityUtils.getLoginUser().getUser();
tPurchase.setPurchaseDeptId(user.getDeptId());
tPurchase.setHandled_by_user_id(user.getUserId());//经办人
return tPurchaseMapper.insertTPurchase(tPurchase);
}
/**
* 修改外部采购(报销)申请
*
* @param tPurchase 外部采购(报销)申请
* @return 结果
*/
@Override
public int updateTPurchase(TPurchase tPurchase)
{
tPurchase.setUpdateTime(DateUtils.getNowDate());
return tPurchaseMapper.updateTPurchase(tPurchase);
}
/**
* 批量删除外部采购(报销)申请
*
* @param purchaseIds 需要删除的外部采购(报销)申请ID
* @return 结果
*/
@Override
public int deleteTPurchaseByIds(Long[] purchaseIds)
{
return tPurchaseMapper.deleteTPurchaseByIds(purchaseIds);
}
/**
* 删除外部采购(报销)申请信息
*
* @param purchaseId 外部采购(报销)申请ID
* @return 结果
*/
@Override
public int deleteTPurchaseById(Long purchaseId)
{
return tPurchaseMapper.deleteTPurchaseById(purchaseId);
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zehong.system.mapper.TPurchaseMapper">
<resultMap type="TPurchase" id="TPurchaseResult">
<result property="purchaseId" column="purchase_id" />
<result property="purchaseDeptId" column="purchase_dept_id" />
<result property="purchaseName" column="purchase_name" />
<result property="specifications" column="specifications" />
<result property="modelType" column="model_type" />
<result property="applicationDescription" column="application_description" />
<result property="userId" column="user_id" />
<result property="price" column="price" />
<result property="count" column="count" />
<result property="total" column="total" />
<result property="purchaseDeptManagerId" column="purchase_dept_manager_id" />
<result property="approvedUserId" column="approved_user_id" />
<result property="remark" column="remark" />
<result property="createTime" column="create_time" />
<result property="isDel" column="is_del" />
<result property="updateTime" column="update_time" />
<result property="purchaseStatus" column="purchase_status" />
<result property="approvedTime" column="approved_time" />
</resultMap>
<sql id="selectTPurchaseVo">
select purchase_id, purchase_dept_id, purchase_name, specifications, model_type, application_description, user_id, price, count, total, purchase_dept_manager_id, approved_user_id, remark, create_time, is_del, update_time, purchase_status, approved_time from t_purchase
</sql>
<select id="selectTPurchaseList" parameterType="TPurchase" resultMap="TPurchaseResult">
<include refid="selectTPurchaseVo"/>
<where>
<if test="purchaseDeptId != null "> and purchase_dept_id = #{purchaseDeptId}</if>
<if test="purchaseName != null and purchaseName != ''"> and purchase_name like concat('%', #{purchaseName}, '%')</if>
<if test="specifications != null and specifications != ''"> and specifications = #{specifications}</if>
<if test="modelType != null and modelType != ''"> and model_type = #{modelType}</if>
<if test="applicationDescription != null and applicationDescription != ''"> and application_description = #{applicationDescription}</if>
<if test="userId != null "> and user_id = #{userId}</if>
<if test="price != null "> and price = #{price}</if>
<if test="count != null "> and count = #{count}</if>
<if test="total != null "> and total = #{total}</if>
<if test="purchaseDeptManagerId != null "> and purchase_dept_manager_id = #{purchaseDeptManagerId}</if>
<if test="approvedUserId != null "> and approved_user_id = #{approvedUserId}</if>
<if test="isDel != null and isDel != ''"> and is_del = #{isDel}</if>
<if test="purchaseStatus != null and purchaseStatus != ''"> and purchase_status = #{purchaseStatus}</if>
<if test="approvedTime != null "> and approved_time = #{approvedTime}</if>
</where>
</select>
<select id="selectTPurchaseById" parameterType="Long" resultMap="TPurchaseResult">
<include refid="selectTPurchaseVo"/>
where purchase_id = #{purchaseId}
</select>
<insert id="insertTPurchase" parameterType="TPurchase">
insert into t_purchase
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="purchaseId != null">purchase_id,</if>
<if test="purchaseDeptId != null">purchase_dept_id,</if>
<if test="purchaseName != null">purchase_name,</if>
<if test="specifications != null">specifications,</if>
<if test="modelType != null">model_type,</if>
<if test="applicationDescription != null">application_description,</if>
<if test="userId != null">user_id,</if>
<if test="price != null">price,</if>
<if test="count != null">count,</if>
<if test="total != null">total,</if>
<if test="purchaseDeptManagerId != null">purchase_dept_manager_id,</if>
<if test="approvedUserId != null">approved_user_id,</if>
<if test="remark != null">remark,</if>
<if test="createTime != null">create_time,</if>
<if test="isDel != null">is_del,</if>
<if test="updateTime != null">update_time,</if>
<if test="purchaseStatus != null">purchase_status,</if>
<if test="approvedTime != null">approved_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="purchaseId != null">#{purchaseId},</if>
<if test="purchaseDeptId != null">#{purchaseDeptId},</if>
<if test="purchaseName != null">#{purchaseName},</if>
<if test="specifications != null">#{specifications},</if>
<if test="modelType != null">#{modelType},</if>
<if test="applicationDescription != null">#{applicationDescription},</if>
<if test="userId != null">#{userId},</if>
<if test="price != null">#{price},</if>
<if test="count != null">#{count},</if>
<if test="total != null">#{total},</if>
<if test="purchaseDeptManagerId != null">#{purchaseDeptManagerId},</if>
<if test="approvedUserId != null">#{approvedUserId},</if>
<if test="remark != null">#{remark},</if>
<if test="createTime != null">#{createTime},</if>
<if test="isDel != null">#{isDel},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="purchaseStatus != null">#{purchaseStatus},</if>
<if test="approvedTime != null">#{approvedTime},</if>
</trim>
</insert>
<update id="updateTPurchase" parameterType="TPurchase">
update t_purchase
<trim prefix="SET" suffixOverrides=",">
<if test="purchaseDeptId != null">purchase_dept_id = #{purchaseDeptId},</if>
<if test="purchaseName != null">purchase_name = #{purchaseName},</if>
<if test="specifications != null">specifications = #{specifications},</if>
<if test="modelType != null">model_type = #{modelType},</if>
<if test="applicationDescription != null">application_description = #{applicationDescription},</if>
<if test="userId != null">user_id = #{userId},</if>
<if test="price != null">price = #{price},</if>
<if test="count != null">count = #{count},</if>
<if test="total != null">total = #{total},</if>
<if test="purchaseDeptManagerId != null">purchase_dept_manager_id = #{purchaseDeptManagerId},</if>
<if test="approvedUserId != null">approved_user_id = #{approvedUserId},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="isDel != null">is_del = #{isDel},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="purchaseStatus != null">purchase_status = #{purchaseStatus},</if>
<if test="approvedTime != null">approved_time = #{approvedTime},</if>
</trim>
where purchase_id = #{purchaseId}
</update>
<delete id="deleteTPurchaseById" parameterType="Long">
delete from t_purchase where purchase_id = #{purchaseId}
</delete>
<delete id="deleteTPurchaseByIds" parameterType="String">
delete from t_purchase where purchase_id in
<foreach item="purchaseId" collection="array" open="(" separator="," close=")">
#{purchaseId}
</foreach>
</delete>
</mapper>
\ No newline at end of file
......@@ -9,6 +9,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="noticeTitle" column="notice_title" />
<result property="noticeType" column="notice_type" />
<result property="noticeContent" column="notice_content" />
<result property="userId" column="user_id" />
<result property="status" column="status" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
......@@ -17,73 +18,79 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="remark" column="remark" />
</resultMap>
<sql id="selectNoticeVo">
select notice_id, notice_title, notice_type, cast(notice_content as char) as notice_content, status, create_by, create_time, update_by, update_time, remark
from sys_notice
<sql id="selectSysNoticeVo">
select notice_id, notice_title, notice_type, notice_content, user_id, status, create_by, create_time, update_by, update_time, remark from sys_notice
</sql>
<select id="selectNoticeById" parameterType="Long" resultMap="SysNoticeResult">
<include refid="selectNoticeVo"/>
where notice_id = #{noticeId}
</select>
<select id="selectNoticeList" parameterType="SysNotice" resultMap="SysNoticeResult">
<include refid="selectNoticeVo"/>
<include refid="selectSysNoticeVo"/>
<where>
<if test="noticeTitle != null and noticeTitle != ''">
AND notice_title like concat('%', #{noticeTitle}, '%')
</if>
<if test="noticeType != null and noticeType != ''">
AND notice_type = #{noticeType}
</if>
<if test="createBy != null and createBy != ''">
AND create_by like concat('%', #{createBy}, '%')
</if>
<if test="noticeTitle != null and noticeTitle != ''"> and notice_title = #{noticeTitle}</if>
<if test="noticeType != null and noticeType != ''"> and notice_type = #{noticeType}</if>
<if test="noticeContent != null and noticeContent != ''"> and notice_content = #{noticeContent}</if>
<if test="userId != null "> and user_id = #{userId}</if>
<if test="status != null and status != ''"> and status = #{status}</if>
</where>
</select>
<insert id="insertNotice" parameterType="SysNotice">
insert into sys_notice (
<if test="noticeTitle != null and noticeTitle != '' ">notice_title, </if>
<if test="noticeType != null and noticeType != '' ">notice_type, </if>
<if test="noticeContent != null and noticeContent != '' ">notice_content, </if>
<if test="status != null and status != '' ">status, </if>
<if test="remark != null and remark != ''">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
<if test="noticeTitle != null and noticeTitle != ''">#{noticeTitle}, </if>
<if test="noticeType != null and noticeType != ''">#{noticeType}, </if>
<if test="noticeContent != null and noticeContent != ''">#{noticeContent}, </if>
<if test="status != null and status != ''">#{status}, </if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
<select id="selectNoticeById" parameterType="Integer" resultMap="SysNoticeResult">
<include refid="selectSysNoticeVo"/>
where notice_id = #{noticeId}
</select>
<insert id="insertNotice" parameterType="SysNotice" useGeneratedKeys="true" keyProperty="noticeId">
insert into sys_notice
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="noticeTitle != null and noticeTitle != ''">notice_title,</if>
<if test="noticeType != null and noticeType != ''">notice_type,</if>
<if test="noticeContent != null">notice_content,</if>
<if test="userId != null">user_id,</if>
<if test="status != null">status,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="remark != null">remark,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="noticeTitle != null and noticeTitle != ''">#{noticeTitle},</if>
<if test="noticeType != null and noticeType != ''">#{noticeType},</if>
<if test="noticeContent != null">#{noticeContent},</if>
<if test="userId != null">#{userId},</if>
<if test="status != null">#{status},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null">#{remark},</if>
</trim>
</insert>
<update id="updateNotice" parameterType="SysNotice">
update sys_notice
<set>
<if test="noticeTitle != null and noticeTitle != ''">notice_title = #{noticeTitle}, </if>
<if test="noticeType != null and noticeType != ''">notice_type = #{noticeType}, </if>
<if test="noticeContent != null">notice_content = #{noticeContent}, </if>
<if test="status != null and status != ''">status = #{status}, </if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
<trim prefix="SET" suffixOverrides=",">
<if test="noticeTitle != null and noticeTitle != ''">notice_title = #{noticeTitle},</if>
<if test="noticeType != null and noticeType != ''">notice_type = #{noticeType},</if>
<if test="noticeContent != null">notice_content = #{noticeContent},</if>
<if test="userId != null">user_id = #{userId},</if>
<if test="status != null">status = #{status},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="remark != null">remark = #{remark},</if>
</trim>
where notice_id = #{noticeId}
</update>
<delete id="deleteNoticeById" parameterType="Long">
<delete id="deleteNoticeById" parameterType="Integer">
delete from sys_notice where notice_id = #{noticeId}
</delete>
<delete id="deleteNoticeByIds" parameterType="Long">
<delete id="deleteNoticeByIds" parameterType="String">
delete from sys_notice where notice_id in
<foreach item="noticeId" collection="array" open="(" separator="," close=")">
#{noticeId}
</foreach>
</delete>
</mapper>
\ No newline at end of file
import request from '@/utils/request'
// 查询外部采购(报销)申请列表
export function listPurchase(query) {
return request({
url: '/system/purchase/list',
method: 'get',
params: query
})
}
// 查询外部采购(报销)申请详细
export function getPurchase(purchaseId) {
return request({
url: '/system/purchase/' + purchaseId,
method: 'get'
})
}
// 新增外部采购(报销)申请
export function addPurchase(data) {
return request({
url: '/system/purchase',
method: 'post',
data: data
})
}
// 修改外部采购(报销)申请
export function updatePurchase(data) {
return request({
url: '/system/purchase',
method: 'put',
data: data
})
}
// 删除外部采购(报销)申请
export function delPurchase(purchaseId) {
return request({
url: '/system/purchase/' + purchaseId,
method: 'delete'
})
}
// 导出外部采购(报销)申请
export function exportPurchase(query) {
return request({
url: '/system/purchase/export',
method: 'get',
params: query
})
}
\ No newline at end of file
<template>
<div class="instantMessage">
<el-dropdown trigger="click" :popper-append-to-body="false" style="height: 30px">
<div>
<el-badge :value= "this.msgInfo.length" :max="99" class="messageMark">
   <!--<i class="el-icon-chat-dot-round" />-->
<i class="el-icon-message-solid messageDing"/>
 </el-badge>
</div>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item v-if="this.msgInfo.length == 0">
<span>暂无消息</span>
</el-dropdown-item>
<div v-if="this.msgInfo.length >= 0">
<el-row>
<el-col :span="12">
<el-dropdown-item>标题</el-dropdown-item>
</el-col>
<el-col :span="12">
<el-dropdown-item>类型</el-dropdown-item>
</el-col>
</el-row>
<el-row v-for="item in msgInfo">
<el-col :span="12">
<el-dropdown-item class="region-item-style">{{ item.noticeTitle }}</el-dropdown-item>
</el-col>
<el-col :span="12">
<el-dropdown-item v-if="item.noticeType == '1'">通知</el-dropdown-item>
<el-dropdown-item v-if="item.noticeType == '2'">公告</el-dropdown-item>
</el-col>
</el-row>
</div>
</el-dropdown-menu>
</el-dropdown>
</div>
</template>
<script>
export default {
name: "message",
data(){
return{
msgInfo: {}
}
},
created(){
//登录成功后创建websocket
this.$websocket.initWebSocket("ws://localhost:8668/precisionEffect/webSocket/" + this.$store.state.user.roles.join(",") + "/" + this.$store.state.user.userId);
this.$websocket.addEvent("onmessage",(msg) =>{
console.log("您有新的消息请注意接收:", JSON.parse(msg.data));
this.msgInfo = JSON.parse(msg.data);
console
})
},
methods:{
}
}
</script>
<style>
.region-item-style {
max-width: 200px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
</style>
<style scoped lang="scss">
.instantMessage{
display: inline;
.messageMark{
width: 25px;
height: 60px;
margin-right: 9px;
}
.messageDing{
font-size: 28px;
color: #5a5e66;
position: relative;
top: -5px;
}
}
</style>
......@@ -16,7 +16,7 @@
<!-- </el-tooltip>-->
</template>
<Message/>
<el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
<div class="avatar-wrapper">
<!-- <img :src="avatar" class="user-avatar">-->
......@@ -48,7 +48,7 @@ import Hamburger from '@/components/Hamburger'
import Screenfull from '@/components/Screenfull'
import SizeSelect from '@/components/SizeSelect'
import Search from '@/components/HeaderSearch'
import Message from "./Message/Message";
export default {
components: {
Breadcrumb,
......@@ -56,7 +56,8 @@ export default {
Hamburger,
Screenfull,
SizeSelect,
Search
Search,
Message
},
computed: {
...mapGetters([
......@@ -94,6 +95,8 @@ export default {
type: 'warning'
}).then(() => {
this.$store.dispatch('LogOut').then(() => {
//关闭websocket
this.$websocket.close();
location.href = '/index';
})
}).catch(() => {});
......
......@@ -71,3 +71,6 @@ new Vue({
store,
render: h => h(App)
})
import websocket from "@/utils/websocket.js";
Vue.prototype.$websocket = websocket;
import ElementUI from 'element-ui';
let lockReconnect = false;
let socket;
let timer;
let count = 10;
let wsUrl;
function initWebSocket(wsUri) {
wsUrl = wsUri;
//这里面的this都指向vue
socket = new WebSocket(wsUri);
socket.onerror = webSocketOnError;
socket.onclose = closeWebsocket;
socket.onopen = openWebsocket;
}
//错误事件监听
function webSocketOnError(e) {
ElementUI.Notification({
title: '',
message: "WebSocket连接发生错误" + e,
type: 'error',
duration: 0,
});
}
// websocket关闭监听事件
function closeWebsocket() {
reconnect();
}
//开始事件
function openWebsocket() {
if(timer){
clearInterval(timer);
}
}
// 关闭 websocket
function close() {
lockReconnect = true;
socket.close();
}
//消息发送
function webSocketSend(agentData) {
socket.send(agentData);
}
//重连机制
function reconnect(){
if(lockReconnect){
return
}
lockReconnect = true;
//没连接上会一直重连,设置延迟避免请求过多
timer = setTimeout(function(){
count --;
initWebSocket(wsUrl);
this.lockReconnect = false
if(count == 0){
clearInterval(timer);
}
},2000)
}
//监听事件添加
function addEvent(type,event){
if(type == "onopen"){
socket.onopen = event;
}else if(type == "onmessage"){
socket.onmessage = event;
}else if(type == "onclose"){
socket.onclose = event;
}else if(type == "onerror"){
socket.onerror = event;
}else{
socket.addEventListener(type,event);
}
}
export default {
initWebSocket, close, addEvent
}
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<!-- <el-form-item label="采购申请部门" prop="purchaseDeptId">-->
<!-- <el-input-->
<!-- v-model="queryParams.purchaseDeptId"-->
<!-- placeholder="请输入采购申请部门"-->
<!-- clearable-->
<!-- size="small"-->
<!-- @keyup.enter.native="handleQuery"-->
<!-- />-->
<!-- </el-form-item>-->
<el-form-item label="采购名称" prop="purchaseName">
<el-input
v-model="queryParams.purchaseName"
placeholder="请输入采购名称"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<!-- <el-form-item label="规格" prop="specifications">-->
<!-- <el-input-->
<!-- v-model="queryParams.specifications"-->
<!-- placeholder="请输入规格"-->
<!-- clearable-->
<!-- size="small"-->
<!-- @keyup.enter.native="handleQuery"-->
<!-- />-->
<!-- </el-form-item>-->
<!-- <el-form-item label="型号" prop="modelType">-->
<!-- <el-select v-model="queryParams.modelType" placeholder="请选择型号" clearable size="small">-->
<!-- <el-option label="请选择字典生成" value="" />-->
<!-- </el-select>-->
<!-- </el-form-item>-->
<el-form-item label="用途说明" prop="applicationDescription">
<el-input
v-model="queryParams.applicationDescription"
placeholder="请输入用途说明"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="使用人" prop="userId">
<el-input
v-model="queryParams.userId"
placeholder="请输入使用人"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="采购状态" prop="purchaseStatus">
<el-select v-model="queryParams.purchaseStatus" placeholder="请选择采购状态" clearable size="small">
<el-option label="待部门长审核" value="0" />
<el-option label="核算部审批" value="1" />
<el-option label="完成" value="2" />
<el-option label="驳回" value="3" />
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['system:purchase:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['system:purchase:edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['system:purchase:remove']"
>删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="el-icon-download"
size="mini"
:loading="exportLoading"
@click="handleExport"
v-hasPermi="['system:purchase:export']"
>导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="purchaseList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<!-- <el-table-column label="采购主键" align="center" prop="purchaseId" />-->
<el-table-column label="采购申请部门" align="center" prop="purchaseDeptId" />
<el-table-column label="采购名称" align="center" prop="purchaseName" />
<el-table-column label="规格" align="center" prop="specifications" />
<el-table-column label="型号" align="center" prop="modelType" />
<el-table-column label="用途说明" align="center" prop="applicationDescription" />
<el-table-column label="使用人" align="center" prop="userId" />
<el-table-column label="单价" align="center" prop="price" />
<el-table-column label="数量" align="center" prop="count" />
<el-table-column label="总价" align="center" prop="total" />
<el-table-column label="审批人" align="center" prop="approvedUserId" />
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="审批状态" align="center" prop="purchaseStatus" />
<el-table-column label="审核时间" align="center" prop="approvedTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.approvedTime, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['system:purchase:edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['system:purchase:remove']"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改外部采购(报销)申请对话框 -->
<el-dialog :title="title" :visible.sync="open" width="800px" :close-on-click-modal="false" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-row>
<!-- <el-col :span="12">-->
<!-- <el-form-item label="采购申请部门" prop="purchaseDeptId">-->
<!-- <el-input v-model="form.purchaseDeptId" placeholder="请输入采购申请部门" />-->
<!-- </el-form-item>-->
<!-- </el-col>-->
<el-col :span="24">
<el-form-item label="采购名称" prop="purchaseName">
<el-input v-model="form.purchaseName" placeholder="请输入采购名称" />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="规格" prop="specifications">
<el-input v-model="form.specifications" placeholder="请输入规格" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="型号" prop="modelType">
<el-input v-model="form.modelType" placeholder="请输入型号" />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-form-item label="用途说明" prop="applicationDescription">
<el-input v-model="form.applicationDescription" placeholder="请输入用途说明" />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="使用人" prop="userId">
<el-select v-model="form.userId" placeholder="请选择使用人" style="width: 100%">
<el-option v-for="item in usersList"
:key="item.userId"
:label="item.nickName"
:value="item.userId"/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="单价" prop="price" >
<el-input v-model="form.price" placeholder="请输入单价" @blur="sumAmount"/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="数量" prop="count">
<el-input v-model="form.count" placeholder="请输入数量" @blur="sumAmount"/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="总价" prop="total">
<el-input v-model="form.total" placeholder="请输入总价" :disabled=true />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" placeholder="请输入备注" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer" style="text-align: center">
<el-button
style="width: 150px; border-color: #1890ff; color: #1890ff"
@click="reset"
>内容重置</el-button>
<el-button type="primary" style="width: 150px" @click="submitForm"
>提交申请</el-button
>
</div>
</el-dialog>
</div>
</template>
<script>
import { listPurchase, getPurchase, delPurchase, addPurchase, updatePurchase, exportPurchase } from "@/api/transaction/purchase";
import { selectTransactorByDeptId } from "@/api/system/user";
export default {
name: "Purchase",
components: {
},
data() {
return {
usersList: [],
// 遮罩层
loading: true,
// 导出遮罩层
exportLoading: false,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 外部采购(报销)申请表格数据
purchaseList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
purchaseDeptId: null,
purchaseName: null,
specifications: null,
modelType: null,
applicationDescription: null,
userId: null,
price: null,
count: null,
total: null,
purchaseDeptManagerId: null,
approvedUserId: null,
isDel: null,
purchaseStatus: null,
approvedTime: null
},
// 表单参数
form: {},
// 表单校验
rules: {
purchaseName: [
{ required: true, message: "采购名称不能为空", trigger: "blur" },
],
specifications: [
{ required: true, message: "规格不能为空", trigger: "blur" },
],
modelType: [
{ required: true, message: "型号不能为空", trigger: "blur" },
],
applicationDescription: [
{ required: true, message: "用途不能为空", trigger: "blur" },
],
userId: [
{ required: true, message: "请选择使用人", trigger: "change" },
],
price: [
{ required: true, message: "单价不能为空", trigger: "blur" },
],
count: [
{ required: true, message: "数量不能为空", trigger: "blur" },
],
total: [
{ required: true, message: "总价不能为空", trigger: "blur" },
]
}
};
},
created() {
this.getList();
this.getUsers();
},
methods: {
//计算总价
sumAmount() {
if (this.form.price && this.form.count) {
this.form.total = this.accMul(
this.form.price,
this.form.count
);
} else {
this.form.total = "";
}
},
//浮点计算出现无限小数
accMul(arg1, arg2) {
var m = 0,
s1 = arg1.toString(),
s2 = arg2.toString();
try {
m += s1.split(".")[1].length;
} catch (e) {}
try {
m += s2.split(".")[1].length;
} catch (e) {}
return (
(Number(s1.replace(".", "")) * Number(s2.replace(".", ""))) /
Math.pow(10, m)
);
},
/** 查询外部采购(报销)申请列表 */
getList() {
this.loading = true;
listPurchase(this.queryParams).then(response => {
this.purchaseList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
purchaseId: null,
purchaseDeptId: null,
purchaseName: null,
specifications: null,
modelType: null,
applicationDescription: null,
userId: null,
price: null,
count: null,
total: null,
purchaseDeptManagerId: null,
approvedUserId: null,
remark: null,
createTime: null,
isDel: null,
updateTime: null,
purchaseStatus: "0",
approvedTime: null
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.purchaseId)
this.single = selection.length!==1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加外部采购(报销)申请";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const purchaseId = row.purchaseId || this.ids
getPurchase(purchaseId).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改外部采购(报销)申请";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.purchaseId != null) {
updatePurchase(this.form).then(response => {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addPurchase(this.form).then(response => {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const purchaseIds = row.purchaseId || this.ids;
this.$confirm('是否确认删除外部采购(报销)申请编号为"' + purchaseIds + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return delPurchase(purchaseIds);
}).then(() => {
this.getList();
this.msgSuccess("删除成功");
}).catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm('是否确认导出所有外部采购(报销)申请数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(() => {
this.exportLoading = true;
return exportPurchase(queryParams);
}).then(response => {
this.download(response.msg);
this.exportLoading = false;
}).catch(() => {});
},
getUsers() {
this.form.userId = null;
selectTransactorByDeptId({ deptId: this.$store.state.user.deptId }).then(
(res) => {
this.usersList = res.data;
}
);
}
}
};
</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment