| | |
| | | import com.nanometer.smartlab.service.DangerousEncodeService; |
| | | import com.nanometer.smartlab.util.FacesUtils; |
| | | import com.nanometer.smartlab.util.IDUtils; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.apache.log4j.Logger; |
| | | import org.primefaces.context.RequestContext; |
| | | import org.primefaces.event.FileUploadEvent; |
| | |
| | | DangerousEncode su = null; |
| | | while (iterator.hasNext()) { |
| | | su = iterator.next(); |
| | | if (rowKey.equals(su.getId())) { |
| | | if (Long.parseLong(rowKey) == (su.getId())) { |
| | | return su; |
| | | } |
| | | } |
| | |
| | | //保存 |
| | | public void onSaveBtnClick(){ |
| | | try { |
| | | |
| | | String retmsg = ""; |
| | | //插入 |
| | | if (dangerousEncode.getId() == null) { |
| | | //设置 id,创建者和更新时间 |
| | | dangerousEncode.setId(IDUtils.uuid()); |
| | | dangerousEncode.setCreator(getUser().getId()); |
| | | dangerousEncode.setUpdateTime(new Date()); |
| | | |
| | | if (StringUtils.isBlank(dangerousEncode.getReagentCode())){ |
| | | retmsg +=("试剂名称码不能为空"); |
| | | }else { |
| | | List<DangerousEncode> list1 = dangerousEncodeService.selectByCodeAndName(dangerousEncode.getReagentCode(),null,null,null); |
| | | if (list1.size() > 0){ |
| | | retmsg +=("试剂名称码已存在,请更换"); |
| | | } |
| | | } |
| | | |
| | | if (StringUtils.isBlank(dangerousEncode.getReagentName())){ |
| | | retmsg +=("试剂名称不能为空"); |
| | | }else { |
| | | List<DangerousEncode> list1 = dangerousEncodeService.selectByCodeAndName(null,dangerousEncode.getReagentName(),null,null); |
| | | if (list1.size() > 0){ |
| | | retmsg +=("试剂名称已存在,请更换"); |
| | | } |
| | | } |
| | | |
| | | if (StringUtils.isBlank(dangerousEncode.getCode())){ |
| | | retmsg +=("编码不能为空"); |
| | | }else { |
| | | List<DangerousEncode> list1 = dangerousEncodeService.selectByCodeAndName(null,null,null,dangerousEncode.getCode()); |
| | | if (list1.size() > 0){ |
| | | retmsg +=("编码已存在,请更换"); |
| | | } |
| | | } |
| | | //插入 |
| | | dangerousEncodeService.insertOne(dangerousEncode); |
| | | if (StringUtils.isBlank(retmsg)) { |
| | | dangerousEncodeService.insertOne(dangerousEncode); |
| | | } |
| | | } |
| | | //更新 |
| | | else{ |
| | | dangerousEncode.setUpdateTime(new Date()); |
| | | dangerousEncodeService.updateOne(dangerousEncode); |
| | | if (StringUtils.isBlank(dangerousEncode.getReagentCode())){ |
| | | retmsg +=("试剂名称码不能为空"); |
| | | }else { |
| | | List<DangerousEncode> list1 = dangerousEncodeService.selectByCodeAndName(dangerousEncode.getReagentCode(),null,null,null); |
| | | if (list1.size() > 0 && !list1.get(0).getId().equals(dangerousEncode.getId())){ |
| | | retmsg +=("试剂名称码已存在,请更换"); |
| | | } |
| | | } |
| | | |
| | | if (StringUtils.isBlank(dangerousEncode.getReagentName())){ |
| | | retmsg +=("试剂名称不能为空"); |
| | | }else { |
| | | List<DangerousEncode> list1 = dangerousEncodeService.selectByCodeAndName(null,dangerousEncode.getReagentName(),null,null); |
| | | if (list1.size() > 0 && !list1.get(0).getId().equals(dangerousEncode.getId())){ |
| | | retmsg +=("试剂名称已存在,请更换"); |
| | | } |
| | | } |
| | | |
| | | if (StringUtils.isBlank(dangerousEncode.getCode())){ |
| | | retmsg +=("编码不能为空"); |
| | | }else { |
| | | List<DangerousEncode> list1 = dangerousEncodeService.selectByCodeAndName(null,null,null,dangerousEncode.getCode()); |
| | | if (list1.size() > 0 && !list1.get(0).getId().equals(dangerousEncode.getId())){ |
| | | retmsg += "编码已存在,请更换"; |
| | | } |
| | | } |
| | | if (StringUtils.isBlank(retmsg)) { |
| | | dangerousEncode.setUpdateTime(new Date()); |
| | | dangerousEncodeService.updateOne(dangerousEncode); |
| | | } |
| | | } |
| | | |
| | | FacesUtils.info("操作成功"); |
| | | RequestContext.getCurrentInstance().execute("PF('dialog').hide()"); |
| | | |
| | | if (StringUtils.isNotBlank(retmsg)){ |
| | | FacesUtils.error(retmsg); |
| | | }else { |
| | | RequestContext.getCurrentInstance().execute("PF('dialog').hide()"); |
| | | FacesUtils.info("操作成功"); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | FacesUtils.warn("操作失败"); |
| | |
| | | package com.nanometer.smartlab.dao; |
| | | |
| | | import com.nanometer.smartlab.entity.DangerousEncode; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | public interface DangerousEncodeMapper { |
| | | int deleteByPrimaryKey(String id); |
| | | int deleteByPrimaryKey(Long id); |
| | | |
| | | int insert(DangerousEncode record); |
| | | |
| | |
| | | int countAll(Map params); |
| | | |
| | | List<Map> selectExportList(Map params); |
| | | } |
| | | |
| | | List<DangerousEncode> selectByCodeAndName(@Param("reagentcode") String reagentcode,@Param("reagentname") String reagentname,@Param("cas") String cas,@Param("code") String code); |
| | | } |
| | |
| | | |
| | | <resultMap id="BaseResultMap" type="com.nanometer.smartlab.entity.DangerousEncode"> |
| | | <!-- --> |
| | | <id column="id" jdbcType="VARCHAR" property="id" /> |
| | | <id column="id" jdbcType="BIGINT" property="id" /> |
| | | <result column="container_number" jdbcType="VARCHAR" property="containerNumber" /> |
| | | <result column="reagent_code" jdbcType="VARCHAR" property="reagentCode" /> |
| | | <result column="reagent_name" jdbcType="VARCHAR" property="reagentName" /> |
| | |
| | | </resultMap> |
| | | <sql id="Base_Column_List"> |
| | | <!-- --> |
| | | id, container_number, reagent_code, reagent_name, cas, memo, property, feature, avoid, |
| | | id, container_number, reagent_code, reagent_name, cas, memo, property, feature, avoid, |
| | | status, fire, random, code, update_time, creator, count |
| | | </sql> |
| | | <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap"> |
| | | <!-- --> |
| | | select |
| | | select |
| | | <include refid="Base_Column_List" /> |
| | | from sys_dangerous_encode |
| | | where id = #{id,jdbcType=VARCHAR} |
| | | where id = #{id,jdbcType=BIGINT} |
| | | </select> |
| | | <delete id="deleteByPrimaryKey" parameterType="java.lang.String"> |
| | | <delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> |
| | | <!-- --> |
| | | delete from sys_dangerous_encode |
| | | where id = #{id,jdbcType=VARCHAR} |
| | | where id = #{id,jdbcType=BIGINT} |
| | | </delete> |
| | | <insert id="insert" parameterType="com.nanometer.smartlab.entity.DangerousEncode"> |
| | | <!-- --> |
| | | insert into sys_dangerous_encode (id, container_number, reagent_code, |
| | | reagent_name, cas, memo, |
| | | property, feature, avoid, |
| | | status, fire, random, |
| | | code, update_time, creator, |
| | | insert into sys_dangerous_encode (id, container_number, reagent_code, |
| | | reagent_name, cas, memo, |
| | | property, feature, avoid, |
| | | status, fire, random, |
| | | code, update_time, creator, |
| | | count) |
| | | values (#{id,jdbcType=VARCHAR}, #{containerNumber,jdbcType=VARCHAR}, #{reagentCode,jdbcType=VARCHAR}, |
| | | #{reagentName,jdbcType=VARCHAR}, #{cas,jdbcType=VARCHAR}, #{memo,jdbcType=VARCHAR}, |
| | | #{property,jdbcType=VARCHAR}, #{feature,jdbcType=VARCHAR}, #{avoid,jdbcType=VARCHAR}, |
| | | #{status,jdbcType=VARCHAR}, #{fire,jdbcType=VARCHAR}, #{random,jdbcType=VARCHAR}, |
| | | #{code,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP}, #{creator,jdbcType=VARCHAR}, |
| | | values (#{id,jdbcType=BIGINT}, #{containerNumber,jdbcType=VARCHAR}, #{reagentCode,jdbcType=VARCHAR}, |
| | | #{reagentName,jdbcType=VARCHAR}, #{cas,jdbcType=VARCHAR}, #{memo,jdbcType=VARCHAR}, |
| | | #{property,jdbcType=VARCHAR}, #{feature,jdbcType=VARCHAR}, #{avoid,jdbcType=VARCHAR}, |
| | | #{status,jdbcType=VARCHAR}, #{fire,jdbcType=VARCHAR}, #{random,jdbcType=VARCHAR}, |
| | | #{code,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP}, #{creator,jdbcType=VARCHAR}, |
| | | #{count,jdbcType=INTEGER}) |
| | | </insert> |
| | | <insert id="insertSelective" parameterType="com.nanometer.smartlab.entity.DangerousEncode"> |
| | |
| | | </trim> |
| | | <trim prefix="values (" suffix=")" suffixOverrides=","> |
| | | <if test="id != null"> |
| | | #{id,jdbcType=VARCHAR}, |
| | | #{id,jdbcType=BIGINT}, |
| | | </if> |
| | | <if test="containerNumber != null"> |
| | | #{containerNumber,jdbcType=VARCHAR}, |
| | |
| | | count = #{count,jdbcType=INTEGER}, |
| | | </if> |
| | | </set> |
| | | where id = #{id,jdbcType=VARCHAR} |
| | | where id = #{id,jdbcType=BIGINT} |
| | | </update> |
| | | <update id="updateByPrimaryKey" parameterType="com.nanometer.smartlab.entity.DangerousEncode"> |
| | | <!-- --> |
| | |
| | | update_time = #{updateTime,jdbcType=TIMESTAMP}, |
| | | creator = #{creator,jdbcType=VARCHAR}, |
| | | count = #{count,jdbcType=INTEGER} |
| | | where id = #{id,jdbcType=VARCHAR} |
| | | where id = #{id,jdbcType=BIGINT} |
| | | </update> |
| | | |
| | | <select id="selectAll" parameterType="java.util.Map" resultMap="BaseResultMap"> |
| | |
| | | <include refid="Base_Column_List" /> |
| | | from sys_dangerous_encode |
| | | <where> |
| | | 1=1 |
| | | <if test="reagentName !=null and reagentName != ''"> |
| | | reagent_name like concat("%",#{reagentName},"%") |
| | | and reagent_name like concat("%",#{reagentName},"%") |
| | | </if> |
| | | <if test="cas !=null and cas != ''"> |
| | | cas like concat("%",#{cas},"%") |
| | | and cas like concat("%",#{cas},"%") |
| | | </if> |
| | | <if test="reagentCode!=null and reagentCode != ''"> |
| | | reagent_code like concat("%",#{reagentCode},"%") |
| | | and reagent_code like concat("%",#{reagentCode},"%") |
| | | </if> |
| | | <if test="containerNumber !=null and containerNumber != ''"> |
| | | container_number like concat("%",#{containerNumber},"%") |
| | | and container_number like concat("%",#{containerNumber},"%") |
| | | </if> |
| | | </where> |
| | | order by update_time |
| | | order by update_time desc |
| | | <if test="offset !=null and pageSize != null"> |
| | | limit #{offset},#{pageSize} |
| | | </if> |
| | |
| | | select count(1) |
| | | from sys_dangerous_encode |
| | | <where> |
| | | 1=1 |
| | | <if test="reagentName !=null and reagentName != ''"> |
| | | reagent_name like concat("%",#{reagentName},"%") |
| | | and reagent_name like concat("%",#{reagentName},"%") |
| | | </if> |
| | | <if test="cas !=null and cas != ''"> |
| | | cas like concat("%",#{cas},"%") |
| | | and cas like concat("%",#{cas},"%") |
| | | </if> |
| | | <if test="reagentCode!=null and reagentCode != ''"> |
| | | reagent_code like concat("%",#{reagentCode},"%") |
| | | and reagent_code like concat("%",#{reagentCode},"%") |
| | | </if> |
| | | <if test="containerNumber !=null and containerNumber != ''"> |
| | | container_number like concat("%",#{containerNumber},"%") |
| | | and container_number like concat("%",#{containerNumber},"%") |
| | | </if> |
| | | </where> |
| | | </select> |
| | |
| | | status, fire, random, code, update_time, creator, count |
| | | from sys_dangerous_encode |
| | | <where> |
| | | 1=1 |
| | | <if test="reagentName !=null and reagentName != ''"> |
| | | reagent_name like concat("%",#{reagentName},"%") |
| | | and reagent_name like concat("%",#{reagentName},"%") |
| | | </if> |
| | | <if test="cas !=null and cas != ''"> |
| | | cas like concat("%",#{cas},"%") |
| | | and cas like concat("%",#{cas},"%") |
| | | </if> |
| | | <if test="reagentCode!=null and reagentCode != ''"> |
| | | reagent_code like concat("%",#{reagentCode},"%") |
| | | and reagent_code like concat("%",#{reagentCode},"%") |
| | | </if> |
| | | <if test="containerNumber !=null and containerNumber != ''"> |
| | | container_number like concat("%",#{containerNumber},"%") |
| | | and container_number like concat("%",#{containerNumber},"%") |
| | | </if> |
| | | </where> |
| | | </select> |
| | | </mapper> |
| | | <select id="selectByCodeAndName" resultType="com.nanometer.smartlab.entity.DangerousEncode"> |
| | | select |
| | | <include refid="Base_Column_List" /> |
| | | from sys_dangerous_encode |
| | | <where> |
| | | 1=1 |
| | | <if test="reagentcode != null and reagentcode != ''"> |
| | | and reagent_code = #{reagentcode} |
| | | </if> |
| | | <if test="reagentname != null and reagentname != ''"> |
| | | and reagent_name = #{reagentname} |
| | | </if> |
| | | <if test="cas != null and cas != ''"> |
| | | and cas = #{cas} |
| | | </if> |
| | | <if test="code != null and code != ''"> |
| | | and code = #{code} |
| | | </if> |
| | | </where> |
| | | </select> |
| | | </mapper> |
| | |
| | | package com.nanometer.smartlab.entity; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | public class DangerousEncode { |
| | | public class DangerousEncode implements Serializable { |
| | | /** id id **/ |
| | | private String id; |
| | | private Long id; |
| | | |
| | | /** 柜码 container_number **/ |
| | | private String containerNumber; |
| | |
| | | /** 使用次数 count **/ |
| | | private Integer count; |
| | | |
| | | /** id id **/ |
| | | public String getId() { |
| | | public Long getId() { |
| | | return id; |
| | | } |
| | | |
| | | /** id id **/ |
| | | public void setId(String id) { |
| | | this.id = id == null ? null : id.trim(); |
| | | public void setId(Long id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | /** 柜码 container_number **/ |
| | |
| | | this.count = count; |
| | | } |
| | | |
| | | } |
| | | } |
| | |
| | | |
| | | int countAll(DangerousEncode dangerousEncodeFilter); |
| | | |
| | | void deleteOne(String id); |
| | | void deleteOne(Long id); |
| | | |
| | | void insertOne(DangerousEncode dangerousEncode); |
| | | |
| | |
| | | void export2Excel(List<Map> list) throws Exception; |
| | | |
| | | List<Map> exportList(DangerousEncode dangerousEncodeFilter); |
| | | |
| | | List<DangerousEncode> selectByCodeAndName(String reagentcode, String reagentname,String cas,String code); |
| | | } |
| | |
| | | import com.nanometer.smartlab.entity.DangerousEncode; |
| | | import com.nanometer.smartlab.entity.SysUser; |
| | | import com.nanometer.smartlab.util.ExcelUtils; |
| | | import com.nanometer.smartlab.util.FacesUtils; |
| | | import com.nanometer.smartlab.util.IDUtils; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.ss.usermodel.CellType; |
| | | import org.apache.poi.ss.usermodel.Row; |
| | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void deleteOne(String id) { |
| | | public void deleteOne(Long id) { |
| | | dangerousEncodeMapper.deleteByPrimaryKey(id); |
| | | } |
| | | |
| | |
| | | @Override |
| | | @Transactional |
| | | public void importInfoByExcel(FileUploadEvent event, SysUser user) throws Exception { |
| | | |
| | | //准备工作 |
| | | List<DangerousEncode> encodeList = selectAll(null, null, null); |
| | | HashSet<String> set = new HashSet<>(); |
| | | if (encodeList != null && encodeList.size() > 0) { |
| | | encodeList.forEach(encodeData -> { |
| | | set.add(encodeData.getReagentCode()); |
| | | }); |
| | | set.add(""); |
| | | } |
| | | //更新时间 |
| | | Date date = new Date(); |
| | | |
| | | UploadedFile file = event.getFile(); |
| | | InputStream is = file.getInputstream(); |
| | | boolean isExcel2003 = true; |
| | |
| | | int totalRows = sheet.getPhysicalNumberOfRows(); |
| | | Row row = null; |
| | | int totalCells = 0; |
| | | String retmsg = ""; |
| | | for (int i = 1; i < totalRows; i++) { |
| | | List<String> valuesList = new ArrayList<String>(); |
| | | row = sheet.getRow(i); |
| | | |
| | | totalCells = row.getPhysicalNumberOfCells(); |
| | | //System.out.println("====="+totalCells); |
| | | for (int t = 0; t < totalCells; t++) { |
| | | String cellInfo = ""; |
| | | if (row.getCell(t) != null) { |
| | |
| | | } |
| | | valuesList.add(cellInfo); |
| | | } |
| | | |
| | | //柜号 试剂名称码 试剂名称 CAS号 备注 性状 特性 相忌 状态 灭火器 随机码 编码 |
| | | //如果试剂条码存或者为空就失败 |
| | | if (set.contains(valuesList.get(1).trim())){ |
| | | throw new Exception(i + 1 + "行," + 2 + "列,试剂条码存或者为空"); |
| | | } |
| | | |
| | | //加入 |
| | | set.add(valuesList.get(1)); |
| | | |
| | | DangerousEncode dangerousEncode = new DangerousEncode(); |
| | | dangerousEncode.setId(IDUtils.uuid()); |
| | | dangerousEncode.setContainerNumber(valuesList.get(0)); |
| | | dangerousEncode.setReagentCode(valuesList.get(1)); |
| | | dangerousEncode.setReagentName(valuesList.get(2)); |
| | |
| | | dangerousEncode.setFire(valuesList.get(9)); |
| | | dangerousEncode.setRandom(valuesList.get(10)); |
| | | dangerousEncode.setCode(valuesList.get(11)); |
| | | |
| | | if (StringUtils.isBlank(dangerousEncode.getReagentCode())){ |
| | | retmsg += "第"+i+1+"行,试剂名称码不能为空"; |
| | | continue; |
| | | }else { |
| | | List<DangerousEncode> list1 = this.selectByCodeAndName(dangerousEncode.getReagentCode(),null,null,null); |
| | | if (list1.size() > 0){ |
| | | retmsg += "第"+i+1+"行,试剂名称码已存在,请更换"; |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | if (StringUtils.isBlank(dangerousEncode.getReagentName())){ |
| | | retmsg += "第"+i+1+"行,试剂名称不能为空"; |
| | | continue; |
| | | }else { |
| | | List<DangerousEncode> list1 = this.selectByCodeAndName(null,dangerousEncode.getReagentName(),null,null); |
| | | if (list1.size() > 0){ |
| | | retmsg += "第"+i+1+"行,试剂名称已存在,请更换"; |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | if (StringUtils.isBlank(dangerousEncode.getCode())){ |
| | | retmsg += "第"+i+1+"行,编码不能为空"; |
| | | continue; |
| | | }else { |
| | | List<DangerousEncode> list1 = this.selectByCodeAndName(null,null,null,dangerousEncode.getCode()); |
| | | if (list1.size() > 0){ |
| | | retmsg += "第"+i+1+"行,编码已存在,请更换"; |
| | | continue; |
| | | } |
| | | } |
| | | dangerousEncode.setCount(0); |
| | | dangerousEncode.setUpdateTime(date); |
| | | dangerousEncode.setUpdateTime(new Date()); |
| | | dangerousEncode.setCreator(user.getId()); |
| | | dangerousEncodeMapper.insert(dangerousEncode); |
| | | } |
| | | |
| | | |
| | | if (StringUtils.isNotBlank(retmsg)){ |
| | | FacesUtils.error(retmsg); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<DangerousEncode> selectByCodeAndName(String reagentcode, String reagentname, String cas, String code) { |
| | | return dangerousEncodeMapper.selectByCodeAndName(reagentcode,reagentname,cas,code); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void export2Excel(List<Map> list) throws Exception { |
| | | Map<String,String> map = new LinkedHashMap<>(); |
| | | map.put("containerNumber", "柜号"); |
| | |
| | | selection="#{dangerousEncodeController.selectOne}" |
| | | selectionMode="single" |
| | | pageLinks="5"> |
| | | |
| | | <p:column headerText="试剂名称码"> |
| | | <h:outputText value="#{row.reagentCode}"/> |
| | | </p:column> |
| | |
| | | </h:form> |
| | | </p:dialog> |
| | | </ui:composition> |
| | | </html> |
| | | </html> |