package com.welampiot.service.impl; import com.welampiot.common.BaseResult; import com.welampiot.common.InterfaceResultEnum; import com.welampiot.dao.GroupDao; import com.welampiot.dto.GroupDTO; import com.welampiot.service.GroupService; import com.welampiot.utils.ToolUtils; import com.welampiot.vo.GroupVO; import org.apache.ibatis.annotations.Param; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; @Service public class GroupServiceImpl implements GroupService { @Autowired private GroupDao groupDao; @Autowired private ToolUtils toolUtils; @Override public List getListBySection(List sectionList) { return groupDao.getListBySection(sectionList); } @Override public List getListByVO(GroupVO groupVO) { List listByVO = groupDao.getListByVO(groupVO); List list = new ArrayList<>(); for (GroupDTO g :listByVO) { String policy; if (g.getType() == 0){ if (groupVO.getVersion() == 0){ policy = "亮度:"+g.getValue()+"%"; } else if (groupVO.getVersion() == 1) { policy = "lightness:"+g.getValue()+"%"; }else { policy = "Яркость:"+g.getValue()+"%"; } }else if (g.getType() == 1){ if (groupVO.getVersion() == 0){ policy = "未知策略"; } else if (groupVO.getVersion() == 1) { policy = "Unknown Policy"; }else { policy = "Неизвестная стратегия"; } policy = g.getPolicy() == null || g.getPolicy().length() == 0 ? policy : g.getPolicy(); }else { if (groupVO.getVersion() == 0){ policy = "自适应"; } else if (groupVO.getVersion() == 1) { policy = "self-adaption"; }else { policy = "адаптация"; } } g.setPolicy(policy); list.add(g); } return list; } @Override public Integer getCountByVO(GroupVO groupVO) { Integer countByVO = groupDao.getCountByVO(groupVO); return countByVO == null ? 0 : countByVO; } @Override public GroupDTO getDetailByVO(GroupVO groupVO) { GroupDTO detailByVO = groupDao.getDetailByVO(groupVO); if (detailByVO == null) return null; String policy; if (detailByVO.getType() == 0){ if (groupVO.getVersion() == 0){ policy = "亮度:"+detailByVO.getValue()+"%"; } else if (groupVO.getVersion() == 1) { policy = "lightness:"+detailByVO.getValue()+"%"; }else { policy = "Яркость:"+detailByVO.getValue()+"%"; } }else if (detailByVO.getType() == 1){ if (groupVO.getVersion() == 0){ policy = "未知策略"; } else if (groupVO.getVersion() == 1) { policy = "Unknown Policy"; }else { policy = "Неизвестная стратегия"; } policy = detailByVO.getPolicy() == null || detailByVO.getPolicy().length() == 0 ? policy : detailByVO.getPolicy(); }else { if (groupVO.getVersion() == 0){ policy = "自适应"; } else if (groupVO.getVersion() == 1) { policy = "self-adaption"; }else { policy = "адаптация"; } } detailByVO.setWork(policy); return detailByVO; } @Override public BaseResult add(GroupDTO groupDTO) { GroupDTO groupDTO1 = new GroupDTO(); groupDTO1.setNumber(groupDTO.getNumber()); groupDTO1.setSectionId(groupDTO.getSectionId()); if (this.checkData(groupDTO1) > 0) return toolUtils.response(InterfaceResultEnum.GROUP_NUMBER_UNIQUE_ERROR,groupDTO.getVersion()); groupDTO1 = new GroupDTO(); groupDTO1.setName(groupDTO.getName()); groupDTO1.setSectionId(groupDTO.getSectionId()); if (this.checkData(groupDTO1) > 0) return toolUtils.response(InterfaceResultEnum.GROUP_NAME_UNIQUE_ERROR,groupDTO.getVersion()); Date endDate = new Date(System.currentTimeMillis()); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String createTime = simpleDateFormat.format(endDate).toString(); groupDTO.setCreateTime(createTime); groupDTO.setUpdateTime(createTime); groupDao.add(groupDTO); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,groupDTO.getVersion()); } @Override public BaseResult update(GroupDTO groupDTO) { GroupDTO groupDTO1 = new GroupDTO(); groupDTO1.setId(groupDTO.getId()); groupDTO1.setNumber(groupDTO.getNumber()); groupDTO1.setSectionId(groupDTO.getSectionId()); if (this.checkData(groupDTO1) > 0) return toolUtils.response(InterfaceResultEnum.GROUP_NUMBER_UNIQUE_ERROR,groupDTO.getVersion()); groupDTO1 = new GroupDTO(); groupDTO1.setId(groupDTO.getId()); groupDTO1.setName(groupDTO.getName()); groupDTO1.setSectionId(groupDTO.getSectionId()); if (this.checkData(groupDTO1) > 0) return toolUtils.response(InterfaceResultEnum.GROUP_NAME_UNIQUE_ERROR,groupDTO.getVersion()); Date endDate = new Date(System.currentTimeMillis()); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String createTime = simpleDateFormat.format(endDate).toString(); groupDTO.setUpdateTime(createTime); groupDao.update(groupDTO); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,groupDTO.getVersion()); } @Override public Integer checkData(GroupDTO groupDTO) { Integer integer = groupDao.checkData(groupDTO); System.out.println(integer); return integer == null ? 0 : integer; } @Override public Integer deleteById(Integer id) { return groupDao.deleteById(id); } @Override public List getGroupListByDTO(GroupVO vo) { return groupDao.getGroupListByDTO(vo); } @Override public String findPolicyNameByValue(Integer id) { return groupDao.findPolicyNameByValue(id); } @Override public Integer getGroupTotalByDTO(GroupDTO dto) { return groupDao.getGroupTotalByDTO(dto); } @Override public GroupDTO getGroupDTOById(Integer id) { return groupDao.getGroupDTOById(id); } @Override public void updateGroupLampId(GroupDTO dto) { groupDao.updateGroupLampId(dto); } @Override public List getListByIds(@Param("ids") String[] ids){ return groupDao.getListByIds(ids); } }